2 Variable operation that will be used by bootmaint
4 Copyright (c) 2004 - 2016, 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
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 "BootMaintenanceManager.h"
18 Delete Boot Option that represent a Deleted state in BootOptionMenu.
19 After deleting this boot option, call Var_ChangeBootOrder to
20 make sure BootOrder is in valid state.
22 @retval EFI_SUCCESS If all boot load option EFI Variables corresponding to
23 BM_LOAD_CONTEXT marked for deletion is deleted.
24 @retval EFI_NOT_FOUND If can not find the boot option want to be deleted.
25 @return Others If failed to update the "BootOrder" variable after deletion.
33 BM_MENU_ENTRY
*NewMenuEntry
;
34 BM_LOAD_CONTEXT
*NewLoadContext
;
35 UINT16 BootString
[10];
42 for (Index
= 0; Index
< BootOptionMenu
.MenuNumber
; Index
++) {
43 NewMenuEntry
= BOpt_GetMenuEntry (&BootOptionMenu
, (Index
- Index2
));
44 if (NULL
== NewMenuEntry
) {
48 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
49 if (!NewLoadContext
->Deleted
) {
57 NewMenuEntry
->OptionNumber
60 EfiLibDeleteVariable (BootString
, &gEfiGlobalVariableGuid
);
63 // If current Load Option is the same as BootNext,
64 // must delete BootNext in order to make sure
65 // there will be no panic on next boot
67 if (NewLoadContext
->IsBootNext
) {
68 EfiLibDeleteVariable (L
"BootNext", &gEfiGlobalVariableGuid
);
71 RemoveEntryList (&NewMenuEntry
->Link
);
72 BOpt_DestroyMenuEntry (NewMenuEntry
);
76 BootOptionMenu
.MenuNumber
-= Index2
;
78 Status
= Var_ChangeBootOrder ();
83 After any operation on Boot####, there will be a discrepancy in BootOrder.
84 Since some are missing but in BootOrder, while some are present but are
85 not reflected by BootOrder. Then a function rebuild BootOrder from
86 scratch by content from BootOptionMenu is needed.
91 @retval EFI_SUCCESS The boot order is updated successfully.
92 @return EFI_STATUS other than EFI_SUCCESS if failed to
93 Set the "BootOrder" EFI Variable.
103 BM_MENU_ENTRY
*NewMenuEntry
;
104 UINT16
*BootOrderList
;
105 UINT16
*BootOrderListPtr
;
106 UINTN BootOrderListSize
;
109 BootOrderList
= NULL
;
110 BootOrderListSize
= 0;
112 // First check whether BootOrder is present in current configuration
114 GetEfiGlobalVariable2 (L
"BootOrder", (VOID
**) &BootOrderList
, &BootOrderListSize
);
117 // If exists, delete it to hold new BootOrder
119 if (BootOrderList
!= NULL
) {
120 EfiLibDeleteVariable (L
"BootOrder", &gEfiGlobalVariableGuid
);
121 FreePool (BootOrderList
);
122 BootOrderList
= NULL
;
125 // Maybe here should be some check method to ensure that
126 // no new added boot options will be added
127 // but the setup engine now will give only one callback
128 // that is to say, user are granted only one chance to
129 // decide whether the boot option will be added or not
130 // there should be no indictor to show whether this
131 // is a "new" boot option
133 BootOrderListSize
= BootOptionMenu
.MenuNumber
;
135 if (BootOrderListSize
> 0) {
136 BootOrderList
= AllocateZeroPool (BootOrderListSize
* sizeof (UINT16
));
137 ASSERT (BootOrderList
!= NULL
);
138 BootOrderListPtr
= BootOrderList
;
141 // Get all current used Boot#### from BootOptionMenu.
142 // OptionNumber in each BM_LOAD_OPTION is really its
145 for (Index
= 0; Index
< BootOrderListSize
; Index
++) {
146 NewMenuEntry
= BOpt_GetMenuEntry (&BootOptionMenu
, Index
);
147 *BootOrderList
= (UINT16
) NewMenuEntry
->OptionNumber
;
151 BootOrderList
= BootOrderListPtr
;
154 // After building the BootOrderList, write it back
156 Status
= gRT
->SetVariable (
158 &gEfiGlobalVariableGuid
,
160 BootOrderListSize
* sizeof (UINT16
),
163 if (EFI_ERROR (Status
)) {
171 Delete Load Option that represent a Deleted state in BootOptionMenu.
172 After deleting this Driver option, call Var_ChangeDriverOrder to
173 make sure DriverOrder is in valid state.
175 @retval EFI_SUCCESS Load Option is successfully updated.
176 @retval EFI_NOT_FOUND Fail to find the driver option want to be deleted.
177 @return Other value than EFI_SUCCESS if failed to update "Driver Order" EFI
182 Var_DelDriverOption (
186 BM_MENU_ENTRY
*NewMenuEntry
;
187 BM_LOAD_CONTEXT
*NewLoadContext
;
188 UINT16 DriverString
[12];
193 Status
= EFI_SUCCESS
;
195 for (Index
= 0; Index
< DriverOptionMenu
.MenuNumber
; Index
++) {
196 NewMenuEntry
= BOpt_GetMenuEntry (&DriverOptionMenu
, (Index
- Index2
));
197 if (NULL
== NewMenuEntry
) {
198 return EFI_NOT_FOUND
;
201 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
202 if (!NewLoadContext
->Deleted
) {
208 sizeof (DriverString
),
210 NewMenuEntry
->OptionNumber
213 EfiLibDeleteVariable (DriverString
, &gEfiGlobalVariableGuid
);
216 RemoveEntryList (&NewMenuEntry
->Link
);
217 BOpt_DestroyMenuEntry (NewMenuEntry
);
221 DriverOptionMenu
.MenuNumber
-= Index2
;
223 Status
= Var_ChangeDriverOrder ();
228 After any operation on Driver####, there will be a discrepancy in
229 DriverOrder. Since some are missing but in DriverOrder, while some
230 are present but are not reflected by DriverOrder. Then a function
231 rebuild DriverOrder from scratch by content from DriverOptionMenu is
234 @retval EFI_SUCCESS The driver order is updated successfully.
235 @return Other status than EFI_SUCCESS if failed to set the "DriverOrder" EFI Variable.
239 Var_ChangeDriverOrder (
244 BM_MENU_ENTRY
*NewMenuEntry
;
245 UINT16
*DriverOrderList
;
246 UINT16
*DriverOrderListPtr
;
247 UINTN DriverOrderListSize
;
250 DriverOrderList
= NULL
;
251 DriverOrderListSize
= 0;
254 // First check whether DriverOrder is present in current configuration
256 GetEfiGlobalVariable2 (L
"DriverOrder", (VOID
**) &DriverOrderList
, &DriverOrderListSize
);
258 // If exists, delete it to hold new DriverOrder
260 if (DriverOrderList
!= NULL
) {
261 EfiLibDeleteVariable (L
"DriverOrder", &gEfiGlobalVariableGuid
);
262 FreePool (DriverOrderList
);
263 DriverOrderList
= NULL
;
266 DriverOrderListSize
= DriverOptionMenu
.MenuNumber
;
268 if (DriverOrderListSize
> 0) {
269 DriverOrderList
= AllocateZeroPool (DriverOrderListSize
* sizeof (UINT16
));
270 ASSERT (DriverOrderList
!= NULL
);
271 DriverOrderListPtr
= DriverOrderList
;
274 // Get all current used Driver#### from DriverOptionMenu.
275 // OptionNumber in each BM_LOAD_OPTION is really its
278 for (Index
= 0; Index
< DriverOrderListSize
; Index
++) {
279 NewMenuEntry
= BOpt_GetMenuEntry (&DriverOptionMenu
, Index
);
280 *DriverOrderList
= (UINT16
) NewMenuEntry
->OptionNumber
;
284 DriverOrderList
= DriverOrderListPtr
;
287 // After building the DriverOrderList, write it back
289 Status
= gRT
->SetVariable (
291 &gEfiGlobalVariableGuid
,
293 DriverOrderListSize
* sizeof (UINT16
),
296 if (EFI_ERROR (Status
)) {
304 This function delete and build multi-instance device path for
305 specified type of console device.
307 This function clear the EFI variable defined by ConsoleName and
308 gEfiGlobalVariableGuid. It then build the multi-instance device
309 path by appending the device path of the Console (In/Out/Err) instance
310 in ConsoleMenu. Then it scan all corresponding console device by
311 scanning Terminal (built from device supporting Serial I/O instances)
312 devices in TerminalMenu. At last, it save a EFI variable specifed
313 by ConsoleName and gEfiGlobalVariableGuid.
315 @param ConsoleName The name for the console device type. They are
316 usually "ConIn", "ConOut" and "ErrOut".
317 @param ConsoleMenu The console memu which is a list of console devices.
318 @param UpdatePageId The flag specifying which type of console device
321 @retval EFI_SUCCESS The function complete successfully.
322 @return The EFI variable can not be saved. See gRT->SetVariable for detail return information.
326 Var_UpdateConsoleOption (
327 IN UINT16
*ConsoleName
,
328 IN BM_MENU_OPTION
*ConsoleMenu
,
329 IN UINT16 UpdatePageId
332 EFI_DEVICE_PATH_PROTOCOL
*ConDevicePath
;
333 BM_MENU_ENTRY
*NewMenuEntry
;
334 BM_CONSOLE_CONTEXT
*NewConsoleContext
;
335 BM_TERMINAL_CONTEXT
*NewTerminalContext
;
337 VENDOR_DEVICE_PATH Vendor
;
338 EFI_DEVICE_PATH_PROTOCOL
*TerminalDevicePath
;
341 GetEfiGlobalVariable2 (ConsoleName
, (VOID
**)&ConDevicePath
, NULL
);
342 if (ConDevicePath
!= NULL
) {
343 EfiLibDeleteVariable (ConsoleName
, &gEfiGlobalVariableGuid
);
344 FreePool (ConDevicePath
);
345 ConDevicePath
= NULL
;
349 // First add all console input device from console input menu
351 for (Index
= 0; Index
< ConsoleMenu
->MenuNumber
; Index
++) {
352 NewMenuEntry
= BOpt_GetMenuEntry (ConsoleMenu
, Index
);
354 NewConsoleContext
= (BM_CONSOLE_CONTEXT
*) NewMenuEntry
->VariableContext
;
355 if (NewConsoleContext
->IsActive
) {
356 ConDevicePath
= AppendDevicePathInstance (
358 NewConsoleContext
->DevicePath
363 for (Index
= 0; Index
< TerminalMenu
.MenuNumber
; Index
++) {
364 NewMenuEntry
= BOpt_GetMenuEntry (&TerminalMenu
, Index
);
366 NewTerminalContext
= (BM_TERMINAL_CONTEXT
*) NewMenuEntry
->VariableContext
;
367 if (((NewTerminalContext
->IsConIn
!= 0) && (UpdatePageId
== FORM_CON_IN_ID
)) ||
368 ((NewTerminalContext
->IsConOut
!= 0) && (UpdatePageId
== FORM_CON_OUT_ID
)) ||
369 ((NewTerminalContext
->IsStdErr
!= 0) && (UpdatePageId
== FORM_CON_ERR_ID
))
371 Vendor
.Header
.Type
= MESSAGING_DEVICE_PATH
;
372 Vendor
.Header
.SubType
= MSG_VENDOR_DP
;
374 ASSERT (NewTerminalContext
->TerminalType
< (sizeof (TerminalTypeGuid
) / sizeof (TerminalTypeGuid
[0])));
377 &TerminalTypeGuid
[NewTerminalContext
->TerminalType
],
380 SetDevicePathNodeLength (&Vendor
.Header
, sizeof (VENDOR_DEVICE_PATH
));
381 TerminalDevicePath
= AppendDevicePathNode (
382 NewTerminalContext
->DevicePath
,
383 (EFI_DEVICE_PATH_PROTOCOL
*) &Vendor
385 ASSERT (TerminalDevicePath
!= NULL
);
386 ChangeTerminalDevicePath (TerminalDevicePath
, TRUE
);
387 ConDevicePath
= AppendDevicePathInstance (
394 if (ConDevicePath
!= NULL
) {
395 Status
= gRT
->SetVariable (
397 &gEfiGlobalVariableGuid
,
399 GetDevicePathSize (ConDevicePath
),
402 if (EFI_ERROR (Status
)) {
412 This function delete and build multi-instance device path ConIn
415 @retval EFI_SUCCESS The function complete successfully.
416 @return The EFI variable can not be saved. See gRT->SetVariable for detail return information.
419 Var_UpdateConsoleInpOption (
423 return Var_UpdateConsoleOption (L
"ConIn", &ConsoleInpMenu
, FORM_CON_IN_ID
);
427 This function delete and build multi-instance device path ConOut
430 @retval EFI_SUCCESS The function complete successfully.
431 @return The EFI variable can not be saved. See gRT->SetVariable for detail return information.
434 Var_UpdateConsoleOutOption (
438 return Var_UpdateConsoleOption (L
"ConOut", &ConsoleOutMenu
, FORM_CON_OUT_ID
);
442 This function delete and build multi-instance device path ErrOut
445 @retval EFI_SUCCESS The function complete successfully.
446 @return The EFI variable can not be saved. See gRT->SetVariable for detail return information.
449 Var_UpdateErrorOutOption (
453 return Var_UpdateConsoleOption (L
"ErrOut", &ConsoleErrMenu
, FORM_CON_ERR_ID
);
457 This function create a currently loaded Drive Option from
458 the BMM. It then appends this Driver Option to the end of
459 the "DriverOrder" list. It append this Driver Opotion to the end
462 @param CallbackData The BMM context data.
463 @param HiiHandle The HII handle associated with the BMM formset.
464 @param DescriptionData The description of this driver option.
465 @param OptionalData The optional load option.
466 @param ForceReconnect If to force reconnect.
468 @retval EFI_OUT_OF_RESOURCES If not enought memory to complete the operation.
469 @retval EFI_SUCCESS If function completes successfully.
473 Var_UpdateDriverOption (
474 IN BMM_CALLBACK_DATA
*CallbackData
,
475 IN EFI_HII_HANDLE HiiHandle
,
476 IN UINT16
*DescriptionData
,
477 IN UINT16
*OptionalData
,
478 IN UINT8 ForceReconnect
482 UINT16 DriverString
[12];
483 BM_MENU_ENTRY
*NewMenuEntry
;
484 BM_LOAD_CONTEXT
*NewLoadContext
;
485 BOOLEAN OptionalDataExist
;
487 EFI_BOOT_MANAGER_LOAD_OPTION LoadOption
;
488 UINT8
*OptionalDesData
;
489 UINT32 OptionalDataSize
;
491 OptionalDataExist
= FALSE
;
492 OptionalDesData
= NULL
;
493 OptionalDataSize
= 0;
495 Index
= BOpt_GetDriverOptionNumber ();
498 sizeof (DriverString
),
503 if (*DescriptionData
== 0x0000) {
504 StrCpyS (DescriptionData
, MAX_MENU_NUMBER
, DriverString
);
507 if (*OptionalData
!= 0x0000) {
508 OptionalDataExist
= TRUE
;
509 OptionalDesData
= (UINT8
*)OptionalData
;
510 OptionalDataSize
= (UINT32
)StrSize (OptionalData
);
513 NewMenuEntry
= BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT
);
514 if (NULL
== NewMenuEntry
) {
515 return EFI_OUT_OF_RESOURCES
;
518 Status
= EfiBootManagerInitializeLoadOption (
521 LoadOptionTypeDriver
,
522 LOAD_OPTION_ACTIVE
| (ForceReconnect
<< 1),
524 CallbackData
->LoadContext
->FilePathList
,
528 if (!EFI_ERROR (Status
)){
529 Status
= EfiBootManagerAddLoadOptionVariable (&LoadOption
,(UINTN
) -1 );
532 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
533 NewLoadContext
->Deleted
= FALSE
;
534 NewLoadContext
->Attributes
= LoadOption
.Attributes
;
535 NewLoadContext
->FilePathListLength
= (UINT16
)GetDevicePathSize (LoadOption
.FilePath
);
537 NewLoadContext
->Description
= AllocateZeroPool (StrSize (DescriptionData
));
538 ASSERT (NewLoadContext
->Description
!= NULL
);
539 NewMenuEntry
->DisplayString
= NewLoadContext
->Description
;
541 NewLoadContext
->Description
,
542 LoadOption
.Description
,
543 StrSize (DescriptionData
)
546 NewLoadContext
->FilePathList
= AllocateZeroPool (GetDevicePathSize (CallbackData
->LoadContext
->FilePathList
));
547 ASSERT (NewLoadContext
->FilePathList
!= NULL
);
549 NewLoadContext
->FilePathList
,
551 GetDevicePathSize (CallbackData
->LoadContext
->FilePathList
)
554 NewMenuEntry
->HelpString
= UiDevicePathToStr (NewLoadContext
->FilePathList
);
555 NewMenuEntry
->OptionNumber
= Index
;
556 NewMenuEntry
->DisplayStringToken
= HiiSetString (HiiHandle
, 0, NewMenuEntry
->DisplayString
, NULL
);
557 NewMenuEntry
->HelpStringToken
= HiiSetString (HiiHandle
, 0, NewMenuEntry
->HelpString
, NULL
);
559 if (OptionalDataExist
) {
560 NewLoadContext
->OptionalData
= AllocateZeroPool (LoadOption
.OptionalDataSize
);
561 ASSERT (NewLoadContext
->OptionalData
!= NULL
);
563 NewLoadContext
->OptionalData
,
564 LoadOption
.OptionalData
,
565 LoadOption
.OptionalDataSize
569 InsertTailList (&DriverOptionMenu
.Head
, &NewMenuEntry
->Link
);
570 DriverOptionMenu
.MenuNumber
++;
572 EfiBootManagerFreeLoadOption(&LoadOption
);
578 This function create a currently loaded Boot Option from
579 the BMM. It then appends this Boot Option to the end of
580 the "BootOrder" list. It also append this Boot Opotion to the end
583 @param CallbackData The BMM context data.
585 @retval EFI_OUT_OF_RESOURCES If not enought memory to complete the operation.
586 @retval EFI_SUCCESS If function completes successfully.
590 Var_UpdateBootOption (
591 IN BMM_CALLBACK_DATA
*CallbackData
594 UINT16 BootString
[10];
596 BM_MENU_ENTRY
*NewMenuEntry
;
597 BM_LOAD_CONTEXT
*NewLoadContext
;
598 BOOLEAN OptionalDataExist
;
600 BMM_FAKE_NV_DATA
*NvRamMap
;
601 EFI_BOOT_MANAGER_LOAD_OPTION LoadOption
;
603 UINT32 OptionalDataSize
;
605 OptionalDataExist
= FALSE
;
606 NvRamMap
= &CallbackData
->BmmFakeNvData
;
608 OptionalDataSize
= 0;
610 Index
= BOpt_GetBootOptionNumber () ;
611 UnicodeSPrint (BootString
, sizeof (BootString
), L
"Boot%04x", Index
);
613 if (NvRamMap
->BootDescriptionData
[0] == 0x0000) {
614 StrCpyS (NvRamMap
->BootDescriptionData
, sizeof (NvRamMap
->BootDescriptionData
) / sizeof (NvRamMap
->BootDescriptionData
[0]), BootString
);
617 if (NvRamMap
->BootOptionalData
[0] != 0x0000) {
618 OptionalDataExist
= TRUE
;
619 OptionalData
= (UINT8
*)NvRamMap
->BootOptionalData
;
620 OptionalDataSize
= (UINT32
)StrSize (NvRamMap
->BootOptionalData
);
623 NewMenuEntry
= BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT
);
624 if (NULL
== NewMenuEntry
) {
625 return EFI_OUT_OF_RESOURCES
;
628 Status
= EfiBootManagerInitializeLoadOption (
633 NvRamMap
->BootDescriptionData
,
634 CallbackData
->LoadContext
->FilePathList
,
638 if (!EFI_ERROR (Status
)){
639 Status
= EfiBootManagerAddLoadOptionVariable (&LoadOption
,(UINTN
) -1 );
642 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
643 NewLoadContext
->Deleted
= FALSE
;
644 NewLoadContext
->Attributes
= LoadOption
.Attributes
;
645 NewLoadContext
->FilePathListLength
= (UINT16
) GetDevicePathSize (LoadOption
.FilePath
);
647 NewLoadContext
->Description
= AllocateZeroPool (StrSize (NvRamMap
->BootDescriptionData
));
648 ASSERT (NewLoadContext
->Description
!= NULL
);
650 NewMenuEntry
->DisplayString
= NewLoadContext
->Description
;
653 NewLoadContext
->Description
,
654 LoadOption
.Description
,
655 StrSize (NvRamMap
->BootDescriptionData
)
658 NewLoadContext
->FilePathList
= AllocateZeroPool (GetDevicePathSize (CallbackData
->LoadContext
->FilePathList
));
659 ASSERT (NewLoadContext
->FilePathList
!= NULL
);
661 NewLoadContext
->FilePathList
,
663 GetDevicePathSize (CallbackData
->LoadContext
->FilePathList
)
666 NewMenuEntry
->HelpString
= UiDevicePathToStr (NewLoadContext
->FilePathList
);
667 NewMenuEntry
->OptionNumber
= Index
;
668 NewMenuEntry
->DisplayStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->DisplayString
, NULL
);
669 NewMenuEntry
->HelpStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->HelpString
, NULL
);
671 if (OptionalDataExist
) {
672 NewLoadContext
->OptionalData
= AllocateZeroPool (LoadOption
.OptionalDataSize
);
673 ASSERT (NewLoadContext
->OptionalData
!= NULL
);
675 NewLoadContext
->OptionalData
,
676 LoadOption
.OptionalData
,
677 LoadOption
.OptionalDataSize
681 InsertTailList (&BootOptionMenu
.Head
, &NewMenuEntry
->Link
);
682 BootOptionMenu
.MenuNumber
++;
684 EfiBootManagerFreeLoadOption(&LoadOption
);
690 This function update the "BootNext" EFI Variable. If there is
691 no "BootNext" specified in BMM, this EFI Variable is deleted.
692 It also update the BMM context data specified the "BootNext"
695 @param CallbackData The BMM context data.
697 @retval EFI_SUCCESS The function complete successfully.
698 @return The EFI variable can be saved. See gRT->SetVariable
699 for detail return information.
704 IN BMM_CALLBACK_DATA
*CallbackData
707 BM_MENU_ENTRY
*NewMenuEntry
;
708 BM_LOAD_CONTEXT
*NewLoadContext
;
709 BMM_FAKE_NV_DATA
*CurrentFakeNVMap
;
713 Status
= EFI_SUCCESS
;
714 CurrentFakeNVMap
= &CallbackData
->BmmFakeNvData
;
715 for (Index
= 0; Index
< BootOptionMenu
.MenuNumber
; Index
++) {
716 NewMenuEntry
= BOpt_GetMenuEntry (&BootOptionMenu
, Index
);
717 ASSERT (NULL
!= NewMenuEntry
);
719 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
720 NewLoadContext
->IsBootNext
= FALSE
;
723 if (CurrentFakeNVMap
->BootNext
== NONE_BOOTNEXT_VALUE
) {
724 EfiLibDeleteVariable (L
"BootNext", &gEfiGlobalVariableGuid
);
728 NewMenuEntry
= BOpt_GetMenuEntry (
730 CurrentFakeNVMap
->BootNext
732 ASSERT (NewMenuEntry
!= NULL
);
734 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
735 Status
= gRT
->SetVariable (
737 &gEfiGlobalVariableGuid
,
740 &NewMenuEntry
->OptionNumber
742 NewLoadContext
->IsBootNext
= TRUE
;
743 CallbackData
->BmmOldFakeNVData
.BootNext
= CurrentFakeNVMap
->BootNext
;
748 This function update the "BootOrder" EFI Variable based on
749 BMM Formset's NV map. It then refresh BootOptionMenu
750 with the new "BootOrder" list.
752 @param CallbackData The BMM context data.
754 @retval EFI_SUCCESS The function complete successfully.
755 @retval EFI_OUT_OF_RESOURCES Not enough memory to complete the function.
756 @return The EFI variable can not be saved. See gRT->SetVariable for detail return information.
760 Var_UpdateBootOrder (
761 IN BMM_CALLBACK_DATA
*CallbackData
772 // First check whether BootOrder is present in current configuration
774 GetEfiGlobalVariable2 (L
"BootOrder", (VOID
**) &BootOrder
, &BootOrderSize
);
775 if (BootOrder
== NULL
) {
776 return EFI_OUT_OF_RESOURCES
;
779 ASSERT (BootOptionMenu
.MenuNumber
<= (sizeof (CallbackData
->BmmFakeNvData
.BootOptionOrder
) / sizeof (CallbackData
->BmmFakeNvData
.BootOptionOrder
[0])));
782 // OptionOrder is subset of BootOrder
784 for (OrderIndex
= 0; (OrderIndex
< BootOptionMenu
.MenuNumber
) && (CallbackData
->BmmFakeNvData
.BootOptionOrder
[OrderIndex
] != 0); OrderIndex
++) {
785 for (Index
= OrderIndex
; Index
< BootOrderSize
/ sizeof (UINT16
); Index
++) {
786 if ((BootOrder
[Index
] == (UINT16
) (CallbackData
->BmmFakeNvData
.BootOptionOrder
[OrderIndex
] - 1)) && (OrderIndex
!= Index
)) {
787 OptionNumber
= BootOrder
[Index
];
788 CopyMem (&BootOrder
[OrderIndex
+ 1], &BootOrder
[OrderIndex
], (Index
- OrderIndex
) * sizeof (UINT16
));
789 BootOrder
[OrderIndex
] = OptionNumber
;
794 Status
= gRT
->SetVariable (
796 &gEfiGlobalVariableGuid
,
801 FreePool (BootOrder
);
803 BOpt_FreeMenu (&BootOptionMenu
);
804 BOpt_GetBootOptions (CallbackData
);
811 This function update the "DriverOrder" EFI Variable based on
812 BMM Formset's NV map. It then refresh DriverOptionMenu
813 with the new "DriverOrder" list.
815 @param CallbackData The BMM context data.
817 @retval EFI_SUCCESS The function complete successfully.
818 @retval EFI_OUT_OF_RESOURCES Not enough memory to complete the function.
819 @return The EFI variable can not be saved. See gRT->SetVariable for detail return information.
823 Var_UpdateDriverOrder (
824 IN BMM_CALLBACK_DATA
*CallbackData
829 UINT16
*DriverOrderList
;
830 UINT16
*NewDriverOrderList
;
831 UINTN DriverOrderListSize
;
833 DriverOrderList
= NULL
;
834 DriverOrderListSize
= 0;
837 // First check whether DriverOrder is present in current configuration
839 GetEfiGlobalVariable2 (L
"DriverOrder", (VOID
**) &DriverOrderList
, &DriverOrderListSize
);
840 NewDriverOrderList
= AllocateZeroPool (DriverOrderListSize
);
842 if (NewDriverOrderList
== NULL
) {
843 return EFI_OUT_OF_RESOURCES
;
846 // If exists, delete it to hold new DriverOrder
848 if (DriverOrderList
!= NULL
) {
849 EfiLibDeleteVariable (L
"DriverOrder", &gEfiGlobalVariableGuid
);
850 FreePool (DriverOrderList
);
853 ASSERT (DriverOptionMenu
.MenuNumber
<= (sizeof (CallbackData
->BmmFakeNvData
.DriverOptionOrder
) / sizeof (CallbackData
->BmmFakeNvData
.DriverOptionOrder
[0])));
854 for (Index
= 0; Index
< DriverOptionMenu
.MenuNumber
; Index
++) {
855 NewDriverOrderList
[Index
] = (UINT16
) (CallbackData
->BmmFakeNvData
.DriverOptionOrder
[Index
] - 1);
858 Status
= gRT
->SetVariable (
860 &gEfiGlobalVariableGuid
,
865 if (EFI_ERROR (Status
)) {
869 BOpt_FreeMenu (&DriverOptionMenu
);
870 BOpt_GetDriverOptions (CallbackData
);
875 Update the Text Mode of Console.
877 @param CallbackData The context data for BMM.
879 @retval EFI_SUCCSS If the Text Mode of Console is updated.
880 @return Other value if the Text Mode of Console is not updated.
885 IN BMM_CALLBACK_DATA
*CallbackData
890 CONSOLE_OUT_MODE ModeInfo
;
892 Mode
= CallbackData
->BmmFakeNvData
.ConsoleOutMode
;
894 Status
= gST
->ConOut
->QueryMode (gST
->ConOut
, Mode
, &(ModeInfo
.Column
), &(ModeInfo
.Row
));
895 if (!EFI_ERROR(Status
)) {
896 Status
= PcdSet32S (PcdSetupConOutColumn
, (UINT32
) ModeInfo
.Column
);
897 if (!EFI_ERROR (Status
)) {
898 Status
= PcdSet32S (PcdSetupConOutRow
, (UINT32
) ModeInfo
.Row
);