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