mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-08-02 03:48:58 +00:00
legacy+core: unify error codes in bootloaders (#1347)
This commit is contained in:
parent
e871a1c4ae
commit
b9c0b3969b
@ -352,7 +352,7 @@ void process_msg_FirmwareErase(uint8_t iface_num, uint32_t msg_size,
|
|||||||
} else {
|
} else {
|
||||||
// invalid firmware size
|
// invalid firmware size
|
||||||
MSG_SEND_INIT(Failure);
|
MSG_SEND_INIT(Failure);
|
||||||
MSG_SEND_ASSIGN_VALUE(code, FailureType_Failure_DataError);
|
MSG_SEND_ASSIGN_VALUE(code, FailureType_Failure_ProcessError);
|
||||||
MSG_SEND_ASSIGN_STRING(message, "Wrong firmware size");
|
MSG_SEND_ASSIGN_STRING(message, "Wrong firmware size");
|
||||||
MSG_SEND(Failure);
|
MSG_SEND(Failure);
|
||||||
}
|
}
|
||||||
@ -468,7 +468,7 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size,
|
|||||||
|
|
||||||
if (sectrue != r || chunk_size != (chunk_requested + read_offset)) {
|
if (sectrue != r || chunk_size != (chunk_requested + read_offset)) {
|
||||||
MSG_SEND_INIT(Failure);
|
MSG_SEND_INIT(Failure);
|
||||||
MSG_SEND_ASSIGN_VALUE(code, FailureType_Failure_DataError);
|
MSG_SEND_ASSIGN_VALUE(code, FailureType_Failure_ProcessError);
|
||||||
MSG_SEND_ASSIGN_STRING(message, "Invalid chunk size");
|
MSG_SEND_ASSIGN_STRING(message, "Invalid chunk size");
|
||||||
MSG_SEND(Failure);
|
MSG_SEND(Failure);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -352,7 +352,7 @@ void process_msg_FirmwareErase(uint8_t iface_num, uint32_t msg_size,
|
|||||||
} else {
|
} else {
|
||||||
// invalid firmware size
|
// invalid firmware size
|
||||||
MSG_SEND_INIT(Failure);
|
MSG_SEND_INIT(Failure);
|
||||||
MSG_SEND_ASSIGN_VALUE(code, FailureType_Failure_DataError);
|
MSG_SEND_ASSIGN_VALUE(code, FailureType_Failure_ProcessError);
|
||||||
MSG_SEND_ASSIGN_STRING(message, "Wrong firmware size");
|
MSG_SEND_ASSIGN_STRING(message, "Wrong firmware size");
|
||||||
MSG_SEND(Failure);
|
MSG_SEND(Failure);
|
||||||
}
|
}
|
||||||
@ -468,7 +468,7 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size,
|
|||||||
|
|
||||||
if (sectrue != r || chunk_size != (chunk_requested + read_offset)) {
|
if (sectrue != r || chunk_size != (chunk_requested + read_offset)) {
|
||||||
MSG_SEND_INIT(Failure);
|
MSG_SEND_INIT(Failure);
|
||||||
MSG_SEND_ASSIGN_VALUE(code, FailureType_Failure_DataError);
|
MSG_SEND_ASSIGN_VALUE(code, FailureType_Failure_ProcessError);
|
||||||
MSG_SEND_ASSIGN_STRING(message, "Invalid chunk size");
|
MSG_SEND_ASSIGN_STRING(message, "Invalid chunk size");
|
||||||
MSG_SEND(Failure);
|
MSG_SEND(Failure);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -207,10 +207,14 @@ static void rx_callback(usbd_device *dev, uint8_t ep) {
|
|||||||
} else {
|
} else {
|
||||||
flash_state = STATE_END;
|
flash_state = STATE_END;
|
||||||
show_unplug("Device wipe", "aborted.");
|
show_unplug("Device wipe", "aborted.");
|
||||||
send_msg_failure(dev);
|
send_msg_failure(dev, 4); // Failure_ActionCancelled
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (msg_id != 0x0006) {
|
||||||
|
send_msg_failure(dev, 1); // Failure_UnexpectedMessage
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_state == STATE_OPEN) {
|
if (flash_state == STATE_OPEN) {
|
||||||
@ -240,19 +244,20 @@ static void rx_callback(usbd_device *dev, uint8_t ep) {
|
|||||||
send_msg_success(dev);
|
send_msg_success(dev);
|
||||||
flash_state = STATE_FLASHSTART;
|
flash_state = STATE_FLASHSTART;
|
||||||
} else {
|
} else {
|
||||||
send_msg_failure(dev);
|
send_msg_failure(dev, 4); // Failure_ActionCancelled
|
||||||
flash_state = STATE_END;
|
flash_state = STATE_END;
|
||||||
show_unplug("Firmware installation", "aborted.");
|
show_unplug("Firmware installation", "aborted.");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
send_msg_failure(dev, 1); // Failure_UnexpectedMessage
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_state == STATE_FLASHSTART) {
|
if (flash_state == STATE_FLASHSTART) {
|
||||||
if (msg_id == 0x0007) { // FirmwareUpload message (id 7)
|
if (msg_id == 0x0007) { // FirmwareUpload message (id 7)
|
||||||
if (buf[9] != 0x0a) { // invalid contents
|
if (buf[9] != 0x0a) { // invalid contents
|
||||||
send_msg_failure(dev);
|
send_msg_failure(dev, 9); // Failure_ProcessError
|
||||||
flash_state = STATE_END;
|
flash_state = STATE_END;
|
||||||
show_halt("Error installing", "firmware.");
|
show_halt("Error installing", "firmware.");
|
||||||
return;
|
return;
|
||||||
@ -260,27 +265,27 @@ static void rx_callback(usbd_device *dev, uint8_t ep) {
|
|||||||
// read payload length
|
// read payload length
|
||||||
const uint8_t *p = buf + 10;
|
const uint8_t *p = buf + 10;
|
||||||
if (readprotobufint(&p, &flash_len) != sectrue) { // integer too large
|
if (readprotobufint(&p, &flash_len) != sectrue) { // integer too large
|
||||||
send_msg_failure(dev);
|
send_msg_failure(dev, 9); // Failure_ProcessError
|
||||||
flash_state = STATE_END;
|
flash_state = STATE_END;
|
||||||
show_halt("Firmware is", "too big.");
|
show_halt("Firmware is", "too big.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (flash_len <= FLASH_FWHEADER_LEN) { // firmware is too small
|
if (flash_len <= FLASH_FWHEADER_LEN) { // firmware is too small
|
||||||
send_msg_failure(dev);
|
send_msg_failure(dev, 9); // Failure_ProcessError
|
||||||
flash_state = STATE_END;
|
flash_state = STATE_END;
|
||||||
show_halt("Firmware is", "too small.");
|
show_halt("Firmware is", "too small.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (flash_len >
|
if (flash_len >
|
||||||
FLASH_FWHEADER_LEN + FLASH_APP_LEN) { // firmware is too big
|
FLASH_FWHEADER_LEN + FLASH_APP_LEN) { // firmware is too big
|
||||||
send_msg_failure(dev);
|
send_msg_failure(dev, 9); // Failure_ProcessError
|
||||||
flash_state = STATE_END;
|
flash_state = STATE_END;
|
||||||
show_halt("Firmware is", "too big.");
|
show_halt("Firmware is", "too big.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// check firmware magic
|
// check firmware magic
|
||||||
if (memcmp(p, &FIRMWARE_MAGIC_NEW, 4) != 0) {
|
if (memcmp(p, &FIRMWARE_MAGIC_NEW, 4) != 0) {
|
||||||
send_msg_failure(dev);
|
send_msg_failure(dev, 9); // Failure_ProcessError
|
||||||
flash_state = STATE_END;
|
flash_state = STATE_END;
|
||||||
show_halt("Wrong firmware", "header.");
|
show_halt("Wrong firmware", "header.");
|
||||||
return;
|
return;
|
||||||
@ -304,12 +309,13 @@ static void rx_callback(usbd_device *dev, uint8_t ep) {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
send_msg_failure(dev, 1); // Failure_UnexpectedMessage
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_state == STATE_FLASHING) {
|
if (flash_state == STATE_FLASHING) {
|
||||||
if (buf[0] != '?') { // invalid contents
|
if (buf[0] != '?') { // invalid contents
|
||||||
send_msg_failure(dev);
|
send_msg_failure(dev, 9); // Failure_ProcessError
|
||||||
flash_state = STATE_END;
|
flash_state = STATE_END;
|
||||||
show_halt("Error installing", "firmware.");
|
show_halt("Error installing", "firmware.");
|
||||||
return;
|
return;
|
||||||
@ -394,7 +400,7 @@ static void rx_callback(usbd_device *dev, uint8_t ep) {
|
|||||||
"\x75\x12\x5e\x5c\xa2\xcd\x52\x7f\x35\x82\xec\x87\xff\xd9\x40"
|
"\x75\x12\x5e\x5c\xa2\xcd\x52\x7f\x35\x82\xec\x87\xff\xd9\x40"
|
||||||
"\x76\xbc",
|
"\x76\xbc",
|
||||||
32) != 0) {
|
32) != 0) {
|
||||||
send_msg_failure(dev);
|
send_msg_failure(dev, 9); // Failure_ProcessError
|
||||||
show_halt("Error installing", "firmware.");
|
show_halt("Error installing", "firmware.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -432,7 +438,7 @@ static void rx_callback(usbd_device *dev, uint8_t ep) {
|
|||||||
layoutDialog(&bmp_icon_warning, NULL, NULL, NULL, "Firmware installation",
|
layoutDialog(&bmp_icon_warning, NULL, NULL, NULL, "Firmware installation",
|
||||||
"aborted.", NULL, "You need to repeat", "the procedure with",
|
"aborted.", NULL, "You need to repeat", "the procedure with",
|
||||||
"the correct firmware.");
|
"the correct firmware.");
|
||||||
send_msg_failure(dev);
|
send_msg_failure(dev, 9); // Failure_ProcessError
|
||||||
shutdown();
|
shutdown();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -14,11 +14,10 @@ static void send_msg_success(usbd_device *dev) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_msg_failure(usbd_device *dev) {
|
static void send_msg_failure(usbd_device *dev, uint8_t code) {
|
||||||
uint8_t response[64];
|
uint8_t response[64];
|
||||||
memzero(response, sizeof(response));
|
memzero(response, sizeof(response));
|
||||||
// response: Failure message (id 3), payload len 2
|
// response: Failure message (id 3), payload len 2
|
||||||
// - code = 99 (Failure_FirmwareError)
|
|
||||||
memcpy(response,
|
memcpy(response,
|
||||||
// header
|
// header
|
||||||
"?##"
|
"?##"
|
||||||
@ -26,10 +25,11 @@ static void send_msg_failure(usbd_device *dev) {
|
|||||||
"\x00\x03"
|
"\x00\x03"
|
||||||
// msg_size
|
// msg_size
|
||||||
"\x00\x00\x00\x02"
|
"\x00\x00\x00\x02"
|
||||||
// data
|
// code field id
|
||||||
"\x08"
|
"\x08",
|
||||||
"\x63",
|
10);
|
||||||
11);
|
// assign code value
|
||||||
|
response[10] = code;
|
||||||
while (usbd_ep_write_packet(dev, ENDPOINT_ADDRESS_IN, response, 64) != 64) {
|
while (usbd_ep_write_packet(dev, ENDPOINT_ADDRESS_IN, response, 64) != 64) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user