]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Application/UiApp/BootMaint/BootMaint.c
UiApp: Update copyright info, cover old code existed in old 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) 2004 - 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 case FORM_RESET:
607 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
608 return EFI_UNSUPPORTED;
609
610 default:
611 break;
612 }
613 }
614
615 //
616 // Pass changed uncommitted data back to Form Browser
617 //
618 HiiSetBrowserData (&mBootMaintGuid, mBootMaintStorageName, sizeof (BMM_FAKE_NV_DATA), (UINT8 *) CurrentFakeNVMap, NULL);
619
620 return EFI_SUCCESS;
621 }
622
623 /**
624 Function handling request to apply changes for BMM pages.
625
626 @param Private Pointer to callback data buffer.
627 @param CurrentFakeNVMap Pointer to buffer holding data of various values used by BMM
628 @param FormId ID of the form which has sent the request to apply change.
629
630 @retval EFI_SUCCESS Change successfully applied.
631 @retval Other Error occurs while trying to apply changes.
632
633 **/
634 EFI_STATUS
635 ApplyChangeHandler (
636 IN BMM_CALLBACK_DATA *Private,
637 IN BMM_FAKE_NV_DATA *CurrentFakeNVMap,
638 IN EFI_FORM_ID FormId
639 )
640 {
641 BM_CONSOLE_CONTEXT *NewConsoleContext;
642 BM_TERMINAL_CONTEXT *NewTerminalContext;
643 BM_LOAD_CONTEXT *NewLoadContext;
644 BM_MENU_ENTRY *NewMenuEntry;
645 EFI_STATUS Status;
646 UINT16 Index;
647
648 Status = EFI_SUCCESS;
649
650 switch (FormId) {
651 case FORM_BOOT_DEL_ID:
652 for (Index = 0;
653 ((Index < BootOptionMenu.MenuNumber) && (Index < (sizeof (CurrentFakeNVMap->BootOptionDel) / sizeof (CurrentFakeNVMap->BootOptionDel[0]))));
654 Index ++) {
655 NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index);
656 NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;
657 NewLoadContext->Deleted = CurrentFakeNVMap->BootOptionDel[Index];
658 CurrentFakeNVMap->BootOptionDel[Index] = FALSE;
659 }
660
661 Var_DelBootOption ();
662 break;
663
664 case FORM_DRV_DEL_ID:
665 for (Index = 0;
666 ((Index < DriverOptionMenu.MenuNumber) && (Index < (sizeof (CurrentFakeNVMap->DriverOptionDel) / sizeof (CurrentFakeNVMap->DriverOptionDel[0]))));
667 Index++) {
668 NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, Index);
669 NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;
670 NewLoadContext->Deleted = CurrentFakeNVMap->DriverOptionDel[Index];
671 CurrentFakeNVMap->DriverOptionDel[Index] = FALSE;
672 }
673
674 Var_DelDriverOption ();
675 break;
676
677 case FORM_BOOT_CHG_ID:
678 Status = Var_UpdateBootOrder (Private);
679 break;
680
681 case FORM_DRV_CHG_ID:
682 Status = Var_UpdateDriverOrder (Private);
683 break;
684
685 case FORM_TIME_OUT_ID:
686 Status = gRT->SetVariable (
687 L"Timeout",
688 &gEfiGlobalVariableGuid,
689 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
690 sizeof (UINT16),
691 &(CurrentFakeNVMap->BootTimeOut)
692 );
693 ASSERT_EFI_ERROR(Status);
694
695 Private->BmmOldFakeNVData.BootTimeOut = CurrentFakeNVMap->BootTimeOut;
696 break;
697
698 case FORM_BOOT_NEXT_ID:
699 Status = Var_UpdateBootNext (Private);
700 break;
701
702 case FORM_CON_MODE_ID:
703 Status = Var_UpdateConMode (Private);
704 break;
705
706 case FORM_CON_COM_SETUP_ID:
707 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Private->CurrentTerminal);
708
709 ASSERT (NewMenuEntry != NULL);
710
711 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
712
713 NewTerminalContext->BaudRateIndex = CurrentFakeNVMap->COMBaudRate;
714 ASSERT (CurrentFakeNVMap->COMBaudRate < (sizeof (BaudRateList) / sizeof (BaudRateList[0])));
715 NewTerminalContext->BaudRate = BaudRateList[CurrentFakeNVMap->COMBaudRate].Value;
716 NewTerminalContext->DataBitsIndex = CurrentFakeNVMap->COMDataRate;
717 ASSERT (CurrentFakeNVMap->COMDataRate < (sizeof (DataBitsList) / sizeof (DataBitsList[0])));
718 NewTerminalContext->DataBits = (UINT8) DataBitsList[CurrentFakeNVMap->COMDataRate].Value;
719 NewTerminalContext->StopBitsIndex = CurrentFakeNVMap->COMStopBits;
720 ASSERT (CurrentFakeNVMap->COMStopBits < (sizeof (StopBitsList) / sizeof (StopBitsList[0])));
721 NewTerminalContext->StopBits = (UINT8) StopBitsList[CurrentFakeNVMap->COMStopBits].Value;
722 NewTerminalContext->ParityIndex = CurrentFakeNVMap->COMParity;
723 ASSERT (CurrentFakeNVMap->COMParity < (sizeof (ParityList) / sizeof (ParityList[0])));
724 NewTerminalContext->Parity = (UINT8) ParityList[CurrentFakeNVMap->COMParity].Value;
725 NewTerminalContext->TerminalType = CurrentFakeNVMap->COMTerminalType;
726
727 ChangeTerminalDevicePath (
728 NewTerminalContext->DevicePath,
729 FALSE
730 );
731
732 Var_UpdateConsoleInpOption ();
733 Var_UpdateConsoleOutOption ();
734 Var_UpdateErrorOutOption ();
735 break;
736
737 case FORM_CON_IN_ID:
738 for (Index = 0; Index < ConsoleInpMenu.MenuNumber; Index++) {
739 NewMenuEntry = BOpt_GetMenuEntry (&ConsoleInpMenu, Index);
740 NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext;
741 ASSERT (Index < MAX_MENU_NUMBER);
742 NewConsoleContext->IsActive = CurrentFakeNVMap->ConsoleCheck[Index];
743 }
744
745 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
746 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);
747 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
748 ASSERT (Index + ConsoleInpMenu.MenuNumber < MAX_MENU_NUMBER);
749 NewTerminalContext->IsConIn = CurrentFakeNVMap->ConsoleCheck[Index + ConsoleInpMenu.MenuNumber];
750 }
751
752 Var_UpdateConsoleInpOption ();
753 break;
754
755 case FORM_CON_OUT_ID:
756 for (Index = 0; Index < ConsoleOutMenu.MenuNumber; Index++) {
757 NewMenuEntry = BOpt_GetMenuEntry (&ConsoleOutMenu, Index);
758 NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext;
759 ASSERT (Index < MAX_MENU_NUMBER);
760 NewConsoleContext->IsActive = CurrentFakeNVMap->ConsoleCheck[Index];
761 }
762
763 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
764 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);
765 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
766 ASSERT (Index + ConsoleOutMenu.MenuNumber < MAX_MENU_NUMBER);
767 NewTerminalContext->IsConOut = CurrentFakeNVMap->ConsoleCheck[Index + ConsoleOutMenu.MenuNumber];
768 }
769
770 Var_UpdateConsoleOutOption ();
771 break;
772
773 case FORM_CON_ERR_ID:
774 for (Index = 0; Index < ConsoleErrMenu.MenuNumber; Index++) {
775 NewMenuEntry = BOpt_GetMenuEntry (&ConsoleErrMenu, Index);
776 NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext;
777 ASSERT (Index < MAX_MENU_NUMBER);
778 NewConsoleContext->IsActive = CurrentFakeNVMap->ConsoleCheck[Index];
779 }
780
781 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
782 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);
783 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
784 ASSERT (Index + ConsoleErrMenu.MenuNumber < MAX_MENU_NUMBER);
785 NewTerminalContext->IsStdErr = CurrentFakeNVMap->ConsoleCheck[Index + ConsoleErrMenu.MenuNumber];
786 }
787
788 Var_UpdateErrorOutOption ();
789 break;
790
791 case FORM_DRV_ADD_HANDLE_DESC_ID:
792 Status = Var_UpdateDriverOption (
793 Private,
794 Private->BmmHiiHandle,
795 CurrentFakeNVMap->DriverAddHandleDesc,
796 CurrentFakeNVMap->DriverAddHandleOptionalData,
797 CurrentFakeNVMap->DriverAddForceReconnect
798 );
799 if (EFI_ERROR (Status)) {
800 goto Error;
801 }
802
803 BOpt_GetDriverOptions (Private);
804 CreateMenuStringToken (Private, Private->BmmHiiHandle, &DriverOptionMenu);
805 break;
806
807 default:
808 break;
809 }
810
811 Error:
812 return Status;
813 }
814
815 /**
816 Discard all changes done to the BMM pages such as Boot Order change,
817 Driver order change.
818
819 @param Private The BMM context data.
820 @param CurrentFakeNVMap The current Fack NV Map.
821
822 **/
823 VOID
824 DiscardChangeHandler (
825 IN BMM_CALLBACK_DATA *Private,
826 IN BMM_FAKE_NV_DATA *CurrentFakeNVMap
827 )
828 {
829 UINT16 Index;
830
831 switch (Private->BmmPreviousPageId) {
832 case FORM_BOOT_CHG_ID:
833 CopyMem (CurrentFakeNVMap->BootOptionOrder, Private->BmmOldFakeNVData.BootOptionOrder, sizeof (CurrentFakeNVMap->BootOptionOrder));
834 break;
835
836 case FORM_DRV_CHG_ID:
837 CopyMem (CurrentFakeNVMap->DriverOptionOrder, Private->BmmOldFakeNVData.DriverOptionOrder, sizeof (CurrentFakeNVMap->DriverOptionOrder));
838 break;
839
840 case FORM_BOOT_DEL_ID:
841 ASSERT (BootOptionMenu.MenuNumber <= (sizeof (CurrentFakeNVMap->BootOptionDel) / sizeof (CurrentFakeNVMap->BootOptionDel[0])));
842 for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) {
843 CurrentFakeNVMap->BootOptionDel[Index] = FALSE;
844 }
845 break;
846
847 case FORM_DRV_DEL_ID:
848 ASSERT (DriverOptionMenu.MenuNumber <= (sizeof (CurrentFakeNVMap->DriverOptionDel) / sizeof (CurrentFakeNVMap->DriverOptionDel[0])));
849 for (Index = 0; Index < DriverOptionMenu.MenuNumber; Index++) {
850 CurrentFakeNVMap->DriverOptionDel[Index] = FALSE;
851 }
852 break;
853
854 case FORM_BOOT_NEXT_ID:
855 CurrentFakeNVMap->BootNext = Private->BmmOldFakeNVData.BootNext;
856 break;
857
858 case FORM_TIME_OUT_ID:
859 CurrentFakeNVMap->BootTimeOut = Private->BmmOldFakeNVData.BootTimeOut;
860 break;
861
862 case FORM_DRV_ADD_HANDLE_DESC_ID:
863 case FORM_DRV_ADD_FILE_ID:
864 case FORM_DRV_ADD_HANDLE_ID:
865 CurrentFakeNVMap->DriverAddHandleDesc[0] = 0x0000;
866 CurrentFakeNVMap->DriverAddHandleOptionalData[0] = 0x0000;
867 break;
868
869 default:
870 break;
871 }
872 }
873
874
875 /**
876 Create dynamic code for BMM.
877
878 @param BmmCallbackInfo The BMM context data.
879
880 **/
881 VOID
882 InitializeDrivers(
883 IN BMM_CALLBACK_DATA *BmmCallbackInfo
884 )
885 {
886 EFI_HII_HANDLE HiiHandle;
887 VOID *StartOpCodeHandle;
888 VOID *EndOpCodeHandle;
889 EFI_IFR_GUID_LABEL *StartLabel;
890 EFI_IFR_GUID_LABEL *EndLabel;
891 UINTN Index;
892 EFI_STRING_ID FormSetTitle;
893 EFI_STRING_ID FormSetHelp;
894 EFI_STRING String;
895 EFI_STRING_ID Token;
896 EFI_STRING_ID TokenHelp;
897 EFI_HII_HANDLE *HiiHandles;
898 UINTN SkipCount;
899 EFI_GUID FormSetGuid;
900 CHAR16 *DevicePathStr;
901 EFI_STRING_ID DevicePathId;
902
903 HiiHandle = BmmCallbackInfo->BmmHiiHandle;
904 //
905 // Allocate space for creation of UpdateData Buffer
906 //
907 StartOpCodeHandle = HiiAllocateOpCodeHandle ();
908 ASSERT (StartOpCodeHandle != NULL);
909
910 EndOpCodeHandle = HiiAllocateOpCodeHandle ();
911 ASSERT (EndOpCodeHandle != NULL);
912
913 //
914 // Create Hii Extend Label OpCode as the start opcode
915 //
916 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
917 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
918 StartLabel->Number = LABEL_BMM_PLATFORM_INFORMATION;
919
920 //
921 // Create Hii Extend Label OpCode as the end opcode
922 //
923 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
924 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
925 EndLabel->Number = LABEL_END;
926
927 //
928 // Get all the Hii handles
929 //
930 HiiHandles = HiiGetHiiHandles (NULL);
931 ASSERT (HiiHandles != NULL);
932
933 //
934 // Search for formset of each class type
935 //
936 SkipCount = 0;
937 for (Index = 0; HiiHandles[Index] != NULL; Index++) {
938 if (!ExtractDisplayedHiiFormFromHiiHandle (HiiHandles[Index], &gEfiIfrBootMaintenanceGuid, SkipCount, &FormSetTitle, &FormSetHelp, &FormSetGuid)) {
939 SkipCount = 0;
940 continue;
941 }
942 String = HiiGetString (HiiHandles[Index], FormSetTitle, NULL);
943 if (String == NULL) {
944 String = HiiGetString (HiiHandle, STR_MISSING_STRING, NULL);
945 ASSERT (String != NULL);
946 }
947 Token = HiiSetString (HiiHandle, 0, String, NULL);
948 FreePool (String);
949
950 String = HiiGetString (HiiHandles[Index], FormSetHelp, NULL);
951 if (String == NULL) {
952 String = HiiGetString (HiiHandle, STR_MISSING_STRING, NULL);
953 ASSERT (String != NULL);
954 }
955 TokenHelp = HiiSetString (HiiHandle, 0, String, NULL);
956 FreePool (String);
957
958 DevicePathStr = ExtractDevicePathFromHiiHandle(HiiHandles[Index]);
959 DevicePathId = 0;
960 if (DevicePathStr != NULL){
961 DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);
962 FreePool (DevicePathStr);
963 }
964
965 HiiCreateGotoExOpCode (
966 StartOpCodeHandle,
967 0,
968 Token,
969 TokenHelp,
970 0,
971 (EFI_QUESTION_ID) (Index + FRONT_PAGE_KEY_OFFSET),
972 0,
973 &FormSetGuid,
974 DevicePathId
975 );
976 //
977 //One packagelist may has more than one form package,
978 //Index-- means keep current HiiHandle and still extract from the packagelist,
979 //SkipCount++ means skip the formset which was found before in the same form package.
980 //
981 SkipCount++;
982 Index--;
983 }
984
985 HiiUpdateForm (
986 HiiHandle,
987 &mBootMaintGuid,
988 FORM_MAIN_ID,
989 StartOpCodeHandle,
990 EndOpCodeHandle
991 );
992
993 HiiFreeOpCodeHandle (StartOpCodeHandle);
994 HiiFreeOpCodeHandle (EndOpCodeHandle);
995 FreePool (HiiHandles);
996 }
997
998
999 /**
1000 Create dynamic code for BMM.
1001
1002 @param BmmCallbackInfo The BMM context data.
1003
1004 **/
1005 VOID
1006 InitializeBmmConfig(
1007 IN BMM_CALLBACK_DATA *BmmCallbackInfo
1008 )
1009 {
1010 UpdateBootDelPage (BmmCallbackInfo);
1011 UpdateDrvDelPage (BmmCallbackInfo);
1012
1013 if (TerminalMenu.MenuNumber > 0) {
1014 BmmCallbackInfo->CurrentTerminal = 0;
1015 UpdateTerminalPage (BmmCallbackInfo);
1016 }
1017
1018 InitializeDrivers (BmmCallbackInfo);
1019 }
1020
1021 /**
1022 Initialize the Boot Maintenance Utitliy.
1023
1024 **/
1025 VOID
1026 InitializeBM (
1027 VOID
1028 )
1029 {
1030 BMM_CALLBACK_DATA *BmmCallbackInfo;
1031
1032 BmmCallbackInfo = mBmmCallbackInfo;
1033 BmmCallbackInfo->BmmPreviousPageId = FORM_MAIN_ID;
1034 BmmCallbackInfo->BmmCurrentPageId = FORM_MAIN_ID;
1035 BmmCallbackInfo->FeCurrentState = FileExplorerStateInActive;
1036 BmmCallbackInfo->FeDisplayContext = FileExplorerDisplayUnknown;
1037
1038 InitAllMenu (BmmCallbackInfo);
1039
1040 CreateMenuStringToken (BmmCallbackInfo, BmmCallbackInfo->BmmHiiHandle, &ConsoleInpMenu);
1041 CreateMenuStringToken (BmmCallbackInfo, BmmCallbackInfo->BmmHiiHandle, &ConsoleOutMenu);
1042 CreateMenuStringToken (BmmCallbackInfo, BmmCallbackInfo->BmmHiiHandle, &ConsoleErrMenu);
1043 CreateMenuStringToken (BmmCallbackInfo, BmmCallbackInfo->BmmHiiHandle, &BootOptionMenu);
1044 CreateMenuStringToken (BmmCallbackInfo, BmmCallbackInfo->BmmHiiHandle, &DriverOptionMenu);
1045 CreateMenuStringToken (BmmCallbackInfo, BmmCallbackInfo->BmmHiiHandle, &TerminalMenu);
1046 CreateMenuStringToken (BmmCallbackInfo, BmmCallbackInfo->BmmHiiHandle, &DriverMenu);
1047
1048 InitializeBmmConfig(BmmCallbackInfo);
1049 }
1050
1051 /**
1052 Initialized all Menu Option List.
1053
1054 @param CallbackData The BMM context data.
1055
1056 **/
1057 VOID
1058 InitAllMenu (
1059 IN BMM_CALLBACK_DATA *CallbackData
1060 )
1061 {
1062 InitializeListHead (&BootOptionMenu.Head);
1063 InitializeListHead (&DriverOptionMenu.Head);
1064 BOpt_GetBootOptions (CallbackData);
1065 BOpt_GetDriverOptions (CallbackData);
1066 InitializeListHead (&FsOptionMenu.Head);
1067 BOpt_FindDrivers ();
1068 InitializeListHead (&DirectoryMenu.Head);
1069 InitializeListHead (&ConsoleInpMenu.Head);
1070 InitializeListHead (&ConsoleOutMenu.Head);
1071 InitializeListHead (&ConsoleErrMenu.Head);
1072 InitializeListHead (&TerminalMenu.Head);
1073 LocateSerialIo ();
1074 GetAllConsoles ();
1075 mAllMenuInit = TRUE;
1076 }
1077
1078 /**
1079 Free up all Menu Option list.
1080
1081 **/
1082 VOID
1083 FreeAllMenu (
1084 VOID
1085 )
1086 {
1087 if (!mAllMenuInit){
1088 return;
1089 }
1090 BOpt_FreeMenu (&DirectoryMenu);
1091 BOpt_FreeMenu (&FsOptionMenu);
1092 BOpt_FreeMenu (&BootOptionMenu);
1093 BOpt_FreeMenu (&DriverOptionMenu);
1094 BOpt_FreeMenu (&DriverMenu);
1095 FreeAllConsoles ();
1096 mAllMenuInit = FALSE;
1097 }
1098
1099 /**
1100 Initialize all the string depositories.
1101
1102 **/
1103 VOID
1104 InitializeStringDepository (
1105 VOID
1106 )
1107 {
1108 STRING_DEPOSITORY *StringDepository;
1109 StringDepository = AllocateZeroPool (sizeof (STRING_DEPOSITORY) * STRING_DEPOSITORY_NUMBER);
1110 FileOptionStrDepository = StringDepository++;
1111 ConsoleOptionStrDepository = StringDepository++;
1112 BootOptionStrDepository = StringDepository++;
1113 BootOptionHelpStrDepository = StringDepository++;
1114 DriverOptionStrDepository = StringDepository++;
1115 DriverOptionHelpStrDepository = StringDepository++;
1116 TerminalStrDepository = StringDepository;
1117 }
1118
1119 /**
1120 Fetch a usable string node from the string depository and return the string token.
1121
1122 @param CallbackData The BMM context data.
1123 @param StringDepository The string repository.
1124
1125 @retval EFI_STRING_ID String token.
1126
1127 **/
1128 EFI_STRING_ID
1129 GetStringTokenFromDepository (
1130 IN BMM_CALLBACK_DATA *CallbackData,
1131 IN STRING_DEPOSITORY *StringDepository
1132 )
1133 {
1134 STRING_LIST_NODE *CurrentListNode;
1135 STRING_LIST_NODE *NextListNode;
1136
1137 CurrentListNode = StringDepository->CurrentNode;
1138
1139 if ((NULL != CurrentListNode) && (NULL != CurrentListNode->Next)) {
1140 //
1141 // Fetch one reclaimed node from the list.
1142 //
1143 NextListNode = StringDepository->CurrentNode->Next;
1144 } else {
1145 //
1146 // If there is no usable node in the list, update the list.
1147 //
1148 NextListNode = AllocateZeroPool (sizeof (STRING_LIST_NODE));
1149 ASSERT (NextListNode != NULL);
1150 NextListNode->StringToken = HiiSetString (CallbackData->BmmHiiHandle, 0, L" ", NULL);
1151 ASSERT (NextListNode->StringToken != 0);
1152
1153 StringDepository->TotalNodeNumber++;
1154
1155 if (NULL == CurrentListNode) {
1156 StringDepository->ListHead = NextListNode;
1157 } else {
1158 CurrentListNode->Next = NextListNode;
1159 }
1160 }
1161
1162 StringDepository->CurrentNode = NextListNode;
1163
1164 return StringDepository->CurrentNode->StringToken;
1165 }
1166
1167 /**
1168 Reclaim string depositories by moving the current node pointer to list head..
1169
1170 **/
1171 VOID
1172 ReclaimStringDepository (
1173 VOID
1174 )
1175 {
1176 UINTN DepositoryIndex;
1177 STRING_DEPOSITORY *StringDepository;
1178
1179 StringDepository = FileOptionStrDepository;
1180 for (DepositoryIndex = 0; DepositoryIndex < STRING_DEPOSITORY_NUMBER; DepositoryIndex++) {
1181 StringDepository->CurrentNode = StringDepository->ListHead;
1182 StringDepository++;
1183 }
1184 }
1185
1186 /**
1187 Release resource for all the string depositories.
1188
1189 **/
1190 VOID
1191 CleanUpStringDepository (
1192 VOID
1193 )
1194 {
1195 UINTN NodeIndex;
1196 UINTN DepositoryIndex;
1197 STRING_LIST_NODE *CurrentListNode;
1198 STRING_LIST_NODE *NextListNode;
1199 STRING_DEPOSITORY *StringDepository;
1200
1201 //
1202 // Release string list nodes.
1203 //
1204 StringDepository = FileOptionStrDepository;
1205 for (DepositoryIndex = 0; DepositoryIndex < STRING_DEPOSITORY_NUMBER; DepositoryIndex++) {
1206 CurrentListNode = StringDepository->ListHead;
1207 for (NodeIndex = 0; NodeIndex < StringDepository->TotalNodeNumber; NodeIndex++) {
1208 NextListNode = CurrentListNode->Next;
1209 FreePool (CurrentListNode);
1210 CurrentListNode = NextListNode;
1211 }
1212
1213 StringDepository++;
1214 }
1215 //
1216 // Release string depository.
1217 //
1218 FreePool (FileOptionStrDepository);
1219 }
1220
1221 /**
1222 Install BootMaint and FileExplorer HiiPackages.
1223
1224 **/
1225 VOID
1226 InitBootMaintenance(
1227 VOID
1228 )
1229 {
1230 BMM_CALLBACK_DATA *BmmCallbackInfo;
1231 EFI_STATUS Status;
1232 UINT8 *Ptr;
1233
1234 Status = EFI_SUCCESS;
1235
1236 if (!gConnectAllHappened){
1237 EfiBootManagerConnectAll();
1238 gConnectAllHappened = TRUE;
1239 }
1240
1241 EfiBootManagerRefreshAllBootOption ();
1242
1243 //
1244 // Create CallbackData structures for Driver Callback
1245 //
1246 BmmCallbackInfo = AllocateZeroPool (sizeof (BMM_CALLBACK_DATA));
1247 ASSERT (BmmCallbackInfo != NULL);
1248
1249 //
1250 // Create LoadOption in BmmCallbackInfo for Driver Callback
1251 //
1252 Ptr = AllocateZeroPool (sizeof (BM_LOAD_CONTEXT) + sizeof (BM_FILE_CONTEXT) + sizeof (BM_HANDLE_CONTEXT) + sizeof (BM_MENU_ENTRY));
1253 ASSERT (Ptr != NULL);
1254
1255 //
1256 // Initialize Bmm callback data.
1257 //
1258 BmmCallbackInfo->LoadContext = (BM_LOAD_CONTEXT *) Ptr;
1259 Ptr += sizeof (BM_LOAD_CONTEXT);
1260
1261 BmmCallbackInfo->FileContext = (BM_FILE_CONTEXT *) Ptr;
1262 Ptr += sizeof (BM_FILE_CONTEXT);
1263
1264 BmmCallbackInfo->HandleContext = (BM_HANDLE_CONTEXT *) Ptr;
1265 Ptr += sizeof (BM_HANDLE_CONTEXT);
1266
1267 BmmCallbackInfo->MenuEntry = (BM_MENU_ENTRY *) Ptr;
1268
1269 BmmCallbackInfo->Signature = BMM_CALLBACK_DATA_SIGNATURE;
1270 BmmCallbackInfo->BmmConfigAccess.ExtractConfig = BootMaintExtractConfig;
1271 BmmCallbackInfo->BmmConfigAccess.RouteConfig = BootMaintRouteConfig;
1272 BmmCallbackInfo->BmmConfigAccess.Callback = BootMaintCallback;
1273 BmmCallbackInfo->BmmPreviousPageId = FORM_MAIN_ID;
1274 BmmCallbackInfo->BmmCurrentPageId = FORM_MAIN_ID;
1275 BmmCallbackInfo->FeConfigAccess.ExtractConfig = FakeExtractConfig;
1276 BmmCallbackInfo->FeConfigAccess.RouteConfig = FakeRouteConfig;
1277 BmmCallbackInfo->FeConfigAccess.Callback = FileExplorerCallback;
1278 BmmCallbackInfo->FeCurrentState = FileExplorerStateInActive;
1279 BmmCallbackInfo->FeDisplayContext = FileExplorerDisplayUnknown;
1280
1281 //
1282 // Install Device Path Protocol and Config Access protocol to driver handle
1283 //
1284 Status = gBS->InstallMultipleProtocolInterfaces (
1285 &BmmCallbackInfo->BmmDriverHandle,
1286 &gEfiDevicePathProtocolGuid,
1287 &mBmmHiiVendorDevicePath,
1288 &gEfiHiiConfigAccessProtocolGuid,
1289 &BmmCallbackInfo->BmmConfigAccess,
1290 NULL
1291 );
1292 ASSERT_EFI_ERROR (Status);
1293
1294 //
1295 // Install Device Path Protocol and Config Access protocol to driver handle
1296 //
1297 Status = gBS->InstallMultipleProtocolInterfaces (
1298 &BmmCallbackInfo->FeDriverHandle,
1299 &gEfiDevicePathProtocolGuid,
1300 &mFeHiiVendorDevicePath,
1301 &gEfiHiiConfigAccessProtocolGuid,
1302 &BmmCallbackInfo->FeConfigAccess,
1303 NULL
1304 );
1305 ASSERT_EFI_ERROR (Status);
1306
1307 //
1308 // Post our Boot Maint VFR binary to the HII database.
1309 //
1310 BmmCallbackInfo->BmmHiiHandle = HiiAddPackages (
1311 &mBootMaintGuid,
1312 BmmCallbackInfo->BmmDriverHandle,
1313 BmBin,
1314 UiAppStrings,
1315 NULL
1316 );
1317 ASSERT (BmmCallbackInfo->BmmHiiHandle != NULL);
1318
1319 //
1320 // Post our File Explorer VFR binary to the HII database.
1321 //
1322 BmmCallbackInfo->FeHiiHandle = HiiAddPackages (
1323 &mFileExplorerGuid,
1324 BmmCallbackInfo->FeDriverHandle,
1325 FEBin,
1326 UiAppStrings,
1327 NULL
1328 );
1329 ASSERT (BmmCallbackInfo->FeHiiHandle != NULL);
1330
1331 //
1332 // Init OpCode Handle and Allocate space for creation of Buffer
1333 //
1334 mStartOpCodeHandle = HiiAllocateOpCodeHandle ();
1335 ASSERT (mStartOpCodeHandle != NULL);
1336
1337 mEndOpCodeHandle = HiiAllocateOpCodeHandle ();
1338 ASSERT (mEndOpCodeHandle != NULL);
1339
1340 //
1341 // Create Hii Extend Label OpCode as the start opcode
1342 //
1343 mStartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (mStartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
1344 mStartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
1345
1346 //
1347 // Create Hii Extend Label OpCode as the end opcode
1348 //
1349 mEndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (mEndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
1350 mEndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
1351 mEndLabel->Number = LABEL_END;
1352
1353 mBmmCallbackInfo = BmmCallbackInfo;
1354
1355 InitializeStringDepository ();
1356
1357 }
1358
1359 /**
1360 Remove the installed BootMaint and FileExplorer HiiPackages.
1361
1362 **/
1363 VOID
1364 FreeBMPackage(
1365 VOID
1366 )
1367 {
1368 BMM_CALLBACK_DATA *BmmCallbackInfo;
1369
1370 if (mStartOpCodeHandle != NULL) {
1371 HiiFreeOpCodeHandle (mStartOpCodeHandle);
1372 }
1373
1374 if (mEndOpCodeHandle != NULL) {
1375 HiiFreeOpCodeHandle (mEndOpCodeHandle);
1376 }
1377
1378 FreeAllMenu ();
1379 CleanUpStringDepository ();
1380
1381 BmmCallbackInfo = mBmmCallbackInfo;
1382
1383 //
1384 // Remove our IFR data from HII database
1385 //
1386 HiiRemovePackages (BmmCallbackInfo->BmmHiiHandle);
1387 HiiRemovePackages (BmmCallbackInfo->FeHiiHandle);
1388
1389 gBS->UninstallMultipleProtocolInterfaces (
1390 BmmCallbackInfo->FeDriverHandle,
1391 &gEfiDevicePathProtocolGuid,
1392 &mFeHiiVendorDevicePath,
1393 &gEfiHiiConfigAccessProtocolGuid,
1394 &BmmCallbackInfo->FeConfigAccess,
1395 NULL
1396 );
1397
1398 gBS->UninstallMultipleProtocolInterfaces (
1399 BmmCallbackInfo->BmmDriverHandle,
1400 &gEfiDevicePathProtocolGuid,
1401 &mBmmHiiVendorDevicePath,
1402 &gEfiHiiConfigAccessProtocolGuid,
1403 &BmmCallbackInfo->BmmConfigAccess,
1404 NULL
1405 );
1406
1407 FreePool (BmmCallbackInfo->LoadContext);
1408 FreePool (BmmCallbackInfo);
1409 }
1410