Skip to content

Commit 04e1e06

Browse files
bigbrettdanielinux
authored andcommitted
Fix self-update erase before write in boot partition, add monolithic build option
1 parent 999a450 commit 04e1e06

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

config/examples/sim-self-update-monolithic.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ WOLFBOOT_SMALL_STACK?=0
66
SPI_FLASH=0
77
DEBUG=1
88
RAM_CODE=1
9+
SELF_UPDATE_MONOLITHIC=1
910
WOLFBOOT_VERSION=1
1011

1112
# sizes should be multiple of system page size

options.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ ifeq ($(WOLFBOOT_TPM_SEAL),1)
7474
endif
7575
endif
7676

77+
## Monolithic self-update: erase covers fw_size so the payload can span
78+
## the bootloader region into the contiguous boot partition.
79+
ifeq ($(SELF_UPDATE_MONOLITHIC),1)
80+
CFLAGS+=-DWOLFBOOT_SELF_UPDATE_MONOLITHIC
81+
endif
82+
7783
## Persist wolfBoot self header at fixed address
7884
## Invariants and defaults are enforced in wolfboot.h
7985
ifeq ($(WOLFBOOT_SELF_HEADER),1)

src/update_flash.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,19 @@ static uint8_t buffer[FLASHBUFFER_SIZE] XALIGNED(4);
6868
#endif
6969

7070

71-
static void RAMFUNCTION wolfBoot_erase_bootloader(void)
71+
static void RAMFUNCTION wolfBoot_erase_bootloader(uint32_t len)
7272
{
73-
uint32_t len = WOLFBOOT_PARTITION_BOOT_ADDRESS - ARCH_FLASH_OFFSET;
73+
#ifdef WOLFBOOT_SELF_UPDATE_MONOLITHIC
74+
/* Erase the full write range (rounded up to sector boundary) so that
75+
* a monolithic payload that spills past the bootloader region into the
76+
* contiguous boot partition lands on erased flash. */
77+
len = ((len + WOLFBOOT_SECTOR_SIZE - 1) /
78+
WOLFBOOT_SECTOR_SIZE) * WOLFBOOT_SECTOR_SIZE;
79+
#else
80+
(void)len;
81+
len = WOLFBOOT_PARTITION_BOOT_ADDRESS - ARCH_FLASH_OFFSET;
82+
#endif
7483
hal_flash_erase(ARCH_FLASH_OFFSET, len);
75-
7684
}
7785

7886
#include <string.h>
@@ -155,7 +163,7 @@ static void RAMFUNCTION wolfBoot_self_update(struct wolfBoot_image *src)
155163
#endif
156164

157165
hal_flash_unlock();
158-
wolfBoot_erase_bootloader();
166+
wolfBoot_erase_bootloader(src->fw_size);
159167
#ifdef EXT_FLASH
160168
if (PART_IS_EXT(src)) {
161169
while (pos < src->fw_size) {

0 commit comments

Comments
 (0)