2 This file include all platform action which can be customized
5 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
6 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "PlatformBootManager.h"
19 EFI_GUID mBootMenuFile
= {
20 0xEEC25BDC, 0x67F2, 0x4D95, { 0xB1, 0xD5, 0xF8, 0x1B, 0x20, 0x39, 0xD1, 0x1D }
24 Perform the platform diagnostic, such like test memory. OEM/IBV also
25 can customize this function to support specific platform diagnostic.
27 @param MemoryTestLevel The memory test intensive level
28 @param QuietBoot Indicate if need to enable the quiet boot
32 PlatformBootManagerDiagnostics (
33 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel
,
40 // Here we can decide if we need to show
41 // the diagnostics screen
42 // Notes: this quiet boot code should be remove
43 // from the graphic lib
46 BootLogoEnableLogo ();
49 // Perform system diagnostic
51 Status
= PlatformBootManagerMemoryTest (MemoryTestLevel
);
52 if (EFI_ERROR (Status
)) {
53 BootLogoDisableLogo ();
60 // Perform system diagnostic
62 Status
= PlatformBootManagerMemoryTest (MemoryTestLevel
);
66 Do the platform specific action before the console is connected.
69 Update console variable;
70 Register new Driver#### or Boot####;
71 Signal ReadyToLock event.
75 PlatformBootManagerBeforeConsole (
81 WIN_NT_SYSTEM_CONFIGURATION
*Configuration
;
83 GetVariable2 (L
"Setup", &gEfiWinNtSystemConfigGuid
, (VOID
**) &Configuration
, NULL
);
84 if (Configuration
!= NULL
) {
86 // SetupVariable is corrupt
88 Configuration
->ConOutRow
= PcdGet32 (PcdConOutColumn
);
89 Configuration
->ConOutColumn
= PcdGet32 (PcdConOutRow
);
91 Status
= gRT
->SetVariable (
93 &gEfiWinNtSystemConfigGuid
,
94 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
95 sizeof (WIN_NT_SYSTEM_CONFIGURATION
),
98 if (EFI_ERROR (Status
)) {
99 DEBUG ((EFI_D_ERROR
, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status
));
101 FreePool (Configuration
);
105 // Update the ocnsole variables.
107 for (Index
= 0; gPlatformConsole
[Index
].DevicePath
!= NULL
; Index
++) {
108 if ((gPlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
109 EfiBootManagerUpdateConsoleVariable (ConIn
, gPlatformConsole
[Index
].DevicePath
, NULL
);
112 if ((gPlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
113 EfiBootManagerUpdateConsoleVariable (ConOut
, gPlatformConsole
[Index
].DevicePath
, NULL
);
116 if ((gPlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
117 EfiBootManagerUpdateConsoleVariable (ErrOut
, gPlatformConsole
[Index
].DevicePath
, NULL
);
122 // From PI spec vol2:
123 // Prior to invoking any UEFI drivers, applications, or connecting consoles,
124 // the platform should signal the event EFI_END_OF_DXE_EVENT_GUID
126 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid
);
130 Returns the priority number.
136 CONST EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
140 // Make sure Shell is first
142 if (StrCmp (BootOption
->Description
, L
"UEFI Shell") == 0) {
151 CONST EFI_BOOT_MANAGER_LOAD_OPTION
*Left
,
152 CONST EFI_BOOT_MANAGER_LOAD_OPTION
*Right
155 return BootOptionPriority (Left
) - BootOptionPriority (Right
);
159 Generate device path include the input file guid info.
161 @param FileGuid Input file guid for the BootManagerMenuApp.
163 @retval DevicePath for BootManagerMenuApp.
172 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
173 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode
;
175 EfiInitializeFwVolDevicepathNode (&FileNode
, FileGuid
);
177 Status
= gBS
->HandleProtocol (
179 &gEfiLoadedImageProtocolGuid
,
180 (VOID
**) &LoadedImage
182 ASSERT_EFI_ERROR (Status
);
184 return AppendDevicePathNode (
185 DevicePathFromHandle (LoadedImage
->DeviceHandle
),
186 (EFI_DEVICE_PATH_PROTOCOL
*) &FileNode
191 Create one boot option for BootManagerMenuApp.
193 @param FileGuid Input file guid for the BootManagerMenuApp.
194 @param Description Description of the BootManagerMenuApp boot option.
195 @param Position Position of the new load option to put in the ****Order variable.
196 @param IsBootCategory Whether this is a boot category.
199 @retval OptionNumber Return the option number info.
203 RegisterBootManagerMenuAppBootOption (
207 BOOLEAN IsBootCategory
211 EFI_BOOT_MANAGER_LOAD_OPTION NewOption
;
212 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
215 DevicePath
= FvFilePath (FileGuid
);
216 Status
= EfiBootManagerInitializeLoadOption (
218 LoadOptionNumberUnassigned
,
220 IsBootCategory
? LOAD_OPTION_ACTIVE
: LOAD_OPTION_CATEGORY_APP
,
226 ASSERT_EFI_ERROR (Status
);
227 FreePool (DevicePath
);
229 Status
= EfiBootManagerAddLoadOptionVariable (&NewOption
, Position
);
230 ASSERT_EFI_ERROR (Status
);
232 OptionNumber
= NewOption
.OptionNumber
;
234 EfiBootManagerFreeLoadOption (&NewOption
);
240 Check if it's a Device Path pointing to BootManagerMenuApp.
242 @param DevicePath Input device path.
244 @retval TRUE The device path is BootManagerMenuApp File Device Path.
245 @retval FALSE The device path is NOT BootManagerMenuApp File Device Path.
248 IsBootManagerMenuAppFilePath (
249 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
256 Status
= gBS
->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid
, &DevicePath
, &FvHandle
);
257 if (!EFI_ERROR (Status
)) {
258 NameGuid
= EfiGetNameGuidFromFwVolDevicePathNode ((CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) DevicePath
);
259 if (NameGuid
!= NULL
) {
260 return CompareGuid (NameGuid
, &mBootMenuFile
);
268 Return the boot option number to the BootManagerMenuApp.
270 If not found it in the current boot option, create a new one.
272 @retval OptionNumber Return the boot option number to the BootManagerMenuApp.
276 GetBootManagerMenuAppOption (
280 UINTN BootOptionCount
;
281 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOptions
;
287 BootOptions
= EfiBootManagerGetLoadOptions (&BootOptionCount
, LoadOptionTypeBoot
);
289 for (Index
= 0; Index
< BootOptionCount
; Index
++) {
290 if (IsBootManagerMenuAppFilePath (BootOptions
[Index
].FilePath
)) {
291 OptionNumber
= BootOptions
[Index
].OptionNumber
;
296 EfiBootManagerFreeLoadOptions (BootOptions
, BootOptionCount
);
298 if (Index
>= BootOptionCount
) {
300 // If not found the BootManagerMenuApp, create it.
302 OptionNumber
= (UINT16
) RegisterBootManagerMenuAppBootOption (&mBootMenuFile
, L
"UEFI BootManagerMenuApp", (UINTN
) -1, FALSE
);
309 Do the platform specific action after the console is connected.
312 Dynamically switch output mode;
313 Signal console ready platform customized event;
314 Run diagnostics like memory testing;
315 Connect certain devices;
316 Dispatch aditional option roms.
320 PlatformBootManagerAfterConsole (
324 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black
;
325 EFI_GRAPHICS_OUTPUT_BLT_PIXEL White
;
329 EFI_BOOT_MANAGER_LOAD_OPTION BootOption
;
332 Black
.Blue
= Black
.Green
= Black
.Red
= Black
.Reserved
= 0;
333 White
.Blue
= White
.Green
= White
.Red
= White
.Reserved
= 0xFF;
335 EfiBootManagerConnectAll ();
336 EfiBootManagerRefreshAllBootOption ();
339 // Register ENTER as CONTINUE key
341 Enter
.ScanCode
= SCAN_NULL
;
342 Enter
.UnicodeChar
= CHAR_CARRIAGE_RETURN
;
343 EfiBootManagerRegisterContinueKeyOption (0, &Enter
, NULL
);
345 // Map F2 to Boot Manager Menu
347 F2
.ScanCode
= SCAN_F2
;
348 F2
.UnicodeChar
= CHAR_NULL
;
349 EfiBootManagerGetBootManagerMenu (&BootOption
);
350 EfiBootManagerAddKeyOptionVariable (NULL
, (UINT16
) BootOption
.OptionNumber
, 0, &F2
, NULL
);
353 // 3. Boot Device List menu
355 F7
.ScanCode
= SCAN_F7
;
356 F7
.UnicodeChar
= CHAR_NULL
;
357 OptionNumber
= GetBootManagerMenuAppOption ();
358 EfiBootManagerAddKeyOptionVariable (NULL
, (UINT16
)OptionNumber
, 0, &F7
, NULL
);
361 // Make Shell as the first boot option
363 EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot
, (SORT_COMPARE
) CompareBootOption
);
365 PlatformBootManagerDiagnostics (QUICK
, TRUE
);
367 PrintXY (10, 10, &White
, &Black
, L
"F2 to enter Setup. ");
368 PrintXY (10, 30, &White
, &Black
, L
"F7 to enter Boot Manager Menu.");
369 PrintXY (10, 50, &White
, &Black
, L
"Enter to boot directly.");
373 This function is called each second during the boot manager waits the timeout.
375 @param TimeoutRemain The remaining timeout.
379 PlatformBootManagerWaitCallback (
383 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Black
;
384 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION White
;
387 Timeout
= PcdGet16 (PcdPlatformBootTimeOut
);
389 Black
.Raw
= 0x00000000;
390 White
.Raw
= 0x00FFFFFF;
392 BootLogoUpdateProgress (
395 L
"Start boot option",
397 (Timeout
- TimeoutRemain
) * 100 / Timeout
,