PlatformBm.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. /** @file
  2. Implementation for PlatformBootManagerLib library class interfaces.
  3. Copyright (c) 2022 Loongson Technology Corporation Limited. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <IndustryStandard/Pci22.h>
  7. #include <Library/BootLogoLib.h>
  8. #include <Library/PcdLib.h>
  9. #include <Library/QemuBootOrderLib.h>
  10. #include <Library/UefiBootManagerLib.h>
  11. #include <Protocol/FirmwareVolume2.h>
  12. #include <Protocol/LoadedImage.h>
  13. #include <Protocol/PciIo.h>
  14. #include <Library/UefiBootServicesTableLib.h>
  15. #include <Library/DebugLib.h>
  16. #include <Library/MemoryAllocationLib.h>
  17. #include <Library/UefiLib.h>
  18. #include <Library/BaseMemoryLib.h>
  19. #include "PlatformBm.h"
  20. STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = {
  21. //
  22. // VENDOR_DEVICE_PATH SerialDxe
  23. //
  24. {
  25. { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DP_NODE_LEN (VENDOR_DEVICE_PATH) },
  26. SERIAL_DXE_FILE_GUID
  27. },
  28. //
  29. // UART_DEVICE_PATH Uart
  30. //
  31. {
  32. { MESSAGING_DEVICE_PATH, MSG_UART_DP, DP_NODE_LEN (UART_DEVICE_PATH) },
  33. 0, // Reserved
  34. FixedPcdGet64 (PcdUartDefaultBaudRate), // BaudRate
  35. FixedPcdGet8 (PcdUartDefaultDataBits), // DataBits
  36. FixedPcdGet8 (PcdUartDefaultParity), // Parity
  37. FixedPcdGet8 (PcdUartDefaultStopBits) // StopBits
  38. },
  39. //
  40. // VENDOR_DEFINED_DEVICE_PATH TermType
  41. //
  42. {
  43. {
  44. MESSAGING_DEVICE_PATH, MSG_VENDOR_DP,
  45. DP_NODE_LEN (VENDOR_DEFINED_DEVICE_PATH)
  46. }
  47. //
  48. // Guid to be filled in dynamically
  49. //
  50. },
  51. //
  52. // EFI_DEVICE_PATH_PROTOCOL End
  53. //
  54. {
  55. END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
  56. DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)
  57. }
  58. };
  59. STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard = {
  60. //
  61. // USB_CLASS_DEVICE_PATH Keyboard
  62. //
  63. {
  64. {
  65. MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP,
  66. DP_NODE_LEN (USB_CLASS_DEVICE_PATH)
  67. },
  68. 0xFFFF, // VendorId: any
  69. 0xFFFF, // ProductId: any
  70. 3, // DeviceClass: HID
  71. 1, // DeviceSubClass: boot
  72. 1 // DeviceProtocol: keyboard
  73. },
  74. //
  75. // EFI_DEVICE_PATH_PROTOCOL End
  76. //
  77. {
  78. END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
  79. DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)
  80. }
  81. };
  82. /**
  83. Locate all handles that carry the specified protocol, filter them with a
  84. callback function, and pass each handle that passes the filter to another
  85. callback.
  86. @param[in] ProtocolGuid The protocol to look for.
  87. @param[in] Filter The filter function to pass each handle to. If this
  88. parameter is NULL, then all handles are processed.
  89. @param[in] Process The callback function to pass each handle to that
  90. clears the filter.
  91. **/
  92. VOID
  93. FilterAndProcess (
  94. IN EFI_GUID *ProtocolGuid,
  95. IN FILTER_FUNCTION Filter OPTIONAL,
  96. IN CALLBACK_FUNCTION Process
  97. )
  98. {
  99. EFI_STATUS Status;
  100. EFI_HANDLE *Handles;
  101. UINTN NoHandles;
  102. UINTN Idx;
  103. Status = gBS->LocateHandleBuffer (ByProtocol, ProtocolGuid,
  104. NULL /* SearchKey */, &NoHandles, &Handles);
  105. if (EFI_ERROR (Status)) {
  106. //
  107. // This is not an error, just an informative condition.
  108. //
  109. DEBUG ((DEBUG_VERBOSE, "%a: %g: %r\n", __FUNCTION__, ProtocolGuid,
  110. Status));
  111. return;
  112. }
  113. ASSERT (NoHandles > 0);
  114. for (Idx = 0; Idx < NoHandles; ++Idx) {
  115. CHAR16 *DevicePathText;
  116. STATIC CHAR16 Fallback[] = L"<device path unavailable>";
  117. //
  118. // The ConvertDevicePathToText () function handles NULL input transparently.
  119. //
  120. DevicePathText = ConvertDevicePathToText (
  121. DevicePathFromHandle (Handles[Idx]),
  122. FALSE, // DisplayOnly
  123. FALSE // AllowShortcuts
  124. );
  125. if (DevicePathText == NULL) {
  126. DevicePathText = Fallback;
  127. }
  128. if ((Filter == NULL)
  129. || (Filter (Handles[Idx], DevicePathText)))
  130. {
  131. Process (Handles[Idx], DevicePathText);
  132. }
  133. if (DevicePathText != Fallback) {
  134. FreePool (DevicePathText);
  135. }
  136. }
  137. gBS->FreePool (Handles);
  138. }
  139. /**
  140. This FILTER_FUNCTION checks if a handle corresponds to a PCI display device.
  141. @param Handle The handle to check
  142. @param ReportText A pointer to a string at the time of the error.
  143. @retval TURE THe handle corresponds to a PCI display device.
  144. @retval FALSE THe handle does not corresponds to a PCI display device.
  145. **/
  146. BOOLEAN
  147. EFIAPI
  148. IsPciDisplay (
  149. IN EFI_HANDLE Handle,
  150. IN CONST CHAR16 *ReportText
  151. )
  152. {
  153. EFI_STATUS Status;
  154. EFI_PCI_IO_PROTOCOL *PciIo;
  155. PCI_TYPE00 Pci;
  156. Status = gBS->HandleProtocol (Handle, &gEfiPciIoProtocolGuid,
  157. (VOID**)&PciIo);
  158. if (EFI_ERROR (Status)) {
  159. //
  160. // This is not an error worth reporting.
  161. //
  162. return FALSE;
  163. }
  164. Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0 /* Offset */,
  165. sizeof Pci / sizeof (UINT32), &Pci);
  166. if (EFI_ERROR (Status)) {
  167. DEBUG ((DEBUG_ERROR, "%a: %s: %r\n", __FUNCTION__, ReportText, Status));
  168. return FALSE;
  169. }
  170. return IS_PCI_DISPLAY (&Pci);
  171. }
  172. /**
  173. This CALLBACK_FUNCTION attempts to connect a handle non-recursively, asking
  174. the matching driver to produce all first-level child handles.
  175. @param Handle The handle to connect.
  176. @param ReportText A pointer to a string at the time of the error.
  177. @retval VOID
  178. **/
  179. VOID
  180. EFIAPI
  181. Connect (
  182. IN EFI_HANDLE Handle,
  183. IN CONST CHAR16 *ReportText
  184. )
  185. {
  186. EFI_STATUS Status;
  187. Status = gBS->ConnectController (
  188. Handle, // ControllerHandle
  189. NULL, // DriverImageHandle
  190. NULL, // RemainingDevicePath -- produce all children
  191. FALSE // Recursive
  192. );
  193. DEBUG ((EFI_ERROR (Status) ? DEBUG_ERROR : DEBUG_VERBOSE, "%a: %s: %r\n",
  194. __FUNCTION__, ReportText, Status));
  195. }
  196. /**
  197. This CALLBACK_FUNCTION retrieves the EFI_DEVICE_PATH_PROTOCOL from the
  198. handle, and adds it to ConOut and ErrOut.
  199. @param Handle The handle to retrieves.
  200. @param ReportText A pointer to a string at the time of the error.
  201. @retval VOID
  202. **/
  203. VOID
  204. EFIAPI
  205. AddOutput (
  206. IN EFI_HANDLE Handle,
  207. IN CONST CHAR16 *ReportText
  208. )
  209. {
  210. EFI_STATUS Status;
  211. EFI_DEVICE_PATH_PROTOCOL *DevicePath;
  212. DevicePath = DevicePathFromHandle (Handle);
  213. if (DevicePath == NULL) {
  214. DEBUG ((DEBUG_ERROR, "%a: %s: handle %p: device path not found\n",
  215. __FUNCTION__, ReportText, Handle));
  216. return;
  217. }
  218. Status = EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL);
  219. if (EFI_ERROR (Status)) {
  220. DEBUG ((DEBUG_ERROR, "%a: %s: adding to ConOut: %r\n", __FUNCTION__,
  221. ReportText, Status));
  222. return;
  223. }
  224. Status = EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL);
  225. if (EFI_ERROR (Status)) {
  226. DEBUG ((DEBUG_ERROR, "%a: %s: adding to ErrOut: %r\n", __FUNCTION__,
  227. ReportText, Status));
  228. return;
  229. }
  230. DEBUG ((DEBUG_VERBOSE, "%a: %s: added to ConOut and ErrOut\n", __FUNCTION__,
  231. ReportText));
  232. }
  233. /**
  234. Register the boot option.
  235. @param FileGuid File Guid.
  236. @param Description Option descriptor.
  237. @param Attributes Option Attributes.
  238. @retval VOID
  239. **/
  240. VOID
  241. PlatformRegisterFvBootOption (
  242. IN EFI_GUID *FileGuid,
  243. IN CHAR16 *Description,
  244. IN UINT32 Attributes
  245. )
  246. {
  247. EFI_STATUS Status;
  248. INTN OptionIndex;
  249. EFI_BOOT_MANAGER_LOAD_OPTION NewOption;
  250. EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
  251. UINTN BootOptionCount;
  252. MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;
  253. EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
  254. EFI_DEVICE_PATH_PROTOCOL *DevicePath;
  255. Status = gBS->HandleProtocol (
  256. gImageHandle,
  257. &gEfiLoadedImageProtocolGuid,
  258. (VOID **) &LoadedImage
  259. );
  260. ASSERT_EFI_ERROR (Status);
  261. EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);
  262. DevicePath = DevicePathFromHandle (LoadedImage->DeviceHandle);
  263. ASSERT (DevicePath != NULL);
  264. DevicePath = AppendDevicePathNode (
  265. DevicePath,
  266. (EFI_DEVICE_PATH_PROTOCOL *) &FileNode
  267. );
  268. ASSERT (DevicePath != NULL);
  269. Status = EfiBootManagerInitializeLoadOption (
  270. &NewOption,
  271. LoadOptionNumberUnassigned,
  272. LoadOptionTypeBoot,
  273. Attributes,
  274. Description,
  275. DevicePath,
  276. NULL,
  277. 0
  278. );
  279. ASSERT_EFI_ERROR (Status);
  280. FreePool (DevicePath);
  281. BootOptions = EfiBootManagerGetLoadOptions (
  282. &BootOptionCount, LoadOptionTypeBoot
  283. );
  284. OptionIndex = EfiBootManagerFindLoadOption (
  285. &NewOption, BootOptions, BootOptionCount
  286. );
  287. if (OptionIndex == -1) {
  288. Status = EfiBootManagerAddLoadOptionVariable (&NewOption, MAX_UINTN);
  289. ASSERT_EFI_ERROR (Status);
  290. }
  291. EfiBootManagerFreeLoadOption (&NewOption);
  292. EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
  293. }
  294. /**
  295. Remove all MemoryMapped (...)/FvFile (...) and Fv (...)/FvFile (...) boot options
  296. whose device paths do not resolve exactly to an FvFile in the system.
  297. This removes any boot options that point to binaries built into the firmware
  298. and have become stale due to any of the following:
  299. - FvMain's base address or size changed (historical),
  300. - FvMain's FvNameGuid changed,
  301. - the FILE_GUID of the pointed-to binary changed,
  302. - the referenced binary is no longer built into the firmware.
  303. EfiBootManagerFindLoadOption () used in PlatformRegisterFvBootOption () only
  304. avoids exact duplicates.
  305. **/
  306. VOID
  307. RemoveStaleFvFileOptions (
  308. VOID
  309. )
  310. {
  311. EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
  312. UINTN BootOptionCount;
  313. UINTN Index;
  314. BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount,
  315. LoadOptionTypeBoot);
  316. for (Index = 0; Index < BootOptionCount; ++Index) {
  317. EFI_DEVICE_PATH_PROTOCOL *Node1, *Node2, *SearchNode;
  318. EFI_STATUS Status;
  319. EFI_HANDLE FvHandle;
  320. //
  321. // If the device path starts with neither MemoryMapped (...) nor Fv (...),
  322. // then keep the boot option.
  323. //
  324. Node1 = BootOptions[Index].FilePath;
  325. if (!(DevicePathType (Node1) == HARDWARE_DEVICE_PATH
  326. && DevicePathSubType (Node1) == HW_MEMMAP_DP)
  327. && !(DevicePathType (Node1) == MEDIA_DEVICE_PATH
  328. && DevicePathSubType (Node1) == MEDIA_PIWG_FW_VOL_DP))
  329. {
  330. continue;
  331. }
  332. //
  333. // If the second device path node is not FvFile (...), then keep the boot
  334. // option.
  335. //
  336. Node2 = NextDevicePathNode (Node1);
  337. if ((DevicePathType (Node2) != MEDIA_DEVICE_PATH)
  338. || (DevicePathSubType (Node2) != MEDIA_PIWG_FW_FILE_DP))
  339. {
  340. continue;
  341. }
  342. //
  343. // Locate the Firmware Volume2 protocol instance that is denoted by the
  344. // boot option. If this lookup fails (i.e., the boot option references a
  345. // firmware volume that doesn't exist), then we'll proceed to delete the
  346. // boot option.
  347. //
  348. SearchNode = Node1;
  349. Status = gBS->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid,
  350. &SearchNode, &FvHandle);
  351. if (!EFI_ERROR (Status)) {
  352. //
  353. // The firmware volume was found; now let's see if it contains the FvFile
  354. // identified by GUID.
  355. //
  356. EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol;
  357. MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFileNode;
  358. UINTN BufferSize;
  359. EFI_FV_FILETYPE FoundType;
  360. EFI_FV_FILE_ATTRIBUTES FileAttributes;
  361. UINT32 AuthenticationStatus;
  362. Status = gBS->HandleProtocol (FvHandle, &gEfiFirmwareVolume2ProtocolGuid,
  363. (VOID **)&FvProtocol);
  364. ASSERT_EFI_ERROR (Status);
  365. FvFileNode = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)Node2;
  366. //
  367. // Buffer==NULL means we request metadata only: BufferSize, FoundType,
  368. // FileAttributes.
  369. //
  370. Status = FvProtocol->ReadFile (
  371. FvProtocol,
  372. &FvFileNode->FvFileName, // NameGuid
  373. NULL, // Buffer
  374. &BufferSize,
  375. &FoundType,
  376. &FileAttributes,
  377. &AuthenticationStatus
  378. );
  379. if (!EFI_ERROR (Status)) {
  380. //
  381. // The FvFile was found. Keep the boot option.
  382. //
  383. continue;
  384. }
  385. }
  386. //
  387. // Delete the boot option.
  388. //
  389. Status = EfiBootManagerDeleteLoadOptionVariable (
  390. BootOptions[Index].OptionNumber, LoadOptionTypeBoot);
  391. DEBUG_CODE (
  392. CHAR16 *DevicePathString;
  393. DevicePathString = ConvertDevicePathToText (BootOptions[Index].FilePath,
  394. FALSE, FALSE);
  395. DEBUG ((
  396. EFI_ERROR (Status) ? EFI_D_WARN : DEBUG_VERBOSE,
  397. "%a: removing stale Boot#%04x %s: %r\n",
  398. __FUNCTION__,
  399. (UINT32)BootOptions[Index].OptionNumber,
  400. DevicePathString == NULL ? L"<unavailable>" : DevicePathString,
  401. Status
  402. ));
  403. if (DevicePathString != NULL) {
  404. FreePool (DevicePathString);
  405. }
  406. );
  407. }
  408. EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
  409. }
  410. /**
  411. Register the boot option And Keys.
  412. @param VOID
  413. @retval VOID
  414. **/
  415. VOID
  416. PlatformRegisterOptionsAndKeys (
  417. VOID
  418. )
  419. {
  420. EFI_STATUS Status;
  421. EFI_INPUT_KEY Enter;
  422. EFI_INPUT_KEY F2;
  423. EFI_INPUT_KEY Esc;
  424. EFI_BOOT_MANAGER_LOAD_OPTION BootOption;
  425. //
  426. // Register ENTER as CONTINUE key
  427. //
  428. Enter.ScanCode = SCAN_NULL;
  429. Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;
  430. Status = EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);
  431. ASSERT_EFI_ERROR (Status);
  432. //
  433. // Map F2 and ESC to Boot Manager Menu
  434. //
  435. F2.ScanCode = SCAN_F2;
  436. F2.UnicodeChar = CHAR_NULL;
  437. Esc.ScanCode = SCAN_ESC;
  438. Esc.UnicodeChar = CHAR_NULL;
  439. Status = EfiBootManagerGetBootManagerMenu (&BootOption);
  440. ASSERT_EFI_ERROR (Status);
  441. Status = EfiBootManagerAddKeyOptionVariable (
  442. NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL
  443. );
  444. ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);
  445. Status = EfiBootManagerAddKeyOptionVariable (
  446. NULL, (UINT16) BootOption.OptionNumber, 0, &Esc, NULL
  447. );
  448. ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);
  449. }
  450. //
  451. // BDS Platform Functions
  452. //
  453. /**
  454. Do the platform init, can be customized by OEM/IBV
  455. Possible things that can be done in PlatformBootManagerBeforeConsole:
  456. > Update console variable: 1. include hot-plug devices;
  457. > 2. Clear ConIn and add SOL for AMT
  458. > Register new Driver#### or Boot####
  459. > Register new Key####: e.g.: F12
  460. > Signal ReadyToLock event
  461. > Authentication action: 1. connect Auth devices;
  462. > 2. Identify auto logon user.
  463. **/
  464. VOID
  465. EFIAPI
  466. PlatformBootManagerBeforeConsole (
  467. VOID
  468. )
  469. {
  470. RETURN_STATUS PcdStatus;
  471. //
  472. // Signal EndOfDxe PI Event
  473. //
  474. EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);
  475. //
  476. // Dispatch deferred images after EndOfDxe event.
  477. //
  478. EfiBootManagerDispatchDeferredImages ();
  479. //
  480. // Locate the PCI root bridges and make the PCI bus driver connect each,
  481. // non-recursively. This will produce a number of child handles with PciIo on
  482. // them.
  483. //
  484. FilterAndProcess (&gEfiPciRootBridgeIoProtocolGuid, NULL, Connect);
  485. //
  486. // Signal the ACPI platform driver that it can download QEMU ACPI tables.
  487. //
  488. EfiEventGroupSignal (&gRootBridgesConnectedEventGroupGuid);
  489. //
  490. // Find all display class PCI devices (using the handles from the previous
  491. // step), and connect them non-recursively. This should produce a number of
  492. // child handles with GOPs on them.
  493. //
  494. FilterAndProcess (&gEfiPciIoProtocolGuid, IsPciDisplay, Connect);
  495. //
  496. // Now add the device path of all handles with GOP on them to ConOut and
  497. // ErrOut.
  498. //
  499. FilterAndProcess (&gEfiGraphicsOutputProtocolGuid, NULL, AddOutput);
  500. //
  501. // Add the hardcoded short-form USB keyboard device path to ConIn.
  502. //
  503. EfiBootManagerUpdateConsoleVariable (ConIn,
  504. (EFI_DEVICE_PATH_PROTOCOL *)&mUsbKeyboard, NULL);
  505. //
  506. // Add the hardcoded serial console device path to ConIn, ConOut, ErrOut.
  507. //
  508. CopyGuid (&mSerialConsole.TermType.Guid, &gEfiTtyTermGuid);
  509. EfiBootManagerUpdateConsoleVariable (ConIn,
  510. (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);
  511. EfiBootManagerUpdateConsoleVariable (ConOut,
  512. (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);
  513. EfiBootManagerUpdateConsoleVariable (ErrOut,
  514. (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);
  515. //
  516. // Set the front page timeout from the QEMU configuration.
  517. //
  518. PcdStatus = PcdSet16S (PcdPlatformBootTimeOut,
  519. GetFrontPageTimeoutFromQemu ());
  520. ASSERT_RETURN_ERROR (PcdStatus);
  521. //
  522. // Register platform-specific boot options and keyboard shortcuts.
  523. //
  524. PlatformRegisterOptionsAndKeys ();
  525. }
  526. /**
  527. Do the platform specific action after the console is ready
  528. Possible things that can be done in PlatformBootManagerAfterConsole:
  529. > Console post action:
  530. > Dynamically switch output mode from 100x31 to 80x25 for certain senarino
  531. > Signal console ready platform customized event
  532. > Run diagnostics like memory testing
  533. > Connect certain devices
  534. > Dispatch aditional option roms
  535. > Special boot: e.g.: USB boot, enter UI
  536. **/
  537. VOID
  538. EFIAPI
  539. PlatformBootManagerAfterConsole (
  540. VOID
  541. )
  542. {
  543. //
  544. // Show the splash screen.
  545. //
  546. BootLogoEnableLogo ();
  547. //
  548. // Connect the rest of the devices.
  549. //
  550. EfiBootManagerConnectAll ();
  551. //
  552. // Process QEMU's -kernel command line option. Note that the kernel booted
  553. // this way should receive ACPI tables, which is why we connect all devices
  554. // first (see above) -- PCI enumeration blocks ACPI table installation, if
  555. // there is a PCI host.
  556. //
  557. TryRunningQemuKernel ();
  558. //
  559. // Enumerate all possible boot options, then filter and reorder them based on
  560. // the QEMU configuration.
  561. //
  562. EfiBootManagerRefreshAllBootOption ();
  563. //
  564. // Register UEFI Shell
  565. //
  566. PlatformRegisterFvBootOption (
  567. &gUefiShellFileGuid, L"EFI Internal Shell", LOAD_OPTION_ACTIVE
  568. );
  569. RemoveStaleFvFileOptions ();
  570. SetBootOrderFromQemu ();
  571. }
  572. /**
  573. This function is called each second during the boot manager waits the
  574. timeout.
  575. @param TimeoutRemain The remaining timeout.
  576. **/
  577. VOID
  578. EFIAPI
  579. PlatformBootManagerWaitCallback (
  580. IN UINT16 TimeoutRemain
  581. )
  582. {
  583. EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Black;
  584. EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION White;
  585. UINT16 Timeout;
  586. Timeout = PcdGet16 (PcdPlatformBootTimeOut);
  587. Black.Raw = 0x00000000;
  588. White.Raw = 0x00FFFFFF;
  589. BootLogoUpdateProgress (
  590. White.Pixel,
  591. Black.Pixel,
  592. L"Start boot option",
  593. White.Pixel,
  594. (Timeout - TimeoutRemain) * 100 / Timeout,
  595. 0
  596. );
  597. }
  598. /**
  599. The function is called when no boot option could be launched,
  600. including platform recovery options and options pointing to applications
  601. built into firmware volumes.
  602. If this function returns, BDS attempts to enter an infinite loop.
  603. **/
  604. VOID
  605. EFIAPI
  606. PlatformBootManagerUnableToBoot (
  607. VOID
  608. )
  609. {
  610. EFI_STATUS Status;
  611. EFI_INPUT_KEY Key;
  612. EFI_BOOT_MANAGER_LOAD_OPTION BootManagerMenu;
  613. UINTN Index;
  614. //
  615. // BootManagerMenu doesn't contain the correct information when return status
  616. // is EFI_NOT_FOUND.
  617. //
  618. Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);
  619. if (EFI_ERROR (Status)) {
  620. return;
  621. }
  622. //
  623. // Normally BdsDxe does not print anything to the system console, but this is
  624. // a last resort -- the end-user will likely not see any DEBUG messages
  625. // logged in this situation.
  626. //
  627. // AsciiPrint () will NULL-check gST->ConOut internally. We check gST->ConIn
  628. // here to see if it makes sense to request and wait for a keypress.
  629. //
  630. if (gST->ConIn != NULL) {
  631. AsciiPrint (
  632. "%a: No bootable option or device was found.\n"
  633. "%a: Press any key to enter the Boot Manager Menu.\n",
  634. gEfiCallerBaseName,
  635. gEfiCallerBaseName
  636. );
  637. Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &Index);
  638. ASSERT_EFI_ERROR (Status);
  639. ASSERT (Index == 0);
  640. //
  641. // Drain any queued keys.
  642. //
  643. while (!EFI_ERROR (gST->ConIn->ReadKeyStroke (gST->ConIn, &Key))) {
  644. //
  645. // just throw away Key
  646. //
  647. }
  648. }
  649. for (;;) {
  650. EfiBootManagerBoot (&BootManagerMenu);
  651. }
  652. }