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