1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-12 09:38:08 +00:00

boardloader: fix production build, disable reset_flags_init for now

This commit is contained in:
Pavol Rusnak 2017-10-29 20:29:18 +01:00
parent 16f657361c
commit 311a28242b
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -9,7 +9,6 @@ void flash_set_option_bytes(void)
{ {
FLASH_OBProgramInitTypeDef opts; FLASH_OBProgramInitTypeDef opts;
for(;;) {
HAL_FLASHEx_OBGetConfig(&opts); HAL_FLASHEx_OBGetConfig(&opts);
opts.OptionType = 0; opts.OptionType = 0;
@ -27,7 +26,7 @@ void flash_set_option_bytes(void)
} }
if (opts.OptionType == 0) { if (opts.OptionType == 0) {
break; // protections are configured return; // protections are configured
} }
// attempt to lock down the boardloader sectors // attempt to lock down the boardloader sectors
@ -38,14 +37,18 @@ void flash_set_option_bytes(void)
HAL_FLASH_OB_Lock(); HAL_FLASH_OB_Lock();
HAL_FLASH_Lock(); HAL_FLASH_Lock();
} }
}
#define FLASH_OPTION_BYTES_1 (*(const uint64_t *)0x1FFFC000)
#define FLASH_OPTION_BYTES_2 (*(const uint64_t *)0x1FFFC008)
secbool flash_check_option_bytes(void) secbool flash_check_option_bytes(void)
{ {
if ((FLASH->OPTCR & FLASH_OPTCR_nWRP) != (FLASH_OPTCR_nWRP_0 | FLASH_OPTCR_nWRP_1 | FLASH_OPTCR_nWRP_2)) return secfalse; // RDP level 2 WRP for sectors 0, 1 and 2 flash option control register matches
if ((FLASH->OPTCR & FLASH_OPTCR_RDP) != FLASH_OPTCR_RDP_2) return secfalse; if (((FLASH_OPTION_BYTES_1 & 0xFFEC) == 0xCCEC) && ((FLASH_OPTION_BYTES_2 & 0x0FFF) == 0x0FF8) && (FLASH->OPTCR == 0x0FF8CCED)) {
return sectrue; return sectrue;
} }
return secfalse;
}
void periph_init(void) void periph_init(void)
{ {
@ -77,6 +80,7 @@ void periph_init(void)
secbool reset_flags_init(void) secbool reset_flags_init(void)
{ {
/*
#if PRODUCTION #if PRODUCTION
// this is effective enough that it makes development painful, so only use it for production. // this is effective enough that it makes development painful, so only use it for production.
// check the reset flags to assure that we arrive here due to a regular full power-on event, // check the reset flags to assure that we arrive here due to a regular full power-on event,
@ -85,6 +89,7 @@ secbool reset_flags_init(void)
return secfalse; return secfalse;
} }
#endif #endif
*/
RCC->CSR |= RCC_CSR_RMVF; // clear the reset flags RCC->CSR |= RCC_CSR_RMVF; // clear the reset flags