2 This file include all platform action which can be customized
5 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "PlatformBootManager.h"
18 EFI_GUID mBootMenuFile
= {
19 0xEEC25BDC, 0x67F2, 0x4D95, { 0xB1, 0xD5, 0xF8, 0x1B, 0x20, 0x39, 0xD1, 0x1D }
23 Perform the platform diagnostic, such like test memory. OEM/IBV also
24 can customize this function to support specific platform diagnostic.
26 @param MemoryTestLevel The memory test intensive level
27 @param QuietBoot Indicate if need to enable the quiet boot
31 PlatformBootManagerDiagnostics (
32 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel
,
39 // Here we can decide if we need to show
40 // the diagnostics screen
41 // Notes: this quiet boot code should be remove
42 // from the graphic lib
45 // BootLogoEnableLogo (ImageFormatBmp, PcdGetPtr(PcdLogoFile), EdkiiPlatformLogoDisplayAttributeCenter, 0, 0);
48 // Perform system diagnostic
50 Status
= PlatformBootManagerMemoryTest (MemoryTestLevel
);
51 if (EFI_ERROR (Status
)) {
52 BootLogoDisableLogo ();
59 // Perform system diagnostic
61 Status
= PlatformBootManagerMemoryTest (MemoryTestLevel
);
65 Do the platform specific action before the console is connected.
68 Update console variable;
69 Register new Driver#### or Boot####;
70 Signal ReadyToLock event.
74 PlatformBootManagerBeforeConsole (
80 WIN_NT_SYSTEM_CONFIGURATION
*Configuration
;
82 GetVariable2 (L
"Setup", &gEfiWinNtSystemConfigGuid
, (VOID
**) &Configuration
, NULL
);
83 if (Configuration
!= NULL
) {
85 // SetupVariable is corrupt
87 Configuration
->ConOutRow
= PcdGet32 (PcdConOutColumn
);
88 Configuration
->ConOutColumn
= PcdGet32 (PcdConOutRow
);
90 Status
= gRT
->SetVariable (
92 &gEfiWinNtSystemConfigGuid
,
93 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
94 sizeof (WIN_NT_SYSTEM_CONFIGURATION
),
97 if (EFI_ERROR (Status
)) {
98 DEBUG ((EFI_D_ERROR
, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status
));
100 FreePool (Configuration
);
104 // Update the ocnsole variables.
106 for (Index
= 0; gPlatformConsole
[Index
].DevicePath
!= NULL
; Index
++) {
107 if ((gPlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
108 EfiBootManagerUpdateConsoleVariable (ConIn
, gPlatformConsole
[Index
].DevicePath
, NULL
);
111 if ((gPlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
112 EfiBootManagerUpdateConsoleVariable (ConOut
, gPlatformConsole
[Index
].DevicePath
, NULL
);
115 if ((gPlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
116 EfiBootManagerUpdateConsoleVariable (ErrOut
, gPlatformConsole
[Index
].DevicePath
, NULL
);
122 Returns the priority number.
128 CONST EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
132 // Make sure Shell is first
134 if (StrCmp (BootOption
->Description
, L
"UEFI Shell") == 0) {
143 CONST EFI_BOOT_MANAGER_LOAD_OPTION
*Left
,
144 CONST EFI_BOOT_MANAGER_LOAD_OPTION
*Right
147 return BootOptionPriority (Left
) - BootOptionPriority (Right
);
151 Generate device path include the input file guid info.
153 @param FileGuid Input file guid for the BootManagerMenuApp.
155 @retval DevicePath for BootManagerMenuApp.
164 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
165 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode
;
167 EfiInitializeFwVolDevicepathNode (&FileNode
, FileGuid
);
169 Status
= gBS
->HandleProtocol (
171 &gEfiLoadedImageProtocolGuid
,
172 (VOID
**) &LoadedImage
174 ASSERT_EFI_ERROR (Status
);
176 return AppendDevicePathNode (
177 DevicePathFromHandle (LoadedImage
->DeviceHandle
),
178 (EFI_DEVICE_PATH_PROTOCOL
*) &FileNode
183 Create one boot option for BootManagerMenuApp.
185 @param FileGuid Input file guid for the BootManagerMenuApp.
186 @param Description Description of the BootManagerMenuApp boot option.
187 @param Position Position of the new load option to put in the ****Order variable.
188 @param IsBootCategory Whether this is a boot category.
191 @retval OptionNumber Return the option number info.
195 RegisterBootManagerMenuAppBootOption (
199 BOOLEAN IsBootCategory
203 EFI_BOOT_MANAGER_LOAD_OPTION NewOption
;
204 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
207 DevicePath
= FvFilePath (FileGuid
);
208 Status
= EfiBootManagerInitializeLoadOption (
210 LoadOptionNumberUnassigned
,
212 IsBootCategory
? LOAD_OPTION_ACTIVE
: LOAD_OPTION_CATEGORY_APP
,
218 ASSERT_EFI_ERROR (Status
);
219 FreePool (DevicePath
);
221 Status
= EfiBootManagerAddLoadOptionVariable (&NewOption
, Position
);
222 ASSERT_EFI_ERROR (Status
);
224 OptionNumber
= NewOption
.OptionNumber
;
226 EfiBootManagerFreeLoadOption (&NewOption
);
232 Check if it's a Device Path pointing to BootManagerMenuApp.
234 @param DevicePath Input device path.
236 @retval TRUE The device path is BootManagerMenuApp File Device Path.
237 @retval FALSE The device path is NOT BootManagerMenuApp File Device Path.
240 IsBootManagerMenuAppFilePath (
241 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
248 Status
= gBS
->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid
, &DevicePath
, &FvHandle
);
249 if (!EFI_ERROR (Status
)) {
250 NameGuid
= EfiGetNameGuidFromFwVolDevicePathNode ((CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) DevicePath
);
251 if (NameGuid
!= NULL
) {
252 return CompareGuid (NameGuid
, &mBootMenuFile
);
260 Return the boot option number to the BootManagerMenuApp.
262 If not found it in the current boot option, create a new one.
264 @retval OptionNumber Return the boot option number to the BootManagerMenuApp.
268 GetBootManagerMenuAppOption (
272 UINTN BootOptionCount
;
273 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOptions
;
279 BootOptions
= EfiBootManagerGetLoadOptions (&BootOptionCount
, LoadOptionTypeBoot
);
281 for (Index
= 0; Index
< BootOptionCount
; Index
++) {
282 if (IsBootManagerMenuAppFilePath (BootOptions
[Index
].FilePath
)) {
283 OptionNumber
= BootOptions
[Index
].OptionNumber
;
288 EfiBootManagerFreeLoadOptions (BootOptions
, BootOptionCount
);
290 if (Index
>= BootOptionCount
) {
292 // If not found the BootManagerMenuApp, create it.
294 OptionNumber
= (UINT16
) RegisterBootManagerMenuAppBootOption (&mBootMenuFile
, L
"UEFI BootManagerMenuApp", (UINTN
) -1, FALSE
);
301 Do the platform specific action after the console is connected.
304 Dynamically switch output mode;
305 Signal console ready platform customized event;
306 Run diagnostics like memory testing;
307 Connect certain devices;
308 Dispatch aditional option roms.
312 PlatformBootManagerAfterConsole (
316 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black
;
317 EFI_GRAPHICS_OUTPUT_BLT_PIXEL White
;
321 EFI_BOOT_MANAGER_LOAD_OPTION BootOption
;
324 Black
.Blue
= Black
.Green
= Black
.Red
= Black
.Reserved
= 0;
325 White
.Blue
= White
.Green
= White
.Red
= White
.Reserved
= 0xFF;
327 EfiBootManagerConnectAll ();
328 EfiBootManagerRefreshAllBootOption ();
331 // Register ENTER as CONTINUE key
333 Enter
.ScanCode
= SCAN_NULL
;
334 Enter
.UnicodeChar
= CHAR_CARRIAGE_RETURN
;
335 EfiBootManagerRegisterContinueKeyOption (0, &Enter
, NULL
);
337 // Map F2 to Boot Manager Menu
339 F2
.ScanCode
= SCAN_F2
;
340 F2
.UnicodeChar
= CHAR_NULL
;
341 EfiBootManagerGetBootManagerMenu (&BootOption
);
342 EfiBootManagerAddKeyOptionVariable (NULL
, (UINT16
) BootOption
.OptionNumber
, 0, &F2
, NULL
);
345 // 3. Boot Device List menu
347 F7
.ScanCode
= SCAN_F7
;
348 F7
.UnicodeChar
= CHAR_NULL
;
349 OptionNumber
= GetBootManagerMenuAppOption ();
350 EfiBootManagerAddKeyOptionVariable (NULL
, (UINT16
)OptionNumber
, 0, &F7
, NULL
);
353 // Make Shell as the first boot option
355 EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot
, (SORT_COMPARE
) CompareBootOption
);
357 PlatformBootManagerDiagnostics (QUICK
, TRUE
);
359 PrintXY (10, 10, &White
, &Black
, L
"F2 to enter Setup. ");
360 PrintXY (10, 30, &White
, &Black
, L
"F7 to enter Boot Manager Menu.");
361 PrintXY (10, 50, &White
, &Black
, L
"Enter to boot directly.");
365 This function is called each second during the boot manager waits the timeout.
367 @param TimeoutRemain The remaining timeout.
371 PlatformBootManagerWaitCallback (
375 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Black
;
376 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION White
;
379 Timeout
= PcdGet16 (PcdPlatformBootTimeOut
);
381 Black
.Raw
= 0x00000000;
382 White
.Raw
= 0x00FFFFFF;
384 BootLogoUpdateProgress (
387 L
"Start boot option",
389 (Timeout
- TimeoutRemain
) * 100 / Timeout
,