Skip to content

Commit

Permalink
ResetSystem: Support reboot into firmware (acidanthera#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhen-zen authored Jun 16, 2020
1 parent 2fe4794 commit d6c5c5c
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Application/ResetSystem/ResetSystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit d6c5c5c

Please sign in to comment.