Bootloader: cleanse system if tainted (#554)
* Bootloader: cleanse system if tainted * Bootloader: correctly set VTOR before jump to firmware
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
// Boot request enum
|
||||
#define BOOT_REQUEST_NONE 0x00000000
|
||||
#define BOOT_REQUEST_DFU 0xDF00B000
|
||||
#define BOOT_REQUEST_TAINTED 0xDF00F000
|
||||
// Boot to DFU pin
|
||||
#define BOOT_DFU_PORT GPIOB
|
||||
#define BOOT_DFU_PIN LL_GPIO_PIN_11
|
||||
@@ -136,8 +137,12 @@ void target_init() {
|
||||
|
||||
int target_is_dfu_requested() {
|
||||
if(LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR0) == BOOT_REQUEST_DFU) {
|
||||
LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_NONE);
|
||||
return 1;
|
||||
} else if(LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR0) == BOOT_REQUEST_TAINTED) {
|
||||
// We came here directly from STM bootloader and chip is unusable
|
||||
// One more reset required to fix it
|
||||
LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_NONE);
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
LL_mDelay(100);
|
||||
if(!LL_GPIO_IsInputPinSet(BOOT_DFU_PORT, BOOT_DFU_PIN)) {
|
||||
@@ -159,6 +164,8 @@ void target_switch(void* offset) {
|
||||
|
||||
void target_switch2dfu() {
|
||||
target_led_control("B");
|
||||
// Mark system as tainted, it will be soon
|
||||
LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_TAINTED);
|
||||
// Remap memory to system bootloader
|
||||
LL_SYSCFG_SetRemapMemory(LL_SYSCFG_REMAP_SYSTEMFLASH);
|
||||
target_switch(0x0);
|
||||
@@ -166,6 +173,6 @@ void target_switch2dfu() {
|
||||
|
||||
void target_switch2os() {
|
||||
target_led_control("G");
|
||||
SCB->VTOR = BOOT_ADDRESS + OS_OFFSET;
|
||||
SCB->VTOR = OS_OFFSET;
|
||||
target_switch((void*)(BOOT_ADDRESS + OS_OFFSET));
|
||||
}
|
||||
|
Reference in New Issue
Block a user