1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 01:18:28 +00:00

legacy: unlock flash before erasing (#146)

This commit is contained in:
Hadi 2019-05-11 16:50:58 +04:30 committed by Pavol Rusnak
parent 61d4641810
commit 9ceb479abd

View File

@ -37,10 +37,14 @@ void memory_protect(void) {
(FLASH_OPTCR == 0x0FFCCCED)) { (FLASH_OPTCR == 0x0FFCCCED)) {
return; // already set up correctly - bail out return; // already set up correctly - bail out
} }
flash_unlock();
for (int i = FLASH_STORAGE_SECTOR_FIRST; i <= FLASH_STORAGE_SECTOR_LAST; for (int i = FLASH_STORAGE_SECTOR_FIRST; i <= FLASH_STORAGE_SECTOR_LAST;
i++) { i++) {
flash_erase_sector(i, FLASH_CR_PROGRAM_X32); flash_erase_sector(i, FLASH_CR_PROGRAM_X32);
} }
flash_lock();
flash_unlock_option_bytes(); flash_unlock_option_bytes();
// Section 2.8.6 Flash option control register (FLASH_OPTCR) // Section 2.8.6 Flash option control register (FLASH_OPTCR)
// Bits 31:28 Reserved, must be kept cleared. // Bits 31:28 Reserved, must be kept cleared.