--- /dev/null
+/** @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
--- /dev/null
+## @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