{\r
EFI_STATUS Status;\r
EFI_BOOT_MANAGER_LOAD_OPTION BootManagerMenu;\r
+ EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;\r
+ UINTN OldBootOptionCount;\r
+ UINTN NewBootOptionCount;\r
+\r
+ //\r
+ // Record the total number of boot configured boot options\r
+ //\r
+ BootOptions = EfiBootManagerGetLoadOptions (&OldBootOptionCount,\r
+ LoadOptionTypeBoot);\r
+ EfiBootManagerFreeLoadOptions (BootOptions, OldBootOptionCount);\r
+\r
+ //\r
+ // Connect all devices, and regenerate all boot options\r
+ //\r
+ EfiBootManagerConnectAll ();\r
+ EfiBootManagerRefreshAllBootOption ();\r
+\r
+ //\r
+ // Record the updated number of boot configured boot options\r
+ //\r
+ BootOptions = EfiBootManagerGetLoadOptions (&NewBootOptionCount,\r
+ LoadOptionTypeBoot);\r
+ EfiBootManagerFreeLoadOptions (BootOptions, NewBootOptionCount);\r
+\r
+ //\r
+ // If the number of configured boot options has changed, reboot\r
+ // the system so the new boot options will be taken into account\r
+ // while executing the ordinary BDS bootflow sequence.\r
+ //\r
+ if (NewBootOptionCount != OldBootOptionCount) {\r
+ DEBUG ((DEBUG_WARN, "%a: rebooting after refreshing all boot options\n",\r
+ __FUNCTION__));\r
+ gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);\r
+ }\r
\r
Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);\r
if (EFI_ERROR (Status)) {\r