From 8dacad078204e55ae3942f992522dd59d219ba94 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 20 Jul 2020 15:31:21 +0200 Subject: [PATCH] core/bootloader: update protobuf definitions --- core/SConscript.bootloader | 1 - core/embed/bootloader/protob/Makefile | 4 +- core/embed/bootloader/protob/messages.options | 24 ++-- core/embed/bootloader/protob/messages.pb.c | 2 + core/embed/bootloader/protob/messages.pb.h | 48 +++---- core/embed/bootloader/protob/messages.proto | 118 +++++++++--------- core/embed/bootloader/protob/types.options | 0 core/embed/bootloader/protob/types.pb.c | 11 -- core/embed/bootloader/protob/types.pb.h | 42 ------- core/embed/bootloader/protob/types.proto | 20 --- legacy/firmware/protob/Makefile | 2 +- 11 files changed, 105 insertions(+), 167 deletions(-) delete mode 100644 core/embed/bootloader/protob/types.options delete mode 100644 core/embed/bootloader/protob/types.pb.c delete mode 100644 core/embed/bootloader/protob/types.pb.h delete mode 100644 core/embed/bootloader/protob/types.proto diff --git a/core/SConscript.bootloader b/core/SConscript.bootloader index 826bd77103..98f2272f7e 100644 --- a/core/SConscript.bootloader +++ b/core/SConscript.bootloader @@ -85,7 +85,6 @@ SOURCE_BOOTLOADER = [ 'embed/bootloader/main.c', 'embed/bootloader/messages.c', 'embed/bootloader/protob/messages.pb.c', - 'embed/bootloader/protob/types.pb.c', ] SOURCE_TREZORHAL = [ diff --git a/core/embed/bootloader/protob/Makefile b/core/embed/bootloader/protob/Makefile index 80c57816bd..576276b4e9 100644 --- a/core/embed/bootloader/protob/Makefile +++ b/core/embed/bootloader/protob/Makefile @@ -1,7 +1,7 @@ -all: messages.pb.c types.pb.c +all: messages.pb.c %.pb.c: %.pb %.options - nanopb_generator $< -T + nanopb_generator $< -T -D . -s "mangle_names:M_FLATTEN" %.pb: %.proto protoc -I/usr/include -I. $< -o $@ diff --git a/core/embed/bootloader/protob/messages.options b/core/embed/bootloader/protob/messages.options index 8630df2adb..23e90fbba9 100644 --- a/core/embed/bootloader/protob/messages.options +++ b/core/embed/bootloader/protob/messages.options @@ -1,16 +1,16 @@ -Features.vendor max_size:33 -Features.device_id max_size:25 -Features.language max_size:17 -Features.label max_size:33 -Features.revision max_size:20 -Features.model max_size:17 -Features.fw_vendor max_size:256 -Features.fw_vendor_keys max_size:32 +Features.vendor max_size:33 +Features.device_id max_size:25 +Features.language max_size:17 +Features.label max_size:33 +Features.revision max_size:20 +Features.model max_size:17 +Features.fw_vendor max_size:256 +Features.fw_vendor_keys max_size:32 -Ping.message max_size:256 +Ping.message max_size:256 -Success.message max_size:256 +Success.message max_size:256 -Failure.message max_size:256 +Failure.message max_size:256 -FirmwareUpload.hash max_size:32 +FirmwareUpload.hash max_size:32 diff --git a/core/embed/bootloader/protob/messages.pb.c b/core/embed/bootloader/protob/messages.pb.c index 63076e9ccb..76f60b935c 100644 --- a/core/embed/bootloader/protob/messages.pb.c +++ b/core/embed/bootloader/protob/messages.pb.c @@ -41,3 +41,5 @@ PB_BIND(FirmwareUpload, FirmwareUpload, AUTO) + + diff --git a/core/embed/bootloader/protob/messages.pb.h b/core/embed/bootloader/protob/messages.pb.h index a06349064a..e3d94d004d 100644 --- a/core/embed/bootloader/protob/messages.pb.h +++ b/core/embed/bootloader/protob/messages.pb.h @@ -4,7 +4,6 @@ #ifndef PB_MESSAGES_PB_H_INCLUDED #define PB_MESSAGES_PB_H_INCLUDED #include -#include "types.pb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. @@ -29,6 +28,17 @@ typedef enum _MessageType { MessageType_MessageType_GetFeatures = 55 } MessageType; +typedef enum _FailureType { + FailureType_Failure_UnexpectedMessage = 1, + FailureType_Failure_DataError = 3, + FailureType_Failure_ActionCancelled = 4, + FailureType_Failure_ProcessError = 9 +} FailureType; + +typedef enum _ButtonRequestType { + ButtonRequestType_ButtonRequest_Other = 1 +} ButtonRequestType; + /* Struct definitions */ typedef struct _ButtonAck { char dummy_field; @@ -115,12 +125,6 @@ typedef struct _FirmwareUpload { typedef struct _Ping { bool has_message; char message[256]; - bool has_button_protection; - bool button_protection; - bool has_pin_protection; - bool pin_protection; - bool has_passphrase_protection; - bool passphrase_protection; } Ping; typedef struct _Success { @@ -134,12 +138,20 @@ typedef struct _Success { #define _MessageType_MAX MessageType_MessageType_GetFeatures #define _MessageType_ARRAYSIZE ((MessageType)(MessageType_MessageType_GetFeatures+1)) +#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_Other +#define _ButtonRequestType_ARRAYSIZE ((ButtonRequestType)(ButtonRequestType_ButtonRequest_Other+1)) + /* Initializer values for message structs */ #define Initialize_init_default {0} #define GetFeatures_init_default {0} #define Features_init_default {false, "", false, 0, false, 0, false, 0, false, 0, false, "", false, "", false, "", false, 0, false, {0, {0}}, false, 0, false, "", false, 0, false, 0, false, 0, false, "", false, {0, {0}}} -#define Ping_init_default {false, "", false, 0, false, 0, false, 0} +#define Ping_init_default {false, ""} #define Success_init_default {false, ""} #define Failure_init_default {false, _FailureType_MIN, false, ""} #define ButtonRequest_init_default {false, _ButtonRequestType_MIN} @@ -150,7 +162,7 @@ typedef struct _Success { #define Initialize_init_zero {0} #define GetFeatures_init_zero {0} #define Features_init_zero {false, "", false, 0, false, 0, false, 0, false, 0, false, "", false, "", false, "", false, 0, false, {0, {0}}, false, 0, false, "", false, 0, false, 0, false, 0, false, "", false, {0, {0}}} -#define Ping_init_zero {false, "", false, 0, false, 0, false, 0} +#define Ping_init_zero {false, ""} #define Success_init_zero {false, ""} #define Failure_init_zero {false, _FailureType_MIN, false, ""} #define ButtonRequest_init_zero {false, _ButtonRequestType_MIN} @@ -186,9 +198,6 @@ typedef struct _Success { #define FirmwareUpload_payload_tag 1 #define FirmwareUpload_hash_tag 2 #define Ping_message_tag 1 -#define Ping_button_protection_tag 2 -#define Ping_pin_protection_tag 3 -#define Ping_passphrase_protection_tag 4 #define Success_message_tag 1 /* Struct field encoding specification for nanopb */ @@ -224,10 +233,7 @@ X(a, STATIC, OPTIONAL, BYTES, fw_vendor_keys, 26) #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) +X(a, STATIC, OPTIONAL, STRING, message, 1) #define Ping_CALLBACK NULL #define Ping_DEFAULT NULL @@ -237,13 +243,13 @@ X(a, STATIC, OPTIONAL, STRING, message, 1) #define Success_DEFAULT NULL #define Failure_FIELDLIST(X, a) \ -X(a, STATIC, OPTIONAL, ENUM, code, 1) \ +X(a, STATIC, OPTIONAL, UENUM, 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) +X(a, STATIC, OPTIONAL, UENUM, code, 1) #define ButtonRequest_CALLBACK NULL #define ButtonRequest_DEFAULT NULL @@ -298,10 +304,10 @@ extern const pb_msgdesc_t FirmwareUpload_msg; #define Initialize_size 0 #define GetFeatures_size 0 #define Features_size 493 -#define Ping_size 264 +#define Ping_size 258 #define Success_size 258 -#define Failure_size 269 -#define ButtonRequest_size 11 +#define Failure_size 260 +#define ButtonRequest_size 2 #define ButtonAck_size 0 #define FirmwareErase_size 6 #define FirmwareRequest_size 12 diff --git a/core/embed/bootloader/protob/messages.proto b/core/embed/bootloader/protob/messages.proto index ff0ac993ad..4483f809e5 100644 --- a/core/embed/bootloader/protob/messages.proto +++ b/core/embed/bootloader/protob/messages.proto @@ -1,26 +1,26 @@ syntax = "proto2"; -import "types.proto"; /** * Mapping between Trezor wire identifier (uint) and a protobuf message */ enum MessageType { - MessageType_Initialize = 0; - MessageType_Ping = 1; - MessageType_Success = 2; - MessageType_Failure = 3; - MessageType_FirmwareErase = 6; - MessageType_FirmwareUpload = 7; - MessageType_FirmwareRequest = 8; - MessageType_Features = 17; - MessageType_ButtonRequest = 26; - MessageType_ButtonAck = 27; - MessageType_GetFeatures = 55; + MessageType_Initialize = 0; + MessageType_Ping = 1; + MessageType_Success = 2; + MessageType_Failure = 3; + MessageType_FirmwareErase = 6; + MessageType_FirmwareUpload = 7; + MessageType_FirmwareRequest = 8; + MessageType_Features = 17; + MessageType_ButtonRequest = 26; + MessageType_ButtonAck = 27; + MessageType_GetFeatures = 55; } /** * Request: Reset device to default state and ask for device details + * @start * @next Features */ message Initialize { @@ -28,6 +28,7 @@ message Initialize { /** * Request: Ask for device details (no device reset) + * @start * @next Features */ message GetFeatures { @@ -35,87 +36,89 @@ message GetFeatures { /** * Response: Reports various information about the device - * @prev Initialize - * @prev GetFeatures + * @end */ message Features { - optional string vendor = 1; // name of the manufacturer, e.g. "trezor.io" - optional uint32 major_version = 2; // major version of the firmware/bootloader, e.g. 1 - optional uint32 minor_version = 3; // minor version of the firmware/bootloader, e.g. 0 - optional uint32 patch_version = 4; // patch version of the firmware/bootloader, e.g. 0 - optional bool bootloader_mode = 5; // is device in bootloader mode? - optional string device_id = 6; // device's unique identifier -// optional bool pin_protection = 7; // is device protected by PIN? -// optional bool passphrase_protection = 8; // is node/mnemonic encrypted using passphrase? - optional string language = 9; // device language - optional string label = 10; // device description label - optional bool initialized = 12; // does device contain seed? - optional bytes revision = 13; // SCM revision of firmware -// optional bytes bootloader_hash = 14; // hash of the bootloader -// optional bool imported = 15; // was storage imported from an external source? -// optional bool pin_cached = 16; // is PIN already cached in session? -// optional bool passphrase_cached = 17; // is passphrase already cached in session? - optional bool firmware_present = 18; // is valid firmware loaded? -// optional bool needs_backup = 19; // does storage need backup? (equals to Storage.needs_backup) -// optional uint32 flags = 20; // device flags (equals to Storage.flags) - optional string model = 21; // device hardware model - optional uint32 fw_major = 22; // reported firmware version if in bootloader mode - optional uint32 fw_minor = 23; // reported firmware version if in bootloader mode - optional uint32 fw_patch = 24; // reported firmware version if in bootloader mode - optional string fw_vendor = 25; // reported firmware vendor if in bootloader mode - optional bytes fw_vendor_keys = 26; // reported firmware vendor keys (their hash) + optional string vendor = 1; // name of the manufacturer, e.g. "trezor.io" + optional uint32 major_version = 2; // major version of the firmware/bootloader, e.g. 1 + optional uint32 minor_version = 3; // minor version of the firmware/bootloader, e.g. 0 + optional uint32 patch_version = 4; // patch version of the firmware/bootloader, e.g. 0 + optional bool bootloader_mode = 5; // is device in bootloader mode? + optional string device_id = 6; // device's unique identifier + optional string language = 9; // device language + optional string label = 10; // device description label + optional bool initialized = 12; // does device contain seed? + optional bytes revision = 13; // SCM revision of firmware + optional bool firmware_present = 18; // is valid firmware loaded? + optional string model = 21; // device hardware model + optional uint32 fw_major = 22; // reported firmware version if in bootloader mode + optional uint32 fw_minor = 23; // reported firmware version if in bootloader mode + optional uint32 fw_patch = 24; // reported firmware version if in bootloader mode + optional string fw_vendor = 25; // reported firmware vendor if in bootloader mode + optional bytes fw_vendor_keys = 26; // reported firmware vendor keys (their hash) } /** * Request: Test if the device is alive, device sends back the message in Success response + * @start * @next Success */ message Ping { - optional string message = 1; // message to send back in Success message - optional bool button_protection = 2; // ask for button press - optional bool pin_protection = 3; // ask for PIN if set in device - optional bool passphrase_protection = 4; // ask for passphrase if set in device + optional string message = 1; // message to send back in Success message } /** * Response: Success of the previous request + * @end */ message Success { - optional string message = 1; // human readable description of action or request-specific payload + optional string message = 1; // human readable description of action or request-specific payload } /** * Response: Failure of the previous request + * @end */ message Failure { - optional FailureType code = 1; // computer-readable definition of the error state - optional string message = 2; // human-readable message of the error state + optional FailureType code = 1; // computer-readable definition of the error state + optional string message = 2; // human-readable message of the error state + enum FailureType { + Failure_UnexpectedMessage = 1; + Failure_DataError = 3; + Failure_ActionCancelled = 4; + Failure_ProcessError = 9; + } } /** * Response: Device is waiting for HW button press. + * @auxstart * @next ButtonAck - * @next Cancel */ message ButtonRequest { - optional ButtonRequestType code = 1; + optional ButtonRequestType code = 1; + /** + * Type of button request + */ + enum ButtonRequestType { + ButtonRequest_Other = 1; + } } /** * Request: Computer agrees to wait for HW button press - * @prev ButtonRequest + * @auxend */ message ButtonAck { } /** * Request: Ask device to erase its firmware (so it can be replaced via FirmwareUpload) - * @next Success + * @start * @next FirmwareRequest - * @next Failure */ message FirmwareErase { - optional uint32 length = 1; // length of new firmware + optional uint32 length = 1; // length of new firmware } /** @@ -123,16 +126,17 @@ message FirmwareErase { * @next FirmwareUpload */ message FirmwareRequest { - optional uint32 offset = 1; // offset of requested firmware chunk - optional uint32 length = 2; // length of requested firmware chunk + optional uint32 offset = 1; // offset of requested firmware chunk + optional uint32 length = 2; // length of requested firmware chunk } /** * Request: Send firmware in binary form to the device + * @next FirmwareRequest * @next Success * @next Failure */ -message FirmwareUpload { - required bytes payload = 1; // firmware to be loaded into device - optional bytes hash = 2; // hash of the payload + message FirmwareUpload { + required bytes payload = 1; // firmware to be loaded into device + optional bytes hash = 2; // hash of the payload } diff --git a/core/embed/bootloader/protob/types.options b/core/embed/bootloader/protob/types.options deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/core/embed/bootloader/protob/types.pb.c b/core/embed/bootloader/protob/types.pb.c deleted file mode 100644 index 651020e110..0000000000 --- a/core/embed/bootloader/protob/types.pb.c +++ /dev/null @@ -1,11 +0,0 @@ -/* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.4.1 */ - -#include "types.pb.h" -#if PB_PROTO_HEADER_VERSION != 40 -#error Regenerate this file with the current version of nanopb generator. -#endif - - - - diff --git a/core/embed/bootloader/protob/types.pb.h b/core/embed/bootloader/protob/types.pb.h deleted file mode 100644 index 4930b31815..0000000000 --- a/core/embed/bootloader/protob/types.pb.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Automatically generated nanopb header */ -/* Generated by nanopb-0.4.1 */ - -#ifndef PB_TYPES_PB_H_INCLUDED -#define PB_TYPES_PB_H_INCLUDED -#include - -#if PB_PROTO_HEADER_VERSION != 40 -#error Regenerate this file with the current version of nanopb generator. -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* Enum definitions */ -typedef enum _FailureType { - FailureType_Failure_UnexpectedMessage = 1, - FailureType_Failure_ActionCancelled = 4, - FailureType_Failure_DataError = 3, - FailureType_Failure_ProcessError = 9 -} FailureType; - -typedef enum _ButtonRequestType { - 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_Other -#define _ButtonRequestType_ARRAYSIZE ((ButtonRequestType)(ButtonRequestType_ButtonRequest_Other+1)) - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/core/embed/bootloader/protob/types.proto b/core/embed/bootloader/protob/types.proto deleted file mode 100644 index d44a47ab1a..0000000000 --- a/core/embed/bootloader/protob/types.proto +++ /dev/null @@ -1,20 +0,0 @@ -syntax = "proto2"; - -/** - * Type of failures returned by Failure message - * @used_in Failure - */ -enum FailureType { - Failure_UnexpectedMessage = 1; - Failure_ActionCancelled = 4; - Failure_DataError = 3; - Failure_ProcessError = 9; -} - -/** - * Type of button request - * @used_in ButtonRequest - */ -enum ButtonRequestType { - ButtonRequest_Other = 1; -} diff --git a/legacy/firmware/protob/Makefile b/legacy/firmware/protob/Makefile index 98a630b224..053328f8a6 100644 --- a/legacy/firmware/protob/Makefile +++ b/legacy/firmware/protob/Makefile @@ -18,7 +18,7 @@ PYTHON ?= python @printf " NANOPB $@\n" $(Q)nanopb_generator $< \ -L '#include "%s"' \ - -T \ + -T -D . \ -s "mangle_names:M_FLATTEN" @grep " CALLBACK, " $@ && echo "CALLBACK field found" && rm $@ && exit 1 || :