3

I am emulating a chip with multiple UARTs/USARTs. What I want to do is redirect UART3 to /dev/uart3 on the host, uart7 to /dev/uart7 on the host, etc. I can't seem to find examples or guides that deal with more than one uart, and the examples I did find don't seem to even select which uart they are dumping to a console/socket/whatever. (Some of them use "id=id" but I have no idea what that means and Qemu documentation didn't seem to cover it.)

Seth
  • 707
  • 1
  • 9
  • 20

2 Answers2

1

Create TTY devices by launching an xterm instance with a "shell" program that does not read/write standard input/output like so. Create the xterm window, (implicitly) allocate a PTY device, and print the path to that device:

xterm -e /bin/sh -c 'while true; do sleep 100; done' & ps --ppid $!

Repeat for as many serial in/outs you need to connect to Qemu.

Then start Qemu with: -serial /dev/pts/N -serial /dev/pts/M ... with as many -serial as the emulated machine has defined. Then, the xterm windows will show the output and also will also accept and redirect input. The QEMU monitor prompt will open automatically in the terminal window where QEMU was run and will remain available there while the target executes. This way, it is possible to break/interrupt the QEMU process running inside GDB with Ctrl-C, which does not work (for me) if using 'mon:stdio'.

The number of serial peripherals and their address is hardcoded in Qemu source code. For example, for Xilinx Zynqmp there are going to be two serial devices that you can redirect to stdio/tty, using two -serial options: qemu/hw/arm/xlnx-zynqmp.c:

static const uint64_t uart_addr[XLNX_ZYNQMP_NUM_UARTS] = { 0xFF000000, 0xFF010000 }
alexei
  • 2,031
  • 1
  • 26
  • 28
  • Hi, I tried your xterm command above and it just shows me this line. `[3] 1654915 (enter) PID TTY TIME CMD (and nothing)`. Am I supposed see the PID, TTY, TIME CMD? Can you explain the command above? (I couldn't find the option -c for ubuntu 20.04). Looks like it runs the repeated sleep inside the xterm.. – Chan Kim Oct 13 '22 at 13:45
  • @ChanKim The command I gave was incorrect, it was missing a `do` keyword; I editted the reply, try: `xterm -e /bin/sh -c 'while true; do sleep 100; done' & ps --ppid $!` This should print you the TTY path like `pts/1`. The `-c` argument is to the shell, tells what shell command to run in the launched shell; your shell should have it, for sure. – alexei Oct 15 '22 at 05:03
0

man qemu says:

-serial dev

Redirect the virtual serial port to host character device dev. The default device is "vc" in graphical mode and "stdio" in non graphical mode.This option can be used several times to simulate up to 4 serial ports.

also, You could add virtual USB serial ports:

-usbdevice serial:[vendorid=vendor_id][,productid=product_id]:dev

For dev you substitute your host's serial ports in the form /dev/ttyXXX in both cases

you could omit vendor and product id specification. In that case qemu would create the generic serial usb device with Virto' IDs

Serge
  • 6,088
  • 17
  • 27
  • I used "-serial /dev/tty5" while also doing a cat or a tail-f on /dev/tty5 and no text showed up. I also tried a cat and tail -f on /dev/vcs5, nothing. Did I do something wrong? That does seem to work with "-serial dev/pts/18" while pts 18 is open. but "-serial dev/pts/18 -serial dev/pts/19" didn't output uart2 There are 8 uarts, can I only output 4 of them in Qemu? What about the GPIOs and SPIs, can they be output? – Seth Sep 07 '16 at 19:04
  • 3
    And then how to do anything with them with the Linux kernel? E.g. if I try: `-serial tcp::45456,server,nowait -serial tcp::45457,server,nowait` I can only connect to the first one with `telnet localhost 45456` from host, but the second one stays blank. Maybe I'm missing some kernel config? – Ciro Santilli OurBigBook.com Mar 13 '18 at 16:39
  • Any solution to Ciro's query in the above comment? I am stuck with the same problem, no idea how to use this newly emulated serial port. – Naveen Mar 19 '21 at 12:15
  • 1
    @CiroSantilliOurBigBook.com At present we only support one console per console driver (which is shared between multiple consoles of the same type), so if you want multiple outputs, you'll need to use another type of console driver, for example a video console driver. – Chris Down Sep 07 '22 at 11:35
  • I can connect two xterms (using alexei's answer) or two telnet terms(using Ciro Santilli's comment, but with no nowait option). I had a problem with my VM (wrong IRQ number for the two uarts). – Chan Kim Oct 17 '22 at 06:40