Skip to content

Commit 9c701bf

Browse files
hw/scripts/nrfutil: add verification step before flashing device
This adds a verification step before flashing to ensure that multiple connected devices are not flashed by mistake.
1 parent a52f357 commit 9c701bf

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

hw/scripts/nrfutil.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ jlink_sn () {
2727
fi
2828
}
2929

30+
verify_sn() {
31+
if [ -n "$SRN_ARG" ]; then
32+
return 0
33+
fi
34+
35+
SN_LIST=$(nrfutil device list --json | grep -oE '"serialNumber"[[:space:]]*:[[:space:]]*"[0-9]+"' \
36+
| grep -oE '[0-9]+' | sort -u)
37+
SN_COUNT=$(wc -l <<< "$SN_LIST")
38+
39+
if [ "$SN_COUNT" -eq 1 ]; then
40+
SRN_ARG="--serial-number $SN_LIST "
41+
return 0
42+
else
43+
echo -e "Multiple devices found, serial numbers: \n$SN_LIST \n"
44+
return 1
45+
fi
46+
}
3047
#
3148
# FILE_NAME must contain the name of the file to load
3249
# FLASH_OFFSET must contain the offset in flash where to place it
@@ -87,6 +104,11 @@ nrfutil_load () {
87104
if [ -z ${ZIP_FILE} ] ; then
88105
jlink_sn
89106

107+
verify_sn
108+
if [ $? -ne 0 ]; then
109+
return 1
110+
fi
111+
90112
echo "Downloading" ${HEX_FILE}
91113

92114
nrfutil device program --firmware ${HEX_FILE} $SRN_ARG ${NRFUTIL_ARG} ${NRFUTIL_TRAITS} --options chip_erase_mode=ERASE_RANGES_TOUCHED_BY_FIRMWARE

0 commit comments

Comments
 (0)