]> git.proxmox.com Git - mirror_edk2.git/blob - CorebootPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
CorebootPayload/PlatformBDS: Impl PlatformBootManagerUnableToBoot
[mirror_edk2.git] / CorebootPayloadPkg / Library / PlatformBootManagerLib / PlatformBootManager.c
1 /** @file
2 This file include all platform action which can be customized
3 by IBV/OEM.
4
5 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "PlatformBootManager.h"
17 #include "PlatformConsole.h"
18
19 VOID
20 InstallReadyToLock (
21 VOID
22 )
23 {
24 EFI_STATUS Status;
25 EFI_HANDLE Handle;
26 EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;
27
28 DEBUG((DEBUG_INFO,"InstallReadyToLock entering......\n"));
29 //
30 // Inform the SMM infrastructure that we're entering BDS and may run 3rd party code hereafter
31 // Since PI1.2.1, we need signal EndOfDxe as ExitPmAuth
32 //
33 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);
34 DEBUG((DEBUG_INFO,"All EndOfDxe callbacks have returned successfully\n"));
35
36 //
37 // Install DxeSmmReadyToLock protocol in order to lock SMM
38 //
39 Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **) &SmmAccess);
40 if (!EFI_ERROR (Status)) {
41 Handle = NULL;
42 Status = gBS->InstallProtocolInterface (
43 &Handle,
44 &gEfiDxeSmmReadyToLockProtocolGuid,
45 EFI_NATIVE_INTERFACE,
46 NULL
47 );
48 ASSERT_EFI_ERROR (Status);
49 }
50
51 DEBUG((DEBUG_INFO,"InstallReadyToLock end\n"));
52 return;
53 }
54
55 /**
56 Return the index of the load option in the load option array.
57
58 The function consider two load options are equal when the
59 OptionType, Attributes, Description, FilePath and OptionalData are equal.
60
61 @param Key Pointer to the load option to be found.
62 @param Array Pointer to the array of load options to be found.
63 @param Count Number of entries in the Array.
64
65 @retval -1 Key wasn't found in the Array.
66 @retval 0 ~ Count-1 The index of the Key in the Array.
67 **/
68 INTN
69 PlatformFindLoadOption (
70 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Key,
71 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Array,
72 IN UINTN Count
73 )
74 {
75 UINTN Index;
76
77 for (Index = 0; Index < Count; Index++) {
78 if ((Key->OptionType == Array[Index].OptionType) &&
79 (Key->Attributes == Array[Index].Attributes) &&
80 (StrCmp (Key->Description, Array[Index].Description) == 0) &&
81 (CompareMem (Key->FilePath, Array[Index].FilePath, GetDevicePathSize (Key->FilePath)) == 0) &&
82 (Key->OptionalDataSize == Array[Index].OptionalDataSize) &&
83 (CompareMem (Key->OptionalData, Array[Index].OptionalData, Key->OptionalDataSize) == 0)) {
84 return (INTN) Index;
85 }
86 }
87
88 return -1;
89 }
90
91 /**
92 Register a boot option using a file GUID in the FV.
93
94 @param FileGuid The file GUID name in FV.
95 @param Description The boot option description.
96 @param Attributes The attributes used for the boot option loading.
97 **/
98 VOID
99 PlatformRegisterFvBootOption (
100 EFI_GUID *FileGuid,
101 CHAR16 *Description,
102 UINT32 Attributes
103 )
104 {
105 EFI_STATUS Status;
106 UINTN OptionIndex;
107 EFI_BOOT_MANAGER_LOAD_OPTION NewOption;
108 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
109 UINTN BootOptionCount;
110 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;
111 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
112 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
113
114 Status = gBS->HandleProtocol (gImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);
115 ASSERT_EFI_ERROR (Status);
116
117 EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);
118 DevicePath = AppendDevicePathNode (
119 DevicePathFromHandle (LoadedImage->DeviceHandle),
120 (EFI_DEVICE_PATH_PROTOCOL *) &FileNode
121 );
122
123 Status = EfiBootManagerInitializeLoadOption (
124 &NewOption,
125 LoadOptionNumberUnassigned,
126 LoadOptionTypeBoot,
127 Attributes,
128 Description,
129 DevicePath,
130 NULL,
131 0
132 );
133 if (!EFI_ERROR (Status)) {
134 BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
135
136 OptionIndex = PlatformFindLoadOption (&NewOption, BootOptions, BootOptionCount);
137
138 if (OptionIndex == -1) {
139 Status = EfiBootManagerAddLoadOptionVariable (&NewOption, (UINTN) -1);
140 ASSERT_EFI_ERROR (Status);
141 }
142 EfiBootManagerFreeLoadOption (&NewOption);
143 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
144 }
145 }
146
147 /**
148 Do the platform specific action before the console is connected.
149
150 Such as:
151 Update console variable;
152 Register new Driver#### or Boot####;
153 Signal ReadyToLock event.
154 **/
155 VOID
156 EFIAPI
157 PlatformBootManagerBeforeConsole (
158 VOID
159 )
160 {
161 EFI_INPUT_KEY Enter;
162 EFI_INPUT_KEY F2;
163 EFI_INPUT_KEY Down;
164 EFI_BOOT_MANAGER_LOAD_OPTION BootOption;
165
166 PlatformConsoleInit ();
167
168 //
169 // Register ENTER as CONTINUE key
170 //
171 Enter.ScanCode = SCAN_NULL;
172 Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;
173 EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);
174
175 //
176 // Map F2 to Boot Manager Menu
177 //
178 F2.ScanCode = SCAN_F2;
179 F2.UnicodeChar = CHAR_NULL;
180 EfiBootManagerGetBootManagerMenu (&BootOption);
181 EfiBootManagerAddKeyOptionVariable (NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL);
182
183 //
184 // Also add Down key to Boot Manager Menu since some serial terminals don't support F2 key.
185 //
186 Down.ScanCode = SCAN_DOWN;
187 Down.UnicodeChar = CHAR_NULL;
188 EfiBootManagerGetBootManagerMenu (&BootOption);
189 EfiBootManagerAddKeyOptionVariable (NULL, (UINT16) BootOption.OptionNumber, 0, &Down, NULL);
190
191 //
192 // Install ready to lock.
193 // This needs to be done before option rom dispatched.
194 //
195 InstallReadyToLock ();
196
197 //
198 // Dispatch deferred images after EndOfDxe event and ReadyToLock installation.
199 //
200 EfiBootManagerDispatchDeferredImages ();
201 }
202
203 /**
204 Do the platform specific action after the console is connected.
205
206 Such as:
207 Dynamically switch output mode;
208 Signal console ready platform customized event;
209 Run diagnostics like memory testing;
210 Connect certain devices;
211 Dispatch aditional option roms.
212 **/
213 VOID
214 EFIAPI
215 PlatformBootManagerAfterConsole (
216 VOID
217 )
218 {
219 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black;
220 EFI_GRAPHICS_OUTPUT_BLT_PIXEL White;
221
222 Black.Blue = Black.Green = Black.Red = Black.Reserved = 0;
223 White.Blue = White.Green = White.Red = White.Reserved = 0xFF;
224
225 EfiBootManagerConnectAll ();
226 EfiBootManagerRefreshAllBootOption ();
227
228 //
229 // Register UEFI Shell
230 //
231 PlatformRegisterFvBootOption (PcdGetPtr (PcdShellFile), L"UEFI Shell", LOAD_OPTION_ACTIVE);
232
233 Print (
234 L"\n"
235 L"F2 or Down to enter Boot Manager Menu.\n"
236 L"ENTER to boot directly.\n"
237 L"\n"
238 );
239
240 }
241
242 /**
243 This function is called each second during the boot manager waits the timeout.
244
245 @param TimeoutRemain The remaining timeout.
246 **/
247 VOID
248 EFIAPI
249 PlatformBootManagerWaitCallback (
250 UINT16 TimeoutRemain
251 )
252 {
253 return;
254 }
255
256 /**
257 The function is called when no boot option could be launched,
258 including platform recovery options and options pointing to applications
259 built into firmware volumes.
260
261 If this function returns, BDS attempts to enter an infinite loop.
262 **/
263 VOID
264 EFIAPI
265 PlatformBootManagerUnableToBoot (
266 VOID
267 )
268 {
269 return;
270 }
271