0

I started to learn esp32 and i run the programs (esp-idf framework) i make with qemu-system-xtensa from espressif repo.

Right now i can run qemu with -serial pty and this redirects everything to /dev/pts/xx and in the qemu window i no longer see any messages.

qemu-system-xtensa -nographic -M esp32 -m 4 -drive file=my_program.bin,if=mtd,format=raw -gdb tcp::1234,nowait -serial pty -S

How can i redirect only the serial UART0 messages that i send from my program to /dev/pts/xx and keep all other messages in the qemu window?

In the qemu window i want to still see the output of any printf() and ESP_LOG messages. For example this is the output and what i see in the qemu window when i start it up:

    ==494730==WARNING: ASan doesn't fully support makecontext/swapcontext functions and may produce false positives in some cases!
Adding SPI flash device
ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x12 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:7128
load:0x40078000,len:15564
ho 0 tail 12 room 4
load:0x40080400,len:4
load:0x40080404,len:3676
entry 0x40080620
I (1525) boot: ESP-IDF v5.2-dev-824-g2404dbb85f 2nd stage bootloader
I (1544) boot: compile time May 30 2023 14:08:49
W (1545) boot: Unicore bootloader
I (1632) boot: chip revision: v0.0
I (1650) boot.esp32: SPI Speed      : 40MHz
I (1653) boot.esp32: SPI Mode       : DIO
I (1655) boot.esp32: SPI Flash Size : 2MB
I (1725) boot: Enabling RNG early entropy source...
I (1808) boot: Partition Table:
I (1810) boot: ## Label            Usage          Type ST Offset   Length
I (1813) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (1819) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (1822) boot:  2 factory          factory app      00 00 00010000 00100000
I (1873) boot: End of partition table
I (1926) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=0993ch ( 39228) map
I (2124) esp_image: segment 1: paddr=00019964 vaddr=3ffb0000 size=016bch (  5820) load
I (2249) esp_image: segment 2: paddr=0001b028 vaddr=40080000 size=04ff0h ( 20464) load
I (2447) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=15d18h ( 89368) map
I (2708) esp_image: segment 4: paddr=00035d40 vaddr=40084ff0 size=06a88h ( 27272) load
I (2904) boot: Loaded app from partition at offset 0x10000
I (2907) boot: Disabling RNG early entropy source...
I (3007) cpu_start: Unicore app
I (3034) cpu_start: Pro cpu up.
I (3036) cpu_start: Single core mode
I (5454) cpu_start: Pro cpu start user code
I (5456) cpu_start: cpu freq: 160000000 Hz
I (5458) cpu_start: Application information:
I (5460) cpu_start: Project name:     test-spi
I (5462) cpu_start: App version:      1
I (5464) cpu_start: Compile time:     May 30 2023 14:08:35
I (5469) cpu_start: ELF file SHA256:  e66898f7c...
I (5471) cpu_start: ESP-IDF:          v5.2-dev-824-g2404dbb85f
I (5473) cpu_start: Min chip rev:     v0.0
I (5475) cpu_start: Max chip rev:     v3.99 
I (5479) cpu_start: Chip rev:         v0.0
I (5492) heap_init: Initializing. RAM available for dynamic allocation:
I (5507) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (5511) heap_init: At 3FFB1E48 len 0002E1B8 (184 KiB): DRAM
I (5513) heap_init: At 3FFE0440 len 0001FBC0 (126 KiB): D/IRAM
I (5518) heap_init: At 40078000 len 00008000 (32 KiB): IRAM
I (5521) heap_init: At 4008BA78 len 00014588 (81 KiB): IRAM
I (5522) heap_init: At 3FF80000 len 00002000 (8 KiB): RTCRAM
I (5811) spi_flash: detected chip: gd
I (5851) spi_flash: flash io: dio
W (5888) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (5962) app_start: Starting scheduler on CPU0
I (6021) main_task: Started on CPU0
I (6121) main_task: Calling app_main()
------------------------              <- this is from a printf()
--- QEMU APP STARTED ---              <- this is from a printf()
------------------------              <- this is from a printf()
I (6211) main_task: Returned from app_main()

EDIT:

So, let me understand, the QEMU windows displays the serial output of the program. I have found in the documentation that i can have 3 UART ports. That means i could leave UART0 to qemu window (by default) and redirect UART1 to pty.

Now if i run

qemu-system-xtensa -nographic -M esp32 -m 4 -drive file=$ESP_FILE,if=mtd,format=raw -gdb tcp::1234,nowait -serial pty -serial pty -S

the first occurence of -serial pty sends the bootloader, RTOS and UART0 to /dev/pts/0 and the seccond occurence of -serial pty sends UART1 to dev/pts/1. The order of occurence seems to be important. And apparently i am forced to redirect "the first serial" too if i need to redirect "the second serial".

My question now is, how can i skip redirecting "the first serial" and let is go to qemu windows (like it does by default) and redirect only "the second serial" to /dev/pts/1? (I have read the qemu-system-xtensa manual, but it's very confusing, and i don't really understand how these redirects work)

  • You don't say what the "other messages" are. Some examples would help in figuring out what the text you want to keep in the graphical window is coming from. – Peter Maydell May 30 '23 at 14:25

1 Answers1

1

There is no way to get QEMU to redirect only the text your program sends to UART0 somewhere else and leave all the text that the bootloader and RTOS send to UART0 in the graphical window. From QEMU's point of view it has no way to tell which characters that arrive at the UART have come from which part of the guest -- it's all just "text on the serial port".

If the board you are emulating has multiple serial ports, you may be able to configure your guest RTOS to send the printf output from your main task to the second serial port. If you are able to do that, then you can tell QEMU "send the output from UART0 to the graphical window, and send the output from UART1 to the text console". (The 'esp32' board is not one of those supported in upstream QEMU, so I don't know whether it has one or two serial ports. You'd have to ask the people who developed it about this.)

Peter Maydell
  • 9,707
  • 1
  • 19
  • 25