mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-24 23:38:09 +00:00
storage: When wiping, erase the active sector first.
This commit is contained in:
parent
d0d3ad2912
commit
579244b068
@ -302,6 +302,7 @@ void norcow_init(uint32_t *norcow_version) {
|
|||||||
flash_init();
|
flash_init();
|
||||||
secbool found = secfalse;
|
secbool found = secfalse;
|
||||||
*norcow_version = 0;
|
*norcow_version = 0;
|
||||||
|
norcow_active_sector = 0;
|
||||||
// detect active sector - starts with magic and has highest version
|
// detect active sector - starts with magic and has highest version
|
||||||
for (uint8_t i = 0; i < NORCOW_SECTOR_COUNT; i++) {
|
for (uint8_t i = 0; i < NORCOW_SECTOR_COUNT; i++) {
|
||||||
uint32_t offset = 0;
|
uint32_t offset = 0;
|
||||||
@ -332,13 +333,16 @@ void norcow_init(uint32_t *norcow_version) {
|
|||||||
* Wipe the storage
|
* Wipe the storage
|
||||||
*/
|
*/
|
||||||
void norcow_wipe(void) {
|
void norcow_wipe(void) {
|
||||||
erase_sector(0, sectrue);
|
// Erase the active sector first, because it contains sensitive data.
|
||||||
for (uint8_t i = 1; i < NORCOW_SECTOR_COUNT; i++) {
|
erase_sector(norcow_active_sector, sectrue);
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < NORCOW_SECTOR_COUNT; i++) {
|
||||||
|
if (i != norcow_active_sector) {
|
||||||
erase_sector(i, secfalse);
|
erase_sector(i, secfalse);
|
||||||
}
|
}
|
||||||
norcow_active_sector = 0;
|
}
|
||||||
norcow_active_version = NORCOW_VERSION;
|
norcow_active_version = NORCOW_VERSION;
|
||||||
norcow_write_sector = 0;
|
norcow_write_sector = norcow_active_sector;
|
||||||
norcow_free_offset = NORCOW_STORAGE_START;
|
norcow_free_offset = NORCOW_STORAGE_START;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ def align4_data(data):
|
|||||||
class Norcow:
|
class Norcow:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.sectors = None
|
self.sectors = None
|
||||||
|
self.active_sector = 0
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
if self.sectors:
|
if self.sectors:
|
||||||
@ -26,7 +27,10 @@ class Norcow:
|
|||||||
else:
|
else:
|
||||||
self.wipe()
|
self.wipe()
|
||||||
|
|
||||||
def wipe(self, sector: int = 0):
|
def wipe(self, sector: int = None):
|
||||||
|
if sector is None:
|
||||||
|
sector = self.active_sector
|
||||||
|
|
||||||
self.sectors = [
|
self.sectors = [
|
||||||
bytearray([0xFF] * consts.NORCOW_SECTOR_SIZE)
|
bytearray([0xFF] * consts.NORCOW_SECTOR_SIZE)
|
||||||
for _ in range(consts.NORCOW_SECTOR_COUNT)
|
for _ in range(consts.NORCOW_SECTOR_COUNT)
|
||||||
|
Loading…
Reference in New Issue
Block a user