Skip to content

Commit

Permalink
Merge pull request #407 from danielinux/dualbank_swap_fork_bootloader…
Browse files Browse the repository at this point in the history
…_once

DUALBANK: fork_bootloader should only execute once
  • Loading branch information
dgarske authored Feb 15, 2024
2 parents 22f5c09 + c25497e commit 8a7c693
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
21 changes: 21 additions & 0 deletions docs/HAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,24 @@ by the bootloader at the end of every write and erase operations on the external
If the IAP interface of the external memory requires it, this function
is called before every write and erase operations to unlock write access to the
device. On some drivers, this function may be empty.


### Additional functions required by `DUALBANK_SWAP` option

If the target device supports hardware-assisted bank swapping, it is appropriate
to provide two additional functions in the port:

`void hal_flash_dualbank_swap(void)`

Called by the bootloader when the two banks must be swapped. On some architectures
this operation implies a reboot, so this function may also never return.


`void fork_bootloader(void)`

This function is called to provide a second copy of the bootloader. Wolfboot will
clone itself if the content does not already match. `fork_bootloader()`
implementation in new ports must return immediately without performing any actions
if the content of the bootloader partition in the two banks already match.


4 changes: 4 additions & 0 deletions hal/stm32f7.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ void RAMFUNCTION fork_bootloader(void)
uint32_t r = 0, w = 0;
int i;

/* Return if content already matches */
if (memcmp(data, (void *)WOLFBOOT_COPY_BOOTLOADER, BOOTLOADER_SIZE) == 0)
return;

/* Read the wolfBoot image in RAM */
memcpy(bootloader_copy_mem, data, BOOTLOADER_SIZE);

Expand Down
4 changes: 4 additions & 0 deletions hal/stm32l5.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ static void RAMFUNCTION fork_bootloader(void)
uint32_t r = 0, w = 0;
int i;

/* Return if content already matches */
if (memcmp(data, (void *)FLASH_BANK2_BASE, BOOTLOADER_SIZE) == 0)
return;

/* Read the wolfBoot image in RAM */
memcpy(bootloader_copy_mem, data, BOOTLOADER_SIZE);

Expand Down
6 changes: 5 additions & 1 deletion hal/stm32u5.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ static void clock_pll_off(void)
DMB();
}

/* This implementation will setup MSI 48 MHz as PLL Source Mux, PLLCLK as
/* This implementation will setup MSI 48 MHz as PLL Source Mux, PLLCLK as
* System Clock Source */
static void clock_pll_on(int powersave)
{
Expand Down Expand Up @@ -490,6 +490,10 @@ static void RAMFUNCTION fork_bootloader(void)
uint32_t r = 0, w = 0;
int i;

/* Return if content already matches */
if (memcmp(data, (void *)FLASH_BANK2_BASE, BOOTLOADER_SIZE) == 0)
return;

/* Read the wolfBoot image in RAM */
memcpy(bootloader_copy_mem, data, BOOTLOADER_SIZE);

Expand Down

0 comments on commit 8a7c693

Please sign in to comment.