How to tell if a SIMPLE_TEXT_OUTPUT_PROTOCOL writes to serial


Joshua Seaton <josh.a.seaton@...>
 

Hi all,

I'm trying to write generic EFI code that wires up `printf` to both
SIMPLE_TEXT_OUTPUT_PROTOCOL and SERIAL_IO_PROTOCOL when present.
However, at least on QEMU, doing this in the naive way results in
double-printing to the console. Is there a way to programmatically
detect whether an implementation of SIMPLE_TEXT_OUTPUT_PROTOCOL writes
to serial so that this can be avoided?


Joshia.


Joshua Seaton <josh.a.seaton@...>
 

*at least on headless QEMU

On Sun, Jun 12, 2022 at 1:28 PM Joshua Seaton <josh.a.seaton@...> wrote:

Hi all,

I'm trying to write generic EFI code that wires up `printf` to both
SIMPLE_TEXT_OUTPUT_PROTOCOL and SERIAL_IO_PROTOCOL when present.
However, at least on QEMU, doing this in the naive way results in
double-printing to the console. Is there a way to programmatically
detect whether an implementation of SIMPLE_TEXT_OUTPUT_PROTOCOL writes
to serial so that this can be avoided?


Joshia.


Nate DeSimone
 

Hi Joshua,

The best way to figure that out would be to parse the list of EFI_DEVICE_PATH_PROTOCOL(s) that are present in the "ConOut" UEFI variable. Probably the best thing to look for would be the presence of a UART_DEVICE_PATH node followed by a VENDOR_DEVICE_PATH node with one of the following GUIDs:

- gEfiPcAnsiGuid
- gEfiVT100Guid
- gEfiVT100PlusGuid
- gEfiVTUTF8Guid
- gEfiTtyTermGuid

If that exists then TerminalDxe should already be forwarding your prints to the UART. If it doesn't then I would do the following:

1. Find the SERIAL_IO_PROTOCOL instance that you want to hook up to printf()
2. Get the EFI_DEVICE_PATH_PROTOCOL from that handle
3. Make a copy of that DEVICE_PATH and add a VENDOR_DEVICE_PATH with one of the above terminal type GUIDs to the end.
4. Append the resulting DEVICE_PATH to the "ConOut" UEFI Variable
5. ConnectController()

Hope that helps,
Nate

-----Original Message-----
From: discuss@edk2.groups.io <discuss@edk2.groups.io> On Behalf Of Joshua Seaton
Sent: Sunday, June 12, 2022 1:44 PM
To: discuss@edk2.groups.io
Subject: Re: [edk2-discuss] How to tell if a SIMPLE_TEXT_OUTPUT_PROTOCOL writes to serial

*at least on headless QEMU

On Sun, Jun 12, 2022 at 1:28 PM Joshua Seaton <josh.a.seaton@...> wrote:

Hi all,

I'm trying to write generic EFI code that wires up `printf` to both
SIMPLE_TEXT_OUTPUT_PROTOCOL and SERIAL_IO_PROTOCOL when present.
However, at least on QEMU, doing this in the naive way results in
double-printing to the console. Is there a way to programmatically
detect whether an implementation of SIMPLE_TEXT_OUTPUT_PROTOCOL writes
to serial so that this can be avoided?


Joshia.