]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg: Implement PlatformBootManagerLib for LinuxBoot
authorNhi Pham <nhi@os.amperecomputing.com>
Sat, 23 Oct 2021 07:32:41 +0000 (14:32 +0700)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sat, 23 Oct 2021 08:38:20 +0000 (08:38 +0000)
LinuxBoot is a firmware that replaces specific firmware functionality
like the UEFI DXE phase with a Linux kernel and runtime. It is built-in
UEFI image like an application, which is executed at the end of DXE
phase.

To achieve the LinuxBoot boot flow "SEC->PEI->DXE->BDS->LinuxBoot",
today we use the common well-known GUID of UEFI Shell for LinuxBoot
payload, so LinuxBoot developers can effortlessly find the UEFI Shell
Application and replace it with the LinuxBoot payload without
recompiling platform EDK2 (There might be an issue with a few systems
that don't have a UEFI Shell). Also, we have a hard requirement to force
the BDS to boot into the LinuxBoot as it is essentially required that
only the LinuxBoot boot option is permissible and UEFI is an
intermediate bootstrap phase. Considering all the above, it is
reasonable to just have a new GUID for LinuxBoot and require a LinuxBoot
specific BDS implementation. In addition, with making the BDS
implementation simpler, we can reduce many DXE drivers which we think it
is not necessary for LinuxBoot booting.

This patch adds a new PlatformBootManagerLib implementation which
registers only the gArmTokenSpaceGuid.PcdLinuxBootFileGuid for LinuxBoot
payload as an active boot option. It allows BDS to jump to the LinuxBoot
quickly by skipping the UiApp and UEFI Shell.

The PlatformBootManagerLib library derived from
ArmPkg/Library/PlatformBootManagerLib.

Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
Acked-by: Moritz Fischer <moritzf@google.com>
ArmPkg/ArmPkg.dec
ArmPkg/ArmPkg.dsc
ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBm.c [new file with mode: 0644]
ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBootManagerLib.inf [new file with mode: 0644]

index 5935663fa9a382704651b3e7ac1b2d7873f1200d..9da1bbc9f2166dc8ae93f96a34d3165fffed34dc 100644 (file)
@@ -3,6 +3,7 @@
 #\r
 # Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>\r
 # Copyright (c) 2011 - 2021, 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
   #\r
   gArmTokenSpaceGuid.PcdPciBusMin|0x0|UINT32|0x00000059\r
   gArmTokenSpaceGuid.PcdPciBusMax|0x0|UINT32|0x0000005A\r
+\r
+[PcdsDynamicEx]\r
+  #\r
+  # This dynamic PCD hold the GUID of a firmware FFS which contains\r
+  # the LinuxBoot payload.\r
+  #\r
+  gArmTokenSpaceGuid.PcdLinuxBootFileGuid|{0x0}|VOID*|0x0000005C\r
index 8abe3713c829cbe81842c52de6982e7cbef5c323..59fd8f295d4f614cc68ee1021e691f94e279ab81 100644 (file)
@@ -5,6 +5,7 @@
 # Copyright (c) 2011 - 2021, Arm Limited. All rights reserved.<BR>\r
 # Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r
 # Copyright (c) Microsoft Corporation.<BR>\r
+# Copyright (c) 2021, Ampere Computing LLC. All rights reserved.\r
 #\r
 #    SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
   ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf\r
   ArmPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf\r
   ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf\r
+  ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBootManagerLib.inf\r
 \r
   ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.inf\r
   ArmPkg/Drivers/ArmScmiDxe/ArmScmiDxe.inf\r
diff --git a/ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBm.c b/ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBm.c
new file mode 100644 (file)
index 0000000..3295c5a
--- /dev/null
@@ -0,0 +1,186 @@
+/** @file\r
+  Implementation for PlatformBootManagerLib library class interfaces.\r
+\r
+  Copyright (C) 2015-2016, Red Hat, Inc.\r
+  Copyright (c) 2014 - 2019, 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) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Guid/EventGroup.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/UefiBootManagerLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Protocol/LoadedImage.h>\r
+#include <Protocol/PlatformBootManager.h>\r
+\r
+/**\r
+  Register a boot option using a file GUID in the FV.\r
+\r
+  @param  FileGuid     The file GUID name in the FV.\r
+  @param  Description  The description of the boot option.\r
+  @param  Attributes   The attributes of the boot option.\r
+\r
+**/\r
+STATIC\r
+VOID\r
+PlatformRegisterFvBootOption (\r
+  CONST EFI_GUID *FileGuid,\r
+  CHAR16         *Description,\r
+  UINT32         Attributes\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  INTN                              OptionIndex;\r
+  EFI_BOOT_MANAGER_LOAD_OPTION      NewOption;\r
+  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 (\r
+                  gImageHandle,\r
+                  &gEfiLoadedImageProtocolGuid,\r
+                  (VOID **)&LoadedImage\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\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
+             Attributes,\r
+             Description,\r
+             DevicePath,\r
+             NULL,\r
+             0\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+  FreePool (DevicePath);\r
+\r
+  BootOptions = EfiBootManagerGetLoadOptions (\r
+                  &BootOptionCount,\r
+                  LoadOptionTypeBoot\r
+                  );\r
+\r
+  OptionIndex = EfiBootManagerFindLoadOption (\r
+                  &NewOption,\r
+                  BootOptions,\r
+                  BootOptionCount\r
+                  );\r
+\r
+  if (OptionIndex == -1) {\r
+    Status = EfiBootManagerAddLoadOptionVariable (&NewOption, MAX_UINTN);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+  EfiBootManagerFreeLoadOption (&NewOption);\r
+  EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);\r
+}\r
+\r
+/**\r
+  Do the platform specific action before the console is connected.\r
+\r
+  Such as:\r
+    Update console variable;\r
+    Register new Driver#### or Boot####;\r
+    Signal ReadyToLock event.\r
+**/\r
+VOID\r
+EFIAPI\r
+PlatformBootManagerBeforeConsole (\r
+  VOID\r
+  )\r
+{\r
+  //\r
+  // Signal EndOfDxe PI Event\r
+  //\r
+  EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);\r
+}\r
+\r
+/**\r
+  Do the platform specific action after the console is connected.\r
+\r
+  Such as:\r
+    Dynamically switch output mode;\r
+    Signal console ready platform customized event;\r
+    Run diagnostics like memory testing;\r
+    Connect certain devices;\r
+    Dispatch additional option roms.\r
+**/\r
+VOID\r
+EFIAPI\r
+PlatformBootManagerAfterConsole (\r
+  VOID\r
+  )\r
+{\r
+  EFI_GUID LinuxBootFileGuid;\r
+\r
+  CopyGuid (&LinuxBootFileGuid, PcdGetPtr (PcdLinuxBootFileGuid));\r
+\r
+  if (!CompareGuid (&LinuxBootFileGuid, &gZeroGuid)) {\r
+    //\r
+    // Register LinuxBoot\r
+    //\r
+    PlatformRegisterFvBootOption (\r
+      &LinuxBootFileGuid,\r
+      L"LinuxBoot",\r
+      LOAD_OPTION_ACTIVE\r
+      );\r
+  } else {\r
+    DEBUG ((DEBUG_ERROR, "%a: PcdLinuxBootFileGuid was not set!\n", __FUNCTION__));\r
+  }\r
+}\r
+\r
+/**\r
+  This function is called each second during the boot manager waits the\r
+  timeout.\r
+\r
+  @param TimeoutRemain  The remaining timeout.\r
+**/\r
+VOID\r
+EFIAPI\r
+PlatformBootManagerWaitCallback (\r
+  UINT16 TimeoutRemain\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+/**\r
+  The function is called when no boot option could be launched,\r
+  including platform recovery options and options pointing to applications\r
+  built into firmware volumes.\r
+\r
+  If this function returns, BDS attempts to enter an infinite loop.\r
+**/\r
+VOID\r
+EFIAPI\r
+PlatformBootManagerUnableToBoot (\r
+  VOID\r
+  )\r
+{\r
+  return;\r
+}\r
diff --git a/ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBootManagerLib.inf b/ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBootManagerLib.inf
new file mode 100644 (file)
index 0000000..139b617
--- /dev/null
@@ -0,0 +1,58 @@
+## @file\r
+#  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) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r
+#  Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>\r
+#\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x0001001B\r
+  BASE_NAME                      = LinuxBootBootManagerLib\r
+  FILE_GUID                      = 1FA91547-DB23-4F6A-8AF8-3B9782A7F917\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PlatformBootManagerLib|DXE_DRIVER\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = ARM AARCH64\r
+#\r
+\r
+[Sources]\r
+  LinuxBootBm.c\r
+\r
+[Packages]\r
+  ArmPkg/ArmPkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  MdePkg/MdePkg.dec\r
+  ShellPkg/ShellPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  MemoryAllocationLib\r
+  PcdLib\r
+  PrintLib\r
+  UefiBootManagerLib\r
+  UefiBootServicesTableLib\r
+  UefiLib\r
+  UefiRuntimeServicesTableLib\r
+\r
+[Pcd]\r
+  gArmTokenSpaceGuid.PcdLinuxBootFileGuid\r
+\r
+[Guids]\r
+  gEfiEndOfDxeEventGroupGuid\r
+  gUefiShellFileGuid\r
+  gZeroGuid\r
+\r
+[Protocols]\r
+  gEfiLoadedImageProtocolGuid\r