Fixed STM32L5 dual-bank mode

pull/154/head
Daniele Lacamera 2021-11-17 11:52:37 +01:00
parent bccfbdd2c0
commit 33102a54fd
3 changed files with 30 additions and 3 deletions

View File

@ -642,6 +642,17 @@ static void gtzc_init(void)
#define OPTR_SWAP_BANK (1 << 20)
#define AIRCR *(volatile uint32_t *)(0xE000ED0C)
#define AIRCR_VKEY (0x05FA << 16)
#define AIRCR_SYSRESETREQ (1 << 2)
static void RAMFUNCTION stm32l5_reboot(void)
{
AIRCR = AIRCR_SYSRESETREQ | AIRCR_VKEY;
while(1)
;
}
void RAMFUNCTION hal_flash_dualbank_swap(void)
{
@ -655,6 +666,7 @@ void RAMFUNCTION hal_flash_dualbank_swap(void)
FLASH_OPTR |= FLASH_OPTR_SWAP_BANK;
hal_flash_opt_lock();
hal_flash_lock();
stm32l5_reboot();
}
static void led_unsecure()

View File

@ -68,7 +68,7 @@ void RAMFUNCTION wolfBoot_start(void)
/* First time we boot this update, set to TESTING to await
* confirmation from the system
*/
if ((wolfBoot_get_partition_state(active, &p_state) == 0) &&
if ((active == PART_BOOT) && (wolfBoot_get_partition_state(active, &p_state) == 0) &&
(p_state == IMG_STATE_UPDATING))
{
hal_flash_unlock();
@ -77,9 +77,21 @@ void RAMFUNCTION wolfBoot_start(void)
}
/* Booting from update is possible via HW-assisted swap */
if (active == PART_UPDATE)
if (active == PART_UPDATE) {
hal_flash_dualbank_swap();
/* On some platform, e.g. STM32L5, hal_flash_dualbank_swap
* never returns. A reboot is triggered instead, so the code
* below is only executed if we are staging the firmware.
*/
active = PART_BOOT;
if ((wolfBoot_get_partition_state(active, &p_state) == 0) &&
(p_state == IMG_STATE_UPDATING))
{
hal_flash_unlock();
wolfBoot_set_partition_state(active, IMG_STATE_TESTING);
hal_flash_lock();
}
}
hal_prepare_boot();
do_boot((void *)WOLFBOOT_PARTITION_BOOT_ADDRESS + IMAGE_HEADER_SIZE);
}

View File

@ -27,6 +27,7 @@
#include <string.h>
#include "system.h"
#include "hal.h"
#include "wolfboot/wolfboot.h"
#define LED_BOOT_PIN (12) //PG12 - Discovery - Green Led
#define LED_USR_PIN (3) //PD3 - Discovery - Red Led
@ -100,6 +101,8 @@ void main(void)
boot_led_on();
usr_led_on();
boot_led_off();
if (wolfBoot_current_firmware_version() > 1)
boot_led_on();
while(1)
;
}