mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #15512 from aabadie/pr/tools/emulator_term
tools/emulator: allow use with *term targets + introduce EMULATE=1 instead of emulate target
This commit is contained in:
commit
4736a881fc
@ -397,17 +397,19 @@ 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)))
|
||||
# Use renode as default emulator
|
||||
RIOT_EMULATOR ?= renode
|
||||
-include $(RIOTMAKE)/tools/$(RIOT_EMULATOR).inc.mk
|
||||
endif
|
||||
|
||||
# Include common serial logic to define TERMPROG, TERMFLAGS variables based on
|
||||
# the content of RIOT_TERMINAL
|
||||
include $(RIOTMAKE)/tools/serial.inc.mk
|
||||
|
||||
# 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 programmer logic if available
|
||||
-include $(RIOTMAKE)/tools/$(PROGRAMMER).inc.mk
|
||||
|
||||
@ -746,20 +748,10 @@ debug-server:
|
||||
$(call check_cmd,$(DEBUGSERVER),Debug server program)
|
||||
$(DEBUGSERVER) $(DEBUGSERVER_FLAGS)
|
||||
|
||||
emulate: all $(EMULATORDEPS)
|
||||
ifeq (,$(filter debug%,$(MAKECMDGOALS)))
|
||||
ifeq (1,$(EMULATE))
|
||||
emulate:
|
||||
$(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:
|
||||
|
@ -94,6 +94,6 @@ Use it like this:
|
||||
|
||||
$ cd examples/hello-world
|
||||
$ BOARD=microbit make clean all -j4
|
||||
$ BOARD=microbit make emulate
|
||||
$ EMULATE=1 BOARD=microbit make term
|
||||
|
||||
*/
|
||||
|
@ -9,3 +9,6 @@ PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*)))
|
||||
PROGRAMMER ?= openocd
|
||||
DEBUG_ADAPTER ?= stlink
|
||||
STLINK_VERSION ?= 2
|
||||
|
||||
# Tell renode on which UART stdio is available
|
||||
RENODE_SYSBUS_UART ?= sysbus.uart2
|
||||
|
@ -172,7 +172,7 @@ To emulate this board you need an updated version of
|
||||
[renode](https://github.com/renode/renode) installed, at least version 1.11.
|
||||
|
||||
```
|
||||
BOARD=stm32f4discovery make all emulate
|
||||
EMULATE=1 BOARD=stm32f4discovery make all term
|
||||
```
|
||||
|
||||
## Known Issues / Problems
|
||||
|
3
dist/tools/emulator/debug.sh
vendored
3
dist/tools/emulator/debug.sh
vendored
@ -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}"
|
||||
|
68
dist/tools/emulator/term.sh
vendored
Executable file
68
dist/tools/emulator/term.sh
vendored
Executable file
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script wraps an emulator (renode or qemu) and a terminal client
|
||||
# in a single command and takes 6 arguments:
|
||||
# 1. the type of emulator (renode or qemu)
|
||||
# 2. the board to emulate,
|
||||
# 3. the application directory of the the current application
|
||||
# 4. the terminal client tool
|
||||
# 5. the options of the terminal client
|
||||
# 6. the serial port to connect to the terminal client to
|
||||
|
||||
# This script is supposed to be called from RIOTs make system when using the
|
||||
# "term" or "cleanterm" targets.
|
||||
|
||||
# @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
|
||||
EMULATOR=$1
|
||||
BOARD=$2
|
||||
APPDIR=$3
|
||||
TERMPROG=$4
|
||||
TERMFLAGS=$5
|
||||
PORT=$6
|
||||
|
||||
# temporary file that contains the emulator pid
|
||||
EMULATOR_PIDFILE=$(mktemp -t "emulator_pid.XXXXXXXXXX")
|
||||
SOCAT_PIDFILE=$(mktemp -t "socat_pid.XXXXXXXXXX")
|
||||
|
||||
# will be called by trap
|
||||
cleanup() {
|
||||
if [ ${EMULATOR} = "qemu" ]
|
||||
then
|
||||
echo "cleanup ${SOCAT_PIDFILE}"
|
||||
kill "$(cat ${SOCAT_PIDFILE})"
|
||||
rm -f "${SOCAT_PIDFILE}"
|
||||
fi
|
||||
echo "cleanup ${EMULATOR_PIDFILE}"
|
||||
kill "$(cat ${EMULATOR_PIDFILE})"
|
||||
rm -f "${EMULATOR_PIDFILE}"
|
||||
rm -f ${PORT}
|
||||
exit 0
|
||||
}
|
||||
# cleanup after script terminates
|
||||
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 & \
|
||||
echo \$! > ${EMULATOR_PIDFILE}" &
|
||||
|
||||
# with qemu, start socat redirector in background
|
||||
if [ ${EMULATOR} = "qemu" ]
|
||||
then
|
||||
sleep 1
|
||||
sh -c "\
|
||||
socat pty,link=${PORT},raw,echo=0 TCP:localhost:5555 & \
|
||||
echo \$! > ${SOCAT_PIDFILE}" &
|
||||
fi
|
||||
|
||||
# Start the terminal client after PORT is available. PORT can be a symlink.
|
||||
while [ ! -L "${PORT}" ]
|
||||
do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
sh -c "${TERMPROG} ${TERMFLAGS}"
|
@ -1,13 +1,25 @@
|
||||
EMULATOR ?= qemu-system-arm
|
||||
EMULATOR_MACHINE ?= $(BOARD)
|
||||
EMULATOR_MONITOR_PORT ?= 45454
|
||||
EMULATOR_MONITOR_FLAGS ?= telnet::$(EMULATOR_MONITOR_PORT),server,nowait
|
||||
QEMU ?= qemu-system-arm
|
||||
QEMU_MACHINE ?= $(BOARD)
|
||||
QEMU_MONITOR_PORT ?= 45454
|
||||
QEMU_MONITOR_FLAGS ?= telnet::$(QEMU_MONITOR_PORT),server,nowait
|
||||
FLASHFILE ?= $(ELFFILE)
|
||||
|
||||
EMULATOR_FLAGS = -machine $(EMULATOR_MACHINE) -device loader,file=$(ELFFILE) \
|
||||
-serial stdio \
|
||||
-monitor $(EMULATOR_MONITOR_FLAGS) \
|
||||
-nographic
|
||||
QEMU_SERIAL_TCP_PORT ?= 5555
|
||||
|
||||
# Configure emulator variables
|
||||
EMULATOR ?= $(QEMU)
|
||||
EMULATOR_FLAGS ?= -machine $(QEMU_MACHINE) -device loader,file=$(ELFFILE) \
|
||||
-serial telnet::$(QEMU_SERIAL_TCP_PORT),server,nowait,nodelay \
|
||||
-monitor $(QEMU_MONITOR_FLAGS) \
|
||||
-nographic
|
||||
|
||||
# Configure the qemu terminal access
|
||||
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)' $(EMULATOR_SERIAL_PORT)
|
||||
|
||||
# Configure the debugger
|
||||
GDB_PORT ?= 3333
|
||||
@ -19,3 +31,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 ?=
|
||||
|
@ -9,18 +9,45 @@ 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 logging configuration
|
||||
RENODE_SHOW_LOG ?= 0
|
||||
ifneq (1,$(RENODE_SHOW_LOG))
|
||||
RENODE_CONFIG_FLAGS += --hide-log
|
||||
endif
|
||||
RENODE_LOG_LEVEL ?= 2 # Warning level
|
||||
RENODE_CONFIG_FLAGS += -e "logLevel $(RENODE_LOG_LEVEL)"
|
||||
|
||||
# Renode GUI
|
||||
RENODE_SHOW_GUI ?= 0
|
||||
ifneq (1,$(RENODE_SHOW_GUI))
|
||||
RENODE_CONFIG_FLAGS += --disable-xwt
|
||||
endif
|
||||
|
||||
# Configure local serial port
|
||||
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)' $(EMULATOR_SERIAL_PORT)
|
||||
|
||||
# Configure the debugger
|
||||
GDB_PORT ?= 3333
|
||||
RENODE_DEBUG_FLAGS += $(RENODE_CONFIG_FLAGS)
|
||||
RENODE_DEBUG_FLAGS += -e "machine StartGdbServer $(GDB_PORT) true"
|
||||
|
||||
@ -29,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 ?=
|
||||
|
Loading…
Reference in New Issue
Block a user