]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
UefiPayloadPkg: consume the BootManagerMenuFile HOB
[mirror_edk2.git] / UefiPayloadPkg / Library / PlatformBootManagerLib / PlatformBootManager.c
index fce48d26a1a5b55e0fdbdbf1626d0c3f8fa39c63..c4d317fa9e25fa5f746c563baac168071eb40e09 100644 (file)
@@ -10,6 +10,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include "PlatformBootManager.h"\r
 #include "PlatformConsole.h"\r
 #include <Protocol/PlatformBootManagerOverride.h>\r
+#include <Guid/BootManagerMenu.h>\r
+#include <Library/HobLib.h>\r
 \r
 UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_PROTOCOL  *mUniversalPayloadPlatformBootManagerOverrideInstance = NULL;\r
 \r
@@ -286,3 +288,53 @@ PlatformBootManagerUnableToBoot (
   return;\r
 }\r
 \r
+/**\r
+  Get/update PcdBootManagerMenuFile from GUID HOB which will be assigned in bootloader.\r
+\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PlatformBootManagerLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+)\r
+{\r
+  EFI_STATUS                           Status;\r
+  UINTN                                Size;\r
+  VOID                                 *GuidHob;\r
+  UNIVERSAL_PAYLOAD_GENERIC_HEADER     *GenericHeader;\r
+  UNIVERSAL_PAYLOAD_BOOT_MANAGER_MENU  *BootManagerMenuFile;\r
+\r
+  GuidHob = GetFirstGuidHob (&gEdkiiBootManagerMenuFileGuid);\r
+\r
+  if (GuidHob == NULL) {\r
+    //\r
+    // If the HOB is not create, the default value of PcdBootManagerMenuFile will be used.\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  GenericHeader = (UNIVERSAL_PAYLOAD_GENERIC_HEADER *) GET_GUID_HOB_DATA (GuidHob);\r
+  if ((sizeof (UNIVERSAL_PAYLOAD_GENERIC_HEADER) > GET_GUID_HOB_DATA_SIZE (GuidHob)) || (GenericHeader->Length > GET_GUID_HOB_DATA_SIZE (GuidHob))) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  if (GenericHeader->Revision == UNIVERSAL_PAYLOAD_BOOT_MANAGER_MENU_REVISION) {\r
+    BootManagerMenuFile = (UNIVERSAL_PAYLOAD_BOOT_MANAGER_MENU *) GET_GUID_HOB_DATA (GuidHob);\r
+    if (BootManagerMenuFile->Header.Length < UNIVERSAL_PAYLOAD_SIZEOF_THROUGH_FIELD (UNIVERSAL_PAYLOAD_BOOT_MANAGER_MENU, FileName)) {\r
+      return EFI_NOT_FOUND;\r
+    }\r
+    Size = sizeof (BootManagerMenuFile->FileName);\r
+    Status = PcdSetPtrS (PcdBootManagerMenuFile, &Size, &BootManagerMenuFile->FileName);\r
+    ASSERT_EFI_ERROR (Status);\r
+  } else {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r