diff --git a/Makefile.include b/Makefile.include index 720501151b..72b1039274 100644 --- a/Makefile.include +++ b/Makefile.include @@ -397,11 +397,13 @@ include $(BOARDDIR)/Makefile.include 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))) +# Include emulator code when required and if available +ifeq (1,$(EMULATE)) # Use renode as default emulator RIOT_EMULATOR ?= renode -include $(RIOTMAKE)/tools/$(RIOT_EMULATOR).inc.mk + TERMDEPS += $(EMULATORDEPS) + DEBUGDEPS += $(EMULATORDEPS) endif # Include common serial logic to define TERMPROG, TERMFLAGS variables based on @@ -746,20 +748,10 @@ debug-server: $(call check_cmd,$(DEBUGSERVER),Debug server program) $(DEBUGSERVER) $(DEBUGSERVER_FLAGS) -emulate: all $(EMULATORDEPS) -ifeq (,$(filter term cleanterm debug%,$(MAKECMDGOALS))) +ifeq (1,$(EMULATE)) +emulate: $(call check_cmd,$(EMULATOR),Emulation program) $(EMULATOR) $(EMULATOR_FLAGS) -else - @: -endif - -emulate-only: $(EMULATORDEPS) -ifeq (,$(filter term cleanterm debug%,$(MAKECMDGOALS))) - $(call check_cmd,$(EMULATOR),Emulation program) - $(EMULATOR) $(EMULATOR_FLAGS) -else - @: endif reset: diff --git a/dist/tools/emulator/debug.sh b/dist/tools/emulator/debug.sh index efd5d90423..0b8e457f9f 100755 --- a/dist/tools/emulator/debug.sh +++ b/dist/tools/emulator/debug.sh @@ -45,9 +45,10 @@ trap '' INT # start emulator GDB server sh -c "\ GDB_PORT=${GDB_PORT} \ + EMULATE=1 \ EMULATOR_PIDFILE=${EMULATOR_PIDFILE} \ BOARD=${BOARD} \ - make -C ${APPDIR} emulate-only debug-server & \ + make -C ${APPDIR} 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/emulator/term.sh b/dist/tools/emulator/term.sh index 0a1b183145..7b8f260eb2 100755 --- a/dist/tools/emulator/term.sh +++ b/dist/tools/emulator/term.sh @@ -45,8 +45,9 @@ trap "cleanup terminal for ${EMULATOR} emulator" EXIT # start emulator in background sh -c "\ EMULATOR_PIDFILE=${EMULATOR_PIDFILE} \ + EMULATE=1 \ BOARD=${BOARD} \ - make -C ${APPDIR} emulate-only & \ + make -C ${APPDIR} emulate & \ echo \$! > ${EMULATOR_PIDFILE}" & # with qemu, start socat redirector in background diff --git a/makefiles/tools/qemu.inc.mk b/makefiles/tools/qemu.inc.mk index b013ea103f..a1aa6cb598 100644 --- a/makefiles/tools/qemu.inc.mk +++ b/makefiles/tools/qemu.inc.mk @@ -4,17 +4,19 @@ EMULATOR_MONITOR_PORT ?= 45454 EMULATOR_MONITOR_FLAGS ?= telnet::$(EMULATOR_MONITOR_PORT),server,nowait FLASHFILE ?= $(ELFFILE) +QEMU_SERIAL_TCP_PORT ?= 5555 EMULATOR_FLAGS = -machine $(EMULATOR_MACHINE) -device loader,file=$(ELFFILE) \ - -serial telnet::5555,server,nowait,nodelay \ + -serial telnet::$(QEMU_SERIAL_TCP_PORT),server,nowait,nodelay \ -monitor $(EMULATOR_MONITOR_FLAGS) \ -nographic # Configure the qemu terminal access -PORT = /tmp/riot_$(APPLICATION)_$(BOARD)_uart +EMULATOR_SERIAL_PORT ?= /tmp/riot_$(APPLICATION)_$(BOARD)_uart +PORT = $(EMULATOR_SERIAL_PORT) RIOT_TERMPROG := $(TERMPROG) RIOT_TERMFLAGS := $(TERMFLAGS) TERMPROG := $(RIOTTOOLS)/emulator/term.sh -TERMFLAGS := $(RIOT_EMULATOR) $(BOARD) $(APPDIR) $(RIOT_TERMPROG) '$(RIOT_TERMFLAGS)' $(PORT) +TERMFLAGS := $(RIOT_EMULATOR) $(BOARD) $(APPDIR) $(RIOT_TERMPROG) '$(RIOT_TERMFLAGS)' $(EMULATOR_SERIAL_PORT) # Configure the debugger GDB_PORT ?= 3333 @@ -26,3 +28,7 @@ DEBUGSERVER_FLAGS ?= $(QEMU_DEBUG_FLAGS) DEBUGGER_FLAGS ?= $(BOARD) $(APPDIR) $(ELFFILE) $(GDB_PORT) DEBUGGER ?= $(RIOTTOOLS)/emulator/debug.sh + +# No flasher available with qemu emulator +FLASHER ?= +FFLAGS ?= diff --git a/makefiles/tools/renode.inc.mk b/makefiles/tools/renode.inc.mk index efc8d6a394..0351c5f95c 100644 --- a/makefiles/tools/renode.inc.mk +++ b/makefiles/tools/renode.inc.mk @@ -30,19 +30,21 @@ ifneq (1,$(RENODE_SHOW_GUI)) endif # Configure local serial port -PORT = /tmp/riot_$(APPLICATION)_$(BOARD)_uart -RENODE_CONFIG_FLAGS += -e "emulation CreateUartPtyTerminal \"term\" \"$(PORT)\" true" -RENODE_CONFIG_FLAGS += -e "connector Connect sysbus.uart0 term" +RENODE_SYSBUS_UART ?= sysbus.uart0 +EMULATOR_SERIAL_PORT ?= /tmp/riot_$(APPLICATION)_$(BOARD)_uart +RENODE_CONFIG_FLAGS += -e "emulation CreateUartPtyTerminal \"term\" \"$(EMULATOR_SERIAL_PORT)\" true" +RENODE_CONFIG_FLAGS += -e "connector Connect $(RENODE_SYSBUS_UART) term" # Set emulator variables EMULATOR_FLAGS ?= $(RENODE_CONFIG_FLAGS) -e start EMULATOR ?= $(RENODE) # Configure the terminal +PORT = $(EMULATOR_SERIAL_PORT) RIOT_TERMPROG := $(TERMPROG) RIOT_TERMFLAGS := $(TERMFLAGS) TERMPROG := $(RIOTTOOLS)/emulator/term.sh -TERMFLAGS := $(RIOT_EMULATOR) $(BOARD) $(APPDIR) $(RIOT_TERMPROG) '$(RIOT_TERMFLAGS)' $(PORT) +TERMFLAGS := $(RIOT_EMULATOR) $(BOARD) $(APPDIR) $(RIOT_TERMPROG) '$(RIOT_TERMFLAGS)' $(EMULATOR_SERIAL_PORT) # Configure the debugger GDB_PORT ?= 3333 @@ -54,3 +56,7 @@ DEBUGSERVER_FLAGS ?= $(RENODE_DEBUG_FLAGS) DEBUGGER_FLAGS ?= $(BOARD) $(APPDIR) $(ELFFILE) $(GDB_PORT) "-ex \"monitor start\"" DEBUGGER ?= $(RIOTTOOLS)/emulator/debug.sh + +# No flasher available with renode emulator +FLASHER ?= +FFLAGS ?=