mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-04-26 12:09:02 +00:00
implement firmware_present flag in bootloader
This commit is contained in:
parent
cda9ae4b29
commit
2f7ed2aa0f
@ -89,22 +89,26 @@ void load_app(void)
|
|||||||
(*(void (**)())(FLASH_APP_START + 4))();
|
(*(void (**)())(FLASH_APP_START + 4))();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int firmware_present;
|
||||||
|
|
||||||
void bootloader_loop(void)
|
void bootloader_loop(void)
|
||||||
{
|
{
|
||||||
static char serial[25];
|
oledClear();
|
||||||
|
|
||||||
fill_serialno_fixed(serial);
|
|
||||||
|
|
||||||
oledDrawBitmap(0, 0, &bmp_logo64);
|
oledDrawBitmap(0, 0, &bmp_logo64);
|
||||||
|
if (firmware_present) {
|
||||||
oledDrawString(52, 0, "TREZOR");
|
oledDrawString(52, 0, "TREZOR");
|
||||||
|
static char serial[25];
|
||||||
|
fill_serialno_fixed(serial);
|
||||||
oledDrawString(52, 20, "Serial No.");
|
oledDrawString(52, 20, "Serial No.");
|
||||||
oledDrawString(52, 40, serial + 12); // second part of serial
|
oledDrawString(52, 40, serial + 12); // second part of serial
|
||||||
serial[12] = 0;
|
serial[12] = 0;
|
||||||
oledDrawString(52, 30, serial); // first part of serial
|
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));
|
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();
|
oledRefresh();
|
||||||
|
|
||||||
usbInit();
|
usbInit();
|
||||||
@ -140,11 +144,13 @@ int main(void)
|
|||||||
memory_protect();
|
memory_protect();
|
||||||
oledInit();
|
oledInit();
|
||||||
|
|
||||||
|
firmware_present = check_firmware_sanity();
|
||||||
|
|
||||||
// at least one button is unpressed
|
// at least one button is unpressed
|
||||||
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) {
|
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();
|
oledClear();
|
||||||
oledDrawBitmap(40, 0, &bmp_logo64_empty);
|
oledDrawBitmap(40, 0, &bmp_logo64_empty);
|
||||||
@ -158,8 +164,6 @@ int main(void)
|
|||||||
load_app();
|
load_app();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bootloader_loop();
|
bootloader_loop();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -21,15 +21,15 @@
|
|||||||
#define __BOOTLOADER_H__
|
#define __BOOTLOADER_H__
|
||||||
|
|
||||||
#define VERSION_MAJOR 1
|
#define VERSION_MAJOR 1
|
||||||
#define VERSION_MINOR 2
|
#define VERSION_MINOR 3
|
||||||
#define VERSION_PATCH 8
|
#define VERSION_PATCH 0
|
||||||
|
|
||||||
#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 "\x03"
|
||||||
#define VERSION_PATCH_CHAR "\x08"
|
#define VERSION_PATCH_CHAR "\x00"
|
||||||
|
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
|
@ -202,21 +202,34 @@ static void send_msg_failure(usbd_device *dev)
|
|||||||
, 64) != 64) {}
|
, 64) != 64) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int firmware_present;
|
||||||
|
|
||||||
static void send_msg_features(usbd_device *dev)
|
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"
|
// vendor = "bitcointrezor.com"
|
||||||
// major_version = VERSION_MAJOR
|
// major_version = VERSION_MAJOR
|
||||||
// minor_version = VERSION_MINOR
|
// minor_version = VERSION_MINOR
|
||||||
// patch_version = VERSION_PATCH
|
// patch_version = VERSION_PATCH
|
||||||
// bootloader_mode = True
|
// bootloader_mode = True
|
||||||
|
// firmware_present = True/False
|
||||||
|
if (firmware_present) {
|
||||||
while ( usbd_ep_write_packet(dev, ENDPOINT_ADDRESS_IN,
|
while ( usbd_ep_write_packet(dev, ENDPOINT_ADDRESS_IN,
|
||||||
"?##" // header
|
"?##" // header
|
||||||
"\x00\x11" // msg_id
|
"\x00\x11" // msg_id
|
||||||
"\x00\x00\x00\x1b" // payload_len
|
"\x00\x00\x00\x1e" // payload_len
|
||||||
"\x0a\x11" "bitcointrezor.com\x10" VERSION_MAJOR_CHAR "\x18" VERSION_MINOR_CHAR " " VERSION_PATCH_CHAR "(\x01" // data
|
"\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"
|
"\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) {}
|
, 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)
|
static void send_msg_buttonrequest_firmwarecheck(usbd_device *dev)
|
||||||
|
2
vendor/trezor-common
vendored
2
vendor/trezor-common
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 4c2b12b0c51e293fe08f04554cdd55a081250653
|
Subproject commit c2a0b255ff1ba174085ebe76c46f8e049f85d197
|
Loading…
Reference in New Issue
Block a user