]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.c
Nt32Pkg PlatformBootManagerLib: Enable BootManagerMenuApp.
[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 BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
278
279 for (Index = 0; Index < BootOptionCount; Index++) {
280 if (IsBootManagerMenuAppFilePath (BootOptions[Index].FilePath)) {
281 OptionNumber = BootOptions[Index].OptionNumber;
282 break;
283 }
284 }
285
286 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
287
288 if (Index >= BootOptionCount) {
289 //
290 // If not found the BootManagerMenuApp, create it.
291 //
292 OptionNumber = (UINT16) RegisterBootManagerMenuAppBootOption (&mBootMenuFile, L"UEFI BootManagerMenuApp", (UINTN) -1, FALSE);
293 }
294
295 return OptionNumber;
296 }
297
298 /**
299 Do the platform specific action after the console is connected.
300
301 Such as:
302 Dynamically switch output mode;
303 Signal console ready platform customized event;
304 Run diagnostics like memory testing;
305 Connect certain devices;
306 Dispatch aditional option roms.
307 **/
308 VOID
309 EFIAPI
310 PlatformBootManagerAfterConsole (
311 VOID
312 )
313 {
314 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black;
315 EFI_GRAPHICS_OUTPUT_BLT_PIXEL White;
316 EFI_INPUT_KEY Enter;
317 EFI_INPUT_KEY F2;
318 EFI_INPUT_KEY F7;
319 EFI_BOOT_MANAGER_LOAD_OPTION BootOption;
320 UINTN OptionNumber;
321
322 Black.Blue = Black.Green = Black.Red = Black.Reserved = 0;
323 White.Blue = White.Green = White.Red = White.Reserved = 0xFF;
324
325 EfiBootManagerConnectAll ();
326 EfiBootManagerRefreshAllBootOption ();
327
328 //
329 // Register ENTER as CONTINUE key
330 //
331 Enter.ScanCode = SCAN_NULL;
332 Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;
333 EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);
334 //
335 // Map F2 to Boot Manager Menu
336 //
337 F2.ScanCode = SCAN_F2;
338 F2.UnicodeChar = CHAR_NULL;
339 EfiBootManagerGetBootManagerMenu (&BootOption);
340 EfiBootManagerAddKeyOptionVariable (NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL);
341
342 //
343 // 3. Boot Device List menu
344 //
345 F7.ScanCode = SCAN_F7;
346 F7.UnicodeChar = CHAR_NULL;
347 OptionNumber = GetBootManagerMenuAppOption ();
348 EfiBootManagerAddKeyOptionVariable (NULL, (UINT16)OptionNumber, 0, &F7, NULL);
349
350 //
351 // Make Shell as the first boot option
352 //
353 EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, (SORT_COMPARE) CompareBootOption);
354
355 PlatformBootManagerDiagnostics (QUICK, TRUE);
356
357 PrintXY (10, 10, &White, &Black, L"F2 to enter Setup. ");
358 PrintXY (10, 30, &White, &Black, L"F7 to enter Boot Manager Menu.");
359 PrintXY (10, 50, &White, &Black, L"Enter to boot directly.");
360 }
361
362 /**
363 This function is called each second during the boot manager waits the timeout.
364
365 @param TimeoutRemain The remaining timeout.
366 **/
367 VOID
368 EFIAPI
369 PlatformBootManagerWaitCallback (
370 UINT16 TimeoutRemain
371 )
372 {
373 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Black;
374 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION White;
375 UINT16 Timeout;
376
377 Timeout = PcdGet16 (PcdPlatformBootTimeOut);
378
379 Black.Raw = 0x00000000;
380 White.Raw = 0x00FFFFFF;
381
382 BootLogoUpdateProgress (
383 White.Pixel,
384 Black.Pixel,
385 L"Start boot option",
386 White.Pixel,
387 (Timeout - TimeoutRemain) * 100 / Timeout,
388 0
389 );
390 }