@@ -55,13 +55,15 @@ SKIP_BUILD=0
5555SKIP_FLASH=0
5656TEST_UPDATE=0
5757TEST_SELFUPDATE=0
58+ TRIGGER_MAGIC=0
5859
5960usage () {
6061 echo " Usage: $0 [OPTIONS]"
6162 echo " "
6263 echo " Options:"
6364 echo " --test-update Build test-update.srec with v2 image in update partition (use 'trigger' command to start update)"
6465 echo " --test-selfupdate Build test-selfupdate.srec with bootloader v1 + v2 bootloader update (use 'trigger' command to start update)"
66+ echo " --trigger-magic Include trigger magic bytes to auto-start update on boot (use with --test-update)"
6567 echo " --skip-build Skip the build step (use existing .srec)"
6668 echo " --skip-flash Skip flashing (just build)"
6769 echo " -h, --help Show this help message"
@@ -70,10 +72,11 @@ usage() {
7072 echo " MOUNT_PATH Override mount path (default: auto-detect)"
7173 echo " "
7274 echo " Examples:"
73- echo " $0 # Build and flash factory.srec (v1 only)"
74- echo " $0 --test-update # Build with v2 in update partition, use 'trigger' cmd"
75- echo " $0 --test-selfupdate # Build with bootloader v2 update, tests self-update"
76- echo " $0 --skip-flash # Build without flashing"
75+ echo " $0 # Build and flash factory.srec (v1 only)"
76+ echo " $0 --test-update # Build with v2 in update partition, use 'trigger' cmd"
77+ echo " $0 --test-update --trigger-magic # Build with v2 and auto-trigger update on boot"
78+ echo " $0 --test-selfupdate # Build with bootloader v2 update, tests self-update"
79+ echo " $0 --skip-flash # Build without flashing"
7780 exit 0
7881}
7982
@@ -89,6 +92,10 @@ while [[ $# -gt 0 ]]; do
8992 SREC_FILE=" test-selfupdate.srec"
9093 shift
9194 ;;
95+ --trigger-magic)
96+ TRIGGER_MAGIC=1
97+ shift
98+ ;;
9299 --skip-build)
93100 SKIP_BUILD=1
94101 shift
@@ -293,7 +300,11 @@ if [ $SKIP_BUILD -eq 0 ]; then
293300 echo -e " ${GREEN} Build successful: test-selfupdate.srec${NC} "
294301
295302 elif [ $TEST_UPDATE -eq 1 ]; then
296- echo -e " ${GREEN} [2/3] Building test-update.srec (v1 boot + v2 update, no trigger)...${NC} "
303+ if [ $TRIGGER_MAGIC -eq 1 ]; then
304+ echo -e " ${GREEN} [2/3] Building test-update.srec (v1 boot + v2 update + trigger magic)...${NC} "
305+ else
306+ echo -e " ${GREEN} [2/3] Building test-update.srec (v1 boot + v2 update, no trigger)...${NC} "
307+ fi
297308 make clean
298309 make factory.srec
299310
@@ -307,14 +318,38 @@ if [ $SKIP_BUILD -eq 0 ]; then
307318 echo " wolfboot.bin @ 0x0"
308319 echo " image_v1_signed.bin @ ${WOLFBOOT_PARTITION_BOOT_ADDRESS} (boot partition)"
309320 echo " image_v2_signed.bin @ ${WOLFBOOT_PARTITION_UPDATE_ADDRESS} (update partition)"
310- echo " "
311- echo -e " ${YELLOW} NOTE: No trigger magic - use test-app 'trigger' command to start update${NC} "
312321
313- ./tools/bin-assemble/bin-assemble \
314- test-update.bin \
315- 0x0 wolfboot.bin \
316- ${WOLFBOOT_PARTITION_BOOT_ADDRESS} test-app/image_v1_signed_backup.bin \
317- ${WOLFBOOT_PARTITION_UPDATE_ADDRESS} test-app/image_v2_signed.bin
322+ if [ $TRIGGER_MAGIC -eq 1 ]; then
323+ # Calculate trigger magic address: end of update partition - 5 bytes
324+ # Update partition end = UPDATE_ADDRESS + PARTITION_SIZE
325+ # Trigger magic "pBOOT" (5 bytes) goes at end - 5
326+ TRIGGER_ADDRESS=$( printf " 0x%X" $(( ${WOLFBOOT_PARTITION_UPDATE_ADDRESS} + ${WOLFBOOT_PARTITION_SIZE} - 5 )) )
327+ echo " trigger_magic.bin @ ${TRIGGER_ADDRESS} (auto-trigger update)"
328+ echo " "
329+ echo -e " ${CYAN} NOTE: Update will start automatically on first boot${NC} "
330+
331+ # Create trigger magic file
332+ echo -n " pBOOT" > trigger_magic.bin
333+
334+ ./tools/bin-assemble/bin-assemble \
335+ test-update.bin \
336+ 0x0 wolfboot.bin \
337+ ${WOLFBOOT_PARTITION_BOOT_ADDRESS} test-app/image_v1_signed_backup.bin \
338+ ${WOLFBOOT_PARTITION_UPDATE_ADDRESS} test-app/image_v2_signed.bin \
339+ ${TRIGGER_ADDRESS} trigger_magic.bin
340+
341+ # Cleanup trigger magic file
342+ rm -f trigger_magic.bin
343+ else
344+ echo " "
345+ echo -e " ${YELLOW} NOTE: No trigger magic - use test-app 'trigger' command to start update${NC} "
346+
347+ ./tools/bin-assemble/bin-assemble \
348+ test-update.bin \
349+ 0x0 wolfboot.bin \
350+ ${WOLFBOOT_PARTITION_BOOT_ADDRESS} test-app/image_v1_signed_backup.bin \
351+ ${WOLFBOOT_PARTITION_UPDATE_ADDRESS} test-app/image_v2_signed.bin
352+ fi
318353
319354 # Convert to srec
320355 echo -e " ${CYAN} Converting to test-update.srec...${NC} "
@@ -325,10 +360,14 @@ if [ $SKIP_BUILD -eq 0 ]; then
325360
326361 echo -e " ${GREEN} Build successful: test-update.srec${NC} "
327362 echo " "
328- echo -e " ${CYAN} After boot, use these test-app commands:${NC} "
329- echo " status - Show partition info (should show v1 boot, v2 update)"
330- echo " trigger - Set update flag and reboot"
331- echo " reboot - Reboot to start update"
363+ if [ $TRIGGER_MAGIC -eq 1 ]; then
364+ echo -e " ${CYAN} Update will start automatically on boot.${NC} "
365+ else
366+ echo -e " ${CYAN} After boot, use these test-app commands:${NC} "
367+ echo " status - Show partition info (should show v1 boot, v2 update)"
368+ echo " trigger - Set update flag and reboot"
369+ echo " reboot - Reboot to start update"
370+ fi
332371 else
333372 echo -e " ${GREEN} [2/3] Building factory.srec...${NC} "
334373 make clean
0 commit comments