]>
Commit | Line | Data |
---|---|---|
c976f9cb AB |
1 | /** @file\r |
2 | Implementation for PlatformBootManagerLib library class interfaces.\r | |
3 | \r | |
4 | Copyright (C) 2015-2016, Red Hat, Inc.\r | |
0f9395d7 | 5 | Copyright (c) 2014 - 2019, ARM Ltd. All rights reserved.<BR>\r |
eea668c9 | 6 | Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r |
c976f9cb AB |
7 | Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r |
8 | \r | |
4059386c | 9 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
c976f9cb AB |
10 | \r |
11 | **/\r | |
12 | \r | |
13 | #include <IndustryStandard/Pci22.h>\r | |
a43d75e1 | 14 | #include <Library/BootLogoLib.h>\r |
4bbcc285 | 15 | #include <Library/CapsuleLib.h>\r |
c976f9cb | 16 | #include <Library/DevicePathLib.h>\r |
4bbcc285 | 17 | #include <Library/HobLib.h>\r |
c976f9cb AB |
18 | #include <Library/PcdLib.h>\r |
19 | #include <Library/UefiBootManagerLib.h>\r | |
20 | #include <Library/UefiLib.h>\r | |
cae82316 | 21 | #include <Library/UefiRuntimeServicesTableLib.h>\r |
c976f9cb | 22 | #include <Protocol/DevicePath.h>\r |
13ca0abb | 23 | #include <Protocol/EsrtManagement.h>\r |
c976f9cb AB |
24 | #include <Protocol/GraphicsOutput.h>\r |
25 | #include <Protocol/LoadedImage.h>\r | |
0ae52d4f | 26 | #include <Protocol/NonDiscoverableDevice.h>\r |
c976f9cb AB |
27 | #include <Protocol/PciIo.h>\r |
28 | #include <Protocol/PciRootBridgeIo.h>\r | |
1b6e7633 | 29 | #include <Protocol/PlatformBootManager.h>\r |
c976f9cb | 30 | #include <Guid/EventGroup.h>\r |
0ae52d4f | 31 | #include <Guid/NonDiscoverableDevice.h>\r |
c976f9cb | 32 | #include <Guid/TtyTerm.h>\r |
6631c096 | 33 | #include <Guid/SerialPortLibVendor.h>\r |
c976f9cb AB |
34 | \r |
35 | #include "PlatformBm.h"\r | |
36 | \r | |
37 | #define DP_NODE_LEN(Type) { (UINT8)sizeof (Type), (UINT8)(sizeof (Type) >> 8) }\r | |
38 | \r | |
c976f9cb AB |
39 | #pragma pack (1)\r |
40 | typedef struct {\r | |
41 | VENDOR_DEVICE_PATH SerialDxe;\r | |
42 | UART_DEVICE_PATH Uart;\r | |
43 | VENDOR_DEFINED_DEVICE_PATH TermType;\r | |
44 | EFI_DEVICE_PATH_PROTOCOL End;\r | |
45 | } PLATFORM_SERIAL_CONSOLE;\r | |
46 | #pragma pack ()\r | |
47 | \r | |
c976f9cb AB |
48 | STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = {\r |
49 | //\r | |
50 | // VENDOR_DEVICE_PATH SerialDxe\r | |
51 | //\r | |
52 | {\r | |
53 | { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DP_NODE_LEN (VENDOR_DEVICE_PATH) },\r | |
6631c096 | 54 | EDKII_SERIAL_PORT_LIB_VENDOR_GUID\r |
c976f9cb AB |
55 | },\r |
56 | \r | |
57 | //\r | |
58 | // UART_DEVICE_PATH Uart\r | |
59 | //\r | |
60 | {\r | |
61 | { MESSAGING_DEVICE_PATH, MSG_UART_DP, DP_NODE_LEN (UART_DEVICE_PATH) },\r | |
62 | 0, // Reserved\r | |
63 | FixedPcdGet64 (PcdUartDefaultBaudRate), // BaudRate\r | |
64 | FixedPcdGet8 (PcdUartDefaultDataBits), // DataBits\r | |
65 | FixedPcdGet8 (PcdUartDefaultParity), // Parity\r | |
66 | FixedPcdGet8 (PcdUartDefaultStopBits) // StopBits\r | |
67 | },\r | |
68 | \r | |
69 | //\r | |
70 | // VENDOR_DEFINED_DEVICE_PATH TermType\r | |
71 | //\r | |
72 | {\r | |
73 | {\r | |
74 | MESSAGING_DEVICE_PATH, MSG_VENDOR_DP,\r | |
75 | DP_NODE_LEN (VENDOR_DEFINED_DEVICE_PATH)\r | |
76 | }\r | |
77 | //\r | |
78 | // Guid to be filled in dynamically\r | |
79 | //\r | |
80 | },\r | |
81 | \r | |
82 | //\r | |
83 | // EFI_DEVICE_PATH_PROTOCOL End\r | |
84 | //\r | |
85 | {\r | |
86 | END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
87 | DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)\r | |
88 | }\r | |
89 | };\r | |
90 | \r | |
91 | \r | |
92 | #pragma pack (1)\r | |
93 | typedef struct {\r | |
94 | USB_CLASS_DEVICE_PATH Keyboard;\r | |
95 | EFI_DEVICE_PATH_PROTOCOL End;\r | |
96 | } PLATFORM_USB_KEYBOARD;\r | |
97 | #pragma pack ()\r | |
98 | \r | |
99 | STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard = {\r | |
100 | //\r | |
101 | // USB_CLASS_DEVICE_PATH Keyboard\r | |
102 | //\r | |
103 | {\r | |
104 | {\r | |
105 | MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP,\r | |
106 | DP_NODE_LEN (USB_CLASS_DEVICE_PATH)\r | |
107 | },\r | |
108 | 0xFFFF, // VendorId: any\r | |
109 | 0xFFFF, // ProductId: any\r | |
110 | 3, // DeviceClass: HID\r | |
111 | 1, // DeviceSubClass: boot\r | |
112 | 1 // DeviceProtocol: keyboard\r | |
113 | },\r | |
114 | \r | |
115 | //\r | |
116 | // EFI_DEVICE_PATH_PROTOCOL End\r | |
117 | //\r | |
118 | {\r | |
119 | END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
120 | DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)\r | |
121 | }\r | |
122 | };\r | |
123 | \r | |
124 | \r | |
125 | /**\r | |
126 | Check if the handle satisfies a particular condition.\r | |
127 | \r | |
128 | @param[in] Handle The handle to check.\r | |
129 | @param[in] ReportText A caller-allocated string passed in for reporting\r | |
130 | purposes. It must never be NULL.\r | |
131 | \r | |
132 | @retval TRUE The condition is satisfied.\r | |
133 | @retval FALSE Otherwise. This includes the case when the condition could not\r | |
134 | be fully evaluated due to an error.\r | |
135 | **/\r | |
136 | typedef\r | |
137 | BOOLEAN\r | |
138 | (EFIAPI *FILTER_FUNCTION) (\r | |
139 | IN EFI_HANDLE Handle,\r | |
140 | IN CONST CHAR16 *ReportText\r | |
141 | );\r | |
142 | \r | |
143 | \r | |
144 | /**\r | |
145 | Process a handle.\r | |
146 | \r | |
147 | @param[in] Handle The handle to process.\r | |
148 | @param[in] ReportText A caller-allocated string passed in for reporting\r | |
149 | purposes. It must never be NULL.\r | |
150 | **/\r | |
151 | typedef\r | |
152 | VOID\r | |
153 | (EFIAPI *CALLBACK_FUNCTION) (\r | |
154 | IN EFI_HANDLE Handle,\r | |
155 | IN CONST CHAR16 *ReportText\r | |
156 | );\r | |
157 | \r | |
158 | /**\r | |
159 | Locate all handles that carry the specified protocol, filter them with a\r | |
160 | callback function, and pass each handle that passes the filter to another\r | |
161 | callback.\r | |
162 | \r | |
163 | @param[in] ProtocolGuid The protocol to look for.\r | |
164 | \r | |
165 | @param[in] Filter The filter function to pass each handle to. If this\r | |
166 | parameter is NULL, then all handles are processed.\r | |
167 | \r | |
168 | @param[in] Process The callback function to pass each handle to that\r | |
169 | clears the filter.\r | |
170 | **/\r | |
171 | STATIC\r | |
172 | VOID\r | |
173 | FilterAndProcess (\r | |
174 | IN EFI_GUID *ProtocolGuid,\r | |
175 | IN FILTER_FUNCTION Filter OPTIONAL,\r | |
176 | IN CALLBACK_FUNCTION Process\r | |
177 | )\r | |
178 | {\r | |
179 | EFI_STATUS Status;\r | |
180 | EFI_HANDLE *Handles;\r | |
181 | UINTN NoHandles;\r | |
182 | UINTN Idx;\r | |
183 | \r | |
184 | Status = gBS->LocateHandleBuffer (ByProtocol, ProtocolGuid,\r | |
185 | NULL /* SearchKey */, &NoHandles, &Handles);\r | |
186 | if (EFI_ERROR (Status)) {\r | |
187 | //\r | |
188 | // This is not an error, just an informative condition.\r | |
189 | //\r | |
190 | DEBUG ((EFI_D_VERBOSE, "%a: %g: %r\n", __FUNCTION__, ProtocolGuid,\r | |
191 | Status));\r | |
192 | return;\r | |
193 | }\r | |
194 | \r | |
195 | ASSERT (NoHandles > 0);\r | |
196 | for (Idx = 0; Idx < NoHandles; ++Idx) {\r | |
197 | CHAR16 *DevicePathText;\r | |
198 | STATIC CHAR16 Fallback[] = L"<device path unavailable>";\r | |
199 | \r | |
200 | //\r | |
201 | // The ConvertDevicePathToText() function handles NULL input transparently.\r | |
202 | //\r | |
203 | DevicePathText = ConvertDevicePathToText (\r | |
204 | DevicePathFromHandle (Handles[Idx]),\r | |
205 | FALSE, // DisplayOnly\r | |
206 | FALSE // AllowShortcuts\r | |
207 | );\r | |
208 | if (DevicePathText == NULL) {\r | |
209 | DevicePathText = Fallback;\r | |
210 | }\r | |
211 | \r | |
212 | if (Filter == NULL || Filter (Handles[Idx], DevicePathText)) {\r | |
213 | Process (Handles[Idx], DevicePathText);\r | |
214 | }\r | |
215 | \r | |
216 | if (DevicePathText != Fallback) {\r | |
217 | FreePool (DevicePathText);\r | |
218 | }\r | |
219 | }\r | |
220 | gBS->FreePool (Handles);\r | |
221 | }\r | |
222 | \r | |
223 | \r | |
224 | /**\r | |
225 | This FILTER_FUNCTION checks if a handle corresponds to a PCI display device.\r | |
226 | **/\r | |
227 | STATIC\r | |
228 | BOOLEAN\r | |
229 | EFIAPI\r | |
230 | IsPciDisplay (\r | |
231 | IN EFI_HANDLE Handle,\r | |
232 | IN CONST CHAR16 *ReportText\r | |
233 | )\r | |
234 | {\r | |
235 | EFI_STATUS Status;\r | |
236 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
237 | PCI_TYPE00 Pci;\r | |
238 | \r | |
239 | Status = gBS->HandleProtocol (Handle, &gEfiPciIoProtocolGuid,\r | |
240 | (VOID**)&PciIo);\r | |
241 | if (EFI_ERROR (Status)) {\r | |
242 | //\r | |
243 | // This is not an error worth reporting.\r | |
244 | //\r | |
245 | return FALSE;\r | |
246 | }\r | |
247 | \r | |
248 | Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0 /* Offset */,\r | |
249 | sizeof Pci / sizeof (UINT32), &Pci);\r | |
250 | if (EFI_ERROR (Status)) {\r | |
251 | DEBUG ((EFI_D_ERROR, "%a: %s: %r\n", __FUNCTION__, ReportText, Status));\r | |
252 | return FALSE;\r | |
253 | }\r | |
254 | \r | |
255 | return IS_PCI_DISPLAY (&Pci);\r | |
256 | }\r | |
257 | \r | |
258 | \r | |
0ae52d4f AB |
259 | /**\r |
260 | This FILTER_FUNCTION checks if a handle corresponds to a non-discoverable\r | |
261 | USB host controller.\r | |
262 | **/\r | |
263 | STATIC\r | |
264 | BOOLEAN\r | |
265 | EFIAPI\r | |
266 | IsUsbHost (\r | |
267 | IN EFI_HANDLE Handle,\r | |
268 | IN CONST CHAR16 *ReportText\r | |
269 | )\r | |
270 | {\r | |
271 | NON_DISCOVERABLE_DEVICE *Device;\r | |
272 | EFI_STATUS Status;\r | |
273 | \r | |
274 | Status = gBS->HandleProtocol (Handle,\r | |
275 | &gEdkiiNonDiscoverableDeviceProtocolGuid,\r | |
276 | (VOID **)&Device);\r | |
277 | if (EFI_ERROR (Status)) {\r | |
278 | return FALSE;\r | |
279 | }\r | |
280 | \r | |
281 | if (CompareGuid (Device->Type, &gEdkiiNonDiscoverableUhciDeviceGuid) ||\r | |
282 | CompareGuid (Device->Type, &gEdkiiNonDiscoverableEhciDeviceGuid) ||\r | |
283 | CompareGuid (Device->Type, &gEdkiiNonDiscoverableXhciDeviceGuid)) {\r | |
284 | return TRUE;\r | |
285 | }\r | |
286 | return FALSE;\r | |
287 | }\r | |
288 | \r | |
289 | \r | |
c976f9cb AB |
290 | /**\r |
291 | This CALLBACK_FUNCTION attempts to connect a handle non-recursively, asking\r | |
292 | the matching driver to produce all first-level child handles.\r | |
293 | **/\r | |
294 | STATIC\r | |
295 | VOID\r | |
296 | EFIAPI\r | |
297 | Connect (\r | |
298 | IN EFI_HANDLE Handle,\r | |
299 | IN CONST CHAR16 *ReportText\r | |
300 | )\r | |
301 | {\r | |
302 | EFI_STATUS Status;\r | |
303 | \r | |
304 | Status = gBS->ConnectController (\r | |
305 | Handle, // ControllerHandle\r | |
306 | NULL, // DriverImageHandle\r | |
307 | NULL, // RemainingDevicePath -- produce all children\r | |
308 | FALSE // Recursive\r | |
309 | );\r | |
310 | DEBUG ((EFI_ERROR (Status) ? EFI_D_ERROR : EFI_D_VERBOSE, "%a: %s: %r\n",\r | |
311 | __FUNCTION__, ReportText, Status));\r | |
312 | }\r | |
313 | \r | |
314 | \r | |
315 | /**\r | |
316 | This CALLBACK_FUNCTION retrieves the EFI_DEVICE_PATH_PROTOCOL from the\r | |
317 | handle, and adds it to ConOut and ErrOut.\r | |
318 | **/\r | |
319 | STATIC\r | |
320 | VOID\r | |
321 | EFIAPI\r | |
322 | AddOutput (\r | |
323 | IN EFI_HANDLE Handle,\r | |
324 | IN CONST CHAR16 *ReportText\r | |
325 | )\r | |
326 | {\r | |
327 | EFI_STATUS Status;\r | |
328 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
329 | \r | |
330 | DevicePath = DevicePathFromHandle (Handle);\r | |
331 | if (DevicePath == NULL) {\r | |
332 | DEBUG ((EFI_D_ERROR, "%a: %s: handle %p: device path not found\n",\r | |
333 | __FUNCTION__, ReportText, Handle));\r | |
334 | return;\r | |
335 | }\r | |
336 | \r | |
337 | Status = EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL);\r | |
338 | if (EFI_ERROR (Status)) {\r | |
339 | DEBUG ((EFI_D_ERROR, "%a: %s: adding to ConOut: %r\n", __FUNCTION__,\r | |
340 | ReportText, Status));\r | |
341 | return;\r | |
342 | }\r | |
343 | \r | |
344 | Status = EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL);\r | |
345 | if (EFI_ERROR (Status)) {\r | |
346 | DEBUG ((EFI_D_ERROR, "%a: %s: adding to ErrOut: %r\n", __FUNCTION__,\r | |
347 | ReportText, Status));\r | |
348 | return;\r | |
349 | }\r | |
350 | \r | |
351 | DEBUG ((EFI_D_VERBOSE, "%a: %s: added to ConOut and ErrOut\n", __FUNCTION__,\r | |
352 | ReportText));\r | |
353 | }\r | |
354 | \r | |
355 | STATIC\r | |
356 | VOID\r | |
357 | PlatformRegisterFvBootOption (\r | |
07548e17 | 358 | CONST EFI_GUID *FileGuid,\r |
c976f9cb | 359 | CHAR16 *Description,\r |
321b0788 AB |
360 | UINT32 Attributes,\r |
361 | EFI_INPUT_KEY *Key\r | |
c976f9cb AB |
362 | )\r |
363 | {\r | |
364 | EFI_STATUS Status;\r | |
365 | INTN OptionIndex;\r | |
366 | EFI_BOOT_MANAGER_LOAD_OPTION NewOption;\r | |
367 | EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;\r | |
368 | UINTN BootOptionCount;\r | |
369 | MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;\r | |
370 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r | |
371 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
372 | \r | |
373 | Status = gBS->HandleProtocol (\r | |
374 | gImageHandle,\r | |
375 | &gEfiLoadedImageProtocolGuid,\r | |
376 | (VOID **) &LoadedImage\r | |
377 | );\r | |
378 | ASSERT_EFI_ERROR (Status);\r | |
379 | \r | |
380 | EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);\r | |
381 | DevicePath = DevicePathFromHandle (LoadedImage->DeviceHandle);\r | |
382 | ASSERT (DevicePath != NULL);\r | |
383 | DevicePath = AppendDevicePathNode (\r | |
384 | DevicePath,\r | |
385 | (EFI_DEVICE_PATH_PROTOCOL *) &FileNode\r | |
386 | );\r | |
387 | ASSERT (DevicePath != NULL);\r | |
388 | \r | |
389 | Status = EfiBootManagerInitializeLoadOption (\r | |
390 | &NewOption,\r | |
391 | LoadOptionNumberUnassigned,\r | |
392 | LoadOptionTypeBoot,\r | |
393 | Attributes,\r | |
394 | Description,\r | |
395 | DevicePath,\r | |
396 | NULL,\r | |
397 | 0\r | |
398 | );\r | |
399 | ASSERT_EFI_ERROR (Status);\r | |
400 | FreePool (DevicePath);\r | |
401 | \r | |
402 | BootOptions = EfiBootManagerGetLoadOptions (\r | |
403 | &BootOptionCount, LoadOptionTypeBoot\r | |
404 | );\r | |
405 | \r | |
406 | OptionIndex = EfiBootManagerFindLoadOption (\r | |
407 | &NewOption, BootOptions, BootOptionCount\r | |
408 | );\r | |
409 | \r | |
410 | if (OptionIndex == -1) {\r | |
411 | Status = EfiBootManagerAddLoadOptionVariable (&NewOption, MAX_UINTN);\r | |
412 | ASSERT_EFI_ERROR (Status);\r | |
321b0788 AB |
413 | Status = EfiBootManagerAddKeyOptionVariable (NULL,\r |
414 | (UINT16)NewOption.OptionNumber, 0, Key, NULL);\r | |
415 | ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);\r | |
c976f9cb AB |
416 | }\r |
417 | EfiBootManagerFreeLoadOption (&NewOption);\r | |
418 | EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);\r | |
419 | }\r | |
420 | \r | |
421 | \r | |
1b6e7633 HZ |
422 | STATIC\r |
423 | VOID\r | |
424 | GetPlatformOptions (\r | |
425 | VOID\r | |
426 | )\r | |
427 | {\r | |
428 | EFI_STATUS Status;\r | |
429 | EFI_BOOT_MANAGER_LOAD_OPTION *CurrentBootOptions;\r | |
430 | EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;\r | |
431 | EFI_INPUT_KEY *BootKeys;\r | |
432 | PLATFORM_BOOT_MANAGER_PROTOCOL *PlatformBootManager;\r | |
433 | UINTN CurrentBootOptionCount;\r | |
434 | UINTN Index;\r | |
435 | UINTN BootCount;\r | |
436 | \r | |
437 | Status = gBS->LocateProtocol (&gPlatformBootManagerProtocolGuid, NULL,\r | |
438 | (VOID **)&PlatformBootManager);\r | |
439 | if (EFI_ERROR (Status)) {\r | |
440 | return;\r | |
441 | }\r | |
442 | Status = PlatformBootManager->GetPlatformBootOptionsAndKeys (\r | |
443 | &BootCount,\r | |
444 | &BootOptions,\r | |
445 | &BootKeys\r | |
446 | );\r | |
447 | if (EFI_ERROR (Status)) {\r | |
448 | return;\r | |
449 | }\r | |
450 | //\r | |
451 | // Fetch the existent boot options. If there are none, CurrentBootCount\r | |
452 | // will be zeroed.\r | |
453 | //\r | |
454 | CurrentBootOptions = EfiBootManagerGetLoadOptions (\r | |
455 | &CurrentBootOptionCount,\r | |
456 | LoadOptionTypeBoot\r | |
457 | );\r | |
458 | //\r | |
459 | // Process the platform boot options.\r | |
460 | //\r | |
461 | for (Index = 0; Index < BootCount; Index++) {\r | |
462 | INTN Match;\r | |
463 | UINTN BootOptionNumber;\r | |
464 | \r | |
465 | //\r | |
466 | // If there are any preexistent boot options, and the subject platform boot\r | |
467 | // option is already among them, then don't try to add it. Just get its\r | |
468 | // assigned boot option number so we can associate a hotkey with it. Note\r | |
469 | // that EfiBootManagerFindLoadOption() deals fine with (CurrentBootOptions\r | |
470 | // == NULL) if (CurrentBootCount == 0).\r | |
471 | //\r | |
472 | Match = EfiBootManagerFindLoadOption (\r | |
473 | &BootOptions[Index],\r | |
474 | CurrentBootOptions,\r | |
475 | CurrentBootOptionCount\r | |
476 | );\r | |
477 | if (Match >= 0) {\r | |
478 | BootOptionNumber = CurrentBootOptions[Match].OptionNumber;\r | |
479 | } else {\r | |
480 | //\r | |
481 | // Add the platform boot options as a new one, at the end of the boot\r | |
482 | // order. Note that if the platform provided this boot option with an\r | |
483 | // unassigned option number, then the below function call will assign a\r | |
484 | // number.\r | |
485 | //\r | |
486 | Status = EfiBootManagerAddLoadOptionVariable (\r | |
487 | &BootOptions[Index],\r | |
488 | MAX_UINTN\r | |
489 | );\r | |
490 | if (EFI_ERROR (Status)) {\r | |
491 | DEBUG ((DEBUG_ERROR, "%a: failed to register \"%s\": %r\n",\r | |
492 | __FUNCTION__, BootOptions[Index].Description, Status));\r | |
493 | continue;\r | |
494 | }\r | |
495 | BootOptionNumber = BootOptions[Index].OptionNumber;\r | |
496 | }\r | |
497 | \r | |
498 | //\r | |
499 | // Register a hotkey with the boot option, if requested.\r | |
500 | //\r | |
501 | if (BootKeys[Index].UnicodeChar == L'\0') {\r | |
502 | continue;\r | |
503 | }\r | |
504 | \r | |
505 | Status = EfiBootManagerAddKeyOptionVariable (\r | |
506 | NULL,\r | |
507 | BootOptionNumber,\r | |
508 | 0,\r | |
2b2959dd | 509 | &BootKeys[Index],\r |
1b6e7633 HZ |
510 | NULL\r |
511 | );\r | |
512 | if (EFI_ERROR (Status)) {\r | |
513 | DEBUG ((DEBUG_ERROR, "%a: failed to register hotkey for \"%s\": %r\n",\r | |
514 | __FUNCTION__, BootOptions[Index].Description, Status));\r | |
515 | }\r | |
516 | }\r | |
517 | EfiBootManagerFreeLoadOptions (CurrentBootOptions, CurrentBootOptionCount);\r | |
518 | EfiBootManagerFreeLoadOptions (BootOptions, BootCount);\r | |
519 | FreePool (BootKeys);\r | |
520 | }\r | |
521 | \r | |
c976f9cb AB |
522 | STATIC\r |
523 | VOID\r | |
524 | PlatformRegisterOptionsAndKeys (\r | |
525 | VOID\r | |
526 | )\r | |
527 | {\r | |
528 | EFI_STATUS Status;\r | |
529 | EFI_INPUT_KEY Enter;\r | |
530 | EFI_INPUT_KEY F2;\r | |
531 | EFI_INPUT_KEY Esc;\r | |
532 | EFI_BOOT_MANAGER_LOAD_OPTION BootOption;\r | |
533 | \r | |
1b6e7633 HZ |
534 | GetPlatformOptions ();\r |
535 | \r | |
c976f9cb AB |
536 | //\r |
537 | // Register ENTER as CONTINUE key\r | |
538 | //\r | |
539 | Enter.ScanCode = SCAN_NULL;\r | |
540 | Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;\r | |
541 | Status = EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);\r | |
542 | ASSERT_EFI_ERROR (Status);\r | |
543 | \r | |
544 | //\r | |
545 | // Map F2 and ESC to Boot Manager Menu\r | |
546 | //\r | |
547 | F2.ScanCode = SCAN_F2;\r | |
548 | F2.UnicodeChar = CHAR_NULL;\r | |
549 | Esc.ScanCode = SCAN_ESC;\r | |
550 | Esc.UnicodeChar = CHAR_NULL;\r | |
551 | Status = EfiBootManagerGetBootManagerMenu (&BootOption);\r | |
552 | ASSERT_EFI_ERROR (Status);\r | |
553 | Status = EfiBootManagerAddKeyOptionVariable (\r | |
554 | NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL\r | |
555 | );\r | |
556 | ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);\r | |
557 | Status = EfiBootManagerAddKeyOptionVariable (\r | |
558 | NULL, (UINT16) BootOption.OptionNumber, 0, &Esc, NULL\r | |
559 | );\r | |
560 | ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);\r | |
561 | }\r | |
562 | \r | |
563 | \r | |
564 | //\r | |
565 | // BDS Platform Functions\r | |
566 | //\r | |
567 | /**\r | |
568 | Do the platform init, can be customized by OEM/IBV\r | |
569 | Possible things that can be done in PlatformBootManagerBeforeConsole:\r | |
570 | > Update console variable: 1. include hot-plug devices;\r | |
571 | > 2. Clear ConIn and add SOL for AMT\r | |
572 | > Register new Driver#### or Boot####\r | |
573 | > Register new Key####: e.g.: F12\r | |
574 | > Signal ReadyToLock event\r | |
575 | > Authentication action: 1. connect Auth devices;\r | |
576 | > 2. Identify auto logon user.\r | |
577 | **/\r | |
578 | VOID\r | |
579 | EFIAPI\r | |
580 | PlatformBootManagerBeforeConsole (\r | |
581 | VOID\r | |
582 | )\r | |
583 | {\r | |
584 | //\r | |
585 | // Signal EndOfDxe PI Event\r | |
586 | //\r | |
587 | EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);\r | |
588 | \r | |
0f9395d7 SM |
589 | //\r |
590 | // Dispatch deferred images after EndOfDxe event.\r | |
591 | //\r | |
592 | EfiBootManagerDispatchDeferredImages ();\r | |
593 | \r | |
c976f9cb AB |
594 | //\r |
595 | // Locate the PCI root bridges and make the PCI bus driver connect each,\r | |
596 | // non-recursively. This will produce a number of child handles with PciIo on\r | |
597 | // them.\r | |
598 | //\r | |
599 | FilterAndProcess (&gEfiPciRootBridgeIoProtocolGuid, NULL, Connect);\r | |
600 | \r | |
601 | //\r | |
602 | // Find all display class PCI devices (using the handles from the previous\r | |
603 | // step), and connect them non-recursively. This should produce a number of\r | |
604 | // child handles with GOPs on them.\r | |
605 | //\r | |
606 | FilterAndProcess (&gEfiPciIoProtocolGuid, IsPciDisplay, Connect);\r | |
607 | \r | |
608 | //\r | |
609 | // Now add the device path of all handles with GOP on them to ConOut and\r | |
610 | // ErrOut.\r | |
611 | //\r | |
612 | FilterAndProcess (&gEfiGraphicsOutputProtocolGuid, NULL, AddOutput);\r | |
613 | \r | |
0ae52d4f AB |
614 | //\r |
615 | // The core BDS code connects short-form USB device paths by explicitly\r | |
616 | // looking for handles with PCI I/O installed, and checking the PCI class\r | |
617 | // code whether it matches the one for a USB host controller. This means\r | |
618 | // non-discoverable USB host controllers need to have the non-discoverable\r | |
619 | // PCI driver attached first.\r | |
620 | //\r | |
621 | FilterAndProcess (&gEdkiiNonDiscoverableDeviceProtocolGuid, IsUsbHost, Connect);\r | |
622 | \r | |
c976f9cb AB |
623 | //\r |
624 | // Add the hardcoded short-form USB keyboard device path to ConIn.\r | |
625 | //\r | |
626 | EfiBootManagerUpdateConsoleVariable (ConIn,\r | |
627 | (EFI_DEVICE_PATH_PROTOCOL *)&mUsbKeyboard, NULL);\r | |
628 | \r | |
629 | //\r | |
630 | // Add the hardcoded serial console device path to ConIn, ConOut, ErrOut.\r | |
631 | //\r | |
b1d3895f AB |
632 | STATIC_ASSERT (FixedPcdGet8 (PcdDefaultTerminalType) == 4,\r |
633 | "PcdDefaultTerminalType must be TTYTERM");\r | |
7191dd3c AB |
634 | STATIC_ASSERT (FixedPcdGet8 (PcdUartDefaultParity) != 0,\r |
635 | "PcdUartDefaultParity must be set to an actual value, not 'default'");\r | |
636 | STATIC_ASSERT (FixedPcdGet8 (PcdUartDefaultStopBits) != 0,\r | |
637 | "PcdUartDefaultStopBits must be set to an actual value, not 'default'");\r | |
b1d3895f | 638 | \r |
c976f9cb AB |
639 | CopyGuid (&mSerialConsole.TermType.Guid, &gEfiTtyTermGuid);\r |
640 | \r | |
641 | EfiBootManagerUpdateConsoleVariable (ConIn,\r | |
642 | (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);\r | |
643 | EfiBootManagerUpdateConsoleVariable (ConOut,\r | |
644 | (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);\r | |
645 | EfiBootManagerUpdateConsoleVariable (ErrOut,\r | |
646 | (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);\r | |
647 | \r | |
648 | //\r | |
649 | // Register platform-specific boot options and keyboard shortcuts.\r | |
650 | //\r | |
651 | PlatformRegisterOptionsAndKeys ();\r | |
652 | }\r | |
653 | \r | |
cae82316 AB |
654 | STATIC\r |
655 | VOID\r | |
656 | HandleCapsules (\r | |
657 | VOID\r | |
658 | )\r | |
659 | {\r | |
660 | ESRT_MANAGEMENT_PROTOCOL *EsrtManagement;\r | |
661 | EFI_PEI_HOB_POINTERS HobPointer;\r | |
662 | EFI_CAPSULE_HEADER *CapsuleHeader;\r | |
663 | BOOLEAN NeedReset;\r | |
664 | EFI_STATUS Status;\r | |
665 | \r | |
666 | DEBUG ((DEBUG_INFO, "%a: processing capsules ...\n", __FUNCTION__));\r | |
667 | \r | |
668 | Status = gBS->LocateProtocol (&gEsrtManagementProtocolGuid, NULL,\r | |
669 | (VOID **)&EsrtManagement);\r | |
670 | if (!EFI_ERROR (Status)) {\r | |
671 | EsrtManagement->SyncEsrtFmp ();\r | |
672 | }\r | |
673 | \r | |
674 | //\r | |
675 | // Find all capsule images from hob\r | |
676 | //\r | |
677 | HobPointer.Raw = GetHobList ();\r | |
678 | NeedReset = FALSE;\r | |
679 | while ((HobPointer.Raw = GetNextHob (EFI_HOB_TYPE_UEFI_CAPSULE,\r | |
680 | HobPointer.Raw)) != NULL) {\r | |
681 | CapsuleHeader = (VOID *)(UINTN)HobPointer.Capsule->BaseAddress;\r | |
682 | \r | |
683 | Status = ProcessCapsuleImage (CapsuleHeader);\r | |
684 | if (EFI_ERROR (Status)) {\r | |
685 | DEBUG ((DEBUG_ERROR, "%a: failed to process capsule %p - %r\n",\r | |
686 | __FUNCTION__, CapsuleHeader, Status));\r | |
687 | return;\r | |
688 | }\r | |
689 | \r | |
690 | NeedReset = TRUE;\r | |
691 | HobPointer.Raw = GET_NEXT_HOB (HobPointer);\r | |
692 | }\r | |
693 | \r | |
694 | if (NeedReset) {\r | |
695 | DEBUG ((DEBUG_WARN, "%a: capsule update successful, resetting ...\n",\r | |
696 | __FUNCTION__));\r | |
697 | \r | |
698 | gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);\r | |
699 | CpuDeadLoop();\r | |
700 | }\r | |
701 | }\r | |
702 | \r | |
703 | \r | |
6c4194c9 AB |
704 | #define VERSION_STRING_PREFIX L"Tianocore/EDK2 firmware version "\r |
705 | \r | |
c976f9cb AB |
706 | /**\r |
707 | Do the platform specific action after the console is ready\r | |
708 | Possible things that can be done in PlatformBootManagerAfterConsole:\r | |
709 | > Console post action:\r | |
ff5fef14 | 710 | > Dynamically switch output mode from 100x31 to 80x25 for certain scenario\r |
c976f9cb AB |
711 | > Signal console ready platform customized event\r |
712 | > Run diagnostics like memory testing\r | |
713 | > Connect certain devices\r | |
ff5fef14 | 714 | > Dispatch additional option roms\r |
c976f9cb AB |
715 | > Special boot: e.g.: USB boot, enter UI\r |
716 | **/\r | |
717 | VOID\r | |
718 | EFIAPI\r | |
719 | PlatformBootManagerAfterConsole (\r | |
720 | VOID\r | |
721 | )\r | |
722 | {\r | |
13ca0abb | 723 | EFI_STATUS Status;\r |
6c4194c9 AB |
724 | EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r |
725 | UINTN FirmwareVerLength;\r | |
726 | UINTN PosX;\r | |
727 | UINTN PosY;\r | |
321b0788 | 728 | EFI_INPUT_KEY Key;\r |
6c4194c9 AB |
729 | \r |
730 | FirmwareVerLength = StrLen (PcdGetPtr (PcdFirmwareVersionString));\r | |
c976f9cb AB |
731 | \r |
732 | //\r | |
733 | // Show the splash screen.\r | |
734 | //\r | |
a43d75e1 AB |
735 | Status = BootLogoEnableLogo ();\r |
736 | if (EFI_ERROR (Status)) {\r | |
6c4194c9 | 737 | if (FirmwareVerLength > 0) {\r |
26b99f3b | 738 | Print (VERSION_STRING_PREFIX L"%s\n",\r |
6c4194c9 AB |
739 | PcdGetPtr (PcdFirmwareVersionString));\r |
740 | }\r | |
a43d75e1 | 741 | Print (L"Press ESCAPE for boot options ");\r |
6c4194c9 AB |
742 | } else if (FirmwareVerLength > 0) {\r |
743 | Status = gBS->HandleProtocol (gST->ConsoleOutHandle,\r | |
744 | &gEfiGraphicsOutputProtocolGuid, (VOID **)&GraphicsOutput);\r | |
745 | if (!EFI_ERROR (Status)) {\r | |
746 | PosX = (GraphicsOutput->Mode->Info->HorizontalResolution -\r | |
747 | (StrLen (VERSION_STRING_PREFIX) + FirmwareVerLength) *\r | |
748 | EFI_GLYPH_WIDTH) / 2;\r | |
749 | PosY = 0;\r | |
750 | \r | |
751 | PrintXY (PosX, PosY, NULL, NULL, VERSION_STRING_PREFIX L"%s",\r | |
752 | PcdGetPtr (PcdFirmwareVersionString));\r | |
753 | }\r | |
a43d75e1 | 754 | }\r |
6c4194c9 | 755 | \r |
cae82316 AB |
756 | //\r |
757 | // On ARM, there is currently no reason to use the phased capsule\r | |
758 | // update approach where some capsules are dispatched before EndOfDxe\r | |
759 | // and some are dispatched after. So just handle all capsules here,\r | |
760 | // when the console is up and we can actually give the user some\r | |
761 | // feedback about what is going on.\r | |
762 | //\r | |
763 | HandleCapsules ();\r | |
4bbcc285 | 764 | \r |
c976f9cb AB |
765 | //\r |
766 | // Register UEFI Shell\r | |
767 | //\r | |
321b0788 AB |
768 | Key.ScanCode = SCAN_NULL;\r |
769 | Key.UnicodeChar = L's';\r | |
344f615d | 770 | PlatformRegisterFvBootOption (&gUefiShellFileGuid, L"UEFI Shell", 0, &Key);\r |
c976f9cb AB |
771 | }\r |
772 | \r | |
773 | /**\r | |
774 | This function is called each second during the boot manager waits the\r | |
775 | timeout.\r | |
776 | \r | |
777 | @param TimeoutRemain The remaining timeout.\r | |
778 | **/\r | |
779 | VOID\r | |
780 | EFIAPI\r | |
781 | PlatformBootManagerWaitCallback (\r | |
782 | UINT16 TimeoutRemain\r | |
783 | )\r | |
784 | {\r | |
a43d75e1 AB |
785 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Black;\r |
786 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION White;\r | |
787 | UINT16 Timeout;\r | |
788 | EFI_STATUS Status;\r | |
789 | \r | |
790 | Timeout = PcdGet16 (PcdPlatformBootTimeOut);\r | |
791 | \r | |
792 | Black.Raw = 0x00000000;\r | |
793 | White.Raw = 0x00FFFFFF;\r | |
794 | \r | |
795 | Status = BootLogoUpdateProgress (\r | |
796 | White.Pixel,\r | |
797 | Black.Pixel,\r | |
798 | L"Press ESCAPE for boot options",\r | |
799 | White.Pixel,\r | |
800 | (Timeout - TimeoutRemain) * 100 / Timeout,\r | |
801 | 0\r | |
802 | );\r | |
803 | if (EFI_ERROR (Status)) {\r | |
804 | Print (L".");\r | |
805 | }\r | |
c976f9cb | 806 | }\r |
eea668c9 RN |
807 | \r |
808 | /**\r | |
809 | The function is called when no boot option could be launched,\r | |
810 | including platform recovery options and options pointing to applications\r | |
811 | built into firmware volumes.\r | |
812 | \r | |
813 | If this function returns, BDS attempts to enter an infinite loop.\r | |
814 | **/\r | |
815 | VOID\r | |
816 | EFIAPI\r | |
817 | PlatformBootManagerUnableToBoot (\r | |
818 | VOID\r | |
819 | )\r | |
820 | {\r | |
40e2e3ca AB |
821 | EFI_STATUS Status;\r |
822 | EFI_BOOT_MANAGER_LOAD_OPTION BootManagerMenu;\r | |
823 | \r | |
824 | Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);\r | |
825 | if (EFI_ERROR (Status)) {\r | |
826 | return;\r | |
827 | }\r | |
828 | \r | |
829 | for (;;) {\r | |
830 | EfiBootManagerBoot (&BootManagerMenu);\r | |
831 | }\r | |
eea668c9 | 832 | }\r |