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
);
100 EfiBootManagerFreeLoadOption (&NewOption
);
101 EfiBootManagerFreeLoadOptions (BootOptions
, BootOptionCount
);
105 Do the platform specific action before the console is connected.
108 Update console variable;
109 Register new Driver#### or Boot####;
110 Signal ReadyToLock event.
114 PlatformBootManagerBeforeConsole (
119 // Signal EndOfDxe PI Event
121 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid
);
125 Do the platform specific action after the console is connected.
128 Dynamically switch output mode;
129 Signal console ready platform customized event;
130 Run diagnostics like memory testing;
131 Connect certain devices;
132 Dispatch additional option roms.
136 PlatformBootManagerAfterConsole (
140 EFI_GUID LinuxBootFileGuid
;
142 CopyGuid (&LinuxBootFileGuid
, PcdGetPtr (PcdLinuxBootFileGuid
));
144 if (!CompareGuid (&LinuxBootFileGuid
, &gZeroGuid
)) {
146 // Register LinuxBoot
148 PlatformRegisterFvBootOption (
154 DEBUG ((DEBUG_ERROR
, "%a: PcdLinuxBootFileGuid was not set!\n", __FUNCTION__
));
159 This function is called each second during the boot manager waits the
162 @param TimeoutRemain The remaining timeout.
166 PlatformBootManagerWaitCallback (
174 The function is called when no boot option could be launched,
175 including platform recovery options and options pointing to applications
176 built into firmware volumes.
178 If this function returns, BDS attempts to enter an infinite loop.
182 PlatformBootManagerUnableToBoot (