]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Skip registering BootManagerMenu if absent
authorSunny Wang <sunnywang@hpe.com>
Fri, 1 Jul 2016 02:38:24 +0000 (10:38 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Tue, 5 Jul 2016 09:33:05 +0000 (17:33 +0800)
This is a enhancement to support the case when platform firmware
doesn't support Boot Manager Menu. For now, if BootManagerMenu FFS
can not be retrieved from FV, BDS core code will still register a
boot option for it. Then, this non-functional boot option will
still be booted by user's request (like HotKey or Exit from shell)
to cause additional boot time and error status code reported.
Therefore, it would be good to skip BootManagerMenu boot option
registration and then return error status and Invalid BootOption
data for this case so that the BootManagerBoot() or other consumers
can directly return without doing anything.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Sunny Wang <sunnywang@hpe.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
MdeModulePkg/Include/Library/UefiBootManagerLib.h
MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
MdeModulePkg/Universal/BdsDxe/BdsEntry.c

index 0fdb23dcbdba9e60dac99b598c6cbf1c394603af..e333ffd86bcef712a797013a782a73bac7247361 100644 (file)
@@ -418,12 +418,16 @@ EfiBootManagerBoot (
   );\r
 \r
 /**\r
-  Return the Boot Manager Menu.\r
\r
+  Return the boot option corresponding to the Boot Manager Menu.\r
+  It may automatically create one if the boot option hasn't been created yet.\r
+\r
   @param BootOption    Return the Boot Manager Menu.\r
 \r
   @retval EFI_SUCCESS   The Boot Manager Menu is successfully returned.\r
-  @retval EFI_NOT_FOUND The Boot Manager Menu is not found.\r
+  @retval EFI_NOT_FOUND The Boot Manager Menu cannot be found.\r
+  @retval others        Return status of gRT->SetVariable (). BootOption still points\r
+                        to the Boot Manager Menu even the Status is not EFI_SUCCESS\r
+                        and EFI_NOT_FOUND.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
index d0165170143f07ee557e9115dd99e0753f43b1aa..4da401d23cfd15d40afae5722a651e55cf05791a 100644 (file)
@@ -2,7 +2,7 @@
   Library functions which relates with booting.\r
 \r
 Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>\r
-(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
+(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -2159,7 +2159,7 @@ EfiBootManagerRefreshAllBootOption (
 }\r
 \r
 /**\r
-  This function is called to create the boot option for the Boot Manager Menu.\r
+  This function is called to get or create the boot option for the Boot Manager Menu.\r
 \r
   The Boot Manager Menu is shown after successfully booting a boot option.\r
   Assume the BootManagerMenuFile is in the same FV as the module links to this library.\r
@@ -2167,8 +2167,10 @@ EfiBootManagerRefreshAllBootOption (
   @param  BootOption    Return the boot option of the Boot Manager Menu\r
 \r
   @retval EFI_SUCCESS   Successfully register the Boot Manager Menu.\r
-  @retval Status        Return status of gRT->SetVariable (). BootOption still points\r
-                        to the Boot Manager Menu even the Status is not EFI_SUCCESS.\r
+  @retval EFI_NOT_FOUND The Boot Manager Menu cannot be found.\r
+  @retval others        Return status of gRT->SetVariable (). BootOption still points\r
+                        to the Boot Manager Menu even the Status is not EFI_SUCCESS\r
+                        and EFI_NOT_FOUND.\r
 **/\r
 EFI_STATUS\r
 BmRegisterBootManagerMenu (\r
@@ -2181,7 +2183,28 @@ BmRegisterBootManagerMenu (
   EFI_DEVICE_PATH_PROTOCOL           *DevicePath;\r
   EFI_LOADED_IMAGE_PROTOCOL          *LoadedImage;\r
   MEDIA_FW_VOL_FILEPATH_DEVICE_PATH  FileNode;\r
+  VOID                               *Data;\r
+  UINTN                              DataSize;\r
 \r
+  Data = NULL;\r
+  Status = GetSectionFromFv (\r
+             PcdGetPtr (PcdBootManagerMenuFile),\r
+             EFI_SECTION_PE32,\r
+             0,\r
+             (VOID **) &Data,\r
+             &DataSize\r
+             );\r
+  if (Data != NULL) {\r
+    FreePool (Data);\r
+  }\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_WARN, "[Bds]BootManagerMenu FFS section can not be found, skip its boot option registration\n"));\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //\r
+  // Get BootManagerMenu application's description from EFI User Interface Section.\r
+  //\r
   Status = GetSectionFromFv (\r
              PcdGetPtr (PcdBootManagerMenuFile),\r
              EFI_SECTION_USER_INTERFACE,\r
@@ -2237,12 +2260,14 @@ BmRegisterBootManagerMenu (
 /**\r
   Return the boot option corresponding to the Boot Manager Menu.\r
   It may automatically create one if the boot option hasn't been created yet.\r
-  \r
+\r
   @param BootOption    Return the Boot Manager Menu.\r
 \r
   @retval EFI_SUCCESS   The Boot Manager Menu is successfully returned.\r
-  @retval Status        Return status of gRT->SetVariable (). BootOption still points\r
-                        to the Boot Manager Menu even the Status is not EFI_SUCCESS.\r
+  @retval EFI_NOT_FOUND The Boot Manager Menu cannot be found.\r
+  @retval others        Return status of gRT->SetVariable (). BootOption still points\r
+                        to the Boot Manager Menu even the Status is not EFI_SUCCESS\r
+                        and EFI_NOT_FOUND.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
index 741ddc302bbcb2c87cdcdc5617ac76744f91285a..c86cd7a576adcd4c32f2055e2c5b507b2a661f69 100644 (file)
@@ -5,8 +5,9 @@
   After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry will be invoked\r
   to enter BDS phase.\r
 \r
-(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
 Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
+(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -273,7 +274,7 @@ BOOLEAN
 BootBootOptions (\r
   IN EFI_BOOT_MANAGER_LOAD_OPTION    *BootOptions,\r
   IN UINTN                           BootOptionCount,\r
-  IN EFI_BOOT_MANAGER_LOAD_OPTION    *BootManagerMenu\r
+  IN EFI_BOOT_MANAGER_LOAD_OPTION    *BootManagerMenu OPTIONAL\r
   )\r
 {\r
   UINTN                              Index;\r
@@ -312,7 +313,7 @@ BootBootOptions (
     // interactive mode, the boot manager will stop processing the BootOrder variable and\r
     // present a boot manager menu to the user.\r
     //\r
-    if (BootOptions[Index].Status == EFI_SUCCESS) {\r
+    if ((BootManagerMenu != NULL) && (BootOptions[Index].Status == EFI_SUCCESS)) {\r
       EfiBootManagerBoot (BootManagerMenu);\r
       break;\r
     }\r
@@ -425,22 +426,32 @@ BdsFormalizeConsoleVariable (
   \r
   Item 3 is used to solve case when OS corrupts OsIndications. Here simply delete this NV variable.\r
 \r
+  Create a boot option for BootManagerMenu if it hasn't been created yet\r
+\r
 **/\r
 VOID \r
 BdsFormalizeOSIndicationVariable (\r
   VOID\r
   )\r
 {\r
-  EFI_STATUS Status;\r
-  UINT64     OsIndicationSupport;\r
-  UINT64     OsIndication;\r
-  UINTN      DataSize;\r
-  UINT32     Attributes;\r
+  EFI_STATUS                      Status;\r
+  UINT64                          OsIndicationSupport;\r
+  UINT64                          OsIndication;\r
+  UINTN                           DataSize;\r
+  UINT32                          Attributes;\r
+  EFI_BOOT_MANAGER_LOAD_OPTION    BootManagerMenu;\r
 \r
   //\r
   // OS indicater support variable\r
   //\r
-  OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI | EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;\r
+  Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);\r
+  if (Status != EFI_NOT_FOUND) {\r
+    OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI | EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;\r
+    EfiBootManagerFreeLoadOption (&BootManagerMenu);\r
+  } else {\r
+    OsIndicationSupport = EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;\r
+  }\r
+\r
   Status = gRT->SetVariable (\r
                   EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME,\r
                   &gEfiGlobalVariableGuid,\r
@@ -601,6 +612,7 @@ BdsEntry (
   BOOLEAN                         PlatformRecovery;\r
   BOOLEAN                         BootSuccess;\r
   EFI_DEVICE_PATH_PROTOCOL        *FilePath;\r
+  EFI_STATUS                      BootManagerMenuStatus;\r
 \r
   HotkeyTriggered = NULL;\r
   Status          = EFI_SUCCESS;\r
@@ -851,9 +863,9 @@ BdsEntry (
   );\r
 \r
   //\r
-  // BootManagerMenu always contains the correct information even call fails.\r
+  // BootManagerMenu doesn't contain the correct information when return status is EFI_NOT_FOUND.\r
   //\r
-  EfiBootManagerGetBootManagerMenu (&BootManagerMenu);\r
+  BootManagerMenuStatus = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);\r
 \r
   BootFwUi         = (BOOLEAN) ((OsIndication & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) != 0);\r
   PlatformRecovery = (BOOLEAN) ((OsIndication & EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY) != 0);\r
@@ -878,7 +890,7 @@ BdsEntry (
   //\r
   // Launch Boot Manager Menu directly when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set. Skip HotkeyBoot\r
   //\r
-  if (BootFwUi) {\r
+  if (BootFwUi && (BootManagerMenuStatus != EFI_NOT_FOUND)) {\r
     //\r
     // Follow generic rule, Call BdsDxeOnConnectConInCallBack to connect ConIn before enter UI\r
     //\r
@@ -923,7 +935,9 @@ BdsEntry (
       if (!EFI_ERROR (Status)) {\r
         EfiBootManagerBoot (&LoadOption);\r
         EfiBootManagerFreeLoadOption (&LoadOption);\r
-        if ((LoadOption.Status == EFI_SUCCESS) && (LoadOption.OptionNumber != BootManagerMenu.OptionNumber)) {\r
+        if ((LoadOption.Status == EFI_SUCCESS) && \r
+            (BootManagerMenuStatus != EFI_NOT_FOUND) &&\r
+            (LoadOption.OptionNumber != BootManagerMenu.OptionNumber)) {\r
           //\r
           // Boot to Boot Manager Menu upon EFI_SUCCESS\r
           // Exception: Do not boot again when the BootNext points to Boot Manager Menu.\r
@@ -938,12 +952,14 @@ BdsEntry (
       // Retry to boot if any of the boot succeeds\r
       //\r
       LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypeBoot);\r
-      BootSuccess = BootBootOptions (LoadOptions, LoadOptionCount, &BootManagerMenu);\r
+      BootSuccess = BootBootOptions (LoadOptions, LoadOptionCount, (BootManagerMenuStatus != EFI_NOT_FOUND) ? &BootManagerMenu : NULL);\r
       EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r
     } while (BootSuccess);\r
   }\r
 \r
-  EfiBootManagerFreeLoadOption (&BootManagerMenu);\r
+  if (BootManagerMenuStatus != EFI_NOT_FOUND) {\r
+    EfiBootManagerFreeLoadOption (&BootManagerMenu);\r
+  }\r
 \r
   if (!BootSuccess) {\r
     LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);\r