]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBm.c
ArmPkg: Implement PlatformBootManagerLib for LinuxBoot
[mirror_edk2.git] / ArmPkg / Library / LinuxBootBootManagerLib / LinuxBootBm.c
1 /** @file
2 Implementation for PlatformBootManagerLib library class interfaces.
3
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>
9
10 SPDX-License-Identifier: BSD-2-Clause-Patent
11
12 **/
13
14 #include <Uefi.h>
15
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>
29
30 /**
31 Register a boot option using a file GUID in the FV.
32
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.
36
37 **/
38 STATIC
39 VOID
40 PlatformRegisterFvBootOption (
41 CONST EFI_GUID *FileGuid,
42 CHAR16 *Description,
43 UINT32 Attributes
44 )
45 {
46 EFI_STATUS Status;
47 INTN OptionIndex;
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;
54
55 Status = gBS->HandleProtocol (
56 gImageHandle,
57 &gEfiLoadedImageProtocolGuid,
58 (VOID **)&LoadedImage
59 );
60 ASSERT_EFI_ERROR (Status);
61
62 EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);
63 DevicePath = DevicePathFromHandle (LoadedImage->DeviceHandle);
64 ASSERT (DevicePath != NULL);
65 DevicePath = AppendDevicePathNode (
66 DevicePath,
67 (EFI_DEVICE_PATH_PROTOCOL *)&FileNode
68 );
69 ASSERT (DevicePath != NULL);
70
71 Status = EfiBootManagerInitializeLoadOption (
72 &NewOption,
73 LoadOptionNumberUnassigned,
74 LoadOptionTypeBoot,
75 Attributes,
76 Description,
77 DevicePath,
78 NULL,
79 0
80 );
81 ASSERT_EFI_ERROR (Status);
82 FreePool (DevicePath);
83
84 BootOptions = EfiBootManagerGetLoadOptions (
85 &BootOptionCount,
86 LoadOptionTypeBoot
87 );
88
89 OptionIndex = EfiBootManagerFindLoadOption (
90 &NewOption,
91 BootOptions,
92 BootOptionCount
93 );
94
95 if (OptionIndex == -1) {
96 Status = EfiBootManagerAddLoadOptionVariable (&NewOption, MAX_UINTN);
97 ASSERT_EFI_ERROR (Status);
98 }
99 EfiBootManagerFreeLoadOption (&NewOption);
100 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
101 }
102
103 /**
104 Do the platform specific action before the console is connected.
105
106 Such as:
107 Update console variable;
108 Register new Driver#### or Boot####;
109 Signal ReadyToLock event.
110 **/
111 VOID
112 EFIAPI
113 PlatformBootManagerBeforeConsole (
114 VOID
115 )
116 {
117 //
118 // Signal EndOfDxe PI Event
119 //
120 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);
121 }
122
123 /**
124 Do the platform specific action after the console is connected.
125
126 Such as:
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.
132 **/
133 VOID
134 EFIAPI
135 PlatformBootManagerAfterConsole (
136 VOID
137 )
138 {
139 EFI_GUID LinuxBootFileGuid;
140
141 CopyGuid (&LinuxBootFileGuid, PcdGetPtr (PcdLinuxBootFileGuid));
142
143 if (!CompareGuid (&LinuxBootFileGuid, &gZeroGuid)) {
144 //
145 // Register LinuxBoot
146 //
147 PlatformRegisterFvBootOption (
148 &LinuxBootFileGuid,
149 L"LinuxBoot",
150 LOAD_OPTION_ACTIVE
151 );
152 } else {
153 DEBUG ((DEBUG_ERROR, "%a: PcdLinuxBootFileGuid was not set!\n", __FUNCTION__));
154 }
155 }
156
157 /**
158 This function is called each second during the boot manager waits the
159 timeout.
160
161 @param TimeoutRemain The remaining timeout.
162 **/
163 VOID
164 EFIAPI
165 PlatformBootManagerWaitCallback (
166 UINT16 TimeoutRemain
167 )
168 {
169 return;
170 }
171
172 /**
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.
176
177 If this function returns, BDS attempts to enter an infinite loop.
178 **/
179 VOID
180 EFIAPI
181 PlatformBootManagerUnableToBoot (
182 VOID
183 )
184 {
185 return;
186 }