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>
FilePath = FileDevicePath (NULL, EFI_REMOVABLE_MEDIA_FILE_NAME);\r
Status = EfiBootManagerInitializeLoadOption (\r
&LoadOption,\r
FilePath = FileDevicePath (NULL, EFI_REMOVABLE_MEDIA_FILE_NAME);\r
Status = EfiBootManagerInitializeLoadOption (\r
&LoadOption,\r
+ LoadOptionNumberUnassigned,\r
LoadOptionTypePlatformRecovery,\r
LOAD_OPTION_ACTIVE,\r
L"Default PlatformRecovery",\r
LoadOptionTypePlatformRecovery,\r
LOAD_OPTION_ACTIVE,\r
L"Default PlatformRecovery",\r
0\r
);\r
ASSERT_EFI_ERROR (Status);\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
EfiBootManagerFreeLoadOption (&LoadOption);\r
FreePool (FilePath);\r
+ EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r
\r
//\r
// Report Status Code to indicate connecting drivers will happen\r
\r
//\r
// Report Status Code to indicate connecting drivers will happen\r