]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/BdsDxe: Avoid overwriting PlatformRecovery####
authorRuiyu Ni <ruiyu.ni@intel.com>
Tue, 15 Nov 2016 10:02:32 +0000 (18:02 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Fri, 18 Nov 2016 02:42:04 +0000 (10:42 +0800)
Current implementation always creates PlatformRecovery0000
pointing to \EFI\BOOT\BOOT$(ARCH).efi but it may overwrite
PlatformRecovery#### created before (maybe by a DXE driver).

The patch only uses the smallest unused option number for
the \EFI\BOOT\BOOT$(ARCH).efi PlatformRecovery#### to avoid
overwriting already-created PlatformRecovery####.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jie Lin <jie.lin@intel.com>
Reviewed-by: Sunny Wang <sunnywang@hpe.com>
MdeModulePkg/Universal/BdsDxe/BdsEntry.c

index 32bcbf342eecdd248e78404a067cac6d5533f3c0..98b393109389d74a1fe824562afe845acc6535a0 100644 (file)
@@ -837,7 +837,7 @@ BdsEntry (
   FilePath = FileDevicePath (NULL, EFI_REMOVABLE_MEDIA_FILE_NAME);\r
   Status = EfiBootManagerInitializeLoadOption (\r
              &LoadOption,\r
-             0,\r
+             LoadOptionNumberUnassigned,\r
              LoadOptionTypePlatformRecovery,\r
              LOAD_OPTION_ACTIVE,\r
              L"Default PlatformRecovery",\r
@@ -846,9 +846,24 @@ BdsEntry (
              0\r
              );\r
   ASSERT_EFI_ERROR (Status);\r
-  EfiBootManagerLoadOptionToVariable (&LoadOption);\r
+  LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);\r
+  if (EfiBootManagerFindLoadOption (&LoadOption, LoadOptions, LoadOptionCount) == -1) {\r
+    for (Index = 0; Index < LoadOptionCount; Index++) {\r
+      //\r
+      // The PlatformRecovery#### options are sorted by OptionNumber.\r
+      // Find the the smallest unused number as the new OptionNumber.\r
+      //\r
+      if (LoadOptions[Index].OptionNumber != Index) {\r
+        break;\r
+      }\r
+    }\r
+    LoadOption.OptionNumber = Index;\r
+    Status = EfiBootManagerLoadOptionToVariable (&LoadOption);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
   EfiBootManagerFreeLoadOption (&LoadOption);\r
   FreePool (FilePath);\r
+  EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r
 \r
   //\r
   // Report Status Code to indicate connecting drivers will happen\r