mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 17:38:39 +00:00
boardloader: check flash_option_bytes at start
This commit is contained in:
parent
90ae9ed1c0
commit
8a707ce40d
@ -1,10 +1,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "rng.h"
|
||||
|
||||
#include STM32_HAL_H
|
||||
|
||||
#include "lowlevel.h"
|
||||
|
||||
#define WANTED_WRP (OB_WRP_SECTOR_0 | OB_WRP_SECTOR_1 | OB_WRP_SECTOR_2)
|
||||
#define WANTED_RDP (OB_RDP_LEVEL_2)
|
||||
#define WANTED_BOR (OB_BOR_LEVEL3)
|
||||
@ -38,3 +35,11 @@ void flash_set_option_bytes(void)
|
||||
HAL_FLASHEx_OBProgram(&opts);
|
||||
}
|
||||
}
|
||||
|
||||
bool flash_check_option_bytes(void)
|
||||
{
|
||||
return
|
||||
((FLASH->OPTCR & FLASH_OPTCR_nWRP) == (FLASH_OPTCR_nWRP_0 | FLASH_OPTCR_nWRP_1 | FLASH_OPTCR_nWRP_2)) &&
|
||||
((FLASH->OPTCR & FLASH_OPTCR_RDP) == FLASH_OPTCR_RDP_2) &&
|
||||
((FLASH->OPTCR & FLASH_OPTCR_BOR_LEV) == (FLASH_OPTCR_BOR_LEV_0 | FLASH_OPTCR_BOR_LEV_1));
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
#ifndef __BOARDLOADER_LOWLEVEL_H__
|
||||
#define __BOARDLOADER_LOWLEVEL_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
void flash_set_option_bytes(void);
|
||||
bool flash_check_option_bytes(void);
|
||||
|
||||
#endif
|
||||
|
@ -125,6 +125,10 @@ int main(void)
|
||||
|
||||
#if PRODUCTION
|
||||
flash_set_option_bytes();
|
||||
if (!flash_check_option_bytes()) {
|
||||
// TODO: erase storage
|
||||
ensure(0, "wrong option bytes");
|
||||
}
|
||||
#endif
|
||||
|
||||
clear_otg_hs_memory();
|
||||
|
Loading…
Reference in New Issue
Block a user