]> xenbits.xensource.com Git - ovmf.git/commitdiff
ArmPkg/PlatformBootManagerLib: Add path to boot UEFI Shell over UiApp
authorPierre Gondois <pierre.gondois@arm.com>
Tue, 25 Apr 2023 11:27:16 +0000 (13:27 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 4 May 2023 14:26:58 +0000 (14:26 +0000)
The UEFI Shell is a non-active boot option, at the opposite of UiApp.
If no valid boot option is found, UiApp is selected. UiApp requires a
human interaction. When installing a new EDKII image in CIs or when
scripting is required, this is problematic.

If no valid boot option is discovered, add a path to directly go to
the UEFI Shell where the startup.nsh script is automatically executed.
The UEFI Shell is launched after connecting possible devices, but
before the reset that is meant to automatically make them visible.

The new PcdUefiShellDefaultBootEnable must be set to TRUE to enable
this behaviour. The Pcd is set to false by default.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Tested-by: Patrik Berglund <patrik.berglund@arm.com>
ArmPkg/ArmPkg.dec
ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c
ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf

index f17ba913e6de1326d49b93d6a15378ff2f522d24..2444457ae58ad8e50733595228f28b14cca62c10 100644 (file)
@@ -2,7 +2,7 @@
 # ARM processor package.\r
 #\r
 # Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>\r
-# Copyright (c) 2011 - 2022, ARM Limited. All rights reserved.\r
+# Copyright (c) 2011 - 2023, ARM Limited. All rights reserved.\r
 # Copyright (c) 2021, Ampere Computing LLC. All rights reserved.\r
 #\r
 #    SPDX-License-Identifier: BSD-2-Clause-Patent\r
   #\r
   gArmTokenSpaceGuid.PcdArmDmaDeviceOffset|0x0|UINT64|0x0000044\r
 \r
+  #\r
+  # Boot the Uefi Shell instead of UiApp when no valid boot option is found.\r
+  # This is useful in CI environment so that startup.nsh can be launched.\r
+  # The default value is FALSE.\r
+  #\r
+  gArmTokenSpaceGuid.PcdUefiShellDefaultBootEnable|FALSE|BOOLEAN|0x0000052\r
+\r
 [PcdsFixedAtBuild.common, PcdsPatchableInModule.common]\r
   gArmTokenSpaceGuid.PcdFdBaseAddress|0|UINT64|0x0000002B\r
   gArmTokenSpaceGuid.PcdFvBaseAddress|0|UINT64|0x0000002D\r
index 08998ffe4d17f7a9ca7f5975aa33eaad7247763d..ea093bb725234d80f020546a5bc1aa52f0fb216f 100644 (file)
@@ -2,7 +2,7 @@
   Implementation for PlatformBootManagerLib library class interfaces.\r
 \r
   Copyright (C) 2015-2016, Red Hat, Inc.\r
-  Copyright (c) 2014 - 2021, ARM Ltd. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2023, Arm Ltd. All rights reserved.<BR>\r
   Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
   Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r
   Copyright (c) 2021, Semihalf All rights reserved.<BR>\r
@@ -470,6 +470,64 @@ PlatformRegisterFvBootOption (
   EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);\r
 }\r
 \r
+/** Boot a Fv Boot Option.\r
+\r
+  This function is useful for booting the UEFI Shell as it is loaded\r
+  as a non active boot option.\r
+\r
+  @param[in] FileGuid      The File GUID.\r
+  @param[in] Description   String describing the Boot Option.\r
+\r
+**/\r
+STATIC\r
+VOID\r
+PlatformBootFvBootOption (\r
+  IN  CONST EFI_GUID  *FileGuid,\r
+  IN  CHAR16          *Description\r
+  )\r
+{\r
+  EFI_STATUS                         Status;\r
+  EFI_BOOT_MANAGER_LOAD_OPTION       NewOption;\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 (\r
+                  gImageHandle,\r
+                  &gEfiLoadedImageProtocolGuid,\r
+                  (VOID **)&LoadedImage\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // The UEFI Shell was registered in PlatformRegisterFvBootOption ()\r
+  // previously, thus it must still be available in this FV.\r
+  //\r
+  EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);\r
+  DevicePath = DevicePathFromHandle (LoadedImage->DeviceHandle);\r
+  ASSERT (DevicePath != NULL);\r
+  DevicePath = AppendDevicePathNode (\r
+                 DevicePath,\r
+                 (EFI_DEVICE_PATH_PROTOCOL *)&FileNode\r
+                 );\r
+  ASSERT (DevicePath != NULL);\r
+\r
+  Status = EfiBootManagerInitializeLoadOption (\r
+             &NewOption,\r
+             LoadOptionNumberUnassigned,\r
+             LoadOptionTypeBoot,\r
+             LOAD_OPTION_ACTIVE,\r
+             Description,\r
+             DevicePath,\r
+             NULL,\r
+             0\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+  FreePool (DevicePath);\r
+\r
+  EfiBootManagerBoot (&NewOption);\r
+}\r
+\r
 STATIC\r
 VOID\r
 GetPlatformOptions (\r
@@ -1075,6 +1133,18 @@ PlatformBootManagerUnableToBoot (
   EfiBootManagerConnectAll ();\r
   EfiBootManagerRefreshAllBootOption ();\r
 \r
+  //\r
+  // Boot the 'UEFI Shell'. If the Pcd is not set, the UEFI Shell is not\r
+  // an active boot option and must be manually selected through UiApp\r
+  // (at least during the fist boot).\r
+  //\r
+  if (FixedPcdGetBool (PcdUefiShellDefaultBootEnable)) {\r
+    PlatformBootFvBootOption (\r
+      &gUefiShellFileGuid,\r
+      L"UEFI Shell (default)"\r
+      );\r
+  }\r
+\r
   //\r
   // Record the updated number of boot configured boot options\r
   //\r
index 86751b45f82b21a968c00b4f78a92c51be2c79e0..05ed46456cc482d735490ad4418aa75a1b331aa7 100644 (file)
@@ -2,7 +2,7 @@
 #  Implementation for PlatformBootManagerLib library class interfaces.\r
 #\r
 #  Copyright (C) 2015-2016, Red Hat, Inc.\r
-#  Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>\r
+#  Copyright (c) 2014 - 2023, Arm Ltd. All rights reserved.<BR>\r
 #  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
 #  Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r
 #\r
@@ -29,6 +29,7 @@
   PlatformBm.h\r
 \r
 [Packages]\r
+  ArmPkg/ArmPkg.dec\r
   EmbeddedPkg/EmbeddedPkg.dec\r
   MdeModulePkg/MdeModulePkg.dec\r
   MdePkg/MdePkg.dec\r
@@ -55,6 +56,7 @@
   gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport\r
 \r
 [FixedPcd]\r
+  gArmTokenSpaceGuid.PcdUefiShellDefaultBootEnable\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString\r
   gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate\r