Skip to content

Commit 0668586

Browse files
committed
Merge remote-tracking branch 'benma/nanopb-2'
2 parents 7f55b19 + 40a9a06 commit 0668586

File tree

7 files changed

+25
-28
lines changed

7 files changed

+25
-28
lines changed

.ci/run-container-ci

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
set -e
2626
set -x
2727

28-
CONTAINER=shiftcrypto/firmware_v2:16
28+
CONTAINER=shiftcrypto/firmware_v2:17
2929

3030
if [ "$1" == "pull" ] ; then
3131
docker pull "$CONTAINER"

Dockerfile

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,6 @@ RUN mkdir ~/Downloads &&\
3434
rm -f gcc.tar.bz2 &&\
3535
cd ~/Downloads && rsync -a gcc-arm-none-eabi-8-2018-q4-major/ /usr/local/
3636

37-
# Install nanopb
38-
RUN cd ~/Downloads &&\
39-
wget https://jpa.kapsi.fi/nanopb/download/nanopb-0.3.9.2-linux-x86.tar.gz &&\
40-
echo "00624f2834066ab31613dd2bb53b258a3b81cd83554df4a7cf49725c5cf34c46 nanopb-0.3.9.2-linux-x86.tar.gz" | sha256sum -c &&\
41-
tar -xvzf nanopb-0.3.9.2-linux-x86.tar.gz &&\
42-
rm -f nanopb-0.3.9.2-linux-x86.tar.gz &&\
43-
mv ~/Downloads/nanopb-0.3.9.2-linux-x86/generator-bin/protoc* /usr/local/bin/ &&\
44-
mv ~/Downloads/nanopb-0.3.9.2-linux-x86/generator-bin/nanopb_generator /usr/local/bin/ &&\
45-
mv ~/Downloads/nanopb-0.3.9.2-linux-x86/generator-bin/libpython*so* /usr/local/bin/ &&\
46-
mv ~/Downloads/nanopb-0.3.9.2-linux-x86/generator-bin/*so* /usr/local/lib/ &&\
47-
mv ~/Downloads/nanopb-0.3.9.2-linux-x86/generator-bin/include/* /usr/local/include/ &&\
48-
mv ~/Downloads/nanopb-0.3.9.2-linux-x86/generator/proto/google/ /usr/local/include/
49-
5037
# Tools for building
5138
RUN apt-get update && apt-get install -y \
5239
build-essential \
@@ -111,6 +98,11 @@ RUN python3 -m pip install --upgrade \
11198
wheel==0.33.6 \
11299
twine==1.15.0
113100

101+
# For protoc
102+
RUN apt-get update && apt-get install -y protobuf-compiler
103+
# Make Python3 the default, so tools/nanopb/generator/*.py run with Python3.
104+
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
105+
114106
# Developer tools
115107
RUN apt-get update && apt-get install -y \
116108
bash-completion

messages/CMakeLists.txt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
find_program(PROTOC_GEN_NANOPB protoc-gen-nanopb)
2-
31
set(PROTO_FILES
42
hww.proto
53
backup.proto
@@ -18,13 +16,6 @@ set(PROTO_FILES
1816
string(REGEX REPLACE "\.proto" ".pb.c" OUTPUT_SOURCES "${PROTO_FILES}")
1917
string(REGEX REPLACE "\.proto" ".pb.h" OUTPUT_HEADERS "${PROTO_FILES}")
2018

21-
if (PROTOC_GEN_NANOPB STREQUAL "PROTOC_GEN_NANOPB-NOTFOUND")
22-
message(FATAL_ERROR
23-
"Could not find 'protoc-gen-nanopb'.\n"
24-
"Please install it from here: https://jpa.kapsi.fi/nanopb/download/\n"
25-
"And add generator-bin/ to your path.")
26-
endif()
27-
2819
# Create absolute paths to protobuf sources
2920
foreach(i ${PROTO_FILES})
3021
list(APPEND PROTO_FILES_ABSOLUTE "${CMAKE_CURRENT_SOURCE_DIR}/${i}")
@@ -55,7 +46,11 @@ add_custom_command(
5546
OUTPUT ${OUTPUT_SOURCES} ${OUTPUT_HEADERS}
5647
DEPENDS ${PROTO_FILES} ${PROTO_OPTION_FILES}
5748
COMMAND
58-
${PROTOC} "--proto_path=${CMAKE_CURRENT_SOURCE_DIR}" "--nanopb_out=-I${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_CURRENT_BINARY_DIR}" ${PROTO_FILES_ABSOLUTE}
49+
${CMAKE_SOURCE_DIR}/tools/nanopb/generator/protoc
50+
--plugin=protoc-gen-nanopb=${CMAKE_SOURCE_DIR}/tools/nanopb/generator/protoc-gen-nanopb
51+
--proto_path=${CMAKE_CURRENT_SOURCE_DIR}
52+
'--nanopb_out=-I${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_CURRENT_BINARY_DIR}'
53+
${PROTO_FILES_ABSOLUTE}
5954
)
6055

6156
add_custom_target(

messages/backup.options

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// skip `bool has_*` fields for submessages
16+
// https://github.com/nanopb/nanopb/blob/1fdc916e984b27cc0a3824427f70a15def567a2e/docs/migration.rst#submessages-now-have-has-field-in-proto3-mode
17+
* proto3_singular_msgs:true
18+
1519
Backup.backup_version no_unions:true
1620
BackupData.seed fixed_length:true max_size:32
1721
BackupData.generator fixed_length:true max_size:20

messages/btc.options

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
// skip `bool has_*` fields for submessages
17+
// https://github.com/nanopb/nanopb/blob/1fdc916e984b27cc0a3824427f70a15def567a2e/docs/migration.rst#submessages-now-have-has-field-in-proto3-mode
18+
* proto3_singular_msgs:true
19+
1620
BTCScriptConfig.Multisig.xpubs max_count:15
1721
BTCPubRequest.keypath max_count:10
1822
BTCSignInitRequest.script_configs max_count:3

src/backup/backup_common.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ void backup_calculate_checksum(BackupContent* content, BackupData* backup_data,
9797
* @param[in] field The field that is encoded.
9898
* @param[in] arg The encode/decode data passed to the callback.
9999
*/
100-
static bool _encode_backup_data(pb_ostream_t* ostream, const pb_field_t* field, void* const* arg)
100+
static bool _encode_backup_data(
101+
pb_ostream_t* ostream,
102+
const pb_field_iter_t* field,
103+
void* const* arg)
101104
{
102-
(void)field;
103105
encode_data_t* encode_data = (encode_data_t*)*arg;
104106
if (*(encode_data->mode) != BackupMode_PLAINTEXT) {
105107
return false;
@@ -161,7 +163,7 @@ backup_error_t backup_fill(
161163

162164
// This function is a callback to nanopb when serializing the `data` field.
163165
// We call it here manually once more to extract the length.
164-
_encode_backup_data(&submessage_out_stream, iter.pos, (void* const*)&encode_data);
166+
_encode_backup_data(&submessage_out_stream, &iter, (void* const*)&encode_data);
165167

166168
// This length is the serialization of BackupData as protobuf, including the `data` field
167169
// tag prefix serialization. See the comment in backup.proto for more details.

tools/nanopb

0 commit comments

Comments
 (0)