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 #include <Library/CapsuleLib.h>
49 #include <Protocol/EsrtManagement.h>
51 EFI_GUID
*ConnectDriverTable
[] = {
52 &gEfiMmioDeviceProtocolGuid
,
53 &gEfiI2cMasterProtocolGuid
,
54 &gEfiI2cHostProtocolGuid
57 #define SHELL_ENVIRONMENT_INTERFACE_PROTOCOL \
59 0x47c7b221, 0xc42a, 0x11d2, 0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b \
61 VOID
*mShellImageCallbackReg
= NULL
;
65 EFI_USER_PROFILE_HANDLE mCurrentUser
= NULL
;
66 EFI_EVENT mHotKeyTimerEvent
= NULL
;
67 EFI_EVENT mHitHotkeyEvent
= NULL
;
68 EFI_EVENT mUsbKeyboardConnectEvent
= NULL
;
69 BOOLEAN mHotKeyPressed
= FALSE
;
70 VOID
*mHitHotkeyRegistration
;
71 #define KEYBOARD_TIMER_INTERVAL 20000 // 0.02s
74 ConnectUSBController (
79 PlatformBdsConnectSimpleConsole (
80 IN BDS_CONSOLE_CONNECT_ENTRY
*PlatformConsole
84 BootIntoFirmwareInterface(
90 PlatformBdsInitHotKeyEvent (
101 UINT32 PmcDisableAddress
;
102 UINT8 SataStorageAmount
;
104 UINT16 SataPortStatus
;
107 DEBUG ((EFI_D_INFO
, "Disable AHCI event is signalled\n"));
108 SataStorageAmount
= 0;
109 SataBase
= *(UINT32
*) Context
;
112 // BayTrail-M EDS chapter 16 ---- PCI IO Register Offset 92 (SATA Port Control and Status)
114 SataPortStatus
= MmioRead16 (SataBase
+ R_PCH_SATA_PCS
);
117 // Bit 8 EN: Port 0 Present
119 if ((SataPortStatus
& 0x100) == 0x100) {
124 // Bit 9 EN: Port 1 Present
126 if ((SataPortStatus
& 0x200) == 0x200) {
131 // Disable SATA controller when it sets to AHCI mode without carrying any devices
132 // in order to prevent AHCI yellow bang under Win device manager.
134 if (SataStorageAmount
== 0) {
135 PmcDisableAddress
= (MmioRead32 ((PCH_PCI_EXPRESS_BASE_ADDRESS
+ (UINT32
) (31 << 15)) + R_PCH_LPC_PMC_BASE
) & B_PCH_LPC_PMC_BASE_BAR
) + R_PCH_PMC_FUNC_DIS
;
136 MmioOr32 (PmcDisableAddress
, B_PCH_PMC_FUNC_DIS_SATA
);
137 S3BootScriptSaveMemWrite (
138 EfiBootScriptWidthUint32
,
139 (UINTN
) PmcDisableAddress
,
141 (VOID
*) (UINTN
) PmcDisableAddress
153 EFI_SMM_ACCESS2_PROTOCOL
*SmmAccess
;
154 EFI_ACPI_S3_SAVE_PROTOCOL
*AcpiS3Save
;
157 // Install DxeSmmReadyToLock protocol prior to the processing of boot options
159 Status
= gBS
->LocateProtocol (
160 &gEfiSmmAccess2ProtocolGuid
,
164 if (!EFI_ERROR (Status
)) {
167 // Prepare S3 information, this MUST be done before DxeSmmReadyToLock
169 Status
= gBS
->LocateProtocol (
170 &gEfiAcpiS3SaveProtocolGuid
,
174 if (!EFI_ERROR (Status
)) {
175 AcpiS3Save
->S3Save (AcpiS3Save
, NULL
);
179 Status
= gBS
->InstallProtocolInterface (
181 &gExitPmAuthProtocolGuid
,
182 EFI_NATIVE_INTERFACE
,
185 ASSERT_EFI_ERROR (Status
);
188 // Signal EndOfDxe PI Event
190 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid
);
193 Status
= gBS
->InstallProtocolInterface (
195 &gEfiDxeSmmReadyToLockProtocolGuid
,
196 EFI_NATIVE_INTERFACE
,
199 ASSERT_EFI_ERROR (Status
);
212 BdsSetConsoleMode (TRUE
);
213 DEBUG ((EFI_D_INFO
, "BdsEntry ShellImageCallback \n"));
217 // BDS Platform Functions
220 Platform Bds init. Include the platform firmware vendor, revision
235 EFI_EVENT ShellImageEvent
;
236 EFI_GUID ShellEnvProtocol
= SHELL_ENVIRONMENT_INTERFACE_PROTOCOL
;
239 SerialPortWrite((UINT8
*)">>>>BdsEntry[GCC]\r\n", 19);
241 SerialPortWrite((UINT8
*)">>>>BdsEntry\r\n", 14);
243 BdsLibSaveMemoryTypeInformation ();
246 // Before user authentication, the user identification devices need be connected
247 // from the platform customized device paths
249 PlatformBdsConnectAuthDevice ();
252 // As console is not ready, the auto logon user will be identified.
254 BdsLibUserIdentify (&mCurrentUser
);
257 // Change Gop mode when boot into Shell
259 if (mShellImageCallbackReg
== NULL
) {
260 Status
= gBS
->CreateEvent (
261 EFI_EVENT_NOTIFY_SIGNAL
,
267 if (!EFI_ERROR (Status
)) {
268 Status
= gBS
->RegisterProtocolNotify (
271 &mShellImageCallbackReg
274 DEBUG ((EFI_D_INFO
, "BdsEntry ShellImageCallback \n"));
281 IN EFI_DEVICE_PATH_PROTOCOL
*PciDevicePath
,
282 OUT EFI_DEVICE_PATH_PROTOCOL
**GopDevicePath
287 EFI_HANDLE PciDeviceHandle
;
288 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
289 EFI_DEVICE_PATH_PROTOCOL
*TempPciDevicePath
;
290 UINTN GopHandleCount
;
291 EFI_HANDLE
*GopHandleBuffer
;
294 SYSTEM_CONFIGURATION mSystemConfiguration
;
296 if (PciDevicePath
== NULL
|| GopDevicePath
== NULL
) {
297 return EFI_INVALID_PARAMETER
;
301 // Initialize the GopDevicePath to be PciDevicePath
303 *GopDevicePath
= PciDevicePath
;
304 TempPciDevicePath
= PciDevicePath
;
306 Status
= gBS
->LocateDevicePath (
307 &gEfiDevicePathProtocolGuid
,
311 if (EFI_ERROR (Status
)) {
316 // Try to connect this handle, so that GOP driver could start on this
317 // device and create child handles with GraphicsOutput Protocol installed
318 // on them, then we get device paths of these child handles and select
319 // them as possible console device.
323 // Select display devices
325 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
326 Status
= gRT
->GetVariable(
328 &gEfiNormalSetupGuid
,
331 &mSystemConfiguration
333 if (EFI_ERROR (Status
) || VarSize
!= sizeof(SYSTEM_CONFIGURATION
)) {
334 //The setup variable is corrupted
335 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
336 Status
= gRT
->GetVariable(
338 &gEfiNormalSetupGuid
,
341 &mSystemConfiguration
343 ASSERT_EFI_ERROR (Status
);
346 if(mSystemConfiguration
.BootDisplayDevice
!= 0x0)
348 ACPI_ADR_DEVICE_PATH AcpiAdr
;
349 EFI_DEVICE_PATH_PROTOCOL
*MyDevicePath
= NULL
;
351 AcpiAdr
.Header
.Type
= ACPI_DEVICE_PATH
;
352 AcpiAdr
.Header
.SubType
= ACPI_ADR_DP
;
354 switch (mSystemConfiguration
.BootDisplayDevice
) {
356 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA
, PORT_CRT
, 0); //CRT Device
359 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL
, PORT_B_HDMI
, 0); //HDMI Device Port B
362 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL
, PORT_B_DP
, 0); //DP PortB
365 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL
, PORT_C_DP
, 0); //DP PortC
368 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL
, PORT_C_DP
, 0); //eDP Port C
371 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL
, PORT_MIPI_A
, 0); //DSI Port A
374 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL
, PORT_MIPI_C
, 0); //DSI Port C
377 AcpiAdr
.ADR
= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA
, PORT_CRT
, 0);
381 SetDevicePathNodeLength (&AcpiAdr
.Header
, sizeof (ACPI_ADR_DEVICE_PATH
));
383 MyDevicePath
= AppendDevicePathNode(MyDevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&AcpiAdr
);
385 gBS
->ConnectController (
392 FreePool(MyDevicePath
);
396 gBS
->ConnectController (
404 Status
= gBS
->LocateHandleBuffer (
406 &gEfiGraphicsOutputProtocolGuid
,
411 if (!EFI_ERROR (Status
)) {
413 // Add all the child handles as possible Console Device
415 for (Index
= 0; Index
< GopHandleCount
; Index
++) {
416 Status
= gBS
->HandleProtocol (
417 GopHandleBuffer
[Index
],
418 &gEfiDevicePathProtocolGuid
,
419 (VOID
**)&TempDevicePath
421 if (EFI_ERROR (Status
)) {
427 GetDevicePathSize (PciDevicePath
) - END_DEVICE_PATH_LENGTH
430 // In current implementation, we only enable one of the child handles
431 // as console device, i.e. sotre one of the child handle's device
432 // path to variable "ConOut"
433 // In future, we could select all child handles to be console device
435 *GopDevicePath
= TempDevicePath
;
438 gBS
->FreePool (GopHandleBuffer
);
446 Search out all the platform pci or agp video device. The function may will
447 find multiple video device, and return all enabled device path.
449 @param PlugInPciVgaDevicePath Return the platform plug in pci video device
450 path if the system have plug in pci video device.
451 @param OnboardPciVgaDevicePath Return the platform active agp video device path
452 if the system have plug in agp video device or on
455 @retval EFI_SUCCSS Get all platform active video device path.
456 @retval EFI_STATUS Return the status of gBS->LocateDevicePath (),
457 gBS->ConnectController (),
458 and gBS->LocateHandleBuffer ().
462 GetPlugInPciVgaDevicePath (
463 IN OUT EFI_DEVICE_PATH_PROTOCOL
**PlugInPciVgaDevicePath
,
464 IN OUT EFI_DEVICE_PATH_PROTOCOL
**OnboardPciVgaDevicePath
468 EFI_HANDLE RootHandle
;
470 EFI_HANDLE
*HandleBuffer
;
473 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
474 BOOLEAN PlugInPciVga
;
475 EFI_PCI_IO_PROTOCOL
*PciIo
;
484 // Make all the PCI_IO protocols on PCI Seg 0 show up
486 BdsLibConnectDevicePath (gPlatformRootBridges
[0]);
488 Status
= gBS
->LocateDevicePath (
489 &gEfiDevicePathProtocolGuid
,
490 &gPlatformRootBridges
[0],
493 if (EFI_ERROR (Status
)) {
497 Status
= gBS
->ConnectController (
503 if (EFI_ERROR (Status
)) {
508 // Start to check all the pci io to find all possible VGA device
512 Status
= gBS
->LocateHandleBuffer (
514 &gEfiPciIoProtocolGuid
,
519 if (EFI_ERROR (Status
)) {
523 for (Index
= 0; Index
< HandleCount
; Index
++) {
524 Status
= gBS
->HandleProtocol (
526 &gEfiPciIoProtocolGuid
,
529 if (!EFI_ERROR (Status
)) {
532 // Check for all VGA device
534 Status
= PciIo
->Pci
.Read (
538 sizeof (Pci
) / sizeof (UINT32
),
541 if (EFI_ERROR (Status
)) {
546 // Here we decide which VGA device to enable in PCI bus
548 // The first plugin PCI VGA card device will be present as PCI VGA
549 // The onchip AGP or AGP card will be present as AGP VGA
551 if (!IS_PCI_VGA (&Pci
)) {
556 // Set the device as the possible console out device,
558 // Below code will make every VGA device to be one
559 // of the possibe console out device
562 gBS
->HandleProtocol (
564 &gEfiDevicePathProtocolGuid
,
570 while (gPlatformAllPossiblePciVgaConsole
[Index1
] != NULL
) {
573 gPlatformAllPossiblePciVgaConsole
[Index1
],
574 GetDevicePathSize (gPlatformAllPossiblePciVgaConsole
[Index1
])
578 // This device is an AGP device
580 *OnboardPciVgaDevicePath
= DevicePath
;
581 PlugInPciVga
= FALSE
;
589 *PlugInPciVgaDevicePath
= DevicePath
;
594 FreePool (HandleBuffer
);
601 Find the platform active vga, and base on the policy to enable the vga as
602 the console out device. The policy is driven by one setup variable "VBIOS".
606 @param EFI_UNSUPPORTED There is no active vga device
608 @retval EFI_STATUS Return the status of BdsLibGetVariableAndSize ()
612 PlatformBdsForceActiveVga (
617 EFI_DEVICE_PATH_PROTOCOL
*PlugInPciVgaDevicePath
;
618 EFI_DEVICE_PATH_PROTOCOL
*OnboardPciVgaDevicePath
;
619 EFI_DEVICE_PATH_PROTOCOL
*DevicePathFirst
;
620 EFI_DEVICE_PATH_PROTOCOL
*DevicePathSecond
;
621 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
623 SYSTEM_CONFIGURATION mSystemConfiguration
;
625 Status
= EFI_SUCCESS
;
626 PlugInPciVgaDevicePath
= NULL
;
627 OnboardPciVgaDevicePath
= NULL
;
630 // Check the policy which is the first enabled VGA
632 GetPlugInPciVgaDevicePath (&PlugInPciVgaDevicePath
, &OnboardPciVgaDevicePath
);
634 if (PlugInPciVgaDevicePath
== NULL
&& OnboardPciVgaDevicePath
== NULL
) {
635 return EFI_UNSUPPORTED
;
638 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
639 Status
= gRT
->GetVariable(
641 &gEfiNormalSetupGuid
,
644 &mSystemConfiguration
646 if (EFI_ERROR (Status
) || VarSize
!= sizeof(SYSTEM_CONFIGURATION
)) {
647 //The setup variable is corrupted
648 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
649 Status
= gRT
->GetVariable(
651 &gEfiNormalSetupGuid
,
654 &mSystemConfiguration
656 ASSERT_EFI_ERROR (Status
);
660 if ((PlugInPciVgaDevicePath
== NULL
&& OnboardPciVgaDevicePath
!= NULL
) ) {
661 DEBUG ((EFI_D_ERROR
,"Update onboard PCI VGA ...\n"));
662 DevicePathFirst
= OnboardPciVgaDevicePath
;
663 DevicePathSecond
= PlugInPciVgaDevicePath
;
666 if(OnboardPciVgaDevicePath
!= NULL
&& mSystemConfiguration
.PrimaryVideoAdaptor
== 0) {
667 DEBUG ((EFI_D_ERROR
,"Update onboard PCI VGA When set primary!!!...\n"));
668 DevicePathFirst
= OnboardPciVgaDevicePath
;
669 DevicePathSecond
= PlugInPciVgaDevicePath
;
673 DEBUG ((EFI_D_ERROR
,"Update plug in PCI VGA ...\n"));
674 DevicePathFirst
= PlugInPciVgaDevicePath
;
675 DevicePathSecond
= OnboardPciVgaDevicePath
;
678 GetGopDevicePath (DevicePathFirst
, &GopDevicePath
);
679 DevicePathFirst
= GopDevicePath
;
681 Status
= BdsLibUpdateConsoleVariable (
691 UpdateConsoleResolution(
695 UINT32 HorizontalResolution
;
696 UINT32 VerticalResolution
;
697 SYSTEM_CONFIGURATION SystemConfiguration
;
702 HorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
703 VerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
705 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
706 Status
= gRT
->GetVariable(
708 &gEfiNormalSetupGuid
,
713 if (EFI_ERROR (Status
) || VarSize
!= sizeof(SYSTEM_CONFIGURATION
)) {
714 //The setup variable is corrupted
715 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
716 Status
= gRT
->GetVariable(
718 &gEfiNormalSetupGuid
,
723 ASSERT_EFI_ERROR (Status
);
726 switch (SystemConfiguration
.IgdFlatPanel
) {
730 // Use the detault PCD values.
735 HorizontalResolution
= 640;
736 VerticalResolution
= 480;
740 HorizontalResolution
= 800;
741 VerticalResolution
= 600;
745 HorizontalResolution
= 1024;
746 VerticalResolution
= 768;
750 HorizontalResolution
= 1280;
751 VerticalResolution
= 1024;
755 HorizontalResolution
= 1366;
756 VerticalResolution
= 768;
760 HorizontalResolution
= 1680;
761 VerticalResolution
= 1050;
765 HorizontalResolution
= 1920;
766 VerticalResolution
= 1200;
770 HorizontalResolution
= 1280;
771 VerticalResolution
= 800;
775 PcdSet32 (PcdSetupVideoHorizontalResolution
, HorizontalResolution
);
776 PcdSet32 (PcdSetupVideoVerticalResolution
, VerticalResolution
);
777 DEBUG ((EFI_D_ERROR
, "HorizontalResolution = %x; VerticalResolution = %x", HorizontalResolution
, VerticalResolution
));
783 Connect the predefined platform default console device. Always try to find
784 and enable the vga device if have.
786 @param PlatformConsole Predefined platform default console device array.
788 @retval EFI_SUCCESS Success connect at least one ConIn and ConOut
789 device, there must have one ConOut device is
792 @retval EFI_STATUS Return the status of
793 BdsLibConnectAllDefaultConsoles ()
797 PlatformBdsConnectConsole (
798 IN BDS_CONSOLE_CONNECT_ENTRY
*PlatformConsole
803 EFI_DEVICE_PATH_PROTOCOL
*VarConout
;
804 EFI_DEVICE_PATH_PROTOCOL
*VarConin
;
805 UINTN DevicePathSize
;
807 UpdateConsoleResolution();
810 Status
= EFI_SUCCESS
;
812 VarConout
= BdsLibGetVariableAndSize (
814 &gEfiGlobalVariableGuid
,
817 VarConin
= BdsLibGetVariableAndSize (
819 &gEfiGlobalVariableGuid
,
822 if (VarConout
== NULL
|| VarConin
== NULL
) {
824 // Have chance to connect the platform default console,
825 // the platform default console is the minimum device group
826 // the platform should support
828 while (PlatformConsole
[Index
].DevicePath
!= NULL
) {
831 // Update the console variable with the connect type
833 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
834 BdsLibUpdateConsoleVariable (L
"ConIn", PlatformConsole
[Index
].DevicePath
, NULL
);
837 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
838 BdsLibUpdateConsoleVariable (L
"ConOut", PlatformConsole
[Index
].DevicePath
, NULL
);
841 if ((PlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
842 BdsLibUpdateConsoleVariable (L
"ErrOut", PlatformConsole
[Index
].DevicePath
, NULL
);
850 // Make sure we have at least one active VGA, and have the right
851 // active VGA in console variable
853 Status
= PlatformBdsForceActiveVga ();
854 if (EFI_ERROR (Status
)) {
858 DEBUG ((EFI_D_INFO
, "DISPLAY INIT DONE\n"));
861 // Connect the all the default console with current console variable
863 Status
= BdsLibConnectAllDefaultConsoles ();
864 if (EFI_ERROR (Status
)) {
872 Connect with predefined platform connect sequence,
873 the OEM/IBV can customize with their own connect sequence.
881 PlatformBdsConnectSequence (
890 // Here we can get the customized platform connect sequence
891 // Notes: we can connect with new variable which record the
892 // last time boots connect device path sequence
894 while (gPlatformConnectSequence
[Index
] != NULL
) {
897 // Build the platform boot option
899 BdsLibConnectDevicePath (gPlatformConnectSequence
[Index
]);
904 // Just use the simple policy to connect all devices
905 // There should be no difference between debug tip and release tip, or it will be extremely hard to debug.
907 // There is case that IdeController driver will write boot script in driver model Start() function. It will be rejected by boot script save.
908 // It is only found when DEBUG disabled, because we are using BdsLibConnectAll() when DEBUG enabled.
910 // So we use BdsLibConnectAll() here to make sure IdeController.Start() is invoked before InstallReadyToLock().
911 // We may also consider to connect SataController only later if needed.
918 Load the predefined driver option, OEM/IBV can customize this
919 to load their own drivers
921 @param BdsDriverLists The header of the driver option link list.
927 PlatformBdsGetDriverOption (
928 IN OUT LIST_ENTRY
*BdsDriverLists
936 // Here we can get the customized platform driver option
938 while (gPlatformDriverOption
[Index
] != NULL
) {
941 // Build the platform boot option
943 BdsLibRegisterNewOption (BdsDriverLists
, gPlatformDriverOption
[Index
], NULL
, L
"DriverOrder");
950 This function is used for some critical time if the the system
951 have no any boot option, and there is no time out for user to add
952 the new boot option. This can also treat as the platform default
955 @param BdsBootOptionList The header of the boot option link list.
961 PlatformBdsPredictBootOption (
962 IN OUT LIST_ENTRY
*BdsBootOptionList
970 // Here give chance to get platform boot option data
972 while (gPlatformBootOption
[Index
] != NULL
) {
975 // Build the platform boot option
977 BdsLibRegisterNewOption (BdsBootOptionList
, gPlatformBootOption
[Index
], NULL
, L
"BootOrder");
983 Perform the platform diagnostic, such like test memory. OEM/IBV also
984 can customize this fuction to support specific platform diagnostic.
986 @param MemoryTestLevel The memory test intensive level
987 @param QuietBoot Indicate if need to enable the quiet boot
988 @param BaseMemoryTest A pointer to BdsMemoryTest()
994 PlatformBdsDiagnostics (
995 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel
,
996 IN BOOLEAN QuietBoot
,
997 IN BASEM_MEMORY_TEST BaseMemoryTest
1003 // Here we can decide if we need to show
1004 // the diagnostics screen
1005 // Notes: this quiet boot code should be remove
1006 // from the graphic lib
1009 EnableQuietBoot (PcdGetPtr(PcdLogoFile
));
1012 // Perform system diagnostic
1014 Status
= BaseMemoryTest (MemoryTestLevel
);
1015 if (EFI_ERROR (Status
)) {
1016 DisableQuietBoot ();
1023 // Perform system diagnostic
1025 Status
= BaseMemoryTest (MemoryTestLevel
);
1030 For EFI boot option, BDS separate them as six types:
1031 1. Network - The boot option points to the SimpleNetworkProtocol device.
1032 Bds will try to automatically create this type boot option when enumerate.
1033 2. Shell - The boot option points to internal flash shell.
1034 Bds will try to automatically create this type boot option when enumerate.
1035 3. Removable BlockIo - The boot option only points to the removable media
1036 device, like USB flash disk, DVD, Floppy etc.
1037 These device should contain a *removable* blockIo
1038 protocol in their device handle.
1039 Bds will try to automatically create this type boot option
1041 4. Fixed BlockIo - The boot option only points to a Fixed blockIo device,
1043 These device should contain a *fixed* blockIo
1044 protocol in their device handle.
1045 BDS will skip fixed blockIo devices, and NOT
1046 automatically create boot option for them. But BDS
1047 will help to delete those fixed blockIo boot option,
1048 whose description rule conflict with other auto-created
1050 5. Non-BlockIo Simplefile - The boot option points to a device whose handle
1051 has SimpleFileSystem Protocol, but has no blockio
1052 protocol. These devices do not offer blockIo
1053 protocol, but BDS still can get the
1054 \EFI\BOOT\boot{machinename}.EFI by SimpleFileSystem
1056 6. File - The boot option points to a file. These boot options are usually
1057 created by user manually or OS loader. BDS will not delete or modify
1060 This function will enumerate all possible boot device in the system, and
1061 automatically create boot options for Network, Shell, Removable BlockIo,
1062 and Non-BlockIo Simplefile devices.
1063 It will only execute once of every boot.
1065 @param BdsBootOptionList The header of the link list which indexed all
1066 current boot options
1068 @retval EFI_SUCCESS Finished all the boot device enumerate and create
1069 the boot option base on that boot device
1071 @retval EFI_OUT_OF_RESOURCES Failed to enumerate the boot device and create the boot option list
1075 PlatformBdsLibEnumerateAllBootOption (
1076 IN OUT LIST_ENTRY
*BdsBootOptionList
1080 UINT16 FloppyNumber
;
1081 UINT16 HarddriveNumber
;
1086 UINT16 NonBlockNumber
;
1087 UINTN NumberBlockIoHandles
;
1088 EFI_HANDLE
*BlockIoHandles
;
1089 EFI_BLOCK_IO_PROTOCOL
*BlkIo
;
1090 BOOLEAN Removable
[2];
1091 UINTN RemovableIndex
;
1093 UINTN NumOfLoadFileHandles
;
1094 EFI_HANDLE
*LoadFileHandles
;
1095 UINTN FvHandleCount
;
1096 EFI_HANDLE
*FvHandleBuffer
;
1097 EFI_FV_FILETYPE Type
;
1099 EFI_FV_FILE_ATTRIBUTES Attributes
;
1100 UINT32 AuthenticationStatus
;
1101 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
1102 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1103 UINTN DevicePathType
;
1105 EFI_HANDLE
*FileSystemHandles
;
1106 UINTN NumberFileSystemHandles
;
1108 EFI_IMAGE_DOS_HEADER DosHeader
;
1111 EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData
;
1112 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
;
1115 EFI_HANDLE
*NetworkHandles
;
1119 HarddriveNumber
= 0;
1126 ZeroMem (Buffer
, sizeof (Buffer
));
1129 // If the boot device enumerate happened, just get the boot
1130 // device from the boot order variable
1132 if (mEnumBootDevice
) {
1133 GetVariable2 (LAST_ENUM_LANGUAGE_VARIABLE_NAME
, &gLastEnumLangGuid
, (VOID
**)&LastLang
, NULL
);
1134 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&PlatLang
, NULL
);
1135 ASSERT (PlatLang
!= NULL
);
1136 if ((LastLang
!= NULL
) && (AsciiStrCmp (LastLang
, PlatLang
) == 0)) {
1137 Status
= BdsLibBuildOptionFromVar (BdsBootOptionList
, L
"BootOrder");
1138 FreePool (LastLang
);
1139 FreePool (PlatLang
);
1142 Status
= gRT
->SetVariable (
1143 LAST_ENUM_LANGUAGE_VARIABLE_NAME
,
1145 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1146 AsciiStrSize (PlatLang
),
1150 // Failure to set the variable only impacts the performance next time enumerating the boot options.
1153 if (LastLang
!= NULL
) {
1154 FreePool (LastLang
);
1156 FreePool (PlatLang
);
1161 // Notes: this dirty code is to get the legacy boot option from the
1162 // BBS table and create to variable as the EFI boot option, it should
1163 // be removed after the CSM can provide legacy boot option directly
1165 REFRESH_LEGACY_BOOT_OPTIONS
;
1168 // Delete invalid boot option
1170 BdsDeleteAllInvalidEfiBootOption ();
1173 // Parse removable media followed by fixed media.
1174 // The Removable[] array is used by the for-loop below to create removable media boot options
1175 // at first, and then to create fixed media boot options.
1177 Removable
[0] = FALSE
;
1178 Removable
[1] = TRUE
;
1180 gBS
->LocateHandleBuffer (
1182 &gEfiBlockIoProtocolGuid
,
1184 &NumberBlockIoHandles
,
1188 for (RemovableIndex
= 0; RemovableIndex
< 2; RemovableIndex
++) {
1189 for (Index
= 0; Index
< NumberBlockIoHandles
; Index
++) {
1190 Status
= gBS
->HandleProtocol (
1191 BlockIoHandles
[Index
],
1192 &gEfiBlockIoProtocolGuid
,
1196 // skip the logical partition
1198 if (EFI_ERROR (Status
) || BlkIo
->Media
->LogicalPartition
) {
1203 // firstly fixed block io then the removable block io
1205 if (BlkIo
->Media
->RemovableMedia
== Removable
[RemovableIndex
]) {
1208 DevicePath
= DevicePathFromHandle (BlockIoHandles
[Index
]);
1209 DevicePathType
= BdsGetBootTypeFromDevicePath (DevicePath
);
1211 switch (DevicePathType
) {
1212 case BDS_EFI_ACPI_FLOPPY_BOOT
:
1213 if (FloppyNumber
!= 0) {
1214 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY
)), FloppyNumber
);
1216 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY
)));
1218 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1223 // Assume a removable SATA device should be the DVD/CD device, a fixed SATA device should be the Hard Drive device.
1225 case BDS_EFI_MESSAGE_ATAPI_BOOT
:
1226 case BDS_EFI_MESSAGE_SATA_BOOT
:
1227 if (BlkIo
->Media
->RemovableMedia
) {
1228 if (CdromNumber
!= 0) {
1229 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD
)), CdromNumber
);
1231 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD
)));
1235 if (HarddriveNumber
!= 0) {
1236 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE
)), HarddriveNumber
);
1238 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE
)));
1242 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "Buffer: %S\n", Buffer
));
1243 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1246 case BDS_EFI_MESSAGE_USB_DEVICE_BOOT
:
1247 if (UsbNumber
!= 0) {
1248 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB
)), UsbNumber
);
1250 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB
)));
1252 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1256 case BDS_EFI_MESSAGE_SCSI_BOOT
:
1257 if (ScsiNumber
!= 0) {
1258 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI
)), ScsiNumber
);
1260 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI
)));
1262 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1266 case BDS_EFI_MESSAGE_MISC_BOOT
:
1268 if (MiscNumber
!= 0) {
1269 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC
)), MiscNumber
);
1271 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC
)));
1273 BdsLibBuildOptionFromHandle (BlockIoHandles
[Index
], BdsBootOptionList
, Buffer
);
1280 if (NumberBlockIoHandles
!= 0) {
1281 FreePool (BlockIoHandles
);
1285 // If there is simple file protocol which does not consume block Io protocol, create a boot option for it here.
1288 gBS
->LocateHandleBuffer (
1290 &gEfiSimpleFileSystemProtocolGuid
,
1292 &NumberFileSystemHandles
,
1295 for (Index
= 0; Index
< NumberFileSystemHandles
; Index
++) {
1296 Status
= gBS
->HandleProtocol (
1297 FileSystemHandles
[Index
],
1298 &gEfiBlockIoProtocolGuid
,
1301 if (!EFI_ERROR (Status
)) {
1303 // Skip if the file system handle supports a BlkIo protocol,
1309 // Do the removable Media thing. \EFI\BOOT\boot{machinename}.EFI
1310 // machinename is ia32, ia64, x64, ...
1312 Hdr
.Union
= &HdrData
;
1314 Status
= BdsLibGetImageHeader (
1315 FileSystemHandles
[Index
],
1316 EFI_REMOVABLE_MEDIA_FILE_NAME
,
1320 if (!EFI_ERROR (Status
) &&
1321 EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr
.Pe32
->FileHeader
.Machine
) &&
1322 Hdr
.Pe32
->OptionalHeader
.Subsystem
== EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION
) {
1328 // No such file or the file is not a EFI application, delete this boot option
1330 BdsLibDeleteOptionFromHandle (FileSystemHandles
[Index
]);
1332 if (NonBlockNumber
!= 0) {
1333 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK
)), NonBlockNumber
);
1335 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK
)));
1337 BdsLibBuildOptionFromHandle (FileSystemHandles
[Index
], BdsBootOptionList
, Buffer
);
1342 if (NumberFileSystemHandles
!= 0) {
1343 FreePool (FileSystemHandles
);
1347 // Check if we have on flash shell
1349 gBS
->LocateHandleBuffer (
1351 &gEfiFirmwareVolume2ProtocolGuid
,
1356 for (Index
= 0; Index
< FvHandleCount
; Index
++) {
1357 gBS
->HandleProtocol (
1358 FvHandleBuffer
[Index
],
1359 &gEfiFirmwareVolume2ProtocolGuid
,
1363 Status
= Fv
->ReadFile (
1365 PcdGetPtr(PcdShellFile
),
1370 &AuthenticationStatus
1372 if (EFI_ERROR (Status
)) {
1374 // Skip if no shell file in the FV
1379 // Build the shell boot option
1381 BdsLibBuildOptionFromShell (FvHandleBuffer
[Index
], BdsBootOptionList
);
1384 if (FvHandleCount
!= 0) {
1385 FreePool (FvHandleBuffer
);
1389 // Parse Network Boot Device
1391 NumOfLoadFileHandles
= 0;
1393 // Search Load File protocol for PXE boot option.
1395 gBS
->LocateHandleBuffer (
1397 &gEfiLoadFileProtocolGuid
,
1399 &NumOfLoadFileHandles
,
1403 for (Index
= 0; Index
< NumOfLoadFileHandles
; Index
++) {
1406 //Locate EFI_DEVICE_PATH_PROTOCOL to dynamically get IPv4/IPv6 protocol information.
1409 Status
= gBS
->HandleProtocol (
1410 LoadFileHandles
[Index
],
1411 &gEfiDevicePathProtocolGuid
,
1412 (VOID
**) &DevicePath
1415 ASSERT_EFI_ERROR (Status
);
1417 while (!IsDevicePathEnd (DevicePath
)) {
1418 if ((DevicePath
->Type
== MESSAGING_DEVICE_PATH
) &&
1419 (DevicePath
->SubType
== MSG_IPv4_DP
)) {
1422 //Get handle infomation
1425 NetworkHandles
= NULL
;
1426 Status
= gBS
->LocateHandle (
1428 &gEfiSimpleNetworkProtocolGuid
,
1434 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1435 NetworkHandles
= AllocateZeroPool(BufferSize
);
1436 if (NetworkHandles
== NULL
) {
1437 return (EFI_OUT_OF_RESOURCES
);
1439 Status
= gBS
->LocateHandle(
1441 &gEfiSimpleNetworkProtocolGuid
,
1449 //Get the MAC string
1451 Status
= NetLibGetMacString (
1456 if (EFI_ERROR (Status
)) {
1459 IPverStr
= L
" IPv4";
1460 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK
)),MacStr
,IPverStr
);
1463 if((DevicePath
->Type
== MESSAGING_DEVICE_PATH
) &&
1464 (DevicePath
->SubType
== MSG_IPv6_DP
)) {
1467 //Get handle infomation
1470 NetworkHandles
= NULL
;
1471 Status
= gBS
->LocateHandle (
1473 &gEfiSimpleNetworkProtocolGuid
,
1479 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1480 NetworkHandles
= AllocateZeroPool(BufferSize
);
1481 if (NetworkHandles
== NULL
) {
1482 return (EFI_OUT_OF_RESOURCES
);
1484 Status
= gBS
->LocateHandle(
1486 &gEfiSimpleNetworkProtocolGuid
,
1494 //Get the MAC string
1496 Status
= NetLibGetMacString (
1501 if (EFI_ERROR (Status
)) {
1504 IPverStr
= L
" IPv6";
1505 UnicodeSPrint (Buffer
, sizeof (Buffer
), L
"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK
)),MacStr
,IPverStr
);
1508 DevicePath
= NextDevicePathNode (DevicePath
);
1511 BdsLibBuildOptionFromHandle (LoadFileHandles
[Index
], BdsBootOptionList
, Buffer
);
1514 if (NumOfLoadFileHandles
!= 0) {
1515 FreePool (LoadFileHandles
);
1519 // Check if we have on flash shell
1521 /* gBS->LocateHandleBuffer (
1523 &gEfiFirmwareVolume2ProtocolGuid,
1528 for (Index = 0; Index < FvHandleCount; Index++) {
1529 gBS->HandleProtocol (
1530 FvHandleBuffer[Index],
1531 &gEfiFirmwareVolume2ProtocolGuid,
1535 Status = Fv->ReadFile (
1537 PcdGetPtr(PcdShellFile),
1542 &AuthenticationStatus
1544 if (EFI_ERROR (Status)) {
1546 // Skip if no shell file in the FV
1551 // Build the shell boot option
1553 BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList);
1556 if (FvHandleCount != 0) {
1557 FreePool (FvHandleBuffer);
1561 // Make sure every boot only have one time
1562 // boot device enumerate
1564 Status
= BdsLibBuildOptionFromVar (BdsBootOptionList
, L
"BootOrder");
1565 mEnumBootDevice
= TRUE
;
1574 The function will execute with as the platform policy, current policy
1575 is driven by boot mode. IBV/OEM can customize this code for their specific
1578 @param DriverOptionList - The header of the driver option link list
1579 @param BootOptionList - The header of the boot option link list
1580 @param ProcessCapsules - A pointer to ProcessCapsules()
1581 @param BaseMemoryTest - A pointer to BaseMemoryTest()
1588 PlatformBdsPolicyBehavior (
1589 IN OUT LIST_ENTRY
*DriverOptionList
,
1590 IN OUT LIST_ENTRY
*BootOptionList
,
1591 IN PROCESS_CAPSULES BdsProcessCapsules
,
1592 IN BASEM_MEMORY_TEST BaseMemoryTest
1597 EFI_BOOT_MODE BootMode
;
1598 BOOLEAN DeferredImageExist
;
1600 SYSTEM_CONFIGURATION SystemConfiguration
;
1602 PLATFORM_PCI_DEVICE_PATH
*EmmcBootDevPath
;
1603 EFI_GLOBAL_NVS_AREA_PROTOCOL
*GlobalNvsArea
;
1604 EFI_HANDLE FvProtocolHandle
;
1606 EFI_HANDLE
*HandleBuffer
;
1608 UINTN SataPciRegBase
= 0;
1609 UINT16 SataModeSelect
= 0;
1610 VOID
*RegistrationExitPmAuth
= NULL
;
1612 BOOLEAN IsFirstBoot
;
1614 UINTN BootOrderSize
;
1615 ESRT_MANAGEMENT_PROTOCOL
*EsrtManagement
;
1617 Timeout
= PcdGet16 (PcdPlatformBootTimeOut
);
1618 if (Timeout
> 10 ) {
1619 //we think the Timeout variable is corrupted
1623 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
1624 Status
= gRT
->GetVariable(
1626 &gEfiNormalSetupGuid
,
1629 &SystemConfiguration
1632 if (EFI_ERROR (Status
) || VarSize
!= sizeof(SYSTEM_CONFIGURATION
)) {
1633 //The setup variable is corrupted
1634 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
1635 Status
= gRT
->GetVariable(
1637 &gEfiNormalSetupGuid
,
1640 &SystemConfiguration
1642 ASSERT_EFI_ERROR (Status
);
1646 // Load the driver option as the driver option list
1648 PlatformBdsGetDriverOption (DriverOptionList
);
1651 // Get current Boot Mode
1653 BootMode
= GetBootModeHob();
1656 // No deferred images exist by default
1658 DeferredImageExist
= FALSE
;
1659 if ((BootMode
!= BOOT_WITH_MINIMAL_CONFIGURATION
) && (PcdGet32(PcdFlashFvShellSize
) > 0)){
1660 gDS
->ProcessFirmwareVolume (
1661 (VOID
*)(UINTN
)PcdGet32(PcdFlashFvShellBase
),
1662 PcdGet32(PcdFlashFvShellSize
),
1667 if (SystemConfiguration
.FastBoot
== 1) {
1668 BootOrder
= BdsLibGetVariableAndSize (
1670 &gEfiGlobalVariableGuid
,
1673 if ((BootOrder
!= NULL
) && (BootMode
!= BOOT_ON_FLASH_UPDATE
)) {
1675 // BootOrder exist, it means system has boot before. We can do fast boot.
1677 BootMode
= BOOT_WITH_MINIMAL_CONFIGURATION
;
1683 // Use eMMC to boot OS and turn on AHCI, when SATA HDD is diconnected,
1684 // SATA AHCI CTLR device will show yellow bang, implement this solution to solve it.
1686 SataPciRegBase
= MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA
, 0, 0);
1687 SataModeSelect
= MmioRead16 (SataPciRegBase
+ R_PCH_SATA_MAP
) & B_PCH_SATA_MAP_SMS_MASK
;
1688 Status
= EFI_SUCCESS
;
1689 if (SataModeSelect
!= V_PCH_SATA_MAP_SMS_IDE
) {
1690 Status
= gBS
->CreateEvent (
1697 if (!EFI_ERROR (Status
)) {
1698 Status
= gBS
->RegisterProtocolNotify (
1699 &gExitPmAuthProtocolGuid
,
1701 &RegistrationExitPmAuth
1706 Status
= gBS
->LocateProtocol(&gEsrtManagementProtocolGuid
, NULL
, (VOID
**)&EsrtManagement
);
1707 if (EFI_ERROR(Status
)) {
1708 EsrtManagement
= NULL
;
1713 case BOOT_WITH_MINIMAL_CONFIGURATION
:
1714 PlatformBdsInitHotKeyEvent ();
1715 PlatformBdsConnectSimpleConsole (gPlatformSimpleConsole
);
1719 // Check to see if it's needed to dispatch more DXE drivers.
1721 for (Index
= 0; Index
< sizeof(ConnectDriverTable
)/sizeof(EFI_GUID
*); Index
++) {
1722 Status
= gBS
->LocateHandleBuffer (
1724 ConnectDriverTable
[Index
],
1729 if (!EFI_ERROR (Status
)) {
1730 for (Index1
= 0; Index1
< HandleCount
; Index1
++) {
1731 gBS
->ConnectController (
1732 HandleBuffer
[Index1
],
1740 if (HandleBuffer
!= NULL
) {
1741 FreePool (HandleBuffer
);
1748 // Locate the Global NVS Protocol.
1750 Status
= gBS
->LocateProtocol (
1751 &gEfiGlobalNvsAreaProtocolGuid
,
1753 (void **)&GlobalNvsArea
1755 if (GlobalNvsArea
->Area
->emmcVersion
== 0){
1756 EmmcBootDevPath
= (PLATFORM_PCI_DEVICE_PATH
*)gPlatformSimpleBootOption
[0];
1757 EmmcBootDevPath
->PciDevice
.Device
= 0x10;
1761 // Connect boot device here to give time to read keyboard.
1763 BdsLibConnectDevicePath (gPlatformSimpleBootOption
[0]);
1766 // This is a workround for dectecting hotkey from USB keyboard.
1768 gBS
->Stall(KEYBOARD_TIMER_INTERVAL
);
1770 if (mHotKeyTimerEvent
!= NULL
) {
1776 gBS
->CloseEvent (mHotKeyTimerEvent
);
1777 mHotKeyTimerEvent
= NULL
;
1779 if (mHotKeyPressed
) {
1781 // Skip show progress count down
1784 goto FULL_CONFIGURATION
;
1787 if (SystemConfiguration
.QuietBoot
) {
1788 EnableQuietBoot (PcdGetPtr(PcdLogoFile
));
1790 PlatformBdsDiagnostics (IGNORE
, FALSE
, BaseMemoryTest
);
1795 TcgPhysicalPresenceLibProcessRequest();
1798 TrEEPhysicalPresenceLibProcessRequest(NULL
);
1801 if (EsrtManagement
!= NULL
) {
1802 EsrtManagement
->LockEsrtRepository();
1806 // Close boot script and install ready to lock
1808 InstallReadyToLock ();
1811 // Give one chance to enter the setup if we
1812 // select Gummiboot "Reboot Into Firmware Interface" and Fast Boot is enabled.
1814 BootIntoFirmwareInterface();
1817 case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES
:
1820 // In no-configuration boot mode, we can connect the
1821 // console directly.
1823 BdsLibConnectAllDefaultConsoles ();
1824 PlatformBdsDiagnostics (IGNORE
, TRUE
, BaseMemoryTest
);
1827 // Perform some platform specific connect sequence
1829 PlatformBdsConnectSequence ();
1832 // As console is ready, perform user identification again.
1834 if (mCurrentUser
== NULL
) {
1835 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1836 if (DeferredImageExist
) {
1838 // After user authentication, the deferred drivers was loaded again.
1839 // Here, need to ensure the deferred images are connected.
1841 BdsLibConnectAllDefaultConsoles ();
1842 PlatformBdsConnectSequence ();
1846 if (EsrtManagement
!= NULL
) {
1847 EsrtManagement
->LockEsrtRepository();
1851 // Close boot script and install ready to lock
1853 InstallReadyToLock ();
1856 // Notes: current time out = 0 can not enter the
1859 PlatformBdsEnterFrontPageWithHotKey (Timeout
, FALSE
);
1862 // Check the boot option with the boot option list
1864 BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
1867 case BOOT_ON_FLASH_UPDATE
:
1870 // Boot with the specific configuration
1872 PlatformBdsConnectConsole (gPlatformConsole
);
1873 PlatformBdsDiagnostics (EXTENSIVE
, FALSE
, BaseMemoryTest
);
1875 DEBUG((EFI_D_INFO
, "ProcessCapsules Before EndOfDxe......\n"));
1877 DEBUG((EFI_D_INFO
, "ProcessCapsules Done\n"));
1880 // Close boot script and install ready to lock
1882 InstallReadyToLock ();
1884 BdsLibConnectAll ();
1887 // Perform user identification
1889 if (mCurrentUser
== NULL
) {
1890 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1891 if (DeferredImageExist
) {
1893 // After user authentication, the deferred drivers was loaded again.
1894 // Here, need to ensure the deferred images are connected.
1896 BdsLibConnectAll ();
1900 if (EsrtManagement
!= NULL
) {
1901 EsrtManagement
->SyncEsrtFmp();
1904 DEBUG((EFI_D_INFO
, "ProcessCapsules After ConnectAll......\n"));
1906 DEBUG((EFI_D_INFO
, "ProcessCapsules Done\n"));
1909 case BOOT_IN_RECOVERY_MODE
:
1912 // In recovery mode, just connect platform console
1913 // and show up the front page
1915 PlatformBdsConnectConsole (gPlatformConsole
);
1916 PlatformBdsDiagnostics (EXTENSIVE
, FALSE
, BaseMemoryTest
);
1917 BdsLibConnectAll ();
1920 // Perform user identification
1922 if (mCurrentUser
== NULL
) {
1923 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1924 if (DeferredImageExist
) {
1926 // After user authentication, the deferred drivers was loaded again.
1927 // Here, need to ensure the deferred drivers are connected.
1929 BdsLibConnectAll ();
1934 // Close boot script and install ready to lock
1936 InstallReadyToLock ();
1939 // In recovery boot mode, we still enter to the
1942 PlatformBdsEnterFrontPageWithHotKey (Timeout
, FALSE
);
1946 case BOOT_WITH_FULL_CONFIGURATION
:
1947 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS
:
1948 case BOOT_WITH_DEFAULT_SETTINGS
:
1952 // Connect platform console
1954 Status
= PlatformBdsConnectConsole (gPlatformConsole
);
1955 if (EFI_ERROR (Status
)) {
1958 // Here OEM/IBV can customize with defined action
1960 PlatformBdsNoConsoleAction ();
1964 // Chenyunh[TODO]: This is Workgroud to show the fs for uSDcard,
1965 // Need to root cause this issue.
1967 DEBUG ((DEBUG_ERROR
, "Start to reconnect all driver.\n"));
1968 BdsLibDisconnectAllEfi();
1969 BdsLibConnectAll ();
1970 DEBUG ((DEBUG_ERROR
, "End to reconnect all driver.\n"));
1973 // Perform some platform specific connect sequence
1975 PlatformBdsConnectSequence ();
1976 if (SystemConfiguration
.QuietBoot
) {
1977 EnableQuietBoot (PcdGetPtr(PcdLogoFile
));
1979 PlatformBdsDiagnostics (IGNORE
, FALSE
, BaseMemoryTest
);
1983 // Do a pre-delay so Hard Disk can spin up and see more logo.
1985 gBS
->Stall(SystemConfiguration
.HddPredelay
* 1000000);
1988 // Perform user identification
1990 if (mCurrentUser
== NULL
) {
1991 PlatformBdsUserIdentify (&mCurrentUser
, &DeferredImageExist
);
1992 if (DeferredImageExist
) {
1994 // After user authentication, the deferred drivers was loaded again.
1995 // Here, need to ensure the deferred drivers are connected.
1997 Status
= PlatformBdsConnectConsole (gPlatformConsole
);
1998 if (EFI_ERROR (Status
)) {
1999 PlatformBdsNoConsoleAction ();
2001 PlatformBdsConnectSequence ();
2005 TcgPhysicalPresenceLibProcessRequest();
2008 TrEEPhysicalPresenceLibProcessRequest(NULL
);
2011 if (EsrtManagement
!= NULL
) {
2012 EsrtManagement
->SyncEsrtFmp();
2015 // Close boot script and install ready to lock
2017 InstallReadyToLock ();
2020 // Here we have enough time to do the enumeration of boot device
2022 PlatformBdsLibEnumerateAllBootOption (BootOptionList
);
2025 // Give one chance to enter the setup if we
2026 // have the time out
2028 PlatformBdsEnterFrontPageWithHotKey (Timeout
, FALSE
);
2031 // Give one chance to enter the setup if we
2032 // select Gummiboot "Reboot Into Firmware Interface"
2034 BootIntoFirmwareInterface();
2037 // In default boot mode, always find all boot
2038 // option and do enumerate all the default boot option
2041 BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
2042 if (IsListEmpty(BootOptionList
)) {
2043 PlatformBdsPredictBootOption (BootOptionList
);
2054 IsFirstBoot
= PcdGetBool(PcdBootState
);
2056 PcdSetBool(PcdBootState
, FALSE
);
2063 Hook point after a boot attempt succeeds. We don't expect a boot option to
2064 return, so the UEFI 2.0 specification defines that you will default to an
2065 interactive mode and stop processing the BootOrder list in this case. This
2066 is alos a platform implementation and can be customized by IBV/OEM.
2068 @param Option Pointer to Boot Option that succeeded to boot.
2075 PlatformBdsBootSuccess (
2076 IN BDS_COMMON_OPTION
*Option
2082 // If Boot returned with EFI_SUCCESS and there is not in the boot device
2083 // select loop then we need to pop up a UI and wait for user input.
2085 TmpStr
= Option
->StatusString
;
2086 if (TmpStr
!= NULL
) {
2087 BdsLibOutputStrings (gST
->ConOut
, TmpStr
, Option
->Description
, L
"\n\r", NULL
);
2093 Hook point after a boot attempt fails.
2095 @param Option - Pointer to Boot Option that failed to boot.
2096 @param Status - Status returned from failed boot.
2097 @param ExitData - Exit data returned from failed boot.
2098 @param ExitDataSize - Exit data size returned from failed boot.
2105 PlatformBdsBootFail (
2106 IN BDS_COMMON_OPTION
*Option
,
2107 IN EFI_STATUS Status
,
2108 IN CHAR16
*ExitData
,
2109 IN UINTN ExitDataSize
2113 EFI_HANDLE FvProtocolHandle
;
2116 // If Boot returned with failed status then we need to pop up a UI and wait
2119 TmpStr
= Option
->StatusString
;
2120 if (TmpStr
!= NULL
) {
2121 BdsLibOutputStrings (gST
->ConOut
, TmpStr
, Option
->Description
, L
"\n\r", NULL
);
2124 if (PcdGet32(PcdFlashFvShellSize
) > 0){
2125 gDS
->ProcessFirmwareVolume (
2126 (VOID
*)(UINTN
)PcdGet32(PcdFlashFvShellBase
),
2127 PcdGet32(PcdFlashFvShellSize
),
2131 PlatformBdsConnectSequence ();
2135 This function is remained for IBV/OEM to do some platform action,
2136 if there no console device can be connected.
2140 @retval EFI_SUCCESS Direct return success now.
2144 PlatformBdsNoConsoleAction (
2152 This function locks the block
2154 @param Base The base address flash region to be locked.
2159 IN EFI_PHYSICAL_ADDRESS Base
2162 EFI_FV_BLOCK_MAP_ENTRY
*BlockMap
;
2163 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
2164 EFI_PHYSICAL_ADDRESS BaseAddress
;
2168 BaseAddress
= Base
- 0x400000 + 2;
2169 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) ((UINTN
) (Base
));
2170 BlockMap
= &(FvHeader
->BlockMap
[0]);
2172 while ((BlockMap
->NumBlocks
!= 0) && (BlockMap
->Length
!= 0)) {
2173 BlockLength
= BlockMap
->Length
;
2174 for (Index
= 0; Index
< BlockMap
->NumBlocks
; Index
++) {
2175 MmioOr8 ((UINTN
) BaseAddress
, 0x03);
2176 BaseAddress
+= BlockLength
;
2184 PlatformBdsLockNonUpdatableFlash (
2188 EFI_PHYSICAL_ADDRESS Base
;
2190 Base
= (EFI_PHYSICAL_ADDRESS
) PcdGet32 (PcdFlashFvMainBase
);
2195 Base
= (EFI_PHYSICAL_ADDRESS
) PcdGet32 (PcdFlashFvRecoveryBase
);
2202 Lock the ConsoleIn device in system table. All key
2203 presses will be ignored until the Password is typed in. The only way to
2204 disable the password is to type it in to a ConIn device.
2206 @param Password Password used to lock ConIn device.
2208 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
2209 @retval EFI_UNSUPPORTED Password not found
2218 return EFI_UNSUPPORTED
;
2222 Connect the predefined platform default authentication devices.
2224 This function connects the predefined device path for authentication device,
2225 and if the predefined device path has child device path, the child handle will
2226 be connected too. But the child handle of the child will not be connected.
2231 PlatformBdsConnectAuthDevice (
2239 EFI_HANDLE
*HandleBuffer
;
2240 EFI_DEVICE_PATH_PROTOCOL
*ChildDevicePath
;
2241 EFI_USER_MANAGER_PROTOCOL
*Manager
;
2243 Status
= gBS
->LocateProtocol (
2244 &gEfiUserManagerProtocolGuid
,
2248 if (EFI_ERROR (Status
)) {
2250 // As user manager protocol is not installed, the authentication devices
2251 // should not be connected.
2257 while (gUserAuthenticationDevice
[Index
] != NULL
) {
2259 // Connect the platform customized device paths
2261 BdsLibConnectDevicePath (gUserAuthenticationDevice
[Index
]);
2266 // Find and connect the child device paths of the platform customized device paths
2268 HandleBuffer
= NULL
;
2269 for (Index
= 0; gUserAuthenticationDevice
[Index
] != NULL
; Index
++) {
2271 Status
= gBS
->LocateHandleBuffer (
2278 ASSERT (!EFI_ERROR (Status
));
2281 // Find and connect the child device paths of gUserIdentificationDevice[Index]
2283 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
2284 ChildDevicePath
= NULL
;
2285 Status
= gBS
->HandleProtocol (
2286 HandleBuffer
[HandleIndex
],
2287 &gEfiDevicePathProtocolGuid
,
2288 (VOID
**) &ChildDevicePath
2290 if (EFI_ERROR (Status
) || ChildDevicePath
== NULL
) {
2296 gUserAuthenticationDevice
[Index
],
2297 (GetDevicePathSize (gUserAuthenticationDevice
[Index
]) - sizeof (EFI_DEVICE_PATH_PROTOCOL
))
2301 gBS
->ConnectController (
2302 HandleBuffer
[HandleIndex
],
2310 if (HandleBuffer
!= NULL
) {
2311 FreePool (HandleBuffer
);
2316 This function is to identify a user, and return whether deferred images exist.
2318 @param[out] User Point to user profile handle.
2319 @param[out] DeferredImageExist On return, points to TRUE if the deferred image
2320 exist or FALSE if it did not exist.
2325 PlatformBdsUserIdentify (
2326 OUT EFI_USER_PROFILE_HANDLE
*User
,
2327 OUT BOOLEAN
*DeferredImageExist
2331 EFI_DEFERRED_IMAGE_LOAD_PROTOCOL
*DeferredImage
;
2333 EFI_HANDLE
*HandleBuf
;
2336 EFI_DEVICE_PATH_PROTOCOL
*ImageDevicePath
;
2342 // Perform user identification
2345 Status
= BdsLibUserIdentify (User
);
2346 } while (EFI_ERROR (Status
));
2349 // After user authentication now, try to find whether deferred image exists
2353 *DeferredImageExist
= FALSE
;
2354 Status
= gBS
->LocateHandleBuffer (
2356 &gEfiDeferredImageLoadProtocolGuid
,
2361 if (EFI_ERROR (Status
)) {
2365 for (Index
= 0; Index
< HandleCount
; Index
++) {
2366 Status
= gBS
->HandleProtocol (
2368 &gEfiDeferredImageLoadProtocolGuid
,
2369 (VOID
**) &DeferredImage
2371 if (!EFI_ERROR (Status
)) {
2373 // Find whether deferred image exists in this instance.
2376 Status
= DeferredImage
->GetImageInfo(
2380 (VOID
**) &DriverImage
,
2384 if (!EFI_ERROR (Status
)) {
2386 // The deferred image is found.
2388 FreePool (HandleBuf
);
2389 *DeferredImageExist
= TRUE
;
2395 FreePool (HandleBuf
);
2402 ShowProgressHotKey (
2403 IN UINT16 TimeoutDefault
2407 UINT16 TimeoutRemain
;
2410 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
2411 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
2412 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
2415 if (TimeoutDefault
== 0) {
2419 gST
->ConOut
->SetAttribute(gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
2421 if (DebugAssertEnabled())
2423 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"));
2428 SerialPortWrite((UINT8
*)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)[GCC]", 76);
2430 SerialPortWrite((UINT8
*)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)", 71);
2433 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
2434 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
2435 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
2438 // Clear the progress status bar first
2440 TmpStr
= L
"Start boot option, Press <F2> or <DEL> to enter setup page.";
2441 PlatformBdsShowProgress (Foreground
, Background
, TmpStr
, Color
, 0, 0);
2443 TimeoutRemain
= TimeoutDefault
;
2444 while (TimeoutRemain
!= 0) {
2445 if (DebugAssertEnabled())
2447 DEBUG ((EFI_D_INFO
, "Showing progress bar...Remaining %d second!\n", TimeoutRemain
));
2451 SerialPortWrite ((UINT8
*)".", 1);
2453 Status
= WaitForSingleEvent (gST
->ConIn
->WaitForKey
, ONE_SECOND
);
2454 if (Status
!= EFI_TIMEOUT
) {
2462 if (TmpStr
!= NULL
) {
2463 PlatformBdsShowProgress (
2468 ((TimeoutDefault
- TimeoutRemain
) * 100 / TimeoutDefault
),
2477 if (TimeoutRemain
== 0) {
2478 if (DebugAssertEnabled())
2483 SerialPortWrite ((UINT8
*)"\r\n", 2);
2489 // User pressed some key
2491 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2492 if (EFI_ERROR (Status
)) {
2497 // Check Volume Up Key to enter Setup
2499 GpioValue
= MmioRead32 (IO_BASE_ADDRESS
+ 0x0668); // The value of GPIOC_5
2500 if (((GpioValue
& BIT0
) == 0) && (Key
.ScanCode
== SCAN_UP
)) {
2505 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
2507 // User pressed enter, equivalent to select "continue"
2514 //F5 -- Device Manager
2515 //F7 -- Boot Manager
2516 // do not use F8. generally people assume it is windows safe mode key.
2519 DEBUG ((EFI_D_INFO
, "[Key Pressed]: ScanCode 0x%x\n", Key
.ScanCode
));
2520 switch(Key
.ScanCode
) {
2530 gHotKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
2534 gHotKey
= FRONT_PAGE_KEY_BOOT_MANAGER
;
2538 gHotKey
= FRONT_PAGE_KEY_BOOT_MAINTAIN
;
2542 //set gHotKey to continue so that flow will not go into CallFrontPage
2543 gHotKey
= FRONT_PAGE_KEY_CONTINUE
;
2554 This function is the main entry of the platform setup entry.
2555 The function will present the main menu of the system setup,
2556 this is the platform reference part and can be customize.
2559 @param TimeoutDefault The fault time out value before the system
2561 @param ConnectAllHappened The indicater to check if the connect all have
2566 PlatformBdsEnterFrontPageWithHotKey (
2567 IN UINT16 TimeoutDefault
,
2568 IN BOOLEAN ConnectAllHappened
2573 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
2574 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
2575 UINTN BootTextColumn
;
2578 GraphicsOutput
= NULL
;
2579 SimpleTextOut
= NULL
;
2581 PERF_START (NULL
, "BdsTimeOut", "BDS", 0);
2584 // Indicate if we need connect all in the platform setup
2586 if (ConnectAllHappened
) {
2587 gConnectAllHappened
= TRUE
;
2590 if (!mModeInitialized
) {
2592 // After the console is ready, get current video resolution
2593 // and text mode before launching setup at first time.
2595 Status
= gBS
->HandleProtocol (
2596 gST
->ConsoleOutHandle
,
2597 &gEfiGraphicsOutputProtocolGuid
,
2598 (VOID
**)&GraphicsOutput
2600 if (EFI_ERROR (Status
)) {
2601 GraphicsOutput
= NULL
;
2604 Status
= gBS
->HandleProtocol (
2605 gST
->ConsoleOutHandle
,
2606 &gEfiSimpleTextOutProtocolGuid
,
2607 (VOID
**)&SimpleTextOut
2609 if (EFI_ERROR (Status
)) {
2610 SimpleTextOut
= NULL
;
2613 if (GraphicsOutput
!= NULL
) {
2615 // Get current video resolution and text mode.
2617 mBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
2618 mBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
2621 if (SimpleTextOut
!= NULL
) {
2622 Status
= SimpleTextOut
->QueryMode (
2624 SimpleTextOut
->Mode
->Mode
,
2628 mBootTextModeColumn
= (UINT32
)BootTextColumn
;
2629 mBootTextModeRow
= (UINT32
)BootTextRow
;
2633 // Get user defined text mode for setup.
2635 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
2636 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
2637 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
2638 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
2640 mModeInitialized
= TRUE
;
2643 if (TimeoutDefault
!= 0xffff) {
2644 Status
= ShowProgressHotKey (TimeoutDefault
);
2647 // Ensure screen is clear when switch Console from Graphics mode to Text mode
2649 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
2650 gST
->ConOut
->ClearScreen (gST
->ConOut
);
2652 if (EFI_ERROR (Status
)) {
2654 // Timeout or user press enter to continue
2660 // Install BM HiiPackages.
2661 // Keep BootMaint HiiPackage, so that it can be covered by global setting.
2666 BdsSetConsoleMode (TRUE
);
2668 InitializeFrontPage (FALSE
);
2671 // Update Front Page strings
2673 UpdateFrontPageStrings ();
2675 Status
= EFI_SUCCESS
;
2678 Status
= CallFrontPage ();
2680 gCallbackKey
= gHotKey
;
2685 // If gCallbackKey is greater than 1 and less or equal to 5,
2686 // it will launch configuration utilities.
2689 // 4 = device manager
2690 // 5 = boot maintenance manager
2692 if (gCallbackKey
!= 0) {
2693 REPORT_STATUS_CODE (
2695 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
2700 // Based on the key that was set, we can determine what to do
2702 switch (gCallbackKey
) {
2704 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
2705 // describe to their customers in documentation how to find their setup information (namely
2706 // under the device manager and specific buckets)
2708 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager
2710 case FRONT_PAGE_KEY_CONTINUE
:
2713 // User hit continue
2717 case FRONT_PAGE_KEY_LANGUAGE
:
2720 // User made a language setting change - display front page again
2724 case FRONT_PAGE_KEY_BOOT_MANAGER
:
2726 // Remove the installed BootMaint HiiPackages when exit.
2731 // User chose to run the Boot Manager
2736 // Reinstall BootMaint HiiPackages after exiting from Boot Manager.
2741 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
2744 // Display the Device Manager
2747 CallDeviceManager ();
2748 } while (gCallbackKey
== FRONT_PAGE_KEY_DEVICE_MANAGER
);
2751 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
2754 // Display the Boot Maintenance Manager
2756 BdsStartBootMaint ();
2760 } while (((UINTN
)gCallbackKey
) != FRONT_PAGE_KEY_CONTINUE
);
2763 //Will leave browser, check any reset required change is applied? if yes, reset system
2765 SetupResetReminder ();
2767 // Remove the installed BootMaint HiiPackages when exit.
2773 // Automatically load current entry
2774 // Note: The following lines of code only execute when Auto boot
2777 PERF_END (NULL
, "BdsTimeOut", "BDS", 0);
2782 BootIntoFirmwareInterface(
2789 UINT64 OsIndication
;
2793 DataSize
= sizeof(UINT64
);
2794 Status
= gRT
->GetVariable (
2796 &gEfiGlobalVariableGuid
,
2802 DEBUG ((EFI_D_INFO
, "OSIndication Variable Value %d\n", OsIndication
));
2804 //Goto FrontPage directly when bit EFI_OS_INDICATIONS_BOOT_TO_FW_UI in OSIndication Variable is setted.
2806 if (!EFI_ERROR(Status
) && (OsIndication
!= 0)) {
2808 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
2814 PlatformBdsConnectSimpleConsole (
2815 IN BDS_CONSOLE_CONNECT_ENTRY
*PlatformConsole
2820 EFI_DEVICE_PATH_PROTOCOL
*VarConout
;
2821 EFI_DEVICE_PATH_PROTOCOL
*VarConin
;
2822 UINTN DevicePathSize
;
2826 Status
= EFI_SUCCESS
;
2828 VarConout
= BdsLibGetVariableAndSize (
2830 &gEfiGlobalVariableGuid
,
2833 VarConin
= BdsLibGetVariableAndSize (
2835 &gEfiGlobalVariableGuid
,
2838 if (VarConout
== NULL
|| VarConin
== NULL
) {
2840 // Have chance to connect the platform default console,
2841 // the platform default console is the minimum device group
2842 // the platform should support
2844 while (PlatformConsole
[Index
].DevicePath
!= NULL
) {
2847 // Update the console variable with the connect type
2849 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
2850 BdsLibUpdateConsoleVariable (L
"ConIn", PlatformConsole
[Index
].DevicePath
, NULL
);
2853 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
2854 BdsLibUpdateConsoleVariable (L
"ConOut", PlatformConsole
[Index
].DevicePath
, NULL
);
2857 if ((PlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
2858 BdsLibUpdateConsoleVariable (L
"ErrOut", PlatformConsole
[Index
].DevicePath
, NULL
);
2866 // Connect ConIn first to give keyboard time to parse hot key event.
2868 Status
= BdsLibConnectConsoleVariable (L
"ConIn");
2869 if (EFI_ERROR (Status
)) {
2874 // Make sure we have at least one active VGA, and have the right
2875 // active VGA in console variable
2877 Status
= PlatformBdsForceActiveVga ();
2880 // It seems impossible not to have any ConOut device on platform,
2881 // so we check the status here.
2883 Status
= BdsLibConnectConsoleVariable (L
"ConOut");
2884 if (EFI_ERROR (Status
)) {
2893 Timer handler to convert the key from USB.
2895 @param Event Indicates the event that invoke this function.
2896 @param Context Indicates the calling context.
2900 HotKeyTimerHandler (
2908 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2909 if (EFI_ERROR (Status
)) {
2913 switch(Key
.ScanCode
) {
2916 mHotKeyPressed
= TRUE
;
2920 gHotKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
2921 mHotKeyPressed
= TRUE
;
2925 gHotKey
= FRONT_PAGE_KEY_BOOT_MANAGER
;
2926 mHotKeyPressed
= TRUE
;
2930 gHotKey
= FRONT_PAGE_KEY_BOOT_MAINTAIN
;
2931 mHotKeyPressed
= TRUE
;
2935 if (mHotKeyPressed
) {
2941 gBS
->CloseEvent (mHotKeyTimerEvent
);
2942 mHotKeyTimerEvent
= NULL
;
2950 Callback function for SimpleTextInEx protocol install events
2952 @param Event the event that is signaled.
2953 @param Context not used here.
2965 Status
= gBS
->CloseEvent(mHitHotkeyEvent
);
2966 if (EFI_ERROR (Status
)) {
2969 Status
= gBS
->CreateEvent (
2970 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
2976 if (EFI_ERROR (Status
)) {
2979 Status
= gBS
->SetTimer (
2982 KEYBOARD_TIMER_INTERVAL
2984 if (EFI_ERROR (Status
)) {
2994 PlatformBdsInitHotKeyEvent (
3001 // Register Protocol notify for Hotkey service
3003 Status
= gBS
->CreateEvent (
3010 ASSERT_EFI_ERROR (Status
);
3013 // Register for protocol notifications on this event
3015 Status
= gBS
->RegisterProtocolNotify (
3016 &gEfiSimpleTextInputExProtocolGuid
,
3018 &mHitHotkeyRegistration
3020 ASSERT_EFI_ERROR (Status
);