hw/scripts: Add option for remote load/debug using J-Link
This adds support for JLINK_REMOTE env to specify remote JLinkGDBServer
instance to connect to. If specified (as 'host:port' or just 'host' to
use default 2331 port), both 'load' and 'debug' won't spawn local server
process and will instead try to connect to specified one.
JLINK_GDB_SERVER=JLinkGDBServer
+jlink_target_cmd () {
+ if [ -z $JLINK_REMOTE ]; then
+ JLINK_TARGET_CMD="target remote localhost:$PORT"
+ else
+ JLINK_TARGET_HOST=`echo $JLINK_REMOTE | cut -d : -f 1 -s`
+ if [ -z $JLINK_TARGET_HOST ]; then
+ JLINK_TARGET_HOST=$JLINK_REMOTE
+ JLINK_TARGET_PORT=2331
+ else
+ JLINK_TARGET_PORT=`echo $JLINK_REMOTE | cut -d : -f 2`
+ fi
+ JLINK_TARGET_CMD="target remote $JLINK_TARGET_HOST:$JLINK_TARGET_PORT"
+ fi
+}
+
#
# FILE_NAME is the file to load
# FLASH_OFFSET is location in the flash
@@ -30,6 +45,7 @@ jlink_load () {
windows_detect
parse_extra_jtag_cmd $EXTRA_JTAG_CMD
+ jlink_target_cmd
if [ $WINDOWS -eq 1 ]; then
JLINK_GDB_SERVER=JLinkGDBServerCL
@@ -55,8 +71,10 @@ jlink_load () {
# downloading somewhere in the flash. So need to figure out how to tell it
# not to do that, or report failure if gdb fails to write this file
#
+ if [ -z $JLINK_TARGET_HOST]; then
echo "shell sh -c \"trap '' 2; $JLINK_GDB_SERVER -device $JLINK_DEV -speed 1000 -if SWD -port $PORT -singlerun $EXTRA_JTAG_CMD &\" " > $GDB_CMD_FILE
- echo "target remote localhost:$PORT" >> $GDB_CMD_FILE
+ fi
+ echo "$JLINK_TARGET_CMD" >> $GDB_CMD_FILE
echo "mon reset" >> $GDB_CMD_FILE
echo "restore $FILE_NAME binary $FLASH_OFFSET" >> $GDB_CMD_FILE
@@ -118,6 +136,7 @@ jlink_debug() {
JLINK_GDB_SERVER=JLinkGDBServerCL
fi
parse_extra_jtag_cmd $EXTRA_JTAG_CMD
+ jlink_target_cmd
if [ -z "$NO_GDB" ]; then
GDB_CMD_FILE=.gdb_cmds
@@ -133,6 +152,7 @@ jlink_debug() {
echo "Debugging" $FILE_NAME
+ if [ -z $JLINK_TARGET_HOST]; then
if [ $WINDOWS -eq 1 ]; then
#
# Launch jlink server in a separate command interpreter, to make
@@ -147,8 +167,9 @@ jlink_debug() {
$JLINK_GDB_SERVER -device $JLINK_DEV -speed 4000 -if SWD -port $PORT -singlerun $EXTRA_JTAG_CMD > /dev/null &
set +m
fi
+ fi
- echo "target remote localhost:$PORT" > $GDB_CMD_FILE
+ echo "$JLINK_TARGET_CMD" > $GDB_CMD_FILE
# Whether target should be reset or not
if [ ! -z "$RESET" ]; then
echo "mon reset" >> $GDB_CMD_FILE
