Skip to content

Instantly share code, notes, and snippets.

@doug65536
Created May 27, 2021 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doug65536/da96a0e47b3b9d95eddd6969288b6b37 to your computer and use it in GitHub Desktop.
Save doug65536/da96a0e47b3b9d95eddd6969288b6b37 to your computer and use it in GitHub Desktop.
bool serial_logger_efi_t::init(int port)
{
EFI_STATUS status;
UINTN serial_port_count = 0;
EFI_HANDLE *serial_ports = nullptr;
status = efi_systab->BootServices->LocateHandleBuffer(
ByProtocol,
&efi_serial_io_guid,
nullptr,
&serial_port_count,
&serial_ports);
if (EFI_ERROR(status)) {
DEBUG(TSTR "LocateHandleBuffer SERIAL_IO_PROTOCOL failed");
return false;
}
EFI_SERIAL_IO_PROTOCOL *serial_handles[16];
for (size_t i = 0; i < serial_port_count && i < 16; ++i) {
status = efi_systab->BootServices->HandleProtocol(
serial_ports[i],
&efi_serial_io_guid,
(VOID**)&serial_handles[i]);
if (!EFI_ERROR(status)) {
char message[] = "Hello";
UINTN message_len = sizeof(message) - 1;
status = serial_handles[i]->Write(serial_handles[i],
&message_len, message);
if (EFI_ERROR(status)) {
// To see in debugger
volatile int it_failed _unused = 1;
}
} else {
DEBUG(TSTR "HandleProtocol SERIAL_IO_PROTOCOL failed");
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment