From 2f7ed2aa0fec6647c1a1e4940d38ff816a51324c Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 26 Sep 2016 13:09:09 +0200 Subject: [PATCH] implement firmware_present flag in bootloader --- bootloader/bootloader.c | 52 ++++++++++++++++++++++------------------- bootloader/bootloader.h | 8 +++---- bootloader/usb.c | 29 ++++++++++++++++------- vendor/trezor-common | 2 +- 4 files changed, 54 insertions(+), 37 deletions(-) diff --git a/bootloader/bootloader.c b/bootloader/bootloader.c index decb267..10db8ff 100644 --- a/bootloader/bootloader.c +++ b/bootloader/bootloader.c @@ -89,22 +89,26 @@ void load_app(void) (*(void (**)())(FLASH_APP_START + 4))(); } +int firmware_present; + void bootloader_loop(void) { - static char serial[25]; - - fill_serialno_fixed(serial); - + oledClear(); oledDrawBitmap(0, 0, &bmp_logo64); - oledDrawString(52, 0, "TREZOR"); - - oledDrawString(52, 20, "Serial No."); - oledDrawString(52, 40, serial + 12); // second part of serial - serial[12] = 0; - oledDrawString(52, 30, serial); // first part of serial - - oledDrawStringRight(OLED_WIDTH - 1, OLED_HEIGHT - 8, "Loader " VERSTR(VERSION_MAJOR) "." VERSTR(VERSION_MINOR) "." VERSTR(VERSION_PATCH)); - + if (firmware_present) { + oledDrawString(52, 0, "TREZOR"); + static char serial[25]; + fill_serialno_fixed(serial); + oledDrawString(52, 20, "Serial No."); + oledDrawString(52, 40, serial + 12); // second part of serial + serial[12] = 0; + oledDrawString(52, 30, serial); // first part of serial + oledDrawStringRight(OLED_WIDTH - 1, OLED_HEIGHT - 8, "Loader " VERSTR(VERSION_MAJOR) "." VERSTR(VERSION_MINOR) "." VERSTR(VERSION_PATCH)); + } else { + oledDrawString(52, 10, "Welcome!"); + oledDrawString(52, 30, "Please visit"); + oledDrawString(52, 50, "trezor.io/start"); + } oledRefresh(); usbInit(); @@ -140,24 +144,24 @@ int main(void) memory_protect(); oledInit(); + firmware_present = check_firmware_sanity(); + // at least one button is unpressed uint16_t state = gpio_port_read(BTN_PORT); - if ((state & BTN_PIN_YES) == BTN_PIN_YES || (state & BTN_PIN_NO) == BTN_PIN_NO) { + int unpressed = ((state & BTN_PIN_YES) == BTN_PIN_YES || (state & BTN_PIN_NO) == BTN_PIN_NO); - if (check_firmware_sanity()) { + if (firmware_present && unpressed) { - 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); - } - - load_app(); + uint8_t hash[32]; + if (!signatures_ok(hash)) { + show_unofficial_warning(hash); } + load_app(); } bootloader_loop(); diff --git a/bootloader/bootloader.h b/bootloader/bootloader.h index 7046c62..687c3ff 100644 --- a/bootloader/bootloader.h +++ b/bootloader/bootloader.h @@ -21,15 +21,15 @@ #define __BOOTLOADER_H__ #define VERSION_MAJOR 1 -#define VERSION_MINOR 2 -#define VERSION_PATCH 8 +#define VERSION_MINOR 3 +#define VERSION_PATCH 0 #define STR(X) #X #define VERSTR(X) STR(X) #define VERSION_MAJOR_CHAR "\x01" -#define VERSION_MINOR_CHAR "\x02" -#define VERSION_PATCH_CHAR "\x08" +#define VERSION_MINOR_CHAR "\x03" +#define VERSION_PATCH_CHAR "\x00" #include "memory.h" diff --git a/bootloader/usb.c b/bootloader/usb.c index 3745b0c..ecdaa6b 100644 --- a/bootloader/usb.c +++ b/bootloader/usb.c @@ -202,21 +202,34 @@ static void send_msg_failure(usbd_device *dev) , 64) != 64) {} } +extern int firmware_present; + static void send_msg_features(usbd_device *dev) { - // send response: Features message (id 17), payload len 27 + // send response: Features message (id 17), payload len 30 // vendor = "bitcointrezor.com" // major_version = VERSION_MAJOR // minor_version = VERSION_MINOR // patch_version = VERSION_PATCH // bootloader_mode = True - while ( usbd_ep_write_packet(dev, ENDPOINT_ADDRESS_IN, - "?##" // header - "\x00\x11" // msg_id - "\x00\x00\x00\x1b" // payload_len - "\x0a\x11" "bitcointrezor.com\x10" VERSION_MAJOR_CHAR "\x18" VERSION_MINOR_CHAR " " VERSION_PATCH_CHAR "(\x01" // data - "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" - , 64) != 64) {} + // firmware_present = True/False + if (firmware_present) { + while ( usbd_ep_write_packet(dev, ENDPOINT_ADDRESS_IN, + "?##" // header + "\x00\x11" // msg_id + "\x00\x00\x00\x1e" // payload_len + "\x0a\x11" "bitcointrezor.com\x10" VERSION_MAJOR_CHAR "\x18" VERSION_MINOR_CHAR " " VERSION_PATCH_CHAR "(\x01" // data + "\x90\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + , 64) != 64) {} + } else { + while ( usbd_ep_write_packet(dev, ENDPOINT_ADDRESS_IN, + "?##" // header + "\x00\x11" // msg_id + "\x00\x00\x00\x1e" // payload_len + "\x0a\x11" "bitcointrezor.com\x10" VERSION_MAJOR_CHAR "\x18" VERSION_MINOR_CHAR " " VERSION_PATCH_CHAR "(\x01" // data + "\x90\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + , 64) != 64) {} + } } static void send_msg_buttonrequest_firmwarecheck(usbd_device *dev) diff --git a/vendor/trezor-common b/vendor/trezor-common index 4c2b12b..c2a0b25 160000 --- a/vendor/trezor-common +++ b/vendor/trezor-common @@ -1 +1 @@ -Subproject commit 4c2b12b0c51e293fe08f04554cdd55a081250653 +Subproject commit c2a0b255ff1ba174085ebe76c46f8e049f85d197