]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/BdsDxe/BdsEntry.c
MdeModulePkg/BdsDxe: Avoid overwriting PlatformRecovery####
[mirror_edk2.git] / 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