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
1521DO_BUILD=0
22+ DO_UPDATE=0
1623DO_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
1935if [[ $# -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)"
2541fi
2642
2743while 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
75131done
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
116193fi
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
121201fi
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