mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-17 21:22:10 +00:00
chore: make fields on FirmwareRequest required (fixes #1941)
[no changelog]
This commit is contained in:
parent
63c27bafd6
commit
7638694484
@ -21,8 +21,8 @@ message FirmwareErase {
|
||||
* @next FirmwareUpload
|
||||
*/
|
||||
message FirmwareRequest {
|
||||
optional uint32 offset = 1; // offset of requested firmware chunk
|
||||
optional uint32 length = 2; // length of requested firmware chunk
|
||||
required uint32 offset = 1; // offset of requested firmware chunk
|
||||
required uint32 length = 2; // length of requested firmware chunk
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -351,8 +351,8 @@ void process_msg_FirmwareErase(uint8_t iface_num, uint32_t msg_size,
|
||||
? IMAGE_INIT_CHUNK_SIZE
|
||||
: firmware_remaining;
|
||||
MSG_SEND_INIT(FirmwareRequest);
|
||||
MSG_SEND_ASSIGN_VALUE(offset, 0);
|
||||
MSG_SEND_ASSIGN_VALUE(length, chunk_requested);
|
||||
MSG_SEND_ASSIGN_REQUIRED_VALUE(offset, 0);
|
||||
MSG_SEND_ASSIGN_REQUIRED_VALUE(length, chunk_requested);
|
||||
MSG_SEND(FirmwareRequest);
|
||||
} else {
|
||||
// invalid firmware size
|
||||
@ -588,8 +588,8 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size,
|
||||
// request the rest of the first chunk
|
||||
MSG_SEND_INIT(FirmwareRequest);
|
||||
chunk_requested = IMAGE_CHUNK_SIZE - read_offset;
|
||||
MSG_SEND_ASSIGN_VALUE(offset, read_offset);
|
||||
MSG_SEND_ASSIGN_VALUE(length, chunk_requested);
|
||||
MSG_SEND_ASSIGN_REQUIRED_VALUE(offset, read_offset);
|
||||
MSG_SEND_ASSIGN_REQUIRED_VALUE(length, chunk_requested);
|
||||
MSG_SEND(FirmwareRequest);
|
||||
|
||||
firmware_remaining -= read_offset;
|
||||
@ -624,8 +624,8 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size,
|
||||
if (firmware_upload_chunk_retry > 0) {
|
||||
--firmware_upload_chunk_retry;
|
||||
MSG_SEND_INIT(FirmwareRequest);
|
||||
MSG_SEND_ASSIGN_VALUE(offset, firmware_block * IMAGE_CHUNK_SIZE);
|
||||
MSG_SEND_ASSIGN_VALUE(length, chunk_requested);
|
||||
MSG_SEND_ASSIGN_REQUIRED_VALUE(offset, firmware_block * IMAGE_CHUNK_SIZE);
|
||||
MSG_SEND_ASSIGN_REQUIRED_VALUE(length, chunk_requested);
|
||||
MSG_SEND(FirmwareRequest);
|
||||
return (int)firmware_remaining;
|
||||
}
|
||||
@ -658,8 +658,8 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size,
|
||||
? IMAGE_CHUNK_SIZE
|
||||
: firmware_remaining;
|
||||
MSG_SEND_INIT(FirmwareRequest);
|
||||
MSG_SEND_ASSIGN_VALUE(offset, firmware_block * IMAGE_CHUNK_SIZE);
|
||||
MSG_SEND_ASSIGN_VALUE(length, chunk_requested);
|
||||
MSG_SEND_ASSIGN_REQUIRED_VALUE(offset, firmware_block * IMAGE_CHUNK_SIZE);
|
||||
MSG_SEND_ASSIGN_REQUIRED_VALUE(length, chunk_requested);
|
||||
MSG_SEND(FirmwareRequest);
|
||||
} else {
|
||||
MSG_SEND_INIT(Success);
|
||||
|
@ -99,9 +99,7 @@ typedef struct _FirmwareErase {
|
||||
} FirmwareErase;
|
||||
|
||||
typedef struct _FirmwareRequest {
|
||||
bool has_offset;
|
||||
uint32_t offset;
|
||||
bool has_length;
|
||||
uint32_t length;
|
||||
} FirmwareRequest;
|
||||
|
||||
@ -151,7 +149,7 @@ extern "C" {
|
||||
#define ButtonRequest_init_default {false, _ButtonRequestType_MIN}
|
||||
#define ButtonAck_init_default {0}
|
||||
#define FirmwareErase_init_default {false, 0}
|
||||
#define FirmwareRequest_init_default {false, 0, false, 0}
|
||||
#define FirmwareRequest_init_default {0, 0}
|
||||
#define FirmwareUpload_init_default {{{NULL}, NULL}, false, {0, {0}}}
|
||||
#define Initialize_init_zero {0}
|
||||
#define GetFeatures_init_zero {0}
|
||||
@ -162,7 +160,7 @@ extern "C" {
|
||||
#define ButtonRequest_init_zero {false, _ButtonRequestType_MIN}
|
||||
#define ButtonAck_init_zero {0}
|
||||
#define FirmwareErase_init_zero {false, 0}
|
||||
#define FirmwareRequest_init_zero {false, 0, false, 0}
|
||||
#define FirmwareRequest_init_zero {0, 0}
|
||||
#define FirmwareUpload_init_zero {{{NULL}, NULL}, false, {0, {0}}}
|
||||
|
||||
/* Field tags (for use in manual encoding/decoding) */
|
||||
@ -256,8 +254,8 @@ X(a, STATIC, OPTIONAL, UINT32, length, 1)
|
||||
#define FirmwareErase_DEFAULT NULL
|
||||
|
||||
#define FirmwareRequest_FIELDLIST(X, a) \
|
||||
X(a, STATIC, OPTIONAL, UINT32, offset, 1) \
|
||||
X(a, STATIC, OPTIONAL, UINT32, length, 2)
|
||||
X(a, STATIC, REQUIRED, UINT32, offset, 1) \
|
||||
X(a, STATIC, REQUIRED, UINT32, length, 2)
|
||||
#define FirmwareRequest_CALLBACK NULL
|
||||
#define FirmwareRequest_DEFAULT NULL
|
||||
|
||||
|
@ -126,8 +126,8 @@ message FirmwareErase {
|
||||
* @next FirmwareUpload
|
||||
*/
|
||||
message FirmwareRequest {
|
||||
optional uint32 offset = 1; // offset of requested firmware chunk
|
||||
optional uint32 length = 2; // length of requested firmware chunk
|
||||
required uint32 offset = 1; // offset of requested firmware chunk
|
||||
required uint32 length = 2; // length of requested firmware chunk
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -345,8 +345,8 @@ void process_msg_FirmwareErase(uint8_t iface_num, uint32_t msg_size,
|
||||
? IMAGE_INIT_CHUNK_SIZE
|
||||
: firmware_remaining;
|
||||
MSG_SEND_INIT(FirmwareRequest);
|
||||
MSG_SEND_ASSIGN_VALUE(offset, 0);
|
||||
MSG_SEND_ASSIGN_VALUE(length, chunk_requested);
|
||||
MSG_SEND_ASSIGN_REQUIRED_VALUE(offset, 0);
|
||||
MSG_SEND_ASSIGN_REQUIRED_VALUE(length, chunk_requested);
|
||||
MSG_SEND(FirmwareRequest);
|
||||
} else {
|
||||
// invalid firmware size
|
||||
@ -564,8 +564,8 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size,
|
||||
// request the rest of the first chunk
|
||||
MSG_SEND_INIT(FirmwareRequest);
|
||||
chunk_requested = IMAGE_CHUNK_SIZE - read_offset;
|
||||
MSG_SEND_ASSIGN_VALUE(offset, read_offset);
|
||||
MSG_SEND_ASSIGN_VALUE(length, chunk_requested);
|
||||
MSG_SEND_ASSIGN_REQUIRED_VALUE(offset, read_offset);
|
||||
MSG_SEND_ASSIGN_REQUIRED_VALUE(length, chunk_requested);
|
||||
MSG_SEND(FirmwareRequest);
|
||||
|
||||
firmware_remaining -= read_offset;
|
||||
@ -599,8 +599,8 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size,
|
||||
if (firmware_upload_chunk_retry > 0) {
|
||||
--firmware_upload_chunk_retry;
|
||||
MSG_SEND_INIT(FirmwareRequest);
|
||||
MSG_SEND_ASSIGN_VALUE(offset, firmware_block * IMAGE_CHUNK_SIZE);
|
||||
MSG_SEND_ASSIGN_VALUE(length, chunk_requested);
|
||||
MSG_SEND_ASSIGN_REQUIRED_VALUE(offset, firmware_block * IMAGE_CHUNK_SIZE);
|
||||
MSG_SEND_ASSIGN_REQUIRED_VALUE(length, chunk_requested);
|
||||
MSG_SEND(FirmwareRequest);
|
||||
return (int)firmware_remaining;
|
||||
}
|
||||
@ -633,8 +633,8 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size,
|
||||
? IMAGE_CHUNK_SIZE
|
||||
: firmware_remaining;
|
||||
MSG_SEND_INIT(FirmwareRequest);
|
||||
MSG_SEND_ASSIGN_VALUE(offset, firmware_block * IMAGE_CHUNK_SIZE);
|
||||
MSG_SEND_ASSIGN_VALUE(length, chunk_requested);
|
||||
MSG_SEND_ASSIGN_REQUIRED_VALUE(offset, firmware_block * IMAGE_CHUNK_SIZE);
|
||||
MSG_SEND_ASSIGN_REQUIRED_VALUE(length, chunk_requested);
|
||||
MSG_SEND(FirmwareRequest);
|
||||
} else {
|
||||
MSG_SEND_INIT(Success);
|
||||
|
@ -97,8 +97,6 @@ def update(
|
||||
|
||||
# TREZORv2 method
|
||||
while isinstance(resp, messages.FirmwareRequest):
|
||||
assert resp.offset is not None
|
||||
assert resp.length is not None
|
||||
length = resp.length
|
||||
payload = data[resp.offset : resp.offset + length]
|
||||
digest = blake2s(payload).digest()
|
||||
|
@ -2057,15 +2057,15 @@ class FirmwareErase(protobuf.MessageType):
|
||||
class FirmwareRequest(protobuf.MessageType):
|
||||
MESSAGE_WIRE_TYPE = 8
|
||||
FIELDS = {
|
||||
1: protobuf.Field("offset", "uint32", repeated=False, required=False, default=None),
|
||||
2: protobuf.Field("length", "uint32", repeated=False, required=False, default=None),
|
||||
1: protobuf.Field("offset", "uint32", repeated=False, required=True),
|
||||
2: protobuf.Field("length", "uint32", repeated=False, required=True),
|
||||
}
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
offset: Optional["int"] = None,
|
||||
length: Optional["int"] = None,
|
||||
offset: "int",
|
||||
length: "int",
|
||||
) -> None:
|
||||
self.offset = offset
|
||||
self.length = length
|
||||
|
Loading…
Reference in New Issue
Block a user