2 Provide boot option support for Application "BootMaint"
4 Include file system navigation, system handle selection
6 Boot option manipulation
8 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
9 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include "BootMaintenanceManager.h"
16 /// Define the maximum characters that will be accepted.
22 Check whether a reset is needed, if reset is needed, Popup a menu to notice user.
26 BmmSetupResetReminder (
31 CHAR16
*StringBuffer1
;
32 CHAR16
*StringBuffer2
;
34 EDKII_FORM_BROWSER_EXTENSION2_PROTOCOL
*FormBrowserEx2
;
37 // Use BrowserEx2 protocol to check whether reset is required.
39 Status
= gBS
->LocateProtocol (&gEdkiiFormBrowserEx2ProtocolGuid
, NULL
, (VOID
**)&FormBrowserEx2
);
42 // check any reset required change is applied? if yes, reset system
44 if (!EFI_ERROR (Status
) && FormBrowserEx2
->IsResetRequired ()) {
45 StringBuffer1
= AllocateZeroPool (MAX_CHAR
* sizeof (CHAR16
));
46 ASSERT (StringBuffer1
!= NULL
);
47 StringBuffer2
= AllocateZeroPool (MAX_CHAR
* sizeof (CHAR16
));
48 ASSERT (StringBuffer2
!= NULL
);
49 StrCpyS (StringBuffer1
, MAX_CHAR
, L
"Configuration changed. Reset to apply it Now.");
50 StrCpyS (StringBuffer2
, MAX_CHAR
, L
"Press ENTER to reset");
52 // Popup a menu to notice user
55 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, StringBuffer1
, StringBuffer2
, NULL
);
56 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
58 FreePool (StringBuffer1
);
59 FreePool (StringBuffer2
);
61 gRT
->ResetSystem (EfiResetCold
, EFI_SUCCESS
, 0, NULL
);
66 Create a menu entry by given menu type.
68 @param MenuType The Menu type to be created.
70 @retval NULL If failed to create the menu.
71 @return the new menu entry.
75 BOpt_CreateMenuEntry (
79 BM_MENU_ENTRY
*MenuEntry
;
83 // Get context size according to menu type
86 case BM_LOAD_CONTEXT_SELECT
:
87 ContextSize
= sizeof (BM_LOAD_CONTEXT
);
90 case BM_FILE_CONTEXT_SELECT
:
91 ContextSize
= sizeof (BM_FILE_CONTEXT
);
94 case BM_CONSOLE_CONTEXT_SELECT
:
95 ContextSize
= sizeof (BM_CONSOLE_CONTEXT
);
98 case BM_TERMINAL_CONTEXT_SELECT
:
99 ContextSize
= sizeof (BM_TERMINAL_CONTEXT
);
102 case BM_HANDLE_CONTEXT_SELECT
:
103 ContextSize
= sizeof (BM_HANDLE_CONTEXT
);
111 if (ContextSize
== 0) {
116 // Create new menu entry
118 MenuEntry
= AllocateZeroPool (sizeof (BM_MENU_ENTRY
));
119 if (MenuEntry
== NULL
) {
123 MenuEntry
->VariableContext
= AllocateZeroPool (ContextSize
);
124 if (MenuEntry
->VariableContext
== NULL
) {
125 FreePool (MenuEntry
);
129 MenuEntry
->Signature
= BM_MENU_ENTRY_SIGNATURE
;
130 MenuEntry
->ContextSelection
= MenuType
;
135 Free up all resource allocated for a BM_MENU_ENTRY.
137 @param MenuEntry A pointer to BM_MENU_ENTRY.
141 BOpt_DestroyMenuEntry (
142 BM_MENU_ENTRY
*MenuEntry
145 BM_LOAD_CONTEXT
*LoadContext
;
146 BM_FILE_CONTEXT
*FileContext
;
147 BM_CONSOLE_CONTEXT
*ConsoleContext
;
148 BM_TERMINAL_CONTEXT
*TerminalContext
;
149 BM_HANDLE_CONTEXT
*HandleContext
;
152 // Select by the type in Menu entry for current context type
154 switch (MenuEntry
->ContextSelection
) {
155 case BM_LOAD_CONTEXT_SELECT
:
156 LoadContext
= (BM_LOAD_CONTEXT
*)MenuEntry
->VariableContext
;
157 FreePool (LoadContext
->FilePathList
);
158 if (LoadContext
->OptionalData
!= NULL
) {
159 FreePool (LoadContext
->OptionalData
);
162 FreePool (LoadContext
);
165 case BM_FILE_CONTEXT_SELECT
:
166 FileContext
= (BM_FILE_CONTEXT
*)MenuEntry
->VariableContext
;
168 if (!FileContext
->IsRoot
) {
169 FreePool (FileContext
->DevicePath
);
171 if (FileContext
->FHandle
!= NULL
) {
172 FileContext
->FHandle
->Close (FileContext
->FHandle
);
176 if (FileContext
->FileName
!= NULL
) {
177 FreePool (FileContext
->FileName
);
180 if (FileContext
->Info
!= NULL
) {
181 FreePool (FileContext
->Info
);
184 FreePool (FileContext
);
187 case BM_CONSOLE_CONTEXT_SELECT
:
188 ConsoleContext
= (BM_CONSOLE_CONTEXT
*)MenuEntry
->VariableContext
;
189 FreePool (ConsoleContext
->DevicePath
);
190 FreePool (ConsoleContext
);
193 case BM_TERMINAL_CONTEXT_SELECT
:
194 TerminalContext
= (BM_TERMINAL_CONTEXT
*)MenuEntry
->VariableContext
;
195 FreePool (TerminalContext
->DevicePath
);
196 FreePool (TerminalContext
);
199 case BM_HANDLE_CONTEXT_SELECT
:
200 HandleContext
= (BM_HANDLE_CONTEXT
*)MenuEntry
->VariableContext
;
201 FreePool (HandleContext
);
208 FreePool (MenuEntry
->DisplayString
);
209 if (MenuEntry
->HelpString
!= NULL
) {
210 FreePool (MenuEntry
->HelpString
);
213 FreePool (MenuEntry
);
217 Get the Menu Entry from the list in Menu Entry List.
219 If MenuNumber is great or equal to the number of Menu
220 Entry in the list, then ASSERT.
222 @param MenuOption The Menu Entry List to read the menu entry.
223 @param MenuNumber The index of Menu Entry.
225 @return The Menu Entry.
230 BM_MENU_OPTION
*MenuOption
,
234 BM_MENU_ENTRY
*NewMenuEntry
;
238 ASSERT (MenuNumber
< MenuOption
->MenuNumber
);
240 List
= MenuOption
->Head
.ForwardLink
;
241 for (Index
= 0; Index
< MenuNumber
; Index
++) {
242 List
= List
->ForwardLink
;
245 NewMenuEntry
= CR (List
, BM_MENU_ENTRY
, Link
, BM_MENU_ENTRY_SIGNATURE
);
251 Free resources allocated in Allocate Rountine.
253 @param FreeMenu Menu to be freed
257 BM_MENU_OPTION
*FreeMenu
260 BM_MENU_ENTRY
*MenuEntry
;
262 while (!IsListEmpty (&FreeMenu
->Head
)) {
264 FreeMenu
->Head
.ForwardLink
,
267 BM_MENU_ENTRY_SIGNATURE
269 RemoveEntryList (&MenuEntry
->Link
);
270 BOpt_DestroyMenuEntry (MenuEntry
);
273 FreeMenu
->MenuNumber
= 0;
278 Build the BootOptionMenu according to BootOrder Variable.
279 This Routine will access the Boot#### to get EFI_LOAD_OPTION.
281 @param CallbackData The BMM context data.
283 @return EFI_NOT_FOUND Fail to find "BootOrder" variable.
284 @return EFI_SUCESS Success build boot option menu.
288 BOpt_GetBootOptions (
289 IN BMM_CALLBACK_DATA
*CallbackData
293 UINT16 BootString
[10];
294 UINT8
*LoadOptionFromVar
;
295 UINTN BootOptionSize
;
296 BOOLEAN BootNextFlag
;
297 UINT16
*BootOrderList
;
298 UINTN BootOrderListSize
;
301 BM_MENU_ENTRY
*NewMenuEntry
;
302 BM_LOAD_CONTEXT
*NewLoadContext
;
303 UINT8
*LoadOptionPtr
;
305 UINTN OptionalDataSize
;
306 UINT8
*LoadOptionEnd
;
307 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
310 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
;
311 UINTN BootOptionCount
;
314 BootOrderListSize
= 0;
316 BootOrderList
= NULL
;
318 LoadOptionFromVar
= NULL
;
319 BOpt_FreeMenu (&BootOptionMenu
);
320 InitializeListHead (&BootOptionMenu
.Head
);
323 // Get the BootOrder from the Var
325 GetEfiGlobalVariable2 (L
"BootOrder", (VOID
**)&BootOrderList
, &BootOrderListSize
);
326 if (BootOrderList
== NULL
) {
327 return EFI_NOT_FOUND
;
331 // Get the BootNext from the Var
333 GetEfiGlobalVariable2 (L
"BootNext", (VOID
**)&BootNext
, &BootNextSize
);
334 if (BootNext
!= NULL
) {
335 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
;
408 // LoadOption is a pointer type of UINT8
409 // for easy use with following LOAD_OPTION
410 // embedded in this struct
413 NewLoadContext
->Attributes
= *(UINT32
*)LoadOptionPtr
;
415 LoadOptionPtr
+= sizeof (UINT32
);
417 NewLoadContext
->FilePathListLength
= *(UINT16
*)LoadOptionPtr
;
418 LoadOptionPtr
+= sizeof (UINT16
);
420 StringSize
= StrSize ((UINT16
*)LoadOptionPtr
);
422 NewLoadContext
->Description
= AllocateZeroPool (StrSize ((UINT16
*)LoadOptionPtr
));
423 ASSERT (NewLoadContext
->Description
!= NULL
);
424 StrCpyS (NewLoadContext
->Description
, StrSize ((UINT16
*)LoadOptionPtr
) / sizeof (UINT16
), (UINT16
*)LoadOptionPtr
);
426 ASSERT (NewLoadContext
->Description
!= NULL
);
427 NewMenuEntry
->DisplayString
= NewLoadContext
->Description
;
428 NewMenuEntry
->DisplayStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->DisplayString
, NULL
);
430 LoadOptionPtr
+= StringSize
;
432 NewLoadContext
->FilePathList
= AllocateZeroPool (NewLoadContext
->FilePathListLength
);
433 ASSERT (NewLoadContext
->FilePathList
!= NULL
);
435 NewLoadContext
->FilePathList
,
436 (EFI_DEVICE_PATH_PROTOCOL
*)LoadOptionPtr
,
437 NewLoadContext
->FilePathListLength
440 NewMenuEntry
->HelpString
= UiDevicePathToStr (NewLoadContext
->FilePathList
);
441 NewMenuEntry
->HelpStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->HelpString
, NULL
);
443 LoadOptionPtr
+= NewLoadContext
->FilePathListLength
;
445 if (LoadOptionPtr
< LoadOptionEnd
) {
446 OptionalDataSize
= BootOptionSize
-
450 NewLoadContext
->FilePathListLength
;
452 NewLoadContext
->OptionalData
= AllocateZeroPool (OptionalDataSize
);
453 ASSERT (NewLoadContext
->OptionalData
!= NULL
);
455 NewLoadContext
->OptionalData
,
461 InsertTailList (&BootOptionMenu
.Head
, &NewMenuEntry
->Link
);
463 FreePool (LoadOptionFromVar
);
466 EfiBootManagerFreeLoadOptions (BootOption
, BootOptionCount
);
468 if (BootNext
!= NULL
) {
472 if (BootOrderList
!= NULL
) {
473 FreePool (BootOrderList
);
476 BootOptionMenu
.MenuNumber
= MenuCount
;
482 Find drivers that will be added as Driver#### variables from handles
483 in current system environment
484 All valid handles in the system except those consume SimpleFs, LoadFile
485 are stored in DriverMenu for future use.
487 @retval EFI_SUCCESS The function complets successfully.
488 @return Other value if failed to build the DriverMenu.
496 UINTN NoDevicePathHandles
;
497 EFI_HANDLE
*DevicePathHandle
;
500 BM_MENU_ENTRY
*NewMenuEntry
;
501 BM_HANDLE_CONTEXT
*NewHandleContext
;
502 EFI_HANDLE CurHandle
;
504 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*SimpleFs
;
505 EFI_LOAD_FILE_PROTOCOL
*LoadFile
;
510 InitializeListHead (&DriverMenu
.Head
);
513 // At first, get all handles that support Device Path
514 // protocol which is the basic requirement for
517 Status
= gBS
->LocateHandleBuffer (
519 &gEfiDevicePathProtocolGuid
,
521 &NoDevicePathHandles
,
524 if (EFI_ERROR (Status
)) {
529 for (Index
= 0; Index
< NoDevicePathHandles
; Index
++) {
530 CurHandle
= DevicePathHandle
[Index
];
532 Status
= gBS
->HandleProtocol (
534 &gEfiSimpleFileSystemProtocolGuid
,
537 if (Status
== EFI_SUCCESS
) {
541 Status
= gBS
->HandleProtocol (
543 &gEfiLoadFileProtocolGuid
,
546 if (Status
== EFI_SUCCESS
) {
550 NewMenuEntry
= BOpt_CreateMenuEntry (BM_HANDLE_CONTEXT_SELECT
);
551 if (NULL
== NewMenuEntry
) {
552 FreePool (DevicePathHandle
);
553 return EFI_OUT_OF_RESOURCES
;
556 NewHandleContext
= (BM_HANDLE_CONTEXT
*)NewMenuEntry
->VariableContext
;
557 NewHandleContext
->Handle
= CurHandle
;
558 NewHandleContext
->DevicePath
= DevicePathFromHandle (CurHandle
);
559 NewMenuEntry
->DisplayString
= UiDevicePathToStr (NewHandleContext
->DevicePath
);
560 NewMenuEntry
->DisplayStringToken
= HiiSetString (mBmmCallbackInfo
->BmmHiiHandle
, 0, NewMenuEntry
->DisplayString
, NULL
);
561 NewMenuEntry
->HelpString
= NULL
;
562 NewMenuEntry
->HelpStringToken
= NewMenuEntry
->DisplayStringToken
;
563 NewMenuEntry
->OptionNumber
= OptionNumber
;
565 InsertTailList (&DriverMenu
.Head
, &NewMenuEntry
->Link
);
568 if (DevicePathHandle
!= NULL
) {
569 FreePool (DevicePathHandle
);
572 DriverMenu
.MenuNumber
= OptionNumber
;
578 Get the Option Number that has not been allocated for use.
580 @param Type The type of Option.
582 @return The available Option Number.
586 BOpt_GetOptionNumber (
594 UINT16
*OptionBuffer
;
603 UnicodeSPrint (StrTemp
, sizeof (StrTemp
), L
"%sOrder", Type
);
605 GetEfiGlobalVariable2 (StrTemp
, (VOID
**)&OrderList
, &OrderListSize
);
606 for (OptionNumber
= 0; ; OptionNumber
++) {
607 if (OrderList
!= NULL
) {
608 for (Index
= 0; Index
< OrderListSize
/ sizeof (UINT16
); Index
++) {
609 if (OptionNumber
== OrderList
[Index
]) {
615 if (Index
< OrderListSize
/ sizeof (UINT16
)) {
617 // The OptionNumber occurs in the OrderList, continue to use next one
622 UnicodeSPrint (StrTemp
, sizeof (StrTemp
), L
"%s%04x", Type
, (UINTN
)OptionNumber
);
623 DEBUG ((DEBUG_ERROR
, "Option = %s\n", StrTemp
));
624 GetEfiGlobalVariable2 (StrTemp
, (VOID
**)&OptionBuffer
, &OptionSize
);
625 if (NULL
== OptionBuffer
) {
627 // The Boot[OptionNumber] / Driver[OptionNumber] NOT occurs, we found it
638 Get the Option Number for Boot#### that does not used.
640 @return The available Option Number.
644 BOpt_GetBootOptionNumber (
648 return BOpt_GetOptionNumber (L
"Boot");
653 Get the Option Number for Driver#### that does not used.
655 @return The unused Option Number.
659 BOpt_GetDriverOptionNumber (
663 return BOpt_GetOptionNumber (L
"Driver");
668 Build up all DriverOptionMenu
670 @param CallbackData The BMM context data.
672 @retval EFI_SUCESS The functin completes successfully.
673 @retval EFI_OUT_OF_RESOURCES Not enough memory to compete the operation.
674 @retval EFI_NOT_FOUND Fail to get "DriverOrder" variable.
678 BOpt_GetDriverOptions (
679 IN BMM_CALLBACK_DATA
*CallbackData
683 UINT16 DriverString
[12];
684 UINT8
*LoadOptionFromVar
;
685 UINTN DriverOptionSize
;
687 UINT16
*DriverOrderList
;
688 UINTN DriverOrderListSize
;
689 BM_MENU_ENTRY
*NewMenuEntry
;
690 BM_LOAD_CONTEXT
*NewLoadContext
;
691 UINT8
*LoadOptionPtr
;
693 UINTN OptionalDataSize
;
694 UINT8
*LoadOptionEnd
;
696 DriverOrderListSize
= 0;
697 DriverOrderList
= NULL
;
698 DriverOptionSize
= 0;
699 LoadOptionFromVar
= NULL
;
700 BOpt_FreeMenu (&DriverOptionMenu
);
701 InitializeListHead (&DriverOptionMenu
.Head
);
703 // Get the DriverOrder from the Var
705 GetEfiGlobalVariable2 (L
"DriverOrder", (VOID
**)&DriverOrderList
, &DriverOrderListSize
);
706 if (DriverOrderList
== NULL
) {
707 return EFI_NOT_FOUND
;
710 for (Index
= 0; Index
< DriverOrderListSize
/ sizeof (UINT16
); Index
++) {
713 sizeof (DriverString
),
715 DriverOrderList
[Index
]
718 // Get all loadoptions from the VAR
720 GetEfiGlobalVariable2 (DriverString
, (VOID
**)&LoadOptionFromVar
, &DriverOptionSize
);
721 if (LoadOptionFromVar
== NULL
) {
725 NewMenuEntry
= BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT
);
726 if (NULL
== NewMenuEntry
) {
727 return EFI_OUT_OF_RESOURCES
;
730 NewLoadContext
= (BM_LOAD_CONTEXT
*)NewMenuEntry
->VariableContext
;
731 LoadOptionPtr
= LoadOptionFromVar
;
732 LoadOptionEnd
= LoadOptionFromVar
+ DriverOptionSize
;
733 NewMenuEntry
->OptionNumber
= DriverOrderList
[Index
];
734 NewLoadContext
->Deleted
= FALSE
;
735 NewLoadContext
->IsLegacy
= FALSE
;
738 // LoadOption is a pointer type of UINT8
739 // for easy use with following LOAD_OPTION
740 // embedded in this struct
743 NewLoadContext
->Attributes
= *(UINT32
*)LoadOptionPtr
;
745 LoadOptionPtr
+= sizeof (UINT32
);
747 NewLoadContext
->FilePathListLength
= *(UINT16
*)LoadOptionPtr
;
748 LoadOptionPtr
+= sizeof (UINT16
);
750 StringSize
= StrSize ((UINT16
*)LoadOptionPtr
);
751 NewLoadContext
->Description
= AllocateZeroPool (StringSize
);
752 ASSERT (NewLoadContext
->Description
!= NULL
);
754 NewLoadContext
->Description
,
755 (UINT16
*)LoadOptionPtr
,
758 NewMenuEntry
->DisplayString
= NewLoadContext
->Description
;
759 NewMenuEntry
->DisplayStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->DisplayString
, NULL
);
761 LoadOptionPtr
+= StringSize
;
763 NewLoadContext
->FilePathList
= AllocateZeroPool (NewLoadContext
->FilePathListLength
);
764 ASSERT (NewLoadContext
->FilePathList
!= NULL
);
766 NewLoadContext
->FilePathList
,
767 (EFI_DEVICE_PATH_PROTOCOL
*)LoadOptionPtr
,
768 NewLoadContext
->FilePathListLength
771 NewMenuEntry
->HelpString
= UiDevicePathToStr (NewLoadContext
->FilePathList
);
772 NewMenuEntry
->HelpStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->HelpString
, NULL
);
774 LoadOptionPtr
+= NewLoadContext
->FilePathListLength
;
776 if (LoadOptionPtr
< LoadOptionEnd
) {
777 OptionalDataSize
= DriverOptionSize
-
781 NewLoadContext
->FilePathListLength
;
783 NewLoadContext
->OptionalData
= AllocateZeroPool (OptionalDataSize
);
784 ASSERT (NewLoadContext
->OptionalData
!= NULL
);
786 NewLoadContext
->OptionalData
,
792 InsertTailList (&DriverOptionMenu
.Head
, &NewMenuEntry
->Link
);
793 FreePool (LoadOptionFromVar
);
796 if (DriverOrderList
!= NULL
) {
797 FreePool (DriverOrderList
);
800 DriverOptionMenu
.MenuNumber
= Index
;
805 Get option number according to Boot#### and BootOrder variable.
806 The value is saved as #### + 1.
808 @param CallbackData The BMM context data.
812 IN BMM_CALLBACK_DATA
*CallbackData
815 BMM_FAKE_NV_DATA
*BmmConfig
;
817 UINT16 OptionOrderIndex
;
819 BM_MENU_ENTRY
*NewMenuEntry
;
820 BM_LOAD_CONTEXT
*NewLoadContext
;
822 ASSERT (CallbackData
!= NULL
);
824 DeviceType
= (UINTN
)-1;
825 BmmConfig
= &CallbackData
->BmmFakeNvData
;
826 ZeroMem (BmmConfig
->BootOptionOrder
, sizeof (BmmConfig
->BootOptionOrder
));
828 for (Index
= 0, OptionOrderIndex
= 0; ((Index
< BootOptionMenu
.MenuNumber
) &&
829 (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
847 BmmConfig
->BootOptionOrder
[OptionOrderIndex
++] = (UINT32
)(NewMenuEntry
->OptionNumber
+ 1);
852 Get driver option order from globalc DriverOptionMenu.
854 @param CallbackData The BMM context data.
859 IN BMM_CALLBACK_DATA
*CallbackData
862 BMM_FAKE_NV_DATA
*BmmConfig
;
864 UINT16 OptionOrderIndex
;
866 BM_MENU_ENTRY
*NewMenuEntry
;
867 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]))));
879 NewMenuEntry
= BOpt_GetMenuEntry (&DriverOptionMenu
, Index
);
880 NewLoadContext
= (BM_LOAD_CONTEXT
*)NewMenuEntry
->VariableContext
;
882 if (NewLoadContext
->IsLegacy
) {
883 if (((BBS_BBS_DEVICE_PATH
*)NewLoadContext
->FilePathList
)->DeviceType
!= DeviceType
) {
884 DeviceType
= ((BBS_BBS_DEVICE_PATH
*)NewLoadContext
->FilePathList
)->DeviceType
;
887 // Only show one legacy boot option for the same device type
888 // assuming the boot options are grouped by the device type
894 BmmConfig
->DriverOptionOrder
[OptionOrderIndex
++] = (UINT32
)(NewMenuEntry
->OptionNumber
+ 1);
899 Boot the file specified by the input file path info.
901 @param FilePath Point to the file path.
903 @retval TRUE Exit caller function.
904 @retval FALSE Not exit caller function.
909 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
912 EFI_BOOT_MANAGER_LOAD_OPTION BootOption
;
917 FileName
= ExtractFileNameFromDevicePath (FilePath
);
918 if (FileName
!= NULL
) {
919 EfiBootManagerInitializeLoadOption (
930 // Since current no boot from removable media directly is allowed */
932 gST
->ConOut
->ClearScreen (gST
->ConOut
);
934 // Check whether need to reset system.
936 BmmSetupResetReminder ();
938 BmmSetConsoleMode (FALSE
);
939 EfiBootManagerBoot (&BootOption
);
940 BmmSetConsoleMode (TRUE
);
944 EfiBootManagerFreeLoadOption (&BootOption
);
951 Display the form base on the selected file.
953 @param FilePath Point to the file path.
954 @param FormId The form need to display.
959 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
960 IN EFI_FORM_ID FormId
963 gBootMaintenancePrivate
.LoadContext
->FilePathList
= FilePath
;
965 UpdateOptionPage (&gBootMaintenancePrivate
, FormId
, FilePath
);
967 gBootMaintenancePrivate
.FormBrowser2
->SendForm (
968 gBootMaintenancePrivate
.FormBrowser2
,
969 &gBootMaintenancePrivate
.BmmHiiHandle
,
980 Create boot option base on the input file path info.
982 @param FilePath Point to the file path.
984 @retval TRUE Exit caller function.
985 @retval FALSE Not exit caller function.
989 CreateBootOptionFromFile (
990 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
993 return ReSendForm (FilePath
, FORM_BOOT_ADD_ID
);
997 Create driver option base on the input file path info.
999 @param FilePath Point to the file path.
1001 @retval TRUE Exit caller function.
1002 @retval FALSE Not exit caller function.
1007 CreateDriverOptionFromFile (
1008 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
1011 return ReSendForm (FilePath
, FORM_DRV_ADD_FILE_ID
);