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
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
EfiBootManagerHotkeyBoot ();\r
\r
- //\r
- // Boot to "BootNext"\r
- //\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
@param VendorGuid A unique identifier for the vendor.\r
@param Attributes Attributes bitmask to set for the variable.\r
@param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE, \r
- EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or \r
- EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero \r
+ or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero\r
causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is \r
set, then a SetVariable() call with a DataSize of zero will not cause any change to \r
the variable value (the timestamp associated with the variable may be updated however \r
@retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.\r
@retval EFI_WRITE_PROTECTED The variable in question is read-only.\r
@retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.\r
- @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS \r
- or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo \r
- does NOT pass the validation check carried out by the firmware.\r
+ @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS\r
+ being set, but the AuthInfo does NOT pass the validation check carried out by the firmware.\r
\r
@retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.\r
**/\r