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
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