mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
Merge branch 'nanopb-0.4'
This commit is contained in:
commit
3c7806aaf6
1
Pipfile
1
Pipfile
@ -10,6 +10,7 @@ scons = "*"
|
||||
protobuf = "==3.6.1"
|
||||
pyblake2 = "*"
|
||||
Pyro4 = "*"
|
||||
nanopb = "==0.4.1"
|
||||
|
||||
## test tools
|
||||
pytest = "*"
|
||||
|
29
Pipfile.lock
generated
29
Pipfile.lock
generated
@ -1,7 +1,7 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "0b8d85136c58724c9a9ed769913e4a486ec5b8dad6e96fe7c6aa0c45a2509538"
|
||||
"sha256": "1fb4b3d284c147d94baaa4a6a1224fa9d3d62371cefd4ccd1faa5a2fc80460b2"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {},
|
||||
@ -418,6 +418,14 @@
|
||||
],
|
||||
"version": "==0.4.3"
|
||||
},
|
||||
"nanopb": {
|
||||
"hashes": [
|
||||
"sha256:0f1ef49aed947892a648197201c0c0b86b1e093794ef5cdba85f3f4ee00c5bfb",
|
||||
"sha256:462b94f57cdfc691f4d303c2585024bb5da1f958d16b90d8982043b3d76188ce"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==0.4.1"
|
||||
},
|
||||
"nose": {
|
||||
"hashes": [
|
||||
"sha256:9ff7c6cc443f8c51994b34a667bbcf45afd6d945be7477b52e97516fd17c53ac",
|
||||
@ -556,11 +564,11 @@
|
||||
},
|
||||
"pyro4": {
|
||||
"hashes": [
|
||||
"sha256:2bfe12a22f396474b0e57c898c7e2c561a8f850bf2055d8cf0f7119f0c7a523f",
|
||||
"sha256:7c4712257ba5bed8bc4ed037bdad5b4683a483a5fd634a2ac3effa5ba787f511"
|
||||
"sha256:98c2c9547d111ecbf2c1f327953ee1919db60b701b8fe9a612f40359b2ea70ba",
|
||||
"sha256:b69200747c4c69bfa6fa8b917806b0a9ee7939daaf67ab9bb5ccac7e5179feee"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==4.77"
|
||||
"version": "==4.78"
|
||||
},
|
||||
"pytest": {
|
||||
"hashes": [
|
||||
@ -639,10 +647,11 @@
|
||||
},
|
||||
"serpent": {
|
||||
"hashes": [
|
||||
"sha256:34070629becc4db10ff35ddcaed0f6ab83135fff0a6bd3b913910656bba0eb64",
|
||||
"sha256:b112cd656feacb899a29f8ec4cc136b238dcbaca069aaf4eaea3cc09cd0610e4"
|
||||
"sha256:72753820246a7d8486e8b385353e3bbf769abfceec2e850fa527a288b084ff7a",
|
||||
"sha256:b2e8fa890481ca068faf9913c7019db5a8c30aa5e7e5870846996749872cecb3"
|
||||
],
|
||||
"version": "==1.30.1"
|
||||
"markers": "python_version >= '3.2'",
|
||||
"version": "==1.30.2"
|
||||
},
|
||||
"shamir-mnemonic": {
|
||||
"hashes": [
|
||||
@ -738,10 +747,10 @@
|
||||
},
|
||||
"virtualenv": {
|
||||
"hashes": [
|
||||
"sha256:916497082376027a387c49af092a4316c0e9db753f95ea1af22eba569f107cfe",
|
||||
"sha256:9a87270123622593ad454a81055b771a8898590ff3d6f3abbe48c4111ff49e79"
|
||||
"sha256:a7a7f272882815c2f84b9a5bfd75ab4e32eea257bc3169a9c139310c064ebbeb",
|
||||
"sha256:d98aa9ae72aa2f892e697e38c0314cd835c8f44d7f38b2fe27d11a6aa084dd2c"
|
||||
],
|
||||
"version": "==20.0.0b1"
|
||||
"version": "==20.0.0b2"
|
||||
},
|
||||
"wcwidth": {
|
||||
"hashes": [
|
||||
|
@ -72,15 +72,18 @@ SOURCE_STMHAL = [
|
||||
'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c',
|
||||
]
|
||||
|
||||
SOURCE_NANOPB = [
|
||||
'vendor/nanopb/pb_common.c',
|
||||
'vendor/nanopb/pb_decode.c',
|
||||
'vendor/nanopb/pb_encode.c',
|
||||
]
|
||||
|
||||
SOURCE_BOOTLOADER = [
|
||||
'embed/bootloader/startup.s',
|
||||
'embed/bootloader/header.S',
|
||||
'embed/bootloader/bootui.c',
|
||||
'embed/bootloader/main.c',
|
||||
'embed/bootloader/messages.c',
|
||||
'embed/bootloader/nanopb/pb_common.c',
|
||||
'embed/bootloader/nanopb/pb_decode.c',
|
||||
'embed/bootloader/nanopb/pb_encode.c',
|
||||
'embed/bootloader/protob/messages.pb.c',
|
||||
'embed/bootloader/protob/types.pb.c',
|
||||
]
|
||||
@ -148,6 +151,7 @@ env.Replace(
|
||||
'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Inc',
|
||||
'vendor/micropython/lib/stm32lib/CMSIS/STM32F4xx/Include',
|
||||
'vendor/micropython/lib/cmsis/inc',
|
||||
'vendor/nanopb',
|
||||
] + CPPPATH_MOD,
|
||||
CPPDEFINES=[
|
||||
('TREZOR_MODEL', '$TREZOR_MODEL'),
|
||||
@ -155,6 +159,8 @@ env.Replace(
|
||||
'USE_HAL_DRIVER',
|
||||
('STM32_HAL_H', '"<stm32f4xx.h>"'),
|
||||
'PB_FIELD_16BIT',
|
||||
'PB_ENCODE_ARRAYS_UNPACKED',
|
||||
'PB_VALIDATE_UTF8',
|
||||
] + CPPDEFINES_MOD,
|
||||
ASFLAGS=CPU_ASFLAGS,
|
||||
ASPPFLAGS='$CFLAGS $CCFLAGS', )
|
||||
@ -170,6 +176,7 @@ env.Replace(
|
||||
obj_program = []
|
||||
obj_program += env.Object(source=SOURCE_MOD)
|
||||
obj_program += env.Object(source=SOURCE_BOOTLOADER)
|
||||
obj_program += env.Object(source=SOURCE_NANOPB)
|
||||
obj_program += env.Object(source=SOURCE_STMHAL)
|
||||
obj_program += env.Object(source=SOURCE_TREZORHAL)
|
||||
|
||||
|
@ -107,7 +107,7 @@ static void _usb_write_flush(usb_write_state *state) {
|
||||
}
|
||||
|
||||
static secbool _send_msg(uint8_t iface_num, uint16_t msg_id,
|
||||
const pb_field_t fields[], const void *msg) {
|
||||
const pb_msgdesc_t *fields, const void *msg) {
|
||||
// determine message size by serializing it into a dummy stream
|
||||
pb_ostream_t sizestream = {.callback = NULL,
|
||||
.state = NULL,
|
||||
@ -225,7 +225,7 @@ static bool _usb_read(pb_istream_t *stream, uint8_t *buf, size_t count) {
|
||||
static void _usb_read_flush(usb_read_state *state) { (void)state; }
|
||||
|
||||
static secbool _recv_msg(uint8_t iface_num, uint32_t msg_size, uint8_t *buf,
|
||||
const pb_field_t fields[], void *msg) {
|
||||
const pb_msgdesc_t *fields, void *msg) {
|
||||
usb_read_state state = {.iface_num = iface_num,
|
||||
.packet_index = 0,
|
||||
.packet_pos = MSG_HEADER1_LEN,
|
||||
|
@ -1 +0,0 @@
|
||||
../../vendor/nanopb
|
@ -1,7 +1,7 @@
|
||||
all: messages.pb.c types.pb.c
|
||||
|
||||
%.pb.c: %.pb %.options
|
||||
../../../vendor/nanopb/generator/nanopb_generator.py $< -T
|
||||
nanopb_generator $< -T
|
||||
|
||||
%.pb: %.proto
|
||||
protoc -I/usr/include -I. $< -o $@
|
||||
|
@ -3,7 +3,6 @@ Features.device_id max_size:25
|
||||
Features.language max_size:17
|
||||
Features.label max_size:33
|
||||
Features.revision max_size:20
|
||||
Features.bootloader_hash max_size:32
|
||||
Features.model max_size:17
|
||||
Features.fw_vendor max_size:256
|
||||
Features.fw_vendor_keys max_size:32
|
||||
|
@ -1,95 +1,43 @@
|
||||
/* Automatically generated nanopb constant definitions */
|
||||
/* Generated by nanopb-0.3.9.4 */
|
||||
/* Generated by nanopb-0.4.1 */
|
||||
|
||||
#include "messages.pb.h"
|
||||
|
||||
/* @@protoc_insertion_point(includes) */
|
||||
#if PB_PROTO_HEADER_VERSION != 30
|
||||
#if PB_PROTO_HEADER_VERSION != 40
|
||||
#error Regenerate this file with the current version of nanopb generator.
|
||||
#endif
|
||||
|
||||
PB_BIND(Initialize, Initialize, AUTO)
|
||||
|
||||
|
||||
const pb_field_t Initialize_fields[1] = {
|
||||
PB_LAST_FIELD
|
||||
};
|
||||
PB_BIND(GetFeatures, GetFeatures, AUTO)
|
||||
|
||||
const pb_field_t GetFeatures_fields[1] = {
|
||||
PB_LAST_FIELD
|
||||
};
|
||||
|
||||
const pb_field_t Features_fields[18] = {
|
||||
PB_FIELD( 1, STRING , OPTIONAL, STATIC , FIRST, Features, vendor, vendor, 0),
|
||||
PB_FIELD( 2, UINT32 , OPTIONAL, STATIC , OTHER, Features, major_version, vendor, 0),
|
||||
PB_FIELD( 3, UINT32 , OPTIONAL, STATIC , OTHER, Features, minor_version, major_version, 0),
|
||||
PB_FIELD( 4, UINT32 , OPTIONAL, STATIC , OTHER, Features, patch_version, minor_version, 0),
|
||||
PB_FIELD( 5, BOOL , OPTIONAL, STATIC , OTHER, Features, bootloader_mode, patch_version, 0),
|
||||
PB_FIELD( 6, STRING , OPTIONAL, STATIC , OTHER, Features, device_id, bootloader_mode, 0),
|
||||
PB_FIELD( 9, STRING , OPTIONAL, STATIC , OTHER, Features, language, device_id, 0),
|
||||
PB_FIELD( 10, STRING , OPTIONAL, STATIC , OTHER, Features, label, language, 0),
|
||||
PB_FIELD( 12, BOOL , OPTIONAL, STATIC , OTHER, Features, initialized, label, 0),
|
||||
PB_FIELD( 13, BYTES , OPTIONAL, STATIC , OTHER, Features, revision, initialized, 0),
|
||||
PB_FIELD( 18, BOOL , OPTIONAL, STATIC , OTHER, Features, firmware_present, revision, 0),
|
||||
PB_FIELD( 21, STRING , OPTIONAL, STATIC , OTHER, Features, model, firmware_present, 0),
|
||||
PB_FIELD( 22, UINT32 , OPTIONAL, STATIC , OTHER, Features, fw_major, model, 0),
|
||||
PB_FIELD( 23, UINT32 , OPTIONAL, STATIC , OTHER, Features, fw_minor, fw_major, 0),
|
||||
PB_FIELD( 24, UINT32 , OPTIONAL, STATIC , OTHER, Features, fw_patch, fw_minor, 0),
|
||||
PB_FIELD( 25, STRING , OPTIONAL, STATIC , OTHER, Features, fw_vendor, fw_patch, 0),
|
||||
PB_FIELD( 26, BYTES , OPTIONAL, STATIC , OTHER, Features, fw_vendor_keys, fw_vendor, 0),
|
||||
PB_LAST_FIELD
|
||||
};
|
||||
PB_BIND(Features, Features, 2)
|
||||
|
||||
const pb_field_t Ping_fields[5] = {
|
||||
PB_FIELD( 1, STRING , OPTIONAL, STATIC , FIRST, Ping, message, message, 0),
|
||||
PB_FIELD( 2, BOOL , OPTIONAL, STATIC , OTHER, Ping, button_protection, message, 0),
|
||||
PB_FIELD( 3, BOOL , OPTIONAL, STATIC , OTHER, Ping, pin_protection, button_protection, 0),
|
||||
PB_FIELD( 4, BOOL , OPTIONAL, STATIC , OTHER, Ping, passphrase_protection, pin_protection, 0),
|
||||
PB_LAST_FIELD
|
||||
};
|
||||
|
||||
const pb_field_t Success_fields[2] = {
|
||||
PB_FIELD( 1, STRING , OPTIONAL, STATIC , FIRST, Success, message, message, 0),
|
||||
PB_LAST_FIELD
|
||||
};
|
||||
PB_BIND(Ping, Ping, 2)
|
||||
|
||||
const pb_field_t Failure_fields[3] = {
|
||||
PB_FIELD( 1, ENUM , OPTIONAL, STATIC , FIRST, Failure, code, code, 0),
|
||||
PB_FIELD( 2, STRING , OPTIONAL, STATIC , OTHER, Failure, message, code, 0),
|
||||
PB_LAST_FIELD
|
||||
};
|
||||
|
||||
const pb_field_t ButtonRequest_fields[2] = {
|
||||
PB_FIELD( 1, ENUM , OPTIONAL, STATIC , FIRST, ButtonRequest, code, code, 0),
|
||||
PB_LAST_FIELD
|
||||
};
|
||||
PB_BIND(Success, Success, 2)
|
||||
|
||||
const pb_field_t ButtonAck_fields[1] = {
|
||||
PB_LAST_FIELD
|
||||
};
|
||||
|
||||
const pb_field_t FirmwareErase_fields[2] = {
|
||||
PB_FIELD( 1, UINT32 , OPTIONAL, STATIC , FIRST, FirmwareErase, length, length, 0),
|
||||
PB_LAST_FIELD
|
||||
};
|
||||
PB_BIND(Failure, Failure, 2)
|
||||
|
||||
const pb_field_t FirmwareRequest_fields[3] = {
|
||||
PB_FIELD( 1, UINT32 , OPTIONAL, STATIC , FIRST, FirmwareRequest, offset, offset, 0),
|
||||
PB_FIELD( 2, UINT32 , OPTIONAL, STATIC , OTHER, FirmwareRequest, length, offset, 0),
|
||||
PB_LAST_FIELD
|
||||
};
|
||||
|
||||
const pb_field_t FirmwareUpload_fields[3] = {
|
||||
PB_FIELD( 1, BYTES , REQUIRED, CALLBACK, FIRST, FirmwareUpload, payload, payload, 0),
|
||||
PB_FIELD( 2, BYTES , OPTIONAL, STATIC , OTHER, FirmwareUpload, hash, payload, 0),
|
||||
PB_LAST_FIELD
|
||||
};
|
||||
PB_BIND(ButtonRequest, ButtonRequest, AUTO)
|
||||
|
||||
|
||||
PB_BIND(ButtonAck, ButtonAck, AUTO)
|
||||
|
||||
|
||||
PB_BIND(FirmwareErase, FirmwareErase, AUTO)
|
||||
|
||||
|
||||
PB_BIND(FirmwareRequest, FirmwareRequest, AUTO)
|
||||
|
||||
|
||||
PB_BIND(FirmwareUpload, FirmwareUpload, AUTO)
|
||||
|
||||
|
||||
|
||||
/* Check that field information fits in pb_field_t */
|
||||
#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT)
|
||||
#error Field descriptor for Failure.message is too large. Define PB_FIELD_16BIT to fix this.
|
||||
#endif
|
||||
|
||||
|
||||
/* @@protoc_insertion_point(eof) */
|
||||
|
@ -1,14 +1,12 @@
|
||||
/* Automatically generated nanopb header */
|
||||
/* Generated by nanopb-0.3.9.4 */
|
||||
/* Generated by nanopb-0.4.1 */
|
||||
|
||||
#ifndef PB_MESSAGES_PB_H_INCLUDED
|
||||
#define PB_MESSAGES_PB_H_INCLUDED
|
||||
#include <pb.h>
|
||||
|
||||
#include "types.pb.h"
|
||||
|
||||
/* @@protoc_insertion_point(includes) */
|
||||
#if PB_PROTO_HEADER_VERSION != 30
|
||||
#if PB_PROTO_HEADER_VERSION != 40
|
||||
#error Regenerate this file with the current version of nanopb generator.
|
||||
#endif
|
||||
|
||||
@ -30,30 +28,23 @@ typedef enum _MessageType {
|
||||
MessageType_MessageType_ButtonAck = 27,
|
||||
MessageType_MessageType_GetFeatures = 55
|
||||
} MessageType;
|
||||
#define _MessageType_MIN MessageType_MessageType_Initialize
|
||||
#define _MessageType_MAX MessageType_MessageType_GetFeatures
|
||||
#define _MessageType_ARRAYSIZE ((MessageType)(MessageType_MessageType_GetFeatures+1))
|
||||
|
||||
/* Struct definitions */
|
||||
typedef struct _ButtonAck {
|
||||
char dummy_field;
|
||||
/* @@protoc_insertion_point(struct:ButtonAck) */
|
||||
} ButtonAck;
|
||||
|
||||
typedef struct _GetFeatures {
|
||||
char dummy_field;
|
||||
/* @@protoc_insertion_point(struct:GetFeatures) */
|
||||
} GetFeatures;
|
||||
|
||||
typedef struct _Initialize {
|
||||
char dummy_field;
|
||||
/* @@protoc_insertion_point(struct:Initialize) */
|
||||
} Initialize;
|
||||
|
||||
typedef struct _ButtonRequest {
|
||||
bool has_code;
|
||||
ButtonRequestType code;
|
||||
/* @@protoc_insertion_point(struct:ButtonRequest) */
|
||||
} ButtonRequest;
|
||||
|
||||
typedef struct _Failure {
|
||||
@ -61,7 +52,6 @@ typedef struct _Failure {
|
||||
FailureType code;
|
||||
bool has_message;
|
||||
char message[256];
|
||||
/* @@protoc_insertion_point(struct:Failure) */
|
||||
} Failure;
|
||||
|
||||
typedef PB_BYTES_ARRAY_T(20) Features_revision_t;
|
||||
@ -101,13 +91,11 @@ typedef struct _Features {
|
||||
char fw_vendor[256];
|
||||
bool has_fw_vendor_keys;
|
||||
Features_fw_vendor_keys_t fw_vendor_keys;
|
||||
/* @@protoc_insertion_point(struct:Features) */
|
||||
} Features;
|
||||
|
||||
typedef struct _FirmwareErase {
|
||||
bool has_length;
|
||||
uint32_t length;
|
||||
/* @@protoc_insertion_point(struct:FirmwareErase) */
|
||||
} FirmwareErase;
|
||||
|
||||
typedef struct _FirmwareRequest {
|
||||
@ -115,7 +103,6 @@ typedef struct _FirmwareRequest {
|
||||
uint32_t offset;
|
||||
bool has_length;
|
||||
uint32_t length;
|
||||
/* @@protoc_insertion_point(struct:FirmwareRequest) */
|
||||
} FirmwareRequest;
|
||||
|
||||
typedef PB_BYTES_ARRAY_T(32) FirmwareUpload_hash_t;
|
||||
@ -123,7 +110,6 @@ typedef struct _FirmwareUpload {
|
||||
pb_callback_t payload;
|
||||
bool has_hash;
|
||||
FirmwareUpload_hash_t hash;
|
||||
/* @@protoc_insertion_point(struct:FirmwareUpload) */
|
||||
} FirmwareUpload;
|
||||
|
||||
typedef struct _Ping {
|
||||
@ -135,16 +121,19 @@ typedef struct _Ping {
|
||||
bool pin_protection;
|
||||
bool has_passphrase_protection;
|
||||
bool passphrase_protection;
|
||||
/* @@protoc_insertion_point(struct:Ping) */
|
||||
} Ping;
|
||||
|
||||
typedef struct _Success {
|
||||
bool has_message;
|
||||
char message[256];
|
||||
/* @@protoc_insertion_point(struct:Success) */
|
||||
} Success;
|
||||
|
||||
/* Default values for struct fields */
|
||||
|
||||
/* Helper constants for enums */
|
||||
#define _MessageType_MIN MessageType_MessageType_Initialize
|
||||
#define _MessageType_MAX MessageType_MessageType_GetFeatures
|
||||
#define _MessageType_ARRAYSIZE ((MessageType)(MessageType_MessageType_GetFeatures+1))
|
||||
|
||||
|
||||
/* Initializer values for message structs */
|
||||
#define Initialize_init_default {0}
|
||||
@ -203,42 +192,123 @@ typedef struct _Success {
|
||||
#define Success_message_tag 1
|
||||
|
||||
/* Struct field encoding specification for nanopb */
|
||||
extern const pb_field_t Initialize_fields[1];
|
||||
extern const pb_field_t GetFeatures_fields[1];
|
||||
extern const pb_field_t Features_fields[18];
|
||||
extern const pb_field_t Ping_fields[5];
|
||||
extern const pb_field_t Success_fields[2];
|
||||
extern const pb_field_t Failure_fields[3];
|
||||
extern const pb_field_t ButtonRequest_fields[2];
|
||||
extern const pb_field_t ButtonAck_fields[1];
|
||||
extern const pb_field_t FirmwareErase_fields[2];
|
||||
extern const pb_field_t FirmwareRequest_fields[3];
|
||||
extern const pb_field_t FirmwareUpload_fields[3];
|
||||
#define Initialize_FIELDLIST(X, a) \
|
||||
|
||||
#define Initialize_CALLBACK NULL
|
||||
#define Initialize_DEFAULT NULL
|
||||
|
||||
#define GetFeatures_FIELDLIST(X, a) \
|
||||
|
||||
#define GetFeatures_CALLBACK NULL
|
||||
#define GetFeatures_DEFAULT NULL
|
||||
|
||||
#define Features_FIELDLIST(X, a) \
|
||||
X(a, STATIC, OPTIONAL, STRING, vendor, 1) \
|
||||
X(a, STATIC, OPTIONAL, UINT32, major_version, 2) \
|
||||
X(a, STATIC, OPTIONAL, UINT32, minor_version, 3) \
|
||||
X(a, STATIC, OPTIONAL, UINT32, patch_version, 4) \
|
||||
X(a, STATIC, OPTIONAL, BOOL, bootloader_mode, 5) \
|
||||
X(a, STATIC, OPTIONAL, STRING, device_id, 6) \
|
||||
X(a, STATIC, OPTIONAL, STRING, language, 9) \
|
||||
X(a, STATIC, OPTIONAL, STRING, label, 10) \
|
||||
X(a, STATIC, OPTIONAL, BOOL, initialized, 12) \
|
||||
X(a, STATIC, OPTIONAL, BYTES, revision, 13) \
|
||||
X(a, STATIC, OPTIONAL, BOOL, firmware_present, 18) \
|
||||
X(a, STATIC, OPTIONAL, STRING, model, 21) \
|
||||
X(a, STATIC, OPTIONAL, UINT32, fw_major, 22) \
|
||||
X(a, STATIC, OPTIONAL, UINT32, fw_minor, 23) \
|
||||
X(a, STATIC, OPTIONAL, UINT32, fw_patch, 24) \
|
||||
X(a, STATIC, OPTIONAL, STRING, fw_vendor, 25) \
|
||||
X(a, STATIC, OPTIONAL, BYTES, fw_vendor_keys, 26)
|
||||
#define Features_CALLBACK NULL
|
||||
#define Features_DEFAULT NULL
|
||||
|
||||
#define Ping_FIELDLIST(X, a) \
|
||||
X(a, STATIC, OPTIONAL, STRING, message, 1) \
|
||||
X(a, STATIC, OPTIONAL, BOOL, button_protection, 2) \
|
||||
X(a, STATIC, OPTIONAL, BOOL, pin_protection, 3) \
|
||||
X(a, STATIC, OPTIONAL, BOOL, passphrase_protection, 4)
|
||||
#define Ping_CALLBACK NULL
|
||||
#define Ping_DEFAULT NULL
|
||||
|
||||
#define Success_FIELDLIST(X, a) \
|
||||
X(a, STATIC, OPTIONAL, STRING, message, 1)
|
||||
#define Success_CALLBACK NULL
|
||||
#define Success_DEFAULT NULL
|
||||
|
||||
#define Failure_FIELDLIST(X, a) \
|
||||
X(a, STATIC, OPTIONAL, ENUM, code, 1) \
|
||||
X(a, STATIC, OPTIONAL, STRING, message, 2)
|
||||
#define Failure_CALLBACK NULL
|
||||
#define Failure_DEFAULT NULL
|
||||
|
||||
#define ButtonRequest_FIELDLIST(X, a) \
|
||||
X(a, STATIC, OPTIONAL, ENUM, code, 1)
|
||||
#define ButtonRequest_CALLBACK NULL
|
||||
#define ButtonRequest_DEFAULT NULL
|
||||
|
||||
#define ButtonAck_FIELDLIST(X, a) \
|
||||
|
||||
#define ButtonAck_CALLBACK NULL
|
||||
#define ButtonAck_DEFAULT NULL
|
||||
|
||||
#define FirmwareErase_FIELDLIST(X, a) \
|
||||
X(a, STATIC, OPTIONAL, UINT32, length, 1)
|
||||
#define FirmwareErase_CALLBACK NULL
|
||||
#define FirmwareErase_DEFAULT NULL
|
||||
|
||||
#define FirmwareRequest_FIELDLIST(X, a) \
|
||||
X(a, STATIC, OPTIONAL, UINT32, offset, 1) \
|
||||
X(a, STATIC, OPTIONAL, UINT32, length, 2)
|
||||
#define FirmwareRequest_CALLBACK NULL
|
||||
#define FirmwareRequest_DEFAULT NULL
|
||||
|
||||
#define FirmwareUpload_FIELDLIST(X, a) \
|
||||
X(a, CALLBACK, REQUIRED, BYTES, payload, 1) \
|
||||
X(a, STATIC, OPTIONAL, BYTES, hash, 2)
|
||||
#define FirmwareUpload_CALLBACK pb_default_field_callback
|
||||
#define FirmwareUpload_DEFAULT NULL
|
||||
|
||||
extern const pb_msgdesc_t Initialize_msg;
|
||||
extern const pb_msgdesc_t GetFeatures_msg;
|
||||
extern const pb_msgdesc_t Features_msg;
|
||||
extern const pb_msgdesc_t Ping_msg;
|
||||
extern const pb_msgdesc_t Success_msg;
|
||||
extern const pb_msgdesc_t Failure_msg;
|
||||
extern const pb_msgdesc_t ButtonRequest_msg;
|
||||
extern const pb_msgdesc_t ButtonAck_msg;
|
||||
extern const pb_msgdesc_t FirmwareErase_msg;
|
||||
extern const pb_msgdesc_t FirmwareRequest_msg;
|
||||
extern const pb_msgdesc_t FirmwareUpload_msg;
|
||||
|
||||
/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
|
||||
#define Initialize_fields &Initialize_msg
|
||||
#define GetFeatures_fields &GetFeatures_msg
|
||||
#define Features_fields &Features_msg
|
||||
#define Ping_fields &Ping_msg
|
||||
#define Success_fields &Success_msg
|
||||
#define Failure_fields &Failure_msg
|
||||
#define ButtonRequest_fields &ButtonRequest_msg
|
||||
#define ButtonAck_fields &ButtonAck_msg
|
||||
#define FirmwareErase_fields &FirmwareErase_msg
|
||||
#define FirmwareRequest_fields &FirmwareRequest_msg
|
||||
#define FirmwareUpload_fields &FirmwareUpload_msg
|
||||
|
||||
/* Maximum encoded size of messages (where known) */
|
||||
#define Initialize_size 0
|
||||
#define GetFeatures_size 0
|
||||
#define Features_size 499
|
||||
#define Ping_size 265
|
||||
#define Success_size 259
|
||||
#define Failure_size 270
|
||||
#define Features_size 493
|
||||
#define Ping_size 264
|
||||
#define Success_size 258
|
||||
#define Failure_size 269
|
||||
#define ButtonRequest_size 11
|
||||
#define ButtonAck_size 0
|
||||
#define FirmwareErase_size 6
|
||||
#define FirmwareRequest_size 12
|
||||
/* FirmwareUpload_size depends on runtime parameters */
|
||||
|
||||
/* Message IDs (where set with "msgid" option) */
|
||||
#ifdef PB_MSGID
|
||||
|
||||
#define MESSAGES_MESSAGES \
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* @@protoc_insertion_point(eof) */
|
||||
|
||||
#endif
|
||||
|
@ -1,3 +1,5 @@
|
||||
syntax = "proto2";
|
||||
|
||||
import "types.proto";
|
||||
|
||||
/**
|
||||
|
@ -1,16 +1,11 @@
|
||||
/* Automatically generated nanopb constant definitions */
|
||||
/* Generated by nanopb-0.4.0-dev */
|
||||
/* Generated by nanopb-0.4.1 */
|
||||
|
||||
#include "types.pb.h"
|
||||
|
||||
/* @@protoc_insertion_point(includes) */
|
||||
#if PB_PROTO_HEADER_VERSION != 30
|
||||
#if PB_PROTO_HEADER_VERSION != 40
|
||||
#error Regenerate this file with the current version of nanopb generator.
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* @@protoc_insertion_point(eof) */
|
||||
|
@ -1,12 +1,11 @@
|
||||
/* Automatically generated nanopb header */
|
||||
/* Generated by nanopb-0.4.0-dev */
|
||||
/* Generated by nanopb-0.4.1 */
|
||||
|
||||
#ifndef PB_TYPES_PB_H_INCLUDED
|
||||
#define PB_TYPES_PB_H_INCLUDED
|
||||
#include <pb.h>
|
||||
|
||||
/* @@protoc_insertion_point(includes) */
|
||||
#if PB_PROTO_HEADER_VERSION != 30
|
||||
#if PB_PROTO_HEADER_VERSION != 40
|
||||
#error Regenerate this file with the current version of nanopb generator.
|
||||
#endif
|
||||
|
||||
@ -17,42 +16,27 @@ extern "C" {
|
||||
/* Enum definitions */
|
||||
typedef enum _FailureType {
|
||||
FailureType_Failure_UnexpectedMessage = 1,
|
||||
FailureType_Failure_ButtonExpected = 2,
|
||||
FailureType_Failure_DataError = 3,
|
||||
FailureType_Failure_ActionCancelled = 4,
|
||||
FailureType_Failure_PinExpected = 5,
|
||||
FailureType_Failure_PinCancelled = 6,
|
||||
FailureType_Failure_PinInvalid = 7,
|
||||
FailureType_Failure_InvalidSignature = 8,
|
||||
FailureType_Failure_ProcessError = 9,
|
||||
FailureType_Failure_NotEnoughFunds = 10,
|
||||
FailureType_Failure_NotInitialized = 11,
|
||||
FailureType_Failure_FirmwareError = 99
|
||||
FailureType_Failure_DataError = 3,
|
||||
FailureType_Failure_ProcessError = 9
|
||||
} FailureType;
|
||||
#define _FailureType_MIN FailureType_Failure_UnexpectedMessage
|
||||
#define _FailureType_MAX FailureType_Failure_FirmwareError
|
||||
#define _FailureType_ARRAYSIZE ((FailureType)(FailureType_Failure_FirmwareError+1))
|
||||
|
||||
typedef enum _ButtonRequestType {
|
||||
ButtonRequestType_ButtonRequest_Other = 1,
|
||||
ButtonRequestType_ButtonRequest_FeeOverThreshold = 2,
|
||||
ButtonRequestType_ButtonRequest_ConfirmOutput = 3,
|
||||
ButtonRequestType_ButtonRequest_ResetDevice = 4,
|
||||
ButtonRequestType_ButtonRequest_ConfirmWord = 5,
|
||||
ButtonRequestType_ButtonRequest_WipeDevice = 6,
|
||||
ButtonRequestType_ButtonRequest_ProtectCall = 7,
|
||||
ButtonRequestType_ButtonRequest_SignTx = 8,
|
||||
ButtonRequestType_ButtonRequest_FirmwareCheck = 9,
|
||||
ButtonRequestType_ButtonRequest_Address = 10,
|
||||
ButtonRequestType_ButtonRequest_PublicKey = 11
|
||||
ButtonRequestType_ButtonRequest_Other = 1
|
||||
} ButtonRequestType;
|
||||
|
||||
/* Helper constants for enums */
|
||||
#define _FailureType_MIN FailureType_Failure_UnexpectedMessage
|
||||
#define _FailureType_MAX FailureType_Failure_ProcessError
|
||||
#define _FailureType_ARRAYSIZE ((FailureType)(FailureType_Failure_ProcessError+1))
|
||||
|
||||
#define _ButtonRequestType_MIN ButtonRequestType_ButtonRequest_Other
|
||||
#define _ButtonRequestType_MAX ButtonRequestType_ButtonRequest_PublicKey
|
||||
#define _ButtonRequestType_ARRAYSIZE ((ButtonRequestType)(ButtonRequestType_ButtonRequest_PublicKey+1))
|
||||
#define _ButtonRequestType_MAX ButtonRequestType_ButtonRequest_Other
|
||||
#define _ButtonRequestType_ARRAYSIZE ((ButtonRequestType)(ButtonRequestType_ButtonRequest_Other+1))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
/* @@protoc_insertion_point(eof) */
|
||||
|
||||
#endif
|
||||
|
@ -1,20 +1,14 @@
|
||||
syntax = "proto2";
|
||||
|
||||
/**
|
||||
* Type of failures returned by Failure message
|
||||
* @used_in Failure
|
||||
*/
|
||||
enum FailureType {
|
||||
Failure_UnexpectedMessage = 1;
|
||||
Failure_ButtonExpected = 2;
|
||||
Failure_DataError = 3;
|
||||
Failure_ActionCancelled = 4;
|
||||
Failure_PinExpected = 5;
|
||||
Failure_PinCancelled = 6;
|
||||
Failure_PinInvalid = 7;
|
||||
Failure_InvalidSignature = 8;
|
||||
Failure_DataError = 3;
|
||||
Failure_ProcessError = 9;
|
||||
Failure_NotEnoughFunds = 10;
|
||||
Failure_NotInitialized = 11;
|
||||
Failure_FirmwareError = 99;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -23,14 +17,4 @@ enum FailureType {
|
||||
*/
|
||||
enum ButtonRequestType {
|
||||
ButtonRequest_Other = 1;
|
||||
ButtonRequest_FeeOverThreshold = 2;
|
||||
ButtonRequest_ConfirmOutput = 3;
|
||||
ButtonRequest_ResetDevice = 4;
|
||||
ButtonRequest_ConfirmWord = 5;
|
||||
ButtonRequest_WipeDevice = 6;
|
||||
ButtonRequest_ProtectCall = 7;
|
||||
ButtonRequest_SignTx = 8;
|
||||
ButtonRequest_FirmwareCheck = 9;
|
||||
ButtonRequest_Address = 10;
|
||||
ButtonRequest_PublicKey = 11;
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ DEBUG_LINK ?= 0
|
||||
DEBUG_LOG ?= 0
|
||||
|
||||
CFLAGS += -Wno-sequence-point
|
||||
CFLAGS += -I../vendor/nanopb -Iprotob -DPB_FIELD_16BIT=1 -DPB_ENCODE_ARRAYS_UNPACKED=1
|
||||
CFLAGS += -I../vendor/nanopb -Iprotob -DPB_FIELD_16BIT=1 -DPB_ENCODE_ARRAYS_UNPACKED=1 -DPB_VALIDATE_UTF8=1
|
||||
CFLAGS += -DDEBUG_LINK=$(DEBUG_LINK)
|
||||
CFLAGS += -DDEBUG_LOG=$(DEBUG_LOG)
|
||||
CFLAGS += -DSCM_REVISION='"$(shell git rev-parse HEAD | sed 's:\(..\):\\x\1:g')"'
|
||||
|
@ -35,7 +35,7 @@ struct MessagesMap_t {
|
||||
char type; // n = normal, d = debug
|
||||
char dir; // i = in, o = out
|
||||
uint16_t msg_id;
|
||||
const pb_field_t *fields;
|
||||
const pb_msgdesc_t *fields;
|
||||
void (*process_func)(const void *ptr);
|
||||
};
|
||||
|
||||
@ -46,7 +46,7 @@ static const struct MessagesMap_t MessagesMap[] = {
|
||||
|
||||
#include "messages_map_limits.h"
|
||||
|
||||
const pb_field_t *MessageFields(char type, char dir, uint16_t msg_id) {
|
||||
const pb_msgdesc_t *MessageFields(char type, char dir, uint16_t msg_id) {
|
||||
const struct MessagesMap_t *m = MessagesMap;
|
||||
while (m->type) {
|
||||
if (type == m->type && dir == m->dir && msg_id == m->msg_id) {
|
||||
@ -159,7 +159,7 @@ static bool pb_debug_callback_out(pb_ostream_t *stream, const uint8_t *buf,
|
||||
#endif
|
||||
|
||||
bool msg_write_common(char type, uint16_t msg_id, const void *msg_ptr) {
|
||||
const pb_field_t *fields = MessageFields(type, 'o', msg_id);
|
||||
const pb_msgdesc_t *fields = MessageFields(type, 'o', msg_id);
|
||||
if (!fields) { // unknown message
|
||||
return false;
|
||||
}
|
||||
@ -212,7 +212,7 @@ enum {
|
||||
READSTATE_READING,
|
||||
};
|
||||
|
||||
void msg_process(char type, uint16_t msg_id, const pb_field_t *fields,
|
||||
void msg_process(char type, uint16_t msg_id, const pb_msgdesc_t *fields,
|
||||
uint8_t *msg_raw, uint32_t msg_size) {
|
||||
static uint8_t msg_data[MSG_IN_SIZE];
|
||||
memzero(msg_data, sizeof(msg_data));
|
||||
@ -231,7 +231,7 @@ void msg_read_common(char type, const uint8_t *buf, uint32_t len) {
|
||||
static uint16_t msg_id = 0xFFFF;
|
||||
static uint32_t msg_size = 0;
|
||||
static uint32_t msg_pos = 0;
|
||||
static const pb_field_t *fields = 0;
|
||||
static const pb_msgdesc_t *fields = 0;
|
||||
|
||||
if (len != 64) return;
|
||||
|
||||
@ -325,7 +325,7 @@ void msg_read_tiny(const uint8_t *buf, int len) {
|
||||
return;
|
||||
}
|
||||
|
||||
const pb_field_t *fields = 0;
|
||||
const pb_msgdesc_t *fields = 0;
|
||||
pb_istream_t stream = pb_istream_from_buffer(buf + 9, msg_size);
|
||||
|
||||
switch (msg_id) {
|
||||
|
@ -14,11 +14,11 @@ PYTHON ?= python
|
||||
|
||||
%.pb.c: %.pb %.options
|
||||
@printf " NANOPB $@\n"
|
||||
$(Q)$(PYTHON) ../../vendor/nanopb/generator/nanopb_generator.py $< \
|
||||
$(Q)nanopb_generator $< \
|
||||
-L '#include "%s"' \
|
||||
-T \
|
||||
-s "mangle_names:M_FLATTEN"
|
||||
@grep CALLBACK $@ && echo "CALLBACK field found" && rm $@ && exit 1 || :
|
||||
@grep " CALLBACK, " $@ && echo "CALLBACK field found" && rm $@ && exit 1 || :
|
||||
|
||||
%.pb: %.proto
|
||||
@printf " PROTOC $@\n"
|
||||
|
2
vendor/nanopb
vendored
2
vendor/nanopb
vendored
@ -1 +1 @@
|
||||
Subproject commit 493adf3616bee052649c63c473f8355630c2797f
|
||||
Subproject commit 3eb9a75c1e66e6182e87e2bd758ff2a4d16acbdc
|
Loading…
Reference in New Issue
Block a user