1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-13 19:18:56 +00:00

boardloader: erase storage on failed option_bytes

This commit is contained in:
Pavol Rusnak 2017-10-16 14:22:10 +02:00
parent 403a92cb7f
commit 001298a90e
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 49 additions and 21 deletions

View File

@ -7,7 +7,7 @@
| Sector 0 | 0x08000000 - 0x08003FFF | 16 KiB | boardloader (1st stage) (write-protected)
| Sector 1 | 0x08004000 - 0x08007FFF | 16 KiB | boardloader (1st stage) (write-protected)
| Sector 2 | 0x08008000 - 0x0800BFFF | 16 KiB | boardloader (1st stage) (write-protected)
| Sector 3 | 0x0800C000 - 0x0800FFFF | 16 KiB | ?
| Sector 3 | 0x0800C000 - 0x0800FFFF | 16 KiB | PIN counter area
| Sector 4 | 0x08010000 - 0x0801FFFF | 64 KiB | storage area #1
| Sector 5 | 0x08020000 - 0x0803FFFF | 128 KiB | bootloader (2nd stage)
| Sector 6 | 0x08040000 - 0x0805FFFF | 128 KiB | firmware
@ -16,18 +16,18 @@
| Sector 9 | 0x080A0000 - 0x080BFFFF | 128 KiB | firmware
| Sector 10 | 0x080C0000 - 0x080DFFFF | 128 KiB | firmware
| Sector 11 | 0x080E0000 - 0x080FFFFF | 128 KiB | firmware
| Sector 12 | 0x08100000 - 0x08103FFF | 16 KiB | ?
| Sector 13 | 0x08104000 - 0x08107FFF | 16 KiB | ?
| Sector 14 | 0x08108000 - 0x0810BFFF | 16 KiB | ?
| Sector 15 | 0x0810C000 - 0x0810FFFF | 16 KiB | ?
| Sector 12 | 0x08100000 - 0x08103FFF | 16 KiB | unused
| Sector 13 | 0x08104000 - 0x08107FFF | 16 KiB | unused
| Sector 14 | 0x08108000 - 0x0810BFFF | 16 KiB | unused
| Sector 15 | 0x0810C000 - 0x0810FFFF | 16 KiB | unused
| Sector 16 | 0x08110000 - 0x0811FFFF | 64 KiB | storage area #2
| Sector 17 | 0x08120000 - 0x0813FFFF | 128 KiB | ?
| Sector 18 | 0x08140000 - 0x0815FFFF | 128 KiB | ?
| Sector 19 | 0x08160000 - 0x0817FFFF | 128 KiB | ?
| Sector 20 | 0x08180000 - 0x0819FFFF | 128 KiB | ?
| Sector 21 | 0x081A0000 - 0x081BFFFF | 128 KiB | ?
| Sector 22 | 0x081C0000 - 0x081DFFFF | 128 KiB | ?
| Sector 23 | 0x081E0000 - 0x081FFFFF | 128 KiB | ?
| Sector 17 | 0x08120000 - 0x0813FFFF | 128 KiB | firmware extra
| Sector 18 | 0x08140000 - 0x0815FFFF | 128 KiB | firmware extra
| Sector 19 | 0x08160000 - 0x0817FFFF | 128 KiB | firmware extra
| Sector 20 | 0x08180000 - 0x0819FFFF | 128 KiB | firmware extra
| Sector 21 | 0x081A0000 - 0x081BFFFF | 128 KiB | firmware extra
| Sector 22 | 0x081C0000 - 0x081DFFFF | 128 KiB | firmware extra
| Sector 23 | 0x081E0000 - 0x081FFFFF | 128 KiB | firmware extra
## RAM

View File

@ -71,8 +71,8 @@ static bool copy_sdcard(void)
display_printf("\n\nerasing flash:\n\n");
// erase flash (except boardloader)
if (!flash_erase_sectors(FLASH_SECTOR_BOARDLOADER_END + 1, FLASH_SECTOR_FIRMWARE_END, progress_callback)) {
// erase all flash (except boardloader)
if (!flash_erase_sectors(FLASH_SECTOR_BOARDLOADER_END + 1, FLASH_SECTOR_LAST, progress_callback)) {
display_printf(" failed\n");
return false;
}
@ -130,7 +130,8 @@ int main(void)
#if PRODUCTION
flash_set_option_bytes();
if (!flash_check_option_bytes()) {
// TODO: erase storage
flash_erase_sectors(FLASH_SECTOR_STORAGE_1, FLASH_SECTOR_STORAGE_1, NULL);
flash_erase_sectors(FLASH_SECTOR_STORAGE_2, FLASH_SECTOR_STORAGE_2, NULL);
ensure(0, "wrong option bytes");
}
#endif

View File

@ -4,14 +4,41 @@
#include <stdbool.h>
#include <stdint.h>
#define FLASH_SECTOR_BOARDLOADER_START 0
#define FLASH_SECTOR_BOARDLOADER_END 2
// see docs/memory.md for more information
#define FLASH_SECTOR_BOOTLOADER_START 5
#define FLASH_SECTOR_BOOTLOADER_END 5
#define FLASH_SECTOR_BOARDLOADER_START 0
// 1
#define FLASH_SECTOR_BOARDLOADER_END 2
#define FLASH_SECTOR_FIRMWARE_START 6
#define FLASH_SECTOR_FIRMWARE_END 11
#define FLASH_SECTOR_PIN_AREA 3
#define FLASH_SECTOR_STORAGE_1 4
#define FLASH_SECTOR_BOOTLOADER 5
#define FLASH_SECTOR_FIRMWARE_START 6
// 7
// 8
// 9
// 10
#define FLASH_SECTOR_FIRMWARE_END 11
#define FLASH_SECTOR_UNUSED_START 12
// 13
// 14
#define FLASH_SECTOR_UNUSED_END 15
#define FLASH_SECTOR_STORAGE_2 16
#define FLASH_SECTOR_FIRMWARE_EXTRA_START 17
// 18
// 19
// 20
// 21
// 22
// 23
#define FLASH_SECTOR_FIRMWARE_EXTRA_END 23
#define FLASH_SECTOR_LAST 23
int flash_init(void);