3 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 This file include all platform action which can be customized
26 #include "BdsPlatform.h"
27 #include "SetupMode.h"
28 #include <Guid/SetupVariable.h>
29 #include <Library/TcgPhysicalPresenceLib.h>
30 #include <Library/Tcg2PhysicalPresenceLib.h>
31 #include <Protocol/I2cMasterMcg.h>
33 #include <PlatformBaseAddresses.h>
34 #include <Protocol/GlobalNvsArea.h>
35 #include <Library/DxeServicesTableLib.h>
36 #include <Protocol/BlockIo.h>
37 #include <PchRegs/PchRegsPcu.h>
38 #include <Library/S3BootScriptLib.h>
39 #include "PchAccess.h"
40 #include "PchRegs/PchRegsSata.h"
41 #include <Library/SerialPortLib.h>
42 #include <Library/DebugLib.h>
44 #include <Library/GenericBdsLib/InternalBdsLib.h>
45 #include <Library/GenericBdsLib/String.h>
46 #include <Library/NetLib.h>
48 #include <Library/CapsuleLib.h>
49 #include <Protocol/EsrtManagement.h>
51 EFI_GUID
*ConnectDriverTable
[] = {
52 &gEfiMmioDeviceProtocolGuid
,
53 &gEfiI2cMasterProtocolGuid
,
54 &gEfiI2cHostProtocolGuid
57 #define SHELL_ENVIRONMENT_INTERFACE_PROTOCOL \
59 0x47c7b221, 0xc42a, 0x11d2, 0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b \
61 VOID
*mShellImageCallbackReg
= NULL
;
65 EFI_USER_PROFILE_HANDLE mCurrentUser
= NULL
;
66 EFI_EVENT mHotKeyTimerEvent
= NULL
;
67 EFI_EVENT mHitHotkeyEvent
= NULL
;
68 EFI_EVENT mUsbKeyboardConnectEvent
= NULL
;
69 BOOLEAN mHotKeyPressed
= FALSE
;
70 VOID
*mHitHotkeyRegistration
;
71 #define KEYBOARD_TIMER_INTERVAL 20000 // 0.02s
74 ConnectUSBController (
79 PlatformBdsConnectSimpleConsole (
80 IN BDS_CONSOLE_CONNECT_ENTRY
*PlatformConsole
84 BootIntoFirmwareInterface(
90 PlatformBdsInitHotKeyEvent (
101 UINT32 PmcDisableAddress
;
102 UINT8 SataStorageAmount
;
104 UINT16 SataPortStatus
;
107 DEBUG ((EFI_D_INFO
, "Disable AHCI event is signalled\n"));
108 SataStorageAmount
= 0;
109 SataBase
= *(UINT32
*) Context
;
112 // BayTrail-M EDS chapter 16 ---- PCI IO Register Offset 92 (SATA Port Control and Status)
114 SataPortStatus
= MmioRead16 (SataBase
+ R_PCH_SATA_PCS
);
117 // Bit 8 EN: Port 0 Present
119 if ((SataPortStatus
& 0x100) == 0x100) {
124 // Bit 9 EN: Port 1 Present
126 if ((SataPortStatus
& 0x200) == 0x200) {
131 // Disable SATA controller when it sets to AHCI mode without carrying any devices
132 // in order to prevent AHCI yellow bang under Win device manager.
134 if (SataStorageAmount
== 0) {
135 PmcDisableAddress
= (MmioRead32 ((PCH_PCI_EXPRESS_BASE_ADDRESS
+ (UINT32
) (31 << 15)) + R_PCH_LPC_PMC_BASE
) & B_PCH_LPC_PMC_BASE_BAR
) + R_PCH_PMC_FUNC_DIS
;
136 MmioOr32 (PmcDisableAddress
, B_PCH_PMC_FUNC_DIS_SATA
);
137 S3BootScriptSaveMemWrite (
138 EfiBootScriptWidthUint32
,
139 (UINTN
) PmcDisableAddress
,
141 (VOID
*) (UINTN
) PmcDisableAddress
153 EFI_SMM_ACCESS2_PROTOCOL
*SmmAccess
;
154 EFI_ACPI_S3_SAVE_PROTOCOL
*AcpiS3Save
;
157 // Install DxeSmmReadyToLock protocol prior to the processing of boot options
159 Status
= gBS
->LocateProtocol (
160 &gEfiSmmAccess2ProtocolGuid
,
164 if (!EFI_ERROR (Status
)) {
167 // Prepare S3 information, this MUST be done before DxeSmmReadyToLock
169 Status
= gBS
->LocateProtocol (
170 &gEfiAcpiS3SaveProtocolGuid
,
174 if (!EFI_ERROR (Status
)) {
175 AcpiS3Save
->S3Save (AcpiS3Save
, NULL
);
179 Status
= gBS
->InstallProtocolInterface (
181 &gExitPmAuthProtocolGuid
,
182 EFI_NATIVE_INTERFACE
,
185 ASSERT_EFI_ERROR (Status
);
188 // Signal EndOfDxe PI Event
190 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid
);
193 Status
= gBS
->InstallProtocolInterface (
195 &gEfiDxeSmmReadyToLockProtocolGuid
,
196 EFI_NATIVE_INTERFACE
,
199 ASSERT_EFI_ERROR (Status
);
212 BdsSetConsoleMode (TRUE
);
213 DEBUG ((EFI_D_INFO
, "BdsEntry ShellImageCallback \n"));
217 // BDS Platform Functions
220 Platform Bds init. Include the platform firmware vendor, revision
235 EFI_EVENT ShellImageEvent
;
236 EFI_GUID ShellEnvProtocol
= SHELL_ENVIRONMENT_INTERFACE_PROTOCOL
;
239 SerialPortWrite((UINT8
*)">>>>BdsEntry[GCC]\r\n", 19);
241 SerialPortWrite((UINT8
*)">>>>BdsEntry\r\n", 14);
243 BdsLibSaveMemoryTypeInformation ();
246 // Before user authentication, the user identification devices need be connected
247 // from the platform customized device paths
249 PlatformBdsConnectAuthDevice ();
252 // As console is not ready, the auto logon user will be identified.
254 BdsLibUserIdentify (&mCurrentUser
);
257 // Change Gop mode when boot into Shell
259 if (mShellImageCallbackReg
== NULL
) {
260 Status
= gBS
->CreateEvent (
261 EFI_EVENT_NOTIFY_SIGNAL
,
267 if (!EFI_ERROR (Status
)) {
268 Status
= gBS
->RegisterProtocolNotify (
271 &mShellImageCallbackReg
274 DEBUG ((EFI_D_INFO
, "BdsEntry ShellImageCallback \n"));
281 IN EFI_DEVICE_PATH_PROTOCOL
*PciDevicePath
,
282 OUT EFI_DEVICE_PATH_PROTOCOL
**GopDevicePath
287 EFI_HANDLE PciDeviceHandle
;
288 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
289 EFI_DEVICE_PATH_PROTOCOL
*TempPciDevicePath
;
290 UINTN GopHandleCount
;
291 EFI_HANDLE
*GopHandleBuffer
;
294 SYSTEM_CONFIGURATION mSystemConfiguration
;
296 if (PciDevicePath
== NULL
|| GopDevicePath
== NULL
) {
297 return EFI_INVALID_PARAMETER
;
301 // Initialize the GopDevicePath to be PciDevicePath
303 *GopDevicePath
= PciDevicePath
;
304 TempPciDevicePath
= PciDevicePath
;
306 Status
= gBS
->LocateDevicePath (
307 &gEfiDevicePathProtocolGuid
,
311 if (EFI_ERROR (Status
)) {
316 // Try to connect this handle, so that GOP driver could start on this
317 // device and create child handles with GraphicsOutput Protocol installed
318 // on them, then we get device paths of these child handles and select
319 // them as possible console device.
323 // Select display devices
325 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
326 Status
= gRT
->GetVariable(
328 &gEfiNormalSetupGuid
,
331 &mSystemConfiguration
333 if (EFI_ERROR (Status
) || VarSize
!= sizeof(SYSTEM_CONFIGURATION
)) {
334 //The setup variable is corrupted
335 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
336 Status
= gRT
->GetVariable(
338 &gEfiNormalSetupGuid
,
341 &mSystemConfiguration
343 ASSERT_EFI_ERROR (Status
);
346 if(mSystemConfiguration
.BootDisplayDevice
!= 0x0)
348 ACPI_ADR_DEVICE_PATH AcpiAdr
;
349 EFI_DEVICE_PATH_PROTOCOL
*MyDevicePath
= NULL
;
351 AcpiAdr
.Header
.Type
= ACPI_DEVICE_PATH
;
352 AcpiAdr
.Header
.SubType
= ACPI_ADR_DP
;
354 switch (mSystemConfiguration
.BootDisplayDevice
) {
356 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA
, PORT_CRT
, 0); //CRT Device
359 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL
, PORT_B_HDMI
, 0); //HDMI Device Port B
362 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL
, PORT_B_DP
, 0); //DP PortB
365 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL
, PORT_C_DP
, 0); //DP PortC
368 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL
, PORT_C_DP
, 0); //eDP Port C
371 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL
, PORT_MIPI_A
, 0); //DSI Port A
374 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL
, PORT_MIPI_C
, 0); //DSI Port C
377 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA
, PORT_CRT
, 0);
381 SetDevicePathNodeLength (&AcpiAdr
.Header
, sizeof (ACPI_ADR_DEVICE_PATH
));
383 MyDevicePath
= AppendDevicePathNode(MyDevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&AcpiAdr
);
385 gBS
->ConnectController (
392 FreePool(MyDevicePath
);
396 gBS
->ConnectController (
404 Status
= gBS
->LocateHandleBuffer (
406 &gEfiGraphicsOutputProtocolGuid
,
411 if (!EFI_ERROR (Status
)) {
413 // Add all the child handles as possible Console Device
415 for (Index
= 0; Index
< GopHandleCount
; Index
++) {
416 Status
= gBS
->HandleProtocol (
417 GopHandleBuffer
[Index
],
418 &gEfiDevicePathProtocolGuid
,
419 (VOID
**)&TempDevicePath
421 if (EFI_ERROR (Status
)) {
427 GetDevicePathSize (PciDevicePath
) - END_DEVICE_PATH_LENGTH
430 // In current implementation, we only enable one of the child handles
431 // as console device, i.e. sotre one of the child handle's device
432 // path to variable "ConOut"
433 // In future, we could select all child handles to be console device
435 *GopDevicePath
= TempDevicePath
;
438 gBS
->FreePool (GopHandleBuffer
);
446 Search out all the platform pci or agp video device. The function may will
447 find multiple video device, and return all enabled device path.
449 @param PlugInPciVgaDevicePath Return the platform plug in pci video device
450 path if the system have plug in pci video device.
451 @param OnboardPciVgaDevicePath Return the platform active agp video device path
452 if the system have plug in agp video device or on
455 @retval EFI_SUCCSS Get all platform active video device path.
456 @retval EFI_STATUS Return the status of gBS->LocateDevicePath (),
457 gBS->ConnectController (),
458 and gBS->LocateHandleBuffer ().
462 GetPlugInPciVgaDevicePath (
463 IN OUT EFI_DEVICE_PATH_PROTOCOL
**PlugInPciVgaDevicePath
,
464 IN OUT EFI_DEVICE_PATH_PROTOCOL
**OnboardPciVgaDevicePath
468 EFI_HANDLE RootHandle
;
470 EFI_HANDLE
*HandleBuffer
;
473 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
474 BOOLEAN PlugInPciVga
;
475 EFI_PCI_IO_PROTOCOL
*PciIo
;
484 // Make all the PCI_IO protocols on PCI Seg 0 show up
486 BdsLibConnectDevicePath (gPlatformRootBridges
[0]);
488 Status
= gBS
->LocateDevicePath (
489 &gEfiDevicePathProtocolGuid
,
490 &gPlatformRootBridges
[0],
493 if (EFI_ERROR (Status
)) {
497 Status
= gBS
->ConnectController (
503 if (EFI_ERROR (Status
)) {
508 // Start to check all the pci io to find all possible VGA device
512 Status
= gBS
->LocateHandleBuffer (
514 &gEfiPciIoProtocolGuid
,
519 if (EFI_ERROR (Status
)) {
523 for (Index
= 0; Index
< HandleCount
; Index
++) {
524 Status
= gBS
->HandleProtocol (
526 &gEfiPciIoProtocolGuid
,
529 if (!EFI_ERROR (Status
)) {
532 // Check for all VGA device
534 Status
= PciIo
->Pci
.Read (
538 sizeof (Pci
) / sizeof (UINT32
),
541 if (EFI_ERROR (Status
)) {
546 // Here we decide which VGA device to enable in PCI bus
548 // The first plugin PCI VGA card device will be present as PCI VGA
549 // The onchip AGP or AGP card will be present as AGP VGA
551 if (!IS_PCI_VGA (&Pci
)) {
556 // Set the device as the possible console out device,
558 // Below code will make every VGA device to be one
559 // of the possibe console out device
562 gBS
->HandleProtocol (
564 &gEfiDevicePathProtocolGuid
,
570 while (gPlatformAllPossiblePciVgaConsole
[Index1
] != NULL
) {
573 gPlatformAllPossiblePciVgaConsole
[Index1
],
574 GetDevicePathSize (gPlatformAllPossiblePciVgaConsole
[Index1
])
578 // This device is an AGP device
580 *OnboardPciVgaDevicePath
= DevicePath
;
581 PlugInPciVga
= FALSE
;
589 *PlugInPciVgaDevicePath
= DevicePath
;
594 FreePool (HandleBuffer
);
601 Find the platform active vga, and base on the policy to enable the vga as
602 the console out device. The policy is driven by one setup variable "VBIOS".
606 @param EFI_UNSUPPORTED There is no active vga device
608 @retval EFI_STATUS Return the status of BdsLibGetVariableAndSize ()
612 PlatformBdsForceActiveVga (
617 EFI_DEVICE_PATH_PROTOCOL
*PlugInPciVgaDevicePath
;
618 EFI_DEVICE_PATH_PROTOCOL
*OnboardPciVgaDevicePath
;
619 EFI_DEVICE_PATH_PROTOCOL
*DevicePathFirst
;
620 EFI_DEVICE_PATH_PROTOCOL
*DevicePathSecond
;
621 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
623 SYSTEM_CONFIGURATION mSystemConfiguration
;
625 Status
= EFI_SUCCESS
;
626 PlugInPciVgaDevicePath
= NULL
;
627 OnboardPciVgaDevicePath
= NULL
;
630 // Check the policy which is the first enabled VGA
632 GetPlugInPciVgaDevicePath (&PlugInPciVgaDevicePath
, &OnboardPciVgaDevicePath
);
634 if (PlugInPciVgaDevicePath
== NULL
&& OnboardPciVgaDevicePath
== NULL
) {
635 return EFI_UNSUPPORTED
;
638 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
639 Status
= gRT
->GetVariable(
641 &gEfiNormalSetupGuid
,
644 &mSystemConfiguration
646 if (EFI_ERROR (Status
) || VarSize
!= sizeof(SYSTEM_CONFIGURATION
)) {
647 //The setup variable is corrupted
648 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
649 Status
= gRT
->GetVariable(
651 &gEfiNormalSetupGuid
,
654 &mSystemConfiguration
656 ASSERT_EFI_ERROR (Status
);
660 if ((PlugInPciVgaDevicePath
== NULL
&& OnboardPciVgaDevicePath
!= NULL
) ) {
661 DEBUG ((EFI_D_ERROR
,"Update onboard PCI VGA ...\n"));
662 DevicePathFirst
= OnboardPciVgaDevicePath
;
663 DevicePathSecond
= PlugInPciVgaDevicePath
;
666 if(OnboardPciVgaDevicePath
!= NULL
&& mSystemConfiguration
.PrimaryVideoAdaptor
== 0) {
667 DEBUG ((EFI_D_ERROR
,"Update onboard PCI VGA When set primary!!!...\n"));
668 DevicePathFirst
= OnboardPciVgaDevicePath
;
669 DevicePathSecond
= PlugInPciVgaDevicePath
;
673 DEBUG ((EFI_D_ERROR
,"Update plug in PCI VGA ...\n"));
674 DevicePathFirst
= PlugInPciVgaDevicePath
;
675 DevicePathSecond
= OnboardPciVgaDevicePath
;
678 GetGopDevicePath (DevicePathFirst
, &GopDevicePath
);
679 DevicePathFirst
= GopDevicePath
;
681 Status
= BdsLibUpdateConsoleVariable (
691 UpdateConsoleResolution(
695 UINT32 HorizontalResolution
;
696 UINT32 VerticalResolution
;
697 SYSTEM_CONFIGURATION SystemConfiguration
;
702 HorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
703 VerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
705 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
706 Status
= gRT
->GetVariable(
708 &gEfiNormalSetupGuid
,
713 if (EFI_ERROR (Status
) || VarSize
!= sizeof(SYSTEM_CONFIGURATION
)) {
714 //The setup variable is corrupted
715 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
716 Status
= gRT
->GetVariable(
718 &gEfiNormalSetupGuid
,
723 ASSERT_EFI_ERROR (Status
);
726 switch (SystemConfiguration
.IgdFlatPanel
) {
730 // Use the detault PCD values.
735 HorizontalResolution
= 640;
736 VerticalResolution
= 480;
740 HorizontalResolution
= 800;
741 VerticalResolution
= 600;
745 HorizontalResolution
= 1024;
746 VerticalResolution
= 768;
750 HorizontalResolution
= 1280;
751 VerticalResolution
= 1024;
755 HorizontalResolution
= 1366;
756 VerticalResolution
= 768;
760 HorizontalResolution
= 1680;
761 VerticalResolution
= 1050;
765 HorizontalResolution
= 1920;
766 VerticalResolution
= 1200;
770 HorizontalResolution
= 1280;
771 VerticalResolution
= 800;
775 PcdSet32 (PcdSetupVideoHorizontalResolution
, HorizontalResolution
);
776 PcdSet32 (PcdSetupVideoVerticalResolution
, VerticalResolution
);
777 DEBUG ((EFI_D_ERROR
, "HorizontalResolution = %x; VerticalResolution = %x", HorizontalResolution
, VerticalResolution
));
783 Connect the predefined platform default console device. Always try to find
784 and enable the vga device if have.
786 @param PlatformConsole Predefined platform default console device array.
788 @retval EFI_SUCCESS Success connect at least one ConIn and ConOut
789 device, there must have one ConOut device is
792 @retval EFI_STATUS Return the status of
793 BdsLibConnectAllDefaultConsoles ()
797 PlatformBdsConnectConsole (
798 IN BDS_CONSOLE_CONNECT_ENTRY
*PlatformConsole
803 EFI_DEVICE_PATH_PROTOCOL
*VarConout
;
804 EFI_DEVICE_PATH_PROTOCOL
*VarConin
;
805 UINTN DevicePathSize
;
807 UpdateConsoleResolution();
810 Status
= EFI_SUCCESS
;
812 VarConout
= BdsLibGetVariableAndSize (
814 &gEfiGlobalVariableGuid
,
817 VarConin
= BdsLibGetVariableAndSize (
819 &gEfiGlobalVariableGuid
,
822 if (VarConout
== NULL
|| VarConin
== NULL
) {
824 // Have chance to connect the platform default console,
825 // the platform default console is the minimum device group
826 // the platform should support
828 while (PlatformConsole
[Index
].DevicePath
!= NULL
) {
831 // Update the console variable with the connect type
833 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
834 BdsLibUpdateConsoleVariable (L
"ConIn", PlatformConsole
[Index
].DevicePath
, NULL
);
837 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
838 BdsLibUpdateConsoleVariable (L
"ConOut", PlatformConsole
[Index
].DevicePath
, NULL
);
841 if ((PlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
842 BdsLibUpdateConsoleVariable (L
"ErrOut", PlatformConsole
[Index
].DevicePath
, NULL
);
850 // Make sure we have at least one active VGA, and have the right
851 // active VGA in console variable
853 Status
= PlatformBdsForceActiveVga ();
854 if (EFI_ERROR (Status
)) {
858 DEBUG ((EFI_D_INFO
, "DISPLAY INIT DONE\n"));
861 // Connect the all the default console with current console variable
863 Status
= BdsLibConnectAllDefaultConsoles ();
864 if (EFI_ERROR (Status
)) {
872 Connect with predefined platform connect sequence,
873 the OEM/IBV can customize with their own connect sequence.
881 PlatformBdsConnectSequence (
890 // Here we can get the customized platform connect sequence
891 // Notes: we can connect with new variable which record the
892 // last time boots connect device path sequence
894 while (gPlatformConnectSequence
[Index
] != NULL
) {
897 // Build the platform boot option
899 BdsLibConnectDevicePath (gPlatformConnectSequence
[Index
]);
904 // Just use the simple policy to connect all devices
905 // There should be no difference between debug tip and release tip, or it will be extremely hard to debug.
907 // There is case that IdeController driver will write boot script in driver model Start() function. It will be rejected by boot script save.
908 // It is only found when DEBUG disabled, because we are using BdsLibConnectAll() when DEBUG enabled.
910 // So we use BdsLibConnectAll() here to make sure IdeController.Start() is invoked before InstallReadyToLock().
911 // We may also consider to connect SataController only later if needed.
918 Load the predefined driver option, OEM/IBV can customize this
919 to load their own drivers
921 @param BdsDriverLists The header of the driver option link list.
927 PlatformBdsGetDriverOption (
928 IN OUT LIST_ENTRY
*BdsDriverLists
936 // Here we can get the customized platform driver option
938 while (gPlatformDriverOption
[Index
] != NULL
) {
941 // Build the platform boot option
943 BdsLibRegisterNewOption (BdsDriverLists
, gPlatformDriverOption
[Index
], NULL
, L
"DriverOrder");
950 This function is used for some critical time if the the system
951 have no any boot option, and there is no time out for user to add
952 the new boot option. This can also treat as the platform default
955 @param BdsBootOptionList The header of the boot option link list.
961 PlatformBdsPredictBootOption (
962 IN OUT LIST_ENTRY
*BdsBootOptionList
970 // Here give chance to get platform boot option data
972 while (gPlatformBootOption
[Index
] != NULL
) {
975 // Build the platform boot option
977 BdsLibRegisterNewOption (BdsBootOptionList
, gPlatformBootOption
[Index
], NULL
, L
"BootOrder");
983 Perform the platform diagnostic, such like test memory. OEM/IBV also
984 can customize this fuction to support specific platform diagnostic.
986 @param MemoryTestLevel The memory test intensive level
987 @param QuietBoot Indicate if need to enable the quiet boot
988 @param BaseMemoryTest A pointer to BdsMemoryTest()
994 PlatformBdsDiagnostics (
995 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel
,
996 IN BOOLEAN QuietBoot
,
997 IN BASEM_MEMORY_TEST BaseMemoryTest
1003 // Here we can decide if we need to show
1004 // the diagnostics screen
1005 // Notes: this quiet boot code should be remove
1006 // from the graphic lib
1009 EnableQuietBoot (PcdGetPtr(PcdLogoFile
));
1012 // Perform system diagnostic
1014 Status
= BaseMemoryTest (MemoryTestLevel
);
1015 if (EFI_ERROR (Status
)) {
1016 DisableQuietBoot ();
1023 // Perform system diagnostic
1025 Status
= BaseMemoryTest (MemoryTestLevel
);
1030 For EFI boot option, BDS separate them as six types:
1031 1. Network - The boot option points to the SimpleNetworkProtocol device.
1032 Bds will try to automatically create this type boot option when enumerate.
1033 2. Shell - The boot option points to internal flash shell.
1034 Bds will try to automatically create this type boot option when enumerate.
1035 3. Removable BlockIo - The boot option only points to the removable media
1036 device, like USB flash disk, DVD, Floppy etc.
1037 These device should contain a *removable* blockIo
1038 protocol in their device handle.
1039 Bds will try to automatically create this type boot option
1041 4. Fixed BlockIo - The boot option only points to a Fixed blockIo device,
1043 These device should contain a *fixed* blockIo
1044 protocol in their device handle.
1045 BDS will skip fixed blockIo devices, and NOT
1046 automatically create boot option for them. But BDS
1047 will help to delete those fixed blockIo boot option,
1048 whose description rule conflict with other auto-created
1050 5. Non-BlockIo Simplefile - The boot option points to a device whose handle
1051 has SimpleFileSystem Protocol, but has no blockio
1052 protocol. These devices do not offer blockIo
1053 protocol, but BDS still can get the
1054 \EFI\BOOT\boot{machinename}.EFI by SimpleFileSystem
1056 6. File - The boot option points to a file. These boot options are usually
1057 created by user manually or OS loader. BDS will not delete or modify
1060 This function will enumerate all possible boot device in the system, and
1061 automatically create boot options for Network, Shell, Removable BlockIo,
1062 and Non-BlockIo Simplefile devices.
1063 It will only execute once of every boot.
1065 @param BdsBootOptionList The header of the link list which indexed all
1066 current boot options
1068 @retval EFI_SUCCESS Finished all the boot device enumerate and create
1069 the boot option base on that boot device
1071 @retval EFI_OUT_OF_RESOURCES Failed to enumerate the boot device and create the boot option list
1075 PlatformBdsLibEnumerateAllBootOption (
1076 IN OUT LIST_ENTRY
*BdsBootOptionList
1080 UINT16 FloppyNumber
;
1081 UINT16 HarddriveNumber
;
1086 UINT16 NonBlockNumber
;
1087 UINTN NumberBlockIoHandles
;
1088 EFI_HANDLE
*BlockIoHandles
;
1089 EFI_BLOCK_IO_PROTOCOL
*BlkIo
;
1090 BOOLEAN Removable
[2];
1091 UINTN RemovableIndex
;
1093 UINTN NumOfLoadFileHandles
;
1094 EFI_HANDLE
*LoadFileHandles
;
1095 UINTN FvHandleCount
;
1096 EFI_HANDLE
*FvHandleBuffer
;
1097 EFI_FV_FILETYPE Type
;
1099 EFI_FV_FILE_ATTRIBUTES Attributes
;
1100 UINT32 AuthenticationStatus
;
1101 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
1102 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1103 UINTN DevicePathType
;
1105 EFI_HANDLE
*FileSystemHandles
;
1106 UINTN NumberFileSystemHandles
;
1108 EFI_IMAGE_DOS_HEADER DosHeader
;
1111 EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData
;
1112 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
;
1115 EFI_HANDLE
*NetworkHandles
;
1119 HarddriveNumber
= 0;
1126 ZeroMem (Buffer
, sizeof (Buffer
));
1129 // If the boot device enumerate happened, just get the boot
1130 // device from the boot order variable
1132 if (mEnumBootDevice
) {
1133 GetVariable2 (LAST_ENUM_LANGUAGE_VARIABLE_NAME
, &gLastEnumLangGuid
, (VOID
**)&LastLang
, NULL
);
1134 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&PlatLang
, NULL
);
1135 ASSERT (PlatLang
!= NULL
);
1136 if ((LastLang
!= NULL
) && (AsciiStrCmp (LastLang
, PlatLang
) == 0)) {
1137 Status
= BdsLibBuildOptionFromVar (BdsBootOptionList
, L
"BootOrder");
1138 FreePool (LastLang
);
1139 FreePool (PlatLang
);
1142 Status
= gRT
->SetVariable (
1143 LAST_ENUM_LANGUAGE_VARIABLE_NAME
,
1145 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1146 AsciiStrSize (PlatLang
),
1150 // Failure to set the variable only impacts the performance next time enumerating the boot options.
1153 if (LastLang
!= NULL
) {
1154 FreePool (LastLang
);
1156 FreePool (PlatLang
);
1161 // Notes: this dirty code is to get the legacy boot option from the
1162 // BBS table and create to variable as the EFI boot option, it should
1163 // be removed after the CSM can provide legacy boot option directly
1165 REFRESH_LEGACY_BOOT_OPTIONS
;
1168 // Delete invalid boot option
1170 BdsDeleteAllInvalidEfiBootOption ();
1173 // Parse removable media followed by fixed media.
1174 // The Removable[] array is used by the for-loop below to create removable media boot options
1175 // at first, and then to create fixed media boot options.
1177 Removable
[0] = FALSE
;
1178 Removable
[1] = TRUE
;
1180 gBS
->LocateHandleBuffer (
1182 &gEfiBlockIoProtocolGuid
,
1184 &NumberBlockIoHandles
,
1188 for (RemovableIndex
= 0; RemovableIndex
< 2; RemovableIndex
++) {
1189 for (Index
= 0; Index
< NumberBlockIoHandles
; Index
++) {
1190 Status
= gBS
->HandleProtocol (
1191 BlockIoHandles
[Index
],
1192 &gEfiBlockIoProtocolGuid
,
1196 // skip the logical partition
1198 if (EFI_ERROR (Status
) || BlkIo
->Media
->LogicalPartition
) {
1203 // firstly fixed block io then the removable block io
1205 if (BlkIo
->Media
->RemovableMedia
== Removable
[RemovableIndex
]) {
1208 DevicePath
= DevicePathFromHandle (BlockIoHandles
[Index
]);
1209 DevicePathType
= BdsGetBootTypeFromDevicePath (DevicePath
);
1211 switch (DevicePathType
) {
1212 case BDS_EFI_ACPI_FLOPPY_BOOT
:
1213 if (FloppyNumber
!= 0) {
1214 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY
)), FloppyNumber
);
1216 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY
)));
1218 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1223 // Assume a removable SATA device should be the DVD/CD device, a fixed SATA device should be the Hard Drive device.
1225 case BDS_EFI_MESSAGE_ATAPI_BOOT
:
1226 case BDS_EFI_MESSAGE_SATA_BOOT
:
1227 if (BlkIo
->Media
->RemovableMedia
) {
1228 if (CdromNumber
!= 0) {
1229 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD
)), CdromNumber
);
1231 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD
)));
1235 if (HarddriveNumber
!= 0) {
1236 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE
)), HarddriveNumber
);
1238 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE
)));
1242 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "Buffer: %S\n", Buffer
));
1243 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1246 case BDS_EFI_MESSAGE_USB_DEVICE_BOOT
:
1247 if (UsbNumber
!= 0) {
1248 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB
)), UsbNumber
);
1250 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB
)));
1252 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1256 case BDS_EFI_MESSAGE_SCSI_BOOT
:
1257 if (ScsiNumber
!= 0) {
1258 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI
)), ScsiNumber
);
1260 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI
)));
1262 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1266 case BDS_EFI_MESSAGE_MISC_BOOT
:
1268 if (MiscNumber
!= 0) {
1269 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC
)), MiscNumber
);
1271 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC
)));
1273 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1280 if (NumberBlockIoHandles
!= 0) {
1281 FreePool (BlockIoHandles
);
1285 // If there is simple file protocol which does not consume block Io protocol, create a boot option for it here.
1288 gBS
->LocateHandleBuffer (
1290 &gEfiSimpleFileSystemProtocolGuid
,
1292 &NumberFileSystemHandles
,
1295 for (Index
= 0; Index
< NumberFileSystemHandles
; Index
++) {
1296 Status
= gBS
->HandleProtocol (
1297 FileSystemHandles
[Index
],
1298 &gEfiBlockIoProtocolGuid
,
1301 if (!EFI_ERROR (Status
)) {
1303 // Skip if the file system handle supports a BlkIo protocol,
1309 // Do the removable Media thing. \EFI\BOOT\boot{machinename}.EFI
1310 // machinename is ia32, ia64, x64, ...
1312 Hdr
.Union
= &HdrData
;
1314 Status
= BdsLibGetImageHeader (
1315 FileSystemHandles
[Index
],
1316 EFI_REMOVABLE_MEDIA_FILE_NAME
,
1320 if (!EFI_ERROR (Status
) &&
1321 EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr
.Pe32
->FileHeader
.Machine
) &&
1322 Hdr
.Pe32
->OptionalHeader
.Subsystem
== EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION
) {
1328 // No such file or the file is not a EFI application, delete this boot option
1330 BdsLibDeleteOptionFromHandle (FileSystemHandles
[Index
]);
1332 if (NonBlockNumber
!= 0) {
1333 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK
)), NonBlockNumber
);
1335 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK
)));
1337 BdsLibBuildOptionFromHandle (FileSystemHandles
[Index
], BdsBootOptionList
, Buffer
);
1342 if (NumberFileSystemHandles
!= 0) {
1343 FreePool (FileSystemHandles
);
1347 // Check if we have on flash shell
1349 gBS
->LocateHandleBuffer (
1351 &gEfiFirmwareVolume2ProtocolGuid
,
1356 for (Index
= 0; Index
< FvHandleCount
; Index
++) {
1357 gBS
->HandleProtocol (
1358 FvHandleBuffer
[Index
],
1359 &gEfiFirmwareVolume2ProtocolGuid
,
1363 Status
= Fv
->ReadFile (
1365 PcdGetPtr(PcdShellFile
),
1370 &AuthenticationStatus
1372 if (EFI_ERROR (Status
)) {
1374 // Skip if no shell file in the FV
1379 // Build the shell boot option
1381 BdsLibBuildOptionFromShell (FvHandleBuffer
[Index
], BdsBootOptionList
);
1384 if (FvHandleCount
!= 0) {
1385 FreePool (FvHandleBuffer
);
1389 // Parse Network Boot Device
1391 NumOfLoadFileHandles
= 0;
1393 // Search Load File protocol for PXE boot option.
1395 gBS
->LocateHandleBuffer (
1397 &gEfiLoadFileProtocolGuid
,
1399 &NumOfLoadFileHandles
,
1403 for (Index
= 0; Index
< NumOfLoadFileHandles
; Index
++) {
1406 //Locate EFI_DEVICE_PATH_PROTOCOL to dynamically get IPv4/IPv6 protocol information.
1409 Status
= gBS
->HandleProtocol (
1410 LoadFileHandles
[Index
],
1411 &gEfiDevicePathProtocolGuid
,
1412 (VOID
**) &DevicePath
1415 ASSERT_EFI_ERROR (Status
);
1417 while (!IsDevicePathEnd (DevicePath
)) {
1418 if ((DevicePath
->Type
== MESSAGING_DEVICE_PATH
) &&
1419 (DevicePath
->SubType
== MSG_IPv4_DP
)) {
1422 //Get handle infomation
1425 NetworkHandles
= NULL
;
1426 Status
= gBS
->LocateHandle (
1428 &gEfiSimpleNetworkProtocolGuid
,
1434 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1435 NetworkHandles
= AllocateZeroPool(BufferSize
);
1436 if (NetworkHandles
== NULL
) {
1437 return (EFI_OUT_OF_RESOURCES
);
1439 Status
= gBS
->LocateHandle(
1441 &gEfiSimpleNetworkProtocolGuid
,
1449 //Get the MAC string
1451 Status
= NetLibGetMacString (
1456 if (EFI_ERROR (Status
)) {
1459 IPverStr
= L
" IPv4";
1460 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK
)),MacStr
,IPverStr
);
1463 if((DevicePath
->Type
== MESSAGING_DEVICE_PATH
) &&
1464 (DevicePath
->SubType
== MSG_IPv6_DP
)) {
1467 //Get handle infomation
1470 NetworkHandles
= NULL
;
1471 Status
= gBS
->LocateHandle (
1473 &gEfiSimpleNetworkProtocolGuid
,
1479 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1480 NetworkHandles
= AllocateZeroPool(BufferSize
);
1481 if (NetworkHandles
== NULL
) {
1482 return (EFI_OUT_OF_RESOURCES
);
1484 Status
= gBS
->LocateHandle(
1486 &gEfiSimpleNetworkProtocolGuid
,
1494 //Get the MAC string
1496 Status
= NetLibGetMacString (
1501 if (EFI_ERROR (Status
)) {
1504 IPverStr
= L
" IPv6";
1505 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK
)),MacStr
,IPverStr
);
1508 DevicePath
= NextDevicePathNode (DevicePath
);
1511 BdsLibBuildOptionFromHandle (LoadFileHandles
[Index
], BdsBootOptionList
, Buffer
);
1514 if (NumOfLoadFileHandles
!= 0) {
1515 FreePool (LoadFileHandles
);
1519 // Check if we have on flash shell
1521 /* gBS->LocateHandleBuffer (
1523 &gEfiFirmwareVolume2ProtocolGuid,
1528 for (Index = 0; Index < FvHandleCount; Index++) {
1529 gBS->HandleProtocol (
1530 FvHandleBuffer[Index],
1531 &gEfiFirmwareVolume2ProtocolGuid,
1535 Status = Fv->ReadFile (
1537 PcdGetPtr(PcdShellFile),
1542 &AuthenticationStatus
1544 if (EFI_ERROR (Status)) {
1546 // Skip if no shell file in the FV
1551 // Build the shell boot option
1553 BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList);
1556 if (FvHandleCount != 0) {
1557 FreePool (FvHandleBuffer);
1561 // Make sure every boot only have one time
1562 // boot device enumerate
1564 Status
= BdsLibBuildOptionFromVar (BdsBootOptionList
, L
"BootOrder");
1565 mEnumBootDevice
= TRUE
;
1574 The function will execute with as the platform policy, current policy
1575 is driven by boot mode. IBV/OEM can customize this code for their specific
1578 @param DriverOptionList - The header of the driver option link list
1579 @param BootOptionList - The header of the boot option link list
1580 @param ProcessCapsules - A pointer to ProcessCapsules()
1581 @param BaseMemoryTest - A pointer to BaseMemoryTest()
1588 PlatformBdsPolicyBehavior (
1589 IN OUT LIST_ENTRY
*DriverOptionList
,
1590 IN OUT LIST_ENTRY
*BootOptionList
,
1591 IN PROCESS_CAPSULES BdsProcessCapsules
,
1592 IN BASEM_MEMORY_TEST BaseMemoryTest
1597 EFI_BOOT_MODE BootMode
;
1598 BOOLEAN DeferredImageExist
;
1600 SYSTEM_CONFIGURATION SystemConfiguration
;
1602 PLATFORM_PCI_DEVICE_PATH
*EmmcBootDevPath
;
1603 EFI_GLOBAL_NVS_AREA_PROTOCOL
*GlobalNvsArea
;
1604 EFI_HANDLE FvProtocolHandle
;
1606 EFI_HANDLE
*HandleBuffer
;
1608 UINTN SataPciRegBase
= 0;
1609 UINT16 SataModeSelect
= 0;
1610 VOID
*RegistrationExitPmAuth
= NULL
;
1612 BOOLEAN IsFirstBoot
;
1614 UINTN BootOrderSize
;
1615 ESRT_MANAGEMENT_PROTOCOL
*EsrtManagement
;
1617 Timeout
= PcdGet16 (PcdPlatformBootTimeOut
);
1618 if (Timeout
> 10 ) {
1619 //we think the Timeout variable is corrupted
1623 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
1624 Status
= gRT
->GetVariable(
1626 &gEfiNormalSetupGuid
,
1629 &SystemConfiguration
1632 if (EFI_ERROR (Status
) || VarSize
!= sizeof(SYSTEM_CONFIGURATION
)) {
1633 //The setup variable is corrupted
1634 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
1635 Status
= gRT
->GetVariable(
1637 &gEfiNormalSetupGuid
,
1640 &SystemConfiguration
1642 ASSERT_EFI_ERROR (Status
);
1646 // Load the driver option as the driver option list
1648 PlatformBdsGetDriverOption (DriverOptionList
);
1651 // Get current Boot Mode
1653 BootMode
= GetBootModeHob();
1656 // No deferred images exist by default
1658 DeferredImageExist
= FALSE
;
1659 if ((BootMode
!= BOOT_WITH_MINIMAL_CONFIGURATION
) && (PcdGet32(PcdFlashFvShellSize
) > 0)){
1660 gDS
->ProcessFirmwareVolume (
1661 (VOID
*)(UINTN
)PcdGet32(PcdFlashFvShellBase
),
1662 PcdGet32(PcdFlashFvShellSize
),
1667 if (SystemConfiguration
.FastBoot
== 1) {
1668 BootOrder
= BdsLibGetVariableAndSize (
1670 &gEfiGlobalVariableGuid
,
1673 if ((BootOrder
!= NULL
) && (BootMode
!= BOOT_ON_FLASH_UPDATE
)) {
1675 // BootOrder exist, it means system has boot before. We can do fast boot.
1677 BootMode
= BOOT_WITH_MINIMAL_CONFIGURATION
;
1683 // Use eMMC to boot OS and turn on AHCI, when SATA HDD is diconnected,
1684 // SATA AHCI CTLR device will show yellow bang, implement this solution to solve it.
1686 SataPciRegBase
= MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA
, 0, 0);
1687 SataModeSelect
= MmioRead16 (SataPciRegBase
+ R_PCH_SATA_MAP
) & B_PCH_SATA_MAP_SMS_MASK
;
1688 Status
= EFI_SUCCESS
;
1689 if (SataModeSelect
!= V_PCH_SATA_MAP_SMS_IDE
) {
1690 Status
= gBS
->CreateEvent (
1697 if (!EFI_ERROR (Status
)) {
1698 Status
= gBS
->RegisterProtocolNotify (
1699 &gExitPmAuthProtocolGuid
,
1701 &RegistrationExitPmAuth
1706 Status
= gBS
->LocateProtocol(&gEsrtManagementProtocolGuid
, NULL
, (VOID
**)&EsrtManagement
);
1707 if (EFI_ERROR(Status
)) {
1708 EsrtManagement
= NULL
;
1713 case BOOT_WITH_MINIMAL_CONFIGURATION
:
1714 PlatformBdsInitHotKeyEvent ();
1715 PlatformBdsConnectSimpleConsole (gPlatformSimpleConsole
);
1719 // Check to see if it's needed to dispatch more DXE drivers.
1721 for (Index
= 0; Index
< sizeof(ConnectDriverTable
)/sizeof(EFI_GUID
*); Index
++) {
1722 Status
= gBS
->LocateHandleBuffer (
1724 ConnectDriverTable
[Index
],
1729 if (!EFI_ERROR (Status
)) {
1730 for (Index1
= 0; Index1
< HandleCount
; Index1
++) {
1731 gBS
->ConnectController (
1732 HandleBuffer
[Index1
],
1740 if (HandleBuffer
!= NULL
) {
1741 FreePool (HandleBuffer
);
1748 // Locate the Global NVS Protocol.
1750 Status
= gBS
->LocateProtocol (
1751 &gEfiGlobalNvsAreaProtocolGuid
,
1753 (void **)&GlobalNvsArea
1755 if (GlobalNvsArea
->Area
->emmcVersion
== 0){
1756 EmmcBootDevPath
= (PLATFORM_PCI_DEVICE_PATH
*)gPlatformSimpleBootOption
[0];
1757 EmmcBootDevPath
->PciDevice
.Device
= 0x10;
1761 // Connect boot device here to give time to read keyboard.
1763 BdsLibConnectDevicePath (gPlatformSimpleBootOption
[0]);
1766 // This is a workround for dectecting hotkey from USB keyboard.
1768 gBS
->Stall(KEYBOARD_TIMER_INTERVAL
);
1770 if (mHotKeyTimerEvent
!= NULL
) {
1776 gBS
->CloseEvent (mHotKeyTimerEvent
);
1777 mHotKeyTimerEvent
= NULL
;
1779 if (mHotKeyPressed
) {
1781 // Skip show progress count down
1784 goto FULL_CONFIGURATION
;
1787 if (SystemConfiguration
.QuietBoot
) {
1788 EnableQuietBoot (PcdGetPtr(PcdLogoFile
));
1790 PlatformBdsDiagnostics (IGNORE
, FALSE
, BaseMemoryTest
);
1795 TcgPhysicalPresenceLibProcessRequest();
1798 Tcg2PhysicalPresenceLibProcessRequest(NULL
);
1801 if (EsrtManagement
!= NULL
) {
1802 EsrtManagement
->LockEsrtRepository();
1806 // Close boot script and install ready to lock
1808 InstallReadyToLock ();
1811 // Give one chance to enter the setup if we
1812 // select Gummiboot "Reboot Into Firmware Interface" and Fast Boot is enabled.
1814 BootIntoFirmwareInterface();
1817 case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES
:
1820 // In no-configuration boot mode, we can connect the
1821 // console directly.
1823 BdsLibConnectAllDefaultConsoles ();
1824 PlatformBdsDiagnostics (IGNORE
, TRUE
, BaseMemoryTest
);
1827 // Perform some platform specific connect sequence
1829 PlatformBdsConnectSequence ();
1832 // As console is ready, perform user identification again.
1834 if (mCurrentUser
== NULL
) {
1835 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1836 if (DeferredImageExist
) {
1838 // After user authentication, the deferred drivers was loaded again.
1839 // Here, need to ensure the deferred images are connected.
1841 BdsLibConnectAllDefaultConsoles ();
1842 PlatformBdsConnectSequence ();
1846 if (EsrtManagement
!= NULL
) {
1847 EsrtManagement
->LockEsrtRepository();
1851 // Close boot script and install ready to lock
1853 InstallReadyToLock ();
1856 // Notes: current time out = 0 can not enter the
1859 PlatformBdsEnterFrontPageWithHotKey (Timeout
, FALSE
);
1862 // Check the boot option with the boot option list
1864 BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
1867 case BOOT_ON_FLASH_UPDATE
:
1870 // Boot with the specific configuration
1872 PlatformBdsConnectConsole (gPlatformConsole
);
1873 PlatformBdsDiagnostics (EXTENSIVE
, FALSE
, BaseMemoryTest
);
1874 EnableQuietBoot (PcdGetPtr(PcdLogoFile
));
1876 DEBUG((DEBUG_INFO
, "ProcessCapsules Before EndOfDxe......\n"));
1878 DEBUG((DEBUG_INFO
, "ProcessCapsules Done\n"));
1881 // Close boot script and install ready to lock
1883 InstallReadyToLock ();
1885 BdsLibConnectAll ();
1888 // Perform user identification
1890 if (mCurrentUser
== NULL
) {
1891 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1892 if (DeferredImageExist
) {
1894 // After user authentication, the deferred drivers was loaded again.
1895 // Here, need to ensure the deferred images are connected.
1897 BdsLibConnectAll ();
1901 if (EsrtManagement
!= NULL
) {
1902 EsrtManagement
->SyncEsrtFmp();
1905 DEBUG((DEBUG_INFO
, "ProcessCapsules After ConnectAll......\n"));
1907 DEBUG((DEBUG_INFO
, "ProcessCapsules Done\n"));
1910 case BOOT_IN_RECOVERY_MODE
:
1913 // In recovery mode, just connect platform console
1914 // and show up the front page
1916 PlatformBdsConnectConsole (gPlatformConsole
);
1917 PlatformBdsDiagnostics (EXTENSIVE
, FALSE
, BaseMemoryTest
);
1918 BdsLibConnectAll ();
1921 // Perform user identification
1923 if (mCurrentUser
== NULL
) {
1924 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1925 if (DeferredImageExist
) {
1927 // After user authentication, the deferred drivers was loaded again.
1928 // Here, need to ensure the deferred drivers are connected.
1930 BdsLibConnectAll ();
1935 // Close boot script and install ready to lock
1937 InstallReadyToLock ();
1940 // In recovery boot mode, we still enter to the
1943 PlatformBdsEnterFrontPageWithHotKey (Timeout
, FALSE
);
1947 case BOOT_WITH_FULL_CONFIGURATION
:
1948 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS
:
1949 case BOOT_WITH_DEFAULT_SETTINGS
:
1953 // Connect platform console
1955 Status
= PlatformBdsConnectConsole (gPlatformConsole
);
1956 if (EFI_ERROR (Status
)) {
1959 // Here OEM/IBV can customize with defined action
1961 PlatformBdsNoConsoleAction ();
1965 // Chenyunh[TODO]: This is Workgroud to show the fs for uSDcard,
1966 // Need to root cause this issue.
1968 DEBUG ((DEBUG_ERROR
, "Start to reconnect all driver.\n"));
1969 BdsLibDisconnectAllEfi();
1970 BdsLibConnectAll ();
1971 DEBUG ((DEBUG_ERROR
, "End to reconnect all driver.\n"));
1974 // Perform some platform specific connect sequence
1976 PlatformBdsConnectSequence ();
1977 if (SystemConfiguration
.QuietBoot
) {
1978 EnableQuietBoot (PcdGetPtr(PcdLogoFile
));
1980 PlatformBdsDiagnostics (IGNORE
, FALSE
, BaseMemoryTest
);
1984 // Do a pre-delay so Hard Disk can spin up and see more logo.
1986 gBS
->Stall(SystemConfiguration
.HddPredelay
* 1000000);
1989 // Perform user identification
1991 if (mCurrentUser
== NULL
) {
1992 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1993 if (DeferredImageExist
) {
1995 // After user authentication, the deferred drivers was loaded again.
1996 // Here, need to ensure the deferred drivers are connected.
1998 Status
= PlatformBdsConnectConsole (gPlatformConsole
);
1999 if (EFI_ERROR (Status
)) {
2000 PlatformBdsNoConsoleAction ();
2002 PlatformBdsConnectSequence ();
2006 TcgPhysicalPresenceLibProcessRequest();
2009 Tcg2PhysicalPresenceLibProcessRequest(NULL
);
2012 if (EsrtManagement
!= NULL
) {
2013 EsrtManagement
->SyncEsrtFmp();
2016 // Close boot script and install ready to lock
2018 InstallReadyToLock ();
2021 // Here we have enough time to do the enumeration of boot device
2023 PlatformBdsLibEnumerateAllBootOption (BootOptionList
);
2026 // Give one chance to enter the setup if we
2027 // have the time out
2029 PlatformBdsEnterFrontPageWithHotKey (Timeout
, FALSE
);
2032 // Give one chance to enter the setup if we
2033 // select Gummiboot "Reboot Into Firmware Interface"
2035 BootIntoFirmwareInterface();
2038 // In default boot mode, always find all boot
2039 // option and do enumerate all the default boot option
2042 BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
2043 if (IsListEmpty(BootOptionList
)) {
2044 PlatformBdsPredictBootOption (BootOptionList
);
2055 IsFirstBoot
= PcdGetBool(PcdBootState
);
2057 PcdSetBool(PcdBootState
, FALSE
);
2064 Hook point after a boot attempt succeeds. We don't expect a boot option to
2065 return, so the UEFI 2.0 specification defines that you will default to an
2066 interactive mode and stop processing the BootOrder list in this case. This
2067 is alos a platform implementation and can be customized by IBV/OEM.
2069 @param Option Pointer to Boot Option that succeeded to boot.
2076 PlatformBdsBootSuccess (
2077 IN BDS_COMMON_OPTION
*Option
2083 // If Boot returned with EFI_SUCCESS and there is not in the boot device
2084 // select loop then we need to pop up a UI and wait for user input.
2086 TmpStr
= Option
->StatusString
;
2087 if (TmpStr
!= NULL
) {
2088 BdsLibOutputStrings (gST
->ConOut
, TmpStr
, Option
->Description
, L
"\n\r", NULL
);
2094 Hook point after a boot attempt fails.
2096 @param Option - Pointer to Boot Option that failed to boot.
2097 @param Status - Status returned from failed boot.
2098 @param ExitData - Exit data returned from failed boot.
2099 @param ExitDataSize - Exit data size returned from failed boot.
2106 PlatformBdsBootFail (
2107 IN BDS_COMMON_OPTION
*Option
,
2108 IN EFI_STATUS Status
,
2109 IN CHAR16
*ExitData
,
2110 IN UINTN ExitDataSize
2114 EFI_HANDLE FvProtocolHandle
;
2117 // If Boot returned with failed status then we need to pop up a UI and wait
2120 TmpStr
= Option
->StatusString
;
2121 if (TmpStr
!= NULL
) {
2122 BdsLibOutputStrings (gST
->ConOut
, TmpStr
, Option
->Description
, L
"\n\r", NULL
);
2125 if (PcdGet32(PcdFlashFvShellSize
) > 0){
2126 gDS
->ProcessFirmwareVolume (
2127 (VOID
*)(UINTN
)PcdGet32(PcdFlashFvShellBase
),
2128 PcdGet32(PcdFlashFvShellSize
),
2132 PlatformBdsConnectSequence ();
2136 This function is remained for IBV/OEM to do some platform action,
2137 if there no console device can be connected.
2141 @retval EFI_SUCCESS Direct return success now.
2145 PlatformBdsNoConsoleAction (
2153 This function locks the block
2155 @param Base The base address flash region to be locked.
2160 IN EFI_PHYSICAL_ADDRESS Base
2163 EFI_FV_BLOCK_MAP_ENTRY
*BlockMap
;
2164 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
2165 EFI_PHYSICAL_ADDRESS BaseAddress
;
2169 BaseAddress
= Base
- 0x400000 + 2;
2170 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) ((UINTN
) (Base
));
2171 BlockMap
= &(FvHeader
->BlockMap
[0]);
2173 while ((BlockMap
->NumBlocks
!= 0) && (BlockMap
->Length
!= 0)) {
2174 BlockLength
= BlockMap
->Length
;
2175 for (Index
= 0; Index
< BlockMap
->NumBlocks
; Index
++) {
2176 MmioOr8 ((UINTN
) BaseAddress
, 0x03);
2177 BaseAddress
+= BlockLength
;
2185 PlatformBdsLockNonUpdatableFlash (
2189 EFI_PHYSICAL_ADDRESS Base
;
2191 Base
= (EFI_PHYSICAL_ADDRESS
) PcdGet32 (PcdFlashFvMainBase
);
2196 Base
= (EFI_PHYSICAL_ADDRESS
) PcdGet32 (PcdFlashFvRecoveryBase
);
2203 Lock the ConsoleIn device in system table. All key
2204 presses will be ignored until the Password is typed in. The only way to
2205 disable the password is to type it in to a ConIn device.
2207 @param Password Password used to lock ConIn device.
2209 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
2210 @retval EFI_UNSUPPORTED Password not found
2219 return EFI_UNSUPPORTED
;
2223 Connect the predefined platform default authentication devices.
2225 This function connects the predefined device path for authentication device,
2226 and if the predefined device path has child device path, the child handle will
2227 be connected too. But the child handle of the child will not be connected.
2232 PlatformBdsConnectAuthDevice (
2240 EFI_HANDLE
*HandleBuffer
;
2241 EFI_DEVICE_PATH_PROTOCOL
*ChildDevicePath
;
2242 EFI_USER_MANAGER_PROTOCOL
*Manager
;
2244 Status
= gBS
->LocateProtocol (
2245 &gEfiUserManagerProtocolGuid
,
2249 if (EFI_ERROR (Status
)) {
2251 // As user manager protocol is not installed, the authentication devices
2252 // should not be connected.
2258 while (gUserAuthenticationDevice
[Index
] != NULL
) {
2260 // Connect the platform customized device paths
2262 BdsLibConnectDevicePath (gUserAuthenticationDevice
[Index
]);
2267 // Find and connect the child device paths of the platform customized device paths
2269 HandleBuffer
= NULL
;
2270 for (Index
= 0; gUserAuthenticationDevice
[Index
] != NULL
; Index
++) {
2272 Status
= gBS
->LocateHandleBuffer (
2279 ASSERT (!EFI_ERROR (Status
));
2282 // Find and connect the child device paths of gUserIdentificationDevice[Index]
2284 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
2285 ChildDevicePath
= NULL
;
2286 Status
= gBS
->HandleProtocol (
2287 HandleBuffer
[HandleIndex
],
2288 &gEfiDevicePathProtocolGuid
,
2289 (VOID
**) &ChildDevicePath
2291 if (EFI_ERROR (Status
) || ChildDevicePath
== NULL
) {
2297 gUserAuthenticationDevice
[Index
],
2298 (GetDevicePathSize (gUserAuthenticationDevice
[Index
]) - sizeof (EFI_DEVICE_PATH_PROTOCOL
))
2302 gBS
->ConnectController (
2303 HandleBuffer
[HandleIndex
],
2311 if (HandleBuffer
!= NULL
) {
2312 FreePool (HandleBuffer
);
2317 This function is to identify a user, and return whether deferred images exist.
2319 @param[out] User Point to user profile handle.
2320 @param[out] DeferredImageExist On return, points to TRUE if the deferred image
2321 exist or FALSE if it did not exist.
2326 PlatformBdsUserIdentify (
2327 OUT EFI_USER_PROFILE_HANDLE
*User
,
2328 OUT BOOLEAN
*DeferredImageExist
2332 EFI_DEFERRED_IMAGE_LOAD_PROTOCOL
*DeferredImage
;
2334 EFI_HANDLE
*HandleBuf
;
2337 EFI_DEVICE_PATH_PROTOCOL
*ImageDevicePath
;
2343 // Perform user identification
2346 Status
= BdsLibUserIdentify (User
);
2347 } while (EFI_ERROR (Status
));
2350 // After user authentication now, try to find whether deferred image exists
2354 *DeferredImageExist
= FALSE
;
2355 Status
= gBS
->LocateHandleBuffer (
2357 &gEfiDeferredImageLoadProtocolGuid
,
2362 if (EFI_ERROR (Status
)) {
2366 for (Index
= 0; Index
< HandleCount
; Index
++) {
2367 Status
= gBS
->HandleProtocol (
2369 &gEfiDeferredImageLoadProtocolGuid
,
2370 (VOID
**) &DeferredImage
2372 if (!EFI_ERROR (Status
)) {
2374 // Find whether deferred image exists in this instance.
2377 Status
= DeferredImage
->GetImageInfo(
2381 (VOID
**) &DriverImage
,
2385 if (!EFI_ERROR (Status
)) {
2387 // The deferred image is found.
2389 FreePool (HandleBuf
);
2390 *DeferredImageExist
= TRUE
;
2396 FreePool (HandleBuf
);
2403 ShowProgressHotKey (
2404 IN UINT16 TimeoutDefault
2408 UINT16 TimeoutRemain
;
2411 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
2412 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
2413 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
2422 if (TimeoutDefault
== 0) {
2426 gST
->ConOut
->SetAttribute(gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
2428 if (DebugAssertEnabled())
2430 DEBUG ((EFI_D_INFO
, "\n\nStart showing progress bar... Press any key to stop it, or press <F2> or <DEL> to enter setup page! ...Zzz....\n"));
2435 SerialPortWrite((UINT8
*)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)[GCC]", 76);
2437 SerialPortWrite((UINT8
*)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)", 71);
2440 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
2441 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
2442 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
2448 // Check if the platform is using test key.
2450 Status
= GetSectionFromAnyFv(
2451 PcdGetPtr(PcdEdkiiRsa2048Sha256TestPublicKeyFileGuid
),
2457 if (!EFI_ERROR(Status
)) {
2458 if ((Size
== PcdGetSize(PcdRsa2048Sha256PublicKeyBuffer
)) &&
2459 (CompareMem(Buffer
, PcdGetPtr(PcdRsa2048Sha256PublicKeyBuffer
), Size
) == 0)) {
2460 TmpStr2
= L
"WARNING: Recovery Test Key is used.\r\n";
2461 if (DebugAssertEnabled()) {
2462 DEBUG ((DEBUG_INFO
, "\n\nWARNING: Recovery Test Key is used.\n"));
2464 SerialPortWrite((UINT8
*)"\n\nWARNING: Recovery Test Key is used.", sizeof("\n\nWARNING: Recovery Test Key is used."));
2466 PcdSetBoolS(PcdTestKeyUsed
, TRUE
);
2470 Status
= GetSectionFromAnyFv(
2471 PcdGetPtr(PcdEdkiiPkcs7TestPublicKeyFileGuid
),
2477 if (!EFI_ERROR(Status
)) {
2478 if ((Size
== PcdGetSize(PcdPkcs7CertBuffer
)) &&
2479 (CompareMem(Buffer
, PcdGetPtr(PcdPkcs7CertBuffer
), Size
) == 0)) {
2480 TmpStr3
= L
"WARNING: Capsule Test Key is used.\r\n";
2481 if (DebugAssertEnabled()) {
2482 DEBUG ((DEBUG_INFO
, "\n\nWARNING: Capsule Test Key is used.\r\n"));
2484 SerialPortWrite((UINT8
*)"\n\nWARNING: Capsule Test Key is used.", sizeof("\n\nWARNING: Capsule Test Key is used."));
2486 PcdSetBoolS(PcdTestKeyUsed
, TRUE
);
2492 // Clear the progress status bar first
2494 TmpStr1
= L
"Start boot option, Press <F2> or <DEL> to enter setup page.\r\n";
2495 TmpStrSize
= StrSize(TmpStr1
);
2496 if (TmpStr2
!= NULL
) {
2497 TmpStrSize
+= StrSize(TmpStr2
);
2499 if (TmpStr3
!= NULL
) {
2500 TmpStrSize
+= StrSize(TmpStr3
);
2502 TmpStr
= AllocatePool (TmpStrSize
);
2503 if (TmpStr
== NULL
) {
2506 StrCpyS(TmpStr
, TmpStrSize
/sizeof(CHAR16
), TmpStr1
);
2507 if (TmpStr2
!= NULL
) {
2508 StrCatS(TmpStr
, TmpStrSize
/sizeof(CHAR16
), TmpStr2
);
2510 if (TmpStr3
!= NULL
) {
2511 StrCatS(TmpStr
, TmpStrSize
/sizeof(CHAR16
), TmpStr3
);
2514 PlatformBdsShowProgress (Foreground
, Background
, TmpStr
, Color
, 0, 0);
2516 TimeoutRemain
= TimeoutDefault
;
2517 while (TimeoutRemain
!= 0) {
2518 if (DebugAssertEnabled())
2520 DEBUG ((EFI_D_INFO
, "Showing progress bar...Remaining %d second!\n", TimeoutRemain
));
2524 SerialPortWrite ((UINT8
*)".", 1);
2526 Status
= WaitForSingleEvent (gST
->ConIn
->WaitForKey
, ONE_SECOND
);
2527 if (Status
!= EFI_TIMEOUT
) {
2535 if (TmpStr
!= NULL
) {
2536 PlatformBdsShowProgress (
2541 ((TimeoutDefault
- TimeoutRemain
) * 100 / TimeoutDefault
),
2550 if (TimeoutRemain
== 0) {
2551 if (DebugAssertEnabled())
2556 SerialPortWrite ((UINT8
*)"\r\n", 2);
2562 // User pressed some key
2564 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2565 if (EFI_ERROR (Status
)) {
2570 // Check Volume Up Key to enter Setup
2572 GpioValue
= MmioRead32 (IO_BASE_ADDRESS
+ 0x0668); // The value of GPIOC_5
2573 if (((GpioValue
& BIT0
) == 0) && (Key
.ScanCode
== SCAN_UP
)) {
2578 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
2580 // User pressed enter, equivalent to select "continue"
2587 //F5 -- Device Manager
2588 //F7 -- Boot Manager
2589 // do not use F8. generally people assume it is windows safe mode key.
2592 DEBUG ((EFI_D_INFO
, "[Key Pressed]: ScanCode 0x%x\n", Key
.ScanCode
));
2593 switch(Key
.ScanCode
) {
2603 gHotKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
2607 gHotKey
= FRONT_PAGE_KEY_BOOT_MANAGER
;
2611 gHotKey
= FRONT_PAGE_KEY_BOOT_MAINTAIN
;
2615 //set gHotKey to continue so that flow will not go into CallFrontPage
2616 gHotKey
= FRONT_PAGE_KEY_CONTINUE
;
2627 This function is the main entry of the platform setup entry.
2628 The function will present the main menu of the system setup,
2629 this is the platform reference part and can be customize.
2632 @param TimeoutDefault The fault time out value before the system
2634 @param ConnectAllHappened The indicater to check if the connect all have
2639 PlatformBdsEnterFrontPageWithHotKey (
2640 IN UINT16 TimeoutDefault
,
2641 IN BOOLEAN ConnectAllHappened
2646 EFI_STATUS LogoStatus
;
2647 EFI_BOOT_LOGO_PROTOCOL
*BootLogo
;
2648 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
2649 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
2650 UINTN BootTextColumn
;
2653 GraphicsOutput
= NULL
;
2654 SimpleTextOut
= NULL
;
2656 PERF_START (NULL
, "BdsTimeOut", "BDS", 0);
2659 // Indicate if we need connect all in the platform setup
2661 if (ConnectAllHappened
) {
2662 gConnectAllHappened
= TRUE
;
2665 if (!mModeInitialized
) {
2667 // After the console is ready, get current video resolution
2668 // and text mode before launching setup at first time.
2670 Status
= gBS
->HandleProtocol (
2671 gST
->ConsoleOutHandle
,
2672 &gEfiGraphicsOutputProtocolGuid
,
2673 (VOID
**)&GraphicsOutput
2675 if (EFI_ERROR (Status
)) {
2676 GraphicsOutput
= NULL
;
2679 Status
= gBS
->HandleProtocol (
2680 gST
->ConsoleOutHandle
,
2681 &gEfiSimpleTextOutProtocolGuid
,
2682 (VOID
**)&SimpleTextOut
2684 if (EFI_ERROR (Status
)) {
2685 SimpleTextOut
= NULL
;
2688 if (GraphicsOutput
!= NULL
) {
2690 // Get current video resolution and text mode.
2692 mBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
2693 mBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
2696 if (SimpleTextOut
!= NULL
) {
2697 Status
= SimpleTextOut
->QueryMode (
2699 SimpleTextOut
->Mode
->Mode
,
2703 mBootTextModeColumn
= (UINT32
)BootTextColumn
;
2704 mBootTextModeRow
= (UINT32
)BootTextRow
;
2708 // Get user defined text mode for setup.
2710 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
2711 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
2712 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
2713 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
2715 mModeInitialized
= TRUE
;
2718 if (TimeoutDefault
!= 0xffff) {
2719 Status
= ShowProgressHotKey (TimeoutDefault
);
2722 // Ensure screen is clear when switch Console from Graphics mode to Text mode
2724 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
2725 gST
->ConOut
->ClearScreen (gST
->ConOut
);
2728 // Boot Logo is corrupted, report it using Boot Logo protocol.
2730 LogoStatus
= gBS
->LocateProtocol (&gEfiBootLogoProtocolGuid
, NULL
, (VOID
**) &BootLogo
);
2731 if (!EFI_ERROR (LogoStatus
) && (BootLogo
!= NULL
)) {
2732 BootLogo
->SetBootLogo (BootLogo
, NULL
, 0, 0, 0, 0);
2735 if (EFI_ERROR (Status
)) {
2737 // Timeout or user press enter to continue
2744 // Install BM HiiPackages.
2745 // Keep BootMaint HiiPackage, so that it can be covered by global setting.
2750 BdsSetConsoleMode (TRUE
);
2752 InitializeFrontPage (FALSE
);
2755 // Update Front Page strings
2757 UpdateFrontPageStrings ();
2759 Status
= EFI_SUCCESS
;
2762 Status
= CallFrontPage ();
2764 gCallbackKey
= gHotKey
;
2769 // If gCallbackKey is greater than 1 and less or equal to 5,
2770 // it will launch configuration utilities.
2773 // 4 = device manager
2774 // 5 = boot maintenance manager
2776 if (gCallbackKey
!= 0) {
2777 REPORT_STATUS_CODE (
2779 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
2784 // Based on the key that was set, we can determine what to do
2786 switch (gCallbackKey
) {
2788 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
2789 // describe to their customers in documentation how to find their setup information (namely
2790 // under the device manager and specific buckets)
2792 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager
2794 case FRONT_PAGE_KEY_CONTINUE
:
2797 // User hit continue
2801 case FRONT_PAGE_KEY_LANGUAGE
:
2804 // User made a language setting change - display front page again
2808 case FRONT_PAGE_KEY_BOOT_MANAGER
:
2810 // Remove the installed BootMaint HiiPackages when exit.
2815 // User chose to run the Boot Manager
2820 // Reinstall BootMaint HiiPackages after exiting from Boot Manager.
2825 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
2828 // Display the Device Manager
2831 CallDeviceManager ();
2832 } while (gCallbackKey
== FRONT_PAGE_KEY_DEVICE_MANAGER
);
2835 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
2838 // Display the Boot Maintenance Manager
2840 BdsStartBootMaint ();
2844 } while (((UINTN
)gCallbackKey
) != FRONT_PAGE_KEY_CONTINUE
);
2847 //Will leave browser, check any reset required change is applied? if yes, reset system
2849 SetupResetReminder ();
2851 // Remove the installed BootMaint HiiPackages when exit.
2857 // Automatically load current entry
2858 // Note: The following lines of code only execute when Auto boot
2861 PERF_END (NULL
, "BdsTimeOut", "BDS", 0);
2866 BootIntoFirmwareInterface(
2873 UINT64 OsIndication
;
2877 DataSize
= sizeof(UINT64
);
2878 Status
= gRT
->GetVariable (
2880 &gEfiGlobalVariableGuid
,
2886 DEBUG ((EFI_D_INFO
, "OSIndication Variable Value %d\n", OsIndication
));
2888 //Goto FrontPage directly when bit EFI_OS_INDICATIONS_BOOT_TO_FW_UI in OSIndication Variable is setted.
2890 if (!EFI_ERROR(Status
) && (OsIndication
!= 0)) {
2892 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
2898 PlatformBdsConnectSimpleConsole (
2899 IN BDS_CONSOLE_CONNECT_ENTRY
*PlatformConsole
2904 EFI_DEVICE_PATH_PROTOCOL
*VarConout
;
2905 EFI_DEVICE_PATH_PROTOCOL
*VarConin
;
2906 UINTN DevicePathSize
;
2910 Status
= EFI_SUCCESS
;
2912 VarConout
= BdsLibGetVariableAndSize (
2914 &gEfiGlobalVariableGuid
,
2917 VarConin
= BdsLibGetVariableAndSize (
2919 &gEfiGlobalVariableGuid
,
2922 if (VarConout
== NULL
|| VarConin
== NULL
) {
2924 // Have chance to connect the platform default console,
2925 // the platform default console is the minimum device group
2926 // the platform should support
2928 while (PlatformConsole
[Index
].DevicePath
!= NULL
) {
2931 // Update the console variable with the connect type
2933 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
2934 BdsLibUpdateConsoleVariable (L
"ConIn", PlatformConsole
[Index
].DevicePath
, NULL
);
2937 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
2938 BdsLibUpdateConsoleVariable (L
"ConOut", PlatformConsole
[Index
].DevicePath
, NULL
);
2941 if ((PlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
2942 BdsLibUpdateConsoleVariable (L
"ErrOut", PlatformConsole
[Index
].DevicePath
, NULL
);
2950 // Connect ConIn first to give keyboard time to parse hot key event.
2952 Status
= BdsLibConnectConsoleVariable (L
"ConIn");
2953 if (EFI_ERROR (Status
)) {
2958 // Make sure we have at least one active VGA, and have the right
2959 // active VGA in console variable
2961 Status
= PlatformBdsForceActiveVga ();
2964 // It seems impossible not to have any ConOut device on platform,
2965 // so we check the status here.
2967 Status
= BdsLibConnectConsoleVariable (L
"ConOut");
2968 if (EFI_ERROR (Status
)) {
2977 Timer handler to convert the key from USB.
2979 @param Event Indicates the event that invoke this function.
2980 @param Context Indicates the calling context.
2984 HotKeyTimerHandler (
2992 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2993 if (EFI_ERROR (Status
)) {
2997 switch(Key
.ScanCode
) {
3000 mHotKeyPressed
= TRUE
;
3004 gHotKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
3005 mHotKeyPressed
= TRUE
;
3009 gHotKey
= FRONT_PAGE_KEY_BOOT_MANAGER
;
3010 mHotKeyPressed
= TRUE
;
3014 gHotKey
= FRONT_PAGE_KEY_BOOT_MAINTAIN
;
3015 mHotKeyPressed
= TRUE
;
3019 if (mHotKeyPressed
) {
3025 gBS
->CloseEvent (mHotKeyTimerEvent
);
3026 mHotKeyTimerEvent
= NULL
;
3034 Callback function for SimpleTextInEx protocol install events
3036 @param Event the event that is signaled.
3037 @param Context not used here.
3049 Status
= gBS
->CloseEvent(mHitHotkeyEvent
);
3050 if (EFI_ERROR (Status
)) {
3053 Status
= gBS
->CreateEvent (
3054 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
3060 if (EFI_ERROR (Status
)) {
3063 Status
= gBS
->SetTimer (
3066 KEYBOARD_TIMER_INTERVAL
3068 if (EFI_ERROR (Status
)) {
3078 PlatformBdsInitHotKeyEvent (
3085 // Register Protocol notify for Hotkey service
3087 Status
= gBS
->CreateEvent (
3094 ASSERT_EFI_ERROR (Status
);
3097 // Register for protocol notifications on this event
3099 Status
= gBS
->RegisterProtocolNotify (
3100 &gEfiSimpleTextInputExProtocolGuid
,
3102 &mHitHotkeyRegistration
3104 ASSERT_EFI_ERROR (Status
);