scripts: Add flash and debug support using pyOCD on NXP boards

Adds a new debug support script using pyOCD and configures most NXP
boards so they can use it. frdm_kw41z is the one exception because pyOCD
doesn't yet support kw41z. Tested with pyOCD v0.8.0 and the latest
DAPLink firmware for each board.

Introduces two new environment variables, PYOCD_FLASHTOOL and
PYOCD_GDBSERVER, that allow you to set custom paths to the pyOCD tools.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
This commit is contained in:
Maureen Helm 2017-05-10 16:12:14 -05:00 committed by Anas Nashif
commit f49e199c27
5 changed files with 90 additions and 4 deletions

View file

@ -6,4 +6,6 @@ OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_A
JLINK_DEVICE = MK64FN1M0xxx12
export FLASH_SCRIPT OPENOCD_LOAD_CMD OPENOCD_VERIFY_CMD JLINK_DEVICE
PYOCD_TARGET = k64f
export FLASH_SCRIPT OPENOCD_LOAD_CMD OPENOCD_VERIFY_CMD JLINK_DEVICE PYOCD_TARGET

View file

@ -2,4 +2,6 @@ DEBUG_SCRIPT = jlink.sh
JLINK_DEVICE = MKL25Z128xxx4
export JLINK_DEVICE
PYOCD_TARGET = kl25z
export JLINK_DEVICE PYOCD_TARGET

View file

@ -2,4 +2,6 @@ DEBUG_SCRIPT = jlink.sh
JLINK_DEVICE = MK64FN1M0xxx12
export JLINK_DEVICE
PYOCD_TARGET = k64f
export JLINK_DEVICE PYOCD_TARGET

View file

@ -2,4 +2,6 @@ DEBUG_SCRIPT = jlink.sh
JLINK_DEVICE = MKW40Z160xxx4
export JLINK_DEVICE
PYOCD_TARGET = kw40z4
export JLINK_DEVICE PYOCD_TARGET

78
scripts/support/pyocd.sh Executable file
View file

@ -0,0 +1,78 @@
#!/bin/sh
# This script is loosly based on a script with same purpose provided
# by RIOT-OS (https://github.com/RIOT-OS/RIOT)
PYOCD_FLASHTOOL=${PYOCD_FLASHTOOL:-pyocd-flashtool}
PYOCD_GDBSERVER=${PYOCD_GDBSERVER:-pyocd-gdbserver}
BIN_NAME=${O}/${KERNEL_BIN_NAME}
ELF_NAME=${O}/${KERNEL_ELF_NAME}
GDB_PORT=${GDB_PORT:-3333}
test_config() {
if ! which ${PYOCD_FLASHTOOL} >/dev/null 2>&1; then
echo "Error: Unable to locate pyOCD flash tool: ${PYOCD_FLASHTOOL}"
exit 1
fi
if ! which ${PYOCD_GDBSERVER} >/dev/null 2>&1; then
echo "Error: Unable to locate pyOCD GDB server: ${PYOCD_GDBSERVER}"
exit 1
fi
}
test_bin() {
if [ ! -f "${BIN_NAME}" ]; then
echo "Error: Unable to locate image binary: ${BIN_NAME}"
exit 1
fi
}
do_flash() {
test_config
test_bin
# flash device with specified image
echo "Flashing Target Device"
${PYOCD_FLASHTOOL} -t ${PYOCD_TARGET} ${BIN_NAME}
}
do_debug() {
do_debugserver 1 &
# connect to the GDB server
${GDB} ${TUI} ${ELF_NAME} \
-ex "target remote :${GDB_PORT}" \
-ex 'load' \
-ex 'monitor reset halt'
}
do_debugserver() {
test_config
# Calling with an arg will result in setsid being used, which will prevent
# Ctrl-C in GDB from killing the server. The server automatically exits
# when the remote GDB disconnects.
if [ -n "$1" ]; then
SETSID=/usr/bin/setsid
else
SETSID=
fi
echo "pyOCD GDB server running on port ${GDB_PORT}"
${SETSID} ${PYOCD_GDBSERVER} -p ${GDB_PORT} -t ${PYOCD_TARGET}
}
CMD="$1"
shift
case "${CMD}" in
flash)
do_flash "$@"
;;
debugserver)
do_debugserver "$@"
;;
debug)
do_debug "$@"
;;
esac