From 94e6ca7aecf8f1b68cd91bfb7eadddd4d4c48d14 Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Tue, 19 Mar 2024 16:50:04 +0100 Subject: [PATCH] Implement BlEnterFirmwareSetup() routine --- sdk/xtdk/xtuefi.h | 3 +++ xtldr/efiutils.c | 45 ++++++++++++++++++++++++++++++++++++++++++ xtldr/includes/xtldr.h | 4 ++++ 3 files changed, 52 insertions(+) diff --git a/sdk/xtdk/xtuefi.h b/sdk/xtdk/xtuefi.h index 4d76de7..9aa21d2 100644 --- a/sdk/xtdk/xtuefi.h +++ b/sdk/xtdk/xtuefi.h @@ -312,6 +312,9 @@ #define EFI_TEXT_BOX_FULL_BLOCK 0x2588 #define EFI_TEXT_BOX_LIGHT_BLOCK 0x2591 +/* EFI OS indication bits */ +#define EFI_OS_INDICATIONS_BOOT_TO_FW_UI 0x0000000000000001ULL + /* EFI protocols GUIDs */ #define EFI_BLOCK_IO_PROTOCOL_GUID {0x964E5B21, 0x6459, 0x11D2, {0x8E, 0x39, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B}} #define EFI_BLOCK_IO2_PROTOCOL_GUID {0xA77B2472, 0xE282, 0x4E9F, {0xA2, 0x45, 0xC2, 0xC0, 0xE2, 0x7B, 0xBC, 0xC1}} diff --git a/xtldr/efiutils.c b/xtldr/efiutils.c index 7e1a75d..5bda800 100644 --- a/xtldr/efiutils.c +++ b/xtldr/efiutils.c @@ -9,6 +9,51 @@ #include +/** + * Reboots into UEFI firmware setup interface. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTCDECL +EFI_STATUS +BlEnterFirmwareSetup() +{ + EFI_GUID Guid = EFI_GLOBAL_VARIABLE_GUID; + PULONGLONG SetupSupport; + ULONGLONG Indications; + EFI_STATUS Status; + + /* Check if booting into firmware interface is supported */ + Status = BlGetEfiVariable(&Guid, L"OsIndicationsSupported", (PVOID*)&SetupSupport); + if(Status != STATUS_EFI_SUCCESS || !(*SetupSupport & EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) + { + /* Reboot into firmware setup is not supported */ + BlDebugPrint(L"WARNING: Reboot into firmware setup interface not supported\n"); + return STATUS_EFI_UNSUPPORTED; + } + + /* Get the value of OsIndications variable */ + Indications = 0; + Status = BlGetEfiVariable(&Guid, L"OsIndications", (PVOID)&Indications); + + /* Enable FW setup on next boot */ + Indications |= EFI_OS_INDICATIONS_BOOT_TO_FW_UI; + Status = BlSetEfiVariable(&Guid, L"OsIndications", (PVOID)&Indications, sizeof(Indications)); + if(Status != STATUS_EFI_SUCCESS) + { + /* Failed to update OsIndications variable */ + return Status; + } + + /* Reboot into firmware setup */ + BlRebootSystem(); + + /* Must not reach this point, just make the compiler happy */ + return STATUS_EFI_SUCCESS; +} + /** * Exits EFI boot services. * diff --git a/xtldr/includes/xtldr.h b/xtldr/includes/xtldr.h index 7225470..cfca6da 100644 --- a/xtldr/includes/xtldr.h +++ b/xtldr/includes/xtldr.h @@ -95,6 +95,10 @@ XTCDECL VOID BlEnableConsoleCursor(); +XTCDECL +EFI_STATUS +BlEnterFirmwareSetup(); + XTCDECL EFI_STATUS BlEnumerateBlockDevices();