You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by "janc.apache.org via commits" <co...@mynewt.apache.org> on 2026/10/31 22:22:07 UTC
(mynewt-core) 03/04: hw/scripts: Quote paths in download and debug scripts
This is an automated email from the ASF dual-hosted git repository.
sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 470b313eeffb01ff0032191ac49544a6acbc5f88
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Sat Oct 31 20:03:30 2026 +0100
hw/scripts: Quote paths in download and debug scripts
Image, core and tool paths were used unquoted in the common download
and debug helpers, so newt load and newt debug failed for projects in
directories with spaces in their names.
Quote the paths on command lines. gdb restore and J-Link commands
cannot take paths with spaces at all, so pass them paths relative to
the current directory (newt runs these scripts from the project root)
and use Tcl braces around the image path in OpenOCD commands.
Assisted-by: Claude:claude-opus-5-5
---
.../da1469x/scripts/dialog_da1469x-debug_jlink.sh | 2 +-
.../scripts/dialog_da1469x-download_jlink.sh | 32 +++++++++++----------
hw/scripts/download.sh | 18 ++++++------
hw/scripts/ezflashcli.sh | 14 ++++-----
hw/scripts/jlink.sh | 20 +++++++------
hw/scripts/mplab_ipe.sh | 8 +++---
hw/scripts/nrfjprog.sh | 12 ++++----
hw/scripts/nrfutil.sh | 22 +++++++--------
hw/scripts/openocd.sh | 20 ++++++-------
hw/scripts/pic32_download.sh | 33 ++++++++++++----------
hw/scripts/pyocd.sh | 16 +++++------
hw/scripts/stlink.sh | 18 ++++++------
hw/scripts/stm32_programmer.sh | 20 ++++++-------
13 files changed, 121 insertions(+), 114 deletions(-)
diff --git a/hw/mcu/dialog/da1469x/scripts/dialog_da1469x-debug_jlink.sh b/hw/mcu/dialog/da1469x/scripts/dialog_da1469x-debug_jlink.sh
index 735feb45b..10dd095b3 100755
--- a/hw/mcu/dialog/da1469x/scripts/dialog_da1469x-debug_jlink.sh
+++ b/hw/mcu/dialog/da1469x/scripts/dialog_da1469x-debug_jlink.sh
@@ -28,7 +28,7 @@
# - NO_GDB set if we should not start gdb to debug
#
-. $CORE_PATH/hw/scripts/jlink.sh
+. "$CORE_PATH"/hw/scripts/jlink.sh
FILE_NAME=$BIN_BASENAME.elf
JLINK_DEV="Cortex-M33"
diff --git a/hw/mcu/dialog/da1469x/scripts/dialog_da1469x-download_jlink.sh b/hw/mcu/dialog/da1469x/scripts/dialog_da1469x-download_jlink.sh
index b9f0ba1c5..21e331ccd 100755
--- a/hw/mcu/dialog/da1469x/scripts/dialog_da1469x-download_jlink.sh
+++ b/hw/mcu/dialog/da1469x/scripts/dialog_da1469x-download_jlink.sh
@@ -29,7 +29,7 @@
# - FLASH_OFFSET contains the flash offset to download to
# - BOOT_LOADER is set if downloading a bootloader
-. $CORE_PATH/hw/scripts/jlink.sh
+. "$CORE_PATH"/hw/scripts/jlink.sh
common_file_to_load
@@ -46,11 +46,11 @@ GDB_CMD_FILE=.gdb_load
JLINK_LOG_FILE=.jlink_log
# flash_loader build for this BSP
-if [ -z $FLASH_LOADER ]; then
+if [ -z "$FLASH_LOADER" ]; then
FL_TGT=da1469x_flash_loader
FLASH_LOADER=$BIN_ROOT/targets/$FL_TGT/app/@apache-mynewt-core/apps/flash_loader/flash_loader.elf
fi
-if [ ! -f $FLASH_LOADER ]; then
+if [ ! -f "$FLASH_LOADER" ]; then
FILE=${FLASH_LOADER##$(pwd)/}
echo "Can't find flash_loader : $FILE"
if [ ! -z $FL_TGT ]; then
@@ -59,9 +59,9 @@ if [ ! -f $FLASH_LOADER ]; then
exit 1
fi
-if [ ! -f $FILE_NAME ]; then
+if [ ! -f "$FILE_NAME" ]; then
FILE=${FILE_NAME##$(pwd)/}
- echo "Cannot find file" $FILE
+ echo "Cannot find file" "$FILE"
exit 1
fi
@@ -71,7 +71,7 @@ hex2le() {
# XXX Write windows version also
file_size() {
- echo `wc -c $FILE_NAME | awk '{print $1}'`
+ echo `wc -c "$FILE_NAME" | awk '{print $1}'`
}
if [ "$BOOT_LOADER" ]; then
@@ -88,11 +88,11 @@ if [ "$BOOT_LOADER" ]; then
exit 1
fi
- ${CORE_PATH}/hw/mcu/dialog/da1469x/scripts/da1469x_header_tool.py secure --sign ${MYNEWT_VAL_BOOT_SIG_PEM} \
+ "${CORE_PATH}"/hw/mcu/dialog/da1469x/scripts/da1469x_header_tool.py secure --sign ${MYNEWT_VAL_BOOT_SIG_PEM} \
-s${MYNEWT_VAL_BOOT_SIG_SLOT} -d${MYNEWT_VAL_BOOT_AES_SLOT} \
- -E${MYNEWT_VAL_BOOT_AES_KEY} ${IMAGE_FILE} ${FILE_NAME}
+ -E${MYNEWT_VAL_BOOT_AES_KEY} "${IMAGE_FILE}" "${FILE_NAME}"
else
- ${CORE_PATH}/hw/mcu/dialog/da1469x/scripts/da1469x_header_tool.py nonsecure ${IMAGE_FILE} ${FILE_NAME}
+ "${CORE_PATH}"/hw/mcu/dialog/da1469x/scripts/da1469x_header_tool.py nonsecure "${IMAGE_FILE}" "${FILE_NAME}"
fi
if [ $? != 0 ]; then
@@ -103,15 +103,15 @@ if [ "$BOOT_LOADER" ]; then
FILE_NAME=${IMAGE_FILE}
fi
-FILE_SIZE=$(file_size $FILE_NAME)
+FILE_SIZE=$(file_size "$FILE_NAME")
if [ -z $JLINK_TARGET_HOST ]; then
JLINK_SERVER_CMD="shell sh -c \"trap '' 2; $JLINK_GDB_SERVER -device cortex-m33 -speed 4000 -if SWD -port $PORT -singlerun $EXTRA_JTAG_CMD > $JLINK_LOG_FILE 2>&1 &\""
fi
if [ -n "$UART_PROTO_DEV" ]; then
- ${CORE_PATH}/hw/mcu/dialog/da1469x/scripts/da1469x_serial.py load ${FLASH_LOADER}.bin \
- -u ${UART_PROTO_DEV} -r ${CORE_PATH}/hw/mcu/dialog/da1469x/scripts/reset.sh
+ "${CORE_PATH}"/hw/mcu/dialog/da1469x/scripts/da1469x_serial.py load "${FLASH_LOADER}".bin \
+ -u ${UART_PROTO_DEV} -r "${CORE_PATH}"/hw/mcu/dialog/da1469x/scripts/reset.sh
if [ $? != 0 ]; then
exit 1
fi
@@ -126,11 +126,13 @@ mon halt
EOF
if [ ! -n "$UART_PROTO_DEV" ]; then
- echo "restore $FLASH_LOADER.bin binary 0x20000000" >> $GDB_CMD_FILE
+ # gdb restore command cannot handle paths with spaces, use a path
+ # relative to the current directory if possible.
+ echo "restore ${FLASH_LOADER#"$(pwd)"/}.bin binary 0x20000000" >> $GDB_CMD_FILE
fi
cat >> $GDB_CMD_FILE <<EOF
-symbol-file $FLASH_LOADER
+symbol-file "$FLASH_LOADER"
# Configure QSPI controller so it can read flash in automode (values
# valid for Macronix flash found on Dialog development kits)
@@ -156,7 +158,7 @@ while fl_state != 1
end
fl_erase 0 $FLASH_OFFSET $FILE_SIZE
-fl_program $FILE_NAME 0 $FLASH_OFFSET
+fl_program ${FILE_NAME#"$(pwd)"/} 0 $FLASH_OFFSET
# 'mon reset' does not appear to reset the board. Write to MCU register
# directly instead.
diff --git a/hw/scripts/download.sh b/hw/scripts/download.sh
index cf0047ff3..588675f18 100755
--- a/hw/scripts/download.sh
+++ b/hw/scripts/download.sh
@@ -51,17 +51,17 @@ fi
case "${MYNEWT_VAL_MYNEWT_DOWNLOADER}" in
"bsp_downloader")
- $CORE_PATH/$MYNEWT_VAL_MYNEWT_DOWNLOADER_SCRIPT
+ "$CORE_PATH"/$MYNEWT_VAL_MYNEWT_DOWNLOADER_SCRIPT
;;
"ezflashcli")
check_downloader ezFlashCLI
- . $CORE_PATH/hw/scripts/ezflashcli.sh
+ . "$CORE_PATH"/hw/scripts/ezflashcli.sh
common_file_to_load
ezflashcli_load
;;
"jlink")
check_downloader $JLINKEXE
- . $CORE_PATH/hw/scripts/jlink.sh
+ . "$CORE_PATH"/hw/scripts/jlink.sh
if [ -z "${MYNEWT_VAL_JLINK_TARGET}" ] ; then
>&2 echo -e "\n\nSyscfg value MYNEWT_DOWNLOADER set to 'jlink' but JLINK_TARGET not set in syscfg."
exit -1
@@ -72,19 +72,19 @@ case "${MYNEWT_VAL_MYNEWT_DOWNLOADER}" in
;;
"nrfjprog")
check_downloader nrfjprog
- . $CORE_PATH/hw/scripts/nrfjprog.sh
+ . "$CORE_PATH"/hw/scripts/nrfjprog.sh
common_file_to_load
nrfjprog_load
;;
"nrfutil")
check_downloader nrfutil
- . $CORE_PATH/hw/scripts/nrfutil.sh
+ . "$CORE_PATH"/hw/scripts/nrfutil.sh
common_file_to_load
nrfutil_load
;;
"openocd")
check_downloader openocd
- . $CORE_PATH/hw/scripts/openocd.sh
+ . "$CORE_PATH"/hw/scripts/openocd.sh
if [ -n "${MYNEWT_VAL_MYNEWT_DOWNLOADER_OPENOCD_INTERFACE}" ] ; then
CFG="-f ${MYNEWT_VAL_MYNEWT_DOWNLOADER_OPENOCD_INTERFACE}"
fi
@@ -105,7 +105,7 @@ case "${MYNEWT_VAL_MYNEWT_DOWNLOADER}" in
;;
"pyocd")
check_downloader pyocd
- . $CORE_PATH/hw/scripts/pyocd.sh
+ . "$CORE_PATH"/hw/scripts/pyocd.sh
if [ -z "${MYNEWT_VAL_PYOCD_TARGET}" ] ; then
>&2 echo -e "\n\nSyscfg value MYNEWT_DOWNLOADER set to 'pyocd' but PYOCD_TARGET not set in syscfg."
>&2 echo -e "pyocd supported targets can be found with 'pyocd list --targets'\n"
@@ -117,13 +117,13 @@ case "${MYNEWT_VAL_MYNEWT_DOWNLOADER}" in
;;
"stflash")
check_downloader st-flash
- . $CORE_PATH/hw/scripts/stlink.sh
+ . "$CORE_PATH"/hw/scripts/stlink.sh
common_file_to_load
stlink_load
;;
"stm32_programmer_cli")
check_downloader STM32_Programmer_CLI
- . $CORE_PATH/hw/scripts/stm32_programmer.sh
+ . "$CORE_PATH"/hw/scripts/stm32_programmer.sh
common_file_to_load
stlink_load
;;
diff --git a/hw/scripts/ezflashcli.sh b/hw/scripts/ezflashcli.sh
index 46428d7ce..cd163b799 100755
--- a/hw/scripts/ezflashcli.sh
+++ b/hw/scripts/ezflashcli.sh
@@ -15,36 +15,36 @@
# specific language governing permissions and limitations
# under the License.
#
-. $CORE_PATH/hw/scripts/common.sh
+. "$CORE_PATH"/hw/scripts/common.sh
#
# FILE_NAME must contain the name of the file to load
# FLASH_OFFSET must contain the offset in flash where to place it
#
ezflashcli_load () {
- if [ -z ${FILE_NAME} ]; then
+ if [ -z "${FILE_NAME}" ]; then
echo "Missing filename"
exit 1
fi
if [ ! -f "${FILE_NAME}" ]; then
# tries stripping current path for readability
FILE=${FILE_NAME##$(pwd)/}
- echo "Cannot find file" $FILE
+ echo "Cannot find file" "$FILE"
exit 1
fi
if [ "$BOOT_LOADER" ]; then
- echo "Downloading" $FILE_NAME
- ezFlashCLI image_flash ${FILE_NAME}
+ echo "Downloading" "$FILE_NAME"
+ ezFlashCLI image_flash "${FILE_NAME}"
else
if [ -z ${FLASH_OFFSET} ]; then
echo "Missing flash offset"
exit 1
fi
- echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET
+ echo "Downloading" "$FILE_NAME" "to" $FLASH_OFFSET
- ezFlashCLI write_flash ${FLASH_OFFSET} ${FILE_NAME}
+ ezFlashCLI write_flash ${FLASH_OFFSET} "${FILE_NAME}"
fi
ezFlashCLI go
diff --git a/hw/scripts/jlink.sh b/hw/scripts/jlink.sh
index 4fa39d11c..14dfe05a6 100755
--- a/hw/scripts/jlink.sh
+++ b/hw/scripts/jlink.sh
@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
-. $CORE_PATH/hw/scripts/common.sh
+. "$CORE_PATH"/hw/scripts/common.sh
JLINK_GDB_SERVER=JLinkGDBServer
@@ -60,14 +60,14 @@ jlink_load () {
if [ $WINDOWS -eq 1 ]; then
JLINK_GDB_SERVER=JLinkGDBServerCL
fi
- if [ -z $FILE_NAME ]; then
+ if [ -z "$FILE_NAME" ]; then
echo "Missing filename"
exit 1
fi
if [ ! -f "$FILE_NAME" ]; then
# tries stripping current path for readability
FILE=${FILE_NAME##$(pwd)/}
- echo "Cannot find file" $FILE
+ echo "Cannot find file" "$FILE"
exit 1
fi
if [ -z $FLASH_OFFSET ]; then
@@ -75,7 +75,7 @@ jlink_load () {
exit 1
fi
- echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET
+ echo "Downloading" "$FILE_NAME" "to" $FLASH_OFFSET
# XXX for some reason JLinkExe overwrites flash at offset 0 when
# downloading somewhere in the flash. So need to figure out how to tell it
@@ -86,7 +86,9 @@ jlink_load () {
fi
echo "$JLINK_TARGET_CMD" >> $GDB_CMD_FILE
echo "mon reset" >> $GDB_CMD_FILE
- echo "restore $FILE_NAME binary $FLASH_OFFSET" >> $GDB_CMD_FILE
+ # gdb restore command cannot handle paths with spaces, use a path
+ # relative to the current directory if possible.
+ echo "restore ${FILE_NAME#"$(pwd)"/} binary $FLASH_OFFSET" >> $GDB_CMD_FILE
# XXXX 'newt run' was not always updating the flash on nrf52dk. With
# 'info reg' in place it seems to work every time. Not sure why.
@@ -153,16 +155,16 @@ jlink_debug() {
if [ -z "$NO_GDB" ]; then
GDB_CMD_FILE=.gdb_cmds
- if [ -z $FILE_NAME ]; then
+ if [ -z "$FILE_NAME" ]; then
echo "Missing filename"
exit 1
fi
if [ ! -f "$FILE_NAME" ]; then
- echo "Cannot find file" $FILE_NAME
+ echo "Cannot find file" "$FILE_NAME"
exit 1
fi
- echo "Debugging" $FILE_NAME
+ echo "Debugging" "$FILE_NAME"
if [ -z $JLINK_TARGET_HOST ]; then
#
@@ -181,7 +183,7 @@ jlink_debug() {
fi
echo "$EXTRA_GDB_CMDS" >> $GDB_CMD_FILE
- $GDB -x $GDB_CMD_FILE $FILE_NAME
+ $GDB -x $GDB_CMD_FILE "$FILE_NAME"
else
$JLINK_GDB_SERVER -device $JLINK_DEV -speed 4000 -if SWD -port $PORT -singlerun $EXTRA_JTAG_CMD
fi
diff --git a/hw/scripts/mplab_ipe.sh b/hw/scripts/mplab_ipe.sh
index a39c6c8c2..ecb90cf79 100644
--- a/hw/scripts/mplab_ipe.sh
+++ b/hw/scripts/mplab_ipe.sh
@@ -17,7 +17,7 @@
# under the License.
#
-. $CORE_PATH/hw/scripts/common.sh
+. "$CORE_PATH"/hw/scripts/common.sh
#
# Programming with Microchip MPLAB IPE command line tool (ipecmd) using
@@ -83,7 +83,7 @@ ipe_prepare_hex() {
if [ "$BOOT_LOADER" -o "$MFG_IMAGE" -o "$MYNEWT_VAL_MCU_NO_BOOTLOADER_BUILD" == "1" ]; then
# ELF contains boot flash and configuration words, xc32-bin2hex
# converts virtual addresses to physical ones.
- xc32-bin2hex ${BIN_BASENAME}.elf || exit 1
+ xc32-bin2hex "${BIN_BASENAME}".elf || exit 1
HEX_FILE=${BIN_BASENAME}.hex
IPE_MEMORY=
IPE_ERASE=
@@ -94,7 +94,7 @@ ipe_prepare_hex() {
fi
HEX_FILE=${BIN_BASENAME}.img.hex
xc32-objcopy -I binary -O ihex --change-addresses ${IMAGE_FLASH_ADDR} \
- ${BIN_BASENAME}.img ${HEX_FILE} || exit 1
+ "${BIN_BASENAME}".img "${HEX_FILE}" || exit 1
# Program memory only, without erase, leave boot flash (bootloader)
# intact. Range limits programming and verification to application
# area, other flash areas may hold data.
@@ -192,7 +192,7 @@ ipe_load() {
echo "Downloading ${HEX_FILE} with ${TOOL}"
# -OL: release device from reset after programming
- if ipe_run -F${HEX_PATH} -M${IPE_MEMORY} ${IPE_ERASE} -OL; then
+ if ipe_run -F"${HEX_PATH}" -M${IPE_MEMORY} ${IPE_ERASE} -OL; then
return
fi
diff --git a/hw/scripts/nrfjprog.sh b/hw/scripts/nrfjprog.sh
index 01045ab53..38a90ca99 100755
--- a/hw/scripts/nrfjprog.sh
+++ b/hw/scripts/nrfjprog.sh
@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
#
-. $CORE_PATH/hw/scripts/common.sh
+. "$CORE_PATH"/hw/scripts/common.sh
jlink_sn () {
if [ -n "$JLINK_SN" ]; then
@@ -32,14 +32,14 @@ jlink_sn () {
# FLASH_OFFSET must contain the offset in flash where to place it
#
nrfjprog_load () {
- if [ -z ${FILE_NAME} ]; then
+ if [ -z "${FILE_NAME}" ]; then
echo "Missing filename"
exit 1
fi
if [ ! -f "${FILE_NAME}" ]; then
# tries stripping current path for readability
FILE=${FILE_NAME##$(pwd)/}
- echo "Cannot find file" $FILE
+ echo "Cannot find file" "$FILE"
exit 1
fi
if [ -z ${FLASH_OFFSET} ]; then
@@ -50,13 +50,13 @@ nrfjprog_load () {
if [ -n "${MYNEWT_VAL_NRFJPROG_COPROCESSOR}" ] ; then
NRFJPROG_ARG="${NRFJPROG_ARG} --coprocessor ${MYNEWT_VAL_NRFJPROG_COPROCESSOR}"
fi
- arm-none-eabi-objcopy -O ihex -I binary --adjust-vma ${FLASH_OFFSET} ${FILE_NAME} ${BIN_BASENAME}.hex
+ arm-none-eabi-objcopy -O ihex -I binary --adjust-vma ${FLASH_OFFSET} "${FILE_NAME}" "${BIN_BASENAME}".hex
jlink_sn
- echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET
+ echo "Downloading" "$FILE_NAME" "to" $FLASH_OFFSET
- nrfjprog ${NRFJPROG_ARG} --program ${BIN_BASENAME}.hex --sectorerase --verify $SRN_ARG
+ nrfjprog ${NRFJPROG_ARG} --program "${BIN_BASENAME}".hex --sectorerase --verify $SRN_ARG
if [ $? -ne 0 ]; then
exit 1
diff --git a/hw/scripts/nrfutil.sh b/hw/scripts/nrfutil.sh
index 03c46d089..08cec2f21 100755
--- a/hw/scripts/nrfutil.sh
+++ b/hw/scripts/nrfutil.sh
@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
#
-. $CORE_PATH/hw/scripts/common.sh
+. "$CORE_PATH"/hw/scripts/common.sh
jlink_sn () {
if [ -n "$JLINK_SN" ]; then
@@ -34,7 +34,7 @@ jlink_sn () {
nrfutil_load () {
HEX_FILE=${BIN_BASENAME}.hex
ELF_FILE=${BIN_BASENAME}.elf
- if [ -z ${FILE_NAME} ]; then
+ if [ -z "${FILE_NAME}" ]; then
echo "Missing filename"
exit 1
fi
@@ -46,17 +46,17 @@ nrfutil_load () {
# If nordicDfu is to be used, create hex file directly from ELF
if [ "${MYNEWT_VAL_NRFUTIL_DFU_MODE:-0}" -eq 1 ] ; then
- arm-none-eabi-objcopy -O ihex ${ELF_FILE} ${HEX_FILE}
+ arm-none-eabi-objcopy -O ihex "${ELF_FILE}" "${HEX_FILE}"
elif [ ! -f "${FILE_NAME}" ]; then
# tries stripping current path for readability
FILE=${FILE_NAME##$(pwd)/}
- echo "Cannot find file" $FILE
+ echo "Cannot find file" "$FILE"
exit 1
elif [ -z ${FLASH_OFFSET} ]; then
echo "Missing flash offset"
exit 1
else
- arm-none-eabi-objcopy -O ihex -I binary --adjust-vma ${FLASH_OFFSET} ${FILE_NAME} ${HEX_FILE}
+ arm-none-eabi-objcopy -O ihex -I binary --adjust-vma ${FLASH_OFFSET} "${FILE_NAME}" "${HEX_FILE}"
fi
if [ -n "${MYNEWT_VAL_NRFJPROG_COPROCESSOR}" ] ; then
@@ -95,19 +95,19 @@ nrfutil_load () {
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}
+ 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
+ if [ -z "${ZIP_FILE}" ] ; then
jlink_sn
- echo "Downloading" ${HEX_FILE}
- nrfutil device program --firmware ${HEX_FILE} ${SRN_ARG} ${NRF_TRAITS_OPT} ${NRFUTIL_ARG} --options chip_erase_mode=ERASE_RANGES_TOUCHED_BY_FIRMWARE
+ echo "Downloading" "${HEX_FILE}"
+ 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
diff --git a/hw/scripts/openocd.sh b/hw/scripts/openocd.sh
index ed6b67338..7bbd2bf55 100755
--- a/hw/scripts/openocd.sh
+++ b/hw/scripts/openocd.sh
@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
#
-. $CORE_PATH/hw/scripts/common.sh
+. "$CORE_PATH"/hw/scripts/common.sh
CFG_RESET="reset halt"
@@ -46,24 +46,24 @@ openocd_load () {
parse_extra_jtag_cmd $EXTRA_JTAG_CMD
if [ $WINDOWS -eq 1 ] ; then
- FILE_NAME=`cygpath -u $FILE_NAME`
+ FILE_NAME=`cygpath -u "$FILE_NAME"`
fi
echo "$EXTRA_JTAG_CMD" > $OCD_CMD_FILE
echo "init" >> $OCD_CMD_FILE
echo "$CFG_RESET" >> $OCD_CMD_FILE
echo "$CFG_POST_INIT" >> $OCD_CMD_FILE
- echo "flash write_image erase $FILE_NAME $FLASH_OFFSET" >> $OCD_CMD_FILE
+ echo "flash write_image erase {$FILE_NAME} $FLASH_OFFSET" >> $OCD_CMD_FILE
openocd_sn
- if [ -z $FILE_NAME ]; then
+ if [ -z "$FILE_NAME" ]; then
echo "Missing filename"
exit 1
fi
if [ ! -f "$FILE_NAME" ]; then
# tries stripping current path for readability
FILE=${FILE_NAME##$(pwd)/}
- echo "Cannot find file" $FILE
+ echo "Cannot find file" "$FILE"
exit 1
fi
if [ -z $FLASH_OFFSET ]; then
@@ -71,7 +71,7 @@ openocd_load () {
exit 1
fi
- echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET
+ echo "Downloading" "$FILE_NAME" "to" $FLASH_OFFSET
openocd $CFG -f $OCD_CMD_FILE $EXTRA_JTAG_CMD -c shutdown
@@ -98,12 +98,12 @@ openocd_debug () {
echo "$EXTRA_JTAG_CMD" >> $OCD_CMD_FILE
if [ -z "$NO_GDB" ]; then
- if [ -z $FILE_NAME ]; then
+ if [ -z "$FILE_NAME" ]; then
echo "Missing filename"
exit 1
fi
if [ ! -f "$FILE_NAME" ]; then
- echo "Cannot find file" $FILE_NAME
+ echo "Cannot find file" "$FILE_NAME"
exit 1
fi
@@ -135,11 +135,11 @@ openocd_debug () {
echo "$EXTRA_GDB_CMDS" >> $GDB_CMD_FILE
if [ $WINDOWS -eq 1 ]; then
- FILE_NAME=`echo $FILE_NAME | sed 's/\//\\\\/g'`
+ FILE_NAME=`echo "$FILE_NAME" | sed 's/\//\\\\/g'`
$COMSPEC /C "start $COMSPEC /C $GDB -x $GDB_CMD_FILE $FILE_NAME"
else
set -m
- $GDB -x $GDB_CMD_FILE $FILE_NAME
+ $GDB -x $GDB_CMD_FILE "$FILE_NAME"
set +m
rm $GDB_CMD_FILE
sleep 1
diff --git a/hw/scripts/pic32_download.sh b/hw/scripts/pic32_download.sh
index 691919f91..49337b77f 100755
--- a/hw/scripts/pic32_download.sh
+++ b/hw/scripts/pic32_download.sh
@@ -44,7 +44,7 @@
# - PIC32_JLINK_SPEED interface speed in kHz (default 12000)
#
-. $CORE_PATH/hw/scripts/jlink.sh
+. "$CORE_PATH"/hw/scripts/jlink.sh
PIC32_DEVICE=${MYNEWT_VAL_JLINK_TARGET}
IMAGE_FLASH_ADDR=${FLASH_OFFSET}
@@ -83,21 +83,24 @@ pic32_jlink_load() {
jlink_sn
local script=${BIN_BASENAME}.jlink
+ # Use paths relative to the current directory if possible, J-Link
+ # commands do not handle paths with spaces.
+ local base=${BIN_BASENAME#"$(pwd)"/}
- echo "r" > $script
- echo "h" >> $script
+ echo "r" > "$script"
+ echo "h" >> "$script"
if [ "$BOOT_LOADER" -o "$MYNEWT_VAL_MCU_NO_BOOTLOADER_BUILD" == "1" ]; then
- xc32-objcopy -O ihex ${BIN_BASENAME}.elf ${BIN_BASENAME}.hex || exit 1
- echo "loadfile ${BIN_BASENAME}.hex" >> $script
+ xc32-objcopy -O ihex "${BIN_BASENAME}".elf "${BIN_BASENAME}".hex || exit 1
+ echo "loadfile ${base}.hex" >> "$script"
else
# J-Link erases only flash pages covered by the image, everything
# else (bootloader, other slots, data areas) is left intact.
- cp ${BIN_BASENAME}.img ${BIN_BASENAME}.bin || exit 1
- echo "loadfile ${BIN_BASENAME}.bin ${IMAGE_FLASH_ADDR}" >> $script
+ cp "${BIN_BASENAME}".img "${BIN_BASENAME}".bin || exit 1
+ echo "loadfile ${base}.bin ${IMAGE_FLASH_ADDR}" >> "$script"
fi
- echo "q" >> $script
+ echo "q" >> "$script"
- pic32_jlink_run -AutoConnect 1 -speed ${PIC32_JLINK_SPEED} -CommandFile $script
+ pic32_jlink_run -AutoConnect 1 -speed ${PIC32_JLINK_SPEED} -CommandFile "$script"
# loadfile prints O.K. when done, J-Link does not always report an error
# when target could not be reached
if ! echo "$JLINK_OUT" | grep -q -E "^O\.K\.[[:space:]]*$"; then
@@ -108,11 +111,11 @@ pic32_jlink_load() {
# Code started by debugger reset and go does not run reliably (first
# context switch never happens). Pulse MCLR without connecting to the
# target instead.
- echo "r0" > $script
- echo "sleep 200" >> $script
- echo "r1" >> $script
- echo "q" >> $script
- pic32_jlink_run -CommandFile $script
+ echo "r0" > "$script"
+ echo "sleep 200" >> "$script"
+ echo "r1" >> "$script"
+ echo "q" >> "$script"
+ pic32_jlink_run -CommandFile "$script"
}
if [ -z "$PIC32_DEVICE" ]; then
@@ -126,7 +129,7 @@ fi
case "${MYNEWT_VAL_MYNEWT_DOWNLOADER}" in
"mplab_ipe")
- . $CORE_PATH/hw/scripts/mplab_ipe.sh
+ . "$CORE_PATH"/hw/scripts/mplab_ipe.sh
# ipecmd expects device name without PIC prefix
MPLAB_DEVICE=${MYNEWT_VAL_MYNEWT_DOWNLOADER_MPLAB_DEVICE:-${PIC32_DEVICE#PIC}}
ipe_load
diff --git a/hw/scripts/pyocd.sh b/hw/scripts/pyocd.sh
index a72c67961..0738fe48f 100755
--- a/hw/scripts/pyocd.sh
+++ b/hw/scripts/pyocd.sh
@@ -16,7 +16,7 @@
# under the License.
#
-. $CORE_PATH/hw/scripts/common.sh
+. "$CORE_PATH"/hw/scripts/common.sh
CONNECTION_MODE_DEFAULT="halt"
@@ -50,14 +50,14 @@ pyocd_load () {
CONNECTION_MODE=$CONNECTION_MODE_DEFAULT
fi
- if [ -z $FILE_NAME ]; then
+ if [ -z "$FILE_NAME" ]; then
echo "Missing filename"
exit 1
fi
if [ ! -f "$FILE_NAME" ]; then
# tries stripping current path for readability
FILE=${FILE_NAME##$(pwd)/}
- echo "Cannot find file" $FILE
+ echo "Cannot find file" "$FILE"
exit 1
fi
if [ -z $FLASH_OFFSET ]; then
@@ -67,9 +67,9 @@ pyocd_load () {
pyocd_sn
- echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET
+ echo "Downloading" "$FILE_NAME" "to" $FLASH_OFFSET
- pyocd flash -e sector -M $CONNECTION_MODE -t $TARGET $FILE_NAME@$FLASH_OFFSET --format bin $UID_ARG
+ pyocd flash -e sector -M $CONNECTION_MODE -t $TARGET "$FILE_NAME"@$FLASH_OFFSET --format bin $UID_ARG
if [ $? -ne 0 ]; then
exit 1
fi
@@ -99,12 +99,12 @@ pyocd_debug () {
fi
if [ -z "$NO_GDB" ]; then
- if [ -z $FILE_NAME ]; then
+ if [ -z "$FILE_NAME" ]; then
echo "Missing filename"
exit 1
fi
if [ ! -f "$FILE_NAME" ]; then
- echo "Cannot find file" $FILE_NAME
+ echo "Cannot find file" "$FILE_NAME"
exit 1
fi
@@ -126,7 +126,7 @@ pyocd_debug () {
echo "$EXTRA_GDB_CMDS" >> $GDB_CMD_FILE
set -m
- $GDB -x $GDB_CMD_FILE $FILE_NAME
+ $GDB -x $GDB_CMD_FILE "$FILE_NAME"
set +m
rm $GDB_CMD_FILE
sleep 1
diff --git a/hw/scripts/stlink.sh b/hw/scripts/stlink.sh
index 0ebe3b946..f65967dfc 100755
--- a/hw/scripts/stlink.sh
+++ b/hw/scripts/stlink.sh
@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
#
-. $CORE_PATH/hw/scripts/common.sh
+. "$CORE_PATH"/hw/scripts/common.sh
#
# FILE_NAME must contain the name of the file to load
@@ -40,14 +40,14 @@ stlink_sn () {
stlink_load () {
stlink_sn
- if [ -z $FILE_NAME ]; then
+ if [ -z "$FILE_NAME" ]; then
echo "Missing filename"
exit 1
fi
if [ ! -f "$FILE_NAME" ]; then
# tries stripping current path for readability
FILE=${FILE_NAME##$(pwd)/}
- echo "Cannot find file" $FILE
+ echo "Cannot find file" "$FILE"
exit 1
fi
if [ -z $FLASH_OFFSET ]; then
@@ -55,12 +55,12 @@ stlink_load () {
exit 1
fi
- echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET
+ echo "Downloading" "$FILE_NAME" "to" $FLASH_OFFSET
if [ "$STLINK_USE_STM32_PROGRAMMER_CLI" == 1 ] ; then
- STM32_Programmer_CLI -c port=SWD $EXTRA_JTAG_CMD -d $FILE_NAME $FLASH_OFFSET -rst
+ STM32_Programmer_CLI -c port=SWD $EXTRA_JTAG_CMD -d "$FILE_NAME" $FLASH_OFFSET -rst
else
- st-flash $EXTRA_JTAG_CMD --reset write $FILE_NAME $FLASH_OFFSET
+ st-flash $EXTRA_JTAG_CMD --reset write "$FILE_NAME" $FLASH_OFFSET
fi
if [ $? -ne 0 ]; then
exit 1
@@ -81,12 +81,12 @@ stlink_debug () {
parse_extra_jtag_cmd $EXTRA_JTAG_CMD
if [ -z "$NO_GDB" ]; then
- if [ -z $FILE_NAME ]; then
+ if [ -z "$FILE_NAME" ]; then
echo "Missing filename"
exit 1
fi
if [ ! -f "$FILE_NAME" ]; then
- echo "Cannot find file" $FILE_NAME
+ echo "Cannot find file" "$FILE_NAME"
exit 1
fi
@@ -108,7 +108,7 @@ stlink_debug () {
echo "$EXTRA_GDB_CMDS" >> $GDB_CMD_FILE
set -m
- $GDB -x $GDB_CMD_FILE $FILE_NAME
+ $GDB -x $GDB_CMD_FILE "$FILE_NAME"
set +m
rm $GDB_CMD_FILE
sleep 1
diff --git a/hw/scripts/stm32_programmer.sh b/hw/scripts/stm32_programmer.sh
index a43f1a89b..263d95385 100755
--- a/hw/scripts/stm32_programmer.sh
+++ b/hw/scripts/stm32_programmer.sh
@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
#
-. $CORE_PATH/hw/scripts/common.sh
+. "$CORE_PATH"/hw/scripts/common.sh
#
# FILE_NAME must contain the name of the file to load
@@ -32,14 +32,14 @@ stlink_sn () {
stlink_load () {
stlink_sn
- if [ -z $FILE_NAME ]; then
+ if [ -z "$FILE_NAME" ]; then
echo "Missing filename"
exit 1
fi
if [ ! -f "$FILE_NAME" ]; then
# tries stripping current path for readability
FILE=${FILE_NAME##$(pwd)/}
- echo "Cannot find file" $FILE
+ echo "Cannot find file" "$FILE"
exit 1
fi
if [ -z $FLASH_OFFSET ]; then
@@ -47,9 +47,9 @@ stlink_load () {
exit 1
fi
- echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET
+ echo "Downloading" "$FILE_NAME" "to" $FLASH_OFFSET
- STM32_Programmer_CLI -c port=SWD $EXTRA_JTAG_CMD -d $FILE_NAME $FLASH_OFFSET -rst
+ STM32_Programmer_CLI -c port=SWD $EXTRA_JTAG_CMD -d "$FILE_NAME" $FLASH_OFFSET -rst
if [ $? -ne 0 ]; then
exit 1
@@ -71,12 +71,12 @@ stlink_debug () {
parse_extra_jtag_cmd $EXTRA_JTAG_CMD
if [ -z "$NO_GDB" ]; then
- if [ -z $FILE_NAME ]; then
+ if [ -z "$FILE_NAME" ]; then
echo "Missing filename"
exit 1
fi
if [ ! -f "$FILE_NAME" ]; then
- echo "Cannot find file" $FILE_NAME
+ echo "Cannot find file" "$FILE_NAME"
exit 1
fi
@@ -84,7 +84,7 @@ stlink_debug () {
# Block Ctrl-C from getting passed to gdb server.
#
set -m
- ST-LINK_gdbserver -d -p $PORT -cp ${CUBEPROGRAMMER_PATH} -g >stlink.log 2>&1 &
+ ST-LINK_gdbserver -d -p $PORT -cp "${CUBEPROGRAMMER_PATH}" -g >stlink.log 2>&1 &
stpid=$!
set +m
@@ -98,7 +98,7 @@ stlink_debug () {
echo "$EXTRA_GDB_CMDS" >> $GDB_CMD_FILE
set -m
- $GDB -x $GDB_CMD_FILE $FILE_NAME
+ $GDB -x $GDB_CMD_FILE "$FILE_NAME"
set +m
rm $GDB_CMD_FILE
sleep 1
@@ -107,7 +107,7 @@ stlink_debug () {
fi
else
# No GDB, wait for ST-LINK_gdbserver to exit
- ST-LINK_gdbserver -d -p $PORT -cp ${CUBEPROGRAMMER_PATH} -g
+ ST-LINK_gdbserver -d -p $PORT -cp "${CUBEPROGRAMMER_PATH}" -g
return $?
fi