Skip to content

Commit 7260ecb

Browse files
dgarskedanielinux
authored andcommitted
Added tests for delta updates. Added logging for delta version errors. Added SIGN_OPTIONS_EXTRA.
1 parent d706916 commit 7260ecb

7 files changed

Lines changed: 139 additions & 40 deletions

File tree

config/examples/nrf5340_net.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ DEBUG_UART?=1
5151
USE_GCC=1
5252
OPTIMIZATION_LEVEL=2
5353

54+
SIGN_OPTIONS_EXTRA=--id 2
55+
5456
#CFLAGS_EXTRA+=-DDEBUG_FLASH
5557

5658
# If debugging network core disable the shared memory, since app core has not enabled access to it

hal/nrf5340.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,9 @@ static void hal_net_check_version(void)
516516

517517
wolfBoot_printf("Waiting for net core update to finish...\n");
518518

519-
/* wait for update_done - note longer wait - 10 seconds */
519+
/* wait for update_done - 30 seconds */
520520
ret = hal_shm_status_wait(&shm->net,
521-
SHARED_STATUS_UPDATE_DONE, 10*1000);
521+
SHARED_STATUS_UPDATE_DONE, 30*1000);
522522
if (ret == 0) {
523523
wolfBoot_printf("Network core firmware update done\n");
524524
}
@@ -543,7 +543,7 @@ static void hal_net_check_version(void)
543543
/* are we updating? */
544544
if (ret == 0 && shm->app.status == SHARED_STATUS_UPDATE_START) {
545545
wolfBoot_printf("Starting update: Ver %d->%d, Size %d->%d\n",
546-
shm->net.version, shm->app.version, shm->net.size, shm->net.size);
546+
shm->net.version, shm->app.version, shm->net.size, shm->app.size);
547547
do_update = 1;
548548

549549
/* trigger update */

options.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,3 +853,6 @@ ifneq ($(KEYVAULT_MAX_ITEMS),)
853853
CFLAGS+=-DKEYVAULT_MAX_ITEMS=$(KEYVAULT_MAX_ITEMS)
854854
endif
855855

856+
ifneq ($(SIGN_OPTIONS_EXTRA),)
857+
SIGN_OPTIONS+=$(SIGN_OPTIONS_EXTRA)
858+
endif

