1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 14:28:07 +00:00

embed: norcow_init, storage_init and flash_init don't return secbool, they halt using ensure if something goes wrong

This commit is contained in:
Pavol Rusnak 2017-12-09 14:48:49 +01:00
parent 6b94fd26e4
commit 6ab0f03ec4
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
8 changed files with 16 additions and 34 deletions

View File

@ -20,9 +20,7 @@
/// called from this module!
/// '''
STATIC mp_obj_t mod_trezorconfig_init(void) {
if (sectrue != storage_init()) {
mp_raise_msg(&mp_type_RuntimeError, "Could not initialize config module");
}
storage_init();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_init_obj, mod_trezorconfig_init);

View File

@ -220,7 +220,7 @@ static void compact()
/*
* Initializes storage
*/
secbool norcow_init(void)
void norcow_init(void)
{
secbool found = secfalse;
// detect active sector - starts with magic
@ -236,17 +236,14 @@ secbool norcow_init(void)
if (sectrue == found) {
norcow_active_offset = find_free_offset(norcow_active_sector);
} else {
if (sectrue != norcow_wipe()) {
return secfalse;
}
norcow_wipe();
}
return sectrue;
}
/*
* Wipe the storage
*/
secbool norcow_wipe(void)
void norcow_wipe(void)
{
norcow_erase(0, sectrue);
for (uint8_t i = 1; i < NORCOW_SECTOR_COUNT; i++) {
@ -254,7 +251,6 @@ secbool norcow_wipe(void)
}
norcow_active_sector = 0;
norcow_active_offset = NORCOW_MAGIC_LEN;
return sectrue;
}
/*

View File

@ -14,12 +14,12 @@
/*
* Initialize storage
*/
secbool norcow_init(void);
void norcow_init(void);
/*
* Wipe the storage
*/
secbool norcow_wipe(void);
void norcow_wipe(void);
/*
* Looks for the given key, returns status of the operation

View File

@ -26,18 +26,13 @@
static secbool initialized = secfalse;
static secbool unlocked = secfalse;
secbool storage_init(void)
void storage_init(void)
{
initialized = secfalse;
unlocked = secfalse;
if (sectrue != flash_init()) {
return secfalse;
}
if (sectrue != norcow_init()) {
return secfalse;
}
flash_init();
norcow_init();
initialized = sectrue;
return sectrue;
}
static void pin_fails_reset(uint32_t ofs)
@ -84,11 +79,7 @@ static secbool pin_fails_increase(uint32_t ofs)
static void pin_fails_check_max(uint32_t ctr)
{
if (~ctr >= 1 << PIN_MAX_TRIES) {
for (;;) {
if (norcow_wipe()) {
break;
}
}
norcow_wipe();
ensure(secfalse, "pin_fails_check_max");
}
}
@ -209,7 +200,7 @@ secbool storage_change_pin(const uint8_t *pin, size_t len, const uint8_t *newpin
return norcow_set(PIN_KEY, newpin, newlen);
}
secbool storage_wipe(void)
void storage_wipe(void)
{
return norcow_wipe();
norcow_wipe();
}

View File

@ -9,7 +9,7 @@
#include <stddef.h>
#include "../../trezorhal/secbool.h"
secbool storage_init(void);
void storage_init(void);
secbool storage_wipe(void);
secbool storage_unlock(const uint8_t *pin, size_t len);
secbool storage_has_pin(void);

View File

@ -41,9 +41,8 @@ static const uint32_t FLASH_SECTOR_TABLE[FLASH_SECTOR_COUNT + 1] = {
[24] = 0x08200000, // last element - not a valid sector
};
secbool flash_init(void)
void flash_init(void)
{
return sectrue;
}
secbool flash_unlock(void)

View File

@ -43,7 +43,7 @@
// note: FLASH_SR_RDERR is STM32F42xxx and STM32F43xxx specific (STM32F427) (reference RM0090 section 3.7.5)
#define FLASH_STATUS_ALL_FLAGS (FLASH_SR_RDERR | FLASH_SR_PGSERR | FLASH_SR_PGPERR | FLASH_SR_PGAERR | FLASH_SR_WRPERR | FLASH_SR_SOP | FLASH_SR_EOP)
secbool flash_init(void);
void flash_init(void);
secbool flash_unlock(void);
secbool flash_lock(void);

View File

@ -60,7 +60,7 @@ static void flash_exit(void)
ensure(sectrue * (r == 0), "munmap failed");
}
secbool flash_init(void)
void flash_init(void)
{
int r;
@ -90,8 +90,6 @@ secbool flash_init(void)
flash_buffer = (uint8_t *)map;
atexit(flash_exit);
return sectrue;
}
secbool flash_unlock(void)