Skip to content

Commit e31755b

Browse files
committed
sim self update: test external flash
1 parent d661c2a commit e31755b

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ jobs:
6161
echo "--- apt-mirrors.txt ---"
6262
cat /etc/apt/apt-mirrors.txt || true
6363
64-
- name: Run self-update test
64+
- name: Run self-update test (internal flash)
6565
run: |
6666
cp config/examples/sim-self-update.config .config
6767
make test-sim-self-update
68+
69+
- name: Run self-update test (external flash)
70+
run: |
71+
make clean
72+
cp config/examples/sim-self-update-ext.config .config
73+
make test-sim-self-update-ext
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
ARCH=sim
2+
TARGET=sim
3+
SIGN?=ED25519
4+
HASH?=SHA256
5+
WOLFBOOT_SMALL_STACK?=0
6+
SPI_FLASH=0
7+
EXT_FLASH=1
8+
DEBUG=1
9+
RAM_CODE=1
10+
WOLFBOOT_VERSION=1
11+
12+
# sizes should be multiple of system page size
13+
WOLFBOOT_PARTITION_SIZE=0x40000
14+
WOLFBOOT_SECTOR_SIZE=0x1000
15+
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x20000
16+
# Update and swap on external flash (address 0x00000)
17+
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x00000
18+
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x40000
19+
20+
# required for keytools
21+
WOLFBOOT_FIXED_PARTITIONS=1

tools/test.mk

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,32 @@ test-sim-self-update: wolfboot.bin FORCE
266266
@# Verify dummy payload was written to bootloader region, indicating the self update swapped images as expected
267267
$(Q)cmp -n $$(wc -c < dummy_update.bin | awk '{print $$1}') dummy_update.bin internal_flash.dd && echo "=== Self-update test PASSED ==="
268268

269+
# Test bootloader self-update mechanism with external flash
270+
test-sim-self-update-ext: wolfboot.bin FORCE
271+
@echo "=== Simulator Self-Update Test (External Flash) ==="
272+
@# Create dummy payload (0xAA pattern) and sign as wolfBoot update v2
273+
$(Q)dd if=/dev/zero bs=$$(wc -c < wolfboot.bin | awk '{print $$1}') count=1 2>/dev/null | tr '\000' '\252' > dummy_update.bin
274+
$(Q)$(SIGN_ENV) $(SIGN_TOOL) $(SIGN_OPTIONS) --wolfboot-update dummy_update.bin $(PRIVATE_KEY) 2
275+
@# Create update partition with signed update and "pBOOT" trailer
276+
$(Q)dd if=/dev/zero bs=$$(($(WOLFBOOT_PARTITION_SIZE))) count=1 2>/dev/null | tr '\000' '\377' > update_part.dd
277+
$(Q)dd if=dummy_update_v2_signed.bin of=update_part.dd bs=1 conv=notrunc
278+
$(Q)printf "pBOOT" | dd of=update_part.dd bs=1 seek=$$(($(WOLFBOOT_PARTITION_SIZE) - 5)) conv=notrunc
279+
@# Create erased boot and swap partitions
280+
$(Q)dd if=/dev/zero bs=$$(($(WOLFBOOT_PARTITION_SIZE))) count=1 2>/dev/null | tr '\000' '\377' > boot_part.dd
281+
$(Q)dd if=/dev/zero bs=$$(($(WOLFBOOT_SECTOR_SIZE))) count=1 2>/dev/null | tr '\000' '\377' > erased_sec.dd
282+
@# Assemble internal flash: wolfboot.bin at 0, empty boot partition
283+
$(Q)$(BINASSEMBLE) internal_flash.dd \
284+
0 wolfboot.bin \
285+
$$(($(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET))) boot_part.dd
286+
@# Assemble external flash: update partition, swap sector
287+
$(Q)$(BINASSEMBLE) external_flash.dd \
288+
0 update_part.dd \
289+
$(WOLFBOOT_PARTITION_SIZE) erased_sec.dd
290+
@# Run simulator - self-update reads from external, writes to internal at offset 0
291+
$(Q)./wolfboot.elf get_version || true
292+
@# Verify dummy payload was written to bootloader region
293+
$(Q)cmp -n $$(wc -c < dummy_update.bin | awk '{print $$1}') dummy_update.bin internal_flash.dd && echo "=== Self-update test (External Flash) PASSED ==="
294+
269295
test-self-update: FORCE
270296
@mv $(PRIVATE_KEY) private_key.old
271297
@make clean factory.bin RAM_CODE=1 WOLFBOOT_VERSION=1 SIGN=$(SIGN)

0 commit comments

Comments
 (0)