]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBm.c
ArmPkg: Implement PlatformBootManagerLib for LinuxBoot
[mirror_edk2.git] / ArmPkg / Library / LinuxBootBootManagerLib / LinuxBootBm.c
CommitLineData
62540372
NP
1/** @file\r
2 Implementation for PlatformBootManagerLib library class interfaces.\r
3\r
4 Copyright (C) 2015-2016, Red Hat, Inc.\r
5 Copyright (c) 2014 - 2019, ARM Ltd. All rights reserved.<BR>\r
6 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
7 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r
8 Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>\r
9\r
10 SPDX-License-Identifier: BSD-2-Clause-Patent\r
11\r
12**/\r
13\r
14#include <Uefi.h>\r
15\r
16#include <Guid/EventGroup.h>\r
17#include <Library/BaseLib.h>\r
18#include <Library/BaseMemoryLib.h>\r
19#include <Library/DebugLib.h>\r
20#include <Library/DevicePathLib.h>\r
21#include <Library/MemoryAllocationLib.h>\r
22#include <Library/PcdLib.h>\r
23#include <Library/UefiBootManagerLib.h>\r
24#include <Library/UefiBootServicesTableLib.h>\r
25#include <Library/UefiLib.h>\r
26#include <Library/UefiRuntimeServicesTableLib.h>\r
27#include <Protocol/LoadedImage.h>\r
28#include <Protocol/PlatformBootManager.h>\r
29\r
30/**\r
31 Register a boot option using a file GUID in the FV.\r
32\r
33 @param FileGuid The file GUID name in the FV.\r
34 @param Description The description of the boot option.\r
35 @param Attributes The attributes of the boot option.\r
36\r
37**/\r
38STATIC\r
39VOID\r
40PlatformRegisterFvBootOption (\r
41 CONST EFI_GUID *FileGuid,\r
42 CHAR16 *Description,\r
43 UINT32 Attributes\r
44 )\r
45{\r
46 EFI_STATUS Status;\r
47 INTN OptionIndex;\r
48 EFI_BOOT_MANAGER_LOAD_OPTION NewOption;\r
49 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;\r
50 UINTN BootOptionCount;\r
51 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;\r
52 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
53 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
54\r
55 Status = gBS->HandleProtocol (\r
56 gImageHandle,\r
57 &gEfiLoadedImageProtocolGuid,\r
58 (VOID **)&LoadedImage\r
59 );\r
60 ASSERT_EFI_ERROR (Status);\r
61\r
62 EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);\r
63 DevicePath = DevicePathFromHandle (LoadedImage->DeviceHandle);\r
64 ASSERT (DevicePath != NULL);\r
65 DevicePath = AppendDevicePathNode (\r
66 DevicePath,\r
67 (EFI_DEVICE_PATH_PROTOCOL *)&FileNode\r
68 );\r
69 ASSERT (DevicePath != NULL);\r
70\r
71 Status = EfiBootManagerInitializeLoadOption (\r
72 &NewOption,\r
73 LoadOptionNumberUnassigned,\r
74 LoadOptionTypeBoot,\r
75 Attributes,\r
76 Description,\r
77 DevicePath,\r
78 NULL,\r
79 0\r
80 );\r
81 ASSERT_EFI_ERROR (Status);\r
82 FreePool (DevicePath);\r
83\r
84 BootOptions = EfiBootManagerGetLoadOptions (\r
85 &BootOptionCount,\r
86 LoadOptionTypeBoot\r
87 );\r
88\r
89 OptionIndex = EfiBootManagerFindLoadOption (\r
90 &NewOption,\r
91 BootOptions,\r
92 BootOptionCount\r
93 );\r
94\r
95 if (OptionIndex == -1) {\r
96 Status = EfiBootManagerAddLoadOptionVariable (&NewOption, MAX_UINTN);\r
97 ASSERT_EFI_ERROR (Status);\r
98 }\r
99 EfiBootManagerFreeLoadOption (&NewOption);\r
100 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);\r
101}\r
102\r
103/**\r
104 Do the platform specific action before the console is connected.\r
105\r
106 Such as:\r
107 Update console variable;\r
108 Register new Driver#### or Boot####;\r
109 Signal ReadyToLock event.\r
110**/\r
111VOID\r
112EFIAPI\r
113PlatformBootManagerBeforeConsole (\r
114 VOID\r
115 )\r
116{\r
117 //\r
118 // Signal EndOfDxe PI Event\r
119 //\r
120 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);\r
121}\r
122\r
123/**\r
124 Do the platform specific action after the console is connected.\r
125\r
126 Such as:\r
127 Dynamically switch output mode;\r
128 Signal console ready platform customized event;\r
129 Run diagnostics like memory testing;\r
130 Connect certain devices;\r
131 Dispatch additional option roms.\r
132**/\r
133VOID\r
134EFIAPI\r
135PlatformBootManagerAfterConsole (\r
136 VOID\r
137 )\r
138{\r
139 EFI_GUID LinuxBootFileGuid;\r
140\r
141 CopyGuid (&LinuxBootFileGuid, PcdGetPtr (PcdLinuxBootFileGuid));\r
142\r
143 if (!CompareGuid (&LinuxBootFileGuid, &gZeroGuid)) {\r
144 //\r
145 // Register LinuxBoot\r
146 //\r
147 PlatformRegisterFvBootOption (\r
148 &LinuxBootFileGuid,\r
149 L"LinuxBoot",\r
150 LOAD_OPTION_ACTIVE\r
151 );\r
152 } else {\r
153 DEBUG ((DEBUG_ERROR, "%a: PcdLinuxBootFileGuid was not set!\n", __FUNCTION__));\r
154 }\r
155}\r
156\r
157/**\r
158 This function is called each second during the boot manager waits the\r
159 timeout.\r
160\r
161 @param TimeoutRemain The remaining timeout.\r
162**/\r
163VOID\r
164EFIAPI\r
165PlatformBootManagerWaitCallback (\r
166 UINT16 TimeoutRemain\r
167 )\r
168{\r
169 return;\r
170}\r
171\r
172/**\r
173 The function is called when no boot option could be launched,\r
174 including platform recovery options and options pointing to applications\r
175 built into firmware volumes.\r
176\r
177 If this function returns, BDS attempts to enter an infinite loop.\r
178**/\r
179VOID\r
180EFIAPI\r
181PlatformBootManagerUnableToBoot (\r
182 VOID\r
183 )\r
184{\r
185 return;\r
186}\r