]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/BootManagerLib/BootManager.c
BootManagerLib: Update copyright, use BSD license instead of Intel license.
[mirror_edk2.git] / MdeModulePkg / Library / BootManagerLib / 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
330\r
331 for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {\r
332 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", BootOrder[Index]);\r
333 Status = EfiBootManagerVariableToLoadOption (OptionName, &BootOption);\r
334 ASSERT_EFI_ERROR (Status);\r
335\r
336 if ((DevicePathType (BootOption.FilePath) == BBS_DEVICE_PATH) &&\r
337 (DevicePathSubType (BootOption.FilePath) == BBS_BBS_DP)) {\r
338 //\r
339 // Legacy Boot Option\r
340 //\r
341 DEBUG ((EFI_D_ERROR, "[BootManagerDxe] ==== Find Legacy Boot Option 0x%x! ==== \n", Index));\r
342 ASSERT ((((BBS_BBS_DEVICE_PATH *) BootOption.FilePath)->DeviceType & 0xF) < sizeof (DeviceTypeIndex) / sizeof (DeviceTypeIndex[0]));\r
343 NextIndex = &DeviceTypeIndex[((BBS_BBS_DEVICE_PATH *) BootOption.FilePath)->DeviceType & 0xF];\r
344\r
345 if (*NextIndex == (UINTN) -1) {\r
346 //\r
347 // *NextIndex is the Index in BootOrder to put the next Option Number for the same type\r
348 //\r
349 *NextIndex = Index + 1;\r
350 } else {\r
351 //\r
352 // insert the current boot option before *NextIndex, causing [*Next .. Index] shift right one position\r
353 //\r
354 OptionNumber = BootOrder[Index];\r
355 CopyMem (&BootOrder[*NextIndex + 1], &BootOrder[*NextIndex], (Index - *NextIndex) * sizeof (UINT16));\r
356 BootOrder[*NextIndex] = OptionNumber;\r
357\r
358 //\r
359 // Update the DeviceTypeIndex array to reflect the right shift operation\r
360 //\r
361 for (DeviceIndex = 0; DeviceIndex < sizeof (DeviceTypeIndex) / sizeof (DeviceTypeIndex[0]); DeviceIndex++) {\r
362 if (DeviceTypeIndex[DeviceIndex] != (UINTN) -1 && DeviceTypeIndex[DeviceIndex] >= *NextIndex) {\r
363 DeviceTypeIndex[DeviceIndex]++;\r
364 }\r
365 }\r
366 }\r
367 }\r
368 EfiBootManagerFreeLoadOption (&BootOption);\r
369 }\r
370\r
371 gRT->SetVariable (\r
372 L"BootOrder",\r
373 &gEfiGlobalVariableGuid,\r
374 VAR_FLAG,\r
375 BootOrderSize,\r
376 BootOrder\r
377 );\r
378 FreePool (BootOrder);\r
379}\r
380\r
381/**\r
382 This function converts an input device structure to a Unicode string.\r
383\r
384 @param DevPath A pointer to the device path structure.\r
385\r
386 @return A new allocated Unicode string that represents the device path.\r
387\r
388**/\r
389CHAR16 *\r
390BmDevicePathToStr (\r
391 IN EFI_DEVICE_PATH_PROTOCOL *DevPath\r
392 )\r
393{\r
394 EFI_STATUS Status;\r
395 CHAR16 *ToText;\r
396 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText;\r
397\r
398 if (DevPath == NULL) {\r
399 return NULL;\r
400 }\r
401\r
402 Status = gBS->LocateProtocol (\r
403 &gEfiDevicePathToTextProtocolGuid,\r
404 NULL,\r
405 (VOID **) &DevPathToText\r
406 );\r
407 ASSERT_EFI_ERROR (Status);\r
408 ToText = DevPathToText->ConvertDevicePathToText (\r
409 DevPath,\r
410 FALSE,\r
411 TRUE\r
412 );\r
413 ASSERT (ToText != NULL);\r
414 return ToText;\r
415}\r
416\r
417/**\r
418 This function invokes Boot Manager. If all devices have not a chance to be connected,\r
419 the connect all will be triggered. It then enumerate all boot options. If \r
420 a boot option from the Boot Manager page is selected, Boot Manager will boot\r
421 from this boot option.\r
422 \r
423**/\r
424VOID\r
425UpdateBootManager (\r
426 VOID\r
427 )\r
428{\r
429 UINTN Index;\r
430 EFI_BOOT_MANAGER_LOAD_OPTION *BootOption;\r
431 UINTN BootOptionCount;\r
432 EFI_STRING_ID Token;\r
433 CHAR16 *HelpString;\r
434 EFI_STRING_ID HelpToken;\r
435 UINT16 *TempStr;\r
436 EFI_HII_HANDLE HiiHandle;\r
437 UINTN TempSize;\r
438 VOID *StartOpCodeHandle;\r
439 VOID *EndOpCodeHandle;\r
440 EFI_IFR_GUID_LABEL *StartLabel;\r
441 EFI_IFR_GUID_LABEL *EndLabel;\r
442 UINT16 DeviceType;\r
443 BOOLEAN IsLegacyOption;\r
444 BOOLEAN NeedEndOp;\r
445 UINTN MaxLen;\r
446\r
447 DeviceType = (UINT16) -1;\r
448\r
449 EfiBootManagerConnectAll ();\r
450\r
451 //\r
452 // for better user experience\r
453 // 1. User changes HD configuration (e.g.: unplug HDD), here we have a chance to remove the HDD boot option\r
454 // 2. User enables/disables UEFI PXE, here we have a chance to add/remove EFI Network boot option\r
455 //\r
456 EfiBootManagerRefreshAllBootOption ();\r
457\r
458 //\r
459 // BdsDxe doesn't group the legacy boot options for the same device type\r
460 // It's UI's choice.\r
461 //\r
462 GroupMultipleLegacyBootOption4SameType ();\r
463\r
464 BootOption = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);\r
465\r
466 HiiHandle = gBootManagerPrivate.HiiHandle;\r
467\r
468 //\r
469 // Allocate space for creation of UpdateData Buffer\r
470 //\r
471 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
472 ASSERT (StartOpCodeHandle != NULL);\r
473\r
474 EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
475 ASSERT (EndOpCodeHandle != NULL);\r
476\r
477 //\r
478 // Create Hii Extend Label OpCode as the start opcode\r
479 //\r
480 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
481 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
482 StartLabel->Number = LABEL_BOOT_OPTION;\r
483\r
484 //\r
485 // Create Hii Extend Label OpCode as the end opcode\r
486 //\r
487 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
488 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
489 EndLabel->Number = LABEL_BOOT_OPTION_END;\r
490 mKeyInput = 0;\r
491 NeedEndOp = FALSE;\r
492 for (Index = 0; Index < BootOptionCount; Index++) {\r
493 //\r
494 // At this stage we are creating a menu entry, thus the Keys are reproduceable\r
495 //\r
496 mKeyInput++;\r
497\r
498 //\r
499 // Don't display the hidden/inactive boot option\r
500 //\r
501 if (((BootOption[Index].Attributes & LOAD_OPTION_HIDDEN) != 0) || ((BootOption[Index].Attributes & LOAD_OPTION_ACTIVE) == 0)) {\r
502 continue;\r
503 }\r
504\r
505 //\r
506 // Group the legacy boot option in the sub title created dynamically\r
507 //\r
508 IsLegacyOption = (BOOLEAN) (\r
509 (DevicePathType (BootOption[Index].FilePath) == BBS_DEVICE_PATH) &&\r
510 (DevicePathSubType (BootOption[Index].FilePath) == BBS_BBS_DP)\r
511 );\r
512\r
513 if (!IsLegacyOption && NeedEndOp) {\r
514 NeedEndOp = FALSE;\r
515 HiiCreateEndOpCode (StartOpCodeHandle);\r
516 }\r
517 \r
518 if (IsLegacyOption && DeviceType != ((BBS_BBS_DEVICE_PATH *) BootOption[Index].FilePath)->DeviceType) {\r
519 if (NeedEndOp) {\r
520 HiiCreateEndOpCode (StartOpCodeHandle);\r
521 }\r
522\r
523 DeviceType = ((BBS_BBS_DEVICE_PATH *) BootOption[Index].FilePath)->DeviceType;\r
524 Token = HiiSetString (\r
525 HiiHandle,\r
526 0,\r
527 mDeviceTypeStr[\r
528 MIN (DeviceType & 0xF, sizeof (mDeviceTypeStr) / sizeof (mDeviceTypeStr[0]) - 1)\r
529 ],\r
530 NULL\r
531 );\r
532 HiiCreateSubTitleOpCode (StartOpCodeHandle, Token, 0, 0, 1);\r
533 NeedEndOp = TRUE;\r
534 }\r
535\r
536 ASSERT (BootOption[Index].Description != NULL);\r
537\r
538 Token = HiiSetString (HiiHandle, 0, BootOption[Index].Description, NULL);\r
539\r
540 TempStr = BmDevicePathToStr (BootOption[Index].FilePath);\r
541 TempSize = StrSize (TempStr);\r
542 HelpString = AllocateZeroPool (TempSize + StrSize (L"Device Path : "));\r
543 MaxLen = (TempSize + StrSize (L"Device Path : "))/sizeof(CHAR16);\r
544 ASSERT (HelpString != NULL);\r
545 StrCatS (HelpString, MaxLen, L"Device Path : ");\r
546 StrCatS (HelpString, MaxLen, TempStr);\r
547\r
548 HelpToken = HiiSetString (HiiHandle, 0, HelpString, NULL);\r
549\r
550 HiiCreateActionOpCode (\r
551 StartOpCodeHandle,\r
552 mKeyInput,\r
553 Token,\r
554 HelpToken,\r
555 EFI_IFR_FLAG_CALLBACK,\r
556 0\r
557 );\r
558 }\r
559\r
560 if (NeedEndOp) {\r
561 HiiCreateEndOpCode (StartOpCodeHandle);\r
562 }\r
563\r
564 HiiUpdateForm (\r
565 HiiHandle,\r
566 &mBootManagerGuid,\r
567 BOOT_MANAGER_FORM_ID,\r
568 StartOpCodeHandle,\r
569 EndOpCodeHandle\r
570 );\r
571\r
572 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
573 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
574\r
575 EfiBootManagerFreeLoadOptions (BootOption, BootOptionCount);\r
576}\r
577\r
578/**\r
579 This function allows a caller to extract the current configuration for one\r
580 or more named elements from the target driver.\r
581\r
582\r
583 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
584 @param Request A null-terminated Unicode string in <ConfigRequest> format.\r
585 @param Progress On return, points to a character in the Request string.\r
586 Points to the string's null terminator if request was successful.\r
587 Points to the most recent '&' before the first failing name/value\r
588 pair (or the beginning of the string if the failure is in the\r
589 first name/value pair) if the request was not successful.\r
590 @param Results A null-terminated Unicode string in <ConfigAltResp> format which\r
591 has all values filled in for the names in the Request string.\r
592 String to be allocated by the called function.\r
593\r
594 @retval EFI_SUCCESS The Results is filled with the requested values.\r
595 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r
596 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r
597 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r
598\r
599**/\r
600EFI_STATUS\r
601EFIAPI\r
602BootManagerExtractConfig (\r
603 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
604 IN CONST EFI_STRING Request,\r
605 OUT EFI_STRING *Progress,\r
606 OUT EFI_STRING *Results\r
607 )\r
608{\r
609 if (Progress == NULL || Results == NULL) {\r
610 return EFI_INVALID_PARAMETER;\r
611 }\r
612 *Progress = Request;\r
613 return EFI_NOT_FOUND;\r
614}\r
615\r
616/**\r
617 This function processes the results of changes in configuration.\r
618\r
619\r
620 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
621 @param Configuration A null-terminated Unicode string in <ConfigResp> format.\r
622 @param Progress A pointer to a string filled in with the offset of the most\r
623 recent '&' before the first failing name/value pair (or the\r
624 beginning of the string if the failure is in the first\r
625 name/value pair) or the terminating NULL if all was successful.\r
626\r
627 @retval EFI_SUCCESS The Results is processed successfully.\r
628 @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
629 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r
630\r
631**/\r
632EFI_STATUS\r
633EFIAPI\r
634BootManagerRouteConfig (\r
635 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
636 IN CONST EFI_STRING Configuration,\r
637 OUT EFI_STRING *Progress\r
638 )\r
639{\r
640 if (Configuration == NULL || Progress == NULL) {\r
641 return EFI_INVALID_PARAMETER;\r
642 }\r
643\r
644 *Progress = Configuration;\r
645\r
646 return EFI_NOT_FOUND;\r
647}\r
648\r
649/**\r
650 This call back function is registered with Boot Manager formset.\r
651 When user selects a boot option, this call back function will\r
652 be triggered. The boot option is saved for later processing.\r
653\r
654\r
655 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
656 @param Action Specifies the type of action taken by the browser.\r
657 @param QuestionId A unique value which is sent to the original exporting driver\r
658 so that it can identify the type of data to expect.\r
659 @param Type The type of value for the question.\r
660 @param Value A pointer to the data being sent to the original exporting driver.\r
661 @param ActionRequest On return, points to the action requested by the callback function.\r
662\r
663 @retval EFI_SUCCESS The callback successfully handled the action.\r
664 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.\r
665\r
666**/\r
667EFI_STATUS\r
668EFIAPI\r
669BootManagerCallback (\r
670 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
671 IN EFI_BROWSER_ACTION Action,\r
672 IN EFI_QUESTION_ID QuestionId,\r
673 IN UINT8 Type,\r
674 IN EFI_IFR_TYPE_VALUE *Value,\r
675 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
676 )\r
677{\r
678 EFI_BOOT_MANAGER_LOAD_OPTION *BootOption;\r
679 UINTN BootOptionCount;\r
680 EFI_INPUT_KEY Key;\r
681 if (Action != EFI_BROWSER_ACTION_CHANGED) {\r
682 //\r
683 // Do nothing for other UEFI Action. Only do call back when data is changed.\r
684 //\r
685 return EFI_UNSUPPORTED;\r
686 }\r
687\r
688 if ((Value == NULL) || (ActionRequest == NULL)) {\r
689 return EFI_INVALID_PARAMETER;\r
690 }\r
691\r
692 BootOption = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);\r
693 //\r
694 // parse the selected option\r
695 //\r
696 BmBdsSetConsoleMode (FALSE);\r
697 EfiBootManagerBoot (&BootOption[QuestionId - 1]);\r
698 BmBdsSetConsoleMode (TRUE);\r
699\r
700 if (EFI_ERROR (BootOption[QuestionId - 1].Status)) {\r
701 gST->ConOut->OutputString (\r
702 gST->ConOut,\r
703 HiiGetString (gBootManagerPrivate.HiiHandle, STRING_TOKEN (STR_ANY_KEY_CONTINUE), NULL)\r
704 );\r
705 gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
706 }\r
707\r
708 EfiBootManagerFreeLoadOptions (BootOption, BootOptionCount);\r
709\r
710 return EFI_SUCCESS;\r
711}\r
712\r
713/**\r
714\r
715 Install Boot Manager Menu driver.\r
716\r
717 @param ImageHandle The image handle.\r
718 @param SystemTable The system table.\r
719\r
720 @retval EFI_SUCEESS Install Boot manager menu success.\r
721 @retval Other Return error status.\r
722\r
723**/\r
724EFI_STATUS\r
725EFIAPI\r
726BootManagerLibConstructor (\r
727 IN EFI_HANDLE ImageHandle,\r
728 IN EFI_SYSTEM_TABLE *SystemTable\r
729 )\r
730{\r
731 EFI_STATUS Status;\r
732\r
733 //\r
734 // Install Device Path Protocol and Config Access protocol to driver handle\r
735 //\r
736 gBootManagerPrivate.DriverHandle = NULL;\r
737 Status = gBS->InstallMultipleProtocolInterfaces (\r
738 &gBootManagerPrivate.DriverHandle,\r
739 &gEfiDevicePathProtocolGuid,\r
740 &mBootManagerHiiVendorDevicePath,\r
741 &gEfiHiiConfigAccessProtocolGuid,\r
742 &gBootManagerPrivate.ConfigAccess,\r
743 NULL\r
744 );\r
745 ASSERT_EFI_ERROR (Status);\r
746\r
747 //\r
748 // Publish our HII data\r
749 //\r
750 gBootManagerPrivate.HiiHandle = HiiAddPackages (\r
751 &mBootManagerGuid,\r
752 gBootManagerPrivate.DriverHandle,\r
753 BootManagerVfrBin,\r
754 BootManagerLibStrings,\r
755 NULL\r
756 );\r
757 ASSERT (gBootManagerPrivate.HiiHandle != NULL);\r
758\r
759 //\r
760 // Update boot manager page \r
761 //\r
762 UpdateBootManager ();\r
763\r
764 return EFI_SUCCESS;\r
765}\r
766\r
767/**\r
768 Unloads the application and its installed protocol.\r
769\r
770 @param[in] ImageHandle Handle that identifies the image to be unloaded.\r
771 @param[in] SystemTable System Table\r
772\r
773 @retval EFI_SUCCESS The image has been unloaded.\r
774**/\r
775EFI_STATUS\r
776EFIAPI\r
777BootManagerLibDestructor (\r
778 IN EFI_HANDLE ImageHandle,\r
779 IN EFI_SYSTEM_TABLE *SystemTable\r
780 )\r
781{\r
782 EFI_STATUS Status;\r
783\r
784 Status = gBS->UninstallMultipleProtocolInterfaces (\r
785 gBootManagerPrivate.DriverHandle,\r
786 &gEfiDevicePathProtocolGuid,\r
787 &mBootManagerHiiVendorDevicePath,\r
788 &gEfiHiiConfigAccessProtocolGuid,\r
789 &gBootManagerPrivate.ConfigAccess,\r
790 NULL\r
791 );\r
792 ASSERT_EFI_ERROR (Status);\r
793\r
794 HiiRemovePackages (gBootManagerPrivate.HiiHandle);\r
795\r
796 return EFI_SUCCESS;\r
797}\r
798\r