mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-26 16:18:22 +00:00
bootloader: don't restore storage from unofficial firmware
This commit is contained in:
parent
77ff5a1c55
commit
eb0574bda7
@ -42,6 +42,7 @@
|
|||||||
#define ENDPOINT_ADDRESS_OUT (0x01)
|
#define ENDPOINT_ADDRESS_OUT (0x01)
|
||||||
|
|
||||||
static bool brand_new_firmware;
|
static bool brand_new_firmware;
|
||||||
|
static bool old_was_unsigned;
|
||||||
|
|
||||||
static const struct usb_device_descriptor dev_descr = {
|
static const struct usb_device_descriptor dev_descr = {
|
||||||
.bLength = USB_DT_DEVICE_SIZE,
|
.bLength = USB_DT_DEVICE_SIZE,
|
||||||
@ -437,8 +438,14 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep)
|
|||||||
} while (!button.YesUp && !button.NoUp);
|
} while (!button.YesUp && !button.NoUp);
|
||||||
}
|
}
|
||||||
if (brand_new_firmware || button.YesUp) {
|
if (brand_new_firmware || button.YesUp) {
|
||||||
// backup metadata
|
// check whether current firmware is signed
|
||||||
backup_metadata(meta_backup);
|
if (signatures_ok(NULL)) {
|
||||||
|
old_was_unsigned = false;
|
||||||
|
// backup metadata
|
||||||
|
backup_metadata(meta_backup);
|
||||||
|
} else {
|
||||||
|
old_was_unsigned = true;
|
||||||
|
}
|
||||||
flash_wait_for_last_operation();
|
flash_wait_for_last_operation();
|
||||||
flash_clear_status_flags();
|
flash_clear_status_flags();
|
||||||
flash_unlock();
|
flash_unlock();
|
||||||
@ -587,8 +594,11 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep)
|
|||||||
|
|
||||||
layoutProgress("INSTALLING ... Please wait", 1000);
|
layoutProgress("INSTALLING ... Please wait", 1000);
|
||||||
uint8_t flags = *((uint8_t *)FLASH_META_FLAGS);
|
uint8_t flags = *((uint8_t *)FLASH_META_FLAGS);
|
||||||
// wipe storage if signatures are not ok or the firmware flag isn't set.
|
// wipe storage if:
|
||||||
if ((flags & 0x01) == 0 || !signatures_ok(NULL)) {
|
// 1) old firmware was unsigned
|
||||||
|
// 2) firmware restore flag isn't set
|
||||||
|
// 3) signatures are not ok
|
||||||
|
if (old_was_unsigned || (flags & 0x01) == 0 || !signatures_ok(NULL)) {
|
||||||
memset(meta_backup, 0, sizeof(meta_backup));
|
memset(meta_backup, 0, sizeof(meta_backup));
|
||||||
}
|
}
|
||||||
// copy new firmware header
|
// copy new firmware header
|
||||||
|
Loading…
Reference in New Issue
Block a user