Skip to content

Commit c0688ef

Browse files
committed
Improve the nRF5340 build script to support arguments.
1 parent 55e9efe commit c0688ef

File tree

1 file changed

+114
-56
lines changed

1 file changed

+114
-56
lines changed

tools/scripts/nrf5340/build_flash.sh

Lines changed: 114 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,70 +4,128 @@
44

55
# run from wolfBoot root
66
# ./tools/scripts/nrf5340/build_flash.sh
7-
# optionally run with "erase" argument to rease both internal and external flash
8-
# or provide make arguments "DEBUG=1"
97

10-
11-
if [ "$1" == "erase" ]; then
8+
# optionally run with "--erase" argument to rease both internal and external flash
9+
10+
# Defaults
11+
MAKE_ARGS=
12+
DO_BUILD=0
13+
DO_BUILD_DEBUG=0
14+
DO_ERASE=0
15+
DO_PROGRAM=0
16+
if [[ $# -eq 0 ]] ; then
17+
DO_BUILD=1
18+
DO_BUILD_DEBUG=0
1219
DO_ERASE=1
13-
MAKE_ARGS="$2"
14-
else
15-
DO_ERASE=0
16-
MAKE_ARGS="$1"
20+
DO_PROGRAM=1
21+
echo "Build release with symbols, erase and program"
1722
fi
1823

19-
rm -f ./tools/scripts/nrf5340/*.bin
20-
rm -f ./tools/scripts/nrf5340/*.hex
21-
22-
# Build internal flash images for both cores
23-
24-
# Build net
25-
cp config/examples/nrf5340_net.config .config
26-
make clean
27-
make $MAKE_ARGS
28-
cp factory.bin tools/scripts/nrf5340/factory_net.bin
29-
# Sign flash update for testing (use partition type 2 for network update)
30-
tools/keytools/sign --ecc256 --id 2 test-app/image.bin wolfboot_signing_private_key.der 2
31-
cp test-app/image_v2_signed.bin tools/scripts/nrf5340/image_v2_signed_net.bin
32-
33-
# Build app
34-
cp config/examples/nrf5340.config .config
35-
make clean
36-
make $MAKE_ARGS
37-
38-
cp factory.bin tools/scripts/nrf5340/factory_app.bin
39-
# Sign flash update for testing
40-
tools/keytools/sign --ecc256 test-app/image.bin wolfboot_signing_private_key.der 2
41-
cp test-app/image_v2_signed.bin tools/scripts/nrf5340/image_v2_signed_app.bin
42-
43-
# Create a bin footer with wolfBoot trailer "BOOT" and "p" (ASCII for 0x70 == IMG_STATE_UPDATING):
44-
echo -n "pBOOT" > tools/scripts/nrf5340/trigger_magic.bin
45-
./tools/bin-assemble/bin-assemble \
46-
tools/scripts/nrf5340/update_app_v2.bin \
47-
0x0 tools/scripts/nrf5340/image_v2_signed_app.bin \
48-
0xEDFFB tools/scripts/nrf5340/trigger_magic.bin
49-
50-
51-
# Convert to HEX format for programmer tool
52-
arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x00000000 tools/scripts/nrf5340/factory_app.bin tools/scripts/nrf5340/factory_app.hex
53-
arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x01000000 tools/scripts/nrf5340/factory_net.bin tools/scripts/nrf5340/factory_net.hex
54-
55-
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
56-
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
57-
24+
while test $# -gt 0; do
25+
case "$1" in
26+
-h|--help|-?)
27+
echo "nRF5340 build / flash script"
28+
echo " "
29+
echo "default: build, erase and program"
30+
echo " "
31+
echo "options:"
32+
echo "-h, --help show brief help"
33+
echo "-b, --build build release with symbols"
34+
echo "-d, --debug build debug"
35+
echo "-v, --verbose build verbose"
36+
echo "-e, --erase do erase of internal/external flash"
37+
echo "-p, --program program images built"
38+
exit 0
39+
;;
40+
-b|--build)
41+
DO_BUILD=1
42+
MAKE_ARGS+=" DEBUG_SYMBOLS=1"
43+
echo "Build release with symbols"
44+
shift
45+
;;
46+
-d|--debug)
47+
DO_BUILD=1
48+
MAKE_ARGS+=" DEBUG=1"
49+
echo "Build with debug"
50+
shift
51+
;;
52+
-v|--verbose)
53+
DO_BUILD=1
54+
MAKE_ARGS+=" V=1"
55+
echo "Build with verbose output"
56+
shift
57+
;;
58+
-e|--erase)
59+
DO_ERASE=1
60+
echo "Do erase"
61+
shift
62+
;;
63+
-p|--program)
64+
DO_PROGRAM=1
65+
echo "Do program"
66+
shift
67+
;;
68+
*)
69+
break
70+
;;
71+
esac
72+
done
73+
74+
if [[ $DO_BUILD == 1 ]]; then
75+
rm -f ./tools/scripts/nrf5340/*.bin
76+
rm -f ./tools/scripts/nrf5340/*.hex
77+
78+
# Build internal flash images for both cores
79+
80+
# Build net
81+
cp config/examples/nrf5340_net.config .config
82+
make clean
83+
make $MAKE_ARGS
84+
cp factory.bin tools/scripts/nrf5340/factory_net.bin
85+
# Sign flash update for testing (use partition type 2 for network update)
86+
tools/keytools/sign --ecc256 --id 2 test-app/image.bin wolfboot_signing_private_key.der 2
87+
cp test-app/image_v2_signed.bin tools/scripts/nrf5340/image_v2_signed_net.bin
88+
89+
# Build app
90+
cp config/examples/nrf5340.config .config
91+
make clean
92+
make $MAKE_ARGS
93+
94+
cp factory.bin tools/scripts/nrf5340/factory_app.bin
95+
# Sign flash update for testing
96+
tools/keytools/sign --ecc256 test-app/image.bin wolfboot_signing_private_key.der 2
97+
cp test-app/image_v2_signed.bin tools/scripts/nrf5340/image_v2_signed_app.bin
98+
99+
# Create a bin footer with wolfBoot trailer "BOOT" and "p" (ASCII for 0x70 == IMG_STATE_UPDATING):
100+
echo -n "pBOOT" > tools/scripts/nrf5340/trigger_magic.bin
101+
./tools/bin-assemble/bin-assemble \
102+
tools/scripts/nrf5340/update_app_v2.bin \
103+
0x0 tools/scripts/nrf5340/image_v2_signed_app.bin \
104+
0xEDFFB tools/scripts/nrf5340/trigger_magic.bin
105+
106+
107+
# Convert to HEX format for programmer tool
108+
arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x00000000 tools/scripts/nrf5340/factory_app.bin tools/scripts/nrf5340/factory_app.hex
109+
arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x01000000 tools/scripts/nrf5340/factory_net.bin tools/scripts/nrf5340/factory_net.hex
110+
111+
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
112+
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
113+
fi
58114

59-
if [ "$DO_ERASE" == "1" ]; then
115+
if [[ $DO_ERASE == 1 ]]; then
60116
nrfjprog -f nrf53 --recover
61117
nrfjprog -f nrf53 --qspieraseall
62118
fi
63119

64-
# Program external flash
65-
nrfjprog -f nrf53 --program tools/scripts/nrf5340/update_app_v2.hex --verify
66-
nrfjprog -f nrf53 --program tools/scripts/nrf5340/image_v2_signed_net.hex --verify
120+
if [[ $DO_PROGRAM == 1 ]]; then
121+
# Program external flash
122+
nrfjprog -f nrf53 --program tools/scripts/nrf5340/update_app_v2.hex --verify
123+
nrfjprog -f nrf53 --program tools/scripts/nrf5340/image_v2_signed_net.hex --verify
67124

68125

69-
# Program Internal Flash
70-
#nrfjprog -f nrf53 --program tools/scripts/nrf5340/factory_app.hex --verify
71-
#nrfjprog -f nrf53 --program tools/scripts/nrf5340/factory_net.hex --verify --coprocessor CP_NETWORK
72-
JLinkExe -CommandFile tools/scripts/nrf5340/flash_net.jlink
73-
JLinkExe -CommandFile tools/scripts/nrf5340/flash_app.jlink
126+
# Program Internal Flash
127+
#nrfjprog -f nrf53 --program tools/scripts/nrf5340/factory_app.hex --verify
128+
#nrfjprog -f nrf53 --program tools/scripts/nrf5340/factory_net.hex --verify --coprocessor CP_NETWORK
129+
JLinkExe -CommandFile tools/scripts/nrf5340/flash_net.jlink
130+
JLinkExe -CommandFile tools/scripts/nrf5340/flash_app.jlink
131+
fi

0 commit comments

Comments
 (0)