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

don't halt on broken firmware but stay in bootloader mode

This commit is contained in:
Pavol Rusnak 2016-09-25 15:49:12 +02:00
parent e0e190b3dc
commit 259eeae26e
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 17 additions and 20 deletions

View File

@ -111,22 +111,18 @@ void bootloader_loop(void)
usbLoop();
}
void check_firmware_sanity(void)
int check_firmware_sanity(void)
{
int broken = 0;
if (memcmp((void *)FLASH_META_MAGIC, "TRZR", 4)) { // magic does not match
broken++;
return 0;
}
if (*((uint32_t *)FLASH_META_CODELEN) < 4096) { // firmware reports smaller size than 4kB
broken++;
return 0;
}
if (*((uint32_t *)FLASH_META_CODELEN) > FLASH_TOTAL_SIZE - (FLASH_APP_START - FLASH_ORIGIN)) { // firmware reports bigger size than flash size
broken++;
}
if (broken) {
layoutDialog(&bmp_icon_error, NULL, NULL, NULL, "Firmware appears", "to be broken.", NULL, "Unplug your TREZOR", "and see our support", "page at mytrezor.com");
system_halt();
return 0;
}
return 1;
}
uint32_t __stack_chk_guard;
@ -148,19 +144,20 @@ int main(void)
uint16_t state = gpio_port_read(BTN_PORT);
if ((state & BTN_PIN_YES) == BTN_PIN_YES || (state & BTN_PIN_NO) == BTN_PIN_NO) {
check_firmware_sanity();
if (check_firmware_sanity()) {
oledClear();
oledDrawBitmap(40, 0, &bmp_logo64_empty);
oledRefresh();
oledClear();
oledDrawBitmap(40, 0, &bmp_logo64_empty);
oledRefresh();
uint8_t hash[32];
if (!signatures_ok(hash)) {
show_unofficial_warning(hash);
uint8_t hash[32];
if (!signatures_ok(hash)) {
show_unofficial_warning(hash);
}
load_app();
}
load_app();
}
bootloader_loop();

View File

@ -22,14 +22,14 @@
#define VERSION_MAJOR 1
#define VERSION_MINOR 2
#define VERSION_PATCH 7
#define VERSION_PATCH 8
#define STR(X) #X
#define VERSTR(X) STR(X)
#define VERSION_MAJOR_CHAR "\x01"
#define VERSION_MINOR_CHAR "\x02"
#define VERSION_PATCH_CHAR "\x07"
#define VERSION_PATCH_CHAR "\x08"
#include "memory.h"