3 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
4 Portions copyright (c) 2011, Apple Inc. All rights reserved.
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. 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.
15 #include "PlatformBm.h"
17 EFI_GUID mBootMenuFile
= {
18 0xEEC25BDC, 0x67F2, 0x4D95, { 0xB1, 0xD5, 0xF8, 0x1B, 0x20, 0x39, 0xD1, 0x1D }
22 Initialize the "Setup" variable.
31 EMU_SYSTEM_CONFIGURATION SystemConfigData
;
33 Size
= sizeof (SystemConfigData
);
34 Status
= gRT
->GetVariable (
36 &gEmuSystemConfigGuid
,
39 (VOID
*) &SystemConfigData
42 if (EFI_ERROR (Status
)) {
44 // SetupVariable is corrupt
46 SystemConfigData
.ConOutRow
= PcdGet32 (PcdConOutColumn
);
47 SystemConfigData
.ConOutColumn
= PcdGet32 (PcdConOutRow
);
49 Status
= gRT
->SetVariable (
51 &gEmuSystemConfigGuid
,
52 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
53 sizeof (SystemConfigData
),
54 (VOID
*) &SystemConfigData
56 if (EFI_ERROR (Status
)) {
57 DEBUG ((DEBUG_ERROR
, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status
));
69 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
70 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode
;
72 EfiInitializeFwVolDevicepathNode (&FileNode
, FileGuid
);
74 Status
= gBS
->HandleProtocol (
76 &gEfiLoadedImageProtocolGuid
,
77 (VOID
**) &LoadedImage
79 ASSERT_EFI_ERROR (Status
);
80 return AppendDevicePathNode (
81 DevicePathFromHandle (LoadedImage
->DeviceHandle
),
82 (EFI_DEVICE_PATH_PROTOCOL
*) &FileNode
87 Create one boot option for BootManagerMenuApp.
89 @param FileGuid Input file guid for the BootManagerMenuApp.
90 @param Description Description of the BootManagerMenuApp boot option.
91 @param Position Position of the new load option to put in the ****Order variable.
92 @param IsBootCategory Whether this is a boot category.
95 @retval OptionNumber Return the option number info.
99 RegisterBootManagerMenuAppBootOption (
103 BOOLEAN IsBootCategory
107 EFI_BOOT_MANAGER_LOAD_OPTION NewOption
;
108 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
111 DevicePath
= FvFilePath (FileGuid
);
112 Status
= EfiBootManagerInitializeLoadOption (
114 LoadOptionNumberUnassigned
,
116 IsBootCategory
? LOAD_OPTION_ACTIVE
: LOAD_OPTION_CATEGORY_APP
,
122 ASSERT_EFI_ERROR (Status
);
123 FreePool (DevicePath
);
125 Status
= EfiBootManagerAddLoadOptionVariable (&NewOption
, Position
);
126 ASSERT_EFI_ERROR (Status
);
128 OptionNumber
= NewOption
.OptionNumber
;
130 EfiBootManagerFreeLoadOption (&NewOption
);
136 Check if it's a Device Path pointing to BootManagerMenuApp.
138 @param DevicePath Input device path.
140 @retval TRUE The device path is BootManagerMenuApp File Device Path.
141 @retval FALSE The device path is NOT BootManagerMenuApp File Device Path.
144 IsBootManagerMenuAppFilePath (
145 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
152 Status
= gBS
->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid
, &DevicePath
, &FvHandle
);
153 if (!EFI_ERROR (Status
)) {
154 NameGuid
= EfiGetNameGuidFromFwVolDevicePathNode ((CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) DevicePath
);
155 if (NameGuid
!= NULL
) {
156 return CompareGuid (NameGuid
, &mBootMenuFile
);
164 Return the boot option number to the BootManagerMenuApp.
166 If not found it in the current boot option, create a new one.
168 @retval OptionNumber Return the boot option number to the BootManagerMenuApp.
172 GetBootManagerMenuAppOption (
176 UINTN BootOptionCount
;
177 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOptions
;
183 BootOptions
= EfiBootManagerGetLoadOptions (&BootOptionCount
, LoadOptionTypeBoot
);
185 for (Index
= 0; Index
< BootOptionCount
; Index
++) {
186 if (IsBootManagerMenuAppFilePath (BootOptions
[Index
].FilePath
)) {
187 OptionNumber
= BootOptions
[Index
].OptionNumber
;
192 EfiBootManagerFreeLoadOptions (BootOptions
, BootOptionCount
);
194 if (Index
>= BootOptionCount
) {
196 // If not found the BootManagerMenuApp, create it.
198 OptionNumber
= (UINT16
) RegisterBootManagerMenuAppBootOption (&mBootMenuFile
, L
"UEFI BootManagerMenuApp", (UINTN
) -1, FALSE
);
205 Platform Bds init. Include the platform firmware vendor, revision
210 PlatformBootManagerBeforeConsole (
216 SetupVariableInit ();
218 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid
);
221 while (gPlatformConsole
[Index
].DevicePath
!= NULL
) {
223 // Update the console variable with the connect type
225 if ((gPlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
226 EfiBootManagerUpdateConsoleVariable (ConIn
, gPlatformConsole
[Index
].DevicePath
, NULL
);
229 if ((gPlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
230 EfiBootManagerUpdateConsoleVariable (ConOut
, gPlatformConsole
[Index
].DevicePath
, NULL
);
233 if ((gPlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
234 EfiBootManagerUpdateConsoleVariable (ErrOut
, gPlatformConsole
[Index
].DevicePath
, NULL
);
242 Connect with predefined platform connect sequence,
243 the OEM/IBV can customize with their own connect sequence.
246 PlatformBdsConnectSequence (
251 // Just use the simple policy to connect all devices
253 EfiBootManagerConnectAll ();
257 Perform the platform diagnostic, such like test memory. OEM/IBV also
258 can customize this fuction to support specific platform diagnostic.
260 @param MemoryTestLevel The memory test intensive level
261 @param QuietBoot Indicate if need to enable the quiet boot
264 PlatformBdsDiagnostics (
265 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel
,
272 // Here we can decide if we need to show
273 // the diagnostics screen
276 BootLogoEnableLogo ();
279 // Perform system diagnostic
281 Status
= PlatformBootManagerMemoryTest (MemoryTestLevel
);
282 if (EFI_ERROR (Status
)) {
283 BootLogoDisableLogo ();
290 // Perform system diagnostic
292 PlatformBootManagerMemoryTest (MemoryTestLevel
);
296 Register the static boot options.
299 PlatformBdsRegisterStaticBootOptions (
303 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black
;
304 EFI_GRAPHICS_OUTPUT_BLT_PIXEL White
;
308 EFI_BOOT_MANAGER_LOAD_OPTION BootOption
;
311 Black
.Blue
= Black
.Green
= Black
.Red
= Black
.Reserved
= 0;
312 White
.Blue
= White
.Green
= White
.Red
= White
.Reserved
= 0xFF;
315 // Register ENTER as CONTINUE key
317 Enter
.ScanCode
= SCAN_NULL
;
318 Enter
.UnicodeChar
= CHAR_CARRIAGE_RETURN
;
319 EfiBootManagerRegisterContinueKeyOption (0, &Enter
, NULL
);
321 // Map F2 to Boot Manager Menu
323 F2
.ScanCode
= SCAN_F2
;
324 F2
.UnicodeChar
= CHAR_NULL
;
325 EfiBootManagerGetBootManagerMenu (&BootOption
);
326 EfiBootManagerAddKeyOptionVariable (NULL
, (UINT16
) BootOption
.OptionNumber
, 0, &F2
, NULL
);
329 // 3. Boot Device List menu
331 F7
.ScanCode
= SCAN_F7
;
332 F7
.UnicodeChar
= CHAR_NULL
;
333 OptionNumber
= GetBootManagerMenuAppOption ();
334 EfiBootManagerAddKeyOptionVariable (NULL
, (UINT16
)OptionNumber
, 0, &F7
, NULL
);
336 PrintXY (10, 10, &White
, &Black
, L
"F2 to enter Setup. ");
337 PrintXY (10, 30, &White
, &Black
, L
"F7 to enter Boot Manager Menu.");
338 PrintXY (10, 50, &White
, &Black
, L
"Enter to boot directly.");
342 Do the platform specific action after the console is connected.
345 Dynamically switch output mode;
346 Signal console ready platform customized event;
347 Run diagnostics like memory testing;
348 Connect certain devices;
349 Dispatch aditional option roms.
353 PlatformBootManagerAfterConsole (
359 // Go the different platform policy with different boot mode
360 // Notes: this part code can be change with the table policy
362 switch (GetBootModeHob ()) {
364 case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES
:
365 case BOOT_WITH_MINIMAL_CONFIGURATION
:
366 PlatformBdsDiagnostics (IGNORE
, TRUE
);
369 // Perform some platform specific connect sequence
371 PlatformBdsConnectSequence ();
374 case BOOT_IN_RECOVERY_MODE
:
375 PlatformBdsDiagnostics (EXTENSIVE
, FALSE
);
378 case BOOT_WITH_FULL_CONFIGURATION
:
379 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS
:
380 case BOOT_WITH_DEFAULT_SETTINGS
:
382 PlatformBdsDiagnostics (IGNORE
, TRUE
);
383 PlatformBdsRegisterStaticBootOptions ();
384 PlatformBdsConnectSequence ();
385 EfiBootManagerRefreshAllBootOption ();
391 This function is called each second during the boot manager waits the timeout.
393 @param TimeoutRemain The remaining timeout.
397 PlatformBootManagerWaitCallback (
401 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Black
;
402 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION White
;
405 Timeout
= PcdGet16 (PcdPlatformBootTimeOut
);
407 Black
.Raw
= 0x00000000;
408 White
.Raw
= 0x00FFFFFF;
410 BootLogoUpdateProgress (
413 L
"Start boot option",
415 (Timeout
- TimeoutRemain
) * 100 / Timeout
,
421 The function is called when no boot option could be launched,
422 including platform recovery options and options pointing to applications
423 built into firmware volumes.
425 If this function returns, BDS attempts to enter an infinite loop.
429 PlatformBootManagerUnableToBoot (