Fix self-update erase before write in boot partition, add monolithic build option

pull/715/head
Brett Nicholas 2026-03-04 10:48:45 -07:00 committed by Daniele Lacamera
parent 999a45008d
commit 04e1e063a2
3 changed files with 19 additions and 4 deletions

View File

@ -6,6 +6,7 @@ WOLFBOOT_SMALL_STACK?=0
SPI_FLASH=0
DEBUG=1
RAM_CODE=1
SELF_UPDATE_MONOLITHIC=1
WOLFBOOT_VERSION=1
# sizes should be multiple of system page size

View File

@ -74,6 +74,12 @@ ifeq ($(WOLFBOOT_TPM_SEAL),1)
endif
endif
## Monolithic self-update: erase covers fw_size so the payload can span
## the bootloader region into the contiguous boot partition.
ifeq ($(SELF_UPDATE_MONOLITHIC),1)
CFLAGS+=-DWOLFBOOT_SELF_UPDATE_MONOLITHIC
endif
## Persist wolfBoot self header at fixed address
## Invariants and defaults are enforced in wolfboot.h
ifeq ($(WOLFBOOT_SELF_HEADER),1)

View File

@ -68,11 +68,19 @@ static uint8_t buffer[FLASHBUFFER_SIZE] XALIGNED(4);
#endif
static void RAMFUNCTION wolfBoot_erase_bootloader(void)
static void RAMFUNCTION wolfBoot_erase_bootloader(uint32_t len)
{
uint32_t len = WOLFBOOT_PARTITION_BOOT_ADDRESS - ARCH_FLASH_OFFSET;
#ifdef WOLFBOOT_SELF_UPDATE_MONOLITHIC
/* Erase the full write range (rounded up to sector boundary) so that
* a monolithic payload that spills past the bootloader region into the
* contiguous boot partition lands on erased flash. */
len = ((len + WOLFBOOT_SECTOR_SIZE - 1) /
WOLFBOOT_SECTOR_SIZE) * WOLFBOOT_SECTOR_SIZE;
#else
(void)len;
len = WOLFBOOT_PARTITION_BOOT_ADDRESS - ARCH_FLASH_OFFSET;
#endif
hal_flash_erase(ARCH_FLASH_OFFSET, len);
}
#include <string.h>
@ -155,7 +163,7 @@ static void RAMFUNCTION wolfBoot_self_update(struct wolfBoot_image *src)
#endif
hal_flash_unlock();
wolfBoot_erase_bootloader();
wolfBoot_erase_bootloader(src->fw_size);
#ifdef EXT_FLASH
if (PART_IS_EXT(src)) {
while (pos < src->fw_size) {