3 Copyright (c) 2004 - 2016, 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 // Signal EndOfDxe PI Event
233 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid
);
236 SerialPortWrite((UINT8
*)">>>>BdsEntry[GCC]\r\n", 19);
238 SerialPortWrite((UINT8
*)">>>>BdsEntry\r\n", 14);
240 BdsLibSaveMemoryTypeInformation ();
243 // Before user authentication, the user identification devices need be connected
244 // from the platform customized device paths
246 PlatformBdsConnectAuthDevice ();
249 // As console is not ready, the auto logon user will be identified.
251 BdsLibUserIdentify (&mCurrentUser
);
254 // Change Gop mode when boot into Shell
256 if (mShellImageCallbackReg
== NULL
) {
257 Status
= gBS
->CreateEvent (
258 EFI_EVENT_NOTIFY_SIGNAL
,
264 if (!EFI_ERROR (Status
)) {
265 Status
= gBS
->RegisterProtocolNotify (
268 &mShellImageCallbackReg
271 DEBUG ((EFI_D_INFO
, "BdsEntry ShellImageCallback \n"));
278 IN EFI_DEVICE_PATH_PROTOCOL
*PciDevicePath
,
279 OUT EFI_DEVICE_PATH_PROTOCOL
**GopDevicePath
284 EFI_HANDLE PciDeviceHandle
;
285 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
286 EFI_DEVICE_PATH_PROTOCOL
*TempPciDevicePath
;
287 UINTN GopHandleCount
;
288 EFI_HANDLE
*GopHandleBuffer
;
291 SYSTEM_CONFIGURATION mSystemConfiguration
;
293 if (PciDevicePath
== NULL
|| GopDevicePath
== NULL
) {
294 return EFI_INVALID_PARAMETER
;
298 // Initialize the GopDevicePath to be PciDevicePath
300 *GopDevicePath
= PciDevicePath
;
301 TempPciDevicePath
= PciDevicePath
;
303 Status
= gBS
->LocateDevicePath (
304 &gEfiDevicePathProtocolGuid
,
308 if (EFI_ERROR (Status
)) {
313 // Try to connect this handle, so that GOP dirver could start on this
314 // device and create child handles with GraphicsOutput Protocol installed
315 // on them, then we get device paths of these child handles and select
316 // them as possible console device.
320 // Select display devices
322 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
323 Status
= gRT
->GetVariable(
325 &gEfiNormalSetupGuid
,
328 &mSystemConfiguration
330 if (EFI_ERROR (Status
) || VarSize
!= sizeof(SYSTEM_CONFIGURATION
)) {
331 //The setup variable is corrupted
332 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
333 Status
= gRT
->GetVariable(
335 &gEfiNormalSetupGuid
,
338 &mSystemConfiguration
340 ASSERT_EFI_ERROR (Status
);
343 if(mSystemConfiguration
.BootDisplayDevice
!= 0x0)
345 ACPI_ADR_DEVICE_PATH AcpiAdr
;
346 EFI_DEVICE_PATH_PROTOCOL
*MyDevicePath
= NULL
;
348 AcpiAdr
.Header
.Type
= ACPI_DEVICE_PATH
;
349 AcpiAdr
.Header
.SubType
= ACPI_ADR_DP
;
351 switch (mSystemConfiguration
.BootDisplayDevice
) {
353 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA
, PORT_CRT
, 0); //CRT Device
356 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL
, PORT_B_HDMI
, 0); //HDMI Device Port B
359 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL
, PORT_B_DP
, 0); //DP PortB
362 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL
, PORT_C_DP
, 0); //DP PortC
365 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL
, PORT_C_DP
, 0); //eDP Port C
368 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL
, PORT_MIPI_A
, 0); //DSI Port A
371 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL
, PORT_MIPI_C
, 0); //DSI Port C
374 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA
, PORT_CRT
, 0);
378 SetDevicePathNodeLength (&AcpiAdr
.Header
, sizeof (ACPI_ADR_DEVICE_PATH
));
380 MyDevicePath
= AppendDevicePathNode(MyDevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&AcpiAdr
);
382 gBS
->ConnectController (
389 FreePool(MyDevicePath
);
393 gBS
->ConnectController (
401 Status
= gBS
->LocateHandleBuffer (
403 &gEfiGraphicsOutputProtocolGuid
,
408 if (!EFI_ERROR (Status
)) {
410 // Add all the child handles as possible Console Device
412 for (Index
= 0; Index
< GopHandleCount
; Index
++) {
413 Status
= gBS
->HandleProtocol (
414 GopHandleBuffer
[Index
],
415 &gEfiDevicePathProtocolGuid
,
416 (VOID
**)&TempDevicePath
418 if (EFI_ERROR (Status
)) {
424 GetDevicePathSize (PciDevicePath
) - END_DEVICE_PATH_LENGTH
427 // In current implementation, we only enable one of the child handles
428 // as console device, i.e. sotre one of the child handle's device
429 // path to variable "ConOut"
430 // In futhure, we could select all child handles to be console device
432 *GopDevicePath
= TempDevicePath
;
435 gBS
->FreePool (GopHandleBuffer
);
443 Search out all the platform pci or agp video device. The function may will
444 find multiple video device, and return all enabled device path.
446 @param PlugInPciVgaDevicePath Return the platform plug in pci video device
447 path if the system have plug in pci video device.
448 @param OnboardPciVgaDevicePath Return the platform active agp video device path
449 if the system have plug in agp video device or on
452 @retval EFI_SUCCSS Get all platform active video device path.
453 @retval EFI_STATUS Return the status of gBS->LocateDevicePath (),
454 gBS->ConnectController (),
455 and gBS->LocateHandleBuffer ().
459 GetPlugInPciVgaDevicePath (
460 IN OUT EFI_DEVICE_PATH_PROTOCOL
**PlugInPciVgaDevicePath
,
461 IN OUT EFI_DEVICE_PATH_PROTOCOL
**OnboardPciVgaDevicePath
465 EFI_HANDLE RootHandle
;
467 EFI_HANDLE
*HandleBuffer
;
470 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
471 BOOLEAN PlugInPciVga
;
472 EFI_PCI_IO_PROTOCOL
*PciIo
;
481 // Make all the PCI_IO protocols on PCI Seg 0 show up
483 BdsLibConnectDevicePath (gPlatformRootBridges
[0]);
485 Status
= gBS
->LocateDevicePath (
486 &gEfiDevicePathProtocolGuid
,
487 &gPlatformRootBridges
[0],
490 if (EFI_ERROR (Status
)) {
494 Status
= gBS
->ConnectController (
500 if (EFI_ERROR (Status
)) {
505 // Start to check all the pci io to find all possible VGA device
509 Status
= gBS
->LocateHandleBuffer (
511 &gEfiPciIoProtocolGuid
,
516 if (EFI_ERROR (Status
)) {
520 for (Index
= 0; Index
< HandleCount
; Index
++) {
521 Status
= gBS
->HandleProtocol (
523 &gEfiPciIoProtocolGuid
,
526 if (!EFI_ERROR (Status
)) {
529 // Check for all VGA device
531 Status
= PciIo
->Pci
.Read (
535 sizeof (Pci
) / sizeof (UINT32
),
538 if (EFI_ERROR (Status
)) {
543 // Here we decide which VGA device to enable in PCI bus
545 // The first plugin PCI VGA card device will be present as PCI VGA
546 // The onchip AGP or AGP card will be present as AGP VGA
548 if (!IS_PCI_VGA (&Pci
)) {
553 // Set the device as the possible console out device,
555 // Below code will make every VGA device to be one
556 // of the possibe console out device
559 gBS
->HandleProtocol (
561 &gEfiDevicePathProtocolGuid
,
567 while (gPlatformAllPossiblePciVgaConsole
[Index1
] != NULL
) {
570 gPlatformAllPossiblePciVgaConsole
[Index1
],
571 GetDevicePathSize (gPlatformAllPossiblePciVgaConsole
[Index1
])
575 // This device is an AGP device
577 *OnboardPciVgaDevicePath
= DevicePath
;
578 PlugInPciVga
= FALSE
;
586 *PlugInPciVgaDevicePath
= DevicePath
;
591 FreePool (HandleBuffer
);
598 Find the platform active vga, and base on the policy to enable the vga as
599 the console out device. The policy is driven by one setup variable "VBIOS".
603 @param EFI_UNSUPPORTED There is no active vga device
605 @retval EFI_STATUS Return the status of BdsLibGetVariableAndSize ()
609 PlatformBdsForceActiveVga (
614 EFI_DEVICE_PATH_PROTOCOL
*PlugInPciVgaDevicePath
;
615 EFI_DEVICE_PATH_PROTOCOL
*OnboardPciVgaDevicePath
;
616 EFI_DEVICE_PATH_PROTOCOL
*DevicePathFirst
;
617 EFI_DEVICE_PATH_PROTOCOL
*DevicePathSecond
;
618 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
620 SYSTEM_CONFIGURATION mSystemConfiguration
;
622 Status
= EFI_SUCCESS
;
623 PlugInPciVgaDevicePath
= NULL
;
624 OnboardPciVgaDevicePath
= NULL
;
627 // Check the policy which is the first enabled VGA
629 GetPlugInPciVgaDevicePath (&PlugInPciVgaDevicePath
, &OnboardPciVgaDevicePath
);
631 if (PlugInPciVgaDevicePath
== NULL
&& OnboardPciVgaDevicePath
== NULL
) {
632 return EFI_UNSUPPORTED
;
635 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
636 Status
= gRT
->GetVariable(
638 &gEfiNormalSetupGuid
,
641 &mSystemConfiguration
643 if (EFI_ERROR (Status
) || VarSize
!= sizeof(SYSTEM_CONFIGURATION
)) {
644 //The setup variable is corrupted
645 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
646 Status
= gRT
->GetVariable(
648 &gEfiNormalSetupGuid
,
651 &mSystemConfiguration
653 ASSERT_EFI_ERROR (Status
);
657 if ((PlugInPciVgaDevicePath
== NULL
&& OnboardPciVgaDevicePath
!= NULL
) ) {
658 DEBUG ((EFI_D_ERROR
,"Update onboard PCI VGA ...\n"));
659 DevicePathFirst
= OnboardPciVgaDevicePath
;
660 DevicePathSecond
= PlugInPciVgaDevicePath
;
663 if(OnboardPciVgaDevicePath
!= NULL
&& mSystemConfiguration
.PrimaryVideoAdaptor
== 0) {
664 DEBUG ((EFI_D_ERROR
,"Update onboard PCI VGA When set primary!!!...\n"));
665 DevicePathFirst
= OnboardPciVgaDevicePath
;
666 DevicePathSecond
= PlugInPciVgaDevicePath
;
670 DEBUG ((EFI_D_ERROR
,"Update plug in PCI VGA ...\n"));
671 DevicePathFirst
= PlugInPciVgaDevicePath
;
672 DevicePathSecond
= OnboardPciVgaDevicePath
;
675 GetGopDevicePath (DevicePathFirst
, &GopDevicePath
);
676 DevicePathFirst
= GopDevicePath
;
678 Status
= BdsLibUpdateConsoleVariable (
688 UpdateConsoleResolution(
692 UINT32 HorizontalResolution
;
693 UINT32 VerticalResolution
;
694 SYSTEM_CONFIGURATION SystemConfiguration
;
699 HorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
700 VerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
702 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
703 Status
= gRT
->GetVariable(
705 &gEfiNormalSetupGuid
,
710 if (EFI_ERROR (Status
) || VarSize
!= sizeof(SYSTEM_CONFIGURATION
)) {
711 //The setup variable is corrupted
712 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
713 Status
= gRT
->GetVariable(
715 &gEfiNormalSetupGuid
,
720 ASSERT_EFI_ERROR (Status
);
723 switch (SystemConfiguration
.IgdFlatPanel
) {
727 // Use the detault PCD values.
732 HorizontalResolution
= 640;
733 VerticalResolution
= 480;
737 HorizontalResolution
= 800;
738 VerticalResolution
= 600;
742 HorizontalResolution
= 1024;
743 VerticalResolution
= 768;
747 HorizontalResolution
= 1280;
748 VerticalResolution
= 1024;
752 HorizontalResolution
= 1366;
753 VerticalResolution
= 768;
757 HorizontalResolution
= 1680;
758 VerticalResolution
= 1050;
762 HorizontalResolution
= 1920;
763 VerticalResolution
= 1200;
767 HorizontalResolution
= 1280;
768 VerticalResolution
= 800;
772 PcdSet32 (PcdSetupVideoHorizontalResolution
, HorizontalResolution
);
773 PcdSet32 (PcdSetupVideoVerticalResolution
, VerticalResolution
);
774 DEBUG ((EFI_D_ERROR
, "HorizontalResolution = %x; VerticalResolution = %x", HorizontalResolution
, VerticalResolution
));
780 Connect the predefined platform default console device. Always try to find
781 and enable the vga device if have.
783 @param PlatformConsole Predfined platform default console device array.
785 @retval EFI_SUCCESS Success connect at least one ConIn and ConOut
786 device, there must have one ConOut device is
789 @retval EFI_STATUS Return the status of
790 BdsLibConnectAllDefaultConsoles ()
794 PlatformBdsConnectConsole (
795 IN BDS_CONSOLE_CONNECT_ENTRY
*PlatformConsole
800 EFI_DEVICE_PATH_PROTOCOL
*VarConout
;
801 EFI_DEVICE_PATH_PROTOCOL
*VarConin
;
802 UINTN DevicePathSize
;
804 UpdateConsoleResolution();
807 Status
= EFI_SUCCESS
;
809 VarConout
= BdsLibGetVariableAndSize (
811 &gEfiGlobalVariableGuid
,
814 VarConin
= BdsLibGetVariableAndSize (
816 &gEfiGlobalVariableGuid
,
819 if (VarConout
== NULL
|| VarConin
== NULL
) {
821 // Have chance to connect the platform default console,
822 // the platform default console is the minimue device group
823 // the platform should support
825 while (PlatformConsole
[Index
].DevicePath
!= NULL
) {
828 // Update the console variable with the connect type
830 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
831 BdsLibUpdateConsoleVariable (L
"ConIn", PlatformConsole
[Index
].DevicePath
, NULL
);
834 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
835 BdsLibUpdateConsoleVariable (L
"ConOut", PlatformConsole
[Index
].DevicePath
, NULL
);
838 if ((PlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
839 BdsLibUpdateConsoleVariable (L
"ErrOut", PlatformConsole
[Index
].DevicePath
, NULL
);
847 // Make sure we have at least one active VGA, and have the right
848 // active VGA in console variable
850 Status
= PlatformBdsForceActiveVga ();
851 if (EFI_ERROR (Status
)) {
855 DEBUG ((EFI_D_INFO
, "DISPLAY INIT DONE\n"));
858 // Connect the all the default console with current console variable
860 Status
= BdsLibConnectAllDefaultConsoles ();
861 if (EFI_ERROR (Status
)) {
869 Connect with predeined platform connect sequence,
870 the OEM/IBV can customize with their own connect sequence.
878 PlatformBdsConnectSequence (
887 // Here we can get the customized platform connect sequence
888 // Notes: we can connect with new variable which record the
889 // last time boots connect device path sequence
891 while (gPlatformConnectSequence
[Index
] != NULL
) {
894 // Build the platform boot option
896 BdsLibConnectDevicePath (gPlatformConnectSequence
[Index
]);
901 // Just use the simple policy to connect all devices
902 // There should be no difference between debug tip and release tip, or it will be extremely hard to debug.
904 // There is case that IdeController driver will write boot script in driver model Start() function. It will be rejected by boot script save.
905 // It is only found when DEBUG disabled, because we are using BdsLibConnectAll() when DEBUG enabled.
907 // So we use BdsLibConnectAll() here to make sure IdeController.Start() is invoked before InstallReadyToLock().
908 // We may also consider to connect SataController only later if needed.
915 Load the predefined driver option, OEM/IBV can customize this
916 to load their own drivers
918 @param BdsDriverLists The header of the driver option link list.
924 PlatformBdsGetDriverOption (
925 IN OUT LIST_ENTRY
*BdsDriverLists
933 // Here we can get the customized platform driver option
935 while (gPlatformDriverOption
[Index
] != NULL
) {
938 // Build the platform boot option
940 BdsLibRegisterNewOption (BdsDriverLists
, gPlatformDriverOption
[Index
], NULL
, L
"DriverOrder");
947 This function is used for some critical time if the the system
948 have no any boot option, and there is no time out for user to add
949 the new boot option. This can also treat as the platform default
952 @param BdsBootOptionList The header of the boot option link list.
958 PlatformBdsPredictBootOption (
959 IN OUT LIST_ENTRY
*BdsBootOptionList
967 // Here give chance to get platform boot option data
969 while (gPlatformBootOption
[Index
] != NULL
) {
972 // Build the platform boot option
974 BdsLibRegisterNewOption (BdsBootOptionList
, gPlatformBootOption
[Index
], NULL
, L
"BootOrder");
980 Perform the platform diagnostic, such like test memory. OEM/IBV also
981 can customize this fuction to support specific platform diagnostic.
983 @param MemoryTestLevel The memory test intensive level
984 @param QuietBoot Indicate if need to enable the quiet boot
985 @param BaseMemoryTest A pointer to BdsMemoryTest()
991 PlatformBdsDiagnostics (
992 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel
,
993 IN BOOLEAN QuietBoot
,
994 IN BASEM_MEMORY_TEST BaseMemoryTest
1000 // Here we can decide if we need to show
1001 // the diagnostics screen
1002 // Notes: this quiet boot code should be remove
1003 // from the graphic lib
1006 EnableQuietBoot (PcdGetPtr(PcdLogoFile
));
1009 // Perform system diagnostic
1011 Status
= BaseMemoryTest (MemoryTestLevel
);
1012 if (EFI_ERROR (Status
)) {
1013 DisableQuietBoot ();
1020 // Perform system diagnostic
1022 Status
= BaseMemoryTest (MemoryTestLevel
);
1027 For EFI boot option, BDS separate them as six types:
1028 1. Network - The boot option points to the SimpleNetworkProtocol device.
1029 Bds will try to automatically create this type boot option when enumerate.
1030 2. Shell - The boot option points to internal flash shell.
1031 Bds will try to automatically create this type boot option when enumerate.
1032 3. Removable BlockIo - The boot option only points to the removable media
1033 device, like USB flash disk, DVD, Floppy etc.
1034 These device should contain a *removable* blockIo
1035 protocol in their device handle.
1036 Bds will try to automatically create this type boot option
1038 4. Fixed BlockIo - The boot option only points to a Fixed blockIo device,
1040 These device should contain a *fixed* blockIo
1041 protocol in their device handle.
1042 BDS will skip fixed blockIo devices, and NOT
1043 automatically create boot option for them. But BDS
1044 will help to delete those fixed blockIo boot option,
1045 whose description rule conflict with other auto-created
1047 5. Non-BlockIo Simplefile - The boot option points to a device whose handle
1048 has SimpleFileSystem Protocol, but has no blockio
1049 protocol. These devices do not offer blockIo
1050 protocol, but BDS still can get the
1051 \EFI\BOOT\boot{machinename}.EFI by SimpleFileSystem
1053 6. File - The boot option points to a file. These boot options are usually
1054 created by user manually or OS loader. BDS will not delete or modify
1057 This function will enumerate all possible boot device in the system, and
1058 automatically create boot options for Network, Shell, Removable BlockIo,
1059 and Non-BlockIo Simplefile devices.
1060 It will only execute once of every boot.
1062 @param BdsBootOptionList The header of the link list which indexed all
1063 current boot options
1065 @retval EFI_SUCCESS Finished all the boot device enumerate and create
1066 the boot option base on that boot device
1068 @retval EFI_OUT_OF_RESOURCES Failed to enumerate the boot device and create the boot option list
1072 PlatformBdsLibEnumerateAllBootOption (
1073 IN OUT LIST_ENTRY
*BdsBootOptionList
1077 UINT16 FloppyNumber
;
1078 UINT16 HarddriveNumber
;
1083 UINT16 NonBlockNumber
;
1084 UINTN NumberBlockIoHandles
;
1085 EFI_HANDLE
*BlockIoHandles
;
1086 EFI_BLOCK_IO_PROTOCOL
*BlkIo
;
1087 BOOLEAN Removable
[2];
1088 UINTN RemovableIndex
;
1090 UINTN NumOfLoadFileHandles
;
1091 EFI_HANDLE
*LoadFileHandles
;
1092 UINTN FvHandleCount
;
1093 EFI_HANDLE
*FvHandleBuffer
;
1094 EFI_FV_FILETYPE Type
;
1096 EFI_FV_FILE_ATTRIBUTES Attributes
;
1097 UINT32 AuthenticationStatus
;
1098 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
1099 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1100 UINTN DevicePathType
;
1102 EFI_HANDLE
*FileSystemHandles
;
1103 UINTN NumberFileSystemHandles
;
1105 EFI_IMAGE_DOS_HEADER DosHeader
;
1108 EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData
;
1109 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
;
1112 EFI_HANDLE
*NetworkHandles
;
1116 HarddriveNumber
= 0;
1123 ZeroMem (Buffer
, sizeof (Buffer
));
1126 // If the boot device enumerate happened, just get the boot
1127 // device from the boot order variable
1129 if (mEnumBootDevice
) {
1130 GetVariable2 (LAST_ENUM_LANGUAGE_VARIABLE_NAME
, &gLastEnumLangGuid
, (VOID
**)&LastLang
, NULL
);
1131 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&PlatLang
, NULL
);
1132 ASSERT (PlatLang
!= NULL
);
1133 if ((LastLang
!= NULL
) && (AsciiStrCmp (LastLang
, PlatLang
) == 0)) {
1134 Status
= BdsLibBuildOptionFromVar (BdsBootOptionList
, L
"BootOrder");
1135 FreePool (LastLang
);
1136 FreePool (PlatLang
);
1139 Status
= gRT
->SetVariable (
1140 LAST_ENUM_LANGUAGE_VARIABLE_NAME
,
1142 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1143 AsciiStrSize (PlatLang
),
1147 // Failure to set the variable only impacts the performance next time enumerating the boot options.
1150 if (LastLang
!= NULL
) {
1151 FreePool (LastLang
);
1153 FreePool (PlatLang
);
1158 // Notes: this dirty code is to get the legacy boot option from the
1159 // BBS table and create to variable as the EFI boot option, it should
1160 // be removed after the CSM can provide legacy boot option directly
1162 REFRESH_LEGACY_BOOT_OPTIONS
;
1165 // Delete invalid boot option
1167 BdsDeleteAllInvalidEfiBootOption ();
1170 // Parse removable media followed by fixed media.
1171 // The Removable[] array is used by the for-loop below to create removable media boot options
1172 // at first, and then to create fixed media boot options.
1174 Removable
[0] = FALSE
;
1175 Removable
[1] = TRUE
;
1177 gBS
->LocateHandleBuffer (
1179 &gEfiBlockIoProtocolGuid
,
1181 &NumberBlockIoHandles
,
1185 for (RemovableIndex
= 0; RemovableIndex
< 2; RemovableIndex
++) {
1186 for (Index
= 0; Index
< NumberBlockIoHandles
; Index
++) {
1187 Status
= gBS
->HandleProtocol (
1188 BlockIoHandles
[Index
],
1189 &gEfiBlockIoProtocolGuid
,
1193 // skip the logical partition
1195 if (EFI_ERROR (Status
) || BlkIo
->Media
->LogicalPartition
) {
1200 // firstly fixed block io then the removable block io
1202 if (BlkIo
->Media
->RemovableMedia
== Removable
[RemovableIndex
]) {
1205 DevicePath
= DevicePathFromHandle (BlockIoHandles
[Index
]);
1206 DevicePathType
= BdsGetBootTypeFromDevicePath (DevicePath
);
1208 switch (DevicePathType
) {
1209 case BDS_EFI_ACPI_FLOPPY_BOOT
:
1210 if (FloppyNumber
!= 0) {
1211 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY
)), FloppyNumber
);
1213 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY
)));
1215 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1220 // Assume a removable SATA device should be the DVD/CD device, a fixed SATA device should be the Hard Drive device.
1222 case BDS_EFI_MESSAGE_ATAPI_BOOT
:
1223 case BDS_EFI_MESSAGE_SATA_BOOT
:
1224 if (BlkIo
->Media
->RemovableMedia
) {
1225 if (CdromNumber
!= 0) {
1226 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD
)), CdromNumber
);
1228 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD
)));
1232 if (HarddriveNumber
!= 0) {
1233 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE
)), HarddriveNumber
);
1235 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE
)));
1239 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "Buffer: %S\n", Buffer
));
1240 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1243 case BDS_EFI_MESSAGE_USB_DEVICE_BOOT
:
1244 if (UsbNumber
!= 0) {
1245 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB
)), UsbNumber
);
1247 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB
)));
1249 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1253 case BDS_EFI_MESSAGE_SCSI_BOOT
:
1254 if (ScsiNumber
!= 0) {
1255 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI
)), ScsiNumber
);
1257 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI
)));
1259 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1263 case BDS_EFI_MESSAGE_MISC_BOOT
:
1265 if (MiscNumber
!= 0) {
1266 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC
)), MiscNumber
);
1268 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC
)));
1270 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1277 if (NumberBlockIoHandles
!= 0) {
1278 FreePool (BlockIoHandles
);
1282 // If there is simple file protocol which does not consume block Io protocol, create a boot option for it here.
1285 gBS
->LocateHandleBuffer (
1287 &gEfiSimpleFileSystemProtocolGuid
,
1289 &NumberFileSystemHandles
,
1292 for (Index
= 0; Index
< NumberFileSystemHandles
; Index
++) {
1293 Status
= gBS
->HandleProtocol (
1294 FileSystemHandles
[Index
],
1295 &gEfiBlockIoProtocolGuid
,
1298 if (!EFI_ERROR (Status
)) {
1300 // Skip if the file system handle supports a BlkIo protocol,
1306 // Do the removable Media thing. \EFI\BOOT\boot{machinename}.EFI
1307 // machinename is ia32, ia64, x64, ...
1309 Hdr
.Union
= &HdrData
;
1311 Status
= BdsLibGetImageHeader (
1312 FileSystemHandles
[Index
],
1313 EFI_REMOVABLE_MEDIA_FILE_NAME
,
1317 if (!EFI_ERROR (Status
) &&
1318 EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr
.Pe32
->FileHeader
.Machine
) &&
1319 Hdr
.Pe32
->OptionalHeader
.Subsystem
== EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION
) {
1325 // No such file or the file is not a EFI application, delete this boot option
1327 BdsLibDeleteOptionFromHandle (FileSystemHandles
[Index
]);
1329 if (NonBlockNumber
!= 0) {
1330 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK
)), NonBlockNumber
);
1332 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK
)));
1334 BdsLibBuildOptionFromHandle (FileSystemHandles
[Index
], BdsBootOptionList
, Buffer
);
1339 if (NumberFileSystemHandles
!= 0) {
1340 FreePool (FileSystemHandles
);
1344 // Check if we have on flash shell
1346 gBS
->LocateHandleBuffer (
1348 &gEfiFirmwareVolume2ProtocolGuid
,
1353 for (Index
= 0; Index
< FvHandleCount
; Index
++) {
1354 gBS
->HandleProtocol (
1355 FvHandleBuffer
[Index
],
1356 &gEfiFirmwareVolume2ProtocolGuid
,
1360 Status
= Fv
->ReadFile (
1362 PcdGetPtr(PcdShellFile
),
1367 &AuthenticationStatus
1369 if (EFI_ERROR (Status
)) {
1371 // Skip if no shell file in the FV
1376 // Build the shell boot option
1378 BdsLibBuildOptionFromShell (FvHandleBuffer
[Index
], BdsBootOptionList
);
1381 if (FvHandleCount
!= 0) {
1382 FreePool (FvHandleBuffer
);
1386 // Parse Network Boot Device
1388 NumOfLoadFileHandles
= 0;
1390 // Search Load File protocol for PXE boot option.
1392 gBS
->LocateHandleBuffer (
1394 &gEfiLoadFileProtocolGuid
,
1396 &NumOfLoadFileHandles
,
1400 for (Index
= 0; Index
< NumOfLoadFileHandles
; Index
++) {
1403 //Locate EFI_DEVICE_PATH_PROTOCOL to dynamically get IPv4/IPv6 protocol information.
1406 Status
= gBS
->HandleProtocol (
1407 LoadFileHandles
[Index
],
1408 &gEfiDevicePathProtocolGuid
,
1409 (VOID
**) &DevicePath
1412 ASSERT_EFI_ERROR (Status
);
1414 while (!IsDevicePathEnd (DevicePath
)) {
1415 if ((DevicePath
->Type
== MESSAGING_DEVICE_PATH
) &&
1416 (DevicePath
->SubType
== MSG_IPv4_DP
)) {
1419 //Get handle infomation
1422 NetworkHandles
= NULL
;
1423 Status
= gBS
->LocateHandle (
1425 &gEfiSimpleNetworkProtocolGuid
,
1431 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1432 NetworkHandles
= AllocateZeroPool(BufferSize
);
1433 if (NetworkHandles
== NULL
) {
1434 return (EFI_OUT_OF_RESOURCES
);
1436 Status
= gBS
->LocateHandle(
1438 &gEfiSimpleNetworkProtocolGuid
,
1446 //Get the MAC string
1448 Status
= NetLibGetMacString (
1453 if (EFI_ERROR (Status
)) {
1456 IPverStr
= L
" IPv4";
1457 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK
)),MacStr
,IPverStr
);
1460 if((DevicePath
->Type
== MESSAGING_DEVICE_PATH
) &&
1461 (DevicePath
->SubType
== MSG_IPv6_DP
)) {
1464 //Get handle infomation
1467 NetworkHandles
= NULL
;
1468 Status
= gBS
->LocateHandle (
1470 &gEfiSimpleNetworkProtocolGuid
,
1476 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1477 NetworkHandles
= AllocateZeroPool(BufferSize
);
1478 if (NetworkHandles
== NULL
) {
1479 return (EFI_OUT_OF_RESOURCES
);
1481 Status
= gBS
->LocateHandle(
1483 &gEfiSimpleNetworkProtocolGuid
,
1491 //Get the MAC string
1493 Status
= NetLibGetMacString (
1498 if (EFI_ERROR (Status
)) {
1501 IPverStr
= L
" IPv6";
1502 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK
)),MacStr
,IPverStr
);
1505 DevicePath
= NextDevicePathNode (DevicePath
);
1508 BdsLibBuildOptionFromHandle (LoadFileHandles
[Index
], BdsBootOptionList
, Buffer
);
1511 if (NumOfLoadFileHandles
!= 0) {
1512 FreePool (LoadFileHandles
);
1516 // Check if we have on flash shell
1518 /* gBS->LocateHandleBuffer (
1520 &gEfiFirmwareVolume2ProtocolGuid,
1525 for (Index = 0; Index < FvHandleCount; Index++) {
1526 gBS->HandleProtocol (
1527 FvHandleBuffer[Index],
1528 &gEfiFirmwareVolume2ProtocolGuid,
1532 Status = Fv->ReadFile (
1534 PcdGetPtr(PcdShellFile),
1539 &AuthenticationStatus
1541 if (EFI_ERROR (Status)) {
1543 // Skip if no shell file in the FV
1548 // Build the shell boot option
1550 BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList);
1553 if (FvHandleCount != 0) {
1554 FreePool (FvHandleBuffer);
1558 // Make sure every boot only have one time
1559 // boot device enumerate
1561 Status
= BdsLibBuildOptionFromVar (BdsBootOptionList
, L
"BootOrder");
1562 mEnumBootDevice
= TRUE
;
1571 The function will excute with as the platform policy, current policy
1572 is driven by boot mode. IBV/OEM can customize this code for their specific
1575 @param DriverOptionList - The header of the driver option link list
1576 @param BootOptionList - The header of the boot option link list
1577 @param ProcessCapsules - A pointer to ProcessCapsules()
1578 @param BaseMemoryTest - A pointer to BaseMemoryTest()
1585 PlatformBdsPolicyBehavior (
1586 IN OUT LIST_ENTRY
*DriverOptionList
,
1587 IN OUT LIST_ENTRY
*BootOptionList
,
1588 IN PROCESS_CAPSULES ProcessCapsules
,
1589 IN BASEM_MEMORY_TEST BaseMemoryTest
1594 EFI_BOOT_MODE BootMode
;
1595 BOOLEAN DeferredImageExist
;
1597 CHAR16 CapsuleVarName
[36];
1598 CHAR16
*TempVarName
;
1599 SYSTEM_CONFIGURATION SystemConfiguration
;
1601 BOOLEAN SetVariableFlag
;
1602 PLATFORM_PCI_DEVICE_PATH
*EmmcBootDevPath
;
1603 EFI_GLOBAL_NVS_AREA_PROTOCOL
*GlobalNvsArea
;
1604 EFI_HANDLE FvProtocolHandle
;
1606 EFI_HANDLE
*HandleBuffer
;
1608 UINTN SataPciRegBase
= 0;
1609 UINT16 SataModeSelect
= 0;
1610 VOID
*RegistrationExitPmAuth
= NULL
;
1612 BOOLEAN IsFirstBoot
;
1614 UINTN BootOrderSize
;
1616 Timeout
= PcdGet16 (PcdPlatformBootTimeOut
);
1617 if (Timeout
> 10 ) {
1618 //we think the Timeout variable is corrupted
1622 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
1623 Status
= gRT
->GetVariable(
1625 &gEfiNormalSetupGuid
,
1628 &SystemConfiguration
1631 if (EFI_ERROR (Status
) || VarSize
!= sizeof(SYSTEM_CONFIGURATION
)) {
1632 //The setup variable is corrupted
1633 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
1634 Status
= gRT
->GetVariable(
1636 &gEfiNormalSetupGuid
,
1639 &SystemConfiguration
1641 ASSERT_EFI_ERROR (Status
);
1645 // Load the driver option as the driver option list
1647 PlatformBdsGetDriverOption (DriverOptionList
);
1650 // Get current Boot Mode
1652 BootMode
= GetBootModeHob();
1655 // Clear all the capsule variables CapsuleUpdateData, CapsuleUpdateData1, CapsuleUpdateData2...
1656 // as early as possible which will avoid the next time boot after the capsule update
1657 // will still into the capsule loop
1659 StrCpy (CapsuleVarName
, EFI_CAPSULE_VARIABLE_NAME
);
1660 TempVarName
= CapsuleVarName
+ StrLen (CapsuleVarName
);
1662 SetVariableFlag
= TRUE
;
1663 while (SetVariableFlag
) {
1665 UnicodeValueToString (TempVarName
, 0, Index
, 0);
1667 Status
= gRT
->SetVariable (
1669 &gEfiCapsuleVendorGuid
,
1670 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_RUNTIME_ACCESS
|
1671 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1675 if (EFI_ERROR (Status
)) {
1677 // There is no capsule variables, quit
1679 SetVariableFlag
= FALSE
;
1686 // No deferred images exist by default
1688 DeferredImageExist
= FALSE
;
1689 if ((BootMode
!= BOOT_WITH_MINIMAL_CONFIGURATION
) && (PcdGet32(PcdFlashFvShellSize
) > 0)){
1690 gDS
->ProcessFirmwareVolume (
1691 (VOID
*)(UINTN
)PcdGet32(PcdFlashFvShellBase
),
1692 PcdGet32(PcdFlashFvShellSize
),
1697 if (SystemConfiguration
.FastBoot
== 1) {
1698 BootOrder
= BdsLibGetVariableAndSize (
1700 &gEfiGlobalVariableGuid
,
1703 if ((BootOrder
!= NULL
) && (BootMode
!= BOOT_ON_FLASH_UPDATE
)) {
1705 // BootOrder exist, it means system has boot before. We can do fast boot.
1707 BootMode
= BOOT_WITH_MINIMAL_CONFIGURATION
;
1713 // Use eMMC to boot OS and turn on AHCI, when SATA HDD is diconnected,
1714 // SATA AHCI CTLR device will show yellow bang, implement this solution to solve it.
1716 SataPciRegBase
= MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA
, 0, 0);
1717 SataModeSelect
= MmioRead16 (SataPciRegBase
+ R_PCH_SATA_MAP
) & B_PCH_SATA_MAP_SMS_MASK
;
1718 Status
= EFI_SUCCESS
;
1719 if (SataModeSelect
!= V_PCH_SATA_MAP_SMS_IDE
) {
1720 Status
= gBS
->CreateEvent (
1727 if (!EFI_ERROR (Status
)) {
1728 Status
= gBS
->RegisterProtocolNotify (
1729 &gExitPmAuthProtocolGuid
,
1731 &RegistrationExitPmAuth
1738 case BOOT_WITH_MINIMAL_CONFIGURATION
:
1739 PlatformBdsInitHotKeyEvent ();
1740 PlatformBdsConnectSimpleConsole (gPlatformSimpleConsole
);
1744 // Check to see if it's needed to dispatch more DXE drivers.
1746 for (Index
= 0; Index
< sizeof(ConnectDriverTable
)/sizeof(EFI_GUID
*); Index
++) {
1747 Status
= gBS
->LocateHandleBuffer (
1749 ConnectDriverTable
[Index
],
1754 if (!EFI_ERROR (Status
)) {
1755 for (Index1
= 0; Index1
< HandleCount
; Index1
++) {
1756 gBS
->ConnectController (
1757 HandleBuffer
[Index1
],
1765 if (HandleBuffer
!= NULL
) {
1766 FreePool (HandleBuffer
);
1773 // Locate the Global NVS Protocol.
1775 Status
= gBS
->LocateProtocol (
1776 &gEfiGlobalNvsAreaProtocolGuid
,
1778 (void **)&GlobalNvsArea
1780 if (GlobalNvsArea
->Area
->emmcVersion
== 0){
1781 EmmcBootDevPath
= (PLATFORM_PCI_DEVICE_PATH
*)gPlatformSimpleBootOption
[0];
1782 EmmcBootDevPath
->PciDevice
.Device
= 0x10;
1786 // Connect boot device here to give time to read keyboard.
1788 BdsLibConnectDevicePath (gPlatformSimpleBootOption
[0]);
1791 // This is a workround for dectecting hotkey from USB keyboard.
1793 gBS
->Stall(KEYBOARD_TIMER_INTERVAL
);
1795 if (mHotKeyTimerEvent
!= NULL
) {
1801 gBS
->CloseEvent (mHotKeyTimerEvent
);
1802 mHotKeyTimerEvent
= NULL
;
1804 if (mHotKeyPressed
) {
1806 // Skip show progress count down
1809 goto FULL_CONFIGURATION
;
1812 if (SystemConfiguration
.QuietBoot
) {
1813 EnableQuietBoot (PcdGetPtr(PcdLogoFile
));
1815 PlatformBdsDiagnostics (IGNORE
, FALSE
, BaseMemoryTest
);
1820 TcgPhysicalPresenceLibProcessRequest();
1823 TrEEPhysicalPresenceLibProcessRequest(NULL
);
1826 // Close boot script and install ready to lock
1828 InstallReadyToLock ();
1831 // Give one chance to enter the setup if we
1832 // select Gummiboot "Reboot Into Firmware Interface" and Fast Boot is enabled.
1834 BootIntoFirmwareInterface();
1837 case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES
:
1840 // In no-configuration boot mode, we can connect the
1841 // console directly.
1843 BdsLibConnectAllDefaultConsoles ();
1844 PlatformBdsDiagnostics (IGNORE
, TRUE
, BaseMemoryTest
);
1847 // Perform some platform specific connect sequence
1849 PlatformBdsConnectSequence ();
1852 // As console is ready, perform user identification again.
1854 if (mCurrentUser
== NULL
) {
1855 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1856 if (DeferredImageExist
) {
1858 // After user authentication, the deferred drivers was loaded again.
1859 // Here, need to ensure the deferred images are connected.
1861 BdsLibConnectAllDefaultConsoles ();
1862 PlatformBdsConnectSequence ();
1867 // Close boot script and install ready to lock
1869 InstallReadyToLock ();
1872 // Notes: current time out = 0 can not enter the
1875 PlatformBdsEnterFrontPageWithHotKey (Timeout
, FALSE
);
1878 // Check the boot option with the boot option list
1880 BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
1883 case BOOT_ON_FLASH_UPDATE
:
1886 // Boot with the specific configuration
1888 PlatformBdsConnectConsole (gPlatformConsole
);
1889 PlatformBdsDiagnostics (EXTENSIVE
, FALSE
, BaseMemoryTest
);
1890 BdsLibConnectAll ();
1893 // Perform user identification
1895 if (mCurrentUser
== NULL
) {
1896 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1897 if (DeferredImageExist
) {
1899 // After user authentication, the deferred drivers was loaded again.
1900 // Here, need to ensure the deferred images are connected.
1902 BdsLibConnectAll ();
1907 // Close boot script and install ready to lock
1909 InstallReadyToLock ();
1911 ProcessCapsules (BOOT_ON_FLASH_UPDATE
);
1914 case BOOT_IN_RECOVERY_MODE
:
1917 // In recovery mode, just connect platform console
1918 // and show up the front page
1920 PlatformBdsConnectConsole (gPlatformConsole
);
1921 PlatformBdsDiagnostics (EXTENSIVE
, FALSE
, BaseMemoryTest
);
1922 BdsLibConnectAll ();
1925 // Perform user identification
1927 if (mCurrentUser
== NULL
) {
1928 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1929 if (DeferredImageExist
) {
1931 // After user authentication, the deferred drivers was loaded again.
1932 // Here, need to ensure the deferred drivers are connected.
1934 BdsLibConnectAll ();
1939 // Close boot script and install ready to lock
1941 InstallReadyToLock ();
1944 // In recovery boot mode, we still enter to the
1947 PlatformBdsEnterFrontPageWithHotKey (Timeout
, FALSE
);
1951 case BOOT_WITH_FULL_CONFIGURATION
:
1952 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS
:
1953 case BOOT_WITH_DEFAULT_SETTINGS
:
1957 // Connect platform console
1959 Status
= PlatformBdsConnectConsole (gPlatformConsole
);
1960 if (EFI_ERROR (Status
)) {
1963 // Here OEM/IBV can customize with defined action
1965 PlatformBdsNoConsoleAction ();
1969 // Chenyunh[TODO]: This is Workgroud to show the fs for uSDcard,
1970 // Need to root cause this issue.
1972 DEBUG ((DEBUG_ERROR
, "Start to reconnect all driver.\n"));
1973 BdsLibDisconnectAllEfi();
1974 BdsLibConnectAll ();
1975 DEBUG ((DEBUG_ERROR
, "End to reconnect all driver.\n"));
1978 // Perform some platform specific connect sequence
1980 PlatformBdsConnectSequence ();
1981 if (SystemConfiguration
.QuietBoot
) {
1982 EnableQuietBoot (PcdGetPtr(PcdLogoFile
));
1984 PlatformBdsDiagnostics (IGNORE
, FALSE
, BaseMemoryTest
);
1988 // Do a pre-delay so Hard Disk can spin up and see more logo.
1990 gBS
->Stall(SystemConfiguration
.HddPredelay
* 1000000);
1993 // Perform user identification
1995 if (mCurrentUser
== NULL
) {
1996 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1997 if (DeferredImageExist
) {
1999 // After user authentication, the deferred drivers was loaded again.
2000 // Here, need to ensure the deferred drivers are connected.
2002 Status
= PlatformBdsConnectConsole (gPlatformConsole
);
2003 if (EFI_ERROR (Status
)) {
2004 PlatformBdsNoConsoleAction ();
2006 PlatformBdsConnectSequence ();
2010 TcgPhysicalPresenceLibProcessRequest();
2013 TrEEPhysicalPresenceLibProcessRequest(NULL
);
2016 // Close boot script and install ready to lock
2018 InstallReadyToLock ();
2021 // Here we have enough time to do the enumeration of boot device
2023 PlatformBdsLibEnumerateAllBootOption (BootOptionList
);
2026 // Give one chance to enter the setup if we
2027 // have the time out
2029 PlatformBdsEnterFrontPageWithHotKey (Timeout
, FALSE
);
2032 // Give one chance to enter the setup if we
2033 // select Gummiboot "Reboot Into Firmware Interface"
2035 BootIntoFirmwareInterface();
2038 // In default boot mode, always find all boot
2039 // option and do enumerate all the default boot option
2042 BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
2043 if (IsListEmpty(BootOptionList
)) {
2044 PlatformBdsPredictBootOption (BootOptionList
);
2055 IsFirstBoot
= PcdGetBool(PcdBootState
);
2057 PcdSetBool(PcdBootState
, FALSE
);
2064 Hook point after a boot attempt succeeds. We don't expect a boot option to
2065 return, so the UEFI 2.0 specification defines that you will default to an
2066 interactive mode and stop processing the BootOrder list in this case. This
2067 is alos a platform implementation and can be customized by IBV/OEM.
2069 @param Option Pointer to Boot Option that succeeded to boot.
2076 PlatformBdsBootSuccess (
2077 IN BDS_COMMON_OPTION
*Option
2083 // If Boot returned with EFI_SUCCESS and there is not in the boot device
2084 // select loop then we need to pop up a UI and wait for user input.
2086 TmpStr
= Option
->StatusString
;
2087 if (TmpStr
!= NULL
) {
2088 BdsLibOutputStrings (gST
->ConOut
, TmpStr
, Option
->Description
, L
"\n\r", NULL
);
2094 Hook point after a boot attempt fails.
2096 @param Option - Pointer to Boot Option that failed to boot.
2097 @param Status - Status returned from failed boot.
2098 @param ExitData - Exit data returned from failed boot.
2099 @param ExitDataSize - Exit data size returned from failed boot.
2106 PlatformBdsBootFail (
2107 IN BDS_COMMON_OPTION
*Option
,
2108 IN EFI_STATUS Status
,
2109 IN CHAR16
*ExitData
,
2110 IN UINTN ExitDataSize
2114 EFI_HANDLE FvProtocolHandle
;
2117 // If Boot returned with failed status then we need to pop up a UI and wait
2120 TmpStr
= Option
->StatusString
;
2121 if (TmpStr
!= NULL
) {
2122 BdsLibOutputStrings (gST
->ConOut
, TmpStr
, Option
->Description
, L
"\n\r", NULL
);
2125 if (PcdGet32(PcdFlashFvShellSize
) > 0){
2126 gDS
->ProcessFirmwareVolume (
2127 (VOID
*)(UINTN
)PcdGet32(PcdFlashFvShellBase
),
2128 PcdGet32(PcdFlashFvShellSize
),
2132 PlatformBdsConnectSequence ();
2136 This function is remained for IBV/OEM to do some platform action,
2137 if there no console device can be connected.
2141 @retval EFI_SUCCESS Direct return success now.
2145 PlatformBdsNoConsoleAction (
2153 This function locks the block
2155 @param Base The base address flash region to be locked.
2160 IN EFI_PHYSICAL_ADDRESS Base
2163 EFI_FV_BLOCK_MAP_ENTRY
*BlockMap
;
2164 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
2165 EFI_PHYSICAL_ADDRESS BaseAddress
;
2170 BaseAddress
= Base
- 0x400000 + 2;
2171 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) ((UINTN
) (Base
));
2172 BlockMap
= &(FvHeader
->BlockMap
[0]);
2174 while ((BlockMap
->NumBlocks
!= 0) && (BlockMap
->Length
!= 0)) {
2175 BlockLength
= BlockMap
->Length
;
2176 for (Index
= 0; Index
< BlockMap
->NumBlocks
; Index
++) {
2177 Data
= MmioOr8 ((UINTN
) BaseAddress
, 0x03);
2178 BaseAddress
+= BlockLength
;
2186 PlatformBdsLockNonUpdatableFlash (
2190 EFI_PHYSICAL_ADDRESS Base
;
2192 Base
= (EFI_PHYSICAL_ADDRESS
) PcdGet32 (PcdFlashFvMainBase
);
2197 Base
= (EFI_PHYSICAL_ADDRESS
) PcdGet32 (PcdFlashFvRecoveryBase
);
2204 Lock the ConsoleIn device in system table. All key
2205 presses will be ignored until the Password is typed in. The only way to
2206 disable the password is to type it in to a ConIn device.
2208 @param Password Password used to lock ConIn device.
2210 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
2211 @retval EFI_UNSUPPORTED Password not found
2220 return EFI_UNSUPPORTED
;
2224 Connect the predefined platform default authentication devices.
2226 This function connects the predefined device path for authentication device,
2227 and if the predefined device path has child device path, the child handle will
2228 be connected too. But the child handle of the child will not be connected.
2233 PlatformBdsConnectAuthDevice (
2241 EFI_HANDLE
*HandleBuffer
;
2242 EFI_DEVICE_PATH_PROTOCOL
*ChildDevicePath
;
2243 EFI_USER_MANAGER_PROTOCOL
*Manager
;
2245 Status
= gBS
->LocateProtocol (
2246 &gEfiUserManagerProtocolGuid
,
2250 if (EFI_ERROR (Status
)) {
2252 // As user manager protocol is not installed, the authentication devices
2253 // should not be connected.
2259 while (gUserAuthenticationDevice
[Index
] != NULL
) {
2261 // Connect the platform customized device paths
2263 BdsLibConnectDevicePath (gUserAuthenticationDevice
[Index
]);
2268 // Find and connect the child device paths of the platform customized device paths
2270 HandleBuffer
= NULL
;
2271 for (Index
= 0; gUserAuthenticationDevice
[Index
] != NULL
; Index
++) {
2273 Status
= gBS
->LocateHandleBuffer (
2280 ASSERT (!EFI_ERROR (Status
));
2283 // Find and connect the child device paths of gUserIdentificationDevice[Index]
2285 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
2286 ChildDevicePath
= NULL
;
2287 Status
= gBS
->HandleProtocol (
2288 HandleBuffer
[HandleIndex
],
2289 &gEfiDevicePathProtocolGuid
,
2290 (VOID
**) &ChildDevicePath
2292 if (EFI_ERROR (Status
) || ChildDevicePath
== NULL
) {
2298 gUserAuthenticationDevice
[Index
],
2299 (GetDevicePathSize (gUserAuthenticationDevice
[Index
]) - sizeof (EFI_DEVICE_PATH_PROTOCOL
))
2303 gBS
->ConnectController (
2304 HandleBuffer
[HandleIndex
],
2312 if (HandleBuffer
!= NULL
) {
2313 FreePool (HandleBuffer
);
2318 This function is to identify a user, and return whether deferred images exist.
2320 @param[out] User Point to user profile handle.
2321 @param[out] DeferredImageExist On return, points to TRUE if the deferred image
2322 exist or FALSE if it did not exist.
2327 PlatformBdsUserIdentify (
2328 OUT EFI_USER_PROFILE_HANDLE
*User
,
2329 OUT BOOLEAN
*DeferredImageExist
2333 EFI_DEFERRED_IMAGE_LOAD_PROTOCOL
*DeferredImage
;
2335 EFI_HANDLE
*HandleBuf
;
2338 EFI_DEVICE_PATH_PROTOCOL
*ImageDevicePath
;
2344 // Perform user identification
2347 Status
= BdsLibUserIdentify (User
);
2348 } while (EFI_ERROR (Status
));
2351 // After user authentication now, try to find whether deferred image exists
2355 *DeferredImageExist
= FALSE
;
2356 Status
= gBS
->LocateHandleBuffer (
2358 &gEfiDeferredImageLoadProtocolGuid
,
2363 if (EFI_ERROR (Status
)) {
2367 for (Index
= 0; Index
< HandleCount
; Index
++) {
2368 Status
= gBS
->HandleProtocol (
2370 &gEfiDeferredImageLoadProtocolGuid
,
2371 (VOID
**) &DeferredImage
2373 if (!EFI_ERROR (Status
)) {
2375 // Find whether deferred image exists in this instance.
2378 Status
= DeferredImage
->GetImageInfo(
2382 (VOID
**) &DriverImage
,
2386 if (!EFI_ERROR (Status
)) {
2388 // The deferred image is found.
2390 FreePool (HandleBuf
);
2391 *DeferredImageExist
= TRUE
;
2397 FreePool (HandleBuf
);
2404 ShowProgressHotKey (
2405 IN UINT16 TimeoutDefault
2409 UINT16 TimeoutRemain
;
2412 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
2413 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
2414 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
2417 if (TimeoutDefault
== 0) {
2421 gST
->ConOut
->SetAttribute(gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
2423 if (DebugAssertEnabled())
2425 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"));
2430 SerialPortWrite((UINT8
*)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)[GCC]", 76);
2432 SerialPortWrite((UINT8
*)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)", 71);
2435 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
2436 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
2437 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
2440 // Clear the progress status bar first
2442 TmpStr
= L
"Start boot option, Press <F2> or <DEL> to enter setup page.";
2443 PlatformBdsShowProgress (Foreground
, Background
, TmpStr
, Color
, 0, 0);
2445 TimeoutRemain
= TimeoutDefault
;
2446 while (TimeoutRemain
!= 0) {
2447 if (DebugAssertEnabled())
2449 DEBUG ((EFI_D_INFO
, "Showing progress bar...Remaining %d second!\n", TimeoutRemain
));
2453 SerialPortWrite ((UINT8
*)".", 1);
2455 Status
= WaitForSingleEvent (gST
->ConIn
->WaitForKey
, ONE_SECOND
);
2456 if (Status
!= EFI_TIMEOUT
) {
2464 if (TmpStr
!= NULL
) {
2465 PlatformBdsShowProgress (
2470 ((TimeoutDefault
- TimeoutRemain
) * 100 / TimeoutDefault
),
2479 if (TimeoutRemain
== 0) {
2480 if (DebugAssertEnabled())
2485 SerialPortWrite ((UINT8
*)"\r\n", 2);
2491 // User pressed some key
2493 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2494 if (EFI_ERROR (Status
)) {
2499 // Check Volume Up Key to enter Setup
2501 GpioValue
= MmioRead32 (IO_BASE_ADDRESS
+ 0x0668); // The value of GPIOC_5
2502 if (((GpioValue
& BIT0
) == 0) && (Key
.ScanCode
== SCAN_UP
)) {
2507 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
2509 // User pressed enter, equivalent to select "continue"
2516 //F5 -- Device Manager
2517 //F7 -- Boot Manager
2518 // do not use F8. generally people assume it is windows safe mode key.
2521 DEBUG ((EFI_D_INFO
, "[Key Pressed]: ScanCode 0x%x\n", Key
.ScanCode
));
2522 switch(Key
.ScanCode
) {
2532 gHotKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
2536 gHotKey
= FRONT_PAGE_KEY_BOOT_MANAGER
;
2540 gHotKey
= FRONT_PAGE_KEY_BOOT_MAINTAIN
;
2544 //set gHotKey to continue so that flow will not go into CallFrontPage
2545 gHotKey
= FRONT_PAGE_KEY_CONTINUE
;
2556 This function is the main entry of the platform setup entry.
2557 The function will present the main menu of the system setup,
2558 this is the platform reference part and can be customize.
2561 @param TimeoutDefault The fault time out value before the system
2563 @param ConnectAllHappened The indicater to check if the connect all have
2568 PlatformBdsEnterFrontPageWithHotKey (
2569 IN UINT16 TimeoutDefault
,
2570 IN BOOLEAN ConnectAllHappened
2575 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
2576 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
2577 UINTN BootTextColumn
;
2580 GraphicsOutput
= NULL
;
2581 SimpleTextOut
= NULL
;
2583 PERF_START (NULL
, "BdsTimeOut", "BDS", 0);
2586 // Indicate if we need connect all in the platform setup
2588 if (ConnectAllHappened
) {
2589 gConnectAllHappened
= TRUE
;
2592 if (!mModeInitialized
) {
2594 // After the console is ready, get current video resolution
2595 // and text mode before launching setup at first time.
2597 Status
= gBS
->HandleProtocol (
2598 gST
->ConsoleOutHandle
,
2599 &gEfiGraphicsOutputProtocolGuid
,
2600 (VOID
**)&GraphicsOutput
2602 if (EFI_ERROR (Status
)) {
2603 GraphicsOutput
= NULL
;
2606 Status
= gBS
->HandleProtocol (
2607 gST
->ConsoleOutHandle
,
2608 &gEfiSimpleTextOutProtocolGuid
,
2609 (VOID
**)&SimpleTextOut
2611 if (EFI_ERROR (Status
)) {
2612 SimpleTextOut
= NULL
;
2615 if (GraphicsOutput
!= NULL
) {
2617 // Get current video resolution and text mode.
2619 mBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
2620 mBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
2623 if (SimpleTextOut
!= NULL
) {
2624 Status
= SimpleTextOut
->QueryMode (
2626 SimpleTextOut
->Mode
->Mode
,
2630 mBootTextModeColumn
= (UINT32
)BootTextColumn
;
2631 mBootTextModeRow
= (UINT32
)BootTextRow
;
2635 // Get user defined text mode for setup.
2637 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
2638 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
2639 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
2640 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
2642 mModeInitialized
= TRUE
;
2645 if (TimeoutDefault
!= 0xffff) {
2646 Status
= ShowProgressHotKey (TimeoutDefault
);
2649 // Ensure screen is clear when switch Console from Graphics mode to Text mode
2651 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
2652 gST
->ConOut
->ClearScreen (gST
->ConOut
);
2654 if (EFI_ERROR (Status
)) {
2656 // Timeout or user press enter to continue
2662 // Install BM HiiPackages.
2663 // Keep BootMaint HiiPackage, so that it can be covered by global setting.
2668 BdsSetConsoleMode (TRUE
);
2670 InitializeFrontPage (FALSE
);
2673 // Update Front Page strings
2675 UpdateFrontPageStrings ();
2677 Status
= EFI_SUCCESS
;
2680 Status
= CallFrontPage ();
2682 gCallbackKey
= gHotKey
;
2687 // If gCallbackKey is greater than 1 and less or equal to 5,
2688 // it will launch configuration utilities.
2691 // 4 = device manager
2692 // 5 = boot maintenance manager
2694 if (gCallbackKey
!= 0) {
2695 REPORT_STATUS_CODE (
2697 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
2702 // Based on the key that was set, we can determine what to do
2704 switch (gCallbackKey
) {
2706 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
2707 // describe to their customers in documentation how to find their setup information (namely
2708 // under the device manager and specific buckets)
2710 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager
2712 case FRONT_PAGE_KEY_CONTINUE
:
2715 // User hit continue
2719 case FRONT_PAGE_KEY_LANGUAGE
:
2722 // User made a language setting change - display front page again
2726 case FRONT_PAGE_KEY_BOOT_MANAGER
:
2728 // Remove the installed BootMaint HiiPackages when exit.
2733 // User chose to run the Boot Manager
2738 // Reinstall BootMaint HiiPackages after exiting from Boot Manager.
2743 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
2746 // Display the Device Manager
2749 CallDeviceManager ();
2750 } while (gCallbackKey
== FRONT_PAGE_KEY_DEVICE_MANAGER
);
2753 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
2756 // Display the Boot Maintenance Manager
2758 BdsStartBootMaint ();
2762 } while (((UINTN
)gCallbackKey
) != FRONT_PAGE_KEY_CONTINUE
);
2765 //Will leave browser, check any reset required change is applied? if yes, reset system
2767 SetupResetReminder ();
2769 // Remove the installed BootMaint HiiPackages when exit.
2775 // Automatically load current entry
2776 // Note: The following lines of code only execute when Auto boot
2779 PERF_END (NULL
, "BdsTimeOut", "BDS", 0);
2784 BootIntoFirmwareInterface(
2791 UINT64 OsIndication
;
2795 DataSize
= sizeof(UINT64
);
2796 Status
= gRT
->GetVariable (
2798 &gEfiGlobalVariableGuid
,
2804 DEBUG ((EFI_D_INFO
, "OSIndication Variable Value %d\n", OsIndication
));
2806 //Goto FrontPage directly when bit EFI_OS_INDICATIONS_BOOT_TO_FW_UI in OSIndication Variable is setted.
2808 if (!EFI_ERROR(Status
) && (OsIndication
!= 0)) {
2810 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
2816 PlatformBdsConnectSimpleConsole (
2817 IN BDS_CONSOLE_CONNECT_ENTRY
*PlatformConsole
2822 EFI_DEVICE_PATH_PROTOCOL
*VarConout
;
2823 EFI_DEVICE_PATH_PROTOCOL
*VarConin
;
2824 UINTN DevicePathSize
;
2828 Status
= EFI_SUCCESS
;
2830 VarConout
= BdsLibGetVariableAndSize (
2832 &gEfiGlobalVariableGuid
,
2835 VarConin
= BdsLibGetVariableAndSize (
2837 &gEfiGlobalVariableGuid
,
2840 if (VarConout
== NULL
|| VarConin
== NULL
) {
2842 // Have chance to connect the platform default console,
2843 // the platform default console is the minimue device group
2844 // the platform should support
2846 while (PlatformConsole
[Index
].DevicePath
!= NULL
) {
2849 // Update the console variable with the connect type
2851 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
2852 BdsLibUpdateConsoleVariable (L
"ConIn", PlatformConsole
[Index
].DevicePath
, NULL
);
2855 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
2856 BdsLibUpdateConsoleVariable (L
"ConOut", PlatformConsole
[Index
].DevicePath
, NULL
);
2859 if ((PlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
2860 BdsLibUpdateConsoleVariable (L
"ErrOut", PlatformConsole
[Index
].DevicePath
, NULL
);
2868 // Connect ConIn first to give keyboard time to parse hot key event.
2870 Status
= BdsLibConnectConsoleVariable (L
"ConIn");
2871 if (EFI_ERROR (Status
)) {
2876 // Make sure we have at least one active VGA, and have the right
2877 // active VGA in console variable
2879 Status
= PlatformBdsForceActiveVga ();
2882 // It seems impossible not to have any ConOut device on platform,
2883 // so we check the status here.
2885 Status
= BdsLibConnectConsoleVariable (L
"ConOut");
2886 if (EFI_ERROR (Status
)) {
2895 Timer handler to convert the key from USB.
2897 @param Event Indicates the event that invoke this function.
2898 @param Context Indicates the calling context.
2902 HotKeyTimerHandler (
2910 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2911 if (EFI_ERROR (Status
)) {
2915 switch(Key
.ScanCode
) {
2918 mHotKeyPressed
= TRUE
;
2922 gHotKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
2923 mHotKeyPressed
= TRUE
;
2927 gHotKey
= FRONT_PAGE_KEY_BOOT_MANAGER
;
2928 mHotKeyPressed
= TRUE
;
2932 gHotKey
= FRONT_PAGE_KEY_BOOT_MAINTAIN
;
2933 mHotKeyPressed
= TRUE
;
2937 if (mHotKeyPressed
) {
2943 gBS
->CloseEvent (mHotKeyTimerEvent
);
2944 mHotKeyTimerEvent
= NULL
;
2952 Callback function for SimpleTextInEx protocol install events
2954 @param Event the event that is signaled.
2955 @param Context not used here.
2967 Status
= gBS
->CloseEvent(mHitHotkeyEvent
);
2968 if (EFI_ERROR (Status
)) {
2971 Status
= gBS
->CreateEvent (
2972 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
2978 if (EFI_ERROR (Status
)) {
2981 Status
= gBS
->SetTimer (
2984 KEYBOARD_TIMER_INTERVAL
2986 if (EFI_ERROR (Status
)) {
2996 PlatformBdsInitHotKeyEvent (
3003 // Register Protocol notify for Hotkey service
3005 Status
= gBS
->CreateEvent (
3012 ASSERT_EFI_ERROR (Status
);
3015 // Register for protocol notifications on this event
3017 Status
= gBS
->RegisterProtocolNotify (
3018 &gEfiSimpleTextInputExProtocolGuid
,
3020 &mHitHotkeyRegistration
3022 ASSERT_EFI_ERROR (Status
);