Seth
Seth

Reputation: 716

Redirect multiple UARTs in Qemu

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.)

Upvotes: 3

Views: 6954

Answers (2)

alexei
alexei

Reputation: 2291

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 }

Upvotes: 1

Serge
Serge

Reputation: 6095

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

Upvotes: 0

Related Questions