Skip to content

Commit 8a7c693

Browse files
authored
Merge pull request #407 from danielinux/dualbank_swap_fork_bootloader_once
DUALBANK: fork_bootloader should only execute once
2 parents 22f5c09 + c25497e commit 8a7c693

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

docs/HAL.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,24 @@ by the bootloader at the end of every write and erase operations on the external
114114
If the IAP interface of the external memory requires it, this function
115115
is called before every write and erase operations to unlock write access to the
116116
device. On some drivers, this function may be empty.
117+
118+
119+
### Additional functions required by `DUALBANK_SWAP` option
120+
121+
If the target device supports hardware-assisted bank swapping, it is appropriate
122+
to provide two additional functions in the port:
123+
124+
`void hal_flash_dualbank_swap(void)`
125+
126+
Called by the bootloader when the two banks must be swapped. On some architectures
127+
this operation implies a reboot, so this function may also never return.
128+
129+
130+
`void fork_bootloader(void)`
131+
132+
This function is called to provide a second copy of the bootloader. Wolfboot will
133+
clone itself if the content does not already match. `fork_bootloader()`
134+
implementation in new ports must return immediately without performing any actions
135+
if the content of the bootloader partition in the two banks already match.
136+
137+

hal/stm32f7.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,10 @@ void RAMFUNCTION fork_bootloader(void)
461461
uint32_t r = 0, w = 0;
462462
int i;
463463

464+
/* Return if content already matches */
465+
if (memcmp(data, (void *)WOLFBOOT_COPY_BOOTLOADER, BOOTLOADER_SIZE) == 0)
466+
return;
467+
464468
/* Read the wolfBoot image in RAM */
465469
memcpy(bootloader_copy_mem, data, BOOTLOADER_SIZE);
466470

hal/stm32l5.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ static void RAMFUNCTION fork_bootloader(void)
376376
uint32_t r = 0, w = 0;
377377
int i;
378378

379+
/* Return if content already matches */
380+
if (memcmp(data, (void *)FLASH_BANK2_BASE, BOOTLOADER_SIZE) == 0)
381+
return;
382+
379383
/* Read the wolfBoot image in RAM */
380384
memcpy(bootloader_copy_mem, data, BOOTLOADER_SIZE);
381385

hal/stm32u5.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static void clock_pll_off(void)
241241
DMB();
242242
}
243243

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

493+
/* Return if content already matches */
494+
if (memcmp(data, (void *)FLASH_BANK2_BASE, BOOTLOADER_SIZE) == 0)
495+
return;
496+
493497
/* Read the wolfBoot image in RAM */
494498
memcpy(bootloader_copy_mem, data, BOOTLOADER_SIZE);
495499

0 commit comments

Comments
 (0)