2 Implementation for PlatformBootManagerLib library class interfaces.
4 Copyright (C) 2015-2016, Red Hat, Inc.
5 Copyright (c) 2014 - 2019, ARM Ltd. All rights reserved.<BR>
6 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
7 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
8 Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
10 SPDX-License-Identifier: BSD-2-Clause-Patent
16 #include <Guid/EventGroup.h>
17 #include <Library/BaseLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/DevicePathLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/PcdLib.h>
23 #include <Library/UefiBootManagerLib.h>
24 #include <Library/UefiBootServicesTableLib.h>
25 #include <Library/UefiLib.h>
26 #include <Library/UefiRuntimeServicesTableLib.h>
27 #include <Protocol/LoadedImage.h>
28 #include <Protocol/PlatformBootManager.h>
31 Register a boot option using a file GUID in the FV.
33 @param FileGuid The file GUID name in the FV.
34 @param Description The description of the boot option.
35 @param Attributes The attributes of the boot option.
40 PlatformRegisterFvBootOption (
41 CONST EFI_GUID
*FileGuid
,
48 EFI_BOOT_MANAGER_LOAD_OPTION NewOption
;
49 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOptions
;
50 UINTN BootOptionCount
;
51 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode
;
52 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
53 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
55 Status
= gBS
->HandleProtocol (
57 &gEfiLoadedImageProtocolGuid
,
60 ASSERT_EFI_ERROR (Status
);
62 EfiInitializeFwVolDevicepathNode (&FileNode
, FileGuid
);
63 DevicePath
= DevicePathFromHandle (LoadedImage
->DeviceHandle
);
64 ASSERT (DevicePath
!= NULL
);
65 DevicePath
= AppendDevicePathNode (
67 (EFI_DEVICE_PATH_PROTOCOL
*)&FileNode
69 ASSERT (DevicePath
!= NULL
);
71 Status
= EfiBootManagerInitializeLoadOption (
73 LoadOptionNumberUnassigned
,
81 ASSERT_EFI_ERROR (Status
);
82 FreePool (DevicePath
);
84 BootOptions
= EfiBootManagerGetLoadOptions (
89 OptionIndex
= EfiBootManagerFindLoadOption (
95 if (OptionIndex
== -1) {
96 Status
= EfiBootManagerAddLoadOptionVariable (&NewOption
, MAX_UINTN
);
97 ASSERT_EFI_ERROR (Status
);
99 EfiBootManagerFreeLoadOption (&NewOption
);
100 EfiBootManagerFreeLoadOptions (BootOptions
, BootOptionCount
);
104 Do the platform specific action before the console is connected.
107 Update console variable;
108 Register new Driver#### or Boot####;
109 Signal ReadyToLock event.
113 PlatformBootManagerBeforeConsole (
118 // Signal EndOfDxe PI Event
120 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid
);
124 Do the platform specific action after the console is connected.
127 Dynamically switch output mode;
128 Signal console ready platform customized event;
129 Run diagnostics like memory testing;
130 Connect certain devices;
131 Dispatch additional option roms.
135 PlatformBootManagerAfterConsole (
139 EFI_GUID LinuxBootFileGuid
;
141 CopyGuid (&LinuxBootFileGuid
, PcdGetPtr (PcdLinuxBootFileGuid
));
143 if (!CompareGuid (&LinuxBootFileGuid
, &gZeroGuid
)) {
145 // Register LinuxBoot
147 PlatformRegisterFvBootOption (
153 DEBUG ((DEBUG_ERROR
, "%a: PcdLinuxBootFileGuid was not set!\n", __FUNCTION__
));
158 This function is called each second during the boot manager waits the
161 @param TimeoutRemain The remaining timeout.
165 PlatformBootManagerWaitCallback (
173 The function is called when no boot option could be launched,
174 including platform recovery options and options pointing to applications
175 built into firmware volumes.
177 If this function returns, BDS attempts to enter an infinite loop.
181 PlatformBootManagerUnableToBoot (