]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.c
Nt32Pkg: Fix VS2010/VS2012 build failure
[mirror_edk2.git] / Nt32Pkg / Library / PlatformBootManagerLib / PlatformBootManager.c
1 /** @file
2 This file include all platform action which can be customized
3 by IBV/OEM.
4
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
10
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.
13
14 **/
15
16 #include "PlatformBootManager.h"
17
18 EFI_GUID mBootMenuFile = {
19 0xEEC25BDC, 0x67F2, 0x4D95, { 0xB1, 0xD5, 0xF8, 0x1B, 0x20, 0x39, 0xD1, 0x1D }
20 };
21
22 /**
23 Perform the platform diagnostic, such like test memory. OEM/IBV also
24 can customize this function to support specific platform diagnostic.
25
26 @param MemoryTestLevel The memory test intensive level
27 @param QuietBoot Indicate if need to enable the quiet boot
28
29 **/
30 VOID
31 PlatformBootManagerDiagnostics (
32 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,
33 IN BOOLEAN QuietBoot
34 )
35 {
36 EFI_STATUS Status;
37
38 //
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
43 //
44 if (QuietBoot) {
45 BootLogoEnableLogo (ImageFormatBmp, PcdGetPtr(PcdLogoFile), EdkiiPlatformLogoDisplayAttributeCenter, 0, 0);
46
47 //
48 // Perform system diagnostic
49 //
50 Status = PlatformBootManagerMemoryTest (MemoryTestLevel);
51 if (EFI_ERROR (Status)) {
52 BootLogoDisableLogo ();
53 }
54
55 return;
56 }
57
58 //
59 // Perform system diagnostic
60 //
61 Status = PlatformBootManagerMemoryTest (MemoryTestLevel);
62 }
63
64 /**
65 Do the platform specific action before the console is connected.
66
67 Such as:
68 Update console variable;
69 Register new Driver#### or Boot####;
70 Signal ReadyToLock event.
71 **/
72 VOID
73 EFIAPI
74 PlatformBootManagerBeforeConsole (
75 VOID
76 )
77 {
78 UINTN Index;
79 EFI_STATUS Status;
80 WIN_NT_SYSTEM_CONFIGURATION *Configuration;
81
82 GetVariable2 (L"Setup", &gEfiWinNtSystemConfigGuid, (VOID **) &Configuration, NULL);
83 if (Configuration != NULL) {
84 //
85 // SetupVariable is corrupt
86 //
87 Configuration->ConOutRow = PcdGet32 (PcdConOutColumn);
88 Configuration->ConOutColumn = PcdGet32 (PcdConOutRow);
89
90 Status = gRT->SetVariable (
91 L"Setup",
92 &gEfiWinNtSystemConfigGuid,
93 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
94 sizeof (WIN_NT_SYSTEM_CONFIGURATION),
95 Configuration
96 );
97 if (EFI_ERROR (Status)) {
98 DEBUG ((EFI_D_ERROR, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status));
99 }
100 FreePool (Configuration);
101 }
102
103 //
104 // Update the ocnsole variables.
105 //
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);
109 }
110
111 if ((gPlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {
112 EfiBootManagerUpdateConsoleVariable (ConOut, gPlatformConsole[Index].DevicePath, NULL);
113 }
114
115 if ((gPlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {
116 EfiBootManagerUpdateConsoleVariable (ErrOut, gPlatformConsole[Index].DevicePath, NULL);
117 }
118 }
119 }
120
121 /**
122 Returns the priority number.
123
124 @param BootOption
125 **/
126 UINTN
127 BootOptionPriority (
128 CONST EFI_BOOT_MANAGER_LOAD_OPTION *BootOption
129 )
130 {
131 //
132 // Make sure Shell is first
133 //
134 if (StrCmp (BootOption->Description, L"UEFI Shell") == 0) {
135 return 0;
136 }
137 return 100;
138 }
139
140 INTN
141 EFIAPI
142 CompareBootOption (
143 CONST EFI_BOOT_MANAGER_LOAD_OPTION *Left,
144 CONST EFI_BOOT_MANAGER_LOAD_OPTION *Right
145 )
146 {
147 return BootOptionPriority (Left) - BootOptionPriority (Right);
148 }
149
150 /**
151 Generate device path include the input file guid info.
152
153 @param FileGuid Input file guid for the BootManagerMenuApp.
154
155 @retval DevicePath for BootManagerMenuApp.
156 **/
157 EFI_DEVICE_PATH *
158 FvFilePath (
159 EFI_GUID *FileGuid
160 )
161 {
162
163 EFI_STATUS Status;
164 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
165 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;
166
167 EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);
168
169 Status = gBS->HandleProtocol (
170 gImageHandle,
171 &gEfiLoadedImageProtocolGuid,
172 (VOID **) &LoadedImage
173 );
174 ASSERT_EFI_ERROR (Status);
175
176 return AppendDevicePathNode (
177 DevicePathFromHandle (LoadedImage->DeviceHandle),
178 (EFI_DEVICE_PATH_PROTOCOL *) &FileNode
179 );
180 }
181
182 /**
183 Create one boot option for BootManagerMenuApp.
184
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.
189
190
191 @retval OptionNumber Return the option number info.
192
193 **/
194 UINTN
195 RegisterBootManagerMenuAppBootOption (
196 EFI_GUID *FileGuid,
197 CHAR16 *Description,
198 UINTN Position,
199 BOOLEAN IsBootCategory
200 )
201 {
202 EFI_STATUS Status;
203 EFI_BOOT_MANAGER_LOAD_OPTION NewOption;
204 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
205 UINTN OptionNumber;
206
207 DevicePath = FvFilePath (FileGuid);
208 Status = EfiBootManagerInitializeLoadOption (
209 &NewOption,
210 LoadOptionNumberUnassigned,
211 LoadOptionTypeBoot,
212 IsBootCategory ? LOAD_OPTION_ACTIVE : LOAD_OPTION_CATEGORY_APP,
213 Description,
214 DevicePath,
215 NULL,
216 0
217 );
218 ASSERT_EFI_ERROR (Status);
219 FreePool (DevicePath);
220
221 Status = EfiBootManagerAddLoadOptionVariable (&NewOption, Position);
222 ASSERT_EFI_ERROR (Status);
223
224 OptionNumber = NewOption.OptionNumber;
225
226 EfiBootManagerFreeLoadOption (&NewOption);
227
228 return OptionNumber;
229 }
230
231 /**
232 Check if it's a Device Path pointing to BootManagerMenuApp.
233
234 @param DevicePath Input device path.
235
236 @retval TRUE The device path is BootManagerMenuApp File Device Path.
237 @retval FALSE The device path is NOT BootManagerMenuApp File Device Path.
238 **/
239 BOOLEAN
240 IsBootManagerMenuAppFilePath (
241 EFI_DEVICE_PATH_PROTOCOL *DevicePath
242 )
243 {
244 EFI_HANDLE FvHandle;
245 VOID *NameGuid;
246 EFI_STATUS Status;
247
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);
253 }
254 }
255
256 return FALSE;
257 }
258
259 /**
260 Return the boot option number to the BootManagerMenuApp.
261
262 If not found it in the current boot option, create a new one.
263
264 @retval OptionNumber Return the boot option number to the BootManagerMenuApp.
265
266 **/
267 UINTN
268 GetBootManagerMenuAppOption (
269 VOID
270 )
271 {
272 UINTN BootOptionCount;
273 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
274 UINTN Index;
275 UINTN OptionNumber;
276
277 OptionNumber = 0;
278
279 BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
280
281 for (Index = 0; Index < BootOptionCount; Index++) {
282 if (IsBootManagerMenuAppFilePath (BootOptions[Index].FilePath)) {
283 OptionNumber = BootOptions[Index].OptionNumber;
284 break;
285 }
286 }
287
288 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
289
290 if (Index >= BootOptionCount) {
291 //
292 // If not found the BootManagerMenuApp, create it.
293 //
294 OptionNumber = (UINT16) RegisterBootManagerMenuAppBootOption (&mBootMenuFile, L"UEFI BootManagerMenuApp", (UINTN) -1, FALSE);
295 }
296
297 return OptionNumber;
298 }
299
300 /**
301 Do the platform specific action after the console is connected.
302
303 Such as:
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.
309 **/
310 VOID
311 EFIAPI
312 PlatformBootManagerAfterConsole (
313 VOID
314 )
315 {
316 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black;
317 EFI_GRAPHICS_OUTPUT_BLT_PIXEL White;
318 EFI_INPUT_KEY Enter;
319 EFI_INPUT_KEY F2;
320 EFI_INPUT_KEY F7;
321 EFI_BOOT_MANAGER_LOAD_OPTION BootOption;
322 UINTN OptionNumber;
323
324 Black.Blue = Black.Green = Black.Red = Black.Reserved = 0;
325 White.Blue = White.Green = White.Red = White.Reserved = 0xFF;
326
327 EfiBootManagerConnectAll ();
328 EfiBootManagerRefreshAllBootOption ();
329
330 //
331 // Register ENTER as CONTINUE key
332 //
333 Enter.ScanCode = SCAN_NULL;
334 Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;
335 EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);
336 //
337 // Map F2 to Boot Manager Menu
338 //
339 F2.ScanCode = SCAN_F2;
340 F2.UnicodeChar = CHAR_NULL;
341 EfiBootManagerGetBootManagerMenu (&BootOption);
342 EfiBootManagerAddKeyOptionVariable (NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL);
343
344 //
345 // 3. Boot Device List menu
346 //
347 F7.ScanCode = SCAN_F7;
348 F7.UnicodeChar = CHAR_NULL;
349 OptionNumber = GetBootManagerMenuAppOption ();
350 EfiBootManagerAddKeyOptionVariable (NULL, (UINT16)OptionNumber, 0, &F7, NULL);
351
352 //
353 // Make Shell as the first boot option
354 //
355 EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, (SORT_COMPARE) CompareBootOption);
356
357 PlatformBootManagerDiagnostics (QUICK, TRUE);
358
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.");
362 }
363
364 /**
365 This function is called each second during the boot manager waits the timeout.
366
367 @param TimeoutRemain The remaining timeout.
368 **/
369 VOID
370 EFIAPI
371 PlatformBootManagerWaitCallback (
372 UINT16 TimeoutRemain
373 )
374 {
375 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Black;
376 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION White;
377 UINT16 Timeout;
378
379 Timeout = PcdGet16 (PcdPlatformBootTimeOut);
380
381 Black.Raw = 0x00000000;
382 White.Raw = 0x00FFFFFF;
383
384 BootLogoUpdateProgress (
385 White.Pixel,
386 Black.Pixel,
387 L"Start boot option",
388 White.Pixel,
389 (Timeout - TimeoutRemain) * 100 / Timeout,
390 0
391 );
392 }