]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c
MdeModulePkg:Increase Nvme capacity display
[mirror_edk2.git] / ArmPkg / Library / PlatformBootManagerLib / PlatformBm.c
... / ...
CommitLineData
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\r
9 SPDX-License-Identifier: BSD-2-Clause-Patent\r
10\r
11**/\r
12\r
13#include <IndustryStandard/Pci22.h>\r
14#include <Library/BootLogoLib.h>\r
15#include <Library/CapsuleLib.h>\r
16#include <Library/DevicePathLib.h>\r
17#include <Library/HobLib.h>\r
18#include <Library/PcdLib.h>\r
19#include <Library/UefiBootManagerLib.h>\r
20#include <Library/UefiLib.h>\r
21#include <Library/UefiRuntimeServicesTableLib.h>\r
22#include <Protocol/DevicePath.h>\r
23#include <Protocol/EsrtManagement.h>\r
24#include <Protocol/GraphicsOutput.h>\r
25#include <Protocol/LoadedImage.h>\r
26#include <Protocol/NonDiscoverableDevice.h>\r
27#include <Protocol/PciIo.h>\r
28#include <Protocol/PciRootBridgeIo.h>\r
29#include <Protocol/PlatformBootManager.h>\r
30#include <Guid/EventGroup.h>\r
31#include <Guid/NonDiscoverableDevice.h>\r
32#include <Guid/TtyTerm.h>\r
33#include <Guid/SerialPortLibVendor.h>\r
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
39#pragma pack (1)\r
40typedef 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
48STATIC 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
54 EDKII_SERIAL_PORT_LIB_VENDOR_GUID\r
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
93typedef 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
99STATIC 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
136typedef\r
137BOOLEAN\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
151typedef\r
152VOID\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
171STATIC\r
172VOID\r
173FilterAndProcess (\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
227STATIC\r
228BOOLEAN\r
229EFIAPI\r
230IsPciDisplay (\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
259/**\r
260 This FILTER_FUNCTION checks if a handle corresponds to a non-discoverable\r
261 USB host controller.\r
262**/\r
263STATIC\r
264BOOLEAN\r
265EFIAPI\r
266IsUsbHost (\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
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
294STATIC\r
295VOID\r
296EFIAPI\r
297Connect (\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
319STATIC\r
320VOID\r
321EFIAPI\r
322AddOutput (\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
355STATIC\r
356VOID\r
357PlatformRegisterFvBootOption (\r
358 CONST EFI_GUID *FileGuid,\r
359 CHAR16 *Description,\r
360 UINT32 Attributes,\r
361 EFI_INPUT_KEY *Key\r
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
413 Status = EfiBootManagerAddKeyOptionVariable (NULL,\r
414 (UINT16)NewOption.OptionNumber, 0, Key, NULL);\r
415 ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);\r
416 }\r
417 EfiBootManagerFreeLoadOption (&NewOption);\r
418 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);\r
419}\r
420\r
421\r
422STATIC\r
423VOID\r
424GetPlatformOptions (\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
509 &BootKeys[Index],\r
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
522STATIC\r
523VOID\r
524PlatformRegisterOptionsAndKeys (\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
534 GetPlatformOptions ();\r
535\r
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
578VOID\r
579EFIAPI\r
580PlatformBootManagerBeforeConsole (\r
581 VOID\r
582 )\r
583{\r
584 //\r
585 // Signal EndOfDxe PI Event\r
586 //\r
587 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);\r
588\r
589 //\r
590 // Dispatch deferred images after EndOfDxe event.\r
591 //\r
592 EfiBootManagerDispatchDeferredImages ();\r
593\r
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
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
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
632 STATIC_ASSERT (FixedPcdGet8 (PcdDefaultTerminalType) == 4,\r
633 "PcdDefaultTerminalType must be TTYTERM");\r
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
638\r
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
654STATIC\r
655VOID\r
656HandleCapsules (\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
704#define VERSION_STRING_PREFIX L"Tianocore/EDK2 firmware version "\r
705\r
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
710 > Dynamically switch output mode from 100x31 to 80x25 for certain scenario\r
711 > Signal console ready platform customized event\r
712 > Run diagnostics like memory testing\r
713 > Connect certain devices\r
714 > Dispatch additional option roms\r
715 > Special boot: e.g.: USB boot, enter UI\r
716**/\r
717VOID\r
718EFIAPI\r
719PlatformBootManagerAfterConsole (\r
720 VOID\r
721 )\r
722{\r
723 EFI_STATUS Status;\r
724 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
725 UINTN FirmwareVerLength;\r
726 UINTN PosX;\r
727 UINTN PosY;\r
728 EFI_INPUT_KEY Key;\r
729\r
730 FirmwareVerLength = StrLen (PcdGetPtr (PcdFirmwareVersionString));\r
731\r
732 //\r
733 // Show the splash screen.\r
734 //\r
735 Status = BootLogoEnableLogo ();\r
736 if (EFI_ERROR (Status)) {\r
737 if (FirmwareVerLength > 0) {\r
738 Print (VERSION_STRING_PREFIX L"%s\n",\r
739 PcdGetPtr (PcdFirmwareVersionString));\r
740 }\r
741 Print (L"Press ESCAPE for boot options ");\r
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
754 }\r
755\r
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
764\r
765 //\r
766 // Register UEFI Shell\r
767 //\r
768 Key.ScanCode = SCAN_NULL;\r
769 Key.UnicodeChar = L's';\r
770 PlatformRegisterFvBootOption (&gUefiShellFileGuid, L"UEFI Shell", 0, &Key);\r
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
779VOID\r
780EFIAPI\r
781PlatformBootManagerWaitCallback (\r
782 UINT16 TimeoutRemain\r
783 )\r
784{\r
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
806}\r
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
815VOID\r
816EFIAPI\r
817PlatformBootManagerUnableToBoot (\r
818 VOID\r
819 )\r
820{\r
821 EFI_STATUS Status;\r
822 EFI_BOOT_MANAGER_LOAD_OPTION BootManagerMenu;\r
823 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;\r
824 UINTN OldBootOptionCount;\r
825 UINTN NewBootOptionCount;\r
826\r
827 //\r
828 // Record the total number of boot configured boot options\r
829 //\r
830 BootOptions = EfiBootManagerGetLoadOptions (&OldBootOptionCount,\r
831 LoadOptionTypeBoot);\r
832 EfiBootManagerFreeLoadOptions (BootOptions, OldBootOptionCount);\r
833\r
834 //\r
835 // Connect all devices, and regenerate all boot options\r
836 //\r
837 EfiBootManagerConnectAll ();\r
838 EfiBootManagerRefreshAllBootOption ();\r
839\r
840 //\r
841 // Record the updated number of boot configured boot options\r
842 //\r
843 BootOptions = EfiBootManagerGetLoadOptions (&NewBootOptionCount,\r
844 LoadOptionTypeBoot);\r
845 EfiBootManagerFreeLoadOptions (BootOptions, NewBootOptionCount);\r
846\r
847 //\r
848 // If the number of configured boot options has changed, reboot\r
849 // the system so the new boot options will be taken into account\r
850 // while executing the ordinary BDS bootflow sequence.\r
851 // *Unless* persistent varstore is being emulated, since we would\r
852 // then end up in an endless reboot loop.\r
853 //\r
854 if (!PcdGetBool (PcdEmuVariableNvModeEnable)) {\r
855 if (NewBootOptionCount != OldBootOptionCount) {\r
856 DEBUG ((DEBUG_WARN, "%a: rebooting after refreshing all boot options\n",\r
857 __FUNCTION__));\r
858 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);\r
859 }\r
860 }\r
861\r
862 Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);\r
863 if (EFI_ERROR (Status)) {\r
864 return;\r
865 }\r
866\r
867 for (;;) {\r
868 EfiBootManagerBoot (&BootManagerMenu);\r
869 }\r
870}\r