mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-02 19:01:04 +00:00
boardloader: small changes to program flow and display output
This commit is contained in:
parent
4831287357
commit
bdae87ddde
@ -44,32 +44,28 @@ bool copy_sdcard(void)
|
|||||||
{
|
{
|
||||||
display_backlight(255);
|
display_backlight(255);
|
||||||
|
|
||||||
display_printf("copying bootloader from SD card\n");
|
display_printf("TREZOR Boardloader\n");
|
||||||
display_printf("in 5 seconds ...\n\n");
|
display_printf("==================\n\n");
|
||||||
|
|
||||||
|
display_printf("bootloader found on the SD card\n\n");
|
||||||
|
display_printf("applying bootloader in 10 seconds\n\n");
|
||||||
display_printf("unplug now if you want to abort\n\n");
|
display_printf("unplug now if you want to abort\n\n");
|
||||||
|
|
||||||
display_printf("5 ");
|
for (int i = 10; i >= 0; i--) {
|
||||||
|
display_printf("%d ", i);
|
||||||
hal_delay(1000);
|
hal_delay(1000);
|
||||||
display_printf("4 ");
|
}
|
||||||
hal_delay(1000);
|
|
||||||
display_printf("3 ");
|
|
||||||
hal_delay(1000);
|
|
||||||
display_printf("2 ");
|
|
||||||
hal_delay(1000);
|
|
||||||
display_printf("1 ");
|
|
||||||
hal_delay(1000);
|
|
||||||
display_printf("0!\n\n");
|
|
||||||
|
|
||||||
display_printf("erasing flash ");
|
display_printf("\n\nerasing flash:\n");
|
||||||
|
|
||||||
// erase flash (except boardloader)
|
// erase flash (except boardloader)
|
||||||
if (!flash_erase_sectors(FLASH_SECTOR_BOARDLOADER_END + 1, FLASH_SECTOR_FIRMWARE_END, progress_callback)) {
|
if (!flash_erase_sectors(FLASH_SECTOR_BOARDLOADER_END + 1, FLASH_SECTOR_FIRMWARE_END, progress_callback)) {
|
||||||
display_printf(" failed\n");
|
display_printf(" failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
display_printf(" done\n");
|
display_printf(" done\n\n");
|
||||||
|
|
||||||
display_printf("copying new bootloader from SD card\n");
|
display_printf("copying new bootloader from SD card\n\n");
|
||||||
|
|
||||||
sdcard_power_on();
|
sdcard_power_on();
|
||||||
|
|
||||||
@ -104,7 +100,7 @@ bool copy_sdcard(void)
|
|||||||
sdcard_power_off();
|
sdcard_power_off();
|
||||||
flash_lock();
|
flash_lock();
|
||||||
|
|
||||||
display_printf("done\n\n");
|
display_printf("\ndone\n\n");
|
||||||
display_printf("Unplug the device and remove the SD card\n");
|
display_printf("Unplug the device and remove the SD card\n");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -124,22 +120,6 @@ static const uint8_t * const BOARDLOADER_KEYS[] = {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
void check_and_jump(void)
|
|
||||||
{
|
|
||||||
image_header hdr;
|
|
||||||
|
|
||||||
if (!image_parse_header((const uint8_t *)BOOTLOADER_START, IMAGE_MAGIC, IMAGE_MAXSIZE, &hdr)) {
|
|
||||||
display_printf("invalid bootloader header\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (image_check_signature((const uint8_t *)BOOTLOADER_START, &hdr, BOARDLOADER_KEY_M, BOARDLOADER_KEY_N, BOARDLOADER_KEYS)) {
|
|
||||||
jump_to(BOOTLOADER_START + HEADER_SIZE);
|
|
||||||
} else {
|
|
||||||
display_printf("invalid bootloader signature\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
__stack_chk_guard = rng_get();
|
__stack_chk_guard = rng_get();
|
||||||
@ -156,13 +136,21 @@ int main(void)
|
|||||||
ensure(0 == sdcard_init(), NULL);
|
ensure(0 == sdcard_init(), NULL);
|
||||||
|
|
||||||
if (check_sdcard()) {
|
if (check_sdcard()) {
|
||||||
ensure(true == copy_sdcard(), NULL);
|
ensure(copy_sdcard(), NULL);
|
||||||
for (;;);
|
shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
check_and_jump();
|
image_header hdr;
|
||||||
|
|
||||||
ensure(0, "halt");
|
ensure(
|
||||||
|
image_parse_header((const uint8_t *)BOOTLOADER_START, IMAGE_MAGIC, IMAGE_MAXSIZE, &hdr),
|
||||||
|
"invalid bootloader header");
|
||||||
|
|
||||||
|
ensure(
|
||||||
|
image_check_signature((const uint8_t *)BOOTLOADER_START, &hdr, BOARDLOADER_KEY_M, BOARDLOADER_KEY_N, BOARDLOADER_KEYS),
|
||||||
|
"invalid bootloader signature");
|
||||||
|
|
||||||
|
jump_to(BOOTLOADER_START + HEADER_SIZE);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user