From 6191cd12ec2d4b74c59db945de3297bd5a2334a3 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Mon, 1 May 2017 13:55:10 -0500 Subject: [PATCH] scripts: Add support for 'make debug' using Segger JLink on NXP boards Adds a new debug support script using Segger JLink and configures all NXP boards so they can use it. Tested with Segger JLink GDB server V6.14b and OpenSDA v2.1 firmware. Change-Id: Ia1b297d9c93d21db61379e22f27ae54cda3ad461 Signed-off-by: Maureen Helm --- boards/arm/frdm_k64f/Makefile.board | 4 +- boards/arm/frdm_kl25z/Makefile.board | 5 ++ boards/arm/frdm_kw41z/Makefile.board | 5 ++ boards/arm/hexiwear_k64/Makefile.board | 5 ++ boards/arm/hexiwear_kw40z/Makefile.board | 5 ++ scripts/support/jlink.sh | 67 ++++++++++++++++++++++++ 6 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 boards/arm/frdm_kl25z/Makefile.board create mode 100644 boards/arm/frdm_kw41z/Makefile.board create mode 100644 boards/arm/hexiwear_k64/Makefile.board create mode 100644 boards/arm/hexiwear_kw40z/Makefile.board create mode 100755 scripts/support/jlink.sh diff --git a/boards/arm/frdm_k64f/Makefile.board b/boards/arm/frdm_k64f/Makefile.board index e47333183d6ef6..6684d0a01e5814 100644 --- a/boards/arm/frdm_k64f/Makefile.board +++ b/boards/arm/frdm_k64f/Makefile.board @@ -4,4 +4,6 @@ DEBUG_SCRIPT = openocd.sh OPENOCD_LOAD_CMD = "flash write_image erase ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_ADDRESS}" OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_ADDRESS}" -export FLASH_SCRIPT OPENOCD_LOAD_CMD OPENOCD_VERIFY_CMD +JLINK_DEVICE = MK64FN1M0xxx12 + +export FLASH_SCRIPT OPENOCD_LOAD_CMD OPENOCD_VERIFY_CMD JLINK_DEVICE diff --git a/boards/arm/frdm_kl25z/Makefile.board b/boards/arm/frdm_kl25z/Makefile.board new file mode 100644 index 00000000000000..2823a94f957392 --- /dev/null +++ b/boards/arm/frdm_kl25z/Makefile.board @@ -0,0 +1,5 @@ +DEBUG_SCRIPT = jlink.sh + +JLINK_DEVICE = MKL25Z128xxx4 + +export JLINK_DEVICE diff --git a/boards/arm/frdm_kw41z/Makefile.board b/boards/arm/frdm_kw41z/Makefile.board new file mode 100644 index 00000000000000..3dd9817349447d --- /dev/null +++ b/boards/arm/frdm_kw41z/Makefile.board @@ -0,0 +1,5 @@ +DEBUG_SCRIPT = jlink.sh + +JLINK_DEVICE = MKW41Z512xxx4 + +export JLINK_DEVICE diff --git a/boards/arm/hexiwear_k64/Makefile.board b/boards/arm/hexiwear_k64/Makefile.board new file mode 100644 index 00000000000000..ef762a998e9238 --- /dev/null +++ b/boards/arm/hexiwear_k64/Makefile.board @@ -0,0 +1,5 @@ +DEBUG_SCRIPT = jlink.sh + +JLINK_DEVICE = MK64FN1M0xxx12 + +export JLINK_DEVICE diff --git a/boards/arm/hexiwear_kw40z/Makefile.board b/boards/arm/hexiwear_kw40z/Makefile.board new file mode 100644 index 00000000000000..ad405ee7d8f0cf --- /dev/null +++ b/boards/arm/hexiwear_kw40z/Makefile.board @@ -0,0 +1,5 @@ +DEBUG_SCRIPT = jlink.sh + +JLINK_DEVICE = MKW40Z160xxx4 + +export JLINK_DEVICE diff --git a/scripts/support/jlink.sh b/scripts/support/jlink.sh new file mode 100755 index 00000000000000..30ca46be7a8b74 --- /dev/null +++ b/scripts/support/jlink.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# This script is loosly based on a script with same purpose provided +# by RIOT-OS (https://github.com/RIOT-OS/RIOT) + +JLINK_GDBSERVER=${JLINK_GDBSERVER:-JLinkGDBServer} +JLINK_IF=${JLINK_IF:-swd} +BIN_NAME=${O}/${KERNEL_BIN_NAME} +ELF_NAME=${O}/${KERNEL_ELF_NAME} +GDB_PORT=${GDB_PORT:-2331} + +test_config() { + if ! which ${JLINK_GDBSERVER} >/dev/null 2>&1; then + echo "Error: Unable to locate JLink GDB server: ${JLINK_GDBSERVER}" + exit 1 + fi +} + +test_bin() { + if [ ! -f "${BIN_NAME}" ]; then + echo "Error: Unable to locate image binary: ${BIN_NAME}" + exit 1 + fi +} + +do_debug() { + do_debugserver 1 & + + # connect to the GDB server + ${GDB} ${TUI} ${ELF_NAME} \ + -ex "target remote :${GDB_PORT}" \ + -ex 'monitor halt' \ + -ex 'load' \ + -ex 'monitor reset' +} + +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 "JLink GDB server running on port ${GDB_PORT}" + ${SETSID} ${JLINK_GDBSERVER} \ + -port ${GDB_PORT} \ + -if ${JLINK_IF} \ + -device ${JLINK_DEVICE} \ + -singlerun +} + +CMD="$1" +shift + +case "${CMD}" in + debugserver) + do_debugserver "$@" + ;; + debug) + do_debug "$@" + ;; +esac