1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 14:58:09 +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(); 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 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 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 if (*((uint32_t *)FLASH_META_CODELEN) > FLASH_TOTAL_SIZE - (FLASH_APP_START - FLASH_ORIGIN)) { // firmware reports bigger size than flash size
broken++; return 0;
}
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 1;
} }
uint32_t __stack_chk_guard; uint32_t __stack_chk_guard;
@ -148,7 +144,7 @@ int main(void)
uint16_t state = gpio_port_read(BTN_PORT); uint16_t state = gpio_port_read(BTN_PORT);
if ((state & BTN_PIN_YES) == BTN_PIN_YES || (state & BTN_PIN_NO) == BTN_PIN_NO) { if ((state & BTN_PIN_YES) == BTN_PIN_YES || (state & BTN_PIN_NO) == BTN_PIN_NO) {
check_firmware_sanity(); if (check_firmware_sanity()) {
oledClear(); oledClear();
oledDrawBitmap(40, 0, &bmp_logo64_empty); oledDrawBitmap(40, 0, &bmp_logo64_empty);
@ -160,6 +156,7 @@ int main(void)
} }
load_app(); load_app();
}
} }

View File

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