2 Boot Maintainence Main File
4 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
5 All rights reserved. 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
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.
15 #include "BootMaint.h"
18 #include "FrontPage.h"
20 EFI_DEVICE_PATH_PROTOCOL EndDevicePath
[] = {
23 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
25 END_DEVICE_PATH_LENGTH
,
32 EFI_GUID EfiLegacyDevOrderGuid
= EFI_LEGACY_DEV_ORDER_VARIABLE_GUID
;
33 EFI_GUID mBootMaintGuid
= BOOT_MAINT_FORMSET_GUID
;
34 EFI_GUID mFileExplorerGuid
= FILE_EXPLORE_FORMSET_GUID
;
36 CHAR16 mBootMaintStorageName
[] = L
"BmData";
37 CHAR16 mFileExplorerStorageName
[] = L
"FeData";
42 @param CallbackData The BMM context data.
47 IN BMM_CALLBACK_DATA
*CallbackData
51 Free up all Menu Option list.
60 Create string tokens for a menu from its help strings and display strings
63 @param CallbackData The BMM context data.
64 @param HiiHandle Hii Handle of the package to be updated.
65 @param MenuOption The Menu whose string tokens need to be created
67 @retval EFI_SUCCESS string tokens created successfully
68 @retval others contain some errors
72 CreateMenuStringToken (
73 IN BMM_CALLBACK_DATA
*CallbackData
,
74 IN EFI_HII_HANDLE HiiHandle
,
75 IN BM_MENU_OPTION
*MenuOption
78 BM_MENU_ENTRY
*NewMenuEntry
;
81 for (Index
= 0; Index
< MenuOption
->MenuNumber
; Index
++) {
82 NewMenuEntry
= BOpt_GetMenuEntry (MenuOption
, Index
);
86 &NewMenuEntry
->DisplayStringToken
,
87 NewMenuEntry
->DisplayString
90 if (NULL
== NewMenuEntry
->HelpString
) {
91 NewMenuEntry
->HelpStringToken
= NewMenuEntry
->DisplayStringToken
;
95 &NewMenuEntry
->HelpStringToken
,
96 NewMenuEntry
->HelpString
105 This function allows a caller to extract the current configuration for one
106 or more named elements from the target driver.
109 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
110 @param Request A null-terminated Unicode string in <ConfigRequest> format.
111 @param Progress On return, points to a character in the Request string.
112 Points to the string's null terminator if request was successful.
113 Points to the most recent '&' before the first failing name/value
114 pair (or the beginning of the string if the failure is in the
115 first name/value pair) if the request was not successful.
116 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
117 has all values filled in for the names in the Request string.
118 String to be allocated by the called function.
120 @retval EFI_SUCCESS The Results is filled with the requested values.
121 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
122 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
123 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
128 BootMaintExtractConfig (
129 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
130 IN CONST EFI_STRING Request
,
131 OUT EFI_STRING
*Progress
,
132 OUT EFI_STRING
*Results
137 BMM_CALLBACK_DATA
*Private
;
139 if (Request
== NULL
) {
140 return EFI_NOT_FOUND
;
143 Private
= BMM_CALLBACK_DATA_FROM_THIS (This
);
146 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
148 BufferSize
= sizeof (BMM_FAKE_NV_DATA
);
149 Status
= gHiiConfigRouting
->BlockToConfig (
152 (UINT8
*) &Private
->BmmFakeNvData
,
161 This function processes the results of changes in configuration.
164 @param This - Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
165 @param Action - Specifies the type of action taken by the browser.
166 @param QuestionId - A unique value which is sent to the original exporting driver
167 so that it can identify the type of data to expect.
168 @param Type - The type of value for the question.
169 @param Value - A pointer to the data being sent to the original exporting driver.
170 @param ActionRequest - On return, points to the action requested by the callback function.
172 @retval EFI_SUCCESS The callback successfully handled the action.
173 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
174 @retval EFI_DEVICE_ERROR The variable could not be saved.
175 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
181 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
182 IN EFI_BROWSER_ACTION Action
,
183 IN EFI_QUESTION_ID QuestionId
,
185 IN EFI_IFR_TYPE_VALUE
*Value
,
186 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
189 BMM_CALLBACK_DATA
*Private
;
190 BM_MENU_ENTRY
*NewMenuEntry
;
191 BMM_FAKE_NV_DATA
*CurrentFakeNVMap
;
207 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
208 return EFI_INVALID_PARAMETER
;
218 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
220 Private
= BMM_CALLBACK_DATA_FROM_THIS (This
);
221 UpdatePageId (Private
, QuestionId
);
224 // Retrive uncommitted data from Form Browser
226 CurrentFakeNVMap
= &Private
->BmmFakeNvData
;
227 BufferSize
= sizeof (BMM_FAKE_NV_DATA
);
228 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) CurrentFakeNVMap
);
229 if (EFI_ERROR (Status
)) {
234 // need to be subtituded.
236 // Update Select FD/HD/CD/NET/BEV Order Form
238 if (FORM_SET_FD_ORDER_ID
== Private
->BmmPreviousPageId
||
239 FORM_SET_HD_ORDER_ID
== Private
->BmmPreviousPageId
||
240 FORM_SET_CD_ORDER_ID
== Private
->BmmPreviousPageId
||
241 FORM_SET_NET_ORDER_ID
== Private
->BmmPreviousPageId
||
242 FORM_SET_BEV_ORDER_ID
== Private
->BmmPreviousPageId
||
243 ((FORM_BOOT_SETUP_ID
== Private
->BmmPreviousPageId
) &&
244 (QuestionId
>= LEGACY_FD_QUESTION_ID
) &&
245 (QuestionId
< (LEGACY_BEV_QUESTION_ID
+ 100)) )
248 DisMap
= Private
->BmmOldFakeNVData
.DisableMap
;
250 FormId
= Private
->BmmPreviousPageId
;
251 if (FormId
== FORM_BOOT_SETUP_ID
) {
252 FormId
= Private
->BmmCurrentPageId
;
256 case FORM_SET_FD_ORDER_ID
:
257 Number
= (UINT16
) LegacyFDMenu
.MenuNumber
;
258 OldLegacyDev
= Private
->BmmOldFakeNVData
.LegacyFD
;
259 NewLegacyDev
= CurrentFakeNVMap
->LegacyFD
;
262 case FORM_SET_HD_ORDER_ID
:
263 Number
= (UINT16
) LegacyHDMenu
.MenuNumber
;
264 OldLegacyDev
= Private
->BmmOldFakeNVData
.LegacyHD
;
265 NewLegacyDev
= CurrentFakeNVMap
->LegacyHD
;
268 case FORM_SET_CD_ORDER_ID
:
269 Number
= (UINT16
) LegacyCDMenu
.MenuNumber
;
270 OldLegacyDev
= Private
->BmmOldFakeNVData
.LegacyCD
;
271 NewLegacyDev
= CurrentFakeNVMap
->LegacyCD
;
274 case FORM_SET_NET_ORDER_ID
:
275 Number
= (UINT16
) LegacyNETMenu
.MenuNumber
;
276 OldLegacyDev
= Private
->BmmOldFakeNVData
.LegacyNET
;
277 NewLegacyDev
= CurrentFakeNVMap
->LegacyNET
;
280 case FORM_SET_BEV_ORDER_ID
:
281 Number
= (UINT16
) LegacyBEVMenu
.MenuNumber
;
282 OldLegacyDev
= Private
->BmmOldFakeNVData
.LegacyBEV
;
283 NewLegacyDev
= CurrentFakeNVMap
->LegacyBEV
;
290 // First, find the different position
291 // if there is change, it should be only one
293 for (Index
= 0; Index
< Number
; Index
++) {
294 if (OldLegacyDev
[Index
] != NewLegacyDev
[Index
]) {
295 OldValue
= OldLegacyDev
[Index
];
296 NewValue
= NewLegacyDev
[Index
];
301 if (Index
!= Number
) {
303 // there is change, now process
305 if (0xFF == NewValue
) {
307 // This item will be disable
308 // Just move the items behind this forward to overlap it
311 Bit
= 7 - (OldValue
% 8);
312 DisMap
[Pos
] = (UINT8
) (DisMap
[Pos
] | (UINT8
) (1 << Bit
));
313 for (Index2
= Index
; Index2
< Number
- 1; Index2
++) {
314 NewLegacyDev
[Index2
] = NewLegacyDev
[Index2
+ 1];
317 NewLegacyDev
[Index2
] = 0xFF;
319 for (Index2
= 0; Index2
< Number
; Index2
++) {
320 if (Index2
== Index
) {
324 if (OldLegacyDev
[Index2
] == NewValue
) {
326 // If NewValue is in OldLegacyDev array
327 // remember its old position
329 NewValuePos
= Index2
;
334 if (Index2
!= Number
) {
336 // We will change current item to an existing item
337 // (It's hard to describe here, please read code, it's like a cycle-moving)
339 for (Index2
= NewValuePos
; Index2
!= Index
;) {
340 if (NewValuePos
< Index
) {
341 NewLegacyDev
[Index2
] = OldLegacyDev
[Index2
+ 1];
344 NewLegacyDev
[Index2
] = OldLegacyDev
[Index2
- 1];
350 // If NewValue is not in OldlegacyDev array, we are changing to a disabled item
351 // so we should modify DisMap to reflect the change
354 Bit
= 7 - (NewValue
% 8);
355 DisMap
[Pos
] = (UINT8
) (DisMap
[Pos
] & (~ (UINT8
) (1 << Bit
)));
356 if (0xFF != OldValue
) {
358 // Because NewValue is a item that was disabled before
359 // so after changing the OldValue should be disabled
360 // actually we are doing a swap of enable-disable states of two items
363 Bit
= 7 - (OldValue
% 8);
364 DisMap
[Pos
] = (UINT8
) (DisMap
[Pos
] | (UINT8
) (1 << Bit
));
369 // To prevent DISABLE appears in the middle of the list
370 // we should perform a re-ordering
373 while (Index
< Number
) {
374 if (0xFF != NewLegacyDev
[Index
]) {
381 while (Index2
< Number
) {
382 if (0xFF != NewLegacyDev
[Index2
]) {
389 if (Index2
< Number
) {
390 NewLegacyDev
[Index
] = NewLegacyDev
[Index2
];
391 NewLegacyDev
[Index2
] = 0xFF;
405 if (QuestionId
< FILE_OPTION_OFFSET
) {
406 if (QuestionId
< CONFIG_OPTION_OFFSET
) {
407 switch (QuestionId
) {
408 case KEY_VALUE_BOOT_FROM_FILE
:
409 Private
->FeCurrentState
= BOOT_FROM_FILE_STATE
;
412 // Exit Bmm main formset to send File Explorer formset.
414 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
417 case FORM_BOOT_ADD_ID
:
418 Private
->FeCurrentState
= ADD_BOOT_OPTION_STATE
;
421 // Exit Bmm main formset to send File Explorer formset.
423 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
426 case FORM_DRV_ADD_FILE_ID
:
427 Private
->FeCurrentState
= ADD_DRIVER_OPTION_STATE
;
430 // Exit Bmm main formset to send File Explorer formset.
432 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
435 case FORM_DRV_ADD_HANDLE_ID
:
436 CleanUpPage (FORM_DRV_ADD_HANDLE_ID
, Private
);
437 UpdateDrvAddHandlePage (Private
);
440 case FORM_BOOT_DEL_ID
:
441 CleanUpPage (FORM_BOOT_DEL_ID
, Private
);
442 UpdateBootDelPage (Private
);
445 case FORM_BOOT_CHG_ID
:
446 case FORM_DRV_CHG_ID
:
447 UpdatePageBody (QuestionId
, Private
);
450 case FORM_DRV_DEL_ID
:
451 CleanUpPage (FORM_DRV_DEL_ID
, Private
);
452 UpdateDrvDelPage (Private
);
455 case FORM_BOOT_NEXT_ID
:
456 CleanUpPage (FORM_BOOT_NEXT_ID
, Private
);
457 UpdateBootNextPage (Private
);
460 case FORM_TIME_OUT_ID
:
461 CleanUpPage (FORM_TIME_OUT_ID
, Private
);
462 UpdateTimeOutPage (Private
);
466 gRT
->ResetSystem (EfiResetCold
, EFI_SUCCESS
, 0, NULL
);
467 return EFI_UNSUPPORTED
;
470 case FORM_CON_OUT_ID
:
471 case FORM_CON_ERR_ID
:
472 UpdatePageBody (QuestionId
, Private
);
475 case FORM_CON_MODE_ID
:
476 CleanUpPage (FORM_CON_MODE_ID
, Private
);
477 UpdateConModePage (Private
);
480 case FORM_CON_COM_ID
:
481 CleanUpPage (FORM_CON_COM_ID
, Private
);
482 UpdateConCOMPage (Private
);
485 case FORM_SET_FD_ORDER_ID
:
486 case FORM_SET_HD_ORDER_ID
:
487 case FORM_SET_CD_ORDER_ID
:
488 case FORM_SET_NET_ORDER_ID
:
489 case FORM_SET_BEV_ORDER_ID
:
490 CleanUpPage (QuestionId
, Private
);
491 UpdateSetLegacyDeviceOrderPage (QuestionId
, Private
);
494 case KEY_VALUE_SAVE_AND_EXIT
:
495 case KEY_VALUE_NO_SAVE_AND_EXIT
:
497 if (QuestionId
== KEY_VALUE_SAVE_AND_EXIT
) {
498 Status
= ApplyChangeHandler (Private
, CurrentFakeNVMap
, Private
->BmmPreviousPageId
);
499 if (EFI_ERROR (Status
)) {
502 } else if (QuestionId
== KEY_VALUE_NO_SAVE_AND_EXIT
) {
503 DiscardChangeHandler (Private
, CurrentFakeNVMap
);
507 // Tell browser not to ask for confirmation of changes,
508 // since we have already applied or discarded.
510 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
516 } else if ((QuestionId
>= TERMINAL_OPTION_OFFSET
) && (QuestionId
< CONSOLE_OPTION_OFFSET
)) {
517 Index2
= (UINT16
) (QuestionId
- TERMINAL_OPTION_OFFSET
);
518 Private
->CurrentTerminal
= Index2
;
520 CleanUpPage (FORM_CON_COM_SETUP_ID
, Private
);
521 UpdateTerminalPage (Private
);
523 } else if (QuestionId
>= HANDLE_OPTION_OFFSET
) {
524 Index2
= (UINT16
) (QuestionId
- HANDLE_OPTION_OFFSET
);
526 NewMenuEntry
= BOpt_GetMenuEntry (&DriverMenu
, Index2
);
527 ASSERT (NewMenuEntry
!= NULL
);
528 Private
->HandleContext
= (BM_HANDLE_CONTEXT
*) NewMenuEntry
->VariableContext
;
530 CleanUpPage (FORM_DRV_ADD_HANDLE_DESC_ID
, Private
);
532 Private
->MenuEntry
= NewMenuEntry
;
533 Private
->LoadContext
->FilePathList
= Private
->HandleContext
->DevicePath
;
535 UpdateDriverAddHandleDescPage (Private
);
540 // Pass changed uncommitted data back to Form Browser
542 BufferSize
= sizeof (BMM_FAKE_NV_DATA
);
543 Status
= SetBrowserData (NULL
, NULL
, BufferSize
, (UINT8
*) CurrentFakeNVMap
, NULL
);
549 Function handling request to apply changes for BMM pages.
551 @param Private Pointer to callback data buffer.
552 @param CurrentFakeNVMap Pointer to buffer holding data of various values used by BMM
553 @param FormId ID of the form which has sent the request to apply change.
555 @retval EFI_SUCCESS Change successfully applied.
556 @retval Other Error occurs while trying to apply changes.
561 IN BMM_CALLBACK_DATA
*Private
,
562 IN BMM_FAKE_NV_DATA
*CurrentFakeNVMap
,
563 IN EFI_FORM_ID FormId
566 BM_CONSOLE_CONTEXT
*NewConsoleContext
;
567 BM_TERMINAL_CONTEXT
*NewTerminalContext
;
568 BM_LOAD_CONTEXT
*NewLoadContext
;
569 BM_MENU_ENTRY
*NewMenuEntry
;
573 Status
= EFI_SUCCESS
;
576 case FORM_SET_FD_ORDER_ID
:
577 case FORM_SET_HD_ORDER_ID
:
578 case FORM_SET_CD_ORDER_ID
:
579 case FORM_SET_NET_ORDER_ID
:
580 case FORM_SET_BEV_ORDER_ID
:
581 Var_UpdateBBSOption (Private
);
584 case FORM_BOOT_DEL_ID
:
585 for (Index
= 0; Index
< BootOptionMenu
.MenuNumber
; Index
++) {
586 NewMenuEntry
= BOpt_GetMenuEntry (&BootOptionMenu
, Index
);
587 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
588 NewLoadContext
->Deleted
= CurrentFakeNVMap
->BootOptionDel
[Index
];
591 Var_DelBootOption ();
594 case FORM_DRV_DEL_ID
:
595 for (Index
= 0; Index
< DriverOptionMenu
.MenuNumber
; Index
++) {
596 NewMenuEntry
= BOpt_GetMenuEntry (&DriverOptionMenu
, Index
);
597 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
598 NewLoadContext
->Deleted
= CurrentFakeNVMap
->DriverOptionDel
[Index
];
601 Var_DelDriverOption ();
604 case FORM_BOOT_CHG_ID
:
605 Status
= Var_UpdateBootOrder (Private
);
608 case FORM_DRV_CHG_ID
:
609 Status
= Var_UpdateDriverOrder (Private
);
612 case FORM_TIME_OUT_ID
:
613 Status
= gRT
->SetVariable (
615 &gEfiGlobalVariableGuid
,
618 &(CurrentFakeNVMap
->BootTimeOut
)
620 if (EFI_ERROR (Status
)) {
624 Private
->BmmOldFakeNVData
.BootTimeOut
= CurrentFakeNVMap
->BootTimeOut
;
627 case FORM_BOOT_NEXT_ID
:
628 Status
= Var_UpdateBootNext (Private
);
631 case FORM_CON_MODE_ID
:
632 Status
= Var_UpdateConMode (Private
);
635 case FORM_CON_COM_SETUP_ID
:
636 NewMenuEntry
= BOpt_GetMenuEntry (&TerminalMenu
, Private
->CurrentTerminal
);
638 ASSERT (NewMenuEntry
!= NULL
);
640 NewTerminalContext
= (BM_TERMINAL_CONTEXT
*) NewMenuEntry
->VariableContext
;
642 NewTerminalContext
->BaudRateIndex
= CurrentFakeNVMap
->COMBaudRate
;
643 NewTerminalContext
->BaudRate
= BaudRateList
[CurrentFakeNVMap
->COMBaudRate
].Value
;
644 NewTerminalContext
->DataBitsIndex
= CurrentFakeNVMap
->COMDataRate
;
645 NewTerminalContext
->DataBits
= (UINT8
) DataBitsList
[CurrentFakeNVMap
->COMDataRate
].Value
;
646 NewTerminalContext
->StopBitsIndex
= CurrentFakeNVMap
->COMStopBits
;
647 NewTerminalContext
->StopBits
= (UINT8
) StopBitsList
[CurrentFakeNVMap
->COMStopBits
].Value
;
648 NewTerminalContext
->ParityIndex
= CurrentFakeNVMap
->COMParity
;
649 NewTerminalContext
->Parity
= (UINT8
) ParityList
[CurrentFakeNVMap
->COMParity
].Value
;
650 NewTerminalContext
->TerminalType
= CurrentFakeNVMap
->COMTerminalType
;
652 ChangeTerminalDevicePath (
653 NewTerminalContext
->DevicePath
,
657 Var_UpdateConsoleInpOption ();
658 Var_UpdateConsoleOutOption ();
659 Var_UpdateErrorOutOption ();
663 for (Index
= 0; Index
< ConsoleInpMenu
.MenuNumber
; Index
++) {
664 NewMenuEntry
= BOpt_GetMenuEntry (&ConsoleInpMenu
, Index
);
665 NewConsoleContext
= (BM_CONSOLE_CONTEXT
*) NewMenuEntry
->VariableContext
;
666 NewConsoleContext
->IsActive
= CurrentFakeNVMap
->ConsoleCheck
[Index
];
669 for (Index
= 0; Index
< TerminalMenu
.MenuNumber
; Index
++) {
670 NewMenuEntry
= BOpt_GetMenuEntry (&TerminalMenu
, Index
);
671 NewTerminalContext
= (BM_TERMINAL_CONTEXT
*) NewMenuEntry
->VariableContext
;
672 NewTerminalContext
->IsConIn
= CurrentFakeNVMap
->ConsoleCheck
[Index
+ ConsoleInpMenu
.MenuNumber
];
675 Var_UpdateConsoleInpOption ();
678 case FORM_CON_OUT_ID
:
679 for (Index
= 0; Index
< ConsoleOutMenu
.MenuNumber
; Index
++) {
680 NewMenuEntry
= BOpt_GetMenuEntry (&ConsoleOutMenu
, Index
);
681 NewConsoleContext
= (BM_CONSOLE_CONTEXT
*) NewMenuEntry
->VariableContext
;
682 NewConsoleContext
->IsActive
= CurrentFakeNVMap
->ConsoleCheck
[Index
];
685 for (Index
= 0; Index
< TerminalMenu
.MenuNumber
; Index
++) {
686 NewMenuEntry
= BOpt_GetMenuEntry (&TerminalMenu
, Index
);
687 NewTerminalContext
= (BM_TERMINAL_CONTEXT
*) NewMenuEntry
->VariableContext
;
688 NewTerminalContext
->IsConOut
= CurrentFakeNVMap
->ConsoleCheck
[Index
+ ConsoleOutMenu
.MenuNumber
];
691 Var_UpdateConsoleOutOption ();
694 case FORM_CON_ERR_ID
:
695 for (Index
= 0; Index
< ConsoleErrMenu
.MenuNumber
; Index
++) {
696 NewMenuEntry
= BOpt_GetMenuEntry (&ConsoleErrMenu
, Index
);
697 NewConsoleContext
= (BM_CONSOLE_CONTEXT
*) NewMenuEntry
->VariableContext
;
698 NewConsoleContext
->IsActive
= CurrentFakeNVMap
->ConsoleCheck
[Index
];
701 for (Index
= 0; Index
< TerminalMenu
.MenuNumber
; Index
++) {
702 NewMenuEntry
= BOpt_GetMenuEntry (&TerminalMenu
, Index
);
703 NewTerminalContext
= (BM_TERMINAL_CONTEXT
*) NewMenuEntry
->VariableContext
;
704 NewTerminalContext
->IsStdErr
= CurrentFakeNVMap
->ConsoleCheck
[Index
+ ConsoleErrMenu
.MenuNumber
];
707 Var_UpdateErrorOutOption ();
710 case FORM_DRV_ADD_HANDLE_DESC_ID
:
711 Status
= Var_UpdateDriverOption (
713 Private
->BmmHiiHandle
,
714 CurrentFakeNVMap
->DriverAddHandleDesc
,
715 CurrentFakeNVMap
->DriverAddHandleOptionalData
,
716 CurrentFakeNVMap
->DriverAddForceReconnect
718 if (EFI_ERROR (Status
)) {
722 BOpt_GetDriverOptions (Private
);
723 CreateMenuStringToken (Private
, Private
->BmmHiiHandle
, &DriverOptionMenu
);
735 Discard all changes done to the BMM pages such as Boot Order change,
738 @param Private The BMM context data.
739 @param CurrentFakeNVMap The current Fack NV Map.
743 DiscardChangeHandler (
744 IN BMM_CALLBACK_DATA
*Private
,
745 IN BMM_FAKE_NV_DATA
*CurrentFakeNVMap
750 switch (Private
->BmmPreviousPageId
) {
751 case FORM_BOOT_CHG_ID
:
752 case FORM_DRV_CHG_ID
:
753 CopyMem (CurrentFakeNVMap
->OptionOrder
, Private
->BmmOldFakeNVData
.OptionOrder
, 100);
756 case FORM_BOOT_DEL_ID
:
757 for (Index
= 0; Index
< BootOptionMenu
.MenuNumber
; Index
++) {
758 CurrentFakeNVMap
->BootOptionDel
[Index
] = 0x00;
762 case FORM_DRV_DEL_ID
:
763 for (Index
= 0; Index
< DriverOptionMenu
.MenuNumber
; Index
++) {
764 CurrentFakeNVMap
->DriverOptionDel
[Index
] = 0x00;
768 case FORM_BOOT_NEXT_ID
:
769 CurrentFakeNVMap
->BootNext
= Private
->BmmOldFakeNVData
.BootNext
;
772 case FORM_TIME_OUT_ID
:
773 CurrentFakeNVMap
->BootTimeOut
= Private
->BmmOldFakeNVData
.BootTimeOut
;
776 case FORM_DRV_ADD_HANDLE_DESC_ID
:
777 case FORM_DRV_ADD_FILE_ID
:
778 case FORM_DRV_ADD_HANDLE_ID
:
779 CurrentFakeNVMap
->DriverAddHandleDesc
[0] = 0x0000;
780 CurrentFakeNVMap
->DriverAddHandleOptionalData
[0] = 0x0000;
789 Initialize the Boot Maintenance Utitliy.
792 @retval EFI_SUCCESS utility ended successfully
793 @retval others contain some errors
801 EFI_LEGACY_BIOS_PROTOCOL
*LegacyBios
;
802 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
803 BMM_CALLBACK_DATA
*BmmCallbackInfo
;
807 Status
= EFI_SUCCESS
;
810 // Create CallbackData structures for Driver Callback
812 BmmCallbackInfo
= AllocateZeroPool (sizeof (BMM_CALLBACK_DATA
));
813 if (BmmCallbackInfo
== NULL
) {
814 return EFI_OUT_OF_RESOURCES
;
818 // Create LoadOption in BmmCallbackInfo for Driver Callback
820 Ptr
= AllocateZeroPool (sizeof (BM_LOAD_CONTEXT
) + sizeof (BM_FILE_CONTEXT
) + sizeof (BM_HANDLE_CONTEXT
) + sizeof (BM_MENU_ENTRY
));
822 FreePool (BmmCallbackInfo
);
823 return EFI_OUT_OF_RESOURCES
;
827 // Initialize Bmm callback data.
829 BmmCallbackInfo
->LoadContext
= (BM_LOAD_CONTEXT
*) Ptr
;
830 Ptr
+= sizeof (BM_LOAD_CONTEXT
);
832 BmmCallbackInfo
->FileContext
= (BM_FILE_CONTEXT
*) Ptr
;
833 Ptr
+= sizeof (BM_FILE_CONTEXT
);
835 BmmCallbackInfo
->HandleContext
= (BM_HANDLE_CONTEXT
*) Ptr
;
836 Ptr
+= sizeof (BM_HANDLE_CONTEXT
);
838 BmmCallbackInfo
->MenuEntry
= (BM_MENU_ENTRY
*) Ptr
;
840 BmmCallbackInfo
->Signature
= BMM_CALLBACK_DATA_SIGNATURE
;
841 BmmCallbackInfo
->BmmConfigAccess
.ExtractConfig
= BootMaintExtractConfig
;
842 BmmCallbackInfo
->BmmConfigAccess
.RouteConfig
= FakeRouteConfig
;
843 BmmCallbackInfo
->BmmConfigAccess
.Callback
= BootMaintCallback
;
844 BmmCallbackInfo
->BmmPreviousPageId
= FORM_MAIN_ID
;
845 BmmCallbackInfo
->BmmCurrentPageId
= FORM_MAIN_ID
;
846 BmmCallbackInfo
->FeConfigAccess
.ExtractConfig
= FakeExtractConfig
;
847 BmmCallbackInfo
->FeConfigAccess
.RouteConfig
= FakeRouteConfig
;
848 BmmCallbackInfo
->FeConfigAccess
.Callback
= FileExplorerCallback
;
849 BmmCallbackInfo
->FeCurrentState
= INACTIVE_STATE
;
850 BmmCallbackInfo
->FeDisplayContext
= UNKNOWN_CONTEXT
;
853 // Create driver handle used by HII database
855 Status
= HiiLibCreateHiiDriverHandle (&BmmCallbackInfo
->BmmDriverHandle
);
856 if (EFI_ERROR (Status
)) {
861 // Install Config Access protocol to driver handle
863 Status
= gBS
->InstallProtocolInterface (
864 &BmmCallbackInfo
->BmmDriverHandle
,
865 &gEfiHiiConfigAccessProtocolGuid
,
866 EFI_NATIVE_INTERFACE
,
867 &BmmCallbackInfo
->BmmConfigAccess
869 if (EFI_ERROR (Status
)) {
874 // Create driver handle used by HII database
876 Status
= HiiLibCreateHiiDriverHandle (&BmmCallbackInfo
->FeDriverHandle
);
877 if (EFI_ERROR (Status
)) {
882 // Install Config Access protocol to driver handle
884 Status
= gBS
->InstallProtocolInterface (
885 &BmmCallbackInfo
->FeDriverHandle
,
886 &gEfiHiiConfigAccessProtocolGuid
,
887 EFI_NATIVE_INTERFACE
,
888 &BmmCallbackInfo
->FeConfigAccess
890 if (EFI_ERROR (Status
)) {
895 // Post our Boot Maint VFR binnary to the HII database.
897 PackageList
= HiiLibPreparePackageList (2, &mBootMaintGuid
, BmBin
, BdsDxeStrings
);
898 ASSERT (PackageList
!= NULL
);
900 Status
= gHiiDatabase
->NewPackageList (
903 BmmCallbackInfo
->BmmDriverHandle
,
904 &BmmCallbackInfo
->BmmHiiHandle
906 FreePool (PackageList
);
909 // Post our File Explorer VFR binary to the HII database.
911 PackageList
= HiiLibPreparePackageList (2, &mFileExplorerGuid
, FEBin
, BdsDxeStrings
);
912 ASSERT (PackageList
!= NULL
);
914 Status
= gHiiDatabase
->NewPackageList (
917 BmmCallbackInfo
->FeDriverHandle
,
918 &BmmCallbackInfo
->FeHiiHandle
920 FreePool (PackageList
);
923 // Allocate space for creation of Buffer
925 gUpdateData
.BufferSize
= UPDATE_DATA_SIZE
;
926 gUpdateData
.Data
= AllocateZeroPool (UPDATE_DATA_SIZE
);
927 if (gUpdateData
.Data
== NULL
) {
928 FreePool (BmmCallbackInfo
->LoadContext
);
929 FreePool (BmmCallbackInfo
);
930 return EFI_OUT_OF_RESOURCES
;
933 InitializeStringDepository ();
935 InitAllMenu (BmmCallbackInfo
);
937 CreateMenuStringToken (BmmCallbackInfo
, BmmCallbackInfo
->BmmHiiHandle
, &ConsoleInpMenu
);
938 CreateMenuStringToken (BmmCallbackInfo
, BmmCallbackInfo
->BmmHiiHandle
, &ConsoleOutMenu
);
939 CreateMenuStringToken (BmmCallbackInfo
, BmmCallbackInfo
->BmmHiiHandle
, &ConsoleErrMenu
);
940 CreateMenuStringToken (BmmCallbackInfo
, BmmCallbackInfo
->BmmHiiHandle
, &BootOptionMenu
);
941 CreateMenuStringToken (BmmCallbackInfo
, BmmCallbackInfo
->BmmHiiHandle
, &DriverOptionMenu
);
942 CreateMenuStringToken (BmmCallbackInfo
, BmmCallbackInfo
->BmmHiiHandle
, &TerminalMenu
);
943 CreateMenuStringToken (BmmCallbackInfo
, BmmCallbackInfo
->BmmHiiHandle
, &DriverMenu
);
945 UpdateBootDelPage (BmmCallbackInfo
);
946 UpdateDrvDelPage (BmmCallbackInfo
);
948 if (TerminalMenu
.MenuNumber
> 0) {
949 BmmCallbackInfo
->CurrentTerminal
= 0;
950 UpdateTerminalPage (BmmCallbackInfo
);
953 Status
= EfiLibLocateProtocol (&gEfiLegacyBiosProtocolGuid
, (VOID
**) &LegacyBios
);
954 if (!EFI_ERROR (Status
)) {
955 RefreshUpdateData ();
958 // If LegacyBios Protocol is installed, add 3 tags about legacy boot option
959 // in BootOption form: legacy FD/HD/CD/NET/BEV
962 FORM_SET_FD_ORDER_ID
,
963 STRING_TOKEN (STR_FORM_SET_FD_ORDER_TITLE
),
964 STRING_TOKEN (STR_FORM_SET_FD_ORDER_TITLE
),
965 EFI_IFR_FLAG_CALLBACK
,
966 FORM_SET_FD_ORDER_ID
,
971 FORM_SET_HD_ORDER_ID
,
972 STRING_TOKEN (STR_FORM_SET_HD_ORDER_TITLE
),
973 STRING_TOKEN (STR_FORM_SET_HD_ORDER_TITLE
),
974 EFI_IFR_FLAG_CALLBACK
,
975 FORM_SET_HD_ORDER_ID
,
980 FORM_SET_CD_ORDER_ID
,
981 STRING_TOKEN (STR_FORM_SET_CD_ORDER_TITLE
),
982 STRING_TOKEN (STR_FORM_SET_CD_ORDER_TITLE
),
983 EFI_IFR_FLAG_CALLBACK
,
984 FORM_SET_CD_ORDER_ID
,
989 FORM_SET_NET_ORDER_ID
,
990 STRING_TOKEN (STR_FORM_SET_NET_ORDER_TITLE
),
991 STRING_TOKEN (STR_FORM_SET_NET_ORDER_TITLE
),
992 EFI_IFR_FLAG_CALLBACK
,
993 FORM_SET_NET_ORDER_ID
,
998 FORM_SET_BEV_ORDER_ID
,
999 STRING_TOKEN (STR_FORM_SET_BEV_ORDER_TITLE
),
1000 STRING_TOKEN (STR_FORM_SET_BEV_ORDER_TITLE
),
1001 EFI_IFR_FLAG_CALLBACK
,
1002 FORM_SET_BEV_ORDER_ID
,
1007 BmmCallbackInfo
->BmmHiiHandle
,
1010 FORM_BOOT_LEGACY_DEVICE_ID
,
1017 // Dispatch BMM main formset and File Explorer formset.
1019 FormSetDispatcher (BmmCallbackInfo
);
1022 // Remove our IFR data from HII database
1024 gHiiDatabase
->RemovePackageList (gHiiDatabase
, BmmCallbackInfo
->BmmHiiHandle
);
1025 gHiiDatabase
->RemovePackageList (gHiiDatabase
, BmmCallbackInfo
->FeHiiHandle
);
1027 CleanUpStringDepository ();
1031 FreePool (BmmCallbackInfo
->LoadContext
);
1032 FreePool (BmmCallbackInfo
);
1033 FreePool (gUpdateData
.Data
);
1034 gUpdateData
.Data
= NULL
;
1040 Initialized all Menu Option List.
1042 @param CallbackData The BMM context data.
1049 IN BMM_CALLBACK_DATA
*CallbackData
1052 InitializeListHead (&BootOptionMenu
.Head
);
1053 InitializeListHead (&DriverOptionMenu
.Head
);
1054 BOpt_GetBootOptions (CallbackData
);
1055 BOpt_GetDriverOptions (CallbackData
);
1056 BOpt_GetLegacyOptions ();
1057 InitializeListHead (&FsOptionMenu
.Head
);
1058 BOpt_FindDrivers ();
1059 InitializeListHead (&DirectoryMenu
.Head
);
1060 InitializeListHead (&ConsoleInpMenu
.Head
);
1061 InitializeListHead (&ConsoleOutMenu
.Head
);
1062 InitializeListHead (&ConsoleErrMenu
.Head
);
1063 InitializeListHead (&TerminalMenu
.Head
);
1069 Free up all Menu Option list.
1081 BOpt_FreeMenu (&DirectoryMenu
);
1082 BOpt_FreeMenu (&FsOptionMenu
);
1083 BOpt_FreeMenu (&BootOptionMenu
);
1084 BOpt_FreeMenu (&DriverOptionMenu
);
1085 BOpt_FreeMenu (&DriverMenu
);
1086 BOpt_FreeLegacyOptions ();
1091 Intialize all the string depositories.
1100 InitializeStringDepository (
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
;
1116 Fetch a usable string node from the string depository and return the string token.
1119 @param CallbackData The BMM context data.
1120 @param StringDepository The string repository.
1122 @retval EFI_STRING_ID String token.
1126 GetStringTokenFromDepository (
1127 IN BMM_CALLBACK_DATA
*CallbackData
,
1128 IN STRING_DEPOSITORY
*StringDepository
1131 STRING_LIST_NODE
*CurrentListNode
;
1132 STRING_LIST_NODE
*NextListNode
;
1134 CurrentListNode
= StringDepository
->CurrentNode
;
1136 if ((NULL
!= CurrentListNode
) && (NULL
!= CurrentListNode
->Next
)) {
1138 // Fetch one reclaimed node from the list.
1140 NextListNode
= StringDepository
->CurrentNode
->Next
;
1143 // If there is no usable node in the list, update the list.
1145 NextListNode
= AllocateZeroPool (sizeof (STRING_LIST_NODE
));
1147 HiiLibNewString (CallbackData
->BmmHiiHandle
, &(NextListNode
->StringToken
), L
" ");
1148 ASSERT (NextListNode
->StringToken
!= 0);
1150 StringDepository
->TotalNodeNumber
++;
1152 if (NULL
== CurrentListNode
) {
1153 StringDepository
->ListHead
= NextListNode
;
1155 CurrentListNode
->Next
= NextListNode
;
1159 StringDepository
->CurrentNode
= NextListNode
;
1161 return StringDepository
->CurrentNode
->StringToken
;
1165 Reclaim string depositories by moving the current node pointer to list head..
1174 ReclaimStringDepository (
1178 UINTN DepositoryIndex
;
1179 STRING_DEPOSITORY
*StringDepository
;
1181 StringDepository
= FileOptionStrDepository
;
1182 for (DepositoryIndex
= 0; DepositoryIndex
< STRING_DEPOSITORY_NUMBER
; DepositoryIndex
++) {
1183 StringDepository
->CurrentNode
= StringDepository
->ListHead
;
1189 Release resource for all the string depositories.
1198 CleanUpStringDepository (
1203 UINTN DepositoryIndex
;
1204 STRING_LIST_NODE
*CurrentListNode
;
1205 STRING_LIST_NODE
*NextListNode
;
1206 STRING_DEPOSITORY
*StringDepository
;
1209 // Release string list nodes.
1211 StringDepository
= FileOptionStrDepository
;
1212 for (DepositoryIndex
= 0; DepositoryIndex
< STRING_DEPOSITORY_NUMBER
; DepositoryIndex
++) {
1213 CurrentListNode
= StringDepository
->ListHead
;
1214 for (NodeIndex
= 0; NodeIndex
< StringDepository
->TotalNodeNumber
; NodeIndex
++) {
1215 NextListNode
= CurrentListNode
->Next
;
1216 FreePool (CurrentListNode
);
1217 CurrentListNode
= NextListNode
;
1223 // Release string depository.
1225 FreePool (FileOptionStrDepository
);
1229 Start boot maintenance manager
1234 @retval EFI_SUCCESS If BMM is invoked successfully.
1235 @return Other value if BMM return unsuccessfully.
1244 LIST_ENTRY BdsBootOptionList
;
1246 InitializeListHead (&BdsBootOptionList
);
1249 // Connect all prior to entering the platform setup menu.
1251 if (!gConnectAllHappened
) {
1252 BdsLibConnectAllDriversToAllControllers ();
1253 gConnectAllHappened
= TRUE
;
1256 // Have chance to enumerate boot device
1258 BdsLibEnumerateAllBootOption (&BdsBootOptionList
);
1263 Status
= InitializeBM ();
1269 Dispatch BMM formset and FileExplorer formset.
1272 @param CallbackData The BMM context data.
1274 @retval EFI_SUCCESS If function complete successfully.
1275 @return Other value if the Setup Browser process BMM's pages and
1276 return unsuccessfully.
1281 IN BMM_CALLBACK_DATA
*CallbackData
1285 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
1288 UpdatePageId (CallbackData
, FORM_MAIN_ID
);
1290 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1291 Status
= gFormBrowser2
->SendForm (
1293 &CallbackData
->BmmHiiHandle
,
1300 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
1301 EnableResetRequired ();
1304 ReclaimStringDepository ();
1307 // When this Formset returns, check if we are going to explore files.
1309 if (INACTIVE_STATE
!= CallbackData
->FeCurrentState
) {
1310 UpdateFileExplorer (CallbackData
, 0);
1312 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1313 Status
= gFormBrowser2
->SendForm (
1315 &CallbackData
->FeHiiHandle
,
1322 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
1323 EnableResetRequired ();
1326 CallbackData
->FeCurrentState
= INACTIVE_STATE
;
1327 CallbackData
->FeDisplayContext
= UNKNOWN_CONTEXT
;
1328 ReclaimStringDepository ();
1339 Deletete the Boot Option from EFI Variable. The Boot Order Arrray
1342 @param OptionNumber EDES_TODO: Add parameter description
1343 @param BootOrder The Boot Order array.
1344 @param BootOrderSize The size of the Boot Order Array.
1346 @return Other value if the Boot Option specified by OptionNumber is not deleteed succesfully.
1347 @retval EFI_SUCCESS If function return successfully.
1351 BdsDeleteBootOption (
1352 IN UINTN OptionNumber
,
1353 IN OUT UINT16
*BootOrder
,
1354 IN OUT UINTN
*BootOrderSize
1357 UINT16 BootOption
[100];
1362 Status
= EFI_SUCCESS
;
1365 UnicodeSPrint (BootOption
, sizeof (BootOption
), L
"Boot%04x", OptionNumber
);
1366 Status
= EfiLibDeleteVariable (BootOption
, &gEfiGlobalVariableGuid
);
1368 // adjust boot order array
1370 for (Index
= 0; Index
< *BootOrderSize
/ sizeof (UINT16
); Index
++) {
1371 if (BootOrder
[Index
] == OptionNumber
) {
1377 if (Index
!= *BootOrderSize
/ sizeof (UINT16
)) {
1378 for (Index
= 0; Index
< *BootOrderSize
/ sizeof (UINT16
) - 1; Index
++) {
1379 if (Index
>= Index2Del
) {
1380 BootOrder
[Index
] = BootOrder
[Index
+ 1];
1384 *BootOrderSize
-= sizeof (UINT16
);