Search code examples
uefi

Printing to UEFI Shell StdOut


As per UEFI Shell Specification,

EFI_SHELL_PARAMETERS_PROTOCOL
typedef struct _EFI_SHELL_PARAMETERS_PROTOCOL {
    CHAR16          **Argv;
    UINTN           Argc;
    EFI_FILE_HANDLE StdIn;
    EFI_FILE_HANDLE StdOut;
    EFI_FILE_HANDLE StdErr;
} EFI_SHELL_PARAMETERS_PROTOCOL;

StdOut The file handle for the standard output for this executable. This may be different from the ConOutHandle in the EFI_SYSTEM_TABLE.

I thought that maybe Shell's StdOut is a more preferred standard output for a shell application than EFI_SYSTEM_TABLE.ConOut. However, it seems that I cannot simply open the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on this handle as OpenProtocol throws EFI_INVALID_PARAMETER at me.

I tried opening the protocol with StdOut handle as the Handle and ImageHandle of the application as the Agent. Attributes: EFI_OPEN_PROTOCOL_GET_PROTOCOL.

EFI_FILE_HANDLE type of the StdOut param bothers me. Maybe the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL is not installed on the handle? If so, what's the purpose of StdOut then. Or could it be a bug in the Shell?


Solution

  • EFI_FILE_HANDLE is not the same as EFI_HANDLE, it is defined as:

    typedef struct _EFI_FILE_PROTOCOL         *EFI_FILE_HANDLE;
    

    You have to use the methods from EFI_FILE_PROTOCOL if you want to write to StdOut.