]> xenbits.xensource.com Git - ovmf.git/commitdiff
UefiPayloadPkg: Fix boot shell issue for universal UEFI payload
authorGuo Dong <guo.dong@intel.com>
Wed, 10 May 2023 03:53:55 +0000 (20:53 -0700)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 15 May 2023 21:26:04 +0000 (21:26 +0000)
After moving BDS driver to a new FV for universal UEFI payload,
the shell boot option path is not correct since it used the BDS
FV instead of DXE FV in its device path.
This patch would find the correct FV by reading shell file.
It also removed PcdShellFile by using gUefiShellFileGuid.

Signed-off-by: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Cc: James Lu <james.lu@intel.com>
Cc: Gua Guo <gua.guo@intel.com>
Reviewed-by: James Lu <james.lu@intel.com>
Reviewed-by: Gua Guo <gua.guo@intel.com>
Reviewed-by: Mike Maslenkin <mike.maslenkin@gmail.com>
UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
UefiPayloadPkg/UefiPayloadPkg.dec

index 62637ae6aa0c509742e672586b9fc2e3fc395bf1..4a0219624d8fb2797097a048acdb404da08a8e48 100644 (file)
@@ -2,7 +2,7 @@
   This file include all platform action which can be customized\r
   by IBV/OEM.\r
 \r
-Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2023, Intel Corporation. All rights reserved.<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -11,6 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include "PlatformConsole.h"\r
 #include <Guid/BootManagerMenu.h>\r
 #include <Library/HobLib.h>\r
+#include <Protocol/FirmwareVolume2.h>\r
 \r
 /**\r
   Signal EndOfDxe event and install SMM Ready to lock protocol.\r
@@ -89,6 +90,77 @@ PlatformFindLoadOption (
   return -1;\r
 }\r
 \r
+/**\r
+  Get the FV device path for the shell file.\r
+\r
+  @return   A pointer to device path structure.\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+BdsGetShellFvDevicePath (\r
+  VOID\r
+  )\r
+{\r
+  UINTN                          FvHandleCount;\r
+  EFI_HANDLE                     *FvHandleBuffer;\r
+  UINTN                          Index;\r
+  EFI_STATUS                     Status;\r
+  EFI_FIRMWARE_VOLUME2_PROTOCOL  *Fv;\r
+  UINTN                          Size;\r
+  UINT32                         AuthenticationStatus;\r
+  EFI_DEVICE_PATH_PROTOCOL       *DevicePath;\r
+  EFI_FV_FILETYPE                FoundType;\r
+  EFI_FV_FILE_ATTRIBUTES         FileAttributes;\r
+\r
+  Status = EFI_SUCCESS;\r
+  gBS->LocateHandleBuffer (\r
+         ByProtocol,\r
+         &gEfiFirmwareVolume2ProtocolGuid,\r
+         NULL,\r
+         &FvHandleCount,\r
+         &FvHandleBuffer\r
+         );\r
+\r
+  for (Index = 0; Index < FvHandleCount; Index++) {\r
+    Size = 0;\r
+    gBS->HandleProtocol (\r
+           FvHandleBuffer[Index],\r
+           &gEfiFirmwareVolume2ProtocolGuid,\r
+           (VOID **)&Fv\r
+           );\r
+    Status = Fv->ReadFile (\r
+                   Fv,\r
+                   &gUefiShellFileGuid,\r
+                   NULL,\r
+                   &Size,\r
+                   &FoundType,\r
+                   &FileAttributes,\r
+                   &AuthenticationStatus\r
+                   );\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Found the shell file\r
+      //\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    if (FvHandleCount) {\r
+      FreePool (FvHandleBuffer);\r
+    }\r
+\r
+    return NULL;\r
+  }\r
+\r
+  DevicePath = DevicePathFromHandle (FvHandleBuffer[Index]);\r
+\r
+  if (FvHandleCount) {\r
+    FreePool (FvHandleBuffer);\r
+  }\r
+\r
+  return DevicePath;\r
+}\r
+\r
 /**\r
   Register a boot option using a file GUID in the FV.\r
 \r
@@ -109,15 +181,11 @@ PlatformRegisterFvBootOption (
   EFI_BOOT_MANAGER_LOAD_OPTION       *BootOptions;\r
   UINTN                              BootOptionCount;\r
   MEDIA_FW_VOL_FILEPATH_DEVICE_PATH  FileNode;\r
-  EFI_LOADED_IMAGE_PROTOCOL          *LoadedImage;\r
   EFI_DEVICE_PATH_PROTOCOL           *DevicePath;\r
 \r
-  Status = gBS->HandleProtocol (gImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&LoadedImage);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
   EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);\r
   DevicePath = AppendDevicePathNode (\r
-                 DevicePathFromHandle (LoadedImage->DeviceHandle),\r
+                 BdsGetShellFvDevicePath (),\r
                  (EFI_DEVICE_PATH_PROTOCOL *)&FileNode\r
                  );\r
 \r
@@ -248,7 +316,7 @@ PlatformBootManagerAfterConsole (
   //\r
   // Register UEFI Shell\r
   //\r
-  PlatformRegisterFvBootOption (PcdGetPtr (PcdShellFile), L"UEFI Shell", LOAD_OPTION_ACTIVE);\r
+  PlatformRegisterFvBootOption (&gUefiShellFileGuid, L"UEFI Shell", LOAD_OPTION_ACTIVE);\r
 \r
   if (FixedPcdGetBool (PcdBootManagerEscape)) {\r
     Print (\r
index f9626175e21680d261831a4a0723e064d05ae41a..a3951b7a7ef750162d695c155d95a77702345861 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  Include all platform action which can be customized by IBV/OEM.\r
 #\r
-#  Copyright (c) 2012 - 2021, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2012 - 2023, Intel Corporation. All rights reserved.<BR>\r
 #  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 ##\r
@@ -32,6 +32,7 @@
   MdePkg/MdePkg.dec\r
   MdeModulePkg/MdeModulePkg.dec\r
   UefiPayloadPkg/UefiPayloadPkg.dec\r
+  ShellPkg/ShellPkg.dec\r
 \r
 [LibraryClasses]\r
   BaseLib\r
@@ -52,6 +53,7 @@
 [Guids]\r
   gEfiEndOfDxeEventGroupGuid\r
   gEdkiiBootManagerMenuFileGuid\r
+  gUefiShellFileGuid\r
 \r
 [Protocols]\r
   gEfiGenericMemTestProtocolGuid  ## CONSUMES\r
@@ -69,7 +71,6 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdConInConnectOnDemand\r
-  gUefiPayloadPkgTokenSpaceGuid.PcdShellFile\r
   gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate\r
   gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits\r
   gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity\r
index a23a7b5a78afff8338905d060182a55d7aaa86f2..8d111f3a905264b40462d493faaa69b2264d55dc 100644 (file)
@@ -67,9 +67,6 @@ gUefiPayloadPkgTokenSpaceGuid.PcdPayloadFdMemSize|0|UINT32|0x10000002
 ## Save bootloader parameter\r
 gUefiPayloadPkgTokenSpaceGuid.PcdBootloaderParameter|0|UINT64|0x10000004\r
 \r
-## FFS filename to find the shell application.\r
-gUefiPayloadPkgTokenSpaceGuid.PcdShellFile|{ 0x83, 0xA5, 0x04, 0x7C, 0x3E, 0x9E, 0x1c, 0x4f, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 }|VOID*|0x10000005\r
-\r
 ## Used to help reduce fragmentation in the EFI memory map\r
 gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory|0x19|UINT32|0x10000012\r
 gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS|0x04|UINT32|0x10000013\r