1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 20:38:10 +00:00

Moved flash_unlock to norcow_update

and fixed propagation of error return
This commit is contained in:
Jochen Hoenicke 2017-12-16 17:24:19 +01:00
parent 6aae87437f
commit beef9ecfb5
2 changed files with 9 additions and 9 deletions

View File

@ -295,5 +295,10 @@ secbool norcow_update(uint16_t key, uint16_t offset, uint32_t value)
return secfalse;
}
uint32_t sector_offset = (const uint8_t*) ptr - (const uint8_t *)norcow_ptr(norcow_active_sector, 0, NORCOW_SECTOR_SIZE) + offset;
return flash_write_word_rel(norcow_sectors[norcow_active_sector], sector_offset, value);
if (sectrue != flash_unlock()) {
return secfalse;
}
secbool result = flash_write_word_rel(norcow_sectors[norcow_active_sector], sector_offset, value);
flash_lock();
return result;
}

View File

@ -39,9 +39,9 @@ void storage_init(void)
initialized = sectrue;
}
static void pin_fails_reset(uint16_t ofs)
static secbool pin_fails_reset(uint16_t ofs)
{
norcow_update(PIN_FAIL_KEY, ofs, 0);
return norcow_update(PIN_FAIL_KEY, ofs, 0);
}
static secbool pin_fails_increase(const uint32_t *ptr, uint16_t ofs)
@ -49,12 +49,9 @@ static secbool pin_fails_increase(const uint32_t *ptr, uint16_t ofs)
uint32_t ctr = *ptr;
ctr = ctr << 1;
flash_unlock();
if (sectrue != norcow_update(PIN_FAIL_KEY, ofs, ctr)) {
flash_lock();
return secfalse;
}
flash_lock();
uint32_t check = *ptr;
if (ctr != check) {
@ -158,9 +155,7 @@ static secbool pin_check(uint32_t pin, mp_obj_t callback)
return secfalse;
}
// Finally set the counter to 0 to indicate success.
pin_fails_reset(ofs * sizeof(uint32_t));
return sectrue;
return pin_fails_reset(ofs * sizeof(uint32_t));
}
secbool storage_unlock(const uint32_t pin, mp_obj_t callback)