3 Copyright (c) 2004 - 2014, 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();
1771 // Close boot script and install ready to lock
1773 InstallReadyToLock ();
1776 // Give one chance to enter the setup if we
1777 // select Gummiboot "Reboot Into Firmware Interface" and Fast Boot is enabled.
1779 BootIntoFirmwareInterface();
1782 case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES
:
1785 // In no-configuration boot mode, we can connect the
1786 // console directly.
1788 BdsLibConnectAllDefaultConsoles ();
1789 PlatformBdsDiagnostics (IGNORE
, TRUE
, BaseMemoryTest
);
1792 // Perform some platform specific connect sequence
1794 PlatformBdsConnectSequence ();
1797 // As console is ready, perform user identification again.
1799 if (mCurrentUser
== NULL
) {
1800 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1801 if (DeferredImageExist
) {
1803 // After user authentication, the deferred drivers was loaded again.
1804 // Here, need to ensure the deferred images are connected.
1806 BdsLibConnectAllDefaultConsoles ();
1807 PlatformBdsConnectSequence ();
1812 // Close boot script and install ready to lock
1814 InstallReadyToLock ();
1817 // Notes: current time out = 0 can not enter the
1820 PlatformBdsEnterFrontPageWithHotKey (Timeout
, FALSE
);
1823 // Check the boot option with the boot option list
1825 BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
1828 case BOOT_ON_FLASH_UPDATE
:
1831 // Boot with the specific configuration
1833 PlatformBdsConnectConsole (gPlatformConsole
);
1834 PlatformBdsDiagnostics (EXTENSIVE
, FALSE
, BaseMemoryTest
);
1835 BdsLibConnectAll ();
1838 // Perform user identification
1840 if (mCurrentUser
== NULL
) {
1841 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1842 if (DeferredImageExist
) {
1844 // After user authentication, the deferred drivers was loaded again.
1845 // Here, need to ensure the deferred images are connected.
1847 BdsLibConnectAll ();
1852 // Close boot script and install ready to lock
1854 InstallReadyToLock ();
1856 ProcessCapsules (BOOT_ON_FLASH_UPDATE
);
1859 case BOOT_IN_RECOVERY_MODE
:
1862 // In recovery mode, just connect platform console
1863 // and show up the front page
1865 PlatformBdsConnectConsole (gPlatformConsole
);
1866 PlatformBdsDiagnostics (EXTENSIVE
, FALSE
, BaseMemoryTest
);
1867 BdsLibConnectAll ();
1870 // Perform user identification
1872 if (mCurrentUser
== NULL
) {
1873 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1874 if (DeferredImageExist
) {
1876 // After user authentication, the deferred drivers was loaded again.
1877 // Here, need to ensure the deferred drivers are connected.
1879 BdsLibConnectAll ();
1884 // Close boot script and install ready to lock
1886 InstallReadyToLock ();
1889 // In recovery boot mode, we still enter to the
1892 PlatformBdsEnterFrontPageWithHotKey (Timeout
, FALSE
);
1896 case BOOT_WITH_FULL_CONFIGURATION
:
1897 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS
:
1898 case BOOT_WITH_DEFAULT_SETTINGS
:
1902 // Connect platform console
1904 Status
= PlatformBdsConnectConsole (gPlatformConsole
);
1905 if (EFI_ERROR (Status
)) {
1908 // Here OEM/IBV can customize with defined action
1910 PlatformBdsNoConsoleAction ();
1914 // Chenyunh[TODO]: This is Workgroud to show the fs for uSDcard,
1915 // Need to root cause this issue.
1917 DEBUG ((DEBUG_ERROR
, "Start to reconnect all driver.\n"));
1918 BdsLibDisconnectAllEfi();
1919 BdsLibConnectAll ();
1920 DEBUG ((DEBUG_ERROR
, "End to reconnect all driver.\n"));
1923 // Perform some platform specific connect sequence
1925 PlatformBdsConnectSequence ();
1926 if (SystemConfiguration
.QuietBoot
) {
1927 EnableQuietBoot (PcdGetPtr(PcdLogoFile
));
1929 PlatformBdsDiagnostics (IGNORE
, FALSE
, BaseMemoryTest
);
1933 // Do a pre-delay so Hard Disk can spin up and see more logo.
1935 gBS
->Stall(SystemConfiguration
.HddPredelay
* 1000000);
1938 // Perform user identification
1940 if (mCurrentUser
== NULL
) {
1941 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1942 if (DeferredImageExist
) {
1944 // After user authentication, the deferred drivers was loaded again.
1945 // Here, need to ensure the deferred drivers are connected.
1947 Status
= PlatformBdsConnectConsole (gPlatformConsole
);
1948 if (EFI_ERROR (Status
)) {
1949 PlatformBdsNoConsoleAction ();
1951 PlatformBdsConnectSequence ();
1955 TcgPhysicalPresenceLibProcessRequest();
1959 // Close boot script and install ready to lock
1961 InstallReadyToLock ();
1964 // Here we have enough time to do the enumeration of boot device
1966 PlatformBdsLibEnumerateAllBootOption (BootOptionList
);
1969 // Give one chance to enter the setup if we
1970 // have the time out
1972 PlatformBdsEnterFrontPageWithHotKey (Timeout
, FALSE
);
1975 // Give one chance to enter the setup if we
1976 // select Gummiboot "Reboot Into Firmware Interface"
1978 BootIntoFirmwareInterface();
1981 // In default boot mode, always find all boot
1982 // option and do enumerate all the default boot option
1985 BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
1986 if (IsListEmpty(BootOptionList
)) {
1987 PlatformBdsPredictBootOption (BootOptionList
);
1998 IsFirstBoot
= PcdGetBool(PcdBootState
);
2000 PcdSetBool(PcdBootState
, FALSE
);
2007 Hook point after a boot attempt succeeds. We don't expect a boot option to
2008 return, so the UEFI 2.0 specification defines that you will default to an
2009 interactive mode and stop processing the BootOrder list in this case. This
2010 is alos a platform implementation and can be customized by IBV/OEM.
2012 @param Option Pointer to Boot Option that succeeded to boot.
2019 PlatformBdsBootSuccess (
2020 IN BDS_COMMON_OPTION
*Option
2026 // If Boot returned with EFI_SUCCESS and there is not in the boot device
2027 // select loop then we need to pop up a UI and wait for user input.
2029 TmpStr
= Option
->StatusString
;
2030 if (TmpStr
!= NULL
) {
2031 BdsLibOutputStrings (gST
->ConOut
, TmpStr
, Option
->Description
, L
"\n\r", NULL
);
2037 Hook point after a boot attempt fails.
2039 @param Option - Pointer to Boot Option that failed to boot.
2040 @param Status - Status returned from failed boot.
2041 @param ExitData - Exit data returned from failed boot.
2042 @param ExitDataSize - Exit data size returned from failed boot.
2049 PlatformBdsBootFail (
2050 IN BDS_COMMON_OPTION
*Option
,
2051 IN EFI_STATUS Status
,
2052 IN CHAR16
*ExitData
,
2053 IN UINTN ExitDataSize
2057 EFI_HANDLE FvProtocolHandle
;
2060 // If Boot returned with failed status then we need to pop up a UI and wait
2063 TmpStr
= Option
->StatusString
;
2064 if (TmpStr
!= NULL
) {
2065 BdsLibOutputStrings (gST
->ConOut
, TmpStr
, Option
->Description
, L
"\n\r", NULL
);
2068 if (PcdGet32(PcdFlashFvShellSize
) > 0){
2069 gDS
->ProcessFirmwareVolume (
2070 (VOID
*)(UINTN
)PcdGet32(PcdFlashFvShellBase
),
2071 PcdGet32(PcdFlashFvShellSize
),
2075 PlatformBdsConnectSequence ();
2079 This function is remained for IBV/OEM to do some platform action,
2080 if there no console device can be connected.
2084 @retval EFI_SUCCESS Direct return success now.
2088 PlatformBdsNoConsoleAction (
2096 This function locks the block
2098 @param Base The base address flash region to be locked.
2103 IN EFI_PHYSICAL_ADDRESS Base
2106 EFI_FV_BLOCK_MAP_ENTRY
*BlockMap
;
2107 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
2108 EFI_PHYSICAL_ADDRESS BaseAddress
;
2113 BaseAddress
= Base
- 0x400000 + 2;
2114 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) ((UINTN
) (Base
));
2115 BlockMap
= &(FvHeader
->BlockMap
[0]);
2117 while ((BlockMap
->NumBlocks
!= 0) && (BlockMap
->Length
!= 0)) {
2118 BlockLength
= BlockMap
->Length
;
2119 for (Index
= 0; Index
< BlockMap
->NumBlocks
; Index
++) {
2120 Data
= MmioOr8 ((UINTN
) BaseAddress
, 0x03);
2121 BaseAddress
+= BlockLength
;
2129 PlatformBdsLockNonUpdatableFlash (
2133 EFI_PHYSICAL_ADDRESS Base
;
2135 Base
= (EFI_PHYSICAL_ADDRESS
) PcdGet32 (PcdFlashFvMainBase
);
2140 Base
= (EFI_PHYSICAL_ADDRESS
) PcdGet32 (PcdFlashFvRecoveryBase
);
2147 Lock the ConsoleIn device in system table. All key
2148 presses will be ignored until the Password is typed in. The only way to
2149 disable the password is to type it in to a ConIn device.
2151 @param Password Password used to lock ConIn device.
2153 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
2154 @retval EFI_UNSUPPORTED Password not found
2163 return EFI_UNSUPPORTED
;
2167 Connect the predefined platform default authentication devices.
2169 This function connects the predefined device path for authentication device,
2170 and if the predefined device path has child device path, the child handle will
2171 be connected too. But the child handle of the child will not be connected.
2176 PlatformBdsConnectAuthDevice (
2184 EFI_HANDLE
*HandleBuffer
;
2185 EFI_DEVICE_PATH_PROTOCOL
*ChildDevicePath
;
2186 EFI_USER_MANAGER_PROTOCOL
*Manager
;
2188 Status
= gBS
->LocateProtocol (
2189 &gEfiUserManagerProtocolGuid
,
2193 if (EFI_ERROR (Status
)) {
2195 // As user manager protocol is not installed, the authentication devices
2196 // should not be connected.
2202 while (gUserAuthenticationDevice
[Index
] != NULL
) {
2204 // Connect the platform customized device paths
2206 BdsLibConnectDevicePath (gUserAuthenticationDevice
[Index
]);
2211 // Find and connect the child device paths of the platform customized device paths
2213 HandleBuffer
= NULL
;
2214 for (Index
= 0; gUserAuthenticationDevice
[Index
] != NULL
; Index
++) {
2216 Status
= gBS
->LocateHandleBuffer (
2223 ASSERT (!EFI_ERROR (Status
));
2226 // Find and connect the child device paths of gUserIdentificationDevice[Index]
2228 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
2229 ChildDevicePath
= NULL
;
2230 Status
= gBS
->HandleProtocol (
2231 HandleBuffer
[HandleIndex
],
2232 &gEfiDevicePathProtocolGuid
,
2233 (VOID
**) &ChildDevicePath
2235 if (EFI_ERROR (Status
) || ChildDevicePath
== NULL
) {
2241 gUserAuthenticationDevice
[Index
],
2242 (GetDevicePathSize (gUserAuthenticationDevice
[Index
]) - sizeof (EFI_DEVICE_PATH_PROTOCOL
))
2246 gBS
->ConnectController (
2247 HandleBuffer
[HandleIndex
],
2255 if (HandleBuffer
!= NULL
) {
2256 FreePool (HandleBuffer
);
2261 This function is to identify a user, and return whether deferred images exist.
2263 @param[out] User Point to user profile handle.
2264 @param[out] DeferredImageExist On return, points to TRUE if the deferred image
2265 exist or FALSE if it did not exist.
2270 PlatformBdsUserIdentify (
2271 OUT EFI_USER_PROFILE_HANDLE
*User
,
2272 OUT BOOLEAN
*DeferredImageExist
2276 EFI_DEFERRED_IMAGE_LOAD_PROTOCOL
*DeferredImage
;
2278 EFI_HANDLE
*HandleBuf
;
2281 EFI_DEVICE_PATH_PROTOCOL
*ImageDevicePath
;
2287 // Perform user identification
2290 Status
= BdsLibUserIdentify (User
);
2291 } while (EFI_ERROR (Status
));
2294 // After user authentication now, try to find whether deferred image exists
2298 *DeferredImageExist
= FALSE
;
2299 Status
= gBS
->LocateHandleBuffer (
2301 &gEfiDeferredImageLoadProtocolGuid
,
2306 if (EFI_ERROR (Status
)) {
2310 for (Index
= 0; Index
< HandleCount
; Index
++) {
2311 Status
= gBS
->HandleProtocol (
2313 &gEfiDeferredImageLoadProtocolGuid
,
2314 (VOID
**) &DeferredImage
2316 if (!EFI_ERROR (Status
)) {
2318 // Find whether deferred image exists in this instance.
2321 Status
= DeferredImage
->GetImageInfo(
2325 (VOID
**) &DriverImage
,
2329 if (!EFI_ERROR (Status
)) {
2331 // The deferred image is found.
2333 FreePool (HandleBuf
);
2334 *DeferredImageExist
= TRUE
;
2340 FreePool (HandleBuf
);
2347 ShowProgressHotKey (
2348 IN UINT16 TimeoutDefault
2352 UINT16 TimeoutRemain
;
2355 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
2356 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
2357 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
2360 if (TimeoutDefault
== 0) {
2364 gST
->ConOut
->SetAttribute(gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
2366 if (DebugAssertEnabled())
2368 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"));
2373 SerialPortWrite((UINT8
*)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)[GCC]", 76);
2375 SerialPortWrite((UINT8
*)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)", 71);
2378 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
2379 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
2380 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
2383 // Clear the progress status bar first
2385 TmpStr
= L
"Start boot option, Press <F2> or <DEL> to enter setup page.";
2386 PlatformBdsShowProgress (Foreground
, Background
, TmpStr
, Color
, 0, 0);
2388 TimeoutRemain
= TimeoutDefault
;
2389 while (TimeoutRemain
!= 0) {
2390 if (DebugAssertEnabled())
2392 DEBUG ((EFI_D_INFO
, "Showing progress bar...Remaining %d second!\n", TimeoutRemain
));
2396 SerialPortWrite ((UINT8
*)".", 1);
2398 Status
= WaitForSingleEvent (gST
->ConIn
->WaitForKey
, ONE_SECOND
);
2399 if (Status
!= EFI_TIMEOUT
) {
2407 if (TmpStr
!= NULL
) {
2408 PlatformBdsShowProgress (
2413 ((TimeoutDefault
- TimeoutRemain
) * 100 / TimeoutDefault
),
2422 if (TimeoutRemain
== 0) {
2423 if (DebugAssertEnabled())
2428 SerialPortWrite ((UINT8
*)"\r\n", 2);
2434 // User pressed some key
2436 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2437 if (EFI_ERROR (Status
)) {
2442 // Check Volume Up Key to enter Setup
2444 GpioValue
= MmioRead32 (IO_BASE_ADDRESS
+ 0x0668); // The value of GPIOC_5
2445 if (((GpioValue
& BIT0
) == 0) && (Key
.ScanCode
== SCAN_UP
)) {
2450 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
2452 // User pressed enter, equivalent to select "continue"
2459 //F5 -- Device Manager
2460 //F7 -- Boot Manager
2461 // do not use F8. generally people assume it is windows safe mode key.
2464 DEBUG ((EFI_D_INFO
, "[Key Pressed]: ScanCode 0x%x\n", Key
.ScanCode
));
2465 switch(Key
.ScanCode
) {
2475 gHotKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
2479 gHotKey
= FRONT_PAGE_KEY_BOOT_MANAGER
;
2483 gHotKey
= FRONT_PAGE_KEY_BOOT_MAINTAIN
;
2487 //set gHotKey to continue so that flow will not go into CallFrontPage
2488 gHotKey
= FRONT_PAGE_KEY_CONTINUE
;
2499 This function is the main entry of the platform setup entry.
2500 The function will present the main menu of the system setup,
2501 this is the platform reference part and can be customize.
2504 @param TimeoutDefault The fault time out value before the system
2506 @param ConnectAllHappened The indicater to check if the connect all have
2511 PlatformBdsEnterFrontPageWithHotKey (
2512 IN UINT16 TimeoutDefault
,
2513 IN BOOLEAN ConnectAllHappened
2518 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
2519 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
2520 UINTN BootTextColumn
;
2523 GraphicsOutput
= NULL
;
2524 SimpleTextOut
= NULL
;
2526 PERF_START (NULL
, "BdsTimeOut", "BDS", 0);
2529 // Indicate if we need connect all in the platform setup
2531 if (ConnectAllHappened
) {
2532 gConnectAllHappened
= TRUE
;
2535 if (!mModeInitialized
) {
2537 // After the console is ready, get current video resolution
2538 // and text mode before launching setup at first time.
2540 Status
= gBS
->HandleProtocol (
2541 gST
->ConsoleOutHandle
,
2542 &gEfiGraphicsOutputProtocolGuid
,
2543 (VOID
**)&GraphicsOutput
2545 if (EFI_ERROR (Status
)) {
2546 GraphicsOutput
= NULL
;
2549 Status
= gBS
->HandleProtocol (
2550 gST
->ConsoleOutHandle
,
2551 &gEfiSimpleTextOutProtocolGuid
,
2552 (VOID
**)&SimpleTextOut
2554 if (EFI_ERROR (Status
)) {
2555 SimpleTextOut
= NULL
;
2558 if (GraphicsOutput
!= NULL
) {
2560 // Get current video resolution and text mode.
2562 mBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
2563 mBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
2566 if (SimpleTextOut
!= NULL
) {
2567 Status
= SimpleTextOut
->QueryMode (
2569 SimpleTextOut
->Mode
->Mode
,
2573 mBootTextModeColumn
= (UINT32
)BootTextColumn
;
2574 mBootTextModeRow
= (UINT32
)BootTextRow
;
2578 // Get user defined text mode for setup.
2580 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
2581 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
2582 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
2583 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
2585 mModeInitialized
= TRUE
;
2588 if (TimeoutDefault
!= 0xffff) {
2589 Status
= ShowProgressHotKey (TimeoutDefault
);
2592 // Ensure screen is clear when switch Console from Graphics mode to Text mode
2594 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
2595 gST
->ConOut
->ClearScreen (gST
->ConOut
);
2597 if (EFI_ERROR (Status
)) {
2599 // Timeout or user press enter to continue
2605 // Install BM HiiPackages.
2606 // Keep BootMaint HiiPackage, so that it can be covered by global setting.
2611 BdsSetConsoleMode (TRUE
);
2613 InitializeFrontPage (FALSE
);
2616 // Update Front Page strings
2618 UpdateFrontPageStrings ();
2620 Status
= EFI_SUCCESS
;
2623 Status
= CallFrontPage ();
2625 gCallbackKey
= gHotKey
;
2630 // If gCallbackKey is greater than 1 and less or equal to 5,
2631 // it will launch configuration utilities.
2634 // 4 = device manager
2635 // 5 = boot maintenance manager
2637 if (gCallbackKey
!= 0) {
2638 REPORT_STATUS_CODE (
2640 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
2645 // Based on the key that was set, we can determine what to do
2647 switch (gCallbackKey
) {
2649 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
2650 // describe to their customers in documentation how to find their setup information (namely
2651 // under the device manager and specific buckets)
2653 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager
2655 case FRONT_PAGE_KEY_CONTINUE
:
2658 // User hit continue
2662 case FRONT_PAGE_KEY_LANGUAGE
:
2665 // User made a language setting change - display front page again
2669 case FRONT_PAGE_KEY_BOOT_MANAGER
:
2671 // Remove the installed BootMaint HiiPackages when exit.
2676 // User chose to run the Boot Manager
2681 // Reinstall BootMaint HiiPackages after exiting from Boot Manager.
2686 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
2689 // Display the Device Manager
2692 CallDeviceManager ();
2693 } while (gCallbackKey
== FRONT_PAGE_KEY_DEVICE_MANAGER
);
2696 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
2699 // Display the Boot Maintenance Manager
2701 BdsStartBootMaint ();
2705 } while (((UINTN
)gCallbackKey
) != FRONT_PAGE_KEY_CONTINUE
);
2708 //Will leave browser, check any reset required change is applied? if yes, reset system
2710 SetupResetReminder ();
2712 // Remove the installed BootMaint HiiPackages when exit.
2718 // Automatically load current entry
2719 // Note: The following lines of code only execute when Auto boot
2722 PERF_END (NULL
, "BdsTimeOut", "BDS", 0);
2727 BootIntoFirmwareInterface(
2734 UINT64 OsIndication
;
2738 DataSize
= sizeof(UINT64
);
2739 Status
= gRT
->GetVariable (
2741 &gEfiGlobalVariableGuid
,
2747 DEBUG ((EFI_D_INFO
, "OSIndication Variable Value %d\n", OsIndication
));
2749 //Goto FrontPage directly when bit EFI_OS_INDICATIONS_BOOT_TO_FW_UI in OSIndication Variable is setted.
2751 if (!EFI_ERROR(Status
) && (OsIndication
!= 0)) {
2753 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
2759 PlatformBdsConnectSimpleConsole (
2760 IN BDS_CONSOLE_CONNECT_ENTRY
*PlatformConsole
2765 EFI_DEVICE_PATH_PROTOCOL
*VarConout
;
2766 EFI_DEVICE_PATH_PROTOCOL
*VarConin
;
2767 UINTN DevicePathSize
;
2771 Status
= EFI_SUCCESS
;
2773 VarConout
= BdsLibGetVariableAndSize (
2775 &gEfiGlobalVariableGuid
,
2778 VarConin
= BdsLibGetVariableAndSize (
2780 &gEfiGlobalVariableGuid
,
2783 if (VarConout
== NULL
|| VarConin
== NULL
) {
2785 // Have chance to connect the platform default console,
2786 // the platform default console is the minimue device group
2787 // the platform should support
2789 while (PlatformConsole
[Index
].DevicePath
!= NULL
) {
2792 // Update the console variable with the connect type
2794 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
2795 BdsLibUpdateConsoleVariable (L
"ConIn", PlatformConsole
[Index
].DevicePath
, NULL
);
2798 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
2799 BdsLibUpdateConsoleVariable (L
"ConOut", PlatformConsole
[Index
].DevicePath
, NULL
);
2802 if ((PlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
2803 BdsLibUpdateConsoleVariable (L
"ErrOut", PlatformConsole
[Index
].DevicePath
, NULL
);
2811 // Connect ConIn first to give keyboard time to parse hot key event.
2813 Status
= BdsLibConnectConsoleVariable (L
"ConIn");
2814 if (EFI_ERROR (Status
)) {
2819 // Make sure we have at least one active VGA, and have the right
2820 // active VGA in console variable
2822 Status
= PlatformBdsForceActiveVga ();
2825 // It seems impossible not to have any ConOut device on platform,
2826 // so we check the status here.
2828 Status
= BdsLibConnectConsoleVariable (L
"ConOut");
2829 if (EFI_ERROR (Status
)) {
2838 Timer handler to convert the key from USB.
2840 @param Event Indicates the event that invoke this function.
2841 @param Context Indicates the calling context.
2845 HotKeyTimerHandler (
2853 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2854 if (EFI_ERROR (Status
)) {
2858 switch(Key
.ScanCode
) {
2861 mHotKeyPressed
= TRUE
;
2865 gHotKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
2866 mHotKeyPressed
= TRUE
;
2870 gHotKey
= FRONT_PAGE_KEY_BOOT_MANAGER
;
2871 mHotKeyPressed
= TRUE
;
2875 gHotKey
= FRONT_PAGE_KEY_BOOT_MAINTAIN
;
2876 mHotKeyPressed
= TRUE
;
2880 if (mHotKeyPressed
) {
2886 gBS
->CloseEvent (mHotKeyTimerEvent
);
2887 mHotKeyTimerEvent
= NULL
;
2895 Callback function for SimpleTextInEx protocol install events
2897 @param Event the event that is signaled.
2898 @param Context not used here.
2910 Status
= gBS
->CloseEvent(mHitHotkeyEvent
);
2911 if (EFI_ERROR (Status
)) {
2914 Status
= gBS
->CreateEvent (
2915 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
2921 if (EFI_ERROR (Status
)) {
2924 Status
= gBS
->SetTimer (
2927 KEYBOARD_TIMER_INTERVAL
2929 if (EFI_ERROR (Status
)) {
2939 PlatformBdsInitHotKeyEvent (
2946 // Register Protocol notify for Hotkey service
2948 Status
= gBS
->CreateEvent (
2955 ASSERT_EFI_ERROR (Status
);
2958 // Register for protocol notifications on this event
2960 Status
= gBS
->RegisterProtocolNotify (
2961 &gEfiSimpleTextInputExProtocolGuid
,
2963 &mHitHotkeyRegistration
2965 ASSERT_EFI_ERROR (Status
);