diff --git a/Makefile.include b/Makefile.include index 5407b390de..f2bdb9ff93 100644 --- a/Makefile.include +++ b/Makefile.include @@ -398,7 +398,7 @@ INCLUDES += -I$(RIOTCPU)/$(CPU)/include include $(RIOTCPU)/$(CPU)/Makefile.include # Include emulator code if available and if emulate target is used -ifneq (,$(filter emulate,$(MAKECMDGOALS))) +ifneq (,$(filter emulate%,$(MAKECMDGOALS))) # Use renode as default emulator RIOT_EMULATOR ?= renode -include $(RIOTMAKE)/tools/$(RIOT_EMULATOR).inc.mk @@ -742,9 +742,21 @@ debug-server: $(call check_cmd,$(DEBUGSERVER),Debug server program) $(DEBUGSERVER) $(DEBUGSERVER_FLAGS) -emulate: +emulate: all $(EMULATORDEPS) +ifeq (,$(filter debug%,$(MAKECMDGOALS))) $(call check_cmd,$(EMULATOR),Emulation program) $(EMULATOR) $(EMULATOR_FLAGS) +else + @: +endif + +emulate-only: $(EMULATORDEPS) +ifeq (,$(filter debug%,$(MAKECMDGOALS))) + $(call check_cmd,$(EMULATOR),Emulation program) + $(EMULATOR) $(EMULATOR_FLAGS) +else + @: +endif reset: $(call check_cmd,$(RESET),Reset program) diff --git a/boards/cc2538dk/dist/board.resc b/boards/cc2538dk/dist/board.resc index 3ec9edd893..f077d1d945 100644 --- a/boards/cc2538dk/dist/board.resc +++ b/boards/cc2538dk/dist/board.resc @@ -27,4 +27,3 @@ macro reset """ runMacro $reset -start diff --git a/boards/firefly/dist/board.resc b/boards/firefly/dist/board.resc index 6496d10f1b..b73b022795 100644 --- a/boards/firefly/dist/board.resc +++ b/boards/firefly/dist/board.resc @@ -29,4 +29,3 @@ macro reset """ runMacro $reset -start diff --git a/boards/hifive1/dist/board.resc b/boards/hifive1/dist/board.resc index 0e90f854f2..9db3a1c3bc 100644 --- a/boards/hifive1/dist/board.resc +++ b/boards/hifive1/dist/board.resc @@ -21,4 +21,3 @@ macro reset """ runMacro $reset -start diff --git a/boards/hifive1b/dist/board.resc b/boards/hifive1b/dist/board.resc index 7c08b025a5..9a52b02a3e 100644 --- a/boards/hifive1b/dist/board.resc +++ b/boards/hifive1b/dist/board.resc @@ -21,4 +21,3 @@ macro reset """ runMacro $reset -start diff --git a/dist/tools/renode/renode-debug.sh b/dist/tools/renode/renode-debug.sh new file mode 100755 index 0000000000..4db5c24253 --- /dev/null +++ b/dist/tools/renode/renode-debug.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +# This script wraps Renode emulator GDB server and a debugger +# client in a single command and takes 4 arguments: the board to emulate, +# the application directory of the the current application, the elffile +# containing the firmware to debug, the debugger port and custom debugger client +# arguments + +# This script is supposed to be called from RIOTs make system when using the +# "debug" target. + +# @author Alexandre Abadie + +BOARD=$1 +APPDIR=$2 +ELFFILE=$3 + +# GDB command, usually a separate command for each platform (e.g. arm-none-eabi-gdb) +: ${GDB:=gdb-multiarch} +# Debugger client command, can be used to wrap GDB in a front-end +: ${DBG:=${GDB}} +# Default GDB port, set to 0 to disable, required != 0 for debug and debug-server targets +: ${GDB_PORT:=$4} +# Default debugger flags, +: ${DBG_DEFAULT_FLAGS:=-q -ex \"target remote :${GDB_PORT}\"} +# Custom extra debugger flags, depends on the emulator +: ${DBG_CUSTOM_FLAGS:=$5} +# Debugger flags, will be passed to sh -c, remember to escape any quotation signs. +# Use ${DBG_DEFAULT_FLAGS} to insert the default flags anywhere in the string +: ${DBG_FLAGS:=${DBG_DEFAULT_FLAGS} ${DBG_CUSTOM_FLAGS}} + +# temporary file that contains the emulator pid +EMULATOR_PIDFILE=$(mktemp -t "emulator_pid.XXXXXXXXXX") +# will be called by trap +cleanup() { + kill "$(cat ${EMULATOR_PIDFILE})" + rm -f "${EMULATOR_PIDFILE}" + exit 0 +} +# cleanup after script terminates +trap "cleanup ${EMULATOR_PIDFILE}" EXIT +# don't trap on Ctrl+C, because GDB keeps running +trap '' INT + +# start Renode GDB server +sh -c "\ + GDB_PORT=${GDB_PORT} \ + EMULATOR_PIDFILE=${EMULATOR_PIDFILE} \ + BOARD=${BOARD} \ + make -C ${APPDIR} emulate-only debug-server & \ + echo \$! > ${EMULATOR_PIDFILE}" & +# Start the debugger and connect to the GDB server +sh -c "${DBG} ${DBG_FLAGS} ${ELFFILE}" diff --git a/dist/tools/renode/run-renode.sh b/dist/tools/renode/run-renode.sh deleted file mode 100755 index 8b20e6be14..0000000000 --- a/dist/tools/renode/run-renode.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh - -# -# Unified Renode script for RIOT -# -# This script is supposed to be called from RIOTs make system, -# as it depends on certain environment variables. -# -# It will start the Renode emulator, providing it with several environment -# variables: -# $image_file Full path to the image file (see $IMAGE_FILE below) -# -# Global environment variables used: -# RENODE: Renode command name, default: "renode" -# RENODE_CONFIG: Renode configuration file name, -# default: "${BOARDSDIR}/${BOARD}/dist/board.resc" -# RENODE_BIN_CONFIG: Renode intermediate configuration file name, -# default: "${BINDIR}/board.resc" -# -# @author Bas Stottelaar - -# Default path to Renode configuration file -: ${RENODE_CONFIG:=${BOARDSDIR}/${BOARD}/dist/board.resc} -# Default path to Renode intermediate configuration file -: ${RENODE_BIN_CONFIG:=${BINDIR}/board.resc} -# Default Renode command -: ${RENODE:=renode} -# Image file used for emulation -# Default is to use $ELFFILE -: ${IMAGE_FILE:=${ELFFILE}} - -# -# config test section. -# -test_config() { - if [ ! -f "${RENODE_CONFIG}" ]; then - echo "Error: Unable to locate Renode board file" - echo " (${RENODE_CONFIG})" - exit 1 - fi -} - -# -# helper section. -# -write_config() { - echo "\$image_file = '${IMAGE_FILE}'" > "${RENODE_BIN_CONFIG}" - echo "include @${RENODE_CONFIG}" >> "${RENODE_BIN_CONFIG}" -} - -# -# now comes the actual actions -# -do_write() { - test_config - write_config - echo "Script written to '${RENODE_BIN_CONFIG}'" -} - -do_start() { - test_config - write_config - sh -c "${RENODE} '${RENODE_BIN_CONFIG}'" -} - -# -# parameter dispatching -# -ACTION="$1" - -case "${ACTION}" in - write) - echo "### Writing emulation script ###" - do_write - ;; - start) - echo "### Starting Renode ###" - do_start - ;; - *) - echo "Usage: $0 {write|start}" - exit 2 - ;; -esac diff --git a/makefiles/tools/adafruit-nrfutil.inc.mk b/makefiles/tools/adafruit-nrfutil.inc.mk index eea4ba8024..73c395faf2 100644 --- a/makefiles/tools/adafruit-nrfutil.inc.mk +++ b/makefiles/tools/adafruit-nrfutil.inc.mk @@ -1,6 +1,6 @@ FLASHFILE = $(HEXFILE) FLASHDEPS += $(HEXFILE).zip -FLASHER = adafruit-nrfutil +FLASHER ?= adafruit-nrfutil FFLAGS = dfu serial --port=${PORT} --baudrate=${BAUD} --touch=1200 --package=$(HEXFILE).zip --singlebank %.hex.zip: %.hex diff --git a/makefiles/tools/avrdude.inc.mk b/makefiles/tools/avrdude.inc.mk index 85bb78492f..29f9371f10 100644 --- a/makefiles/tools/avrdude.inc.mk +++ b/makefiles/tools/avrdude.inc.mk @@ -1,8 +1,8 @@ -FLASHER = avrdude +FLASHER ?= avrdude DIST_PATH = $(BOARDDIR)/dist AVARICE_PATH = $(RIOTTOOLS)/avarice DEBUGSERVER_PORT = 4242 -DEBUGSERVER = $(AVARICE_PATH)/debug_srv.sh +DEBUGSERVER ?= $(AVARICE_PATH)/debug_srv.sh # Allow choosing debugger hardware via AVR_DEBUGDEVICE, default to Atmel ICE, # which is compatible to all AVR devices and since the AVR Dragon is no longer # produced, the least expensive option @@ -15,8 +15,8 @@ else # Use JTAG as protocol for debugging DEBUGPROTO := -j $(AVR_DEBUGINTERFACE) endif -DEBUGSERVER_FLAGS = "$(AVR_DEBUGDEVICE) $(DEBUGPROTO) :$(DEBUGSERVER_PORT)" -DEBUGGER_FLAGS = "-x $(AVARICE_PATH)/gdb.conf $(ELFFILE)" +DEBUGSERVER_FLAGS ?= "$(AVR_DEBUGDEVICE) $(DEBUGPROTO) :$(DEBUGSERVER_PORT)" +DEBUGGER_FLAGS ?= "-x $(AVARICE_PATH)/gdb.conf $(ELFFILE)" DEBUGGER = "$(AVARICE_PATH)/debug.sh" $(DEBUGSERVER_FLAGS) $(AVARICE_PATH) $(DEBUGSERVER_PORT) AVRDUDE_PROGRAMMER_FLAGS = -p $(subst atmega,m,$(CPU)) diff --git a/makefiles/tools/bmp.inc.mk b/makefiles/tools/bmp.inc.mk index 208793e211..47503b9722 100644 --- a/makefiles/tools/bmp.inc.mk +++ b/makefiles/tools/bmp.inc.mk @@ -1,5 +1,5 @@ FLASHER ?= $(RIOTTOOLS)/bmp/bmp.py -DEBUGGER = $(RIOTTOOLS)/bmp/bmp.py +DEBUGGER ?= $(RIOTTOOLS)/bmp/bmp.py RESET ?= $(RIOTTOOLS)/bmp/bmp.py FLASHFILE ?= $(ELFFILE) diff --git a/makefiles/tools/cc2538-bsl.inc.mk b/makefiles/tools/cc2538-bsl.inc.mk index cb9bcf7c36..6b55640338 100644 --- a/makefiles/tools/cc2538-bsl.inc.mk +++ b/makefiles/tools/cc2538-bsl.inc.mk @@ -1,5 +1,5 @@ FLASHFILE ?= $(BINFILE) -FLASHER = $(RIOTTOOLS)/cc2538-bsl/cc2538-bsl.py +FLASHER ?= $(RIOTTOOLS)/cc2538-bsl/cc2538-bsl.py FFLAGS_OPTS ?= PROG_BAUD ?= 500000 # default value in cc2538-bsl diff --git a/makefiles/tools/jlink.inc.mk b/makefiles/tools/jlink.inc.mk index 149a6183d6..83a7c0c482 100644 --- a/makefiles/tools/jlink.inc.mk +++ b/makefiles/tools/jlink.inc.mk @@ -1,6 +1,6 @@ FLASHER = $(RIOTTOOLS)/jlink/jlink.sh -DEBUGGER = $(RIOTTOOLS)/jlink/jlink.sh -DEBUGSERVER = $(RIOTTOOLS)/jlink/jlink.sh +DEBUGGER ?= $(RIOTTOOLS)/jlink/jlink.sh +DEBUGSERVER ?= $(RIOTTOOLS)/jlink/jlink.sh RESET ?= $(RIOTTOOLS)/jlink/jlink.sh FLASHFILE ?= $(BINFILE) diff --git a/makefiles/tools/openocd.inc.mk b/makefiles/tools/openocd.inc.mk index e2c4324db5..a67db84f1b 100644 --- a/makefiles/tools/openocd.inc.mk +++ b/makefiles/tools/openocd.inc.mk @@ -1,6 +1,6 @@ FLASHER ?= $(RIOTTOOLS)/openocd/openocd.sh -DEBUGGER = $(RIOTTOOLS)/openocd/openocd.sh -DEBUGSERVER = $(RIOTTOOLS)/openocd/openocd.sh +DEBUGGER ?= $(RIOTTOOLS)/openocd/openocd.sh +DEBUGSERVER ?= $(RIOTTOOLS)/openocd/openocd.sh RESET ?= $(RIOTTOOLS)/openocd/openocd.sh FLASHFILE ?= $(ELFFILE) diff --git a/makefiles/tools/pyocd.inc.mk b/makefiles/tools/pyocd.inc.mk index c23ff60057..087ab9b118 100644 --- a/makefiles/tools/pyocd.inc.mk +++ b/makefiles/tools/pyocd.inc.mk @@ -1,6 +1,6 @@ FLASHER ?= $(RIOTBASE)/dist/tools/pyocd/pyocd.sh -DEBUGGER = $(RIOTBASE)/dist/tools/pyocd/pyocd.sh -DEBUGSERVER = $(RIOTBASE)/dist/tools/pyocd/pyocd.sh +DEBUGGER ?= $(RIOTBASE)/dist/tools/pyocd/pyocd.sh +DEBUGSERVER ?= $(RIOTBASE)/dist/tools/pyocd/pyocd.sh RESET ?= $(RIOTBASE)/dist/tools/pyocd/pyocd.sh FLASH_TARGET_TYPE ?= diff --git a/makefiles/tools/qemu.inc.mk b/makefiles/tools/qemu.inc.mk index 9644dfcee5..9e5732b784 100644 --- a/makefiles/tools/qemu.inc.mk +++ b/makefiles/tools/qemu.inc.mk @@ -2,6 +2,7 @@ EMULATOR ?= qemu-system-arm EMULATOR_MACHINE ?= $(BOARD) EMULATOR_MONITOR_PORT ?= 45454 EMULATOR_MONITOR_FLAGS ?= telnet::$(EMULATOR_MONITOR_PORT),server,nowait +FLASHFILE ?= $(ELFFILE) EMULATOR_FLAGS = -machine $(EMULATOR_MACHINE) -device loader,file=$(ELFFILE) \ -serial stdio \ diff --git a/makefiles/tools/renode.inc.mk b/makefiles/tools/renode.inc.mk index ecd82f4132..0335fe0372 100644 --- a/makefiles/tools/renode.inc.mk +++ b/makefiles/tools/renode.inc.mk @@ -1,2 +1,31 @@ -EMULATOR ?= $(RIOTTOOLS)/renode/run-renode.sh -EMULATOR_FLAGS ?= start +RENODE ?= renode +RENODE_IMAGE_FILE ?= $(ELFFILE) +RENODE_BOARD_CONFIG ?= $(BOARDDIR)/dist/board.resc + +# Global build system configurations +FLASHFILE ?= $(ELFFILE) +EMULATORDEPS += $(RENODE_BOARD_CONFIG) + +# Use renode interactive commands to specify the image file and board config +RENODE_CONFIG_FLAGS += -e "set image_file '$(RENODE_IMAGE_FILE)'" +RENODE_CONFIG_FLAGS += -e "include @$(RENODE_BOARD_CONFIG)" + +# Set emulator variables +EMULATOR_FLAGS ?= $(RENODE_CONFIG_FLAGS) -e start +EMULATOR ?= $(RENODE) + +# Configure the debugger +GDB_PORT ?= 3333 +EMULATOR_PIDFILE ?= +ifneq (,$(EMULATOR_PIDFILE)) + $(info Using Renode pid file $(EMULATOR_PIDFILE)) + RENODE_CONFIG_FLAGS += --pid-file $(EMULATOR_PIDFILE) +endif +RENODE_DEBUG_FLAGS += $(RENODE_CONFIG_FLAGS) +RENODE_DEBUG_FLAGS += -e "machine StartGdbServer $(GDB_PORT) true" + +DEBUGSERVER ?= $(EMULATOR) +DEBUGSERVER_FLAGS ?= $(RENODE_DEBUG_FLAGS) + +DEBUGGER_FLAGS ?= $(BOARD) $(APPDIR) $(ELFFILE) $(GDB_PORT) "-ex \"monitor start\"" +DEBUGGER ?= $(RIOTTOOLS)/renode/renode-debug.sh diff --git a/makefiles/tools/uniflash.inc.mk b/makefiles/tools/uniflash.inc.mk index 5845044063..2e66f3d921 100644 --- a/makefiles/tools/uniflash.inc.mk +++ b/makefiles/tools/uniflash.inc.mk @@ -29,9 +29,9 @@ endif CCS_PATH ?= "CCS_PATH unconfigured" # configure the debug server -DEBUGSERVER = $(CCS_PATH)/ccs/ccs_base/common/uscif/gdb_agent_console -DEBUGSERVER_FLAGS = -p 3333 $(UNIFLASH_CONFIG_DAT) +DEBUGSERVER ?= $(CCS_PATH)/ccs/ccs_base/common/uscif/gdb_agent_console +DEBUGSERVER_FLAGS ?= -p 3333 $(UNIFLASH_CONFIG_DAT) # configure the debugging tool -DEBUGGER = $(PREFIX)gdb -DEBUGGER_FLAGS = -x $(UNIFLASH_CONFIG_GDB) $(ELFFILE) +DEBUGGER ?= $(PREFIX)gdb +DEBUGGER_FLAGS ?= -x $(UNIFLASH_CONFIG_GDB) $(ELFFILE)