ResetSystem: Support reboot into firmware
@@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
+#include <Guid/GlobalVariable.h>
#include <Uefi.h>
#include <Library/BaseMemoryLib.h>
#include <Library/OcDebugLogLib.h>
@@ -33,6 +34,9 @@ UefiMain (
CHAR16 **Argv;
CHAR16 *Mode;
EFI_RESET_TYPE ResetMode;
+ UINT64 OsIndications;
+ UINT32 Attr;
+ UINTN DataSize;
Status = GetArguments (&Argc, &Argv);
if (!EFI_ERROR (Status) && Argc >= 2) {
@@ -42,6 +46,53 @@ UefiMain (
Mode = L"ColdReset";
}
+ if (StrCmp (Mode, L"Firmware") == 0) {
+ DEBUG ((DEBUG_INFO, "OCRST: Entering firmware...\n"));
+ DataSize = sizeof (OsIndications);
+ Status = gRT->GetVariable (
+ EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME,
+ &gEfiGlobalVariableGuid,
+ &Attr,
+ &DataSize,
+ &OsIndications
+ );
+ if (!EFI_ERROR (Status)) {
+ if ((OsIndications & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) != 0) {
+ DataSize = sizeof (OsIndications);
+ Status = gRT->GetVariable (
+ EFI_OS_INDICATIONS_VARIABLE_NAME,
+ &gEfiGlobalVariableGuid,
+ &Attr,
+ &DataSize,
+ &OsIndications
+ );
+ if (!EFI_ERROR (Status)) {
+ OsIndications |= EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
+ } else {
+ OsIndications = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
+ }
+ Status = gRT->SetVariable (
+ EFI_OS_INDICATIONS_VARIABLE_NAME,
+ &gEfiGlobalVariableGuid,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+ sizeof (OsIndications),
+ &OsIndications
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_WARN, "OCRST: Failed to set EFI_OS_INDICATIONS_BOOT_TO_FW_UI - %r\n", Status));
+ return EFI_ABORTED;
+ }
+ } else {
+ DEBUG ((DEBUG_WARN, "OCRST: Firmware do not support EFI_OS_INDICATIONS_BOOT_TO_FW_UI - %r\n", Status));
+ return EFI_UNSUPPORTED;
+ }
+ } else {
+ DEBUG ((DEBUG_WARN, "OCRST: Failed to acquire firmware features - %r\n", Status));
+ return EFI_NOT_FOUND;
+ }
+ Mode = L"ColdReset";
+ }
+
if (StrCmp (Mode, L"ColdReset") == 0) {
DEBUG ((DEBUG_INFO, "OCRST: Perform cold reset...\n"));
ResetMode = EfiResetCold;
