]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/BootManagerUiLib/BootManager.c
MdeModulePkg BrotliLib: Rename function with the specific lib name
[mirror_edk2.git] / MdeModulePkg / Library / BootManagerUiLib / BootManager.c
CommitLineData
3a2dc0f5
DB
1/** @file\r
2 The boot manager reference implementation\r
3\r
c51f5f17 4Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
f3b006c8
ED
5This program and the accompanying materials are licensed and made available under\r
6the terms and conditions of the BSD License that accompanies this distribution.\r
7The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php.\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
3a2dc0f5
DB
12\r
13**/\r
14\r
15#include "BootManager.h"\r
16\r
17UINT16 mKeyInput;\r
18EFI_GUID mBootManagerGuid = BOOT_MANAGER_FORMSET_GUID;\r
19//\r
20// Boot video resolution and text mode.\r
21//\r
22UINT32 mBmBootHorizontalResolution = 0;\r
23UINT32 mBmBootVerticalResolution = 0;\r
24UINT32 mBmBootTextModeColumn = 0;\r
25UINT32 mBmBootTextModeRow = 0;\r
26//\r
27// BIOS setup video resolution and text mode.\r
28//\r
29UINT32 mBmSetupTextModeColumn = 0;\r
30UINT32 mBmSetupTextModeRow = 0;\r
31UINT32 mBmSetupHorizontalResolution = 0;\r
32UINT32 mBmSetupVerticalResolution = 0;\r
33\r
cb9fcac0
ED
34BOOLEAN mBmModeInitialized = FALSE;\r
35\r
3a2dc0f5
DB
36CHAR16 *mDeviceTypeStr[] = {\r
37 L"Legacy BEV",\r
38 L"Legacy Floppy",\r
39 L"Legacy Hard Drive",\r
40 L"Legacy CD ROM",\r
41 L"Legacy PCMCIA",\r
42 L"Legacy USB",\r
43 L"Legacy Embedded Network",\r
44 L"Legacy Unknown Device"\r
45};\r
46\r
47HII_VENDOR_DEVICE_PATH mBootManagerHiiVendorDevicePath = {\r
48 {\r
49 {\r
50 HARDWARE_DEVICE_PATH,\r
51 HW_VENDOR_DP,\r
52 {\r
53 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
54 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
55 }\r
56 },\r
57 //\r
58 // {1DDDBE15-481D-4d2b-8277-B191EAF66525}\r
59 //\r
60 { 0x1dddbe15, 0x481d, 0x4d2b, { 0x82, 0x77, 0xb1, 0x91, 0xea, 0xf6, 0x65, 0x25 } }\r
61 },\r
62 {\r
63 END_DEVICE_PATH_TYPE,\r
64 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
65 { \r
66 (UINT8) (END_DEVICE_PATH_LENGTH),\r
67 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
68 }\r
69 }\r
70};\r
71\r
72BOOT_MANAGER_CALLBACK_DATA gBootManagerPrivate = {\r
73 BOOT_MANAGER_CALLBACK_DATA_SIGNATURE,\r
74 NULL,\r
75 NULL,\r
76 {\r
77 BootManagerExtractConfig,\r
78 BootManagerRouteConfig,\r
79 BootManagerCallback\r
80 }\r
81};\r
82\r
83/**\r
84 This function will change video resolution and text mode\r
85 according to defined setup mode or defined boot mode \r
86\r
87 @param IsSetupMode Indicate mode is changed to setup mode or boot mode. \r
88\r
89 @retval EFI_SUCCESS Mode is changed successfully.\r
90 @retval Others Mode failed to be changed.\r
91\r
92**/\r
93EFI_STATUS\r
b6c8ee68 94BmSetConsoleMode (\r
3a2dc0f5
DB
95 BOOLEAN IsSetupMode\r
96 )\r
97{\r
98 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
99 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;\r
100 UINTN SizeOfInfo;\r
101 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r
102 UINT32 MaxGopMode;\r
103 UINT32 MaxTextMode;\r
104 UINT32 ModeNumber;\r
105 UINT32 NewHorizontalResolution;\r
106 UINT32 NewVerticalResolution;\r
107 UINT32 NewColumns;\r
108 UINT32 NewRows;\r
109 UINTN HandleCount;\r
110 EFI_HANDLE *HandleBuffer;\r
111 EFI_STATUS Status;\r
112 UINTN Index;\r
113 UINTN CurrentColumn;\r
114 UINTN CurrentRow; \r
115\r
116 MaxGopMode = 0;\r
117 MaxTextMode = 0;\r
118\r
119 //\r
120 // Get current video resolution and text mode \r
121 //\r
122 Status = gBS->HandleProtocol (\r
123 gST->ConsoleOutHandle,\r
124 &gEfiGraphicsOutputProtocolGuid,\r
125 (VOID**)&GraphicsOutput\r
126 );\r
127 if (EFI_ERROR (Status)) {\r
128 GraphicsOutput = NULL;\r
129 }\r
130\r
131 Status = gBS->HandleProtocol (\r
132 gST->ConsoleOutHandle,\r
133 &gEfiSimpleTextOutProtocolGuid,\r
134 (VOID**)&SimpleTextOut\r
135 );\r
136 if (EFI_ERROR (Status)) {\r
137 SimpleTextOut = NULL;\r
138 }\r
139\r
140 if ((GraphicsOutput == NULL) || (SimpleTextOut == NULL)) {\r
141 return EFI_UNSUPPORTED;\r
142 }\r
143\r
144 if (IsSetupMode) {\r
145 //\r
2048c585 146 // The required resolution and text mode is setup mode.\r
3a2dc0f5
DB
147 //\r
148 NewHorizontalResolution = mBmSetupHorizontalResolution;\r
149 NewVerticalResolution = mBmSetupVerticalResolution;\r
150 NewColumns = mBmSetupTextModeColumn;\r
151 NewRows = mBmSetupTextModeRow;\r
152 } else {\r
153 //\r
154 // The required resolution and text mode is boot mode.\r
155 //\r
156 NewHorizontalResolution = mBmBootHorizontalResolution;\r
157 NewVerticalResolution = mBmBootVerticalResolution;\r
158 NewColumns = mBmBootTextModeColumn;\r
159 NewRows = mBmBootTextModeRow; \r
160 }\r
161\r
162 if (GraphicsOutput != NULL) {\r
163 MaxGopMode = GraphicsOutput->Mode->MaxMode;\r
164 }\r
165\r
166 if (SimpleTextOut != NULL) {\r
167 MaxTextMode = SimpleTextOut->Mode->MaxMode;\r
168 }\r
169\r
170 //\r
171 // 1. If current video resolution is same with required video resolution,\r
172 // video resolution need not be changed.\r
173 // 1.1. If current text mode is same with required text mode, text mode need not be changed.\r
174 // 1.2. If current text mode is different from required text mode, text mode need be changed.\r
175 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.\r
176 //\r
177 for (ModeNumber = 0; ModeNumber < MaxGopMode; ModeNumber++) {\r
178 Status = GraphicsOutput->QueryMode (\r
179 GraphicsOutput,\r
180 ModeNumber,\r
181 &SizeOfInfo,\r
182 &Info\r
183 );\r
184 if (!EFI_ERROR (Status)) {\r
185 if ((Info->HorizontalResolution == NewHorizontalResolution) &&\r
186 (Info->VerticalResolution == NewVerticalResolution)) {\r
187 if ((GraphicsOutput->Mode->Info->HorizontalResolution == NewHorizontalResolution) &&\r
188 (GraphicsOutput->Mode->Info->VerticalResolution == NewVerticalResolution)) {\r
189 //\r
190 // Current resolution is same with required resolution, check if text mode need be set\r
191 //\r
192 Status = SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOut->Mode->Mode, &CurrentColumn, &CurrentRow);\r
193 ASSERT_EFI_ERROR (Status);\r
194 if (CurrentColumn == NewColumns && CurrentRow == NewRows) {\r
195 //\r
196 // If current text mode is same with required text mode. Do nothing\r
197 //\r
198 FreePool (Info);\r
199 return EFI_SUCCESS;\r
200 } else {\r
201 //\r
2048c585 202 // If current text mode is different from required text mode. Set new video mode\r
3a2dc0f5
DB
203 //\r
204 for (Index = 0; Index < MaxTextMode; Index++) {\r
205 Status = SimpleTextOut->QueryMode (SimpleTextOut, Index, &CurrentColumn, &CurrentRow);\r
206 if (!EFI_ERROR(Status)) {\r
207 if ((CurrentColumn == NewColumns) && (CurrentRow == NewRows)) {\r
208 //\r
209 // Required text mode is supported, set it.\r
210 //\r
211 Status = SimpleTextOut->SetMode (SimpleTextOut, Index);\r
212 ASSERT_EFI_ERROR (Status);\r
213 //\r
214 // Update text mode PCD.\r
215 //\r
e750958b
DB
216 Status = PcdSet32S (PcdConOutColumn, mBmSetupTextModeColumn);\r
217 ASSERT_EFI_ERROR (Status);\r
218 Status = PcdSet32S (PcdConOutRow, mBmSetupTextModeRow);\r
219 ASSERT_EFI_ERROR (Status);\r
3a2dc0f5
DB
220 FreePool (Info);\r
221 return EFI_SUCCESS;\r
222 }\r
223 }\r
224 }\r
225 if (Index == MaxTextMode) {\r
226 //\r
2048c585 227 // If required text mode is not supported, return error.\r
3a2dc0f5
DB
228 //\r
229 FreePool (Info);\r
230 return EFI_UNSUPPORTED;\r
231 }\r
232 }\r
233 } else {\r
234 //\r
235 // If current video resolution is not same with the new one, set new video resolution.\r
236 // In this case, the driver which produces simple text out need be restarted.\r
237 //\r
238 Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);\r
239 if (!EFI_ERROR (Status)) {\r
240 FreePool (Info);\r
241 break;\r
242 }\r
243 }\r
244 }\r
245 FreePool (Info);\r
246 }\r
247 }\r
248\r
249 if (ModeNumber == MaxGopMode) {\r
250 //\r
251 // If the resolution is not supported, return error.\r
252 //\r
253 return EFI_UNSUPPORTED;\r
254 }\r
255\r
256 //\r
257 // Set PCD to Inform GraphicsConsole to change video resolution.\r
258 // Set PCD to Inform Consplitter to change text mode.\r
259 //\r
e750958b
DB
260 Status = PcdSet32S (PcdVideoHorizontalResolution, NewHorizontalResolution);\r
261 ASSERT_EFI_ERROR (Status);\r
262 Status = PcdSet32S (PcdVideoVerticalResolution, NewVerticalResolution);\r
263 ASSERT_EFI_ERROR (Status);\r
264 Status = PcdSet32S (PcdConOutColumn, NewColumns);\r
265 ASSERT_EFI_ERROR (Status);\r
266 Status = PcdSet32S (PcdConOutRow, NewRows);\r
267 ASSERT_EFI_ERROR (Status);\r
3a2dc0f5
DB
268\r
269 //\r
270 // Video mode is changed, so restart graphics console driver and higher level driver.\r
271 // Reconnect graphics console driver and higher level driver.\r
272 // Locate all the handles with GOP protocol and reconnect it.\r
273 //\r
274 Status = gBS->LocateHandleBuffer (\r
275 ByProtocol,\r
276 &gEfiSimpleTextOutProtocolGuid,\r
277 NULL,\r
278 &HandleCount,\r
279 &HandleBuffer\r
280 );\r
281 if (!EFI_ERROR (Status)) {\r
282 for (Index = 0; Index < HandleCount; Index++) {\r
283 gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);\r
284 }\r
285 for (Index = 0; Index < HandleCount; Index++) {\r
286 gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);\r
287 }\r
288 if (HandleBuffer != NULL) {\r
289 FreePool (HandleBuffer);\r
290 }\r
291 }\r
292\r
293 return EFI_SUCCESS;\r
294}\r
295\r
c51f5f17
BD
296/**\r
297\r
298 Check whether a reset is needed,if reset is needed, Popup a menu to notice user.\r
299\r
300**/\r
301VOID\r
302BmSetupResetReminder (\r
303 VOID\r
304 )\r
305{\r
306 EFI_INPUT_KEY Key;\r
307 CHAR16 *StringBuffer1;\r
308 CHAR16 *StringBuffer2;\r
309 EFI_STATUS Status;\r
310 EDKII_FORM_BROWSER_EXTENSION2_PROTOCOL *FormBrowserEx2;\r
311\r
312 //\r
313 // Use BrowserEx2 protocol to check whether reset is required.\r
314 //\r
315 Status = gBS->LocateProtocol (&gEdkiiFormBrowserEx2ProtocolGuid, NULL, (VOID **) &FormBrowserEx2);\r
316 //\r
317 //check any reset required change is applied? if yes, reset system\r
318 //\r
319 if (!EFI_ERROR(Status) && FormBrowserEx2->IsResetRequired ()) {\r
320 StringBuffer1 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));\r
321 ASSERT (StringBuffer1 != NULL);\r
322 StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));\r
323 ASSERT (StringBuffer2 != NULL);\r
324 StrCpyS (StringBuffer1, MAX_STRING_LEN, L"Configuration changed. Reset to apply it Now.");\r
325 StrCpyS (StringBuffer2, MAX_STRING_LEN, L"Press ENTER to reset");\r
326 //\r
327 // Popup a menu to notice user\r
328 //\r
329 do {\r
330 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);\r
331 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
332\r
333 FreePool (StringBuffer1);\r
334 FreePool (StringBuffer2);\r
335\r
336 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);\r
337 }\r
338}\r
339\r
3a2dc0f5
DB
340/**\r
341 Group the legacy boot options in the BootOption.\r
342\r
343 The routine assumes the boot options in the beginning that covers all the device \r
344 types are ordered properly and re-position the following boot options just after\r
345 the corresponding boot options with the same device type.\r
346 For example:\r
347 1. Input = [Harddisk1 CdRom2 Efi1 Harddisk0 CdRom0 CdRom1 Harddisk2 Efi0]\r
348 Assuming [Harddisk1 CdRom2 Efi1] is ordered properly\r
349 Output = [Harddisk1 Harddisk0 Harddisk2 CdRom2 CdRom0 CdRom1 Efi1 Efi0]\r
350\r
351 2. Input = [Efi1 Efi0 CdRom1 Harddisk0 Harddisk1 Harddisk2 CdRom0 CdRom2]\r
352 Assuming [Efi1 Efi0 CdRom1 Harddisk0] is ordered properly\r
353 Output = [Efi1 Efi0 CdRom1 CdRom0 CdRom2 Harddisk0 Harddisk1 Harddisk2]\r
354\r
355**/\r
356VOID\r
357GroupMultipleLegacyBootOption4SameType (\r
358 VOID\r
359 )\r
360{\r
361 EFI_STATUS Status;\r
362 UINTN Index;\r
363 UINTN DeviceIndex;\r
364 UINTN DeviceTypeIndex[7];\r
365 UINTN *NextIndex;\r
366 UINT16 OptionNumber;\r
367 UINT16 *BootOrder;\r
368 UINTN BootOrderSize;\r
369 CHAR16 OptionName[sizeof ("Boot####")];\r
370 EFI_BOOT_MANAGER_LOAD_OPTION BootOption;\r
371\r
372 SetMem (DeviceTypeIndex, sizeof (DeviceTypeIndex), 0xff);\r
373\r
374 GetEfiGlobalVariable2 (L"BootOrder", (VOID **) &BootOrder, &BootOrderSize);\r
bd69e72c
ED
375 if (BootOrder == NULL) {\r
376 return;\r
377 }\r
3a2dc0f5
DB
378\r
379 for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {\r
380 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", BootOrder[Index]);\r
381 Status = EfiBootManagerVariableToLoadOption (OptionName, &BootOption);\r
382 ASSERT_EFI_ERROR (Status);\r
383\r
384 if ((DevicePathType (BootOption.FilePath) == BBS_DEVICE_PATH) &&\r
385 (DevicePathSubType (BootOption.FilePath) == BBS_BBS_DP)) {\r
386 //\r
387 // Legacy Boot Option\r
388 //\r
389 DEBUG ((EFI_D_ERROR, "[BootManagerDxe] ==== Find Legacy Boot Option 0x%x! ==== \n", Index));\r
a031a53f 390 ASSERT ((((BBS_BBS_DEVICE_PATH *) BootOption.FilePath)->DeviceType & 0xF) < ARRAY_SIZE (DeviceTypeIndex));\r
3a2dc0f5
DB
391 NextIndex = &DeviceTypeIndex[((BBS_BBS_DEVICE_PATH *) BootOption.FilePath)->DeviceType & 0xF];\r
392\r
393 if (*NextIndex == (UINTN) -1) {\r
394 //\r
395 // *NextIndex is the Index in BootOrder to put the next Option Number for the same type\r
396 //\r
397 *NextIndex = Index + 1;\r
398 } else {\r
399 //\r
400 // insert the current boot option before *NextIndex, causing [*Next .. Index] shift right one position\r
401 //\r
402 OptionNumber = BootOrder[Index];\r
403 CopyMem (&BootOrder[*NextIndex + 1], &BootOrder[*NextIndex], (Index - *NextIndex) * sizeof (UINT16));\r
404 BootOrder[*NextIndex] = OptionNumber;\r
405\r
406 //\r
407 // Update the DeviceTypeIndex array to reflect the right shift operation\r
408 //\r
a031a53f 409 for (DeviceIndex = 0; DeviceIndex < ARRAY_SIZE (DeviceTypeIndex); DeviceIndex++) {\r
3a2dc0f5
DB
410 if (DeviceTypeIndex[DeviceIndex] != (UINTN) -1 && DeviceTypeIndex[DeviceIndex] >= *NextIndex) {\r
411 DeviceTypeIndex[DeviceIndex]++;\r
412 }\r
413 }\r
414 }\r
415 }\r
416 EfiBootManagerFreeLoadOption (&BootOption);\r
417 }\r
418\r
419 gRT->SetVariable (\r
420 L"BootOrder",\r
421 &gEfiGlobalVariableGuid,\r
422 VAR_FLAG,\r
423 BootOrderSize,\r
424 BootOrder\r
425 );\r
426 FreePool (BootOrder);\r
427}\r
428\r
429/**\r
430 This function converts an input device structure to a Unicode string.\r
431\r
432 @param DevPath A pointer to the device path structure.\r
433\r
434 @return A new allocated Unicode string that represents the device path.\r
435\r
436**/\r
437CHAR16 *\r
438BmDevicePathToStr (\r
439 IN EFI_DEVICE_PATH_PROTOCOL *DevPath\r
440 )\r
441{\r
442 EFI_STATUS Status;\r
443 CHAR16 *ToText;\r
444 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText;\r
445\r
446 if (DevPath == NULL) {\r
447 return NULL;\r
448 }\r
449\r
450 Status = gBS->LocateProtocol (\r
451 &gEfiDevicePathToTextProtocolGuid,\r
452 NULL,\r
453 (VOID **) &DevPathToText\r
454 );\r
455 ASSERT_EFI_ERROR (Status);\r
456 ToText = DevPathToText->ConvertDevicePathToText (\r
457 DevPath,\r
458 FALSE,\r
459 TRUE\r
460 );\r
461 ASSERT (ToText != NULL);\r
462 return ToText;\r
463}\r
464\r
465/**\r
7de6db5f 466 This function invokes Boot Manager. It then enumerate all boot options. If\r
3a2dc0f5
DB
467 a boot option from the Boot Manager page is selected, Boot Manager will boot\r
468 from this boot option.\r
469 \r
470**/\r
471VOID\r
472UpdateBootManager (\r
473 VOID\r
474 )\r
475{\r
476 UINTN Index;\r
477 EFI_BOOT_MANAGER_LOAD_OPTION *BootOption;\r
478 UINTN BootOptionCount;\r
479 EFI_STRING_ID Token;\r
480 CHAR16 *HelpString;\r
481 EFI_STRING_ID HelpToken;\r
482 UINT16 *TempStr;\r
483 EFI_HII_HANDLE HiiHandle;\r
484 UINTN TempSize;\r
485 VOID *StartOpCodeHandle;\r
486 VOID *EndOpCodeHandle;\r
487 EFI_IFR_GUID_LABEL *StartLabel;\r
488 EFI_IFR_GUID_LABEL *EndLabel;\r
489 UINT16 DeviceType;\r
490 BOOLEAN IsLegacyOption;\r
491 BOOLEAN NeedEndOp;\r
492 UINTN MaxLen;\r
493\r
494 DeviceType = (UINT16) -1;\r
495\r
3a2dc0f5
DB
496 //\r
497 // for better user experience\r
498 // 1. User changes HD configuration (e.g.: unplug HDD), here we have a chance to remove the HDD boot option\r
499 // 2. User enables/disables UEFI PXE, here we have a chance to add/remove EFI Network boot option\r
500 //\r
501 EfiBootManagerRefreshAllBootOption ();\r
502\r
503 //\r
504 // BdsDxe doesn't group the legacy boot options for the same device type\r
505 // It's UI's choice.\r
506 //\r
507 GroupMultipleLegacyBootOption4SameType ();\r
508\r
509 BootOption = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);\r
510\r
511 HiiHandle = gBootManagerPrivate.HiiHandle;\r
512\r
513 //\r
514 // Allocate space for creation of UpdateData Buffer\r
515 //\r
516 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
517 ASSERT (StartOpCodeHandle != NULL);\r
518\r
519 EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
520 ASSERT (EndOpCodeHandle != NULL);\r
521\r
522 //\r
523 // Create Hii Extend Label OpCode as the start opcode\r
524 //\r
525 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
526 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
527 StartLabel->Number = LABEL_BOOT_OPTION;\r
528\r
529 //\r
530 // Create Hii Extend Label OpCode as the end opcode\r
531 //\r
532 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
533 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
534 EndLabel->Number = LABEL_BOOT_OPTION_END;\r
535 mKeyInput = 0;\r
536 NeedEndOp = FALSE;\r
537 for (Index = 0; Index < BootOptionCount; Index++) {\r
538 //\r
539 // At this stage we are creating a menu entry, thus the Keys are reproduceable\r
540 //\r
541 mKeyInput++;\r
542\r
543 //\r
544 // Don't display the hidden/inactive boot option\r
545 //\r
546 if (((BootOption[Index].Attributes & LOAD_OPTION_HIDDEN) != 0) || ((BootOption[Index].Attributes & LOAD_OPTION_ACTIVE) == 0)) {\r
547 continue;\r
548 }\r
549\r
550 //\r
551 // Group the legacy boot option in the sub title created dynamically\r
552 //\r
553 IsLegacyOption = (BOOLEAN) (\r
554 (DevicePathType (BootOption[Index].FilePath) == BBS_DEVICE_PATH) &&\r
555 (DevicePathSubType (BootOption[Index].FilePath) == BBS_BBS_DP)\r
556 );\r
557\r
558 if (!IsLegacyOption && NeedEndOp) {\r
559 NeedEndOp = FALSE;\r
560 HiiCreateEndOpCode (StartOpCodeHandle);\r
561 }\r
562 \r
563 if (IsLegacyOption && DeviceType != ((BBS_BBS_DEVICE_PATH *) BootOption[Index].FilePath)->DeviceType) {\r
564 if (NeedEndOp) {\r
565 HiiCreateEndOpCode (StartOpCodeHandle);\r
566 }\r
567\r
568 DeviceType = ((BBS_BBS_DEVICE_PATH *) BootOption[Index].FilePath)->DeviceType;\r
569 Token = HiiSetString (\r
570 HiiHandle,\r
571 0,\r
572 mDeviceTypeStr[\r
a031a53f 573 MIN (DeviceType & 0xF, ARRAY_SIZE (mDeviceTypeStr) - 1)\r
3a2dc0f5
DB
574 ],\r
575 NULL\r
576 );\r
577 HiiCreateSubTitleOpCode (StartOpCodeHandle, Token, 0, 0, 1);\r
578 NeedEndOp = TRUE;\r
579 }\r
580\r
581 ASSERT (BootOption[Index].Description != NULL);\r
582\r
583 Token = HiiSetString (HiiHandle, 0, BootOption[Index].Description, NULL);\r
584\r
585 TempStr = BmDevicePathToStr (BootOption[Index].FilePath);\r
586 TempSize = StrSize (TempStr);\r
587 HelpString = AllocateZeroPool (TempSize + StrSize (L"Device Path : "));\r
588 MaxLen = (TempSize + StrSize (L"Device Path : "))/sizeof(CHAR16);\r
589 ASSERT (HelpString != NULL);\r
590 StrCatS (HelpString, MaxLen, L"Device Path : ");\r
591 StrCatS (HelpString, MaxLen, TempStr);\r
592\r
593 HelpToken = HiiSetString (HiiHandle, 0, HelpString, NULL);\r
594\r
595 HiiCreateActionOpCode (\r
596 StartOpCodeHandle,\r
597 mKeyInput,\r
598 Token,\r
599 HelpToken,\r
600 EFI_IFR_FLAG_CALLBACK,\r
601 0\r
602 );\r
603 }\r
604\r
605 if (NeedEndOp) {\r
606 HiiCreateEndOpCode (StartOpCodeHandle);\r
607 }\r
608\r
609 HiiUpdateForm (\r
610 HiiHandle,\r
611 &mBootManagerGuid,\r
612 BOOT_MANAGER_FORM_ID,\r
613 StartOpCodeHandle,\r
614 EndOpCodeHandle\r
615 );\r
616\r
617 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
618 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
619\r
620 EfiBootManagerFreeLoadOptions (BootOption, BootOptionCount);\r
621}\r
622\r
623/**\r
624 This function allows a caller to extract the current configuration for one\r
625 or more named elements from the target driver.\r
626\r
627\r
628 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
629 @param Request A null-terminated Unicode string in <ConfigRequest> format.\r
630 @param Progress On return, points to a character in the Request string.\r
631 Points to the string's null terminator if request was successful.\r
632 Points to the most recent '&' before the first failing name/value\r
633 pair (or the beginning of the string if the failure is in the\r
634 first name/value pair) if the request was not successful.\r
635 @param Results A null-terminated Unicode string in <ConfigAltResp> format which\r
636 has all values filled in for the names in the Request string.\r
637 String to be allocated by the called function.\r
638\r
639 @retval EFI_SUCCESS The Results is filled with the requested values.\r
640 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r
641 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r
642 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r
643\r
644**/\r
645EFI_STATUS\r
646EFIAPI\r
647BootManagerExtractConfig (\r
648 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
649 IN CONST EFI_STRING Request,\r
650 OUT EFI_STRING *Progress,\r
651 OUT EFI_STRING *Results\r
652 )\r
653{\r
654 if (Progress == NULL || Results == NULL) {\r
655 return EFI_INVALID_PARAMETER;\r
656 }\r
657 *Progress = Request;\r
658 return EFI_NOT_FOUND;\r
659}\r
660\r
661/**\r
662 This function processes the results of changes in configuration.\r
663\r
664\r
665 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
666 @param Configuration A null-terminated Unicode string in <ConfigResp> format.\r
667 @param Progress A pointer to a string filled in with the offset of the most\r
668 recent '&' before the first failing name/value pair (or the\r
669 beginning of the string if the failure is in the first\r
670 name/value pair) or the terminating NULL if all was successful.\r
671\r
672 @retval EFI_SUCCESS The Results is processed successfully.\r
673 @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
674 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r
675\r
676**/\r
677EFI_STATUS\r
678EFIAPI\r
679BootManagerRouteConfig (\r
680 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
681 IN CONST EFI_STRING Configuration,\r
682 OUT EFI_STRING *Progress\r
683 )\r
684{\r
685 if (Configuration == NULL || Progress == NULL) {\r
686 return EFI_INVALID_PARAMETER;\r
687 }\r
688\r
689 *Progress = Configuration;\r
690\r
691 return EFI_NOT_FOUND;\r
692}\r
693\r
cb9fcac0
ED
694/**\r
695 Initial the boot mode related parameters.\r
696\r
697**/\r
698VOID\r
699BmInitialBootModeInfo (\r
700 VOID\r
701 )\r
702{\r
703 EFI_STATUS Status;\r
704 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
705 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;\r
706 UINTN BootTextColumn;\r
707 UINTN BootTextRow;\r
708\r
709 if (mBmModeInitialized) {\r
710 return;\r
711 }\r
712\r
713 //\r
714 // After the console is ready, get current video resolution\r
715 // and text mode before launching setup at first time.\r
716 //\r
717 Status = gBS->HandleProtocol (\r
718 gST->ConsoleOutHandle,\r
719 &gEfiGraphicsOutputProtocolGuid,\r
720 (VOID**)&GraphicsOutput\r
721 );\r
722 if (EFI_ERROR (Status)) {\r
723 GraphicsOutput = NULL;\r
724 }\r
725\r
726 Status = gBS->HandleProtocol (\r
727 gST->ConsoleOutHandle,\r
728 &gEfiSimpleTextOutProtocolGuid,\r
729 (VOID**)&SimpleTextOut\r
730 );\r
731 if (EFI_ERROR (Status)) {\r
732 SimpleTextOut = NULL;\r
733 }\r
734\r
735 if (GraphicsOutput != NULL) {\r
736 //\r
737 // Get current video resolution and text mode.\r
738 //\r
739 mBmBootHorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;\r
740 mBmBootVerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;\r
741 }\r
742\r
743 if (SimpleTextOut != NULL) {\r
744 Status = SimpleTextOut->QueryMode (\r
745 SimpleTextOut,\r
746 SimpleTextOut->Mode->Mode,\r
747 &BootTextColumn,\r
748 &BootTextRow\r
749 );\r
750 mBmBootTextModeColumn = (UINT32)BootTextColumn;\r
751 mBmBootTextModeRow = (UINT32)BootTextRow;\r
752 }\r
753\r
754 //\r
755 // Get user defined text mode for setup.\r
756 //\r
757 mBmSetupHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution);\r
758 mBmSetupVerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution);\r
759 mBmSetupTextModeColumn = PcdGet32 (PcdSetupConOutColumn);\r
760 mBmSetupTextModeRow = PcdGet32 (PcdSetupConOutRow);\r
761\r
762 mBmModeInitialized = TRUE;\r
763}\r
764\r
3a2dc0f5
DB
765/**\r
766 This call back function is registered with Boot Manager formset.\r
767 When user selects a boot option, this call back function will\r
768 be triggered. The boot option is saved for later processing.\r
769\r
770\r
771 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
772 @param Action Specifies the type of action taken by the browser.\r
773 @param QuestionId A unique value which is sent to the original exporting driver\r
774 so that it can identify the type of data to expect.\r
775 @param Type The type of value for the question.\r
776 @param Value A pointer to the data being sent to the original exporting driver.\r
777 @param ActionRequest On return, points to the action requested by the callback function.\r
778\r
779 @retval EFI_SUCCESS The callback successfully handled the action.\r
780 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.\r
781\r
782**/\r
783EFI_STATUS\r
784EFIAPI\r
785BootManagerCallback (\r
786 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
787 IN EFI_BROWSER_ACTION Action,\r
788 IN EFI_QUESTION_ID QuestionId,\r
789 IN UINT8 Type,\r
790 IN EFI_IFR_TYPE_VALUE *Value,\r
791 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
792 )\r
793{\r
794 EFI_BOOT_MANAGER_LOAD_OPTION *BootOption;\r
795 UINTN BootOptionCount;\r
796 EFI_INPUT_KEY Key;\r
0034796f
DB
797\r
798 if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {\r
799 //\r
800 //Means enter the boot manager form.\r
801 //Update the boot manage page,because the boot option may changed.\r
802 //\r
803 if (QuestionId == 0x1212){\r
804 UpdateBootManager();\r
805 }\r
806 return EFI_SUCCESS;\r
807 }\r
808\r
3a2dc0f5
DB
809 if (Action != EFI_BROWSER_ACTION_CHANGED) {\r
810 //\r
811 // Do nothing for other UEFI Action. Only do call back when data is changed.\r
812 //\r
813 return EFI_UNSUPPORTED;\r
814 }\r
815\r
816 if ((Value == NULL) || (ActionRequest == NULL)) {\r
817 return EFI_INVALID_PARAMETER;\r
818 }\r
819\r
820 BootOption = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);\r
1b43162d
DB
821\r
822 //\r
823 // Clear the screen before.\r
824 //\r
825 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
826 gST->ConOut->ClearScreen (gST->ConOut);\r
827\r
c51f5f17
BD
828 //\r
829 //check any reset required change is applied? if yes, reset system\r
830 //\r
831 BmSetupResetReminder ();\r
832\r
3a2dc0f5
DB
833 //\r
834 // parse the selected option\r
835 //\r
b6c8ee68 836 BmSetConsoleMode (FALSE);\r
3a2dc0f5 837 EfiBootManagerBoot (&BootOption[QuestionId - 1]);\r
b6c8ee68 838 BmSetConsoleMode (TRUE);\r
3a2dc0f5
DB
839\r
840 if (EFI_ERROR (BootOption[QuestionId - 1].Status)) {\r
841 gST->ConOut->OutputString (\r
842 gST->ConOut,\r
843 HiiGetString (gBootManagerPrivate.HiiHandle, STRING_TOKEN (STR_ANY_KEY_CONTINUE), NULL)\r
844 );\r
845 gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
846 }\r
847\r
848 EfiBootManagerFreeLoadOptions (BootOption, BootOptionCount);\r
849\r
850 return EFI_SUCCESS;\r
851}\r
852\r
853/**\r
854\r
855 Install Boot Manager Menu driver.\r
856\r
857 @param ImageHandle The image handle.\r
858 @param SystemTable The system table.\r
859\r
860 @retval EFI_SUCEESS Install Boot manager menu success.\r
861 @retval Other Return error status.\r
862\r
863**/\r
864EFI_STATUS\r
865EFIAPI\r
120c8893 866BootManagerUiLibConstructor (\r
3a2dc0f5
DB
867 IN EFI_HANDLE ImageHandle,\r
868 IN EFI_SYSTEM_TABLE *SystemTable\r
869 )\r
870{\r
871 EFI_STATUS Status;\r
872\r
873 //\r
874 // Install Device Path Protocol and Config Access protocol to driver handle\r
875 //\r
876 gBootManagerPrivate.DriverHandle = NULL;\r
877 Status = gBS->InstallMultipleProtocolInterfaces (\r
878 &gBootManagerPrivate.DriverHandle,\r
879 &gEfiDevicePathProtocolGuid,\r
880 &mBootManagerHiiVendorDevicePath,\r
881 &gEfiHiiConfigAccessProtocolGuid,\r
882 &gBootManagerPrivate.ConfigAccess,\r
883 NULL\r
884 );\r
885 ASSERT_EFI_ERROR (Status);\r
886\r
887 //\r
888 // Publish our HII data\r
889 //\r
890 gBootManagerPrivate.HiiHandle = HiiAddPackages (\r
891 &mBootManagerGuid,\r
892 gBootManagerPrivate.DriverHandle,\r
893 BootManagerVfrBin,\r
120c8893 894 BootManagerUiLibStrings,\r
3a2dc0f5
DB
895 NULL\r
896 );\r
897 ASSERT (gBootManagerPrivate.HiiHandle != NULL);\r
898\r
cb9fcac0 899 BmInitialBootModeInfo ();\r
3a2dc0f5
DB
900\r
901 return EFI_SUCCESS;\r
902}\r
903\r
904/**\r
905 Unloads the application and its installed protocol.\r
906\r
907 @param[in] ImageHandle Handle that identifies the image to be unloaded.\r
908 @param[in] SystemTable System Table\r
909\r
910 @retval EFI_SUCCESS The image has been unloaded.\r
911**/\r
912EFI_STATUS\r
913EFIAPI\r
120c8893 914BootManagerUiLibDestructor (\r
3a2dc0f5
DB
915 IN EFI_HANDLE ImageHandle,\r
916 IN EFI_SYSTEM_TABLE *SystemTable\r
917 )\r
918{\r
919 EFI_STATUS Status;\r
920\r
921 Status = gBS->UninstallMultipleProtocolInterfaces (\r
922 gBootManagerPrivate.DriverHandle,\r
923 &gEfiDevicePathProtocolGuid,\r
924 &mBootManagerHiiVendorDevicePath,\r
925 &gEfiHiiConfigAccessProtocolGuid,\r
926 &gBootManagerPrivate.ConfigAccess,\r
927 NULL\r
928 );\r
929 ASSERT_EFI_ERROR (Status);\r
930\r
931 HiiRemovePackages (gBootManagerPrivate.HiiHandle);\r
932\r
933 return EFI_SUCCESS;\r
934}\r
935\r