Skip to content

Commit 8fcc6e5

Browse files
committed
monolithic self-updates: force DISABLE_BACKUP=1, eliminate swap, eliminate update code
1 parent 9debc4c commit 8fcc6e5

6 files changed

Lines changed: 51 additions & 8 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ assemble_internal_flash.dd: FORCE
463463
0 wolfboot.bin \
464464
$$(($(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET))) test-app/image_v1_signed.bin \
465465
$$(($(WOLFBOOT_PARTITION_UPDATE_ADDRESS)-$(ARCH_FLASH_OFFSET))) /tmp/swap \
466-
$$(($(WOLFBOOT_PARTITION_SWAP_ADDRESS)-$(ARCH_FLASH_OFFSET))) /tmp/swap
466+
$(if $(DISABLE_BACKUP),,$$(($(WOLFBOOT_PARTITION_SWAP_ADDRESS)-$(ARCH_FLASH_OFFSET))) /tmp/swap) # swap unused with DISABLE_BACKUP
467467

468468
internal_flash.dd: $(BINASSEMBLE) wolfboot.bin $(BOOT_IMG) $(PRIVATE_KEY) test-app/image_v1_signed.bin
469469
@echo "\t[MERGE] internal_flash.dd"

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ WOLFBOOT_PARTITION_SIZE=0x40000
1414
WOLFBOOT_SECTOR_SIZE=0x1000
1515
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x20000
1616
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x60000
17-
WOLFBOOT_PARTITION_SWAP_ADDRESS=0xA0000
1817

1918
# required for keytools
2019
WOLFBOOT_FIXED_PARTITIONS=1

include/wolfboot/wolfboot.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,22 @@ extern "C" {
464464

465465
#endif /* defined WOLFBOOT */
466466

467+
/* Monolithic self-update: imply DISABLE_BACKUP and enforce prerequisites */
468+
#ifdef WOLFBOOT_SELF_UPDATE_MONOLITHIC
469+
#ifndef DISABLE_BACKUP
470+
#define DISABLE_BACKUP
471+
#endif
472+
#ifdef DELTA_UPDATES
473+
#error "DELTA_UPDATES is not compatible with WOLFBOOT_SELF_UPDATE_MONOLITHIC"
474+
#endif
475+
#ifdef NVM_FLASH_WRITEONCE
476+
#error "NVM_FLASH_WRITEONCE is not compatible with WOLFBOOT_SELF_UPDATE_MONOLITHIC"
477+
#endif
478+
#ifndef RAM_CODE
479+
#error "WOLFBOOT_SELF_UPDATE_MONOLITHIC requires RAM_CODE"
480+
#endif
481+
#endif
482+
467483
#define PART_BOOT 0
468484
#define PART_UPDATE 1
469485
#define PART_SWAP 2

options.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ endif
9292
## the bootloader region into the contiguous boot partition.
9393
ifeq ($(SELF_UPDATE_MONOLITHIC),1)
9494
CFLAGS+=-DWOLFBOOT_SELF_UPDATE_MONOLITHIC
95+
DISABLE_BACKUP=1
9596
endif
9697

9798
## Persist wolfBoot self header at fixed address
@@ -719,6 +720,7 @@ endif
719720

720721
ifeq ($(DISABLE_BACKUP),1)
721722
CFLAGS+= -D"DISABLE_BACKUP"
723+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0
722724
endif
723725

724726
DEBUG_SYMBOLS?=0

src/update_flash.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ void RAMFUNCTION wolfBoot_check_self_update(void)
233233
}
234234
#endif /* RAM_CODE for self_update */
235235

236+
#ifndef WOLFBOOT_SELF_UPDATE_MONOLITHIC
237+
/* The swap-based update machinery (wolfBoot_copy_sector, wolfBoot_update, etc.)
238+
* is not used in monolithic self-update mode. */
239+
236240
static int RAMFUNCTION wolfBoot_copy_sector(struct wolfBoot_image *src,
237241
struct wolfBoot_image *dst, uint32_t sector)
238242
{
@@ -804,7 +808,10 @@ static int RAMFUNCTION wolfBoot_update(int fallback_allowed)
804808
* magic has not been set flag will have an un-determined value when we go
805809
* to check it */
806810
uint8_t flag = SECT_FLAG_NEW;
807-
struct wolfBoot_image boot, update, swap;
811+
struct wolfBoot_image boot, update;
812+
#ifndef DISABLE_BACKUP
813+
struct wolfBoot_image swap;
814+
#endif
808815
uint16_t update_type;
809816
uint32_t fw_size;
810817
uint32_t size;
@@ -856,7 +863,9 @@ static int RAMFUNCTION wolfBoot_update(int fallback_allowed)
856863
return -1;
857864
#endif
858865
wolfBoot_open_image(&boot, PART_BOOT);
866+
#ifndef DISABLE_BACKUP
859867
wolfBoot_open_image(&swap, PART_SWAP);
868+
#endif
860869

861870
#if defined(EXT_ENCRYPTED) && defined(DELTA_UPDATES)
862871
wolfBoot_printf("Update partition fallback image: %d\n", fallback_image);
@@ -1208,6 +1217,7 @@ static int RAMFUNCTION wolfBoot_update(int fallback_allowed)
12081217
#ifdef __CCRX__
12091218
#pragma section
12101219
#endif
1220+
#endif /* !WOLFBOOT_SELF_UPDATE_MONOLITHIC */
12111221

12121222
#if defined(ARCH_SIM) && defined(WOLFBOOT_TPM) && defined(WOLFBOOT_TPM_SEAL)
12131223
int wolfBoot_unlock_disk(void)
@@ -1319,12 +1329,14 @@ int wolfBoot_unlock_disk(void)
13191329
void RAMFUNCTION wolfBoot_start(void)
13201330
{
13211331
int bootRet;
1332+
#ifndef WOLFBOOT_SELF_UPDATE_MONOLITHIC
13221333
int updateRet;
13231334
#ifndef DISABLE_BACKUP
13241335
int resumedFinalErase;
13251336
#endif
13261337
uint8_t bootState;
13271338
uint8_t updateState;
1339+
#endif /* !WOLFBOOT_SELF_UPDATE_MONOLITHIC */
13281340
struct wolfBoot_image boot;
13291341

13301342
#if defined(ARCH_SIM) && defined(WOLFBOOT_TPM) && defined(WOLFBOOT_TPM_SEAL)
@@ -1335,6 +1347,8 @@ void RAMFUNCTION wolfBoot_start(void)
13351347
wolfBoot_check_self_update();
13361348
#endif
13371349

1350+
#ifndef WOLFBOOT_SELF_UPDATE_MONOLITHIC
1351+
13381352
#ifdef NVM_FLASH_WRITEONCE
13391353
/* nvm_select_fresh_sector needs unlocked flash in cases where the unused
13401354
* sector needs to be erased */
@@ -1393,6 +1407,12 @@ void RAMFUNCTION wolfBoot_start(void)
13931407
}
13941408
}
13951409

