2 This module produce main entry for BDS phase - BdsEntry.
3 When this module was dispatched by DxeCore, gEfiBdsArchProtocolGuid will be installed
4 which contains interface of BdsEntry.
5 After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry will be invoked
8 Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
9 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
10 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
11 This program and the accompanying materials
12 are licensed and made available under the terms and conditions of the BSD License
13 which accompanies this distribution. The full text of the license may be found at
14 http://opensource.org/licenses/bsd-license.php
16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
23 #include "HwErrRecSupport.h"
25 #define SET_BOOT_OPTION_SUPPORT_KEY_COUNT(a, c) { \
26 (a) = ((a) & ~EFI_BOOT_OPTION_SUPPORT_COUNT) | (((c) << LowBitSet32 (EFI_BOOT_OPTION_SUPPORT_COUNT)) & EFI_BOOT_OPTION_SUPPORT_COUNT); \
30 /// BDS arch protocol instance initial value.
32 EFI_BDS_ARCH_PROTOCOL gBds
= {
37 // gConnectConInEvent - Event which is signaled when ConIn connection is required
39 EFI_EVENT gConnectConInEvent
= NULL
;
42 /// The read-only variables defined in UEFI Spec.
44 CHAR16
*mReadOnlyVariables
[] = {
45 EFI_PLATFORM_LANG_CODES_VARIABLE_NAME
,
46 EFI_LANG_CODES_VARIABLE_NAME
,
47 EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME
,
48 EFI_HW_ERR_REC_SUPPORT_VARIABLE_NAME
,
49 EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME
52 CHAR16
*mBdsLoadOptionName
[] = {
60 Event to Connect ConIn.
62 @param Event Event whose notification function is being invoked.
63 @param Context Pointer to the notification function's context,
64 which is implementation-dependent.
69 BdsDxeOnConnectConInCallBack (
77 // When Osloader call ReadKeyStroke to signal this event
78 // no driver dependency is assumed existing. So use a non-dispatch version
80 Status
= EfiBootManagerConnectConsoleVariable (ConIn
);
81 if (EFI_ERROR (Status
)) {
83 // Should not enter this case, if enter, the keyboard will not work.
84 // May need platfrom policy to connect keyboard.
86 DEBUG ((EFI_D_WARN
, "[Bds] Connect ConIn failed - %r!!!\n", Status
));
92 Install Boot Device Selection Protocol
94 @param ImageHandle The image handle.
95 @param SystemTable The system table.
97 @retval EFI_SUCEESS BDS has finished initializing.
98 Return the dispatcher and recall BDS.Entry
99 @retval Other Return status from AllocatePool() or gBS->InstallProtocolInterface
105 IN EFI_HANDLE ImageHandle
,
106 IN EFI_SYSTEM_TABLE
*SystemTable
112 // Install protocol interface
115 Status
= gBS
->InstallMultipleProtocolInterfaces (
117 &gEfiBdsArchProtocolGuid
, &gBds
,
120 ASSERT_EFI_ERROR (Status
);
126 Function waits for a given event to fire, or for an optional timeout to expire.
128 @param Event The event to wait for
129 @param Timeout An optional timeout value in 100 ns units.
131 @retval EFI_SUCCESS Event fired before Timeout expired.
132 @retval EFI_TIME_OUT Timout expired before Event fired..
136 BdsWaitForSingleEvent (
138 IN UINT64 Timeout OPTIONAL
143 EFI_EVENT TimerEvent
;
144 EFI_EVENT WaitList
[2];
148 // Create a timer event
150 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
151 if (!EFI_ERROR (Status
)) {
153 // Set the timer event
162 // Wait for the original event or the timer
165 WaitList
[1] = TimerEvent
;
166 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
167 ASSERT_EFI_ERROR (Status
);
168 gBS
->CloseEvent (TimerEvent
);
171 // If the timer expired, change the return to timed out
174 Status
= EFI_TIMEOUT
;
179 // No timeout... just wait on the event
181 Status
= gBS
->WaitForEvent (1, &Event
, &Index
);
182 ASSERT (!EFI_ERROR (Status
));
190 The function reads user inputs.
201 if (PcdGetBool (PcdConInConnectOnDemand
)) {
205 while (gST
->ConIn
!= NULL
) {
207 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
209 if (EFI_ERROR (Status
)) {
219 The function waits for the boot manager timeout expires or hotkey is pressed.
221 It calls PlatformBootManagerWaitCallback each second.
223 @param HotkeyTriggered Input hotkey event.
227 IN EFI_EVENT HotkeyTriggered
231 UINT16 TimeoutRemain
;
233 DEBUG ((EFI_D_INFO
, "[Bds]BdsWait ...Zzzzzzzzzzzz...\n"));
235 TimeoutRemain
= PcdGet16 (PcdPlatformBootTimeOut
);
236 while (TimeoutRemain
!= 0) {
237 DEBUG ((EFI_D_INFO
, "[Bds]BdsWait(%d)..Zzzz...\n", (UINTN
) TimeoutRemain
));
238 PlatformBootManagerWaitCallback (TimeoutRemain
);
240 BdsReadKeys (); // BUGBUG: Only reading can signal HotkeyTriggered
241 // Can be removed after all keyboard drivers invoke callback in timer callback.
243 if (HotkeyTriggered
!= NULL
) {
244 Status
= BdsWaitForSingleEvent (HotkeyTriggered
, EFI_TIMER_PERIOD_SECONDS (1));
245 if (!EFI_ERROR (Status
)) {
249 gBS
->Stall (1000000);
253 // 0xffff means waiting forever
254 // BDS with no hotkey provided and 0xffff as timeout will "hang" in the loop
256 if (TimeoutRemain
!= 0xffff) {
260 DEBUG ((EFI_D_INFO
, "[Bds]Exit the waiting!\n"));
264 Attempt to boot each boot option in the BootOptions array.
266 @param BootOptions Input boot option array.
267 @param BootOptionCount Input boot option count.
268 @param BootManagerMenu Input boot manager menu.
270 @retval TRUE Successfully boot one of the boot options.
271 @retval FALSE Failed boot any of the boot options.
275 IN EFI_BOOT_MANAGER_LOAD_OPTION
*BootOptions
,
276 IN UINTN BootOptionCount
,
277 IN EFI_BOOT_MANAGER_LOAD_OPTION
*BootManagerMenu OPTIONAL
283 // Attempt boot each boot option
285 for (Index
= 0; Index
< BootOptionCount
; Index
++) {
287 // According to EFI Specification, if a load option is not marked
288 // as LOAD_OPTION_ACTIVE, the boot manager will not automatically
291 if ((BootOptions
[Index
].Attributes
& LOAD_OPTION_ACTIVE
) == 0) {
296 // Boot#### load options with LOAD_OPTION_CATEGORY_APP are executables which are not
297 // part of the normal boot processing. Boot options with reserved category values will be
298 // ignored by the boot manager.
300 if ((BootOptions
[Index
].Attributes
& LOAD_OPTION_CATEGORY
) != LOAD_OPTION_CATEGORY_BOOT
) {
305 // All the driver options should have been processed since
306 // now boot will be performed.
308 EfiBootManagerBoot (&BootOptions
[Index
]);
311 // If the boot via Boot#### returns with a status of EFI_SUCCESS, platform firmware
312 // supports boot manager menu, and if firmware is configured to boot in an
313 // interactive mode, the boot manager will stop processing the BootOrder variable and
314 // present a boot manager menu to the user.
316 if ((BootManagerMenu
!= NULL
) && (BootOptions
[Index
].Status
== EFI_SUCCESS
)) {
317 EfiBootManagerBoot (BootManagerMenu
);
322 return (BOOLEAN
) (Index
< BootOptionCount
);
326 The function will load and start every Driver####, SysPrep#### or PlatformRecovery####.
328 @param LoadOptions Load option array.
329 @param LoadOptionCount Load option count.
333 IN EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOptions
,
334 IN UINTN LoadOptionCount
339 BOOLEAN ReconnectAll
;
340 EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType
;
342 ReconnectAll
= FALSE
;
343 LoadOptionType
= LoadOptionTypeMax
;
346 // Process the driver option
348 for (Index
= 0; Index
< LoadOptionCount
; Index
++) {
350 // All the load options in the array should be of the same type.
353 LoadOptionType
= LoadOptions
[Index
].OptionType
;
355 ASSERT (LoadOptionType
== LoadOptions
[Index
].OptionType
);
357 Status
= EfiBootManagerProcessLoadOption (&LoadOptions
[Index
]);
359 if (!EFI_ERROR (Status
)) {
360 if (LoadOptionType
== LoadOptionTypePlatformRecovery
) {
362 // Stop processing if any entry is successful
366 if ((LoadOptions
[Index
].Attributes
& LOAD_OPTION_FORCE_RECONNECT
) != 0) {
373 // If a driver load option is marked as LOAD_OPTION_FORCE_RECONNECT,
374 // then all of the EFI drivers in the system will be disconnected and
375 // reconnected after the last driver load option is processed.
377 if (ReconnectAll
&& LoadOptionType
== LoadOptionTypeDriver
) {
378 EfiBootManagerDisconnectAll ();
379 EfiBootManagerConnectAll ();
385 Validate input console variable data.
387 If found the device path is not a valid device path, remove the variable.
389 @param VariableName Input console variable name.
393 BdsFormalizeConsoleVariable (
394 IN CHAR16
*VariableName
397 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
401 GetEfiGlobalVariable2 (VariableName
, (VOID
**) &DevicePath
, &VariableSize
);
402 if ((DevicePath
!= NULL
) && !IsDevicePathValid (DevicePath
, VariableSize
)) {
403 Status
= gRT
->SetVariable (
405 &gEfiGlobalVariableGuid
,
406 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
411 // Deleting variable with current variable implementation shouldn't fail.
413 ASSERT_EFI_ERROR (Status
);
416 if (DevicePath
!= NULL
) {
417 FreePool (DevicePath
);
422 Formalize OsIndication related variables.
424 For OsIndicationsSupported, Create a BS/RT/UINT64 variable to report caps
425 Delete OsIndications variable if it is not NV/BS/RT UINT64.
427 Item 3 is used to solve case when OS corrupts OsIndications. Here simply delete this NV variable.
429 Create a boot option for BootManagerMenu if it hasn't been created yet
433 BdsFormalizeOSIndicationVariable (
438 UINT64 OsIndicationSupport
;
442 EFI_BOOT_MANAGER_LOAD_OPTION BootManagerMenu
;
445 // OS indicater support variable
447 Status
= EfiBootManagerGetBootManagerMenu (&BootManagerMenu
);
448 if (Status
!= EFI_NOT_FOUND
) {
449 OsIndicationSupport
= EFI_OS_INDICATIONS_BOOT_TO_FW_UI
| EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY
;
450 EfiBootManagerFreeLoadOption (&BootManagerMenu
);
452 OsIndicationSupport
= EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY
;
455 Status
= gRT
->SetVariable (
456 EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME
,
457 &gEfiGlobalVariableGuid
,
458 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
463 // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.
465 ASSERT_EFI_ERROR (Status
);
468 // If OsIndications is invalid, remove it.
470 // 1. Data size != UINT64
471 // 2. OsIndication value inconsistence
472 // 3. OsIndication attribute inconsistence
476 DataSize
= sizeof(UINT64
);
477 Status
= gRT
->GetVariable (
478 EFI_OS_INDICATIONS_VARIABLE_NAME
,
479 &gEfiGlobalVariableGuid
,
484 if (Status
== EFI_NOT_FOUND
) {
488 if ((DataSize
!= sizeof (OsIndication
)) ||
489 ((OsIndication
& ~OsIndicationSupport
) != 0) ||
490 (Attributes
!= (EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
))
493 DEBUG ((EFI_D_ERROR
, "[Bds] Unformalized OsIndications variable exists. Delete it\n"));
494 Status
= gRT
->SetVariable (
495 EFI_OS_INDICATIONS_VARIABLE_NAME
,
496 &gEfiGlobalVariableGuid
,
502 // Deleting variable with current variable implementation shouldn't fail.
504 ASSERT_EFI_ERROR(Status
);
514 BdsFormalizeEfiGlobalVariable (
519 // Validate Console variable.
521 BdsFormalizeConsoleVariable (EFI_CON_IN_VARIABLE_NAME
);
522 BdsFormalizeConsoleVariable (EFI_CON_OUT_VARIABLE_NAME
);
523 BdsFormalizeConsoleVariable (EFI_ERR_OUT_VARIABLE_NAME
);
526 // Validate OSIndication related variable.
528 BdsFormalizeOSIndicationVariable ();
533 Allocate a block of memory that will contain performance data to OS.
537 BdsAllocateMemoryForPerformanceData (
542 EFI_PHYSICAL_ADDRESS AcpiLowMemoryBase
;
543 EDKII_VARIABLE_LOCK_PROTOCOL
*VariableLock
;
545 AcpiLowMemoryBase
= 0x0FFFFFFFFULL
;
548 // Allocate a block of memory that will contain performance data to OS.
550 Status
= gBS
->AllocatePages (
552 EfiReservedMemoryType
,
553 EFI_SIZE_TO_PAGES (PERF_DATA_MAX_LENGTH
),
556 if (!EFI_ERROR (Status
)) {
558 // Save the pointer to variable for use in S3 resume.
560 Status
= BdsDxeSetVariableAndReportStatusCodeOnError (
562 &gPerformanceProtocolGuid
,
563 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
564 sizeof (EFI_PHYSICAL_ADDRESS
),
567 if (EFI_ERROR (Status
)) {
568 DEBUG ((EFI_D_ERROR
, "[Bds] PerfDataMemAddr (%08x) cannot be saved to NV storage.\n", AcpiLowMemoryBase
));
571 // Mark L"PerfDataMemAddr" variable to read-only if the Variable Lock protocol exists
572 // Still lock it even the variable cannot be saved to prevent it's set by 3rd party code.
574 Status
= gBS
->LocateProtocol (&gEdkiiVariableLockProtocolGuid
, NULL
, (VOID
**) &VariableLock
);
575 if (!EFI_ERROR (Status
)) {
576 Status
= VariableLock
->RequestToLock (VariableLock
, L
"PerfDataMemAddr", &gPerformanceProtocolGuid
);
577 ASSERT_EFI_ERROR (Status
);
584 Service routine for BdsInstance->Entry(). Devices are connected, the
585 consoles are initialized, and the boot options are tried.
587 @param This Protocol Instance structure.
593 IN EFI_BDS_ARCH_PROTOCOL
*This
596 EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOptions
;
597 UINTN LoadOptionCount
;
598 CHAR16
*FirmwareVendor
;
599 EFI_EVENT HotkeyTriggered
;
603 UINT32 BootOptionSupport
;
605 EDKII_VARIABLE_LOCK_PROTOCOL
*VariableLock
;
607 EFI_BOOT_MANAGER_LOAD_OPTION LoadOption
;
609 CHAR16 BootNextVariableName
[sizeof ("Boot####")];
610 EFI_BOOT_MANAGER_LOAD_OPTION BootManagerMenu
;
612 BOOLEAN PlatformRecovery
;
614 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
615 EFI_STATUS BootManagerMenuStatus
;
617 HotkeyTriggered
= NULL
;
618 Status
= EFI_SUCCESS
;
622 // Insert the performance probe
624 PERF_END (NULL
, "DXE", NULL
, 0);
625 PERF_START (NULL
, "BDS", NULL
, 0);
626 DEBUG ((EFI_D_INFO
, "[Bds] Entry...\n"));
629 BdsAllocateMemoryForPerformanceData ();
633 // Fill in FirmwareVendor and FirmwareRevision from PCDs
635 FirmwareVendor
= (CHAR16
*) PcdGetPtr (PcdFirmwareVendor
);
636 gST
->FirmwareVendor
= AllocateRuntimeCopyPool (StrSize (FirmwareVendor
), FirmwareVendor
);
637 ASSERT (gST
->FirmwareVendor
!= NULL
);
638 gST
->FirmwareRevision
= PcdGet32 (PcdFirmwareRevision
);
641 // Fixup Tasble CRC after we updated Firmware Vendor and Revision
644 gBS
->CalculateCrc32 ((VOID
*) gST
, sizeof (EFI_SYSTEM_TABLE
), &gST
->Hdr
.CRC32
);
647 // Validate Variable.
649 BdsFormalizeEfiGlobalVariable ();
652 // Mark the read-only variables if the Variable Lock protocol exists
654 Status
= gBS
->LocateProtocol (&gEdkiiVariableLockProtocolGuid
, NULL
, (VOID
**) &VariableLock
);
655 DEBUG ((EFI_D_INFO
, "[BdsDxe] Locate Variable Lock protocol - %r\n", Status
));
656 if (!EFI_ERROR (Status
)) {
657 for (Index
= 0; Index
< sizeof (mReadOnlyVariables
) / sizeof (mReadOnlyVariables
[0]); Index
++) {
658 Status
= VariableLock
->RequestToLock (VariableLock
, mReadOnlyVariables
[Index
], &gEfiGlobalVariableGuid
);
659 ASSERT_EFI_ERROR (Status
);
663 InitializeHwErrRecSupport ();
666 // Initialize L"Timeout" EFI global variable.
668 BootTimeOut
= PcdGet16 (PcdPlatformBootTimeOut
);
669 if (BootTimeOut
!= 0xFFFF) {
671 // If time out value equal 0xFFFF, no need set to 0xFFFF to variable area because UEFI specification
672 // define same behavior between no value or 0xFFFF value for L"Timeout".
674 BdsDxeSetVariableAndReportStatusCodeOnError (
675 EFI_TIME_OUT_VARIABLE_NAME
,
676 &gEfiGlobalVariableGuid
,
677 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
684 // Initialize L"BootOptionSupport" EFI global variable.
685 // Lazy-ConIn implictly disables BDS hotkey.
687 BootOptionSupport
= EFI_BOOT_OPTION_SUPPORT_APP
| EFI_BOOT_OPTION_SUPPORT_SYSPREP
;
688 if (!PcdGetBool (PcdConInConnectOnDemand
)) {
689 BootOptionSupport
|= EFI_BOOT_OPTION_SUPPORT_KEY
;
690 SET_BOOT_OPTION_SUPPORT_KEY_COUNT (BootOptionSupport
, 3);
692 Status
= gRT
->SetVariable (
693 EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME
,
694 &gEfiGlobalVariableGuid
,
695 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
696 sizeof (BootOptionSupport
),
700 // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.
702 ASSERT_EFI_ERROR (Status
);
705 // Cache and remove the "BootNext" NV variable.
707 GetEfiGlobalVariable2 (EFI_BOOT_NEXT_VARIABLE_NAME
, (VOID
**) &BootNext
, &DataSize
);
708 if (DataSize
!= sizeof (UINT16
)) {
709 if (BootNext
!= NULL
) {
714 Status
= gRT
->SetVariable (
715 EFI_BOOT_NEXT_VARIABLE_NAME
,
716 &gEfiGlobalVariableGuid
,
722 // Deleting NV variable shouldn't fail unless it doesn't exist.
724 ASSERT (Status
== EFI_SUCCESS
|| Status
== EFI_NOT_FOUND
);
727 // Initialize the platform language variables
729 InitializeLanguage (TRUE
);
732 // System firmware must include a PlatformRecovery#### variable specifying
733 // a short-form File Path Media Device Path containing the platform default
734 // file path for removable media
736 FilePath
= FileDevicePath (NULL
, EFI_REMOVABLE_MEDIA_FILE_NAME
);
737 Status
= EfiBootManagerInitializeLoadOption (
740 LoadOptionTypePlatformRecovery
,
742 L
"Default PlatformRecovery",
747 ASSERT_EFI_ERROR (Status
);
748 EfiBootManagerLoadOptionToVariable (&LoadOption
);
749 EfiBootManagerFreeLoadOption (&LoadOption
);
753 // Report Status Code to indicate connecting drivers will happen
757 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_DXE_BS_PC_BEGIN_CONNECTING_DRIVERS
)
761 // Do the platform init, can be customized by OEM/IBV
762 // Possible things that can be done in PlatformBootManagerBeforeConsole:
763 // > Update console variable: 1. include hot-plug devices; 2. Clear ConIn and add SOL for AMT
764 // > Register new Driver#### or Boot####
765 // > Register new Key####: e.g.: F12
766 // > Signal ReadyToLock event
767 // > Authentication action: 1. connect Auth devices; 2. Identify auto logon user.
769 PERF_START (NULL
, "PlatformBootManagerBeforeConsole", "BDS", 0);
770 PlatformBootManagerBeforeConsole ();
771 PERF_END (NULL
, "PlatformBootManagerBeforeConsole", "BDS", 0);
774 // Initialize hotkey service
776 EfiBootManagerStartHotkeyService (&HotkeyTriggered
);
779 // Execute Driver Options
781 LoadOptions
= EfiBootManagerGetLoadOptions (&LoadOptionCount
, LoadOptionTypeDriver
);
782 ProcessLoadOptions (LoadOptions
, LoadOptionCount
);
783 EfiBootManagerFreeLoadOptions (LoadOptions
, LoadOptionCount
);
788 PERF_START (NULL
, "EfiBootManagerConnectAllDefaultConsoles", "BDS", 0);
789 if (PcdGetBool (PcdConInConnectOnDemand
)) {
790 EfiBootManagerConnectConsoleVariable (ConOut
);
791 EfiBootManagerConnectConsoleVariable (ErrOut
);
794 // Initialize ConnectConIn event
796 Status
= gBS
->CreateEventEx (
799 BdsDxeOnConnectConInCallBack
,
801 &gConnectConInEventGuid
,
804 if (EFI_ERROR (Status
)) {
805 gConnectConInEvent
= NULL
;
808 EfiBootManagerConnectAllDefaultConsoles ();
810 PERF_END (NULL
, "EfiBootManagerConnectAllDefaultConsoles", "BDS", 0);
813 // Do the platform specific action after the console is ready
814 // Possible things that can be done in PlatformBootManagerAfterConsole:
815 // > Console post action:
816 // > Dynamically switch output mode from 100x31 to 80x25 for certain senarino
817 // > Signal console ready platform customized event
818 // > Run diagnostics like memory testing
819 // > Connect certain devices
820 // > Dispatch aditional option roms
821 // > Special boot: e.g.: USB boot, enter UI
823 PERF_START (NULL
, "PlatformBootManagerAfterConsole", "BDS", 0);
824 PlatformBootManagerAfterConsole ();
825 PERF_END (NULL
, "PlatformBootManagerAfterConsole", "BDS", 0);
827 // Boot to Boot Manager Menu when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set. Skip HotkeyBoot
829 DataSize
= sizeof (UINT64
);
830 Status
= gRT
->GetVariable (
831 EFI_OS_INDICATIONS_VARIABLE_NAME
,
832 &gEfiGlobalVariableGuid
,
837 if (EFI_ERROR (Status
)) {
842 EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType
;
843 DEBUG ((EFI_D_INFO
, "[Bds]OsIndication: %016x\n", OsIndication
));
844 DEBUG ((EFI_D_INFO
, "[Bds]=============Begin Load Options Dumping ...=============\n"));
845 for (LoadOptionType
= 0; LoadOptionType
< LoadOptionTypeMax
; LoadOptionType
++) {
847 EFI_D_INFO
, " %s Options:\n",
848 mBdsLoadOptionName
[LoadOptionType
]
850 LoadOptions
= EfiBootManagerGetLoadOptions (&LoadOptionCount
, LoadOptionType
);
851 for (Index
= 0; Index
< LoadOptionCount
; Index
++) {
853 EFI_D_INFO
, " %s%04x: %s \t\t 0x%04x\n",
854 mBdsLoadOptionName
[LoadOptionType
],
855 LoadOptions
[Index
].OptionNumber
,
856 LoadOptions
[Index
].Description
,
857 LoadOptions
[Index
].Attributes
860 EfiBootManagerFreeLoadOptions (LoadOptions
, LoadOptionCount
);
862 DEBUG ((EFI_D_INFO
, "[Bds]=============End Load Options Dumping=============\n"));
866 // BootManagerMenu doesn't contain the correct information when return status is EFI_NOT_FOUND.
868 BootManagerMenuStatus
= EfiBootManagerGetBootManagerMenu (&BootManagerMenu
);
870 BootFwUi
= (BOOLEAN
) ((OsIndication
& EFI_OS_INDICATIONS_BOOT_TO_FW_UI
) != 0);
871 PlatformRecovery
= (BOOLEAN
) ((OsIndication
& EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY
) != 0);
873 // Clear EFI_OS_INDICATIONS_BOOT_TO_FW_UI to acknowledge OS
875 if (BootFwUi
|| PlatformRecovery
) {
876 OsIndication
&= ~((UINT64
) (EFI_OS_INDICATIONS_BOOT_TO_FW_UI
| EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY
));
877 Status
= gRT
->SetVariable (
878 EFI_OS_INDICATIONS_VARIABLE_NAME
,
879 &gEfiGlobalVariableGuid
,
880 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
885 // Changing the content without increasing its size with current variable implementation shouldn't fail.
887 ASSERT_EFI_ERROR (Status
);
891 // Launch Boot Manager Menu directly when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set. Skip HotkeyBoot
893 if (BootFwUi
&& (BootManagerMenuStatus
!= EFI_NOT_FOUND
)) {
895 // Follow generic rule, Call BdsDxeOnConnectConInCallBack to connect ConIn before enter UI
897 if (PcdGetBool (PcdConInConnectOnDemand
)) {
898 BdsDxeOnConnectConInCallBack (NULL
, NULL
);
902 // Directly enter the setup page.
904 EfiBootManagerBoot (&BootManagerMenu
);
907 if (!PlatformRecovery
) {
909 // Execute SysPrep####
911 LoadOptions
= EfiBootManagerGetLoadOptions (&LoadOptionCount
, LoadOptionTypeSysPrep
);
912 ProcessLoadOptions (LoadOptions
, LoadOptionCount
);
913 EfiBootManagerFreeLoadOptions (LoadOptions
, LoadOptionCount
);
918 PERF_START (NULL
, "BdsWait", "BDS", 0);
919 BdsWait (HotkeyTriggered
);
920 PERF_END (NULL
, "BdsWait", "BDS", 0);
923 // BdsReadKeys() can be removed after all keyboard drivers invoke callback in timer callback.
927 EfiBootManagerHotkeyBoot ();
930 // Boot to "BootNext"
932 if (BootNext
!= NULL
) {
933 UnicodeSPrint (BootNextVariableName
, sizeof (BootNextVariableName
), L
"Boot%04x", *BootNext
);
934 Status
= EfiBootManagerVariableToLoadOption (BootNextVariableName
, &LoadOption
);
935 if (!EFI_ERROR (Status
)) {
936 EfiBootManagerBoot (&LoadOption
);
937 EfiBootManagerFreeLoadOption (&LoadOption
);
938 if ((LoadOption
.Status
== EFI_SUCCESS
) &&
939 (BootManagerMenuStatus
!= EFI_NOT_FOUND
) &&
940 (LoadOption
.OptionNumber
!= BootManagerMenu
.OptionNumber
)) {
942 // Boot to Boot Manager Menu upon EFI_SUCCESS
943 // Exception: Do not boot again when the BootNext points to Boot Manager Menu.
945 EfiBootManagerBoot (&BootManagerMenu
);
952 // Retry to boot if any of the boot succeeds
954 LoadOptions
= EfiBootManagerGetLoadOptions (&LoadOptionCount
, LoadOptionTypeBoot
);
955 BootSuccess
= BootBootOptions (LoadOptions
, LoadOptionCount
, (BootManagerMenuStatus
!= EFI_NOT_FOUND
) ? &BootManagerMenu
: NULL
);
956 EfiBootManagerFreeLoadOptions (LoadOptions
, LoadOptionCount
);
957 } while (BootSuccess
);
960 if (BootManagerMenuStatus
!= EFI_NOT_FOUND
) {
961 EfiBootManagerFreeLoadOption (&BootManagerMenu
);
965 LoadOptions
= EfiBootManagerGetLoadOptions (&LoadOptionCount
, LoadOptionTypePlatformRecovery
);
966 ProcessLoadOptions (LoadOptions
, LoadOptionCount
);
967 EfiBootManagerFreeLoadOptions (LoadOptions
, LoadOptionCount
);
970 DEBUG ((EFI_D_ERROR
, "[Bds] Unable to boot!\n"));
975 Set the variable and report the error through status code upon failure.
977 @param VariableName A Null-terminated string that is the name of the vendor's variable.
978 Each VariableName is unique for each VendorGuid. VariableName must
979 contain 1 or more characters. If VariableName is an empty string,
980 then EFI_INVALID_PARAMETER is returned.
981 @param VendorGuid A unique identifier for the vendor.
982 @param Attributes Attributes bitmask to set for the variable.
983 @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,
984 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or
985 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero
986 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is
987 set, then a SetVariable() call with a DataSize of zero will not cause any change to
988 the variable value (the timestamp associated with the variable may be updated however
989 even if no new data value is provided,see the description of the
990 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not
991 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
992 @param Data The contents for the variable.
994 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
995 defined by the Attributes.
996 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the
997 DataSize exceeds the maximum allowed.
998 @retval EFI_INVALID_PARAMETER VariableName is an empty string.
999 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
1000 @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.
1001 @retval EFI_WRITE_PROTECTED The variable in question is read-only.
1002 @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.
1003 @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
1004 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo
1005 does NOT pass the validation check carried out by the firmware.
1007 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
1010 BdsDxeSetVariableAndReportStatusCodeOnError (
1011 IN CHAR16
*VariableName
,
1012 IN EFI_GUID
*VendorGuid
,
1013 IN UINT32 Attributes
,
1019 EDKII_SET_VARIABLE_STATUS
*SetVariableStatus
;
1022 Status
= gRT
->SetVariable (
1029 if (EFI_ERROR (Status
)) {
1030 NameSize
= StrSize (VariableName
);
1031 SetVariableStatus
= AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS
) + NameSize
+ DataSize
);
1032 if (SetVariableStatus
!= NULL
) {
1033 CopyGuid (&SetVariableStatus
->Guid
, VendorGuid
);
1034 SetVariableStatus
->NameSize
= NameSize
;
1035 SetVariableStatus
->DataSize
= DataSize
;
1036 SetVariableStatus
->SetStatus
= Status
;
1037 SetVariableStatus
->Attributes
= Attributes
;
1038 CopyMem (SetVariableStatus
+ 1, VariableName
, NameSize
);
1039 CopyMem (((UINT8
*) (SetVariableStatus
+ 1)) + NameSize
, Data
, DataSize
);
1041 REPORT_STATUS_CODE_EX (
1043 PcdGet32 (PcdErrorCodeSetVariable
),
1046 &gEdkiiStatusCodeDataTypeVariableGuid
,
1048 sizeof (EDKII_SET_VARIABLE_STATUS
) + NameSize
+ DataSize
1051 FreePool (SetVariableStatus
);