1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-14 03:30:02 +00:00

implement firmware_present flag in bootloader

This commit is contained in:
Pavol Rusnak 2016-09-26 13:09:09 +02:00
parent cda9ae4b29
commit 2f7ed2aa0f
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
4 changed files with 54 additions and 37 deletions

View File

@ -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();

View File

@ -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"

View File

@ -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)

@ -1 +1 @@
Subproject commit 4c2b12b0c51e293fe08f04554cdd55a081250653
Subproject commit c2a0b255ff1ba174085ebe76c46f8e049f85d197