]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
MdeModulePkg/BootManagerMenu: Fix bug that boots to undesired option
[mirror_edk2.git] / MdeModulePkg / Application / BootManagerMenuApp / BootManagerMenu.c
index a8d5c0367495b9223f61d2127e1d78a7084f2d5c..9547c7eb5a83e545e0e0a4827fe2c56a6ecf0093 100644 (file)
@@ -242,7 +242,48 @@ IsBootManagerMenu (
 \r
   return (BOOLEAN) (!EFI_ERROR (Status) && (BootOption->OptionNumber == BootManagerMenu.OptionNumber));\r
 }\r
\r
+\r
+/**\r
+  Return whether to ignore the boot option.\r
+\r
+  @param BootOption  Pointer to EFI_BOOT_MANAGER_LOAD_OPTION to check.\r
+\r
+  @retval TRUE  Ignore the boot optin.\r
+  @retval FALSE Do not ignore the boot option.\r
+**/\r
+BOOLEAN\r
+IgnoreBootOption (\r
+  IN   EFI_BOOT_MANAGER_LOAD_OPTION  *BootOption\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_DEVICE_PATH_PROTOCOL      *ImageDevicePath;\r
+\r
+  //\r
+  // Ignore myself.\r
+  //\r
+  Status = gBS->HandleProtocol (gImageHandle, &gEfiLoadedImageDevicePathProtocolGuid, (VOID **) &ImageDevicePath);\r
+  ASSERT_EFI_ERROR (Status);\r
+  if (CompareMem (BootOption->FilePath, ImageDevicePath, GetDevicePathSize (ImageDevicePath)) == 0) {\r
+    return TRUE;\r
+  }\r
+\r
+  //\r
+  // Do not ignore Boot Manager Menu.\r
+  //\r
+  if (IsBootManagerMenu (BootOption)) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Ignore the hidden/inactive boot option.\r
+  //\r
+  if (((BootOption->Attributes & LOAD_OPTION_HIDDEN) != 0) || ((BootOption->Attributes & LOAD_OPTION_ACTIVE) == 0)) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
 \r
 /**\r
   This funciton uses to initialize boot menu data\r
@@ -262,18 +303,13 @@ InitializeBootMenuData (
   OUT  BOOT_MENU_POPUP_DATA          *BootMenuData\r
   )\r
 {\r
-  EFI_STATUS                    Status;\r
   UINTN                         Index;\r
   UINTN                         StrIndex;\r
-  EFI_DEVICE_PATH_PROTOCOL      *ImageDevicePath;\r
       \r
   if (BootOption == NULL || BootMenuData == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  Status = gBS->HandleProtocol (gImageHandle, &gEfiLoadedImageDevicePathProtocolGuid, (VOID **) &ImageDevicePath);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
   BootMenuData->TitleToken[0] = STRING_TOKEN (STR_BOOT_POPUP_MENU_TITLE_STRING);\r
   BootMenuData->PtrTokens     = AllocateZeroPool (BootOptionCount * sizeof (EFI_STRING_ID));\r
   ASSERT (BootMenuData->PtrTokens != NULL);\r
@@ -282,18 +318,7 @@ InitializeBootMenuData (
   // Skip boot option which created by BootNext Variable\r
   //\r
   for (StrIndex = 0, Index = 0; Index < BootOptionCount; Index++) {\r
-    //\r
-    // Don't display the hidden/inactive boot option except setup application.\r
-    //\r
-    if ((((BootOption[Index].Attributes & LOAD_OPTION_HIDDEN) != 0) || ((BootOption[Index].Attributes & LOAD_OPTION_ACTIVE) == 0)) &&\r
-        !IsBootManagerMenu (&BootOption[Index])) {      \r
-      continue;\r
-    }\r
-\r
-    //\r
-    // Don't display myself\r
-    //\r
-    if (CompareMem (BootOption[Index].FilePath, ImageDevicePath, GetDevicePathSize (ImageDevicePath)) == 0) {\r
+    if (IgnoreBootOption (&BootOption[Index])) {\r
       continue;\r
     }\r
 \r
@@ -640,13 +665,10 @@ BootFromSelectOption (
   ASSERT (BootOptions != NULL);\r
 \r
   for (ItemNum = 0, Index = 0; Index < BootOptionCount; Index++) {\r
-    //\r
-    // Don't display the hidden/inactive boot option except setup application.\r
-    //\r
-    if ((((BootOptions[Index].Attributes & LOAD_OPTION_HIDDEN) != 0) || ((BootOptions[Index].Attributes & LOAD_OPTION_ACTIVE) == 0)) &&\r
-        !IsBootManagerMenu (&BootOptions[Index])) {      \r
+    if (IgnoreBootOption (&BootOptions[Index])) {\r
       continue;\r
     }\r
+\r
     if (ItemNum++ == SelectItem) {\r
       EfiBootManagerBoot (&BootOptions[Index]);\r
       break;\r