Files
obsw/DEBUG_ON_QEMU.md
T
2025-10-28 14:53:43 +01:00

2.4 KiB

Qemu

qemu is an emulator which can be used to run code compiled for a different architecture (say ARMv7 as on zynq) on the host architecture (the PC you are using).

This is mainly useful for testing platform dependent code, in our case the operating system abstraction. This code can not be tested on linux, as the FreeRTOS port used is a different one.

By selecting the ZYNQ_SEMIHOSTING in cmake, the semihosting interface is enabled. This allows the software to signal an exit condition to qemu, which in turn makes qemu exit with the corresponding exit code. This functionality is used for unit testing, where the exit condition is needed to signal success or failure of the unit tests.

Run on qemu

The full call to run the romeo-obsw on qemu is:

qemu-system-arm -semihosting -nographic -monitor none -serial null -serial stdio -machine xilinx-zynq-a9 -m 500M -kernel romeo-obsw

Where the arguments are the following:

  • qemu-system-arm: the qemu emulating arm processors
  • -semihosting: enables the emulated software to communicate with the host. This is only used to allow the software to exit including returning an exit code
  • -nographic: disable qemus graphical interface
  • -monitor none: disable qemu monitoring (not used)
  • -serial null: add first UART, do not connect it.
  • -serial stdio: add second UART, connect it to the console of the host
  • -machine xilinx-zynq-a9: select zynq as emulation target
  • -m 500M: set RAM size
  • -device loader,addr=0x0000012c,data=0x00001234,data-len=4: set data at the memory location data. This is used by the FSW to detect if it is runing on qemu or on a real zynq (where this memory location will not be 0x00001234)
  • -kernel romeo-obsw: which program to run

The first UART can be connected to a serial device on the host. Add -chardev serial,id=serial0,path="/dev/ttyUSB0" where "/dev/ttyUSB0" is the path to the serial device. Then, change the first invocation of -serial from -serial null to -serial chardev:serial0

Debug on qemu

Basically the same call as above, only -kernel is replaced by -s -S, which enables debugging and halts the CPU.

qemu-system-arm -semihosting -nographic -monitor none -serial null -serial stdio -machine xilinx-zynq-a9 -m 500M -device loader,addr=0x0000012c,data=0x00001234,data-len=4 -s -S

After qemu is started, connect to the gdb server:

arm-none-eabi-gdb romeo-obsw
>target remote :1234
>load
>cont