Update for IntelFrameworkModulePkg.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / BootMaint / BootMaint.c
CommitLineData
5c08e117 1/** @file\r
2 The functions for Boot Maintainence Main menu.\r
3\r
b452ca89 4Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
180a5a35 5This program and the accompanying materials\r
5c08e117 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The 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
12\r
13**/\r
14\r
15#include "BootMaint.h"\r
16#include "FormGuid.h"\r
17#include "Bds.h"\r
18#include "FrontPage.h"\r
19\r
20EFI_DEVICE_PATH_PROTOCOL EndDevicePath[] = {\r
21 {\r
22 END_DEVICE_PATH_TYPE,\r
23 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
24 {\r
25 END_DEVICE_PATH_LENGTH,\r
26 0\r
27 }\r
28 }\r
29};\r
30\r
f6f910dd 31HII_VENDOR_DEVICE_PATH mBmmHiiVendorDevicePath = {\r
32 {\r
33 {\r
34 HARDWARE_DEVICE_PATH,\r
35 HW_VENDOR_DP,\r
36 {\r
37 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
38 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
39 }\r
40 },\r
e24fc103 41 BOOT_MAINT_FORMSET_GUID\r
f6f910dd 42 },\r
43 {\r
44 END_DEVICE_PATH_TYPE,\r
45 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
46 { \r
47 (UINT8) (END_DEVICE_PATH_LENGTH),\r
48 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
49 }\r
50 }\r
51};\r
52\r
53HII_VENDOR_DEVICE_PATH mFeHiiVendorDevicePath = {\r
54 {\r
55 {\r
56 HARDWARE_DEVICE_PATH,\r
57 HW_VENDOR_DP,\r
58 {\r
59 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
60 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
61 }\r
62 },\r
e24fc103 63 FILE_EXPLORE_FORMSET_GUID\r
f6f910dd 64 },\r
65 {\r
66 END_DEVICE_PATH_TYPE,\r
67 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
68 { \r
69 (UINT8) (END_DEVICE_PATH_LENGTH),\r
70 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
71 }\r
72 }\r
73};\r
5c08e117 74\r
75bf9d0e 75CHAR16 mBootMaintStorageName[] = L"BmmData";\r
5c08e117 76CHAR16 mFileExplorerStorageName[] = L"FeData";\r
77\r
78/**\r
79 Init all memu.\r
80\r
81 @param CallbackData The BMM context data.\r
82\r
83**/\r
84VOID\r
85InitAllMenu (\r
86 IN BMM_CALLBACK_DATA *CallbackData\r
87 );\r
88\r
89/**\r
90 Free up all Menu Option list.\r
91\r
92**/\r
93VOID\r
94FreeAllMenu (\r
95 VOID\r
96 );\r
97\r
98/**\r
99 Create string tokens for a menu from its help strings and display strings\r
100\r
101 @param CallbackData The BMM context data.\r
102 @param HiiHandle Hii Handle of the package to be updated.\r
103 @param MenuOption The Menu whose string tokens need to be created\r
104\r
105 @retval EFI_SUCCESS String tokens created successfully\r
106 @retval others contain some errors\r
107**/\r
108EFI_STATUS\r
109CreateMenuStringToken (\r
110 IN BMM_CALLBACK_DATA *CallbackData,\r
111 IN EFI_HII_HANDLE HiiHandle,\r
112 IN BM_MENU_OPTION *MenuOption\r
113 )\r
114{\r
115 BM_MENU_ENTRY *NewMenuEntry;\r
116 UINTN Index;\r
117\r
118 for (Index = 0; Index < MenuOption->MenuNumber; Index++) {\r
119 NewMenuEntry = BOpt_GetMenuEntry (MenuOption, Index);\r
120\r
cb7d01c0 121 NewMenuEntry->DisplayStringToken = HiiSetString (\r
122 HiiHandle,\r
123 0,\r
124 NewMenuEntry->DisplayString,\r
125 NULL\r
126 );\r
5c08e117 127\r
128 if (NULL == NewMenuEntry->HelpString) {\r
129 NewMenuEntry->HelpStringToken = NewMenuEntry->DisplayStringToken;\r
130 } else {\r
cb7d01c0 131 NewMenuEntry->HelpStringToken = HiiSetString (\r
132 HiiHandle,\r
133 0,\r
134 NewMenuEntry->HelpString,\r
135 NULL\r
136 );\r
5c08e117 137 }\r
138 }\r
139\r
140 return EFI_SUCCESS;\r
141}\r
142\r
143/**\r
144 This function allows a caller to extract the current configuration for one\r
145 or more named elements from the target driver.\r
146\r
147\r
148 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
149 @param Request A null-terminated Unicode string in <ConfigRequest> format.\r
150 @param Progress On return, points to a character in the Request string.\r
151 Points to the string's null terminator if request was successful.\r
152 Points to the most recent '&' before the first failing name/value\r
153 pair (or the beginning of the string if the failure is in the\r
154 first name/value pair) if the request was not successful.\r
155 @param Results A null-terminated Unicode string in <ConfigAltResp> format which\r
156 has all values filled in for the names in the Request string.\r
157 String to be allocated by the called function.\r
158\r
159 @retval EFI_SUCCESS The Results is filled with the requested values.\r
160 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r
161 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.\r
162 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r
163\r
164**/\r
165EFI_STATUS\r
166EFIAPI\r
167BootMaintExtractConfig (\r
168 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
169 IN CONST EFI_STRING Request,\r
170 OUT EFI_STRING *Progress,\r
171 OUT EFI_STRING *Results\r
172 )\r
173{\r
174 EFI_STATUS Status;\r
175 UINTN BufferSize;\r
176 BMM_CALLBACK_DATA *Private;\r
59aefb7e
LG
177 EFI_STRING ConfigRequestHdr;\r
178 EFI_STRING ConfigRequest;\r
179 BOOLEAN AllocatedRequest;\r
180 UINTN Size;\r
5c08e117 181\r
59aefb7e 182 if (Progress == NULL || Results == NULL) {\r
5c08e117 183 return EFI_INVALID_PARAMETER;\r
184 }\r
185\r
59aefb7e 186 *Progress = Request;\r
e24fc103 187 if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gBootMaintFormSetGuid, mBootMaintStorageName)) {\r
59aefb7e
LG
188 return EFI_NOT_FOUND;\r
189 }\r
5c08e117 190\r
59aefb7e
LG
191 ConfigRequestHdr = NULL;\r
192 ConfigRequest = NULL;\r
193 AllocatedRequest = FALSE;\r
194 Size = 0;\r
195\r
196 Private = BMM_CALLBACK_DATA_FROM_THIS (This);\r
5c08e117 197 //\r
198 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r
199 //\r
200 BufferSize = sizeof (BMM_FAKE_NV_DATA);\r
59aefb7e
LG
201 ConfigRequest = Request;\r
202 if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r
203 //\r
204 // Request has no request element, construct full request string.\r
205 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
206 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r
207 //\r
e24fc103 208 ConfigRequestHdr = HiiConstructConfigHdr (&gBootMaintFormSetGuid, mBootMaintStorageName, Private->BmmDriverHandle);\r
59aefb7e
LG
209 Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
210 ConfigRequest = AllocateZeroPool (Size);\r
211 ASSERT (ConfigRequest != NULL);\r
212 AllocatedRequest = TRUE;\r
213 UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r
214 FreePool (ConfigRequestHdr);\r
215 }\r
216\r
5c08e117 217 Status = gHiiConfigRouting->BlockToConfig (\r
218 gHiiConfigRouting,\r
59aefb7e 219 ConfigRequest,\r
5c08e117 220 (UINT8 *) &Private->BmmFakeNvData,\r
221 BufferSize,\r
222 Results,\r
223 Progress\r
224 );\r
59aefb7e
LG
225 //\r
226 // Free the allocated config request string.\r
227 //\r
228 if (AllocatedRequest) {\r
229 FreePool (ConfigRequest);\r
230 ConfigRequest = NULL;\r
231 }\r
232 //\r
233 // Set Progress string to the original request string.\r
234 //\r
235 if (Request == NULL) {\r
236 *Progress = NULL;\r
237 } else if (StrStr (Request, L"OFFSET") == NULL) {\r
238 *Progress = Request + StrLen (Request);\r
239 }\r
240\r
5c08e117 241 return Status;\r
242}\r
243\r
244/**\r
245 This function processes the results of changes in configuration.\r
246\r
247\r
248 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
249 @param Action Specifies the type of action taken by the browser.\r
250 @param QuestionId A unique value which is sent to the original exporting driver\r
251 so that it can identify the type of data to expect.\r
252 @param Type The type of value for the question.\r
253 @param Value A pointer to the data being sent to the original exporting driver.\r
254 @param ActionRequest On return, points to the action requested by the callback function.\r
255\r
256 @retval EFI_SUCCESS The callback successfully handled the action.\r
257 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.\r
258 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
259 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.\r
260 @retval EFI_INVALID_PARAMETER The parameter of Value or ActionRequest is invalid.\r
261**/\r
262EFI_STATUS\r
263EFIAPI\r
264BootMaintCallback (\r
265 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
266 IN EFI_BROWSER_ACTION Action,\r
267 IN EFI_QUESTION_ID QuestionId,\r
268 IN UINT8 Type,\r
269 IN EFI_IFR_TYPE_VALUE *Value,\r
270 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
271 )\r
272{\r
273 BMM_CALLBACK_DATA *Private;\r
274 BM_MENU_ENTRY *NewMenuEntry;\r
275 BMM_FAKE_NV_DATA *CurrentFakeNVMap;\r
276 EFI_STATUS Status;\r
277 UINTN OldValue;\r
278 UINTN NewValue;\r
279 UINTN Number;\r
280 UINTN Pos;\r
281 UINTN Bit;\r
282 UINT16 NewValuePos;\r
283 UINT16 Index2;\r
284 UINT16 Index;\r
285 UINT8 *OldLegacyDev;\r
286 UINT8 *NewLegacyDev;\r
287 UINT8 *DisMap;\r
288 EFI_FORM_ID FormId;\r
d88f86f1 289\r
84724077
ED
290 if (Action != EFI_BROWSER_ACTION_CHANGING && Action != EFI_BROWSER_ACTION_CHANGED) { \r
291 //\r
292 // All other action return unsupported.\r
293 //\r
294 return EFI_UNSUPPORTED;\r
295 }\r
296 \r
297 Status = EFI_SUCCESS;\r
298 OldValue = 0;\r
299 NewValue = 0;\r
300 Number = 0;\r
301 OldLegacyDev = NULL;\r
302 NewLegacyDev = NULL;\r
303 NewValuePos = 0;\r
304 DisMap = NULL;\r
305\r
306 Private = BMM_CALLBACK_DATA_FROM_THIS (This);\r
307 //\r
308 // Retrive uncommitted data from Form Browser\r
309 //\r
310 CurrentFakeNVMap = &Private->BmmFakeNvData;\r
311 HiiGetBrowserData (&gBootMaintFormSetGuid, mBootMaintStorageName, sizeof (BMM_FAKE_NV_DATA), (UINT8 *) CurrentFakeNVMap);\r
d88f86f1 312 if (Action == EFI_BROWSER_ACTION_CHANGING) {\r
84724077 313 if (Value == NULL) {\r
d88f86f1
ED
314 return EFI_INVALID_PARAMETER;\r
315 }\r
84724077 316 \r
d88f86f1
ED
317 UpdatePageId (Private, QuestionId);\r
318\r
d88f86f1
ED
319 //\r
320 // need to be subtituded.\r
321 //\r
322 // Update Select FD/HD/CD/NET/BEV Order Form\r
323 //\r
324 if (FORM_SET_FD_ORDER_ID == Private->BmmPreviousPageId ||\r
325 FORM_SET_HD_ORDER_ID == Private->BmmPreviousPageId ||\r
326 FORM_SET_CD_ORDER_ID == Private->BmmPreviousPageId ||\r
327 FORM_SET_NET_ORDER_ID == Private->BmmPreviousPageId ||\r
328 FORM_SET_BEV_ORDER_ID == Private->BmmPreviousPageId ||\r
329 ((FORM_BOOT_SETUP_ID == Private->BmmPreviousPageId) &&\r
330 (QuestionId >= LEGACY_FD_QUESTION_ID) &&\r
331 (QuestionId < (LEGACY_BEV_QUESTION_ID + 100)) )\r
332 ) {\r
333\r
334 DisMap = Private->BmmOldFakeNVData.DisableMap;\r
335\r
336 FormId = Private->BmmPreviousPageId;\r
337 if (FormId == FORM_BOOT_SETUP_ID) {\r
338 FormId = Private->BmmCurrentPageId;\r
339 }\r
5c08e117 340\r
d88f86f1
ED
341 switch (FormId) {\r
342 case FORM_SET_FD_ORDER_ID:\r
343 Number = (UINT16) LegacyFDMenu.MenuNumber;\r
344 OldLegacyDev = Private->BmmOldFakeNVData.LegacyFD;\r
345 NewLegacyDev = CurrentFakeNVMap->LegacyFD;\r
346 break;\r
5c08e117 347\r
d88f86f1
ED
348 case FORM_SET_HD_ORDER_ID:\r
349 Number = (UINT16) LegacyHDMenu.MenuNumber;\r
350 OldLegacyDev = Private->BmmOldFakeNVData.LegacyHD;\r
351 NewLegacyDev = CurrentFakeNVMap->LegacyHD;\r
352 break;\r
5c08e117 353\r
d88f86f1
ED
354 case FORM_SET_CD_ORDER_ID:\r
355 Number = (UINT16) LegacyCDMenu.MenuNumber;\r
356 OldLegacyDev = Private->BmmOldFakeNVData.LegacyCD;\r
357 NewLegacyDev = CurrentFakeNVMap->LegacyCD;\r
358 break;\r
5c08e117 359\r
d88f86f1
ED
360 case FORM_SET_NET_ORDER_ID:\r
361 Number = (UINT16) LegacyNETMenu.MenuNumber;\r
362 OldLegacyDev = Private->BmmOldFakeNVData.LegacyNET;\r
363 NewLegacyDev = CurrentFakeNVMap->LegacyNET;\r
364 break;\r
5c08e117 365\r
d88f86f1
ED
366 case FORM_SET_BEV_ORDER_ID:\r
367 Number = (UINT16) LegacyBEVMenu.MenuNumber;\r
368 OldLegacyDev = Private->BmmOldFakeNVData.LegacyBEV;\r
369 NewLegacyDev = CurrentFakeNVMap->LegacyBEV;\r
5c08e117 370 break;\r
5c08e117 371\r
d88f86f1
ED
372 default:\r
373 break;\r
374 }\r
5c08e117 375 //\r
d88f86f1
ED
376 // First, find the different position\r
377 // if there is change, it should be only one\r
5c08e117 378 //\r
d88f86f1
ED
379 for (Index = 0; Index < Number; Index++) {\r
380 if (OldLegacyDev[Index] != NewLegacyDev[Index]) {\r
381 OldValue = OldLegacyDev[Index];\r
382 NewValue = NewLegacyDev[Index];\r
383 break;\r
384 }\r
385 }\r
386\r
387 if (Index != Number) {\r
5c08e117 388 //\r
d88f86f1 389 // there is change, now process\r
5c08e117 390 //\r
d88f86f1
ED
391 if (0xFF == NewValue) {\r
392 //\r
393 // This item will be disable\r
394 // Just move the items behind this forward to overlap it\r
395 //\r
396 Pos = OldValue / 8;\r
397 Bit = 7 - (OldValue % 8);\r
398 DisMap[Pos] = (UINT8) (DisMap[Pos] | (UINT8) (1 << Bit));\r
399 for (Index2 = Index; Index2 < Number - 1; Index2++) {\r
400 NewLegacyDev[Index2] = NewLegacyDev[Index2 + 1];\r
401 }\r
5c08e117 402\r
d88f86f1
ED
403 NewLegacyDev[Index2] = 0xFF;\r
404 } else {\r
405 for (Index2 = 0; Index2 < Number; Index2++) {\r
406 if (Index2 == Index) {\r
407 continue;\r
408 }\r
409\r
410 if (OldLegacyDev[Index2] == NewValue) {\r
411 //\r
412 // If NewValue is in OldLegacyDev array\r
413 // remember its old position\r
414 //\r
415 NewValuePos = Index2;\r
416 break;\r
417 }\r
5c08e117 418 }\r
419\r
d88f86f1 420 if (Index2 != Number) {\r
5c08e117 421 //\r
d88f86f1
ED
422 // We will change current item to an existing item\r
423 // (It's hard to describe here, please read code, it's like a cycle-moving)\r
5c08e117 424 //\r
d88f86f1
ED
425 for (Index2 = NewValuePos; Index2 != Index;) {\r
426 if (NewValuePos < Index) {\r
427 NewLegacyDev[Index2] = OldLegacyDev[Index2 + 1];\r
428 Index2++;\r
429 } else {\r
430 NewLegacyDev[Index2] = OldLegacyDev[Index2 - 1];\r
431 Index2--;\r
432 }\r
5c08e117 433 }\r
d88f86f1 434 } else {\r
5c08e117 435 //\r
d88f86f1
ED
436 // If NewValue is not in OldlegacyDev array, we are changing to a disabled item\r
437 // so we should modify DisMap to reflect the change\r
5c08e117 438 //\r
d88f86f1
ED
439 Pos = NewValue / 8;\r
440 Bit = 7 - (NewValue % 8);\r
441 DisMap[Pos] = (UINT8) (DisMap[Pos] & (~ (UINT8) (1 << Bit)));\r
442 if (0xFF != OldValue) {\r
443 //\r
444 // Because NewValue is a item that was disabled before\r
445 // so after changing the OldValue should be disabled\r
446 // actually we are doing a swap of enable-disable states of two items\r
447 //\r
448 Pos = OldValue / 8;\r
449 Bit = 7 - (OldValue % 8);\r
450 DisMap[Pos] = (UINT8) (DisMap[Pos] | (UINT8) (1 << Bit));\r
451 }\r
5c08e117 452 }\r
453 }\r
d88f86f1
ED
454 //\r
455 // To prevent DISABLE appears in the middle of the list\r
456 // we should perform a re-ordering\r
457 //\r
458 Index = 0;\r
459 while (Index < Number) {\r
460 if (0xFF != NewLegacyDev[Index]) {\r
461 Index++;\r
462 continue;\r
5c08e117 463 }\r
464\r
d88f86f1 465 Index2 = Index;\r
5c08e117 466 Index2++;\r
d88f86f1
ED
467 while (Index2 < Number) {\r
468 if (0xFF != NewLegacyDev[Index2]) {\r
469 break;\r
470 }\r
5c08e117 471\r
d88f86f1
ED
472 Index2++;\r
473 }\r
474\r
475 if (Index2 < Number) {\r
476 NewLegacyDev[Index] = NewLegacyDev[Index2];\r
477 NewLegacyDev[Index2] = 0xFF;\r
478 }\r
479\r
480 Index++;\r
5c08e117 481 }\r
482\r
d88f86f1
ED
483 CopyMem (\r
484 OldLegacyDev,\r
485 NewLegacyDev,\r
486 Number\r
487 );\r
5c08e117 488 }\r
5c08e117 489 }\r
5c08e117 490\r
d88f86f1
ED
491 if (QuestionId < FILE_OPTION_OFFSET) {\r
492 if (QuestionId < CONFIG_OPTION_OFFSET) {\r
493 switch (QuestionId) {\r
494 case KEY_VALUE_BOOT_FROM_FILE:\r
495 Private->FeCurrentState = FileExplorerStateBootFromFile;\r
d88f86f1 496 break;\r
5c08e117 497\r
d88f86f1
ED
498 case FORM_BOOT_ADD_ID:\r
499 Private->FeCurrentState = FileExplorerStateAddBootOption;\r
d88f86f1 500 break;\r
5c08e117 501\r
d88f86f1
ED
502 case FORM_DRV_ADD_FILE_ID:\r
503 Private->FeCurrentState = FileExplorerStateAddDriverOptionState;\r
d88f86f1
ED
504 break;\r
505\r
506 case FORM_DRV_ADD_HANDLE_ID:\r
507 CleanUpPage (FORM_DRV_ADD_HANDLE_ID, Private);\r
508 UpdateDrvAddHandlePage (Private);\r
509 break;\r
510\r
511 case FORM_BOOT_DEL_ID:\r
512 CleanUpPage (FORM_BOOT_DEL_ID, Private);\r
513 UpdateBootDelPage (Private);\r
514 break;\r
515\r
516 case FORM_BOOT_CHG_ID:\r
517 case FORM_DRV_CHG_ID:\r
518 UpdatePageBody (QuestionId, Private);\r
519 break;\r
520\r
521 case FORM_DRV_DEL_ID:\r
522 CleanUpPage (FORM_DRV_DEL_ID, Private);\r
523 UpdateDrvDelPage (Private);\r
524 break;\r
525\r
526 case FORM_BOOT_NEXT_ID:\r
527 CleanUpPage (FORM_BOOT_NEXT_ID, Private);\r
528 UpdateBootNextPage (Private);\r
529 break;\r
530\r
531 case FORM_TIME_OUT_ID:\r
532 CleanUpPage (FORM_TIME_OUT_ID, Private);\r
533 UpdateTimeOutPage (Private);\r
534 break;\r
535\r
d88f86f1
ED
536 case FORM_CON_IN_ID:\r
537 case FORM_CON_OUT_ID:\r
538 case FORM_CON_ERR_ID:\r
539 UpdatePageBody (QuestionId, Private);\r
540 break;\r
541\r
542 case FORM_CON_MODE_ID:\r
543 CleanUpPage (FORM_CON_MODE_ID, Private);\r
544 UpdateConModePage (Private);\r
545 break;\r
546\r
547 case FORM_CON_COM_ID:\r
548 CleanUpPage (FORM_CON_COM_ID, Private);\r
549 UpdateConCOMPage (Private);\r
550 break;\r
551\r
552 case FORM_SET_FD_ORDER_ID:\r
553 case FORM_SET_HD_ORDER_ID:\r
554 case FORM_SET_CD_ORDER_ID:\r
555 case FORM_SET_NET_ORDER_ID:\r
556 case FORM_SET_BEV_ORDER_ID:\r
557 CleanUpPage (QuestionId, Private);\r
558 UpdateSetLegacyDeviceOrderPage (QuestionId, Private);\r
559 break;\r
560\r
d88f86f1
ED
561 default:\r
562 break;\r
563 }\r
564 } else if ((QuestionId >= TERMINAL_OPTION_OFFSET) && (QuestionId < CONSOLE_OPTION_OFFSET)) {\r
565 Index2 = (UINT16) (QuestionId - TERMINAL_OPTION_OFFSET);\r
566 Private->CurrentTerminal = Index2;\r
5c08e117 567\r
d88f86f1
ED
568 CleanUpPage (FORM_CON_COM_SETUP_ID, Private);\r
569 UpdateTerminalPage (Private);\r
5c08e117 570\r
d88f86f1
ED
571 } else if (QuestionId >= HANDLE_OPTION_OFFSET) {\r
572 Index2 = (UINT16) (QuestionId - HANDLE_OPTION_OFFSET);\r
5c08e117 573\r
d88f86f1
ED
574 NewMenuEntry = BOpt_GetMenuEntry (&DriverMenu, Index2);\r
575 ASSERT (NewMenuEntry != NULL);\r
576 Private->HandleContext = (BM_HANDLE_CONTEXT *) NewMenuEntry->VariableContext;\r
5c08e117 577\r
d88f86f1 578 CleanUpPage (FORM_DRV_ADD_HANDLE_DESC_ID, Private);\r
5c08e117 579\r
d88f86f1
ED
580 Private->MenuEntry = NewMenuEntry;\r
581 Private->LoadContext->FilePathList = Private->HandleContext->DevicePath;\r
5c08e117 582\r
d88f86f1
ED
583 UpdateDriverAddHandleDescPage (Private);\r
584 }\r
5c08e117 585 }\r
84724077
ED
586 } else if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
587 if ((Value == NULL) || (ActionRequest == NULL)) {\r
588 return EFI_INVALID_PARAMETER;\r
589 }\r
590 \r
591 switch (QuestionId) {\r
592 case KEY_VALUE_SAVE_AND_EXIT:\r
593 case KEY_VALUE_NO_SAVE_AND_EXIT:\r
594 if (QuestionId == KEY_VALUE_SAVE_AND_EXIT) {\r
595 Status = ApplyChangeHandler (Private, CurrentFakeNVMap, Private->BmmPreviousPageId);\r
596 if (EFI_ERROR (Status)) {\r
597 return Status;\r
598 }\r
599 } else if (QuestionId == KEY_VALUE_NO_SAVE_AND_EXIT) {\r
600 DiscardChangeHandler (Private, CurrentFakeNVMap);\r
601 }\r
d88f86f1 602\r
84724077
ED
603 //\r
604 // Tell browser not to ask for confirmation of changes,\r
605 // since we have already applied or discarded.\r
606 //\r
607 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;\r
608 break; \r
609\r
610 case FORM_RESET:\r
611 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);\r
612 return EFI_UNSUPPORTED;\r
613\r
614 default:\r
615 break;\r
616 }\r
5c08e117 617 }\r
618\r
619 //\r
84724077 620 // Pass changed uncommitted data back to Form Browser\r
5c08e117 621 //\r
84724077
ED
622 HiiSetBrowserData (&gBootMaintFormSetGuid, mBootMaintStorageName, sizeof (BMM_FAKE_NV_DATA), (UINT8 *) CurrentFakeNVMap, NULL);\r
623 return EFI_SUCCESS;\r
5c08e117 624}\r
625\r
626/**\r
627 Function handling request to apply changes for BMM pages.\r
628\r
629 @param Private Pointer to callback data buffer.\r
630 @param CurrentFakeNVMap Pointer to buffer holding data of various values used by BMM\r
631 @param FormId ID of the form which has sent the request to apply change.\r
632\r
633 @retval EFI_SUCCESS Change successfully applied.\r
634 @retval Other Error occurs while trying to apply changes.\r
635\r
636**/\r
637EFI_STATUS\r
638ApplyChangeHandler (\r
639 IN BMM_CALLBACK_DATA *Private,\r
640 IN BMM_FAKE_NV_DATA *CurrentFakeNVMap,\r
641 IN EFI_FORM_ID FormId\r
642 )\r
643{\r
644 BM_CONSOLE_CONTEXT *NewConsoleContext;\r
645 BM_TERMINAL_CONTEXT *NewTerminalContext;\r
646 BM_LOAD_CONTEXT *NewLoadContext;\r
647 BM_MENU_ENTRY *NewMenuEntry;\r
648 EFI_STATUS Status;\r
649 UINT16 Index;\r
650\r
651 Status = EFI_SUCCESS;\r
652\r
653 switch (FormId) {\r
654 case FORM_SET_FD_ORDER_ID:\r
655 case FORM_SET_HD_ORDER_ID:\r
656 case FORM_SET_CD_ORDER_ID:\r
657 case FORM_SET_NET_ORDER_ID:\r
658 case FORM_SET_BEV_ORDER_ID:\r
659 Var_UpdateBBSOption (Private);\r
660 break;\r
661\r
662 case FORM_BOOT_DEL_ID:\r
bd828c8e 663 for (Index = 0; \r
b452ca89 664 ((Index < BootOptionMenu.MenuNumber) && (Index < (sizeof (CurrentFakeNVMap->OptionDel) / sizeof (CurrentFakeNVMap->OptionDel[0])))); \r
bd828c8e 665 Index ++) {\r
5c08e117 666 NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index);\r
667 NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;\r
b452ca89 668 NewLoadContext->Deleted = CurrentFakeNVMap->OptionDel[Index];\r
5c08e117 669 }\r
670\r
671 Var_DelBootOption ();\r
672 break;\r
673\r
674 case FORM_DRV_DEL_ID:\r
bd828c8e 675 for (Index = 0; \r
b452ca89 676 ((Index < DriverOptionMenu.MenuNumber) && (Index < (sizeof (CurrentFakeNVMap->OptionDel) / sizeof (CurrentFakeNVMap->OptionDel[0])))); \r
bd828c8e 677 Index++) {\r
5c08e117 678 NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, Index);\r
679 NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;\r
b452ca89 680 NewLoadContext->Deleted = CurrentFakeNVMap->OptionDel[Index];\r
5c08e117 681 }\r
682\r
683 Var_DelDriverOption ();\r
684 break;\r
685\r
686 case FORM_BOOT_CHG_ID:\r
687 Status = Var_UpdateBootOrder (Private);\r
688 break;\r
689\r
690 case FORM_DRV_CHG_ID:\r
691 Status = Var_UpdateDriverOrder (Private);\r
692 break;\r
693\r
694 case FORM_TIME_OUT_ID:\r
8c81cb83 695 PcdSet16 (PcdPlatformBootTimeOut, CurrentFakeNVMap->BootTimeOut);\r
5c08e117 696\r
697 Private->BmmOldFakeNVData.BootTimeOut = CurrentFakeNVMap->BootTimeOut;\r
698 break;\r
699\r
700 case FORM_BOOT_NEXT_ID:\r
701 Status = Var_UpdateBootNext (Private);\r
702 break;\r
703\r
704 case FORM_CON_MODE_ID:\r
705 Status = Var_UpdateConMode (Private);\r
706 break;\r
707\r
708 case FORM_CON_COM_SETUP_ID:\r
709 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Private->CurrentTerminal);\r
710\r
711 ASSERT (NewMenuEntry != NULL);\r
712\r
713 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;\r
714\r
715 NewTerminalContext->BaudRateIndex = CurrentFakeNVMap->COMBaudRate;\r
716 ASSERT (CurrentFakeNVMap->COMBaudRate < (sizeof (BaudRateList) / sizeof (BaudRateList[0])));\r
717 NewTerminalContext->BaudRate = BaudRateList[CurrentFakeNVMap->COMBaudRate].Value;\r
718 NewTerminalContext->DataBitsIndex = CurrentFakeNVMap->COMDataRate;\r
719 ASSERT (CurrentFakeNVMap->COMDataRate < (sizeof (DataBitsList) / sizeof (DataBitsList[0])));\r
720 NewTerminalContext->DataBits = (UINT8) DataBitsList[CurrentFakeNVMap->COMDataRate].Value;\r
721 NewTerminalContext->StopBitsIndex = CurrentFakeNVMap->COMStopBits;\r
722 ASSERT (CurrentFakeNVMap->COMStopBits < (sizeof (StopBitsList) / sizeof (StopBitsList[0])));\r
723 NewTerminalContext->StopBits = (UINT8) StopBitsList[CurrentFakeNVMap->COMStopBits].Value;\r
724 NewTerminalContext->ParityIndex = CurrentFakeNVMap->COMParity;\r
725 ASSERT (CurrentFakeNVMap->COMParity < (sizeof (ParityList) / sizeof (ParityList[0])));\r
726 NewTerminalContext->Parity = (UINT8) ParityList[CurrentFakeNVMap->COMParity].Value;\r
727 NewTerminalContext->TerminalType = CurrentFakeNVMap->COMTerminalType;\r
8e491a81 728 NewTerminalContext->FlowControl = CurrentFakeNVMap->COMFlowControl;\r
5c08e117 729\r
730 ChangeTerminalDevicePath (\r
8e491a81 731 &(NewTerminalContext->DevicePath),\r
5c08e117 732 FALSE\r
733 );\r
734\r
735 Var_UpdateConsoleInpOption ();\r
736 Var_UpdateConsoleOutOption ();\r
737 Var_UpdateErrorOutOption ();\r
738 break;\r
739\r
740 case FORM_CON_IN_ID:\r
b7b0dca2 741 for (Index = 0; Index < ConsoleInpMenu.MenuNumber; Index++) {\r
5c08e117 742 NewMenuEntry = BOpt_GetMenuEntry (&ConsoleInpMenu, Index);\r
743 NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext;\r
b452ca89 744 ASSERT (Index < MAX_MENU_NUMBER);\r
5c08e117 745 NewConsoleContext->IsActive = CurrentFakeNVMap->ConsoleCheck[Index];\r
746 }\r
747\r
b7b0dca2 748 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {\r
5c08e117 749 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);\r
750 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;\r
b452ca89 751 ASSERT (Index + ConsoleInpMenu.MenuNumber < MAX_MENU_NUMBER);\r
5c08e117 752 NewTerminalContext->IsConIn = CurrentFakeNVMap->ConsoleCheck[Index + ConsoleInpMenu.MenuNumber];\r
753 }\r
754\r
755 Var_UpdateConsoleInpOption ();\r
756 break;\r
757\r
758 case FORM_CON_OUT_ID:\r
b7b0dca2 759 for (Index = 0; Index < ConsoleOutMenu.MenuNumber; Index++) {\r
5c08e117 760 NewMenuEntry = BOpt_GetMenuEntry (&ConsoleOutMenu, Index);\r
761 NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext;\r
b452ca89 762 ASSERT (Index < MAX_MENU_NUMBER);\r
5c08e117 763 NewConsoleContext->IsActive = CurrentFakeNVMap->ConsoleCheck[Index];\r
764 }\r
765\r
b7b0dca2 766 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {\r
5c08e117 767 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);\r
768 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;\r
b452ca89 769 ASSERT (Index + ConsoleOutMenu.MenuNumber < MAX_MENU_NUMBER);\r
5c08e117 770 NewTerminalContext->IsConOut = CurrentFakeNVMap->ConsoleCheck[Index + ConsoleOutMenu.MenuNumber];\r
771 }\r
772\r
773 Var_UpdateConsoleOutOption ();\r
774 break;\r
775\r
776 case FORM_CON_ERR_ID:\r
b7b0dca2 777 for (Index = 0; Index < ConsoleErrMenu.MenuNumber; Index++) {\r
5c08e117 778 NewMenuEntry = BOpt_GetMenuEntry (&ConsoleErrMenu, Index);\r
779 NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext;\r
b452ca89 780 ASSERT (Index < MAX_MENU_NUMBER);\r
5c08e117 781 NewConsoleContext->IsActive = CurrentFakeNVMap->ConsoleCheck[Index];\r
782 }\r
783\r
b7b0dca2 784 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {\r
5c08e117 785 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);\r
786 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;\r
b452ca89 787 ASSERT (Index + ConsoleErrMenu.MenuNumber < MAX_MENU_NUMBER);\r
5c08e117 788 NewTerminalContext->IsStdErr = CurrentFakeNVMap->ConsoleCheck[Index + ConsoleErrMenu.MenuNumber];\r
789 }\r
790\r
791 Var_UpdateErrorOutOption ();\r
792 break;\r
793\r
794 case FORM_DRV_ADD_HANDLE_DESC_ID:\r
795 Status = Var_UpdateDriverOption (\r
796 Private,\r
797 Private->BmmHiiHandle,\r
798 CurrentFakeNVMap->DriverAddHandleDesc,\r
799 CurrentFakeNVMap->DriverAddHandleOptionalData,\r
800 CurrentFakeNVMap->DriverAddForceReconnect\r
801 );\r
802 if (EFI_ERROR (Status)) {\r
803 goto Error;\r
804 }\r
805\r
806 BOpt_GetDriverOptions (Private);\r
807 CreateMenuStringToken (Private, Private->BmmHiiHandle, &DriverOptionMenu);\r
808 break;\r
809\r
810 default:\r
811 break;\r
812 }\r
813\r
814Error:\r
815 return Status;\r
816}\r
817\r
818/**\r
819 Discard all changes done to the BMM pages such as Boot Order change,\r
820 Driver order change.\r
821\r
822 @param Private The BMM context data.\r
823 @param CurrentFakeNVMap The current Fack NV Map.\r
824\r
825**/\r
826VOID\r
827DiscardChangeHandler (\r
828 IN BMM_CALLBACK_DATA *Private,\r
829 IN BMM_FAKE_NV_DATA *CurrentFakeNVMap\r
830 )\r
831{\r
832 UINT16 Index;\r
833\r
834 switch (Private->BmmPreviousPageId) {\r
835 case FORM_BOOT_CHG_ID:\r
836 case FORM_DRV_CHG_ID:\r
b452ca89 837 CopyMem (CurrentFakeNVMap->OptionOrder, Private->BmmOldFakeNVData.OptionOrder, sizeof (CurrentFakeNVMap->OptionOrder));\r
5c08e117 838 break;\r
839\r
840 case FORM_BOOT_DEL_ID:\r
b452ca89 841 ASSERT (BootOptionMenu.MenuNumber <= (sizeof (CurrentFakeNVMap->OptionDel) / sizeof (CurrentFakeNVMap->OptionDel[0])));\r
5c08e117 842 for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) {\r
b452ca89 843 CurrentFakeNVMap->OptionDel[Index] = FALSE;\r
5c08e117 844 }\r
845 break;\r
846\r
847 case FORM_DRV_DEL_ID:\r
b452ca89 848 ASSERT (DriverOptionMenu.MenuNumber <= (sizeof (CurrentFakeNVMap->OptionDel) / sizeof (CurrentFakeNVMap->OptionDel[0])));\r
5c08e117 849 for (Index = 0; Index < DriverOptionMenu.MenuNumber; Index++) {\r
b452ca89 850 CurrentFakeNVMap->OptionDel[Index] = FALSE;\r
5c08e117 851 }\r
852 break;\r
853\r
854 case FORM_BOOT_NEXT_ID:\r
855 CurrentFakeNVMap->BootNext = Private->BmmOldFakeNVData.BootNext;\r
856 break;\r
857\r
858 case FORM_TIME_OUT_ID:\r
859 CurrentFakeNVMap->BootTimeOut = Private->BmmOldFakeNVData.BootTimeOut;\r
860 break;\r
861\r
862 case FORM_DRV_ADD_HANDLE_DESC_ID:\r
863 case FORM_DRV_ADD_FILE_ID:\r
864 case FORM_DRV_ADD_HANDLE_ID:\r
865 CurrentFakeNVMap->DriverAddHandleDesc[0] = 0x0000;\r
866 CurrentFakeNVMap->DriverAddHandleOptionalData[0] = 0x0000;\r
867 break;\r
868\r
869 default:\r
870 break;\r
871 }\r
872}\r
873\r
874/**\r
875 Initialize the Boot Maintenance Utitliy.\r
876\r
877\r
878 @retval EFI_SUCCESS utility ended successfully\r
879 @retval others contain some errors\r
880\r
881**/\r
882EFI_STATUS\r
883InitializeBM (\r
884 VOID\r
885 )\r
886{\r
887 EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;\r
5c08e117 888 BMM_CALLBACK_DATA *BmmCallbackInfo;\r
889 EFI_STATUS Status;\r
890 UINT8 *Ptr;\r
891\r
892 Status = EFI_SUCCESS;\r
893\r
894 //\r
895 // Create CallbackData structures for Driver Callback\r
896 //\r
897 BmmCallbackInfo = AllocateZeroPool (sizeof (BMM_CALLBACK_DATA));\r
898 if (BmmCallbackInfo == NULL) {\r
899 return EFI_OUT_OF_RESOURCES;\r
900 }\r
901\r
902 //\r
903 // Create LoadOption in BmmCallbackInfo for Driver Callback\r
904 //\r
905 Ptr = AllocateZeroPool (sizeof (BM_LOAD_CONTEXT) + sizeof (BM_FILE_CONTEXT) + sizeof (BM_HANDLE_CONTEXT) + sizeof (BM_MENU_ENTRY));\r
906 if (Ptr == NULL) {\r
907 FreePool (BmmCallbackInfo);\r
908 return EFI_OUT_OF_RESOURCES;\r
909 }\r
910\r
911 //\r
912 // Initialize Bmm callback data.\r
913 //\r
914 BmmCallbackInfo->LoadContext = (BM_LOAD_CONTEXT *) Ptr;\r
915 Ptr += sizeof (BM_LOAD_CONTEXT);\r
916\r
917 BmmCallbackInfo->FileContext = (BM_FILE_CONTEXT *) Ptr;\r
918 Ptr += sizeof (BM_FILE_CONTEXT);\r
919\r
920 BmmCallbackInfo->HandleContext = (BM_HANDLE_CONTEXT *) Ptr;\r
921 Ptr += sizeof (BM_HANDLE_CONTEXT);\r
922\r
923 BmmCallbackInfo->MenuEntry = (BM_MENU_ENTRY *) Ptr;\r
924\r
925 BmmCallbackInfo->Signature = BMM_CALLBACK_DATA_SIGNATURE;\r
926 BmmCallbackInfo->BmmConfigAccess.ExtractConfig = BootMaintExtractConfig;\r
927 BmmCallbackInfo->BmmConfigAccess.RouteConfig = FakeRouteConfig;\r
928 BmmCallbackInfo->BmmConfigAccess.Callback = BootMaintCallback;\r
929 BmmCallbackInfo->BmmPreviousPageId = FORM_MAIN_ID;\r
930 BmmCallbackInfo->BmmCurrentPageId = FORM_MAIN_ID;\r
931 BmmCallbackInfo->FeConfigAccess.ExtractConfig = FakeExtractConfig;\r
932 BmmCallbackInfo->FeConfigAccess.RouteConfig = FakeRouteConfig;\r
933 BmmCallbackInfo->FeConfigAccess.Callback = FileExplorerCallback;\r
13078b3f 934 BmmCallbackInfo->FeCurrentState = FileExplorerStateInActive;\r
935 BmmCallbackInfo->FeDisplayContext = FileExplorerDisplayUnknown;\r
5c08e117 936\r
937 //\r
f6f910dd 938 // Install Device Path Protocol and Config Access protocol to driver handle\r
5c08e117 939 //\r
f6f910dd 940 Status = gBS->InstallMultipleProtocolInterfaces (\r
5c08e117 941 &BmmCallbackInfo->BmmDriverHandle,\r
f6f910dd 942 &gEfiDevicePathProtocolGuid,\r
943 &mBmmHiiVendorDevicePath,\r
5c08e117 944 &gEfiHiiConfigAccessProtocolGuid,\r
f6f910dd 945 &BmmCallbackInfo->BmmConfigAccess,\r
946 NULL\r
5c08e117 947 );\r
948 if (EFI_ERROR (Status)) {\r
4376a6f2 949 goto Exit;\r
5c08e117 950 }\r
951\r
952 //\r
f6f910dd 953 // Install Device Path Protocol and Config Access protocol to driver handle\r
5c08e117 954 //\r
f6f910dd 955 Status = gBS->InstallMultipleProtocolInterfaces (\r
5c08e117 956 &BmmCallbackInfo->FeDriverHandle,\r
f6f910dd 957 &gEfiDevicePathProtocolGuid,\r
958 &mFeHiiVendorDevicePath,\r
5c08e117 959 &gEfiHiiConfigAccessProtocolGuid,\r
f6f910dd 960 &BmmCallbackInfo->FeConfigAccess,\r
961 NULL\r
5c08e117 962 );\r
963 if (EFI_ERROR (Status)) {\r
4376a6f2 964 goto Exit;\r
5c08e117 965 }\r
966\r
967 //\r
baf46e70 968 // Post our Boot Maint VFR binary to the HII database.\r
5c08e117 969 //\r
cb7d01c0 970 BmmCallbackInfo->BmmHiiHandle = HiiAddPackages (\r
e24fc103 971 &gBootMaintFormSetGuid,\r
cb7d01c0 972 BmmCallbackInfo->BmmDriverHandle,\r
973 BmBin,\r
974 BdsDxeStrings,\r
975 NULL\r
976 );\r
977 ASSERT (BmmCallbackInfo->BmmHiiHandle != NULL);\r
5c08e117 978\r
979 //\r
980 // Post our File Explorer VFR binary to the HII database.\r
981 //\r
cb7d01c0 982 BmmCallbackInfo->FeHiiHandle = HiiAddPackages (\r
e24fc103 983 &gFileExploreFormSetGuid,\r
cb7d01c0 984 BmmCallbackInfo->FeDriverHandle,\r
985 FEBin,\r
986 BdsDxeStrings,\r
987 NULL\r
988 );\r
989 ASSERT (BmmCallbackInfo->FeHiiHandle != NULL);\r
5c08e117 990\r
991 //\r
75bf9d0e 992 // Init OpCode Handle and Allocate space for creation of Buffer\r
5c08e117 993 //\r
75bf9d0e
LG
994 mStartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
995 if (mStartOpCodeHandle == NULL) {\r
4376a6f2 996 Status = EFI_OUT_OF_RESOURCES;\r
997 goto Exit;\r
5c08e117 998 }\r
999\r
75bf9d0e
LG
1000 mEndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1001 if (mEndOpCodeHandle == NULL) {\r
1002 Status = EFI_OUT_OF_RESOURCES;\r
1003 goto Exit;\r
1004 }\r
1005\r
1006 //\r
1007 // Create Hii Extend Label OpCode as the start opcode\r
1008 //\r
1009 mStartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (mStartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
1010 mStartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
1011\r
1012 //\r
1013 // Create Hii Extend Label OpCode as the end opcode\r
1014 //\r
1015 mEndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (mEndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
1016 mEndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
1017 mEndLabel->Number = LABEL_END;\r
1018\r
5c08e117 1019 InitializeStringDepository ();\r
1020\r
1021 InitAllMenu (BmmCallbackInfo);\r
1022\r
1023 CreateMenuStringToken (BmmCallbackInfo, BmmCallbackInfo->BmmHiiHandle, &ConsoleInpMenu);\r
1024 CreateMenuStringToken (BmmCallbackInfo, BmmCallbackInfo->BmmHiiHandle, &ConsoleOutMenu);\r
1025 CreateMenuStringToken (BmmCallbackInfo, BmmCallbackInfo->BmmHiiHandle, &ConsoleErrMenu);\r
1026 CreateMenuStringToken (BmmCallbackInfo, BmmCallbackInfo->BmmHiiHandle, &BootOptionMenu);\r
1027 CreateMenuStringToken (BmmCallbackInfo, BmmCallbackInfo->BmmHiiHandle, &DriverOptionMenu);\r
1028 CreateMenuStringToken (BmmCallbackInfo, BmmCallbackInfo->BmmHiiHandle, &TerminalMenu);\r
1029 CreateMenuStringToken (BmmCallbackInfo, BmmCallbackInfo->BmmHiiHandle, &DriverMenu);\r
1030\r
1031 UpdateBootDelPage (BmmCallbackInfo);\r
1032 UpdateDrvDelPage (BmmCallbackInfo);\r
1033\r
1034 if (TerminalMenu.MenuNumber > 0) {\r
1035 BmmCallbackInfo->CurrentTerminal = 0;\r
1036 UpdateTerminalPage (BmmCallbackInfo);\r
1037 }\r
1038\r
1039 Status = EfiLibLocateProtocol (&gEfiLegacyBiosProtocolGuid, (VOID **) &LegacyBios);\r
1040 if (!EFI_ERROR (Status)) {\r
1041 RefreshUpdateData ();\r
75bf9d0e 1042 mStartLabel->Number = FORM_BOOT_LEGACY_DEVICE_ID;\r
5c08e117 1043\r
1044 //\r
1045 // If LegacyBios Protocol is installed, add 3 tags about legacy boot option\r
1046 // in BootOption form: legacy FD/HD/CD/NET/BEV\r
1047 //\r
75bf9d0e
LG
1048 HiiCreateGotoOpCode (\r
1049 mStartOpCodeHandle,\r
5c08e117 1050 FORM_SET_FD_ORDER_ID,\r
1051 STRING_TOKEN (STR_FORM_SET_FD_ORDER_TITLE),\r
1052 STRING_TOKEN (STR_FORM_SET_FD_ORDER_TITLE),\r
1053 EFI_IFR_FLAG_CALLBACK,\r
75bf9d0e 1054 FORM_SET_FD_ORDER_ID\r
5c08e117 1055 );\r
1056\r
75bf9d0e
LG
1057 HiiCreateGotoOpCode (\r
1058 mStartOpCodeHandle,\r
5c08e117 1059 FORM_SET_HD_ORDER_ID,\r
1060 STRING_TOKEN (STR_FORM_SET_HD_ORDER_TITLE),\r
1061 STRING_TOKEN (STR_FORM_SET_HD_ORDER_TITLE),\r
1062 EFI_IFR_FLAG_CALLBACK,\r
75bf9d0e 1063 FORM_SET_HD_ORDER_ID\r
5c08e117 1064 );\r
1065\r
75bf9d0e
LG
1066 HiiCreateGotoOpCode (\r
1067 mStartOpCodeHandle,\r
5c08e117 1068 FORM_SET_CD_ORDER_ID,\r
1069 STRING_TOKEN (STR_FORM_SET_CD_ORDER_TITLE),\r
1070 STRING_TOKEN (STR_FORM_SET_CD_ORDER_TITLE),\r
1071 EFI_IFR_FLAG_CALLBACK,\r
75bf9d0e 1072 FORM_SET_CD_ORDER_ID\r
5c08e117 1073 );\r
1074\r
75bf9d0e
LG
1075 HiiCreateGotoOpCode (\r
1076 mStartOpCodeHandle,\r
5c08e117 1077 FORM_SET_NET_ORDER_ID,\r
1078 STRING_TOKEN (STR_FORM_SET_NET_ORDER_TITLE),\r
1079 STRING_TOKEN (STR_FORM_SET_NET_ORDER_TITLE),\r
1080 EFI_IFR_FLAG_CALLBACK,\r
75bf9d0e 1081 FORM_SET_NET_ORDER_ID\r
5c08e117 1082 );\r
1083\r
75bf9d0e
LG
1084 HiiCreateGotoOpCode (\r
1085 mStartOpCodeHandle,\r
5c08e117 1086 FORM_SET_BEV_ORDER_ID,\r
1087 STRING_TOKEN (STR_FORM_SET_BEV_ORDER_TITLE),\r
1088 STRING_TOKEN (STR_FORM_SET_BEV_ORDER_TITLE),\r
1089 EFI_IFR_FLAG_CALLBACK,\r
75bf9d0e 1090 FORM_SET_BEV_ORDER_ID\r
5c08e117 1091 );\r
75bf9d0e
LG
1092 \r
1093 HiiUpdateForm (\r
5c08e117 1094 BmmCallbackInfo->BmmHiiHandle,\r
e24fc103 1095 &gBootMaintFormSetGuid,\r
3cdcfa85 1096 FORM_BOOT_SETUP_ID,\r
75bf9d0e
LG
1097 mStartOpCodeHandle, // Label FORM_BOOT_LEGACY_DEVICE_ID\r
1098 mEndOpCodeHandle // LABEL_END\r
5c08e117 1099 );\r
1100 }\r
1101\r
1102 //\r
1103 // Dispatch BMM main formset and File Explorer formset.\r
1104 //\r
1105 FormSetDispatcher (BmmCallbackInfo);\r
1106\r
1107 //\r
1108 // Remove our IFR data from HII database\r
1109 //\r
cb7d01c0 1110 HiiRemovePackages (BmmCallbackInfo->BmmHiiHandle);\r
1111 HiiRemovePackages (BmmCallbackInfo->FeHiiHandle);\r
5c08e117 1112\r
1113 CleanUpStringDepository ();\r
1114\r
1115 FreeAllMenu ();\r
1116\r
4376a6f2 1117Exit:\r
75bf9d0e
LG
1118 if (mStartOpCodeHandle != NULL) {\r
1119 HiiFreeOpCodeHandle (mStartOpCodeHandle);\r
1120 }\r
1121\r
1122 if (mEndOpCodeHandle != NULL) {\r
1123 HiiFreeOpCodeHandle (mEndOpCodeHandle);\r
1124 }\r
1125\r
4376a6f2 1126 if (BmmCallbackInfo->FeDriverHandle != NULL) {\r
1127 gBS->UninstallMultipleProtocolInterfaces (\r
1128 BmmCallbackInfo->FeDriverHandle,\r
1129 &gEfiDevicePathProtocolGuid,\r
1130 &mFeHiiVendorDevicePath,\r
1131 &gEfiHiiConfigAccessProtocolGuid,\r
1132 &BmmCallbackInfo->FeConfigAccess,\r
1133 NULL\r
1134 );\r
1135 }\r
1136\r
1137 if (BmmCallbackInfo->BmmDriverHandle != NULL) {\r
1138 gBS->UninstallMultipleProtocolInterfaces (\r
1139 BmmCallbackInfo->BmmDriverHandle,\r
1140 &gEfiDevicePathProtocolGuid,\r
1141 &mBmmHiiVendorDevicePath,\r
1142 &gEfiHiiConfigAccessProtocolGuid,\r
1143 &BmmCallbackInfo->BmmConfigAccess,\r
1144 NULL\r
1145 );\r
1146 }\r
1147\r
1148 FreePool (BmmCallbackInfo->LoadContext);\r
1149 FreePool (BmmCallbackInfo);\r
1150\r
5c08e117 1151 return Status;\r
1152}\r
1153\r
1154/**\r
1155 Initialized all Menu Option List.\r
1156\r
1157 @param CallbackData The BMM context data.\r
1158\r
1159**/\r
1160VOID\r
1161InitAllMenu (\r
1162 IN BMM_CALLBACK_DATA *CallbackData\r
1163 )\r
1164{\r
1165 InitializeListHead (&BootOptionMenu.Head);\r
1166 InitializeListHead (&DriverOptionMenu.Head);\r
1167 BOpt_GetBootOptions (CallbackData);\r
1168 BOpt_GetDriverOptions (CallbackData);\r
1169 BOpt_GetLegacyOptions ();\r
1170 InitializeListHead (&FsOptionMenu.Head);\r
1171 BOpt_FindDrivers ();\r
1172 InitializeListHead (&DirectoryMenu.Head);\r
1173 InitializeListHead (&ConsoleInpMenu.Head);\r
1174 InitializeListHead (&ConsoleOutMenu.Head);\r
1175 InitializeListHead (&ConsoleErrMenu.Head);\r
1176 InitializeListHead (&TerminalMenu.Head);\r
1177 LocateSerialIo ();\r
1178 GetAllConsoles ();\r
1179}\r
1180\r
1181/**\r
1182 Free up all Menu Option list.\r
1183\r
1184**/\r
1185VOID\r
1186FreeAllMenu (\r
1187 VOID\r
1188 )\r
1189{\r
1190 BOpt_FreeMenu (&DirectoryMenu);\r
1191 BOpt_FreeMenu (&FsOptionMenu);\r
1192 BOpt_FreeMenu (&BootOptionMenu);\r
1193 BOpt_FreeMenu (&DriverOptionMenu);\r
1194 BOpt_FreeMenu (&DriverMenu);\r
1195 BOpt_FreeLegacyOptions ();\r
1196 FreeAllConsoles ();\r
1197}\r
1198\r
1199/**\r
baf46e70 1200 Initialize all the string depositories.\r
5c08e117 1201\r
1202**/\r
1203VOID\r
1204InitializeStringDepository (\r
1205 VOID\r
1206 )\r
1207{\r
1208 STRING_DEPOSITORY *StringDepository;\r
1209 StringDepository = AllocateZeroPool (sizeof (STRING_DEPOSITORY) * STRING_DEPOSITORY_NUMBER);\r
1210 FileOptionStrDepository = StringDepository++;\r
1211 ConsoleOptionStrDepository = StringDepository++;\r
1212 BootOptionStrDepository = StringDepository++;\r
1213 BootOptionHelpStrDepository = StringDepository++;\r
1214 DriverOptionStrDepository = StringDepository++;\r
1215 DriverOptionHelpStrDepository = StringDepository++;\r
1216 TerminalStrDepository = StringDepository;\r
1217}\r
1218\r
1219/**\r
1220 Fetch a usable string node from the string depository and return the string token.\r
1221\r
1222 @param CallbackData The BMM context data.\r
1223 @param StringDepository The string repository.\r
1224\r
1225 @retval EFI_STRING_ID String token.\r
1226\r
1227**/\r
1228EFI_STRING_ID\r
1229GetStringTokenFromDepository (\r
1230 IN BMM_CALLBACK_DATA *CallbackData,\r
1231 IN STRING_DEPOSITORY *StringDepository\r
1232 )\r
1233{\r
1234 STRING_LIST_NODE *CurrentListNode;\r
1235 STRING_LIST_NODE *NextListNode;\r
1236\r
1237 CurrentListNode = StringDepository->CurrentNode;\r
1238\r
1239 if ((NULL != CurrentListNode) && (NULL != CurrentListNode->Next)) {\r
1240 //\r
1241 // Fetch one reclaimed node from the list.\r
1242 //\r
1243 NextListNode = StringDepository->CurrentNode->Next;\r
1244 } else {\r
1245 //\r
1246 // If there is no usable node in the list, update the list.\r
1247 //\r
1248 NextListNode = AllocateZeroPool (sizeof (STRING_LIST_NODE));\r
1249 ASSERT (NextListNode != NULL);\r
cb7d01c0 1250 NextListNode->StringToken = HiiSetString (CallbackData->BmmHiiHandle, 0, L" ", NULL);\r
5c08e117 1251 ASSERT (NextListNode->StringToken != 0);\r
1252\r
1253 StringDepository->TotalNodeNumber++;\r
1254\r
1255 if (NULL == CurrentListNode) {\r
1256 StringDepository->ListHead = NextListNode;\r
1257 } else {\r
1258 CurrentListNode->Next = NextListNode;\r
1259 }\r
1260 }\r
1261\r
1262 StringDepository->CurrentNode = NextListNode;\r
1263\r
1264 return StringDepository->CurrentNode->StringToken;\r
1265}\r
1266\r
1267/**\r
1268 Reclaim string depositories by moving the current node pointer to list head..\r
1269\r
1270**/\r
1271VOID\r
1272ReclaimStringDepository (\r
1273 VOID\r
1274 )\r
1275{\r
1276 UINTN DepositoryIndex;\r
1277 STRING_DEPOSITORY *StringDepository;\r
1278\r
1279 StringDepository = FileOptionStrDepository;\r
1280 for (DepositoryIndex = 0; DepositoryIndex < STRING_DEPOSITORY_NUMBER; DepositoryIndex++) {\r
1281 StringDepository->CurrentNode = StringDepository->ListHead;\r
1282 StringDepository++;\r
1283 }\r
1284}\r
1285\r
1286/**\r
1287 Release resource for all the string depositories.\r
1288\r
1289**/\r
1290VOID\r
1291CleanUpStringDepository (\r
1292 VOID\r
1293 )\r
1294{\r
1295 UINTN NodeIndex;\r
1296 UINTN DepositoryIndex;\r
1297 STRING_LIST_NODE *CurrentListNode;\r
1298 STRING_LIST_NODE *NextListNode;\r
1299 STRING_DEPOSITORY *StringDepository;\r
1300\r
1301 //\r
1302 // Release string list nodes.\r
1303 //\r
1304 StringDepository = FileOptionStrDepository;\r
1305 for (DepositoryIndex = 0; DepositoryIndex < STRING_DEPOSITORY_NUMBER; DepositoryIndex++) {\r
1306 CurrentListNode = StringDepository->ListHead;\r
1307 for (NodeIndex = 0; NodeIndex < StringDepository->TotalNodeNumber; NodeIndex++) {\r
1308 NextListNode = CurrentListNode->Next;\r
1309 FreePool (CurrentListNode);\r
1310 CurrentListNode = NextListNode;\r
1311 }\r
1312\r
1313 StringDepository++;\r
1314 }\r
1315 //\r
1316 // Release string depository.\r
1317 //\r
1318 FreePool (FileOptionStrDepository);\r
1319}\r
1320\r
1321/**\r
1322 Start boot maintenance manager\r
1323\r
1324 @retval EFI_SUCCESS If BMM is invoked successfully.\r
1325 @return Other value if BMM return unsuccessfully.\r
1326\r
1327**/\r
1328EFI_STATUS\r
1329BdsStartBootMaint (\r
1330 VOID\r
1331 )\r
1332{\r
1333 EFI_STATUS Status;\r
1334 LIST_ENTRY BdsBootOptionList;\r
1335\r
1336 InitializeListHead (&BdsBootOptionList);\r
1337\r
1338 //\r
1339 // Connect all prior to entering the platform setup menu.\r
1340 //\r
1341 if (!gConnectAllHappened) {\r
1342 BdsLibConnectAllDriversToAllControllers ();\r
1343 gConnectAllHappened = TRUE;\r
1344 }\r
1345 //\r
1346 // Have chance to enumerate boot device\r
1347 //\r
1348 BdsLibEnumerateAllBootOption (&BdsBootOptionList);\r
1349\r
1350 //\r
1351 // Init the BMM\r
1352 //\r
1353 Status = InitializeBM ();\r
1354\r
1355 return Status;\r
1356}\r
1357\r
1358/**\r
1359 Dispatch BMM formset and FileExplorer formset.\r
1360\r
1361\r
1362 @param CallbackData The BMM context data.\r
1363\r
1364 @retval EFI_SUCCESS If function complete successfully.\r
1365 @return Other value if the Setup Browser process BMM's pages and\r
1366 return unsuccessfully.\r
1367\r
1368**/\r
1369EFI_STATUS\r
1370FormSetDispatcher (\r
1371 IN BMM_CALLBACK_DATA *CallbackData\r
1372 )\r
1373{\r
1374 EFI_STATUS Status;\r
1375 EFI_BROWSER_ACTION_REQUEST ActionRequest;\r
1376\r
1377 while (TRUE) {\r
1378 UpdatePageId (CallbackData, FORM_MAIN_ID);\r
1379\r
1380 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
1381 Status = gFormBrowser2->SendForm (\r
1382 gFormBrowser2,\r
1383 &CallbackData->BmmHiiHandle,\r
1384 1,\r
e24fc103 1385 &gBootMaintFormSetGuid,\r
5c08e117 1386 0,\r
1387 NULL,\r
1388 &ActionRequest\r
1389 );\r
1390 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {\r
1391 EnableResetRequired ();\r
1392 }\r
1393\r
1394 ReclaimStringDepository ();\r
1395\r
1396 //\r
1397 // When this Formset returns, check if we are going to explore files.\r
1398 //\r
13078b3f 1399 if (FileExplorerStateInActive != CallbackData->FeCurrentState) {\r
5c08e117 1400 UpdateFileExplorer (CallbackData, 0);\r
1401\r
1402 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
1403 Status = gFormBrowser2->SendForm (\r
1404 gFormBrowser2,\r
1405 &CallbackData->FeHiiHandle,\r
1406 1,\r
e24fc103 1407 &gFileExploreFormSetGuid,\r
5c08e117 1408 0,\r
1409 NULL,\r
1410 &ActionRequest\r
1411 );\r
1412 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {\r
1413 EnableResetRequired ();\r
1414 }\r
1415\r
13078b3f 1416 CallbackData->FeCurrentState = FileExplorerStateInActive;\r
1417 CallbackData->FeDisplayContext = FileExplorerDisplayUnknown;\r
5c08e117 1418 ReclaimStringDepository ();\r
1419 } else {\r
1420 break;\r
1421 }\r
1422 }\r
1423\r
1424 return Status;\r
1425}\r
1426\r
1427\r
be887447
RN
1428/**\r
1429 Deletete the Boot Option from EFI Variable. The Boot Order Arrray\r
1430 is also updated.\r
1431\r
1432 @param OptionNumber The number of Boot option want to be deleted.\r
1433 @param BootOrder The Boot Order array.\r
1434 @param BootOrderSize The size of the Boot Order Array.\r
1435\r
1436 @retval EFI_SUCCESS The Boot Option Variable was found and removed\r
1437 @retval EFI_UNSUPPORTED The Boot Option Variable store was inaccessible\r
1438 @retval EFI_NOT_FOUND The Boot Option Variable was not found\r
1439**/\r
1440EFI_STATUS\r
1441EFIAPI\r
1442BdsDeleteBootOption (\r
1443 IN UINTN OptionNumber,\r
1444 IN OUT UINT16 *BootOrder,\r
1445 IN OUT UINTN *BootOrderSize\r
1446 )\r
1447{\r
1448 UINT16 BootOption[100];\r
1449 UINTN Index;\r
1450 EFI_STATUS Status;\r
1451 UINTN Index2Del;\r
1452\r
1453 Status = EFI_SUCCESS;\r
1454 Index2Del = 0;\r
1455\r
1456 UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", OptionNumber);\r
1457 Status = EfiLibDeleteVariable (BootOption, &gEfiGlobalVariableGuid);\r
1458 \r
1459 //\r
1460 // adjust boot order array\r
1461 //\r
1462 for (Index = 0; Index < *BootOrderSize / sizeof (UINT16); Index++) {\r
1463 if (BootOrder[Index] == OptionNumber) {\r
1464 Index2Del = Index;\r
1465 break;\r
1466 }\r
1467 }\r
1468\r
1469 if (Index != *BootOrderSize / sizeof (UINT16)) {\r
1470 for (Index = 0; Index < *BootOrderSize / sizeof (UINT16) - 1; Index++) {\r
1471 if (Index >= Index2Del) {\r
1472 BootOrder[Index] = BootOrder[Index + 1];\r
1473 }\r
1474 }\r
1475\r
1476 *BootOrderSize -= sizeof (UINT16);\r
1477 }\r
1478\r
1479 return Status;\r
1480\r
1481}\r
1482\r
1483\r