boardloader: check flash_option_bytes at start

pull/25/head
Pavol Rusnak 7 years ago
parent 90ae9ed1c0
commit 8a707ce40d
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -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…
Cancel
Save