src/update_flash.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,16 @@ static int wolfBoot_delta_update(struct wolfBoot_image *boot,
338338
ret = wb_patch_init(&ctx, boot->hdr, boot->fw_size +
339339
IMAGE_HEADER_SIZE, update->hdr + *img_offset, *img_size);
340340
} else {
341+
wolfBoot_printf("Delta version check failed! "
342+
"Cur 0x%x, Upd 0x%x, Delta 0x%x\n",
343+
cur_v, upd_v, delta_base_v);
341344
ret = -1;
342345
}
343346
} else {
344347
if (!resume && (cur_v != delta_base_v)) {
345348
/* Wrong base image, cannot apply delta patch */
349+
wolfBoot_printf("Delta Base 0x%x != Cur 0x%x\n",
350+
cur_v, delta_base_v);
346351
ret = -1;
347352
} else {
348353
ret = wb_patch_init(&ctx, boot->hdr, boot->fw_size + IMAGE_HEADER_SIZE,

test-app/app_nrf5340.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void main(void)
5858
wolfBoot_printf("Copyright 2024 wolfSSL Inc\n");
5959
wolfBoot_printf("GPL v3\n");
6060
wolfBoot_printf("Version : 0x%lx\n", app_version);
61+
wolfBoot_printf("Compiled: " __DATE__ ":" __TIME__ "\n");
6162
wolfBoot_printf("========================\n");
6263

6364
/* mark boot successful */

test-app/app_nrf5340_net.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ void main(void)
5656
wolfBoot_printf("Copyright 2024 wolfSSL Inc\n");
5757
wolfBoot_printf("GPL v3\n");
5858
wolfBoot_printf("Version : 0x%lx\n", app_version);
59+
wolfBoot_printf("Compiled: " __DATE__ ":" __TIME__ "\n");
5960
wolfBoot_printf("========================\n");
6061

6162
/* mark boot successful */

tools/scripts/nrf5340/build_flash.sh

Lines changed: 124 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,39 @@
55
# with flag to trigger update (like calling wolfBoot_update_trigger)
66

77
# run from wolfBoot root
8+
# Example use:
9+
# Clean build and program factory version 1
810
# ./tools/scripts/nrf5340/build_flash.sh
911

10-
# optionally run with "--erase" argument to rease both internal and external flash
11-
# example: ./tools/scripts/nrf5340/build_flash.sh --debug --erase --program
12+
# Build full update version 2 and flash to external (also reprograms internal flash)
13+
# ./tools/scripts/nrf5340/build_flash.sh --update
14+
15+
# Build dela update version 3 and flash to external (also reprograms internal flash)
16+
# ./tools/scripts/nrf5340/build_flash.sh --delta
1217

1318
# Defaults
14-
MAKE_ARGS=
19+
MAKE_ARGS=" DEBUG_SYMBOLS=1"
20+
DO_CLEAN=0
1521
DO_BUILD=0
22+
DO_UPDATE=0
1623
DO_BUILD_DEBUG=0
17-
DO_ERASE=0
18-
DO_PROGRAM=0
24+
DO_ERASE_INT=0
25+
DO_ERASE_EXT=0
26+
DO_PROGRAM_INT=0
27+
DO_PROGRAM_EXT=0
28+
DO_DELTA=0
29+
UPDATE_VERSION=1
30+
31+
SIGN_ARGS="--ecc384 --sha384"
32+
#SIGN_ARGS="--ecc256 --sha256"
33+
34+
# Default with no arguments
1935
if [[ $# -eq 0 ]] ; then
36+
DO_CLEAN=1
2037
DO_BUILD=1
21-
DO_BUILD_DEBUG=0
22-
DO_ERASE=1
23-
DO_PROGRAM=1
24-
echo "Build release with symbols, erase and program"
38+
DO_ERASE_INT=1
39+
DO_PROGRAM_INT=1
40+
echo "Clean build release, erase and program (internal flash only)"
2541
fi
2642

2743
while test $# -gt 0; do
@@ -33,99 +49,170 @@ while test $# -gt 0; do
3349
echo " "
3450
echo "options:"
3551
echo "-h, --help show brief help"
52+
echo "-c, --clean cleanup build artifacts"
3653
echo "-b, --build build release with symbols"
3754
echo "-d, --debug build debug"
3855
echo "-v, --verbose build verbose"
56+
echo "--version use custom version"
3957
echo "-e, --erase do erase of internal/external flash"
4058
echo "-p, --program program images built"
59+
echo "-u, --update build update, sign and program external flash"
60+
echo "-t, --delta build update, sign delta and program external flash"
4161
exit 0
4262
;;
63+
-c|--clean)
64+
DO_CLEAN=1
65+
echo "Cleaning build artifacts"
66+
shift
67+
;;
4368
-b|--build)
4469
DO_BUILD=1
45-
MAKE_ARGS+=" DEBUG_SYMBOLS=1"
4670
echo "Build release with symbols"
4771
shift
4872
;;
4973
-d|--debug)
5074
DO_BUILD=1
5175
MAKE_ARGS+=" DEBUG=1"
52-
echo "Build with debug"
76+
echo "Add debug option"
5377
shift
5478
;;
5579
-v|--verbose)
5680
DO_BUILD=1
5781
MAKE_ARGS+=" V=1"
58-
echo "Build with verbose output"
82+
echo "Add verbose output"
5983
shift
6084
;;
6185
-e|--erase)
62-
DO_ERASE=1
86+
DO_ERASE_INT=1
87+
DO_ERASE_EXT=1
6388
echo "Do erase"
6489
shift
6590
;;
6691
-p|--program)
67-
DO_PROGRAM=1
92+
DO_PROGRAM_INT=1
93+
DO_PROGRAM_EXT=1
6894
echo "Do program"
6995
shift
7096
;;
97+
--version)
98+
UPDATE_VERSION="$2"
99+
echo "Use version ${UPDATE_VERSION}"
100+
shift
101+
shift
102+
;;
103+
-u|--update)
104+
DO_UPDATE=1
105+
UPDATE_VERSION=2
106+
DO_BUILD=1
107+
DO_ERASE_INT=1
108+
DO_ERASE_EXT=1
109+
DO_PROGRAM_INT=1
110+
DO_PROGRAM_EXT=1
111+
echo "Do update build and program"
112+
shift
113+
;;
114+
-t|--delta)
115+
DO_DELTA=1
116+
UPDATE_VERSION=3
117+
DO_BUILD=1
118+
DO_UPDATE=0
119+
DO_CLEAN=0
120+
DO_ERASE_INT=1
121+
DO_ERASE_EXT=1
122+
DO_PROGRAM_INT=1
123+
DO_PROGRAM_EXT=1
124+
echo "Do delta build and program"
125+
shift
126+
;;
71127
*)
72128
break
73129
;;
74130
esac
75131
done
76132

