From 259eeae26ea7ae62d91a3bbb86b1f27326257c87 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Sun, 25 Sep 2016 15:49:12 +0200 Subject: [PATCH] don't halt on broken firmware but stay in bootloader mode --- bootloader/bootloader.c | 33 +++++++++++++++------------------ bootloader/bootloader.h | 4 ++-- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/bootloader/bootloader.c b/bootloader/bootloader.c index 30abc4bc54..53d1de996c 100644 --- a/bootloader/bootloader.c +++ b/bootloader/bootloader.c @@ -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(); diff --git a/bootloader/bootloader.h b/bootloader/bootloader.h index abe80786ff..7046c62bca 100644 --- a/bootloader/bootloader.h +++ b/bootloader/bootloader.h @@ -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"