Skip to content

Commit ce1f7f1

Browse files
bigbrettdanielinux
authored andcommitted
add ci test coverage for monolithic and self-update combined cases
1 parent c45268e commit ce1f7f1

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

.github/workflows/test-sim-self-update.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ jobs:
3232
cp config/examples/sim-self-update-ext.config .config
3333
make test-sim-self-update-ext
3434
35+
- name: Run monolithic self-update test
36+
run: |
37+
make clean
38+
cp config/examples/sim-self-update-monolithic.config .config
39+
make test-sim-self-update-monolithic
40+
3541
- name: Run self-header verification test (internal flash)
3642
run: |
3743
make clean
@@ -43,3 +49,10 @@ jobs:
4349
make clean
4450
cp config/examples/sim-self-header-ext.config .config
4551
make test-sim-self-header-ext-verify
52+
53+
- name: Run combined monolithic self-update + self-header test
54+
run: |
55+
make clean
56+
cp config/examples/sim-self-update-monolithic.config .config
57+
make test-sim-self-update-monolithic-self-header WOLFBOOT_SELF_HEADER=1 WOLFBOOT_PARTITION_SELF_HEADER_ADDRESS=0x1F000
58+

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ RAM_CODE=1
99
SELF_UPDATE_MONOLITHIC=1
1010
WOLFBOOT_VERSION=1
1111

12-
# sizes should be multiple of system page size
13-
WOLFBOOT_PARTITION_SIZE=0x40000
12+
# Partition size 512KB so the monolithic payload (bootloader region + app)
13+
# fits in the UPDATE partition.
14+
WOLFBOOT_PARTITION_SIZE=0x80000
1415
WOLFBOOT_SECTOR_SIZE=0x1000
1516
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x20000
16-
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x60000
17+
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0xA0000
1718

1819
# required for keytools
1920
WOLFBOOT_FIXED_PARTITIONS=1

tools/test.mk

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,49 @@ test-sim-self-update-monolithic: wolfboot.bin test-app/image_v1_signed.bin FORCE
300300
@echo " Nested app at boot partition: PASSED"
301301
@echo "=== Monolithic Self-Update Test PASSED ==="
302302

303+
# Test monolithic self-update with self-header persistence.
304+
# Same as test-sim-self-update-monolithic, but also verifies that the
305+
# self-header was persisted at WOLFBOOT_PARTITION_SELF_HEADER_ADDRESS and
306+
# matches the signing tool's --header-only output byte-for-byte.
307+
#
308+
test-sim-self-update-monolithic-self-header: wolfboot.bin test-app/image_v1_signed.bin FORCE
309+
@echo "=== Simulator Monolithic Self-Update + Self-Header Test ==="
310+
@# Create dummy bootloader (0xAA pattern, exactly bootloader region size)
311+
$(Q)dd if=/dev/zero bs=$$(($(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET))) count=1 2>/dev/null | tr '\000' '\252' > monolithic_dummy_bl.bin
312+
@# Concatenate dummy bootloader + signed app image to form monolithic payload
313+
$(Q)cat monolithic_dummy_bl.bin test-app/image_v1_signed.bin > monolithic_payload.bin
314+
@# Sign monolithic payload as wolfBoot self-update v2, and generate header-only
315+
$(Q)$(SIGN_ENV) $(SIGN_TOOL) $(SIGN_OPTIONS) --wolfboot-update monolithic_payload.bin $(PRIVATE_KEY) 2
316+
$(Q)$(SIGN_ENV) $(SIGN_TOOL) $(SIGN_OPTIONS) --wolfboot-update --header-only monolithic_payload.bin $(PRIVATE_KEY) 2
317+
@# Create update partition with signed monolithic image and "pBOOT" trailer
318+
$(Q)dd if=/dev/zero bs=$$(($(WOLFBOOT_PARTITION_SIZE))) count=1 2>/dev/null | tr '\000' '\377' > update_part.dd
319+
$(Q)dd if=monolithic_payload_v2_signed.bin of=update_part.dd bs=1 conv=notrunc
320+
$(Q)printf "pBOOT" | dd of=update_part.dd bs=1 seek=$$(($(WOLFBOOT_PARTITION_SIZE) - 5)) conv=notrunc
321+
@# Create erased boot partition and self-header sector
322+
$(Q)dd if=/dev/zero bs=$$(($(WOLFBOOT_PARTITION_SIZE))) count=1 2>/dev/null | tr '\000' '\377' > boot_part.dd
323+
$(Q)dd if=/dev/zero bs=$$(($(WOLFBOOT_SECTOR_SIZE))) count=1 2>/dev/null | tr '\000' '\377' > self_hdr.dd
324+
@# Assemble flash: wolfboot.bin at 0, erased self-header, empty boot partition, update partition
325+
$(Q)$(BINASSEMBLE) internal_flash.dd \
326+
0 wolfboot.bin \
327+
$$(($(WOLFBOOT_PARTITION_SELF_HEADER_ADDRESS) - $(ARCH_FLASH_OFFSET))) self_hdr.dd \
328+
$$(($(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET))) boot_part.dd \
329+
$$(($(WOLFBOOT_PARTITION_UPDATE_ADDRESS) - $(ARCH_FLASH_OFFSET))) update_part.dd
330+
@# Run simulator - self-update fires, copies monolithic payload to offset 0 and persists header
331+
$(Q)./wolfboot.elf get_version || true
332+
@# Verify bootloader region up to self-header contains 0xAA pattern
333+
@# (the self-header sector itself is overwritten by wolfBoot_update_self_header)
334+
$(Q)cmp -n $$(($(WOLFBOOT_PARTITION_SELF_HEADER_ADDRESS) - $(ARCH_FLASH_OFFSET))) monolithic_dummy_bl.bin internal_flash.dd
335+
@echo " Bootloader region 0xAA pattern: PASSED"
336+
@# Extract nested app from boot partition and verify it matches original signed app
337+
$(Q)dd if=internal_flash.dd bs=1 skip=$$(($(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET))) count=$$(wc -c < test-app/image_v1_signed.bin | awk '{print $$1}') of=nested_app.dd 2>/dev/null
338+
$(Q)cmp nested_app.dd test-app/image_v1_signed.bin
339+
@echo " Nested app at boot partition: PASSED"
340+
@# Extract persisted self-header and verify it matches --header-only output
341+
$(Q)dd if=internal_flash.dd bs=1 skip=$$(($(WOLFBOOT_PARTITION_SELF_HEADER_ADDRESS) - $(ARCH_FLASH_OFFSET))) count=$$(($(WOLFBOOT_SECTOR_SIZE))) of=persisted_hdr.dd 2>/dev/null
342+
$(Q)cmp -n $$(($(IMAGE_HEADER_SIZE))) persisted_hdr.dd monolithic_payload_v2_header.bin
343+
@echo " Self-header persisted correctly: PASSED"
344+
@echo "=== Monolithic Self-Update + Self-Header Test PASSED ==="
345+
303346
# Test self-header cryptographic verification (hash + signature validation)
304347
#
305348
# Verifies that an application can cryptographically verify the bootloader using

0 commit comments

Comments
 (0)