77-
if [[ $DO_BUILD == 1 ]]; then
133+
if [[ $DO_CLEAN == 1 ]]; then
78134
rm -f ./tools/scripts/nrf5340/*.bin
79135
rm -f ./tools/scripts/nrf5340/*.hex
136+
fi
80137

138+
if [[ $DO_BUILD == 1 ]]; then
81139
# Build internal flash images for both cores
82140

83141
# Build net
84142
cp config/examples/nrf5340_net.config .config
85143
make clean
86144
make $MAKE_ARGS
87-
cp factory.bin tools/scripts/nrf5340/factory_net.bin
88-
# Sign flash update for testing (use partition type 2 for network update)
89-
tools/keytools/sign --ecc384 --sha384 --id 2 test-app/image.bin wolfboot_signing_private_key.der 2
90-
cp test-app/image_v2_signed.bin tools/scripts/nrf5340/image_v2_signed_net.bin
145+
cp test-app/image.bin tools/scripts/nrf5340/image_net.bin
146+
if [ ! -f tools/scripts/nrf5340/factory_net.bin ]; then
147+
cp test-app/image_v1_signed.bin tools/scripts/nrf5340/image_net_v1_signed.bin
148+
cp factory.bin tools/scripts/nrf5340/factory_net.bin
149+
fi
91150

92151
# Build app
93152
cp config/examples/nrf5340.config .config
94153
make clean
95154
make $MAKE_ARGS
155+
cp test-app/image.bin tools/scripts/nrf5340/image_app.bin
156+
cp test-app/image.bin tools/scripts/nrf5340/image_app_v${UPDATE_VERSION}.bin
157+
if [ ! -f tools/scripts/nrf5340/factory_app.bin ]; then
158+
cp test-app/image_v1_signed.bin tools/scripts/nrf5340/image_app_v1_signed.bin
159+
cp factory.bin tools/scripts/nrf5340/factory_app.bin
160+
fi
161+
fi
96162

97-
cp factory.bin tools/scripts/nrf5340/factory_app.bin
98-
# Sign flash update for testing
99-
tools/keytools/sign --ecc384 --sha384 test-app/image.bin wolfboot_signing_private_key.der 2
100-
cp test-app/image_v2_signed.bin tools/scripts/nrf5340/image_v2_signed_app.bin
163+
if [[ $DO_UPDATE == 1 ]]; then
164+
# Sign flash update for testing (for network partition using --id 2)
165+
tools/keytools/sign $SIGN_ARGS --id 2 tools/scripts/nrf5340/image_net.bin wolfboot_signing_private_key.der $UPDATE_VERSION
166+
tools/keytools/sign $SIGN_ARGS tools/scripts/nrf5340/image_app.bin wolfboot_signing_private_key.der $UPDATE_VERSION
101167

102168
# Create a bin footer with wolfBoot trailer "BOOT" and "p" (ASCII for 0x70 == IMG_STATE_UPDATING):
103169
echo -n "pBOOT" > tools/scripts/nrf5340/trigger_magic.bin
104170
./tools/bin-assemble/bin-assemble \
105-
tools/scripts/nrf5340/update_app_v2.bin \
106-
0x0 tools/scripts/nrf5340/image_v2_signed_app.bin \
171+
tools/scripts/nrf5340/update_app.bin \
172+
0x0 tools/scripts/nrf5340/image_app_v${UPDATE_VERSION}_signed.bin \
107173
0xEDFFB tools/scripts/nrf5340/trigger_magic.bin
108174

175+
# Net update does not need triggered
176+
cp tools/scripts/nrf5340/image_net_v${UPDATE_VERSION}_signed.bin tools/scripts/nrf5340/update_net.bin
177+
fi
109178

110-
# Convert to HEX format for programmer tool
111-
arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x00000000 tools/scripts/nrf5340/factory_app.bin tools/scripts/nrf5340/factory_app.hex
112-
arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x01000000 tools/scripts/nrf5340/factory_net.bin tools/scripts/nrf5340/factory_net.hex
179+
if [[ $DO_DELTA == 1 ]]; then
180+
# Sign flash update for testing (for network partition using --id 2) delta between v1 and v3
181+
tools/keytools/sign $SIGN_ARGS --id 2 --delta tools/scripts/nrf5340/image_net_v1_signed.bin tools/scripts/nrf5340/image_net.bin wolfboot_signing_private_key.der $UPDATE_VERSION
182+
tools/keytools/sign $SIGN_ARGS --delta tools/scripts/nrf5340/image_app_v1_signed.bin tools/scripts/nrf5340/image_app.bin wolfboot_signing_private_key.der $UPDATE_VERSION
113183

114-
arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x10000000 tools/scripts/nrf5340/update_app_v2.bin tools/scripts/nrf5340/update_app_v2.hex
115-
arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x10100000 tools/scripts/nrf5340/image_v2_signed_net.bin tools/scripts/nrf5340/image_v2_signed_net.hex
184+
# Create a bin footer with wolfBoot trailer "BOOT" and "p" (ASCII for 0x70 == IMG_STATE_UPDATING):
185+
echo -n "pBOOT" > tools/scripts/nrf5340/trigger_magic.bin
186+
./tools/bin-assemble/bin-assemble \
187+
tools/scripts/nrf5340/update_app.bin \
188+
0x0 tools/scripts/nrf5340/image_app_v${UPDATE_VERSION}_signed_diff.bin \
189+
0xEDFFB tools/scripts/nrf5340/trigger_magic.bin
190+
191+
# Net update does not need triggered
192+
cp tools/scripts/nrf5340/image_net_v${UPDATE_VERSION}_signed_diff.bin tools/scripts/nrf5340/update_net.bin
116193
fi
117194

118-
if [[ $DO_ERASE == 1 ]]; then
119-
nrfjprog -f nrf53 --recover
120-
nrfjprog -f nrf53 --qspieraseall
195+
if [[ $DO_ERASE_INT == 1 ]]; then
196+
nrfjprog -f nrf53 --recover
197+
fi
198+
if [[ $DO_ERASE_EXT == 1 ]]; then
199+
# QSPI Erase/Write doesn't work without a --recover
200+
nrfjprog -f nrf53 --qspieraseall
121201
fi
122202

123-
if [[ $DO_PROGRAM == 1 ]]; then
203+
if [[ $DO_PROGRAM_EXT == 1 ]]; then
204+
# Convert to HEX format for programmer tool
205+
arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x10000000 tools/scripts/nrf5340/update_app.bin tools/scripts/nrf5340/update_app.hex
206+
arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x10100000 tools/scripts/nrf5340/update_net.bin tools/scripts/nrf5340/update_net.hex
124207
# Program external flash
125-
nrfjprog -f nrf53 --program tools/scripts/nrf5340/update_app_v2.hex --verify
126-
nrfjprog -f nrf53 --program tools/scripts/nrf5340/image_v2_signed_net.hex --verify
127-
208+
nrfjprog -f nrf53 --program tools/scripts/nrf5340/update_app.hex --verify
209+
nrfjprog -f nrf53 --program tools/scripts/nrf5340/update_net.hex --verify
210+
fi
128211

212+
if [[ $DO_PROGRAM_INT == 1 ]]; then
213+
# Convert to HEX format for programmer tool
214+
arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x00000000 tools/scripts/nrf5340/factory_app.bin tools/scripts/nrf5340/factory_app.hex
215+
arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x01000000 tools/scripts/nrf5340/factory_net.bin tools/scripts/nrf5340/factory_net.hex
129216
# Program Internal Flash
130217
#nrfjprog -f nrf53 --program tools/scripts/nrf5340/factory_app.hex --verify
131218
#nrfjprog -f nrf53 --program tools/scripts/nrf5340/factory_net.hex --verify --coprocessor CP_NETWORK

0 commit comments

Comments
 (0)