1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

boardloader/bootloader: use static const for sector arrays; erase storage if firmware is broken

This commit is contained in:
Pavol Rusnak 2018-06-06 00:52:16 +02:00
parent 290643782a
commit a3af8faf23
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
4 changed files with 12 additions and 5 deletions

View File

@ -104,7 +104,7 @@ static secbool copy_sdcard(void)
display_printf("\n\nerasing flash:\n\n");
// erase all flash (except boardloader)
const uint8_t sectors[] = {
static const uint8_t sectors[] = {
3,
FLASH_SECTOR_STORAGE_1,
FLASH_SECTOR_STORAGE_2,
@ -168,7 +168,7 @@ int main(void)
periph_init();
if (sectrue != flash_configure_option_bytes()) {
const uint8_t sectors[] = {
static const uint8_t sectors[] = {
FLASH_SECTOR_STORAGE_1,
FLASH_SECTOR_STORAGE_2,
};

View File

@ -283,6 +283,13 @@ main_start:
ui_screen_third();
ui_fadein();
// erase storage
static const uint8_t sectors_storage[] = {
FLASH_SECTOR_STORAGE_1,
FLASH_SECTOR_STORAGE_2,
};
ensure(flash_erase_sectors(sectors_storage, sizeof(sectors_storage), NULL), NULL);
// and start the usb loop
if (bootloader_usb_loop(NULL, NULL) != sectrue) {
return 1;

View File

@ -475,7 +475,7 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size, uint8_t *bu
// if firmware is not upgrade, erase storage
if (sectrue != is_upgrade) {
const uint8_t sectors_storage[] = {
static const uint8_t sectors_storage[] = {
FLASH_SECTOR_STORAGE_1,
FLASH_SECTOR_STORAGE_2,
};
@ -530,7 +530,7 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size, uint8_t *bu
int process_msg_WipeDevice(uint8_t iface_num, uint32_t msg_size, uint8_t *buf)
{
const uint8_t sectors[] = {
static const uint8_t sectors[] = {
3,
FLASH_SECTOR_STORAGE_1,
FLASH_SECTOR_STORAGE_2,

View File

@ -77,7 +77,7 @@ int main(void)
display_printf("updating boardloader + bootloader\n");
const uint8_t sectors[] = {
static const uint8_t sectors[] = {
FLASH_SECTOR_BOARDLOADER_START,
1,
FLASH_SECTOR_BOARDLOADER_END,