2 This file include all platform action which can be customized
5 Copyright (c) 2015, 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"
19 EFI_GUID mUefiShellFileGuid
= { 0x7C04A583, 0x9E3E, 0x4f1c, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 };
22 Perform the memory test base on the memory test intensive level,
23 and update the memory resource.
25 @param Level The memory test intensive level.
27 @retval EFI_STATUS Success test all the system memory and update
32 PlatformBootManagerMemoryTest (
33 IN EXTENDMEM_COVERAGE_LEVEL Level
37 BOOLEAN RequireSoftECCInit
;
38 EFI_GENERIC_MEMORY_TEST_PROTOCOL
*GenMemoryTest
;
39 UINT64 TestedMemorySize
;
40 UINT64 TotalMemorySize
;
50 RequireSoftECCInit
= FALSE
;
52 Status
= gBS
->LocateProtocol (
53 &gEfiGenericMemTestProtocolGuid
,
55 (VOID
**) &GenMemoryTest
57 if (EFI_ERROR (Status
)) {
61 Status
= GenMemoryTest
->MemoryTestInit (
66 if (Status
== EFI_NO_MEDIA
) {
68 // The PEI codes also have the relevant memory test code to check the memory,
69 // it can select to test some range of the memory or all of them. If PEI code
70 // checks all the memory, this BDS memory test will has no not-test memory to
71 // do the test, and then the status of EFI_NO_MEDIA will be returned by
72 // "MemoryTestInit". So it does not need to test memory again, just return.
78 Status
= GenMemoryTest
->PerformMemoryTest (
85 if (ErrorOut
&& (Status
== EFI_DEVICE_ERROR
)) {
86 Print (L
"System encounters memory errors!");
90 TempData
= (UINT32
) DivU64x32 (TotalMemorySize
, 16);
91 TestPercent
= (UINTN
) DivU64x32 (
92 DivU64x32 (MultU64x32 (TestedMemorySize
, 100), 16),
95 if (TestPercent
!= PreviousValue
) {
96 Print (L
"Perform memory test: %d/100", TestPercent
);
97 PreviousValue
= TestPercent
;
99 } while (Status
!= EFI_NOT_FOUND
);
101 Status
= GenMemoryTest
->Finished (GenMemoryTest
);
103 Print (L
"\r%dM bytes of system memory tested OK\n", (UINT32
) DivU64x32 (TotalMemorySize
, 1024 * 1024));
109 Return the index of the load option in the load option array.
111 The function consider two load options are equal when the
112 OptionType, Attributes, Description, FilePath and OptionalData are equal.
114 @param Key Pointer to the load option to be found.
115 @param Array Pointer to the array of load options to be found.
116 @param Count Number of entries in the Array.
118 @retval -1 Key wasn't found in the Array.
119 @retval 0 ~ Count-1 The index of the Key in the Array.
122 PlatformFindLoadOption (
123 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION
*Key
,
124 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION
*Array
,
130 for (Index
= 0; Index
< Count
; Index
++) {
131 if ((Key
->OptionType
== Array
[Index
].OptionType
) &&
132 (Key
->Attributes
== Array
[Index
].Attributes
) &&
133 (StrCmp (Key
->Description
, Array
[Index
].Description
) == 0) &&
134 (CompareMem (Key
->FilePath
, Array
[Index
].FilePath
, GetDevicePathSize (Key
->FilePath
)) == 0) &&
135 (Key
->OptionalDataSize
== Array
[Index
].OptionalDataSize
) &&
136 (CompareMem (Key
->OptionalData
, Array
[Index
].OptionalData
, Key
->OptionalDataSize
) == 0)) {
145 PlatformRegisterFvBootOption (
153 EFI_BOOT_MANAGER_LOAD_OPTION NewOption
;
154 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOptions
;
155 UINTN BootOptionCount
;
156 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode
;
157 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
158 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
160 Status
= gBS
->HandleProtocol (gImageHandle
, &gEfiLoadedImageProtocolGuid
, (VOID
**) &LoadedImage
);
161 ASSERT_EFI_ERROR (Status
);
163 EfiInitializeFwVolDevicepathNode (&FileNode
, FileGuid
);
164 DevicePath
= AppendDevicePathNode (
165 DevicePathFromHandle (LoadedImage
->DeviceHandle
),
166 (EFI_DEVICE_PATH_PROTOCOL
*) &FileNode
169 Status
= EfiBootManagerInitializeLoadOption (
171 LoadOptionNumberUnassigned
,
179 if (!EFI_ERROR (Status
)) {
180 BootOptions
= EfiBootManagerGetLoadOptions (&BootOptionCount
, LoadOptionTypeBoot
);
182 OptionIndex
= PlatformFindLoadOption (&NewOption
, BootOptions
, BootOptionCount
);
184 if (OptionIndex
== -1) {
185 Status
= EfiBootManagerAddLoadOptionVariable (&NewOption
, (UINTN
) -1);
186 ASSERT_EFI_ERROR (Status
);
188 EfiBootManagerFreeLoadOption (&NewOption
);
189 EfiBootManagerFreeLoadOptions (BootOptions
, BootOptionCount
);
194 Do the platform specific action before the console is connected.
197 Update console variable;
198 Register new Driver#### or Boot####;
199 Signal ReadyToLock event.
203 PlatformBootManagerBeforeConsole (
209 WIN_NT_SYSTEM_CONFIGURATION
*Configuration
;
212 EFI_BOOT_MANAGER_LOAD_OPTION BootOption
;
214 GetVariable2 (L
"Setup", &gEfiWinNtSystemConfigGuid
, (VOID
**) &Configuration
, NULL
);
215 if (Configuration
!= NULL
) {
217 // SetupVariable is corrupt
219 Configuration
->ConOutRow
= PcdGet32 (PcdConOutColumn
);
220 Configuration
->ConOutColumn
= PcdGet32 (PcdConOutRow
);
222 Status
= gRT
->SetVariable (
224 &gEfiWinNtSystemConfigGuid
,
225 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
226 sizeof (WIN_NT_SYSTEM_CONFIGURATION
),
229 if (EFI_ERROR (Status
)) {
230 DEBUG ((EFI_D_ERROR
, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status
));
232 FreePool (Configuration
);
236 // Update the ocnsole variables.
238 for (Index
= 0; gPlatformConsole
[Index
].DevicePath
!= NULL
; Index
++) {
239 if ((gPlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
240 EfiBootManagerUpdateConsoleVariable (ConIn
, gPlatformConsole
[Index
].DevicePath
, NULL
);
243 if ((gPlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
244 EfiBootManagerUpdateConsoleVariable (ConOut
, gPlatformConsole
[Index
].DevicePath
, NULL
);
247 if ((gPlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
248 EfiBootManagerUpdateConsoleVariable (ErrOut
, gPlatformConsole
[Index
].DevicePath
, NULL
);
253 // Register ENTER as CONTINUE key
255 Enter
.ScanCode
= SCAN_NULL
;
256 Enter
.UnicodeChar
= CHAR_CARRIAGE_RETURN
;
257 EfiBootManagerRegisterContinueKeyOption (0, &Enter
, NULL
);
259 // Map F2 to Boot Manager Menu
261 F2
.ScanCode
= SCAN_F2
;
262 F2
.UnicodeChar
= CHAR_NULL
;
263 EfiBootManagerGetBootManagerMenu (&BootOption
);
264 EfiBootManagerAddKeyOptionVariable (NULL
, (UINT16
) BootOption
.OptionNumber
, 0, &F2
, NULL
);
266 // Register UEFI Shell
268 PlatformRegisterFvBootOption (&mUefiShellFileGuid
, L
"UEFI Shell", LOAD_OPTION_ACTIVE
);
272 Do the platform specific action after the console is connected.
275 Dynamically switch output mode;
276 Signal console ready platform customized event;
277 Run diagnostics like memory testing;
278 Connect certain devices;
279 Dispatch aditional option roms.
283 PlatformBootManagerAfterConsole (
287 PlatformBootManagerMemoryTest (QUICK
);
288 EfiBootManagerConnectAll ();
289 EfiBootManagerRefreshAllBootOption ();
292 L
"F2 to enter Boot Manager Menu.\n"
293 L
"Enter to boot directly.\n"
299 This function is called each second during the boot manager waits the timeout.
301 @param TimeoutRemain The remaining timeout.
305 PlatformBootManagerWaitCallback (
309 Print (L
"\r%-2d seconds remained...", TimeoutRemain
);