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

boardloader: check flash_option_bytes at start

This commit is contained in:
Pavol Rusnak 2017-10-14 12:44:36 +02:00
parent 90ae9ed1c0
commit 8a707ce40d
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 17 additions and 5 deletions

View File

@ -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));
}

View File

@ -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

View File

@ -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();