Current implementation deletes the "BootNext" before calling
any PlatformBootManagerLib APIs, but if system resets in
PlatformBootManagerLib APIs, "BootNext" is not consumed but lost.
The patch defers the deletion of "BootNext" to before booting it.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Sunny Wang <sunnywang@hpe.com>
ASSERT_EFI_ERROR (Status);\r
\r
//\r
ASSERT_EFI_ERROR (Status);\r
\r
//\r
- // Cache and remove the "BootNext" NV variable.\r
+ // Cache the "BootNext" NV variable before calling any PlatformBootManagerLib APIs\r
+ // This could avoid the "BootNext" set by PlatformBootManagerLib be consumed in this boot.\r
//\r
GetEfiGlobalVariable2 (EFI_BOOT_NEXT_VARIABLE_NAME, (VOID **) &BootNext, &DataSize);\r
if (DataSize != sizeof (UINT16)) {\r
//\r
GetEfiGlobalVariable2 (EFI_BOOT_NEXT_VARIABLE_NAME, (VOID **) &BootNext, &DataSize);\r
if (DataSize != sizeof (UINT16)) {\r
}\r
BootNext = NULL;\r
}\r
}\r
BootNext = NULL;\r
}\r
- Status = gRT->SetVariable (\r
- EFI_BOOT_NEXT_VARIABLE_NAME,\r
- &gEfiGlobalVariableGuid,\r
- 0,\r
- 0,\r
- NULL\r
- );\r
- //\r
- // Deleting NV variable shouldn't fail unless it doesn't exist.\r
- //\r
- ASSERT (Status == EFI_SUCCESS || Status == EFI_NOT_FOUND);\r
\r
//\r
// Initialize the platform language variables\r
\r
//\r
// Initialize the platform language variables\r
\r
EfiBootManagerHotkeyBoot ();\r
\r
\r
EfiBootManagerHotkeyBoot ();\r
\r
- //\r
- // Boot to "BootNext"\r
- //\r
if (BootNext != NULL) {\r
if (BootNext != NULL) {\r
+ //\r
+ // Delete "BootNext" NV variable before transferring control to it to prevent loops.\r
+ //\r
+ Status = gRT->SetVariable (\r
+ EFI_BOOT_NEXT_VARIABLE_NAME,\r
+ &gEfiGlobalVariableGuid,\r
+ 0,\r
+ 0,\r
+ NULL\r
+ );\r
+ //\r
+ // Deleting NV variable shouldn't fail unless it doesn't exist.\r
+ //\r
+ ASSERT (Status == EFI_SUCCESS || Status == EFI_NOT_FOUND);\r
+\r
+ //\r
+ // Boot to "BootNext"\r
+ //\r
UnicodeSPrint (BootNextVariableName, sizeof (BootNextVariableName), L"Boot%04x", *BootNext);\r
Status = EfiBootManagerVariableToLoadOption (BootNextVariableName, &LoadOption);\r
if (!EFI_ERROR (Status)) {\r
UnicodeSPrint (BootNextVariableName, sizeof (BootNextVariableName), L"Boot%04x", *BootNext);\r
Status = EfiBootManagerVariableToLoadOption (BootNextVariableName, &LoadOption);\r
if (!EFI_ERROR (Status)) {\r