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