1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

core/bootloader: update protobuf definitions

This commit is contained in:
Pavol Rusnak 2020-07-20 15:31:21 +02:00
parent fdcb64ac24
commit 8dacad0782
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
11 changed files with 105 additions and 167 deletions

View File

@ -85,7 +85,6 @@ SOURCE_BOOTLOADER = [
'embed/bootloader/main.c', 'embed/bootloader/main.c',
'embed/bootloader/messages.c', 'embed/bootloader/messages.c',
'embed/bootloader/protob/messages.pb.c', 'embed/bootloader/protob/messages.pb.c',
'embed/bootloader/protob/types.pb.c',
] ]
SOURCE_TREZORHAL = [ SOURCE_TREZORHAL = [

View File

@ -1,7 +1,7 @@
all: messages.pb.c types.pb.c all: messages.pb.c
%.pb.c: %.pb %.options %.pb.c: %.pb %.options
nanopb_generator $< -T nanopb_generator $< -T -D . -s "mangle_names:M_FLATTEN"
%.pb: %.proto %.pb: %.proto
protoc -I/usr/include -I. $< -o $@ protoc -I/usr/include -I. $< -o $@

View File

@ -1,16 +1,16 @@
Features.vendor max_size:33 Features.vendor max_size:33
Features.device_id max_size:25 Features.device_id max_size:25
Features.language max_size:17 Features.language max_size:17
Features.label max_size:33 Features.label max_size:33
Features.revision max_size:20 Features.revision max_size:20
Features.model max_size:17 Features.model max_size:17
Features.fw_vendor max_size:256 Features.fw_vendor max_size:256
Features.fw_vendor_keys max_size:32 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

View File

@ -41,3 +41,5 @@ PB_BIND(FirmwareUpload, FirmwareUpload, AUTO)

View File

@ -4,7 +4,6 @@
#ifndef PB_MESSAGES_PB_H_INCLUDED #ifndef PB_MESSAGES_PB_H_INCLUDED
#define PB_MESSAGES_PB_H_INCLUDED #define PB_MESSAGES_PB_H_INCLUDED
#include <pb.h> #include <pb.h>
#include "types.pb.h"
#if PB_PROTO_HEADER_VERSION != 40 #if PB_PROTO_HEADER_VERSION != 40
#error Regenerate this file with the current version of nanopb generator. #error Regenerate this file with the current version of nanopb generator.
@ -29,6 +28,17 @@ typedef enum _MessageType {
MessageType_MessageType_GetFeatures = 55 MessageType_MessageType_GetFeatures = 55
} MessageType; } 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 */ /* Struct definitions */
typedef struct _ButtonAck { typedef struct _ButtonAck {
char dummy_field; char dummy_field;
@ -115,12 +125,6 @@ typedef struct _FirmwareUpload {
typedef struct _Ping { typedef struct _Ping {
bool has_message; bool has_message;
char message[256]; 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; } Ping;
typedef struct _Success { typedef struct _Success {
@ -134,12 +138,20 @@ typedef struct _Success {
#define _MessageType_MAX MessageType_MessageType_GetFeatures #define _MessageType_MAX MessageType_MessageType_GetFeatures
#define _MessageType_ARRAYSIZE ((MessageType)(MessageType_MessageType_GetFeatures+1)) #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 */ /* Initializer values for message structs */
#define Initialize_init_default {0} #define Initialize_init_default {0}
#define GetFeatures_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 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 Success_init_default {false, ""}
#define Failure_init_default {false, _FailureType_MIN, false, ""} #define Failure_init_default {false, _FailureType_MIN, false, ""}
#define ButtonRequest_init_default {false, _ButtonRequestType_MIN} #define ButtonRequest_init_default {false, _ButtonRequestType_MIN}
@ -150,7 +162,7 @@ typedef struct _Success {
#define Initialize_init_zero {0} #define Initialize_init_zero {0}
#define GetFeatures_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 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 Success_init_zero {false, ""}
#define Failure_init_zero {false, _FailureType_MIN, false, ""} #define Failure_init_zero {false, _FailureType_MIN, false, ""}
#define ButtonRequest_init_zero {false, _ButtonRequestType_MIN} #define ButtonRequest_init_zero {false, _ButtonRequestType_MIN}
@ -186,9 +198,6 @@ typedef struct _Success {
#define FirmwareUpload_payload_tag 1 #define FirmwareUpload_payload_tag 1
#define FirmwareUpload_hash_tag 2 #define FirmwareUpload_hash_tag 2
#define Ping_message_tag 1 #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 #define Success_message_tag 1
/* Struct field encoding specification for nanopb */ /* Struct field encoding specification for nanopb */
@ -224,10 +233,7 @@ X(a, STATIC, OPTIONAL, BYTES, fw_vendor_keys, 26)
#define Features_DEFAULT NULL #define Features_DEFAULT NULL
#define Ping_FIELDLIST(X, a) \ #define Ping_FIELDLIST(X, a) \
X(a, STATIC, OPTIONAL, STRING, message, 1) \ 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_CALLBACK NULL
#define Ping_DEFAULT NULL #define Ping_DEFAULT NULL
@ -237,13 +243,13 @@ X(a, STATIC, OPTIONAL, STRING, message, 1)
#define Success_DEFAULT NULL #define Success_DEFAULT NULL
#define Failure_FIELDLIST(X, a) \ #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) X(a, STATIC, OPTIONAL, STRING, message, 2)
#define Failure_CALLBACK NULL #define Failure_CALLBACK NULL
#define Failure_DEFAULT NULL #define Failure_DEFAULT NULL
#define ButtonRequest_FIELDLIST(X, a) \ #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_CALLBACK NULL
#define ButtonRequest_DEFAULT NULL #define ButtonRequest_DEFAULT NULL
@ -298,10 +304,10 @@ extern const pb_msgdesc_t FirmwareUpload_msg;
#define Initialize_size 0 #define Initialize_size 0
#define GetFeatures_size 0 #define GetFeatures_size 0
#define Features_size 493 #define Features_size 493
#define Ping_size 264 #define Ping_size 258
#define Success_size 258 #define Success_size 258
#define Failure_size 269 #define Failure_size 260
#define ButtonRequest_size 11 #define ButtonRequest_size 2
#define ButtonAck_size 0 #define ButtonAck_size 0
#define FirmwareErase_size 6 #define FirmwareErase_size 6
#define FirmwareRequest_size 12 #define FirmwareRequest_size 12

View File

@ -1,26 +1,26 @@
syntax = "proto2"; syntax = "proto2";
import "types.proto";
/** /**
* Mapping between Trezor wire identifier (uint) and a protobuf message * Mapping between Trezor wire identifier (uint) and a protobuf message
*/ */
enum MessageType { enum MessageType {
MessageType_Initialize = 0; MessageType_Initialize = 0;
MessageType_Ping = 1; MessageType_Ping = 1;
MessageType_Success = 2; MessageType_Success = 2;
MessageType_Failure = 3; MessageType_Failure = 3;
MessageType_FirmwareErase = 6; MessageType_FirmwareErase = 6;
MessageType_FirmwareUpload = 7; MessageType_FirmwareUpload = 7;
MessageType_FirmwareRequest = 8; MessageType_FirmwareRequest = 8;
MessageType_Features = 17; MessageType_Features = 17;
MessageType_ButtonRequest = 26; MessageType_ButtonRequest = 26;
MessageType_ButtonAck = 27; MessageType_ButtonAck = 27;
MessageType_GetFeatures = 55; MessageType_GetFeatures = 55;
} }
/** /**
* Request: Reset device to default state and ask for device details * Request: Reset device to default state and ask for device details
* @start
* @next Features * @next Features
*/ */
message Initialize { message Initialize {
@ -28,6 +28,7 @@ message Initialize {
/** /**
* Request: Ask for device details (no device reset) * Request: Ask for device details (no device reset)
* @start
* @next Features * @next Features
*/ */
message GetFeatures { message GetFeatures {
@ -35,87 +36,89 @@ message GetFeatures {
/** /**
* Response: Reports various information about the device * Response: Reports various information about the device
* @prev Initialize * @end
* @prev GetFeatures
*/ */
message Features { message Features {
optional string vendor = 1; // name of the manufacturer, e.g. "trezor.io" 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 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 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 uint32 patch_version = 4; // patch version of the firmware/bootloader, e.g. 0
optional bool bootloader_mode = 5; // is device in bootloader mode? optional bool bootloader_mode = 5; // is device in bootloader mode?
optional string device_id = 6; // device's unique identifier optional string device_id = 6; // device's unique identifier
// optional bool pin_protection = 7; // is device protected by PIN? optional string language = 9; // device language
// optional bool passphrase_protection = 8; // is node/mnemonic encrypted using passphrase? optional string label = 10; // device description label
optional string language = 9; // device language optional bool initialized = 12; // does device contain seed?
optional string label = 10; // device description label optional bytes revision = 13; // SCM revision of firmware
optional bool initialized = 12; // does device contain seed? optional bool firmware_present = 18; // is valid firmware loaded?
optional bytes revision = 13; // SCM revision of firmware optional string model = 21; // device hardware model
// optional bytes bootloader_hash = 14; // hash of the bootloader optional uint32 fw_major = 22; // reported firmware version if in bootloader mode
// optional bool imported = 15; // was storage imported from an external source? optional uint32 fw_minor = 23; // reported firmware version if in bootloader mode
// optional bool pin_cached = 16; // is PIN already cached in session? optional uint32 fw_patch = 24; // reported firmware version if in bootloader mode
// optional bool passphrase_cached = 17; // is passphrase already cached in session? optional string fw_vendor = 25; // reported firmware vendor if in bootloader mode
optional bool firmware_present = 18; // is valid firmware loaded? optional bytes fw_vendor_keys = 26; // reported firmware vendor keys (their hash)
// 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)
} }
/** /**
* Request: Test if the device is alive, device sends back the message in Success response * Request: Test if the device is alive, device sends back the message in Success response
* @start
* @next Success * @next Success
*/ */
message Ping { message Ping {
optional string message = 1; // message to send back in Success message 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
} }
/** /**
* Response: Success of the previous request * Response: Success of the previous request
* @end
*/ */
message Success { 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 * Response: Failure of the previous request
* @end
*/ */
message Failure { message Failure {
optional FailureType code = 1; // computer-readable definition 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 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. * Response: Device is waiting for HW button press.
* @auxstart
* @next ButtonAck * @next ButtonAck
* @next Cancel
*/ */
message ButtonRequest { 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 * Request: Computer agrees to wait for HW button press
* @prev ButtonRequest * @auxend
*/ */
message ButtonAck { message ButtonAck {
} }
/** /**
* Request: Ask device to erase its firmware (so it can be replaced via FirmwareUpload) * Request: Ask device to erase its firmware (so it can be replaced via FirmwareUpload)
* @next Success * @start
* @next FirmwareRequest * @next FirmwareRequest
* @next Failure
*/ */
message FirmwareErase { 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 * @next FirmwareUpload
*/ */
message FirmwareRequest { message FirmwareRequest {
optional uint32 offset = 1; // offset of requested firmware chunk optional uint32 offset = 1; // offset of requested firmware chunk
optional uint32 length = 2; // length of requested firmware chunk optional uint32 length = 2; // length of requested firmware chunk
} }
/** /**
* Request: Send firmware in binary form to the device * Request: Send firmware in binary form to the device
* @next FirmwareRequest
* @next Success * @next Success
* @next Failure * @next Failure
*/ */
message FirmwareUpload { message FirmwareUpload {
required bytes payload = 1; // firmware to be loaded into device required bytes payload = 1; // firmware to be loaded into device
optional bytes hash = 2; // hash of the payload optional bytes hash = 2; // hash of the payload
} }

View File

@ -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

View File

@ -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 <pb.h>
#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

View File

@ -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;
}

View File

@ -18,7 +18,7 @@ PYTHON ?= python
@printf " NANOPB $@\n" @printf " NANOPB $@\n"
$(Q)nanopb_generator $< \ $(Q)nanopb_generator $< \
-L '#include "%s"' \ -L '#include "%s"' \
-T \ -T -D . \
-s "mangle_names:M_FLATTEN" -s "mangle_names:M_FLATTEN"
@grep " CALLBACK, " $@ && echo "CALLBACK field found" && rm $@ && exit 1 || : @grep " CALLBACK, " $@ && echo "CALLBACK field found" && rm $@ && exit 1 || :