3 Copyright (c) 2004 - 2015, 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/TrEEPhysicalPresenceLib.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 EFI_GUID
*ConnectDriverTable
[] = {
49 &gEfiMmioDeviceProtocolGuid
,
50 &gEfiI2cMasterProtocolGuid
,
51 &gEfiI2cHostProtocolGuid
54 #define SHELL_ENVIRONMENT_INTERFACE_PROTOCOL \
56 0x47c7b221, 0xc42a, 0x11d2, 0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b \
58 VOID
*mShellImageCallbackReg
= NULL
;
62 EFI_USER_PROFILE_HANDLE mCurrentUser
= NULL
;
63 EFI_EVENT mHotKeyTimerEvent
= NULL
;
64 EFI_EVENT mHitHotkeyEvent
= NULL
;
65 EFI_EVENT mUsbKeyboardConnectEvent
= NULL
;
66 BOOLEAN mHotKeyPressed
= FALSE
;
67 VOID
*mHitHotkeyRegistration
;
68 #define KEYBOARD_TIMER_INTERVAL 20000 // 0.02s
71 ConnectUSBController (
76 PlatformBdsConnectSimpleConsole (
77 IN BDS_CONSOLE_CONNECT_ENTRY
*PlatformConsole
81 BootIntoFirmwareInterface(
87 PlatformBdsInitHotKeyEvent (
98 UINT32 PmcDisableAddress
;
99 UINT8 SataStorageAmount
;
101 UINT16 SataPortStatus
;
104 DEBUG ((EFI_D_INFO
, "Disable AHCI event is signalled\n"));
105 SataStorageAmount
= 0;
106 SataBase
= *(UINT32
*) Context
;
109 // BayTrail-M EDS chapter 16 ---- PCI IO Register Offset 92 (SATA Port Control and Status)
111 SataPortStatus
= MmioRead16 (SataBase
+ R_PCH_SATA_PCS
);
114 // Bit 8 EN: Port 0 Present
116 if ((SataPortStatus
& 0x100) == 0x100) {
121 // Bit 9 EN: Port 1 Present
123 if ((SataPortStatus
& 0x200) == 0x200) {
128 // Disable SATA controller when it sets to AHCI mode without carrying any devices
129 // in order to prevent AHCI yellow bang under Win device manager.
131 if (SataStorageAmount
== 0) {
132 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
;
133 MmioOr32 (PmcDisableAddress
, B_PCH_PMC_FUNC_DIS_SATA
);
134 S3BootScriptSaveMemWrite (
135 EfiBootScriptWidthUint32
,
136 (UINTN
) PmcDisableAddress
,
138 (VOID
*) (UINTN
) PmcDisableAddress
150 EFI_SMM_ACCESS2_PROTOCOL
*SmmAccess
;
151 EFI_ACPI_S3_SAVE_PROTOCOL
*AcpiS3Save
;
154 // Install DxeSmmReadyToLock protocol prior to the processing of boot options
156 Status
= gBS
->LocateProtocol (
157 &gEfiSmmAccess2ProtocolGuid
,
161 if (!EFI_ERROR (Status
)) {
164 // Prepare S3 information, this MUST be done before DxeSmmReadyToLock
166 Status
= gBS
->LocateProtocol (
167 &gEfiAcpiS3SaveProtocolGuid
,
171 if (!EFI_ERROR (Status
)) {
172 AcpiS3Save
->S3Save (AcpiS3Save
, NULL
);
176 Status
= gBS
->InstallProtocolInterface (
178 &gExitPmAuthProtocolGuid
,
179 EFI_NATIVE_INTERFACE
,
182 ASSERT_EFI_ERROR (Status
);
185 Status
= gBS
->InstallProtocolInterface (
187 &gEfiDxeSmmReadyToLockProtocolGuid
,
188 EFI_NATIVE_INTERFACE
,
191 ASSERT_EFI_ERROR (Status
);
204 BdsSetConsoleMode (TRUE
);
205 DEBUG ((EFI_D_INFO
, "BdsEntry ShellImageCallback \n"));
209 // BDS Platform Functions
212 Platform Bds init. Incude the platform firmware vendor, revision
227 EFI_EVENT ShellImageEvent
;
228 EFI_GUID ShellEnvProtocol
= SHELL_ENVIRONMENT_INTERFACE_PROTOCOL
;
231 SerialPortWrite((UINT8
*)">>>>BdsEntry[GCC]\r\n", 19);
233 SerialPortWrite((UINT8
*)">>>>BdsEntry\r\n", 14);
235 BdsLibSaveMemoryTypeInformation ();
238 // Before user authentication, the user identification devices need be connected
239 // from the platform customized device paths
241 PlatformBdsConnectAuthDevice ();
244 // As console is not ready, the auto logon user will be identified.
246 BdsLibUserIdentify (&mCurrentUser
);
249 // Change Gop mode when boot into Shell
251 if (mShellImageCallbackReg
== NULL
) {
252 Status
= gBS
->CreateEvent (
253 EFI_EVENT_NOTIFY_SIGNAL
,
259 if (!EFI_ERROR (Status
)) {
260 Status
= gBS
->RegisterProtocolNotify (
263 &mShellImageCallbackReg
266 DEBUG ((EFI_D_INFO
, "BdsEntry ShellImageCallback \n"));
273 IN EFI_DEVICE_PATH_PROTOCOL
*PciDevicePath
,
274 OUT EFI_DEVICE_PATH_PROTOCOL
**GopDevicePath
279 EFI_HANDLE PciDeviceHandle
;
280 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
281 EFI_DEVICE_PATH_PROTOCOL
*TempPciDevicePath
;
282 UINTN GopHandleCount
;
283 EFI_HANDLE
*GopHandleBuffer
;
286 SYSTEM_CONFIGURATION mSystemConfiguration
;
288 if (PciDevicePath
== NULL
|| GopDevicePath
== NULL
) {
289 return EFI_INVALID_PARAMETER
;
293 // Initialize the GopDevicePath to be PciDevicePath
295 *GopDevicePath
= PciDevicePath
;
296 TempPciDevicePath
= PciDevicePath
;
298 Status
= gBS
->LocateDevicePath (
299 &gEfiDevicePathProtocolGuid
,
303 if (EFI_ERROR (Status
)) {
308 // Try to connect this handle, so that GOP dirver could start on this
309 // device and create child handles with GraphicsOutput Protocol installed
310 // on them, then we get device paths of these child handles and select
311 // them as possible console device.
315 // Select display devices
317 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
318 Status
= gRT
->GetVariable(
320 &gEfiNormalSetupGuid
,
323 &mSystemConfiguration
325 ASSERT_EFI_ERROR (Status
);
327 if(mSystemConfiguration
.BootDisplayDevice
!= 0x0)
329 ACPI_ADR_DEVICE_PATH AcpiAdr
;
330 EFI_DEVICE_PATH_PROTOCOL
*MyDevicePath
= NULL
;
332 AcpiAdr
.Header
.Type
= ACPI_DEVICE_PATH
;
333 AcpiAdr
.Header
.SubType
= ACPI_ADR_DP
;
335 switch (mSystemConfiguration
.BootDisplayDevice
) {
337 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA
, PORT_CRT
, 0); //CRT Device
340 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL
, PORT_B_HDMI
, 0); //HDMI Device Port B
343 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL
, PORT_B_DP
, 0); //DP PortB
346 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL
, PORT_C_DP
, 0); //DP PortC
349 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL
, PORT_C_DP
, 0); //eDP Port C
352 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL
, PORT_MIPI_A
, 0); //DSI Port A
355 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL
, PORT_MIPI_C
, 0); //DSI Port C
358 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA
, PORT_CRT
, 0);
362 SetDevicePathNodeLength (&AcpiAdr
.Header
, sizeof (ACPI_ADR_DEVICE_PATH
));
364 MyDevicePath
= AppendDevicePathNode(MyDevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&AcpiAdr
);
366 gBS
->ConnectController (
373 FreePool(MyDevicePath
);
377 gBS
->ConnectController (
385 Status
= gBS
->LocateHandleBuffer (
387 &gEfiGraphicsOutputProtocolGuid
,
392 if (!EFI_ERROR (Status
)) {
394 // Add all the child handles as possible Console Device
396 for (Index
= 0; Index
< GopHandleCount
; Index
++) {
397 Status
= gBS
->HandleProtocol (
398 GopHandleBuffer
[Index
],
399 &gEfiDevicePathProtocolGuid
,
400 (VOID
**)&TempDevicePath
402 if (EFI_ERROR (Status
)) {
408 GetDevicePathSize (PciDevicePath
) - END_DEVICE_PATH_LENGTH
411 // In current implementation, we only enable one of the child handles
412 // as console device, i.e. sotre one of the child handle's device
413 // path to variable "ConOut"
414 // In futhure, we could select all child handles to be console device
416 *GopDevicePath
= TempDevicePath
;
419 gBS
->FreePool (GopHandleBuffer
);
427 Search out all the platform pci or agp video device. The function may will
428 find multiple video device, and return all enabled device path.
430 @param PlugInPciVgaDevicePath Return the platform plug in pci video device
431 path if the system have plug in pci video device.
432 @param OnboardPciVgaDevicePath Return the platform active agp video device path
433 if the system have plug in agp video device or on
436 @retval EFI_SUCCSS Get all platform active video device path.
437 @retval EFI_STATUS Return the status of gBS->LocateDevicePath (),
438 gBS->ConnectController (),
439 and gBS->LocateHandleBuffer ().
443 GetPlugInPciVgaDevicePath (
444 IN OUT EFI_DEVICE_PATH_PROTOCOL
**PlugInPciVgaDevicePath
,
445 IN OUT EFI_DEVICE_PATH_PROTOCOL
**OnboardPciVgaDevicePath
449 EFI_HANDLE RootHandle
;
451 EFI_HANDLE
*HandleBuffer
;
454 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
455 BOOLEAN PlugInPciVga
;
456 EFI_PCI_IO_PROTOCOL
*PciIo
;
465 // Make all the PCI_IO protocols on PCI Seg 0 show up
467 BdsLibConnectDevicePath (gPlatformRootBridges
[0]);
469 Status
= gBS
->LocateDevicePath (
470 &gEfiDevicePathProtocolGuid
,
471 &gPlatformRootBridges
[0],
474 if (EFI_ERROR (Status
)) {
478 Status
= gBS
->ConnectController (
484 if (EFI_ERROR (Status
)) {
489 // Start to check all the pci io to find all possible VGA device
493 Status
= gBS
->LocateHandleBuffer (
495 &gEfiPciIoProtocolGuid
,
500 if (EFI_ERROR (Status
)) {
504 for (Index
= 0; Index
< HandleCount
; Index
++) {
505 Status
= gBS
->HandleProtocol (
507 &gEfiPciIoProtocolGuid
,
510 if (!EFI_ERROR (Status
)) {
513 // Check for all VGA device
515 Status
= PciIo
->Pci
.Read (
519 sizeof (Pci
) / sizeof (UINT32
),
522 if (EFI_ERROR (Status
)) {
527 // Here we decide which VGA device to enable in PCI bus
529 // The first plugin PCI VGA card device will be present as PCI VGA
530 // The onchip AGP or AGP card will be present as AGP VGA
532 if (!IS_PCI_VGA (&Pci
)) {
537 // Set the device as the possible console out device,
539 // Below code will make every VGA device to be one
540 // of the possibe console out device
543 gBS
->HandleProtocol (
545 &gEfiDevicePathProtocolGuid
,
551 while (gPlatformAllPossiblePciVgaConsole
[Index1
] != NULL
) {
554 gPlatformAllPossiblePciVgaConsole
[Index1
],
555 GetDevicePathSize (gPlatformAllPossiblePciVgaConsole
[Index1
])
559 // This device is an AGP device
561 *OnboardPciVgaDevicePath
= DevicePath
;
562 PlugInPciVga
= FALSE
;
570 *PlugInPciVgaDevicePath
= DevicePath
;
575 FreePool (HandleBuffer
);
582 Find the platform active vga, and base on the policy to enable the vga as
583 the console out device. The policy is driven by one setup variable "VBIOS".
587 @param EFI_UNSUPPORTED There is no active vga device
589 @retval EFI_STATUS Return the status of BdsLibGetVariableAndSize ()
593 PlatformBdsForceActiveVga (
598 EFI_DEVICE_PATH_PROTOCOL
*PlugInPciVgaDevicePath
;
599 EFI_DEVICE_PATH_PROTOCOL
*OnboardPciVgaDevicePath
;
600 EFI_DEVICE_PATH_PROTOCOL
*DevicePathFirst
;
601 EFI_DEVICE_PATH_PROTOCOL
*DevicePathSecond
;
602 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
604 SYSTEM_CONFIGURATION mSystemConfiguration
;
606 Status
= EFI_SUCCESS
;
607 PlugInPciVgaDevicePath
= NULL
;
608 OnboardPciVgaDevicePath
= NULL
;
611 // Check the policy which is the first enabled VGA
613 GetPlugInPciVgaDevicePath (&PlugInPciVgaDevicePath
, &OnboardPciVgaDevicePath
);
615 if (PlugInPciVgaDevicePath
== NULL
&& OnboardPciVgaDevicePath
== NULL
) {
616 return EFI_UNSUPPORTED
;
619 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
620 Status
= gRT
->GetVariable(
622 &gEfiNormalSetupGuid
,
625 &mSystemConfiguration
627 ASSERT_EFI_ERROR (Status
);
630 if ((PlugInPciVgaDevicePath
== NULL
&& OnboardPciVgaDevicePath
!= NULL
) ) {
631 DEBUG ((EFI_D_ERROR
,"Update onboard PCI VGA ...\n"));
632 DevicePathFirst
= OnboardPciVgaDevicePath
;
633 DevicePathSecond
= PlugInPciVgaDevicePath
;
636 if(OnboardPciVgaDevicePath
!= NULL
&& mSystemConfiguration
.PrimaryVideoAdaptor
== 0) {
637 DEBUG ((EFI_D_ERROR
,"Update onboard PCI VGA When set primary!!!...\n"));
638 DevicePathFirst
= OnboardPciVgaDevicePath
;
639 DevicePathSecond
= PlugInPciVgaDevicePath
;
643 DEBUG ((EFI_D_ERROR
,"Update plug in PCI VGA ...\n"));
644 DevicePathFirst
= PlugInPciVgaDevicePath
;
645 DevicePathSecond
= OnboardPciVgaDevicePath
;
648 GetGopDevicePath (DevicePathFirst
, &GopDevicePath
);
649 DevicePathFirst
= GopDevicePath
;
651 Status
= BdsLibUpdateConsoleVariable (
661 UpdateConsoleResolution(
665 UINT32 HorizontalResolution
;
666 UINT32 VerticalResolution
;
667 SYSTEM_CONFIGURATION SystemConfiguration
;
672 HorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
673 VerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
675 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
676 Status
= gRT
->GetVariable(
678 &gEfiNormalSetupGuid
,
683 ASSERT_EFI_ERROR (Status
);
685 switch (SystemConfiguration
.IgdFlatPanel
) {
689 // Use the detault PCD values.
694 HorizontalResolution
= 640;
695 VerticalResolution
= 480;
699 HorizontalResolution
= 800;
700 VerticalResolution
= 600;
704 HorizontalResolution
= 1024;
705 VerticalResolution
= 768;
709 HorizontalResolution
= 1280;
710 VerticalResolution
= 1024;
714 HorizontalResolution
= 1366;
715 VerticalResolution
= 768;
719 HorizontalResolution
= 1680;
720 VerticalResolution
= 1050;
724 HorizontalResolution
= 1920;
725 VerticalResolution
= 1200;
729 HorizontalResolution
= 1280;
730 VerticalResolution
= 800;
734 PcdSet32 (PcdSetupVideoHorizontalResolution
, HorizontalResolution
);
735 PcdSet32 (PcdSetupVideoVerticalResolution
, VerticalResolution
);
736 DEBUG ((EFI_D_ERROR
, "HorizontalResolution = %x; VerticalResolution = %x", HorizontalResolution
, VerticalResolution
));
742 Connect the predefined platform default console device. Always try to find
743 and enable the vga device if have.
745 @param PlatformConsole Predfined platform default console device array.
747 @retval EFI_SUCCESS Success connect at least one ConIn and ConOut
748 device, there must have one ConOut device is
751 @retval EFI_STATUS Return the status of
752 BdsLibConnectAllDefaultConsoles ()
756 PlatformBdsConnectConsole (
757 IN BDS_CONSOLE_CONNECT_ENTRY
*PlatformConsole
762 EFI_DEVICE_PATH_PROTOCOL
*VarConout
;
763 EFI_DEVICE_PATH_PROTOCOL
*VarConin
;
764 UINTN DevicePathSize
;
766 UpdateConsoleResolution();
769 Status
= EFI_SUCCESS
;
771 VarConout
= BdsLibGetVariableAndSize (
773 &gEfiGlobalVariableGuid
,
776 VarConin
= BdsLibGetVariableAndSize (
778 &gEfiGlobalVariableGuid
,
781 if (VarConout
== NULL
|| VarConin
== NULL
) {
783 // Have chance to connect the platform default console,
784 // the platform default console is the minimue device group
785 // the platform should support
787 while (PlatformConsole
[Index
].DevicePath
!= NULL
) {
790 // Update the console variable with the connect type
792 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
793 BdsLibUpdateConsoleVariable (L
"ConIn", PlatformConsole
[Index
].DevicePath
, NULL
);
796 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
797 BdsLibUpdateConsoleVariable (L
"ConOut", PlatformConsole
[Index
].DevicePath
, NULL
);
800 if ((PlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
801 BdsLibUpdateConsoleVariable (L
"ErrOut", PlatformConsole
[Index
].DevicePath
, NULL
);
809 // Make sure we have at least one active VGA, and have the right
810 // active VGA in console variable
812 Status
= PlatformBdsForceActiveVga ();
813 if (EFI_ERROR (Status
)) {
817 DEBUG ((EFI_D_INFO
, "DISPLAY INIT DONE\n"));
820 // Connect the all the default console with current console variable
822 Status
= BdsLibConnectAllDefaultConsoles ();
823 if (EFI_ERROR (Status
)) {
831 Connect with predeined platform connect sequence,
832 the OEM/IBV can customize with their own connect sequence.
840 PlatformBdsConnectSequence (
849 // Here we can get the customized platform connect sequence
850 // Notes: we can connect with new variable which record the
851 // last time boots connect device path sequence
853 while (gPlatformConnectSequence
[Index
] != NULL
) {
856 // Build the platform boot option
858 BdsLibConnectDevicePath (gPlatformConnectSequence
[Index
]);
863 // Just use the simple policy to connect all devices
864 // There should be no difference between debug tip and release tip, or it will be extremely hard to debug.
866 // There is case that IdeController driver will write boot script in driver model Start() function. It will be rejected by boot script save.
867 // It is only found when DEBUG disabled, because we are using BdsLibConnectAll() when DEBUG enabled.
869 // So we use BdsLibConnectAll() here to make sure IdeController.Start() is invoked before InstallReadyToLock().
870 // We may also consider to connect SataController only later if needed.
877 Load the predefined driver option, OEM/IBV can customize this
878 to load their own drivers
880 @param BdsDriverLists The header of the driver option link list.
886 PlatformBdsGetDriverOption (
887 IN OUT LIST_ENTRY
*BdsDriverLists
895 // Here we can get the customized platform driver option
897 while (gPlatformDriverOption
[Index
] != NULL
) {
900 // Build the platform boot option
902 BdsLibRegisterNewOption (BdsDriverLists
, gPlatformDriverOption
[Index
], NULL
, L
"DriverOrder");
909 This function is used for some critical time if the the system
910 have no any boot option, and there is no time out for user to add
911 the new boot option. This can also treat as the platform default
914 @param BdsBootOptionList The header of the boot option link list.
920 PlatformBdsPredictBootOption (
921 IN OUT LIST_ENTRY
*BdsBootOptionList
929 // Here give chance to get platform boot option data
931 while (gPlatformBootOption
[Index
] != NULL
) {
934 // Build the platform boot option
936 BdsLibRegisterNewOption (BdsBootOptionList
, gPlatformBootOption
[Index
], NULL
, L
"BootOrder");
942 Perform the platform diagnostic, such like test memory. OEM/IBV also
943 can customize this fuction to support specific platform diagnostic.
945 @param MemoryTestLevel The memory test intensive level
946 @param QuietBoot Indicate if need to enable the quiet boot
947 @param BaseMemoryTest A pointer to BdsMemoryTest()
953 PlatformBdsDiagnostics (
954 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel
,
955 IN BOOLEAN QuietBoot
,
956 IN BASEM_MEMORY_TEST BaseMemoryTest
962 // Here we can decide if we need to show
963 // the diagnostics screen
964 // Notes: this quiet boot code should be remove
965 // from the graphic lib
968 EnableQuietBoot (PcdGetPtr(PcdLogoFile
));
971 // Perform system diagnostic
973 Status
= BaseMemoryTest (MemoryTestLevel
);
974 if (EFI_ERROR (Status
)) {
982 // Perform system diagnostic
984 Status
= BaseMemoryTest (MemoryTestLevel
);
989 For EFI boot option, BDS separate them as six types:
990 1. Network - The boot option points to the SimpleNetworkProtocol device.
991 Bds will try to automatically create this type boot option when enumerate.
992 2. Shell - The boot option points to internal flash shell.
993 Bds will try to automatically create this type boot option when enumerate.
994 3. Removable BlockIo - The boot option only points to the removable media
995 device, like USB flash disk, DVD, Floppy etc.
996 These device should contain a *removable* blockIo
997 protocol in their device handle.
998 Bds will try to automatically create this type boot option
1000 4. Fixed BlockIo - The boot option only points to a Fixed blockIo device,
1002 These device should contain a *fixed* blockIo
1003 protocol in their device handle.
1004 BDS will skip fixed blockIo devices, and NOT
1005 automatically create boot option for them. But BDS
1006 will help to delete those fixed blockIo boot option,
1007 whose description rule conflict with other auto-created
1009 5. Non-BlockIo Simplefile - The boot option points to a device whose handle
1010 has SimpleFileSystem Protocol, but has no blockio
1011 protocol. These devices do not offer blockIo
1012 protocol, but BDS still can get the
1013 \EFI\BOOT\boot{machinename}.EFI by SimpleFileSystem
1015 6. File - The boot option points to a file. These boot options are usually
1016 created by user manually or OS loader. BDS will not delete or modify
1019 This function will enumerate all possible boot device in the system, and
1020 automatically create boot options for Network, Shell, Removable BlockIo,
1021 and Non-BlockIo Simplefile devices.
1022 It will only execute once of every boot.
1024 @param BdsBootOptionList The header of the link list which indexed all
1025 current boot options
1027 @retval EFI_SUCCESS Finished all the boot device enumerate and create
1028 the boot option base on that boot device
1030 @retval EFI_OUT_OF_RESOURCES Failed to enumerate the boot device and create the boot option list
1034 PlatformBdsLibEnumerateAllBootOption (
1035 IN OUT LIST_ENTRY
*BdsBootOptionList
1039 UINT16 FloppyNumber
;
1040 UINT16 HarddriveNumber
;
1045 UINT16 NonBlockNumber
;
1046 UINTN NumberBlockIoHandles
;
1047 EFI_HANDLE
*BlockIoHandles
;
1048 EFI_BLOCK_IO_PROTOCOL
*BlkIo
;
1049 BOOLEAN Removable
[2];
1050 UINTN RemovableIndex
;
1052 UINTN NumOfLoadFileHandles
;
1053 EFI_HANDLE
*LoadFileHandles
;
1054 UINTN FvHandleCount
;
1055 EFI_HANDLE
*FvHandleBuffer
;
1056 EFI_FV_FILETYPE Type
;
1058 EFI_FV_FILE_ATTRIBUTES Attributes
;
1059 UINT32 AuthenticationStatus
;
1060 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
1061 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1062 UINTN DevicePathType
;
1064 EFI_HANDLE
*FileSystemHandles
;
1065 UINTN NumberFileSystemHandles
;
1067 EFI_IMAGE_DOS_HEADER DosHeader
;
1070 EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData
;
1071 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
;
1074 EFI_HANDLE
*NetworkHandles
;
1078 HarddriveNumber
= 0;
1085 ZeroMem (Buffer
, sizeof (Buffer
));
1088 // If the boot device enumerate happened, just get the boot
1089 // device from the boot order variable
1091 if (mEnumBootDevice
) {
1092 GetVariable2 (LAST_ENUM_LANGUAGE_VARIABLE_NAME
, &gLastEnumLangGuid
, (VOID
**)&LastLang
, NULL
);
1093 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&PlatLang
, NULL
);
1094 ASSERT (PlatLang
!= NULL
);
1095 if ((LastLang
!= NULL
) && (AsciiStrCmp (LastLang
, PlatLang
) == 0)) {
1096 Status
= BdsLibBuildOptionFromVar (BdsBootOptionList
, L
"BootOrder");
1097 FreePool (LastLang
);
1098 FreePool (PlatLang
);
1101 Status
= gRT
->SetVariable (
1102 LAST_ENUM_LANGUAGE_VARIABLE_NAME
,
1104 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1105 AsciiStrSize (PlatLang
),
1109 // Failure to set the variable only impacts the performance next time enumerating the boot options.
1112 if (LastLang
!= NULL
) {
1113 FreePool (LastLang
);
1115 FreePool (PlatLang
);
1120 // Notes: this dirty code is to get the legacy boot option from the
1121 // BBS table and create to variable as the EFI boot option, it should
1122 // be removed after the CSM can provide legacy boot option directly
1124 REFRESH_LEGACY_BOOT_OPTIONS
;
1127 // Delete invalid boot option
1129 BdsDeleteAllInvalidEfiBootOption ();
1132 // Parse removable media followed by fixed media.
1133 // The Removable[] array is used by the for-loop below to create removable media boot options
1134 // at first, and then to create fixed media boot options.
1136 Removable
[0] = FALSE
;
1137 Removable
[1] = TRUE
;
1139 gBS
->LocateHandleBuffer (
1141 &gEfiBlockIoProtocolGuid
,
1143 &NumberBlockIoHandles
,
1147 for (RemovableIndex
= 0; RemovableIndex
< 2; RemovableIndex
++) {
1148 for (Index
= 0; Index
< NumberBlockIoHandles
; Index
++) {
1149 Status
= gBS
->HandleProtocol (
1150 BlockIoHandles
[Index
],
1151 &gEfiBlockIoProtocolGuid
,
1155 // skip the logical partition
1157 if (EFI_ERROR (Status
) || BlkIo
->Media
->LogicalPartition
) {
1162 // firstly fixed block io then the removable block io
1164 if (BlkIo
->Media
->RemovableMedia
== Removable
[RemovableIndex
]) {
1167 DevicePath
= DevicePathFromHandle (BlockIoHandles
[Index
]);
1168 DevicePathType
= BdsGetBootTypeFromDevicePath (DevicePath
);
1170 switch (DevicePathType
) {
1171 case BDS_EFI_ACPI_FLOPPY_BOOT
:
1172 if (FloppyNumber
!= 0) {
1173 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY
)), FloppyNumber
);
1175 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY
)));
1177 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1182 // Assume a removable SATA device should be the DVD/CD device, a fixed SATA device should be the Hard Drive device.
1184 case BDS_EFI_MESSAGE_ATAPI_BOOT
:
1185 case BDS_EFI_MESSAGE_SATA_BOOT
:
1186 if (BlkIo
->Media
->RemovableMedia
) {
1187 if (CdromNumber
!= 0) {
1188 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD
)), CdromNumber
);
1190 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD
)));
1194 if (HarddriveNumber
!= 0) {
1195 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE
)), HarddriveNumber
);
1197 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE
)));
1201 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "Buffer: %S\n", Buffer
));
1202 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1205 case BDS_EFI_MESSAGE_USB_DEVICE_BOOT
:
1206 if (UsbNumber
!= 0) {
1207 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB
)), UsbNumber
);
1209 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB
)));
1211 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1215 case BDS_EFI_MESSAGE_SCSI_BOOT
:
1216 if (ScsiNumber
!= 0) {
1217 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI
)), ScsiNumber
);
1219 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI
)));
1221 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1225 case BDS_EFI_MESSAGE_MISC_BOOT
:
1227 if (MiscNumber
!= 0) {
1228 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC
)), MiscNumber
);
1230 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC
)));
1232 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1239 if (NumberBlockIoHandles
!= 0) {
1240 FreePool (BlockIoHandles
);
1244 // If there is simple file protocol which does not consume block Io protocol, create a boot option for it here.
1247 gBS
->LocateHandleBuffer (
1249 &gEfiSimpleFileSystemProtocolGuid
,
1251 &NumberFileSystemHandles
,
1254 for (Index
= 0; Index
< NumberFileSystemHandles
; Index
++) {
1255 Status
= gBS
->HandleProtocol (
1256 FileSystemHandles
[Index
],
1257 &gEfiBlockIoProtocolGuid
,
1260 if (!EFI_ERROR (Status
)) {
1262 // Skip if the file system handle supports a BlkIo protocol,
1268 // Do the removable Media thing. \EFI\BOOT\boot{machinename}.EFI
1269 // machinename is ia32, ia64, x64, ...
1271 Hdr
.Union
= &HdrData
;
1273 Status
= BdsLibGetImageHeader (
1274 FileSystemHandles
[Index
],
1275 EFI_REMOVABLE_MEDIA_FILE_NAME
,
1279 if (!EFI_ERROR (Status
) &&
1280 EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr
.Pe32
->FileHeader
.Machine
) &&
1281 Hdr
.Pe32
->OptionalHeader
.Subsystem
== EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION
) {
1287 // No such file or the file is not a EFI application, delete this boot option
1289 BdsLibDeleteOptionFromHandle (FileSystemHandles
[Index
]);
1291 if (NonBlockNumber
!= 0) {
1292 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK
)), NonBlockNumber
);
1294 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK
)));
1296 BdsLibBuildOptionFromHandle (FileSystemHandles
[Index
], BdsBootOptionList
, Buffer
);
1301 if (NumberFileSystemHandles
!= 0) {
1302 FreePool (FileSystemHandles
);
1306 // Check if we have on flash shell
1308 gBS
->LocateHandleBuffer (
1310 &gEfiFirmwareVolume2ProtocolGuid
,
1315 for (Index
= 0; Index
< FvHandleCount
; Index
++) {
1316 gBS
->HandleProtocol (
1317 FvHandleBuffer
[Index
],
1318 &gEfiFirmwareVolume2ProtocolGuid
,
1322 Status
= Fv
->ReadFile (
1324 PcdGetPtr(PcdShellFile
),
1329 &AuthenticationStatus
1331 if (EFI_ERROR (Status
)) {
1333 // Skip if no shell file in the FV
1338 // Build the shell boot option
1340 BdsLibBuildOptionFromShell (FvHandleBuffer
[Index
], BdsBootOptionList
);
1343 if (FvHandleCount
!= 0) {
1344 FreePool (FvHandleBuffer
);
1348 // Parse Network Boot Device
1350 NumOfLoadFileHandles
= 0;
1352 // Search Load File protocol for PXE boot option.
1354 gBS
->LocateHandleBuffer (
1356 &gEfiLoadFileProtocolGuid
,
1358 &NumOfLoadFileHandles
,
1362 for (Index
= 0; Index
< NumOfLoadFileHandles
; Index
++) {
1365 //Locate EFI_DEVICE_PATH_PROTOCOL to dynamically get IPv4/IPv6 protocol information.
1368 Status
= gBS
->HandleProtocol (
1369 LoadFileHandles
[Index
],
1370 &gEfiDevicePathProtocolGuid
,
1371 (VOID
**) &DevicePath
1374 ASSERT_EFI_ERROR (Status
);
1376 while (!IsDevicePathEnd (DevicePath
)) {
1377 if ((DevicePath
->Type
== MESSAGING_DEVICE_PATH
) &&
1378 (DevicePath
->SubType
== MSG_IPv4_DP
)) {
1381 //Get handle infomation
1384 NetworkHandles
= NULL
;
1385 Status
= gBS
->LocateHandle (
1387 &gEfiSimpleNetworkProtocolGuid
,
1393 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1394 NetworkHandles
= AllocateZeroPool(BufferSize
);
1395 if (NetworkHandles
== NULL
) {
1396 return (EFI_OUT_OF_RESOURCES
);
1398 Status
= gBS
->LocateHandle(
1400 &gEfiSimpleNetworkProtocolGuid
,
1408 //Get the MAC string
1410 Status
= NetLibGetMacString (
1415 if (EFI_ERROR (Status
)) {
1418 IPverStr
= L
" IPv4";
1419 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK
)),MacStr
,IPverStr
);
1422 if((DevicePath
->Type
== MESSAGING_DEVICE_PATH
) &&
1423 (DevicePath
->SubType
== MSG_IPv6_DP
)) {
1426 //Get handle infomation
1429 NetworkHandles
= NULL
;
1430 Status
= gBS
->LocateHandle (
1432 &gEfiSimpleNetworkProtocolGuid
,
1438 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1439 NetworkHandles
= AllocateZeroPool(BufferSize
);
1440 if (NetworkHandles
== NULL
) {
1441 return (EFI_OUT_OF_RESOURCES
);
1443 Status
= gBS
->LocateHandle(
1445 &gEfiSimpleNetworkProtocolGuid
,
1453 //Get the MAC string
1455 Status
= NetLibGetMacString (
1460 if (EFI_ERROR (Status
)) {
1463 IPverStr
= L
" IPv6";
1464 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK
)),MacStr
,IPverStr
);
1467 DevicePath
= NextDevicePathNode (DevicePath
);
1470 BdsLibBuildOptionFromHandle (LoadFileHandles
[Index
], BdsBootOptionList
, Buffer
);
1473 if (NumOfLoadFileHandles
!= 0) {
1474 FreePool (LoadFileHandles
);
1478 // Check if we have on flash shell
1480 /* gBS->LocateHandleBuffer (
1482 &gEfiFirmwareVolume2ProtocolGuid,
1487 for (Index = 0; Index < FvHandleCount; Index++) {
1488 gBS->HandleProtocol (
1489 FvHandleBuffer[Index],
1490 &gEfiFirmwareVolume2ProtocolGuid,
1494 Status = Fv->ReadFile (
1496 PcdGetPtr(PcdShellFile),
1501 &AuthenticationStatus
1503 if (EFI_ERROR (Status)) {
1505 // Skip if no shell file in the FV
1510 // Build the shell boot option
1512 BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList);
1515 if (FvHandleCount != 0) {
1516 FreePool (FvHandleBuffer);
1520 // Make sure every boot only have one time
1521 // boot device enumerate
1523 Status
= BdsLibBuildOptionFromVar (BdsBootOptionList
, L
"BootOrder");
1524 mEnumBootDevice
= TRUE
;
1533 The function will excute with as the platform policy, current policy
1534 is driven by boot mode. IBV/OEM can customize this code for their specific
1537 @param DriverOptionList - The header of the driver option link list
1538 @param BootOptionList - The header of the boot option link list
1539 @param ProcessCapsules - A pointer to ProcessCapsules()
1540 @param BaseMemoryTest - A pointer to BaseMemoryTest()
1547 PlatformBdsPolicyBehavior (
1548 IN OUT LIST_ENTRY
*DriverOptionList
,
1549 IN OUT LIST_ENTRY
*BootOptionList
,
1550 IN PROCESS_CAPSULES ProcessCapsules
,
1551 IN BASEM_MEMORY_TEST BaseMemoryTest
1556 EFI_BOOT_MODE BootMode
;
1557 BOOLEAN DeferredImageExist
;
1559 CHAR16 CapsuleVarName
[36];
1560 CHAR16
*TempVarName
;
1561 SYSTEM_CONFIGURATION SystemConfiguration
;
1563 BOOLEAN SetVariableFlag
;
1564 PLATFORM_PCI_DEVICE_PATH
*EmmcBootDevPath
;
1565 EFI_GLOBAL_NVS_AREA_PROTOCOL
*GlobalNvsArea
;
1566 EFI_HANDLE FvProtocolHandle
;
1568 EFI_HANDLE
*HandleBuffer
;
1570 UINTN SataPciRegBase
= 0;
1571 UINT16 SataModeSelect
= 0;
1572 VOID
*RegistrationExitPmAuth
= NULL
;
1574 BOOLEAN IsFirstBoot
;
1576 UINTN BootOrderSize
;
1578 Timeout
= PcdGet16 (PcdPlatformBootTimeOut
);
1579 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
1580 Status
= gRT
->GetVariable(
1582 &gEfiNormalSetupGuid
,
1585 &SystemConfiguration
1587 if (EFI_ERROR (Status
)) {
1592 // Load the driver option as the driver option list
1594 PlatformBdsGetDriverOption (DriverOptionList
);
1597 // Get current Boot Mode
1599 BootMode
= GetBootModeHob();
1602 // Clear all the capsule variables CapsuleUpdateData, CapsuleUpdateData1, CapsuleUpdateData2...
1603 // as early as possible which will avoid the next time boot after the capsule update
1604 // will still into the capsule loop
1606 StrCpy (CapsuleVarName
, EFI_CAPSULE_VARIABLE_NAME
);
1607 TempVarName
= CapsuleVarName
+ StrLen (CapsuleVarName
);
1609 SetVariableFlag
= TRUE
;
1610 while (SetVariableFlag
) {
1612 UnicodeValueToString (TempVarName
, 0, Index
, 0);
1614 Status
= gRT
->SetVariable (
1616 &gEfiCapsuleVendorGuid
,
1617 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_RUNTIME_ACCESS
|
1618 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1622 if (EFI_ERROR (Status
)) {
1624 // There is no capsule variables, quit
1626 SetVariableFlag
= FALSE
;
1633 // No deferred images exist by default
1635 DeferredImageExist
= FALSE
;
1636 if ((BootMode
!= BOOT_WITH_MINIMAL_CONFIGURATION
) && (PcdGet32(PcdFlashFvShellSize
) > 0)){
1637 gDS
->ProcessFirmwareVolume (
1638 (VOID
*)(UINTN
)PcdGet32(PcdFlashFvShellBase
),
1639 PcdGet32(PcdFlashFvShellSize
),
1644 if (SystemConfiguration
.FastBoot
== 1) {
1645 BootOrder
= BdsLibGetVariableAndSize (
1647 &gEfiGlobalVariableGuid
,
1650 if ((BootOrder
!= NULL
) && (BootMode
!= BOOT_ON_FLASH_UPDATE
)) {
1652 // BootOrder exist, it means system has boot before. We can do fast boot.
1654 BootMode
= BOOT_WITH_MINIMAL_CONFIGURATION
;
1660 // Use eMMC to boot OS and turn on AHCI, when SATA HDD is diconnected,
1661 // SATA AHCI CTLR device will show yellow bang, implement this solution to solve it.
1663 SataPciRegBase
= MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA
, 0, 0);
1664 SataModeSelect
= MmioRead16 (SataPciRegBase
+ R_PCH_SATA_MAP
) & B_PCH_SATA_MAP_SMS_MASK
;
1665 Status
= EFI_SUCCESS
;
1666 if (SataModeSelect
!= V_PCH_SATA_MAP_SMS_IDE
) {
1667 Status
= gBS
->CreateEvent (
1674 if (!EFI_ERROR (Status
)) {
1675 Status
= gBS
->RegisterProtocolNotify (
1676 &gExitPmAuthProtocolGuid
,
1678 &RegistrationExitPmAuth
1685 case BOOT_WITH_MINIMAL_CONFIGURATION
:
1686 PlatformBdsInitHotKeyEvent ();
1687 PlatformBdsConnectSimpleConsole (gPlatformSimpleConsole
);
1691 // Check to see if it's needed to dispatch more DXE drivers.
1693 for (Index
= 0; Index
< sizeof(ConnectDriverTable
)/sizeof(EFI_GUID
*); Index
++) {
1694 Status
= gBS
->LocateHandleBuffer (
1696 ConnectDriverTable
[Index
],
1701 if (!EFI_ERROR (Status
)) {
1702 for (Index1
= 0; Index1
< HandleCount
; Index1
++) {
1703 gBS
->ConnectController (
1704 HandleBuffer
[Index1
],
1712 if (HandleBuffer
!= NULL
) {
1713 FreePool (HandleBuffer
);
1720 // Locate the Global NVS Protocol.
1722 Status
= gBS
->LocateProtocol (
1723 &gEfiGlobalNvsAreaProtocolGuid
,
1725 (void **)&GlobalNvsArea
1727 if (GlobalNvsArea
->Area
->emmcVersion
== 0){
1728 EmmcBootDevPath
= (PLATFORM_PCI_DEVICE_PATH
*)gPlatformSimpleBootOption
[0];
1729 EmmcBootDevPath
->PciDevice
.Device
= 0x10;
1733 // Connect boot device here to give time to read keyboard.
1735 BdsLibConnectDevicePath (gPlatformSimpleBootOption
[0]);
1738 // This is a workround for dectecting hotkey from USB keyboard.
1740 gBS
->Stall(KEYBOARD_TIMER_INTERVAL
);
1742 if (mHotKeyTimerEvent
!= NULL
) {
1748 gBS
->CloseEvent (mHotKeyTimerEvent
);
1749 mHotKeyTimerEvent
= NULL
;
1751 if (mHotKeyPressed
) {
1753 // Skip show progress count down
1756 goto FULL_CONFIGURATION
;
1759 if (SystemConfiguration
.QuietBoot
) {
1760 EnableQuietBoot (PcdGetPtr(PcdLogoFile
));
1762 PlatformBdsDiagnostics (IGNORE
, FALSE
, BaseMemoryTest
);
1767 TcgPhysicalPresenceLibProcessRequest();
1770 TrEEPhysicalPresenceLibProcessRequest(NULL
);
1773 // Close boot script and install ready to lock
1775 InstallReadyToLock ();
1778 // Give one chance to enter the setup if we
1779 // select Gummiboot "Reboot Into Firmware Interface" and Fast Boot is enabled.
1781 BootIntoFirmwareInterface();
1784 case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES
:
1787 // In no-configuration boot mode, we can connect the
1788 // console directly.
1790 BdsLibConnectAllDefaultConsoles ();
1791 PlatformBdsDiagnostics (IGNORE
, TRUE
, BaseMemoryTest
);
1794 // Perform some platform specific connect sequence
1796 PlatformBdsConnectSequence ();
1799 // As console is ready, perform user identification again.
1801 if (mCurrentUser
== NULL
) {
1802 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1803 if (DeferredImageExist
) {
1805 // After user authentication, the deferred drivers was loaded again.
1806 // Here, need to ensure the deferred images are connected.
1808 BdsLibConnectAllDefaultConsoles ();
1809 PlatformBdsConnectSequence ();
1814 // Close boot script and install ready to lock
1816 InstallReadyToLock ();
1819 // Notes: current time out = 0 can not enter the
1822 PlatformBdsEnterFrontPageWithHotKey (Timeout
, FALSE
);
1825 // Check the boot option with the boot option list
1827 BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
1830 case BOOT_ON_FLASH_UPDATE
:
1833 // Boot with the specific configuration
1835 PlatformBdsConnectConsole (gPlatformConsole
);
1836 PlatformBdsDiagnostics (EXTENSIVE
, FALSE
, BaseMemoryTest
);
1837 BdsLibConnectAll ();
1840 // Perform user identification
1842 if (mCurrentUser
== NULL
) {
1843 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1844 if (DeferredImageExist
) {
1846 // After user authentication, the deferred drivers was loaded again.
1847 // Here, need to ensure the deferred images are connected.
1849 BdsLibConnectAll ();
1854 // Close boot script and install ready to lock
1856 InstallReadyToLock ();
1858 ProcessCapsules (BOOT_ON_FLASH_UPDATE
);
1861 case BOOT_IN_RECOVERY_MODE
:
1864 // In recovery mode, just connect platform console
1865 // and show up the front page
1867 PlatformBdsConnectConsole (gPlatformConsole
);
1868 PlatformBdsDiagnostics (EXTENSIVE
, FALSE
, BaseMemoryTest
);
1869 BdsLibConnectAll ();
1872 // Perform user identification
1874 if (mCurrentUser
== NULL
) {
1875 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1876 if (DeferredImageExist
) {
1878 // After user authentication, the deferred drivers was loaded again.
1879 // Here, need to ensure the deferred drivers are connected.
1881 BdsLibConnectAll ();
1886 // Close boot script and install ready to lock
1888 InstallReadyToLock ();
1891 // In recovery boot mode, we still enter to the
1894 PlatformBdsEnterFrontPageWithHotKey (Timeout
, FALSE
);
1898 case BOOT_WITH_FULL_CONFIGURATION
:
1899 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS
:
1900 case BOOT_WITH_DEFAULT_SETTINGS
:
1904 // Connect platform console
1906 Status
= PlatformBdsConnectConsole (gPlatformConsole
);
1907 if (EFI_ERROR (Status
)) {
1910 // Here OEM/IBV can customize with defined action
1912 PlatformBdsNoConsoleAction ();
1916 // Chenyunh[TODO]: This is Workgroud to show the fs for uSDcard,
1917 // Need to root cause this issue.
1919 DEBUG ((DEBUG_ERROR
, "Start to reconnect all driver.\n"));
1920 BdsLibDisconnectAllEfi();
1921 BdsLibConnectAll ();
1922 DEBUG ((DEBUG_ERROR
, "End to reconnect all driver.\n"));
1925 // Perform some platform specific connect sequence
1927 PlatformBdsConnectSequence ();
1928 if (SystemConfiguration
.QuietBoot
) {
1929 EnableQuietBoot (PcdGetPtr(PcdLogoFile
));
1931 PlatformBdsDiagnostics (IGNORE
, FALSE
, BaseMemoryTest
);
1935 // Do a pre-delay so Hard Disk can spin up and see more logo.
1937 gBS
->Stall(SystemConfiguration
.HddPredelay
* 1000000);
1940 // Perform user identification
1942 if (mCurrentUser
== NULL
) {
1943 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1944 if (DeferredImageExist
) {
1946 // After user authentication, the deferred drivers was loaded again.
1947 // Here, need to ensure the deferred drivers are connected.
1949 Status
= PlatformBdsConnectConsole (gPlatformConsole
);
1950 if (EFI_ERROR (Status
)) {
1951 PlatformBdsNoConsoleAction ();
1953 PlatformBdsConnectSequence ();
1957 TcgPhysicalPresenceLibProcessRequest();
1960 TrEEPhysicalPresenceLibProcessRequest(NULL
);
1963 // Close boot script and install ready to lock
1965 InstallReadyToLock ();
1968 // Here we have enough time to do the enumeration of boot device
1970 PlatformBdsLibEnumerateAllBootOption (BootOptionList
);
1973 // Give one chance to enter the setup if we
1974 // have the time out
1976 PlatformBdsEnterFrontPageWithHotKey (Timeout
, FALSE
);
1979 // Give one chance to enter the setup if we
1980 // select Gummiboot "Reboot Into Firmware Interface"
1982 BootIntoFirmwareInterface();
1985 // In default boot mode, always find all boot
1986 // option and do enumerate all the default boot option
1989 BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
1990 if (IsListEmpty(BootOptionList
)) {
1991 PlatformBdsPredictBootOption (BootOptionList
);
2002 IsFirstBoot
= PcdGetBool(PcdBootState
);
2004 PcdSetBool(PcdBootState
, FALSE
);
2011 Hook point after a boot attempt succeeds. We don't expect a boot option to
2012 return, so the UEFI 2.0 specification defines that you will default to an
2013 interactive mode and stop processing the BootOrder list in this case. This
2014 is alos a platform implementation and can be customized by IBV/OEM.
2016 @param Option Pointer to Boot Option that succeeded to boot.
2023 PlatformBdsBootSuccess (
2024 IN BDS_COMMON_OPTION
*Option
2030 // If Boot returned with EFI_SUCCESS and there is not in the boot device
2031 // select loop then we need to pop up a UI and wait for user input.
2033 TmpStr
= Option
->StatusString
;
2034 if (TmpStr
!= NULL
) {
2035 BdsLibOutputStrings (gST
->ConOut
, TmpStr
, Option
->Description
, L
"\n\r", NULL
);
2041 Hook point after a boot attempt fails.
2043 @param Option - Pointer to Boot Option that failed to boot.
2044 @param Status - Status returned from failed boot.
2045 @param ExitData - Exit data returned from failed boot.
2046 @param ExitDataSize - Exit data size returned from failed boot.
2053 PlatformBdsBootFail (
2054 IN BDS_COMMON_OPTION
*Option
,
2055 IN EFI_STATUS Status
,
2056 IN CHAR16
*ExitData
,
2057 IN UINTN ExitDataSize
2061 EFI_HANDLE FvProtocolHandle
;
2064 // If Boot returned with failed status then we need to pop up a UI and wait
2067 TmpStr
= Option
->StatusString
;
2068 if (TmpStr
!= NULL
) {
2069 BdsLibOutputStrings (gST
->ConOut
, TmpStr
, Option
->Description
, L
"\n\r", NULL
);
2072 if (PcdGet32(PcdFlashFvShellSize
) > 0){
2073 gDS
->ProcessFirmwareVolume (
2074 (VOID
*)(UINTN
)PcdGet32(PcdFlashFvShellBase
),
2075 PcdGet32(PcdFlashFvShellSize
),
2079 PlatformBdsConnectSequence ();
2083 This function is remained for IBV/OEM to do some platform action,
2084 if there no console device can be connected.
2088 @retval EFI_SUCCESS Direct return success now.
2092 PlatformBdsNoConsoleAction (
2100 This function locks the block
2102 @param Base The base address flash region to be locked.
2107 IN EFI_PHYSICAL_ADDRESS Base
2110 EFI_FV_BLOCK_MAP_ENTRY
*BlockMap
;
2111 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
2112 EFI_PHYSICAL_ADDRESS BaseAddress
;
2117 BaseAddress
= Base
- 0x400000 + 2;
2118 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) ((UINTN
) (Base
));
2119 BlockMap
= &(FvHeader
->BlockMap
[0]);
2121 while ((BlockMap
->NumBlocks
!= 0) && (BlockMap
->Length
!= 0)) {
2122 BlockLength
= BlockMap
->Length
;
2123 for (Index
= 0; Index
< BlockMap
->NumBlocks
; Index
++) {
2124 Data
= MmioOr8 ((UINTN
) BaseAddress
, 0x03);
2125 BaseAddress
+= BlockLength
;
2133 PlatformBdsLockNonUpdatableFlash (
2137 EFI_PHYSICAL_ADDRESS Base
;
2139 Base
= (EFI_PHYSICAL_ADDRESS
) PcdGet32 (PcdFlashFvMainBase
);
2144 Base
= (EFI_PHYSICAL_ADDRESS
) PcdGet32 (PcdFlashFvRecoveryBase
);
2151 Lock the ConsoleIn device in system table. All key
2152 presses will be ignored until the Password is typed in. The only way to
2153 disable the password is to type it in to a ConIn device.
2155 @param Password Password used to lock ConIn device.
2157 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
2158 @retval EFI_UNSUPPORTED Password not found
2167 return EFI_UNSUPPORTED
;
2171 Connect the predefined platform default authentication devices.
2173 This function connects the predefined device path for authentication device,
2174 and if the predefined device path has child device path, the child handle will
2175 be connected too. But the child handle of the child will not be connected.
2180 PlatformBdsConnectAuthDevice (
2188 EFI_HANDLE
*HandleBuffer
;
2189 EFI_DEVICE_PATH_PROTOCOL
*ChildDevicePath
;
2190 EFI_USER_MANAGER_PROTOCOL
*Manager
;
2192 Status
= gBS
->LocateProtocol (
2193 &gEfiUserManagerProtocolGuid
,
2197 if (EFI_ERROR (Status
)) {
2199 // As user manager protocol is not installed, the authentication devices
2200 // should not be connected.
2206 while (gUserAuthenticationDevice
[Index
] != NULL
) {
2208 // Connect the platform customized device paths
2210 BdsLibConnectDevicePath (gUserAuthenticationDevice
[Index
]);
2215 // Find and connect the child device paths of the platform customized device paths
2217 HandleBuffer
= NULL
;
2218 for (Index
= 0; gUserAuthenticationDevice
[Index
] != NULL
; Index
++) {
2220 Status
= gBS
->LocateHandleBuffer (
2227 ASSERT (!EFI_ERROR (Status
));
2230 // Find and connect the child device paths of gUserIdentificationDevice[Index]
2232 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
2233 ChildDevicePath
= NULL
;
2234 Status
= gBS
->HandleProtocol (
2235 HandleBuffer
[HandleIndex
],
2236 &gEfiDevicePathProtocolGuid
,
2237 (VOID
**) &ChildDevicePath
2239 if (EFI_ERROR (Status
) || ChildDevicePath
== NULL
) {
2245 gUserAuthenticationDevice
[Index
],
2246 (GetDevicePathSize (gUserAuthenticationDevice
[Index
]) - sizeof (EFI_DEVICE_PATH_PROTOCOL
))
2250 gBS
->ConnectController (
2251 HandleBuffer
[HandleIndex
],
2259 if (HandleBuffer
!= NULL
) {
2260 FreePool (HandleBuffer
);
2265 This function is to identify a user, and return whether deferred images exist.
2267 @param[out] User Point to user profile handle.
2268 @param[out] DeferredImageExist On return, points to TRUE if the deferred image
2269 exist or FALSE if it did not exist.
2274 PlatformBdsUserIdentify (
2275 OUT EFI_USER_PROFILE_HANDLE
*User
,
2276 OUT BOOLEAN
*DeferredImageExist
2280 EFI_DEFERRED_IMAGE_LOAD_PROTOCOL
*DeferredImage
;
2282 EFI_HANDLE
*HandleBuf
;
2285 EFI_DEVICE_PATH_PROTOCOL
*ImageDevicePath
;
2291 // Perform user identification
2294 Status
= BdsLibUserIdentify (User
);
2295 } while (EFI_ERROR (Status
));
2298 // After user authentication now, try to find whether deferred image exists
2302 *DeferredImageExist
= FALSE
;
2303 Status
= gBS
->LocateHandleBuffer (
2305 &gEfiDeferredImageLoadProtocolGuid
,
2310 if (EFI_ERROR (Status
)) {
2314 for (Index
= 0; Index
< HandleCount
; Index
++) {
2315 Status
= gBS
->HandleProtocol (
2317 &gEfiDeferredImageLoadProtocolGuid
,
2318 (VOID
**) &DeferredImage
2320 if (!EFI_ERROR (Status
)) {
2322 // Find whether deferred image exists in this instance.
2325 Status
= DeferredImage
->GetImageInfo(
2329 (VOID
**) &DriverImage
,
2333 if (!EFI_ERROR (Status
)) {
2335 // The deferred image is found.
2337 FreePool (HandleBuf
);
2338 *DeferredImageExist
= TRUE
;
2344 FreePool (HandleBuf
);
2351 ShowProgressHotKey (
2352 IN UINT16 TimeoutDefault
2356 UINT16 TimeoutRemain
;
2359 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
2360 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
2361 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
2364 if (TimeoutDefault
== 0) {
2368 gST
->ConOut
->SetAttribute(gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
2370 if (DebugAssertEnabled())
2372 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"));
2377 SerialPortWrite((UINT8
*)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)[GCC]", 76);
2379 SerialPortWrite((UINT8
*)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)", 71);
2382 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
2383 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
2384 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
2387 // Clear the progress status bar first
2389 TmpStr
= L
"Start boot option, Press <F2> or <DEL> to enter setup page.";
2390 PlatformBdsShowProgress (Foreground
, Background
, TmpStr
, Color
, 0, 0);
2392 TimeoutRemain
= TimeoutDefault
;
2393 while (TimeoutRemain
!= 0) {
2394 if (DebugAssertEnabled())
2396 DEBUG ((EFI_D_INFO
, "Showing progress bar...Remaining %d second!\n", TimeoutRemain
));
2400 SerialPortWrite ((UINT8
*)".", 1);
2402 Status
= WaitForSingleEvent (gST
->ConIn
->WaitForKey
, ONE_SECOND
);
2403 if (Status
!= EFI_TIMEOUT
) {
2411 if (TmpStr
!= NULL
) {
2412 PlatformBdsShowProgress (
2417 ((TimeoutDefault
- TimeoutRemain
) * 100 / TimeoutDefault
),
2426 if (TimeoutRemain
== 0) {
2427 if (DebugAssertEnabled())
2432 SerialPortWrite ((UINT8
*)"\r\n", 2);
2438 // User pressed some key
2440 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2441 if (EFI_ERROR (Status
)) {
2446 // Check Volume Up Key to enter Setup
2448 GpioValue
= MmioRead32 (IO_BASE_ADDRESS
+ 0x0668); // The value of GPIOC_5
2449 if (((GpioValue
& BIT0
) == 0) && (Key
.ScanCode
== SCAN_UP
)) {
2454 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
2456 // User pressed enter, equivalent to select "continue"
2463 //F5 -- Device Manager
2464 //F7 -- Boot Manager
2465 // do not use F8. generally people assume it is windows safe mode key.
2468 DEBUG ((EFI_D_INFO
, "[Key Pressed]: ScanCode 0x%x\n", Key
.ScanCode
));
2469 switch(Key
.ScanCode
) {
2479 gHotKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
2483 gHotKey
= FRONT_PAGE_KEY_BOOT_MANAGER
;
2487 gHotKey
= FRONT_PAGE_KEY_BOOT_MAINTAIN
;
2491 //set gHotKey to continue so that flow will not go into CallFrontPage
2492 gHotKey
= FRONT_PAGE_KEY_CONTINUE
;
2503 This function is the main entry of the platform setup entry.
2504 The function will present the main menu of the system setup,
2505 this is the platform reference part and can be customize.
2508 @param TimeoutDefault The fault time out value before the system
2510 @param ConnectAllHappened The indicater to check if the connect all have
2515 PlatformBdsEnterFrontPageWithHotKey (
2516 IN UINT16 TimeoutDefault
,
2517 IN BOOLEAN ConnectAllHappened
2522 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
2523 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
2524 UINTN BootTextColumn
;
2527 GraphicsOutput
= NULL
;
2528 SimpleTextOut
= NULL
;
2530 PERF_START (NULL
, "BdsTimeOut", "BDS", 0);
2533 // Indicate if we need connect all in the platform setup
2535 if (ConnectAllHappened
) {
2536 gConnectAllHappened
= TRUE
;
2539 if (!mModeInitialized
) {
2541 // After the console is ready, get current video resolution
2542 // and text mode before launching setup at first time.
2544 Status
= gBS
->HandleProtocol (
2545 gST
->ConsoleOutHandle
,
2546 &gEfiGraphicsOutputProtocolGuid
,
2547 (VOID
**)&GraphicsOutput
2549 if (EFI_ERROR (Status
)) {
2550 GraphicsOutput
= NULL
;
2553 Status
= gBS
->HandleProtocol (
2554 gST
->ConsoleOutHandle
,
2555 &gEfiSimpleTextOutProtocolGuid
,
2556 (VOID
**)&SimpleTextOut
2558 if (EFI_ERROR (Status
)) {
2559 SimpleTextOut
= NULL
;
2562 if (GraphicsOutput
!= NULL
) {
2564 // Get current video resolution and text mode.
2566 mBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
2567 mBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
2570 if (SimpleTextOut
!= NULL
) {
2571 Status
= SimpleTextOut
->QueryMode (
2573 SimpleTextOut
->Mode
->Mode
,
2577 mBootTextModeColumn
= (UINT32
)BootTextColumn
;
2578 mBootTextModeRow
= (UINT32
)BootTextRow
;
2582 // Get user defined text mode for setup.
2584 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
2585 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
2586 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
2587 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
2589 mModeInitialized
= TRUE
;
2592 if (TimeoutDefault
!= 0xffff) {
2593 Status
= ShowProgressHotKey (TimeoutDefault
);
2596 // Ensure screen is clear when switch Console from Graphics mode to Text mode
2598 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
2599 gST
->ConOut
->ClearScreen (gST
->ConOut
);
2601 if (EFI_ERROR (Status
)) {
2603 // Timeout or user press enter to continue
2609 // Install BM HiiPackages.
2610 // Keep BootMaint HiiPackage, so that it can be covered by global setting.
2615 BdsSetConsoleMode (TRUE
);
2617 InitializeFrontPage (FALSE
);
2620 // Update Front Page strings
2622 UpdateFrontPageStrings ();
2624 Status
= EFI_SUCCESS
;
2627 Status
= CallFrontPage ();
2629 gCallbackKey
= gHotKey
;
2634 // If gCallbackKey is greater than 1 and less or equal to 5,
2635 // it will launch configuration utilities.
2638 // 4 = device manager
2639 // 5 = boot maintenance manager
2641 if (gCallbackKey
!= 0) {
2642 REPORT_STATUS_CODE (
2644 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
2649 // Based on the key that was set, we can determine what to do
2651 switch (gCallbackKey
) {
2653 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
2654 // describe to their customers in documentation how to find their setup information (namely
2655 // under the device manager and specific buckets)
2657 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager
2659 case FRONT_PAGE_KEY_CONTINUE
:
2662 // User hit continue
2666 case FRONT_PAGE_KEY_LANGUAGE
:
2669 // User made a language setting change - display front page again
2673 case FRONT_PAGE_KEY_BOOT_MANAGER
:
2675 // Remove the installed BootMaint HiiPackages when exit.
2680 // User chose to run the Boot Manager
2685 // Reinstall BootMaint HiiPackages after exiting from Boot Manager.
2690 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
2693 // Display the Device Manager
2696 CallDeviceManager ();
2697 } while (gCallbackKey
== FRONT_PAGE_KEY_DEVICE_MANAGER
);
2700 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
2703 // Display the Boot Maintenance Manager
2705 BdsStartBootMaint ();
2709 } while (((UINTN
)gCallbackKey
) != FRONT_PAGE_KEY_CONTINUE
);
2712 //Will leave browser, check any reset required change is applied? if yes, reset system
2714 SetupResetReminder ();
2716 // Remove the installed BootMaint HiiPackages when exit.
2722 // Automatically load current entry
2723 // Note: The following lines of code only execute when Auto boot
2726 PERF_END (NULL
, "BdsTimeOut", "BDS", 0);
2731 BootIntoFirmwareInterface(
2738 UINT64 OsIndication
;
2742 DataSize
= sizeof(UINT64
);
2743 Status
= gRT
->GetVariable (
2745 &gEfiGlobalVariableGuid
,
2751 DEBUG ((EFI_D_INFO
, "OSIndication Variable Value %d\n", OsIndication
));
2753 //Goto FrontPage directly when bit EFI_OS_INDICATIONS_BOOT_TO_FW_UI in OSIndication Variable is setted.
2755 if (!EFI_ERROR(Status
) && (OsIndication
!= 0)) {
2757 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
2763 PlatformBdsConnectSimpleConsole (
2764 IN BDS_CONSOLE_CONNECT_ENTRY
*PlatformConsole
2769 EFI_DEVICE_PATH_PROTOCOL
*VarConout
;
2770 EFI_DEVICE_PATH_PROTOCOL
*VarConin
;
2771 UINTN DevicePathSize
;
2775 Status
= EFI_SUCCESS
;
2777 VarConout
= BdsLibGetVariableAndSize (
2779 &gEfiGlobalVariableGuid
,
2782 VarConin
= BdsLibGetVariableAndSize (
2784 &gEfiGlobalVariableGuid
,
2787 if (VarConout
== NULL
|| VarConin
== NULL
) {
2789 // Have chance to connect the platform default console,
2790 // the platform default console is the minimue device group
2791 // the platform should support
2793 while (PlatformConsole
[Index
].DevicePath
!= NULL
) {
2796 // Update the console variable with the connect type
2798 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
2799 BdsLibUpdateConsoleVariable (L
"ConIn", PlatformConsole
[Index
].DevicePath
, NULL
);
2802 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
2803 BdsLibUpdateConsoleVariable (L
"ConOut", PlatformConsole
[Index
].DevicePath
, NULL
);
2806 if ((PlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
2807 BdsLibUpdateConsoleVariable (L
"ErrOut", PlatformConsole
[Index
].DevicePath
, NULL
);
2815 // Connect ConIn first to give keyboard time to parse hot key event.
2817 Status
= BdsLibConnectConsoleVariable (L
"ConIn");
2818 if (EFI_ERROR (Status
)) {
2823 // Make sure we have at least one active VGA, and have the right
2824 // active VGA in console variable
2826 Status
= PlatformBdsForceActiveVga ();
2829 // It seems impossible not to have any ConOut device on platform,
2830 // so we check the status here.
2832 Status
= BdsLibConnectConsoleVariable (L
"ConOut");
2833 if (EFI_ERROR (Status
)) {
2842 Timer handler to convert the key from USB.
2844 @param Event Indicates the event that invoke this function.
2845 @param Context Indicates the calling context.
2849 HotKeyTimerHandler (
2857 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2858 if (EFI_ERROR (Status
)) {
2862 switch(Key
.ScanCode
) {
2865 mHotKeyPressed
= TRUE
;
2869 gHotKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
2870 mHotKeyPressed
= TRUE
;
2874 gHotKey
= FRONT_PAGE_KEY_BOOT_MANAGER
;
2875 mHotKeyPressed
= TRUE
;
2879 gHotKey
= FRONT_PAGE_KEY_BOOT_MAINTAIN
;
2880 mHotKeyPressed
= TRUE
;
2884 if (mHotKeyPressed
) {
2890 gBS
->CloseEvent (mHotKeyTimerEvent
);
2891 mHotKeyTimerEvent
= NULL
;
2899 Callback function for SimpleTextInEx protocol install events
2901 @param Event the event that is signaled.
2902 @param Context not used here.
2914 Status
= gBS
->CloseEvent(mHitHotkeyEvent
);
2915 if (EFI_ERROR (Status
)) {
2918 Status
= gBS
->CreateEvent (
2919 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
2925 if (EFI_ERROR (Status
)) {
2928 Status
= gBS
->SetTimer (
2931 KEYBOARD_TIMER_INTERVAL
2933 if (EFI_ERROR (Status
)) {
2943 PlatformBdsInitHotKeyEvent (
2950 // Register Protocol notify for Hotkey service
2952 Status
= gBS
->CreateEvent (
2959 ASSERT_EFI_ERROR (Status
);
2962 // Register for protocol notifications on this event
2964 Status
= gBS
->RegisterProtocolNotify (
2965 &gEfiSimpleTextInputExProtocolGuid
,
2967 &mHitHotkeyRegistration
2969 ASSERT_EFI_ERROR (Status
);