2 Provide boot option support for Application "BootMaint"
4 Include file system navigation, system handle selection
6 Boot option manipulation
8 Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
9 This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include "BootMaintenanceManager.h"
22 /// Define the maximum characters that will be accepted.
28 Check whether a reset is needed, if reset is needed, Popup a menu to notice user.
32 BmmSetupResetReminder (
37 CHAR16
*StringBuffer1
;
38 CHAR16
*StringBuffer2
;
40 EDKII_FORM_BROWSER_EXTENSION2_PROTOCOL
*FormBrowserEx2
;
43 // Use BrowserEx2 protocol to check whether reset is required.
45 Status
= gBS
->LocateProtocol (&gEdkiiFormBrowserEx2ProtocolGuid
, NULL
, (VOID
**) &FormBrowserEx2
);
48 //check any reset required change is applied? if yes, reset system
50 if (!EFI_ERROR(Status
) && FormBrowserEx2
->IsResetRequired()) {
51 StringBuffer1
= AllocateZeroPool (MAX_CHAR
* sizeof (CHAR16
));
52 ASSERT (StringBuffer1
!= NULL
);
53 StringBuffer2
= AllocateZeroPool (MAX_CHAR
* sizeof (CHAR16
));
54 ASSERT (StringBuffer2
!= NULL
);
55 StrCpyS (StringBuffer1
, MAX_CHAR
, L
"Configuration changed. Reset to apply it Now.");
56 StrCpyS (StringBuffer2
, MAX_CHAR
, L
"Press ENTER to reset");
58 // Popup a menu to notice user
61 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, StringBuffer1
, StringBuffer2
, NULL
);
62 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
64 FreePool (StringBuffer1
);
65 FreePool (StringBuffer2
);
67 gRT
->ResetSystem (EfiResetCold
, EFI_SUCCESS
, 0, NULL
);
72 Create a menu entry by given menu type.
74 @param MenuType The Menu type to be created.
76 @retval NULL If failed to create the menu.
77 @return the new menu entry.
81 BOpt_CreateMenuEntry (
85 BM_MENU_ENTRY
*MenuEntry
;
89 // Get context size according to menu type
92 case BM_LOAD_CONTEXT_SELECT
:
93 ContextSize
= sizeof (BM_LOAD_CONTEXT
);
96 case BM_FILE_CONTEXT_SELECT
:
97 ContextSize
= sizeof (BM_FILE_CONTEXT
);
100 case BM_CONSOLE_CONTEXT_SELECT
:
101 ContextSize
= sizeof (BM_CONSOLE_CONTEXT
);
104 case BM_TERMINAL_CONTEXT_SELECT
:
105 ContextSize
= sizeof (BM_TERMINAL_CONTEXT
);
108 case BM_HANDLE_CONTEXT_SELECT
:
109 ContextSize
= sizeof (BM_HANDLE_CONTEXT
);
117 if (ContextSize
== 0) {
122 // Create new menu entry
124 MenuEntry
= AllocateZeroPool (sizeof (BM_MENU_ENTRY
));
125 if (MenuEntry
== NULL
) {
129 MenuEntry
->VariableContext
= AllocateZeroPool (ContextSize
);
130 if (MenuEntry
->VariableContext
== NULL
) {
131 FreePool (MenuEntry
);
135 MenuEntry
->Signature
= BM_MENU_ENTRY_SIGNATURE
;
136 MenuEntry
->ContextSelection
= MenuType
;
141 Free up all resource allocated for a BM_MENU_ENTRY.
143 @param MenuEntry A pointer to BM_MENU_ENTRY.
147 BOpt_DestroyMenuEntry (
148 BM_MENU_ENTRY
*MenuEntry
151 BM_LOAD_CONTEXT
*LoadContext
;
152 BM_FILE_CONTEXT
*FileContext
;
153 BM_CONSOLE_CONTEXT
*ConsoleContext
;
154 BM_TERMINAL_CONTEXT
*TerminalContext
;
155 BM_HANDLE_CONTEXT
*HandleContext
;
158 // Select by the type in Menu entry for current context type
160 switch (MenuEntry
->ContextSelection
) {
161 case BM_LOAD_CONTEXT_SELECT
:
162 LoadContext
= (BM_LOAD_CONTEXT
*) MenuEntry
->VariableContext
;
163 FreePool (LoadContext
->FilePathList
);
164 if (LoadContext
->OptionalData
!= NULL
) {
165 FreePool (LoadContext
->OptionalData
);
167 FreePool (LoadContext
);
170 case BM_FILE_CONTEXT_SELECT
:
171 FileContext
= (BM_FILE_CONTEXT
*) MenuEntry
->VariableContext
;
173 if (!FileContext
->IsRoot
) {
174 FreePool (FileContext
->DevicePath
);
176 if (FileContext
->FHandle
!= NULL
) {
177 FileContext
->FHandle
->Close (FileContext
->FHandle
);
181 if (FileContext
->FileName
!= NULL
) {
182 FreePool (FileContext
->FileName
);
184 if (FileContext
->Info
!= NULL
) {
185 FreePool (FileContext
->Info
);
187 FreePool (FileContext
);
190 case BM_CONSOLE_CONTEXT_SELECT
:
191 ConsoleContext
= (BM_CONSOLE_CONTEXT
*) MenuEntry
->VariableContext
;
192 FreePool (ConsoleContext
->DevicePath
);
193 FreePool (ConsoleContext
);
196 case BM_TERMINAL_CONTEXT_SELECT
:
197 TerminalContext
= (BM_TERMINAL_CONTEXT
*) MenuEntry
->VariableContext
;
198 FreePool (TerminalContext
->DevicePath
);
199 FreePool (TerminalContext
);
202 case BM_HANDLE_CONTEXT_SELECT
:
203 HandleContext
= (BM_HANDLE_CONTEXT
*) MenuEntry
->VariableContext
;
204 FreePool (HandleContext
);
211 FreePool (MenuEntry
->DisplayString
);
212 if (MenuEntry
->HelpString
!= NULL
) {
213 FreePool (MenuEntry
->HelpString
);
216 FreePool (MenuEntry
);
220 Get the Menu Entry from the list in Menu Entry List.
222 If MenuNumber is great or equal to the number of Menu
223 Entry in the list, then ASSERT.
225 @param MenuOption The Menu Entry List to read the menu entry.
226 @param MenuNumber The index of Menu Entry.
228 @return The Menu Entry.
233 BM_MENU_OPTION
*MenuOption
,
237 BM_MENU_ENTRY
*NewMenuEntry
;
241 ASSERT (MenuNumber
< MenuOption
->MenuNumber
);
243 List
= MenuOption
->Head
.ForwardLink
;
244 for (Index
= 0; Index
< MenuNumber
; Index
++) {
245 List
= List
->ForwardLink
;
248 NewMenuEntry
= CR (List
, BM_MENU_ENTRY
, Link
, BM_MENU_ENTRY_SIGNATURE
);
254 Free resources allocated in Allocate Rountine.
256 @param FreeMenu Menu to be freed
260 BM_MENU_OPTION
*FreeMenu
263 BM_MENU_ENTRY
*MenuEntry
;
264 while (!IsListEmpty (&FreeMenu
->Head
)) {
266 FreeMenu
->Head
.ForwardLink
,
269 BM_MENU_ENTRY_SIGNATURE
271 RemoveEntryList (&MenuEntry
->Link
);
272 BOpt_DestroyMenuEntry (MenuEntry
);
274 FreeMenu
->MenuNumber
= 0;
279 Build the BootOptionMenu according to BootOrder Variable.
280 This Routine will access the Boot#### to get EFI_LOAD_OPTION.
282 @param CallbackData The BMM context data.
284 @return EFI_NOT_FOUND Fail to find "BootOrder" variable.
285 @return EFI_SUCESS Success build boot option menu.
289 BOpt_GetBootOptions (
290 IN BMM_CALLBACK_DATA
*CallbackData
294 UINT16 BootString
[10];
295 UINT8
*LoadOptionFromVar
;
296 UINTN BootOptionSize
;
297 BOOLEAN BootNextFlag
;
298 UINT16
*BootOrderList
;
299 UINTN BootOrderListSize
;
302 BM_MENU_ENTRY
*NewMenuEntry
;
303 BM_LOAD_CONTEXT
*NewLoadContext
;
304 UINT8
*LoadOptionPtr
;
306 UINTN OptionalDataSize
;
307 UINT8
*LoadOptionEnd
;
308 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
311 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
;
312 UINTN BootOptionCount
;
315 BootOrderListSize
= 0;
317 BootOrderList
= NULL
;
319 LoadOptionFromVar
= NULL
;
320 BOpt_FreeMenu (&BootOptionMenu
);
321 InitializeListHead (&BootOptionMenu
.Head
);
324 // Get the BootOrder from the Var
326 GetEfiGlobalVariable2 (L
"BootOrder", (VOID
**) &BootOrderList
, &BootOrderListSize
);
327 if (BootOrderList
== NULL
) {
328 return EFI_NOT_FOUND
;
332 // Get the BootNext from the Var
334 GetEfiGlobalVariable2 (L
"BootNext", (VOID
**) &BootNext
, &BootNextSize
);
335 if (BootNext
!= NULL
) {
336 if (BootNextSize
!= sizeof (UINT16
)) {
341 BootOption
= EfiBootManagerGetLoadOptions (&BootOptionCount
, LoadOptionTypeBoot
);
342 for (Index
= 0; Index
< BootOrderListSize
/ sizeof (UINT16
); Index
++) {
344 // Don't display the hidden/inactive boot option
346 if (((BootOption
[Index
].Attributes
& LOAD_OPTION_HIDDEN
) != 0) || ((BootOption
[Index
].Attributes
& LOAD_OPTION_ACTIVE
) == 0)) {
350 UnicodeSPrint (BootString
, sizeof (BootString
), L
"Boot%04x", BootOrderList
[Index
]);
352 // Get all loadoptions from the VAR
354 GetEfiGlobalVariable2 (BootString
, (VOID
**) &LoadOptionFromVar
, &BootOptionSize
);
355 if (LoadOptionFromVar
== NULL
) {
359 if (BootNext
!= NULL
) {
360 BootNextFlag
= (BOOLEAN
) (*BootNext
== BootOrderList
[Index
]);
362 BootNextFlag
= FALSE
;
365 NewMenuEntry
= BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT
);
366 ASSERT (NULL
!= NewMenuEntry
);
368 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
370 LoadOptionPtr
= LoadOptionFromVar
;
371 LoadOptionEnd
= LoadOptionFromVar
+ BootOptionSize
;
373 NewMenuEntry
->OptionNumber
= BootOrderList
[Index
];
374 NewLoadContext
->Deleted
= FALSE
;
375 NewLoadContext
->IsBootNext
= BootNextFlag
;
378 // Is a Legacy Device?
380 Ptr
= (UINT8
*) LoadOptionFromVar
;
383 // Attribute = *(UINT32 *)Ptr;
385 Ptr
+= sizeof (UINT32
);
388 // FilePathSize = *(UINT16 *)Ptr;
390 Ptr
+= sizeof (UINT16
);
393 // Description = (CHAR16 *)Ptr;
395 Ptr
+= StrSize ((CHAR16
*) Ptr
);
398 // Now Ptr point to Device Path
400 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) Ptr
;
401 if ((BBS_DEVICE_PATH
== DevicePath
->Type
) && (BBS_BBS_DP
== DevicePath
->SubType
)) {
402 NewLoadContext
->IsLegacy
= TRUE
;
404 NewLoadContext
->IsLegacy
= FALSE
;
407 // LoadOption is a pointer type of UINT8
408 // for easy use with following LOAD_OPTION
409 // embedded in this struct
412 NewLoadContext
->Attributes
= *(UINT32
*) LoadOptionPtr
;
414 LoadOptionPtr
+= sizeof (UINT32
);
416 NewLoadContext
->FilePathListLength
= *(UINT16
*) LoadOptionPtr
;
417 LoadOptionPtr
+= sizeof (UINT16
);
419 StringSize
= StrSize((UINT16
*)LoadOptionPtr
);
421 NewLoadContext
->Description
= AllocateZeroPool (StrSize((UINT16
*)LoadOptionPtr
));
422 ASSERT (NewLoadContext
->Description
!= NULL
);
423 StrCpyS (NewLoadContext
->Description
, StrSize((UINT16
*)LoadOptionPtr
) / sizeof (UINT16
), (UINT16
*)LoadOptionPtr
);
425 ASSERT (NewLoadContext
->Description
!= NULL
);
426 NewMenuEntry
->DisplayString
= NewLoadContext
->Description
;
427 NewMenuEntry
->DisplayStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->DisplayString
, NULL
);
429 LoadOptionPtr
+= StringSize
;
431 NewLoadContext
->FilePathList
= AllocateZeroPool (NewLoadContext
->FilePathListLength
);
432 ASSERT (NewLoadContext
->FilePathList
!= NULL
);
434 NewLoadContext
->FilePathList
,
435 (EFI_DEVICE_PATH_PROTOCOL
*) LoadOptionPtr
,
436 NewLoadContext
->FilePathListLength
439 NewMenuEntry
->HelpString
= UiDevicePathToStr (NewLoadContext
->FilePathList
);
440 NewMenuEntry
->HelpStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->HelpString
, NULL
);
442 LoadOptionPtr
+= NewLoadContext
->FilePathListLength
;
444 if (LoadOptionPtr
< LoadOptionEnd
) {
445 OptionalDataSize
= BootOptionSize
-
449 NewLoadContext
->FilePathListLength
;
451 NewLoadContext
->OptionalData
= AllocateZeroPool (OptionalDataSize
);
452 ASSERT (NewLoadContext
->OptionalData
!= NULL
);
454 NewLoadContext
->OptionalData
,
460 InsertTailList (&BootOptionMenu
.Head
, &NewMenuEntry
->Link
);
462 FreePool (LoadOptionFromVar
);
464 EfiBootManagerFreeLoadOptions (BootOption
, BootOptionCount
);
466 if (BootNext
!= NULL
) {
469 if (BootOrderList
!= NULL
) {
470 FreePool (BootOrderList
);
473 BootOptionMenu
.MenuNumber
= MenuCount
;
479 Find drivers that will be added as Driver#### variables from handles
480 in current system environment
481 All valid handles in the system except those consume SimpleFs, LoadFile
482 are stored in DriverMenu for future use.
484 @retval EFI_SUCCESS The function complets successfully.
485 @return Other value if failed to build the DriverMenu.
493 UINTN NoDevicePathHandles
;
494 EFI_HANDLE
*DevicePathHandle
;
497 BM_MENU_ENTRY
*NewMenuEntry
;
498 BM_HANDLE_CONTEXT
*NewHandleContext
;
499 EFI_HANDLE CurHandle
;
501 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*SimpleFs
;
502 EFI_LOAD_FILE_PROTOCOL
*LoadFile
;
507 InitializeListHead (&DriverMenu
.Head
);
510 // At first, get all handles that support Device Path
511 // protocol which is the basic requirement for
514 Status
= gBS
->LocateHandleBuffer (
516 &gEfiDevicePathProtocolGuid
,
518 &NoDevicePathHandles
,
521 if (EFI_ERROR (Status
)) {
526 for (Index
= 0; Index
< NoDevicePathHandles
; Index
++) {
527 CurHandle
= DevicePathHandle
[Index
];
529 Status
= gBS
->HandleProtocol (
531 &gEfiSimpleFileSystemProtocolGuid
,
534 if (Status
== EFI_SUCCESS
) {
538 Status
= gBS
->HandleProtocol (
540 &gEfiLoadFileProtocolGuid
,
543 if (Status
== EFI_SUCCESS
) {
547 NewMenuEntry
= BOpt_CreateMenuEntry (BM_HANDLE_CONTEXT_SELECT
);
548 if (NULL
== NewMenuEntry
) {
549 FreePool (DevicePathHandle
);
550 return EFI_OUT_OF_RESOURCES
;
553 NewHandleContext
= (BM_HANDLE_CONTEXT
*) NewMenuEntry
->VariableContext
;
554 NewHandleContext
->Handle
= CurHandle
;
555 NewHandleContext
->DevicePath
= DevicePathFromHandle (CurHandle
);
556 NewMenuEntry
->DisplayString
= UiDevicePathToStr (NewHandleContext
->DevicePath
);
557 NewMenuEntry
->DisplayStringToken
= HiiSetString (mBmmCallbackInfo
->BmmHiiHandle
,0,NewMenuEntry
->DisplayString
,NULL
);
558 NewMenuEntry
->HelpString
= NULL
;
559 NewMenuEntry
->HelpStringToken
= NewMenuEntry
->DisplayStringToken
;
560 NewMenuEntry
->OptionNumber
= OptionNumber
;
562 InsertTailList (&DriverMenu
.Head
, &NewMenuEntry
->Link
);
566 if (DevicePathHandle
!= NULL
) {
567 FreePool (DevicePathHandle
);
570 DriverMenu
.MenuNumber
= OptionNumber
;
576 Get the Option Number that has not been allocated for use.
578 @param Type The type of Option.
580 @return The available Option Number.
584 BOpt_GetOptionNumber (
592 UINT16
*OptionBuffer
;
601 UnicodeSPrint (StrTemp
, sizeof (StrTemp
), L
"%sOrder", Type
);
603 GetEfiGlobalVariable2 (StrTemp
, (VOID
**) &OrderList
, &OrderListSize
);
604 for (OptionNumber
= 0; ; OptionNumber
++) {
605 if (OrderList
!= NULL
) {
606 for (Index
= 0; Index
< OrderListSize
/ sizeof (UINT16
); Index
++) {
607 if (OptionNumber
== OrderList
[Index
]) {
613 if (Index
< OrderListSize
/ sizeof (UINT16
)) {
615 // The OptionNumber occurs in the OrderList, continue to use next one
619 UnicodeSPrint (StrTemp
, sizeof (StrTemp
), L
"%s%04x", Type
, (UINTN
) OptionNumber
);
620 DEBUG((EFI_D_ERROR
,"Option = %s\n", StrTemp
));
621 GetEfiGlobalVariable2 (StrTemp
, (VOID
**) &OptionBuffer
, &OptionSize
);
622 if (NULL
== OptionBuffer
) {
624 // The Boot[OptionNumber] / Driver[OptionNumber] NOT occurs, we found it
635 Get the Option Number for Boot#### that does not used.
637 @return The available Option Number.
641 BOpt_GetBootOptionNumber (
645 return BOpt_GetOptionNumber (L
"Boot");
650 Get the Option Number for Driver#### that does not used.
652 @return The unused Option Number.
656 BOpt_GetDriverOptionNumber (
660 return BOpt_GetOptionNumber (L
"Driver");
665 Build up all DriverOptionMenu
667 @param CallbackData The BMM context data.
669 @retval EFI_SUCESS The functin completes successfully.
670 @retval EFI_OUT_OF_RESOURCES Not enough memory to compete the operation.
671 @retval EFI_NOT_FOUND Fail to get "DriverOrder" variable.
675 BOpt_GetDriverOptions (
676 IN BMM_CALLBACK_DATA
*CallbackData
680 UINT16 DriverString
[12];
681 UINT8
*LoadOptionFromVar
;
682 UINTN DriverOptionSize
;
684 UINT16
*DriverOrderList
;
685 UINTN DriverOrderListSize
;
686 BM_MENU_ENTRY
*NewMenuEntry
;
687 BM_LOAD_CONTEXT
*NewLoadContext
;
688 UINT8
*LoadOptionPtr
;
690 UINTN OptionalDataSize
;
691 UINT8
*LoadOptionEnd
;
693 DriverOrderListSize
= 0;
694 DriverOrderList
= NULL
;
695 DriverOptionSize
= 0;
696 LoadOptionFromVar
= NULL
;
697 BOpt_FreeMenu (&DriverOptionMenu
);
698 InitializeListHead (&DriverOptionMenu
.Head
);
700 // Get the DriverOrder from the Var
702 GetEfiGlobalVariable2 (L
"DriverOrder", (VOID
**) &DriverOrderList
, &DriverOrderListSize
);
703 if (DriverOrderList
== NULL
) {
704 return EFI_NOT_FOUND
;
707 for (Index
= 0; Index
< DriverOrderListSize
/ sizeof (UINT16
); Index
++) {
710 sizeof (DriverString
),
712 DriverOrderList
[Index
]
715 // Get all loadoptions from the VAR
717 GetEfiGlobalVariable2 (DriverString
, (VOID
**) &LoadOptionFromVar
, &DriverOptionSize
);
718 if (LoadOptionFromVar
== NULL
) {
723 NewMenuEntry
= BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT
);
724 if (NULL
== NewMenuEntry
) {
725 return EFI_OUT_OF_RESOURCES
;
728 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
729 LoadOptionPtr
= LoadOptionFromVar
;
730 LoadOptionEnd
= LoadOptionFromVar
+ DriverOptionSize
;
731 NewMenuEntry
->OptionNumber
= DriverOrderList
[Index
];
732 NewLoadContext
->Deleted
= FALSE
;
733 NewLoadContext
->IsLegacy
= FALSE
;
736 // LoadOption is a pointer type of UINT8
737 // for easy use with following LOAD_OPTION
738 // embedded in this struct
741 NewLoadContext
->Attributes
= *(UINT32
*) LoadOptionPtr
;
743 LoadOptionPtr
+= sizeof (UINT32
);
745 NewLoadContext
->FilePathListLength
= *(UINT16
*) LoadOptionPtr
;
746 LoadOptionPtr
+= sizeof (UINT16
);
748 StringSize
= StrSize ((UINT16
*) LoadOptionPtr
);
749 NewLoadContext
->Description
= AllocateZeroPool (StringSize
);
750 ASSERT (NewLoadContext
->Description
!= NULL
);
752 NewLoadContext
->Description
,
753 (UINT16
*) LoadOptionPtr
,
756 NewMenuEntry
->DisplayString
= NewLoadContext
->Description
;
757 NewMenuEntry
->DisplayStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->DisplayString
, NULL
);
759 LoadOptionPtr
+= StringSize
;
761 NewLoadContext
->FilePathList
= AllocateZeroPool (NewLoadContext
->FilePathListLength
);
762 ASSERT (NewLoadContext
->FilePathList
!= NULL
);
764 NewLoadContext
->FilePathList
,
765 (EFI_DEVICE_PATH_PROTOCOL
*) LoadOptionPtr
,
766 NewLoadContext
->FilePathListLength
769 NewMenuEntry
->HelpString
= UiDevicePathToStr (NewLoadContext
->FilePathList
);
770 NewMenuEntry
->HelpStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->HelpString
, NULL
);
772 LoadOptionPtr
+= NewLoadContext
->FilePathListLength
;
774 if (LoadOptionPtr
< LoadOptionEnd
) {
775 OptionalDataSize
= DriverOptionSize
-
779 NewLoadContext
->FilePathListLength
;
781 NewLoadContext
->OptionalData
= AllocateZeroPool (OptionalDataSize
);
782 ASSERT (NewLoadContext
->OptionalData
!= NULL
);
784 NewLoadContext
->OptionalData
,
791 InsertTailList (&DriverOptionMenu
.Head
, &NewMenuEntry
->Link
);
792 FreePool (LoadOptionFromVar
);
796 if (DriverOrderList
!= NULL
) {
797 FreePool (DriverOrderList
);
800 DriverOptionMenu
.MenuNumber
= Index
;
806 Get option number according to Boot#### and BootOrder variable.
807 The value is saved as #### + 1.
809 @param CallbackData The BMM context data.
813 IN BMM_CALLBACK_DATA
*CallbackData
816 BMM_FAKE_NV_DATA
*BmmConfig
;
818 UINT16 OptionOrderIndex
;
820 BM_MENU_ENTRY
*NewMenuEntry
;
821 BM_LOAD_CONTEXT
*NewLoadContext
;
823 ASSERT (CallbackData
!= NULL
);
825 DeviceType
= (UINTN
) -1;
826 BmmConfig
= &CallbackData
->BmmFakeNvData
;
827 ZeroMem (BmmConfig
->BootOptionOrder
, sizeof (BmmConfig
->BootOptionOrder
));
829 for (Index
= 0, OptionOrderIndex
= 0; ((Index
< BootOptionMenu
.MenuNumber
) &&
830 (OptionOrderIndex
< (sizeof (BmmConfig
->BootOptionOrder
) / sizeof (BmmConfig
->BootOptionOrder
[0]))));
832 NewMenuEntry
= BOpt_GetMenuEntry (&BootOptionMenu
, Index
);
833 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
835 if (NewLoadContext
->IsLegacy
) {
836 if (((BBS_BBS_DEVICE_PATH
*) NewLoadContext
->FilePathList
)->DeviceType
!= DeviceType
) {
837 DeviceType
= ((BBS_BBS_DEVICE_PATH
*) NewLoadContext
->FilePathList
)->DeviceType
;
840 // Only show one legacy boot option for the same device type
841 // assuming the boot options are grouped by the device type
846 BmmConfig
->BootOptionOrder
[OptionOrderIndex
++] = (UINT32
) (NewMenuEntry
->OptionNumber
+ 1);
851 Get driver option order from globalc DriverOptionMenu.
853 @param CallbackData The BMM context data.
858 IN BMM_CALLBACK_DATA
*CallbackData
861 BMM_FAKE_NV_DATA
*BmmConfig
;
863 UINT16 OptionOrderIndex
;
865 BM_MENU_ENTRY
*NewMenuEntry
;
866 BM_LOAD_CONTEXT
*NewLoadContext
;
869 ASSERT (CallbackData
!= NULL
);
871 DeviceType
= (UINTN
) -1;
872 BmmConfig
= &CallbackData
->BmmFakeNvData
;
873 ZeroMem (BmmConfig
->DriverOptionOrder
, sizeof (BmmConfig
->DriverOptionOrder
));
875 for (Index
= 0, OptionOrderIndex
= 0; ((Index
< DriverOptionMenu
.MenuNumber
) &&
876 (OptionOrderIndex
< (sizeof (BmmConfig
->DriverOptionOrder
) / sizeof (BmmConfig
->DriverOptionOrder
[0]))));
878 NewMenuEntry
= BOpt_GetMenuEntry (&DriverOptionMenu
, Index
);
879 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
881 if (NewLoadContext
->IsLegacy
) {
882 if (((BBS_BBS_DEVICE_PATH
*) NewLoadContext
->FilePathList
)->DeviceType
!= DeviceType
) {
883 DeviceType
= ((BBS_BBS_DEVICE_PATH
*) NewLoadContext
->FilePathList
)->DeviceType
;
886 // Only show one legacy boot option for the same device type
887 // assuming the boot options are grouped by the device type
892 BmmConfig
->DriverOptionOrder
[OptionOrderIndex
++] = (UINT32
) (NewMenuEntry
->OptionNumber
+ 1);
897 Boot the file specified by the input file path info.
899 @param FilePath Point to the file path.
901 @retval TRUE Exit caller function.
902 @retval FALSE Not exit caller function.
907 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
910 EFI_BOOT_MANAGER_LOAD_OPTION BootOption
;
915 FileName
= ExtractFileNameFromDevicePath(FilePath
);
916 if (FileName
!= NULL
) {
917 EfiBootManagerInitializeLoadOption (
928 // Since current no boot from removable media directly is allowed */
930 gST
->ConOut
->ClearScreen (gST
->ConOut
);
932 // Check whether need to reset system.
934 BmmSetupResetReminder ();
936 BmmSetConsoleMode (FALSE
);
937 EfiBootManagerBoot (&BootOption
);
938 BmmSetConsoleMode (TRUE
);
942 EfiBootManagerFreeLoadOption (&BootOption
);
949 Display the form base on the selected file.
951 @param FilePath Point to the file path.
952 @param FormId The form need to display.
957 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
958 IN EFI_FORM_ID FormId
961 gBootMaintenancePrivate
.LoadContext
->FilePathList
= FilePath
;
963 UpdateOptionPage(&gBootMaintenancePrivate
, FormId
, FilePath
);
965 gBootMaintenancePrivate
.FormBrowser2
->SendForm (
966 gBootMaintenancePrivate
.FormBrowser2
,
967 &gBootMaintenancePrivate
.BmmHiiHandle
,
978 Create boot option base on the input file path info.
980 @param FilePath Point to the file path.
982 @retval TRUE Exit caller function.
983 @retval FALSE Not exit caller function.
987 CreateBootOptionFromFile (
988 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
991 return ReSendForm(FilePath
, FORM_BOOT_ADD_ID
);
995 Create driver option base on the input file path info.
997 @param FilePath Point to the file path.
999 @retval TRUE Exit caller function.
1000 @retval FALSE Not exit caller function.
1005 CreateDriverOptionFromFile (
1006 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
1009 return ReSendForm(FilePath
, FORM_DRV_ADD_FILE_ID
);