zephyr/scripts/support/arc_debugger.sh
Huaqi Fang 9bc69a46fa boards: Update arc em_starterkit support from 2.2 to 2.3
Here are the main changes:
* board: Update EMSK onboard resources such as Button, Switch and LEDs
  + update soc.h for em7d, em9d, em11d
  + update board.h for em_starterkit board
* arc: Add floating point support and code density support
  + add kconfig configuration
  + add compiler options
  + add register definitions, marcos, assembly codes
  + fixes in existing codes and configurations.
* arc: Update detailed board configurations for cores of emsk 2.3
* script: Provide arc_debugger.sh for debugging em_starterkit board
  + make BOARD=em_starterkit debug
    This will start openocd server for emsk, and arc gdb will connect
    to this debug server, user can run `continue` command if user just
    want to run the application, or other commands if debugging needed.
  + make BOARD=em_starterkit debugserver
    This will start an openocd debugger server for emsk, and user can
    connect to this debugserver using arc gdb and do what they want to.
  + make BOARD=em_starterkit flash
    This will download the zephyr application elf file to emsk,
    and run it.

Signed-off-by: Huaqi Fang <huaqi.fang@synopsys.com>
2017-05-19 15:58:41 +02:00

128 lines
3.4 KiB
Bash
Executable File

#!/bin/sh
# This script is loosly based on a script with same purpose provided
# by RIOT-OS (https://github.com/RIOT-OS/RIOT)
OPENOCD=${OPENOCD:-openocd}
OPENOCD_CMD="${OPENOCD}${OPENOCD_DEFAULT_PATH:+ -s $OPENOCD_DEFAULT_PATH}"
OPENOCD_CONFIG=${ZEPHYR_BASE}/boards/${ARCH}/${BOARD_NAME}/support/openocd.cfg
BIN_NAME=${O}/${KERNEL_BIN_NAME}
ELF_NAME=${O}/${KERNEL_ELF_NAME}
test_config() {
if [ ! -f "${OPENOCD_CONFIG}" ]; then
echo "Error: Unable to locate OpenOCD configuration file: ${OPENOCD_CONFIG}"
exit 1
fi
if ! which ${OPENOCD} >/dev/null 2>&1; then
echo "Error: Unable to locate OpenOCD executable: ${OPENOCD}"
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
# setsid is needed so that Ctrl+C in GDB doesn't kill OpenOCD
[ -z "${SETSID}" ] && SETSID="$(which setsid)"
# temporary file that saves OpenOCD pid
OCD_PIDFILE=$(mktemp -t "openocd_pid.XXXXXXXXXX")
# cleanup after script terminates
trap "cleanup ${OCD_PIDFILE}" EXIT
# don't trap on Ctrl+C, because GDB keeps running
trap '' INT
# start OpenOCD as GDB server
${SETSID} sh -c "${OPENOCD_CMD} -f '${OPENOCD_CONFIG}' \
${OPENOCD_EXTRA_INIT} \
-c 'tcl_port ${TCL_PORT:-6333}' \
-c 'telnet_port ${TELNET_PORT:-4444}' \
-c 'gdb_port ${GDB_PORT:-3333}' \
-c 'init' \
-c 'targets' \
-c 'halt' \
& \
echo \$! > $OCD_PIDFILE" &
# connect to the GDB server
${GDB} ${TUI} -ex "target remote :${GDB_PORT:-3333}" \
-ex "load" -ex "c" ${ELF_NAME}
# will be called by trap
cleanup() {
OCD_PID="$(cat $OCD_PIDFILE)"
kill ${OCD_PID} &>/dev/null
rm -f "$OCD_PIDFILE"
exit 0
}
}
do_debug() {
test_config
test_bin
# setsid is needed so that Ctrl+C in GDB doesn't kill OpenOCD
[ -z "${SETSID}" ] && SETSID="$(which setsid)"
# temporary file that saves OpenOCD pid
OCD_PIDFILE=$(mktemp -t "openocd_pid.XXXXXXXXXX")
# cleanup after script terminates
trap "cleanup ${OCD_PIDFILE}" EXIT
# don't trap on Ctrl+C, because GDB keeps running
trap '' INT
# start OpenOCD as GDB server
${SETSID} sh -c "${OPENOCD_CMD} -f '${OPENOCD_CONFIG}' \
${OPENOCD_EXTRA_INIT} \
-c 'tcl_port ${TCL_PORT:-6333}' \
-c 'telnet_port ${TELNET_PORT:-4444}' \
-c 'gdb_port ${GDB_PORT:-3333}' \
-c 'init' \
-c 'targets' \
-c 'halt' \
& \
echo \$! > $OCD_PIDFILE" &
# connect to the GDB server
${GDB} ${TUI} -ex "target remote :${GDB_PORT:-3333}" -ex "load" ${ELF_NAME}
# will be called by trap
cleanup() {
OCD_PID="$(cat $OCD_PIDFILE)"
kill ${OCD_PID} &>/dev/null
rm -f "$OCD_PIDFILE"
exit 0
}
}
do_debugserver() {
test_config
sh -c "${OPENOCD_CMD} -f '${OPENOCD_CONFIG}' \
-c 'init' \
-c 'targets' \
-c 'reset halt'"
}
CMD="$1"
shift
if [ "$KBUILD_VERBOSE" -eq 1 ]
then
set -x
fi
case "${CMD}" in
flash)
echo "Flashing Target Device"
do_flash "$@"
;;
debugserver)
do_debugserver "$@"
;;
debug)
do_debug "$@"
;;
esac