Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions hw/bsp/nordic_pca10059/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ syscfg.defs:
tool without debugger.
value: 0

syscfg.BSP_NRF_SDK_FLASH_LAYOUT:
syscfg.vals.BSP_NRF_SDK_FLASH_LAYOUT:
# Change to use Nordic DFU bootloader which is likely to be used
# when device still has original bootloader
NRFUTIL_TRAITS: nordicDfu
NRFUTIL_DFU_MODE: 1
BOOTUTIL_SINGLE_APPLICATION_SLOT: 1

syscfg.vals:
MYNEWT_DOWNLOADER: nrfutil
JLINK_TARGET: nRF52840_xxAA
PYOCD_TARGET: nrf52840
NRFUTIL_TRAITS: jlink

# Enable nRF52840 MCU and common startup code
MCU_TARGET: nRF52840
Expand Down
54 changes: 36 additions & 18 deletions hw/scripts/nrfutil.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ nrfutil_load () {
echo "Missing filename"
exit 1
fi

NRF_TRAITS_OPT=""
if [ -n "${MYNEWT_VAL_NRFUTIL_TRAITS}" ]; then
NRF_TRAITS_OPT="--traits ${MYNEWT_VAL_NRFUTIL_TRAITS}"
fi

# If nordicDfu is to be used, create hex file directly from ELF
if [ "$MYNEWT_VAL_NRFUTIL_TRAITS" == "nordicDfu" ] ; then
if [ "${MYNEWT_VAL_NRFUTIL_DFU_MODE:-0}" -eq 1 ] ; then
arm-none-eabi-objcopy -O ihex ${ELF_FILE} ${HEX_FILE}
elif [ ! -f "${FILE_NAME}" ]; then
# tries stripping current path for readability
Expand All @@ -65,36 +71,48 @@ nrfutil_load () {
fi

ret=0
if [ -z ${NRFUTIL_TRAITS} ] ; then
if [ -z ${MYNEWT_VAL_NRFUTIL_TRAITS} ] ; then
NRFUTIL_TRAITS="--traits jlink"
if [ "${MYNEWT_VAL_NRFUTIL_DFU_MODE:-0}" -eq 1 ] ; then
ZIP_FILE=${BIN_BASENAME}.zip
if [ -n "${MYNEWT_VAL_NRFUTIL_DFU_SN}" ] ; then
PORT=$(nrfutil device list --traits nordicDfu | awk -v dfu_sn=$MYNEWT_VAL_NRFUTIL_DFU_SN \
'dfu_sn==$1 { sn_match=1 }
/^Ports/ { if(sn_match) { print $2; sn_match=0 }}
')
if [ -z "$PORT" ] ; then
echo "Error: NRFUTIL_DFU_SN does not match any connected board."
return 1
fi
else
NRFUTIL_TRAITS="--traits ${MYNEWT_VAL_NRFUTIL_TRAITS}"
if [ $MYNEWT_VAL_NRFUTIL_TRAITS == "nordicDfu" ] ; then
ZIP_FILE=${BIN_BASENAME}.zip
PORT=`nrfutil device list --traits nordicDfu | awk '/ports/ { print $2 }'`
# TODO: hw-version is probably incorrect for non NRF52 devices
nrfutil pkg generate --hw-version 52 --sd-req 0 --application ${HEX_FILE} --application-version 1 ${ZIP_FILE}
echo "Downloading" ${ZIP_FILE}
nrfutil dfu usb-serial -p ${PORT} --package ${ZIP_FILE}
if [ $? -ne 0 ]; then
ret=1
fi
PORT=$(nrfutil device list --traits nordicDfu | awk '/^Ports/ { print $2 }')
PORT_COUNT=$(echo "$PORT" | wc -w)
if [ "$PORT_COUNT" -eq 0 ]; then
echo "Error: No Nordic DFU devices found."
return 1
elif [ "$PORT_COUNT" -gt 1 ]; then
echo "Error: Found multiple DFU devices. Connect exactly one supported device or add NRFUTIL_DFU_SN to your target."
return 1
fi
fi

# TODO: hw-version is probably incorrect for non NRF52 devices
nrfutil pkg generate --hw-version 52 --sd-req 0 --application ${HEX_FILE} --application-version 1 ${ZIP_FILE}
echo "Downloading" ${ZIP_FILE}
nrfutil dfu usb-serial -p ${PORT} --package ${ZIP_FILE}
if [ $? -ne 0 ]; then
ret=1
fi
fi

if [ -z ${ZIP_FILE} ] ; then
jlink_sn

echo "Downloading" ${HEX_FILE}

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

if [ $? -ne 0 ]; then
ret=1
else
nrfutil device reset $SRN_ARG
nrfutil device reset $SRN_ARG ${NRF_TRAITS_OPT}
fi
fi

Expand Down
15 changes: 12 additions & 3 deletions hw/scripts/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,20 @@ syscfg.defs:
Some NRF have more then one core. This can specify non-default core
(i.e. CP_NETWORK for NRF5340).
value:
NRFUTIL_DFU_MODE:
description: >
Enables firmware upload through nrfutil dfu usb-serial.
value:
NRFUTIL_TRAITS:
description: >
Traits passed to nrfutil command. If not set `jlink` is the default.
It can be 'nordicDfu' to upload binary using Nordic SDK DFU
bootloader protocol.
Optional device traits used by nrfutil to select boards for flashing.
When set (e.g. 'jlink'), all connected devices matching this trait
will be programmed.
value:
NRFUTIL_DFU_SN:
description: >
DFU serial number passed to the nrfutil script.
Used to select the target device for firmware upload.
value:
MYNEWT_DEBUGGER_SN:
description: >
Expand Down
Loading