1410+
#else /* WOLFBOOT_SELF_UPDATE_MONOLITHIC */
1411+
#ifdef SECURE_PKCS11
1412+
WP11_Library_Init();
1413+
#endif
1414+
#endif /* !WOLFBOOT_SELF_UPDATE_MONOLITHIC */
1415+
13961416
bootRet = wolfBoot_open_image(&boot, PART_BOOT);
13971417
wolfBoot_printf("Booting version: 0x%x\n",
13981418
wolfBoot_get_blob_version(boot.hdr));
@@ -1404,6 +1424,7 @@ void RAMFUNCTION wolfBoot_start(void)
14041424
) {
14051425
wolfBoot_printf("Boot failed: Hdr %d, Hash %d, Sig %d\n",
14061426
boot.hdr_ok, boot.sha_ok, boot.signature_ok);
1427+
#ifndef WOLFBOOT_SELF_UPDATE_MONOLITHIC
14071428
wolfBoot_printf("Trying emergency update\n");
14081429
if (likely(wolfBoot_update(1) < 0)) {
14091430
/* panic: no boot option available. */
@@ -1427,6 +1448,13 @@ void RAMFUNCTION wolfBoot_start(void)
14271448
wolfBoot_panic();
14281449
}
14291450
}
1451+
#else
1452+
/* Monolithic mode: no emergency update path available */
1453+
#ifdef WOLFBOOT_TPM
1454+
wolfBoot_tpm2_deinit();
1455+
#endif
1456+
wolfBoot_panic();
1457+
#endif /* !WOLFBOOT_SELF_UPDATE_MONOLITHIC */
14301458
}
14311459
PART_SANITY_CHECK(&boot);
14321460
#else

tools/test.mk

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,13 @@ test-sim-self-update-monolithic: wolfboot.bin test-app/image_v1_signed.bin FORCE
282282
$(Q)dd if=/dev/zero bs=$$(($(WOLFBOOT_PARTITION_SIZE))) count=1 2>/dev/null | tr '\000' '\377' > update_part.dd
283283
$(Q)dd if=monolithic_payload_v2_signed.bin of=update_part.dd bs=1 conv=notrunc
284284
$(Q)printf "pBOOT" | dd of=update_part.dd bs=1 seek=$$(($(WOLFBOOT_PARTITION_SIZE) - 5)) conv=notrunc
285-
@# Create erased boot and swap partitions
285+
@# Create erased boot partition
286286
$(Q)dd if=/dev/zero bs=$$(($(WOLFBOOT_PARTITION_SIZE))) count=1 2>/dev/null | tr '\000' '\377' > boot_part.dd
287-
$(Q)dd if=/dev/zero bs=$$(($(WOLFBOOT_SECTOR_SIZE))) count=1 2>/dev/null | tr '\000' '\377' > erased_sec.dd
288-
@# Assemble flash: wolfboot.bin at 0, empty boot partition, update partition, swap
287+
@# Assemble flash: wolfboot.bin at 0, empty boot partition, update partition
289288
$(Q)$(BINASSEMBLE) internal_flash.dd \
290289
0 wolfboot.bin \
291290
$$(($(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET))) boot_part.dd \
292-
$$(($(WOLFBOOT_PARTITION_UPDATE_ADDRESS) - $(ARCH_FLASH_OFFSET))) update_part.dd \
293-
$$(($(WOLFBOOT_PARTITION_SWAP_ADDRESS) - $(ARCH_FLASH_OFFSET))) erased_sec.dd
291+
$$(($(WOLFBOOT_PARTITION_UPDATE_ADDRESS) - $(ARCH_FLASH_OFFSET))) update_part.dd
294292
@# Run simulator - self-update fires, copies monolithic payload to offset 0
295293
$(Q)./wolfboot.elf get_version || true
296294
@# Verify bootloader region contains 0xAA pattern (dummy bootloader was written)

0 commit comments

Comments
 (0)