]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/BdsDxe: Don't delete "BootNext" until booting it
authorRuiyu Ni <ruiyu.ni@intel.com>
Thu, 28 Sep 2017 05:46:20 +0000 (13:46 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Fri, 29 Sep 2017 07:23:15 +0000 (15:23 +0800)
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>
MdeModulePkg/Universal/BdsDxe/BdsEntry.c

index ac5f9088dd5e32edabab5056a21396c0b9069163..a6fe617b56939ea169a86e113fb6d52e9b5d3a13 100644 (file)
@@ -808,7 +808,8 @@ BdsEntry (
   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
@@ -817,17 +818,6 @@ BdsEntry (
     }\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
@@ -1052,10 +1042,25 @@ BdsEntry (
 \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