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
);
161 FreePool (LoadContext
);
164 case BM_FILE_CONTEXT_SELECT
:
165 FileContext
= (BM_FILE_CONTEXT
*) MenuEntry
->VariableContext
;
167 if (!FileContext
->IsRoot
) {
168 FreePool (FileContext
->DevicePath
);
170 if (FileContext
->FHandle
!= NULL
) {
171 FileContext
->FHandle
->Close (FileContext
->FHandle
);
175 if (FileContext
->FileName
!= NULL
) {
176 FreePool (FileContext
->FileName
);
178 if (FileContext
->Info
!= NULL
) {
179 FreePool (FileContext
->Info
);
181 FreePool (FileContext
);
184 case BM_CONSOLE_CONTEXT_SELECT
:
185 ConsoleContext
= (BM_CONSOLE_CONTEXT
*) MenuEntry
->VariableContext
;
186 FreePool (ConsoleContext
->DevicePath
);
187 FreePool (ConsoleContext
);
190 case BM_TERMINAL_CONTEXT_SELECT
:
191 TerminalContext
= (BM_TERMINAL_CONTEXT
*) MenuEntry
->VariableContext
;
192 FreePool (TerminalContext
->DevicePath
);
193 FreePool (TerminalContext
);
196 case BM_HANDLE_CONTEXT_SELECT
:
197 HandleContext
= (BM_HANDLE_CONTEXT
*) MenuEntry
->VariableContext
;
198 FreePool (HandleContext
);
205 FreePool (MenuEntry
->DisplayString
);
206 if (MenuEntry
->HelpString
!= NULL
) {
207 FreePool (MenuEntry
->HelpString
);
210 FreePool (MenuEntry
);
214 Get the Menu Entry from the list in Menu Entry List.
216 If MenuNumber is great or equal to the number of Menu
217 Entry in the list, then ASSERT.
219 @param MenuOption The Menu Entry List to read the menu entry.
220 @param MenuNumber The index of Menu Entry.
222 @return The Menu Entry.
227 BM_MENU_OPTION
*MenuOption
,
231 BM_MENU_ENTRY
*NewMenuEntry
;
235 ASSERT (MenuNumber
< MenuOption
->MenuNumber
);
237 List
= MenuOption
->Head
.ForwardLink
;
238 for (Index
= 0; Index
< MenuNumber
; Index
++) {
239 List
= List
->ForwardLink
;
242 NewMenuEntry
= CR (List
, BM_MENU_ENTRY
, Link
, BM_MENU_ENTRY_SIGNATURE
);
248 Free resources allocated in Allocate Rountine.
250 @param FreeMenu Menu to be freed
254 BM_MENU_OPTION
*FreeMenu
257 BM_MENU_ENTRY
*MenuEntry
;
258 while (!IsListEmpty (&FreeMenu
->Head
)) {
260 FreeMenu
->Head
.ForwardLink
,
263 BM_MENU_ENTRY_SIGNATURE
265 RemoveEntryList (&MenuEntry
->Link
);
266 BOpt_DestroyMenuEntry (MenuEntry
);
268 FreeMenu
->MenuNumber
= 0;
273 Build the BootOptionMenu according to BootOrder Variable.
274 This Routine will access the Boot#### to get EFI_LOAD_OPTION.
276 @param CallbackData The BMM context data.
278 @return EFI_NOT_FOUND Fail to find "BootOrder" variable.
279 @return EFI_SUCESS Success build boot option menu.
283 BOpt_GetBootOptions (
284 IN BMM_CALLBACK_DATA
*CallbackData
288 UINT16 BootString
[10];
289 UINT8
*LoadOptionFromVar
;
290 UINTN BootOptionSize
;
291 BOOLEAN BootNextFlag
;
292 UINT16
*BootOrderList
;
293 UINTN BootOrderListSize
;
296 BM_MENU_ENTRY
*NewMenuEntry
;
297 BM_LOAD_CONTEXT
*NewLoadContext
;
298 UINT8
*LoadOptionPtr
;
300 UINTN OptionalDataSize
;
301 UINT8
*LoadOptionEnd
;
302 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
305 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
;
306 UINTN BootOptionCount
;
309 BootOrderListSize
= 0;
311 BootOrderList
= NULL
;
313 LoadOptionFromVar
= NULL
;
314 BOpt_FreeMenu (&BootOptionMenu
);
315 InitializeListHead (&BootOptionMenu
.Head
);
318 // Get the BootOrder from the Var
320 GetEfiGlobalVariable2 (L
"BootOrder", (VOID
**) &BootOrderList
, &BootOrderListSize
);
321 if (BootOrderList
== NULL
) {
322 return EFI_NOT_FOUND
;
326 // Get the BootNext from the Var
328 GetEfiGlobalVariable2 (L
"BootNext", (VOID
**) &BootNext
, &BootNextSize
);
329 if (BootNext
!= NULL
) {
330 if (BootNextSize
!= sizeof (UINT16
)) {
335 BootOption
= EfiBootManagerGetLoadOptions (&BootOptionCount
, LoadOptionTypeBoot
);
336 for (Index
= 0; Index
< BootOrderListSize
/ sizeof (UINT16
); Index
++) {
338 // Don't display the hidden/inactive boot option
340 if (((BootOption
[Index
].Attributes
& LOAD_OPTION_HIDDEN
) != 0) || ((BootOption
[Index
].Attributes
& LOAD_OPTION_ACTIVE
) == 0)) {
344 UnicodeSPrint (BootString
, sizeof (BootString
), L
"Boot%04x", BootOrderList
[Index
]);
346 // Get all loadoptions from the VAR
348 GetEfiGlobalVariable2 (BootString
, (VOID
**) &LoadOptionFromVar
, &BootOptionSize
);
349 if (LoadOptionFromVar
== NULL
) {
353 if (BootNext
!= NULL
) {
354 BootNextFlag
= (BOOLEAN
) (*BootNext
== BootOrderList
[Index
]);
356 BootNextFlag
= FALSE
;
359 NewMenuEntry
= BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT
);
360 ASSERT (NULL
!= NewMenuEntry
);
362 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
364 LoadOptionPtr
= LoadOptionFromVar
;
365 LoadOptionEnd
= LoadOptionFromVar
+ BootOptionSize
;
367 NewMenuEntry
->OptionNumber
= BootOrderList
[Index
];
368 NewLoadContext
->Deleted
= FALSE
;
369 NewLoadContext
->IsBootNext
= BootNextFlag
;
372 // Is a Legacy Device?
374 Ptr
= (UINT8
*) LoadOptionFromVar
;
377 // Attribute = *(UINT32 *)Ptr;
379 Ptr
+= sizeof (UINT32
);
382 // FilePathSize = *(UINT16 *)Ptr;
384 Ptr
+= sizeof (UINT16
);
387 // Description = (CHAR16 *)Ptr;
389 Ptr
+= StrSize ((CHAR16
*) Ptr
);
392 // Now Ptr point to Device Path
394 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) Ptr
;
395 if ((BBS_DEVICE_PATH
== DevicePath
->Type
) && (BBS_BBS_DP
== DevicePath
->SubType
)) {
396 NewLoadContext
->IsLegacy
= TRUE
;
398 NewLoadContext
->IsLegacy
= FALSE
;
401 // LoadOption is a pointer type of UINT8
402 // for easy use with following LOAD_OPTION
403 // embedded in this struct
406 NewLoadContext
->Attributes
= *(UINT32
*) LoadOptionPtr
;
408 LoadOptionPtr
+= sizeof (UINT32
);
410 NewLoadContext
->FilePathListLength
= *(UINT16
*) LoadOptionPtr
;
411 LoadOptionPtr
+= sizeof (UINT16
);
413 StringSize
= StrSize((UINT16
*)LoadOptionPtr
);
415 NewLoadContext
->Description
= AllocateZeroPool (StrSize((UINT16
*)LoadOptionPtr
));
416 ASSERT (NewLoadContext
->Description
!= NULL
);
417 StrCpyS (NewLoadContext
->Description
, StrSize((UINT16
*)LoadOptionPtr
) / sizeof (UINT16
), (UINT16
*)LoadOptionPtr
);
419 ASSERT (NewLoadContext
->Description
!= NULL
);
420 NewMenuEntry
->DisplayString
= NewLoadContext
->Description
;
421 NewMenuEntry
->DisplayStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->DisplayString
, NULL
);
423 LoadOptionPtr
+= StringSize
;
425 NewLoadContext
->FilePathList
= AllocateZeroPool (NewLoadContext
->FilePathListLength
);
426 ASSERT (NewLoadContext
->FilePathList
!= NULL
);
428 NewLoadContext
->FilePathList
,
429 (EFI_DEVICE_PATH_PROTOCOL
*) LoadOptionPtr
,
430 NewLoadContext
->FilePathListLength
433 NewMenuEntry
->HelpString
= UiDevicePathToStr (NewLoadContext
->FilePathList
);
434 NewMenuEntry
->HelpStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->HelpString
, NULL
);
436 LoadOptionPtr
+= NewLoadContext
->FilePathListLength
;
438 if (LoadOptionPtr
< LoadOptionEnd
) {
439 OptionalDataSize
= BootOptionSize
-
443 NewLoadContext
->FilePathListLength
;
445 NewLoadContext
->OptionalData
= AllocateZeroPool (OptionalDataSize
);
446 ASSERT (NewLoadContext
->OptionalData
!= NULL
);
448 NewLoadContext
->OptionalData
,
454 InsertTailList (&BootOptionMenu
.Head
, &NewMenuEntry
->Link
);
456 FreePool (LoadOptionFromVar
);
458 EfiBootManagerFreeLoadOptions (BootOption
, BootOptionCount
);
460 if (BootNext
!= NULL
) {
463 if (BootOrderList
!= NULL
) {
464 FreePool (BootOrderList
);
467 BootOptionMenu
.MenuNumber
= MenuCount
;
473 Find drivers that will be added as Driver#### variables from handles
474 in current system environment
475 All valid handles in the system except those consume SimpleFs, LoadFile
476 are stored in DriverMenu for future use.
478 @retval EFI_SUCCESS The function complets successfully.
479 @return Other value if failed to build the DriverMenu.
487 UINTN NoDevicePathHandles
;
488 EFI_HANDLE
*DevicePathHandle
;
491 BM_MENU_ENTRY
*NewMenuEntry
;
492 BM_HANDLE_CONTEXT
*NewHandleContext
;
493 EFI_HANDLE CurHandle
;
495 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*SimpleFs
;
496 EFI_LOAD_FILE_PROTOCOL
*LoadFile
;
501 InitializeListHead (&DriverMenu
.Head
);
504 // At first, get all handles that support Device Path
505 // protocol which is the basic requirement for
508 Status
= gBS
->LocateHandleBuffer (
510 &gEfiDevicePathProtocolGuid
,
512 &NoDevicePathHandles
,
515 if (EFI_ERROR (Status
)) {
520 for (Index
= 0; Index
< NoDevicePathHandles
; Index
++) {
521 CurHandle
= DevicePathHandle
[Index
];
523 Status
= gBS
->HandleProtocol (
525 &gEfiSimpleFileSystemProtocolGuid
,
528 if (Status
== EFI_SUCCESS
) {
532 Status
= gBS
->HandleProtocol (
534 &gEfiLoadFileProtocolGuid
,
537 if (Status
== EFI_SUCCESS
) {
541 NewMenuEntry
= BOpt_CreateMenuEntry (BM_HANDLE_CONTEXT_SELECT
);
542 if (NULL
== NewMenuEntry
) {
543 FreePool (DevicePathHandle
);
544 return EFI_OUT_OF_RESOURCES
;
547 NewHandleContext
= (BM_HANDLE_CONTEXT
*) NewMenuEntry
->VariableContext
;
548 NewHandleContext
->Handle
= CurHandle
;
549 NewHandleContext
->DevicePath
= DevicePathFromHandle (CurHandle
);
550 NewMenuEntry
->DisplayString
= UiDevicePathToStr (NewHandleContext
->DevicePath
);
551 NewMenuEntry
->DisplayStringToken
= HiiSetString (mBmmCallbackInfo
->BmmHiiHandle
,0,NewMenuEntry
->DisplayString
,NULL
);
552 NewMenuEntry
->HelpString
= NULL
;
553 NewMenuEntry
->HelpStringToken
= NewMenuEntry
->DisplayStringToken
;
554 NewMenuEntry
->OptionNumber
= OptionNumber
;
556 InsertTailList (&DriverMenu
.Head
, &NewMenuEntry
->Link
);
560 if (DevicePathHandle
!= NULL
) {
561 FreePool (DevicePathHandle
);
564 DriverMenu
.MenuNumber
= OptionNumber
;
570 Get the Option Number that has not been allocated for use.
572 @param Type The type of Option.
574 @return The available Option Number.
578 BOpt_GetOptionNumber (
586 UINT16
*OptionBuffer
;
595 UnicodeSPrint (StrTemp
, sizeof (StrTemp
), L
"%sOrder", Type
);
597 GetEfiGlobalVariable2 (StrTemp
, (VOID
**) &OrderList
, &OrderListSize
);
598 for (OptionNumber
= 0; ; OptionNumber
++) {
599 if (OrderList
!= NULL
) {
600 for (Index
= 0; Index
< OrderListSize
/ sizeof (UINT16
); Index
++) {
601 if (OptionNumber
== OrderList
[Index
]) {
607 if (Index
< OrderListSize
/ sizeof (UINT16
)) {
609 // The OptionNumber occurs in the OrderList, continue to use next one
613 UnicodeSPrint (StrTemp
, sizeof (StrTemp
), L
"%s%04x", Type
, (UINTN
) OptionNumber
);
614 DEBUG((DEBUG_ERROR
,"Option = %s\n", StrTemp
));
615 GetEfiGlobalVariable2 (StrTemp
, (VOID
**) &OptionBuffer
, &OptionSize
);
616 if (NULL
== OptionBuffer
) {
618 // The Boot[OptionNumber] / Driver[OptionNumber] NOT occurs, we found it
629 Get the Option Number for Boot#### that does not used.
631 @return The available Option Number.
635 BOpt_GetBootOptionNumber (
639 return BOpt_GetOptionNumber (L
"Boot");
644 Get the Option Number for Driver#### that does not used.
646 @return The unused Option Number.
650 BOpt_GetDriverOptionNumber (
654 return BOpt_GetOptionNumber (L
"Driver");
659 Build up all DriverOptionMenu
661 @param CallbackData The BMM context data.
663 @retval EFI_SUCESS The functin completes successfully.
664 @retval EFI_OUT_OF_RESOURCES Not enough memory to compete the operation.
665 @retval EFI_NOT_FOUND Fail to get "DriverOrder" variable.
669 BOpt_GetDriverOptions (
670 IN BMM_CALLBACK_DATA
*CallbackData
674 UINT16 DriverString
[12];
675 UINT8
*LoadOptionFromVar
;
676 UINTN DriverOptionSize
;
678 UINT16
*DriverOrderList
;
679 UINTN DriverOrderListSize
;
680 BM_MENU_ENTRY
*NewMenuEntry
;
681 BM_LOAD_CONTEXT
*NewLoadContext
;
682 UINT8
*LoadOptionPtr
;
684 UINTN OptionalDataSize
;
685 UINT8
*LoadOptionEnd
;
687 DriverOrderListSize
= 0;
688 DriverOrderList
= NULL
;
689 DriverOptionSize
= 0;
690 LoadOptionFromVar
= NULL
;
691 BOpt_FreeMenu (&DriverOptionMenu
);
692 InitializeListHead (&DriverOptionMenu
.Head
);
694 // Get the DriverOrder from the Var
696 GetEfiGlobalVariable2 (L
"DriverOrder", (VOID
**) &DriverOrderList
, &DriverOrderListSize
);
697 if (DriverOrderList
== NULL
) {
698 return EFI_NOT_FOUND
;
701 for (Index
= 0; Index
< DriverOrderListSize
/ sizeof (UINT16
); Index
++) {
704 sizeof (DriverString
),
706 DriverOrderList
[Index
]
709 // Get all loadoptions from the VAR
711 GetEfiGlobalVariable2 (DriverString
, (VOID
**) &LoadOptionFromVar
, &DriverOptionSize
);
712 if (LoadOptionFromVar
== NULL
) {
717 NewMenuEntry
= BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT
);
718 if (NULL
== NewMenuEntry
) {
719 return EFI_OUT_OF_RESOURCES
;
722 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
723 LoadOptionPtr
= LoadOptionFromVar
;
724 LoadOptionEnd
= LoadOptionFromVar
+ DriverOptionSize
;
725 NewMenuEntry
->OptionNumber
= DriverOrderList
[Index
];
726 NewLoadContext
->Deleted
= FALSE
;
727 NewLoadContext
->IsLegacy
= FALSE
;
730 // LoadOption is a pointer type of UINT8
731 // for easy use with following LOAD_OPTION
732 // embedded in this struct
735 NewLoadContext
->Attributes
= *(UINT32
*) LoadOptionPtr
;
737 LoadOptionPtr
+= sizeof (UINT32
);
739 NewLoadContext
->FilePathListLength
= *(UINT16
*) LoadOptionPtr
;
740 LoadOptionPtr
+= sizeof (UINT16
);
742 StringSize
= StrSize ((UINT16
*) LoadOptionPtr
);
743 NewLoadContext
->Description
= AllocateZeroPool (StringSize
);
744 ASSERT (NewLoadContext
->Description
!= NULL
);
746 NewLoadContext
->Description
,
747 (UINT16
*) LoadOptionPtr
,
750 NewMenuEntry
->DisplayString
= NewLoadContext
->Description
;
751 NewMenuEntry
->DisplayStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->DisplayString
, NULL
);
753 LoadOptionPtr
+= StringSize
;
755 NewLoadContext
->FilePathList
= AllocateZeroPool (NewLoadContext
->FilePathListLength
);
756 ASSERT (NewLoadContext
->FilePathList
!= NULL
);
758 NewLoadContext
->FilePathList
,
759 (EFI_DEVICE_PATH_PROTOCOL
*) LoadOptionPtr
,
760 NewLoadContext
->FilePathListLength
763 NewMenuEntry
->HelpString
= UiDevicePathToStr (NewLoadContext
->FilePathList
);
764 NewMenuEntry
->HelpStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->HelpString
, NULL
);
766 LoadOptionPtr
+= NewLoadContext
->FilePathListLength
;
768 if (LoadOptionPtr
< LoadOptionEnd
) {
769 OptionalDataSize
= DriverOptionSize
-
773 NewLoadContext
->FilePathListLength
;
775 NewLoadContext
->OptionalData
= AllocateZeroPool (OptionalDataSize
);
776 ASSERT (NewLoadContext
->OptionalData
!= NULL
);
778 NewLoadContext
->OptionalData
,
785 InsertTailList (&DriverOptionMenu
.Head
, &NewMenuEntry
->Link
);
786 FreePool (LoadOptionFromVar
);
790 if (DriverOrderList
!= NULL
) {
791 FreePool (DriverOrderList
);
794 DriverOptionMenu
.MenuNumber
= Index
;
800 Get option number according to Boot#### and BootOrder variable.
801 The value is saved as #### + 1.
803 @param CallbackData The BMM context data.
807 IN BMM_CALLBACK_DATA
*CallbackData
810 BMM_FAKE_NV_DATA
*BmmConfig
;
812 UINT16 OptionOrderIndex
;
814 BM_MENU_ENTRY
*NewMenuEntry
;
815 BM_LOAD_CONTEXT
*NewLoadContext
;
817 ASSERT (CallbackData
!= NULL
);
819 DeviceType
= (UINTN
) -1;
820 BmmConfig
= &CallbackData
->BmmFakeNvData
;
821 ZeroMem (BmmConfig
->BootOptionOrder
, sizeof (BmmConfig
->BootOptionOrder
));
823 for (Index
= 0, OptionOrderIndex
= 0; ((Index
< BootOptionMenu
.MenuNumber
) &&
824 (OptionOrderIndex
< (sizeof (BmmConfig
->BootOptionOrder
) / sizeof (BmmConfig
->BootOptionOrder
[0]))));
826 NewMenuEntry
= BOpt_GetMenuEntry (&BootOptionMenu
, Index
);
827 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
829 if (NewLoadContext
->IsLegacy
) {
830 if (((BBS_BBS_DEVICE_PATH
*) NewLoadContext
->FilePathList
)->DeviceType
!= DeviceType
) {
831 DeviceType
= ((BBS_BBS_DEVICE_PATH
*) NewLoadContext
->FilePathList
)->DeviceType
;
834 // Only show one legacy boot option for the same device type
835 // assuming the boot options are grouped by the device type
840 BmmConfig
->BootOptionOrder
[OptionOrderIndex
++] = (UINT32
) (NewMenuEntry
->OptionNumber
+ 1);
845 Get driver option order from globalc DriverOptionMenu.
847 @param CallbackData The BMM context data.
852 IN BMM_CALLBACK_DATA
*CallbackData
855 BMM_FAKE_NV_DATA
*BmmConfig
;
857 UINT16 OptionOrderIndex
;
859 BM_MENU_ENTRY
*NewMenuEntry
;
860 BM_LOAD_CONTEXT
*NewLoadContext
;
863 ASSERT (CallbackData
!= NULL
);
865 DeviceType
= (UINTN
) -1;
866 BmmConfig
= &CallbackData
->BmmFakeNvData
;
867 ZeroMem (BmmConfig
->DriverOptionOrder
, sizeof (BmmConfig
->DriverOptionOrder
));
869 for (Index
= 0, OptionOrderIndex
= 0; ((Index
< DriverOptionMenu
.MenuNumber
) &&
870 (OptionOrderIndex
< (sizeof (BmmConfig
->DriverOptionOrder
) / sizeof (BmmConfig
->DriverOptionOrder
[0]))));
872 NewMenuEntry
= BOpt_GetMenuEntry (&DriverOptionMenu
, Index
);
873 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
875 if (NewLoadContext
->IsLegacy
) {
876 if (((BBS_BBS_DEVICE_PATH
*) NewLoadContext
->FilePathList
)->DeviceType
!= DeviceType
) {
877 DeviceType
= ((BBS_BBS_DEVICE_PATH
*) NewLoadContext
->FilePathList
)->DeviceType
;
880 // Only show one legacy boot option for the same device type
881 // assuming the boot options are grouped by the device type
886 BmmConfig
->DriverOptionOrder
[OptionOrderIndex
++] = (UINT32
) (NewMenuEntry
->OptionNumber
+ 1);
891 Boot the file specified by the input file path info.
893 @param FilePath Point to the file path.
895 @retval TRUE Exit caller function.
896 @retval FALSE Not exit caller function.
901 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
904 EFI_BOOT_MANAGER_LOAD_OPTION BootOption
;
909 FileName
= ExtractFileNameFromDevicePath(FilePath
);
910 if (FileName
!= NULL
) {
911 EfiBootManagerInitializeLoadOption (
922 // Since current no boot from removable media directly is allowed */
924 gST
->ConOut
->ClearScreen (gST
->ConOut
);
926 // Check whether need to reset system.
928 BmmSetupResetReminder ();
930 BmmSetConsoleMode (FALSE
);
931 EfiBootManagerBoot (&BootOption
);
932 BmmSetConsoleMode (TRUE
);
936 EfiBootManagerFreeLoadOption (&BootOption
);
943 Display the form base on the selected file.
945 @param FilePath Point to the file path.
946 @param FormId The form need to display.
951 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
952 IN EFI_FORM_ID FormId
955 gBootMaintenancePrivate
.LoadContext
->FilePathList
= FilePath
;
957 UpdateOptionPage(&gBootMaintenancePrivate
, FormId
, FilePath
);
959 gBootMaintenancePrivate
.FormBrowser2
->SendForm (
960 gBootMaintenancePrivate
.FormBrowser2
,
961 &gBootMaintenancePrivate
.BmmHiiHandle
,
972 Create boot option base on the input file path info.
974 @param FilePath Point to the file path.
976 @retval TRUE Exit caller function.
977 @retval FALSE Not exit caller function.
981 CreateBootOptionFromFile (
982 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
985 return ReSendForm(FilePath
, FORM_BOOT_ADD_ID
);
989 Create driver option base on the input file path info.
991 @param FilePath Point to the file path.
993 @retval TRUE Exit caller function.
994 @retval FALSE Not exit caller function.
999 CreateDriverOptionFromFile (
1000 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
1003 return ReSendForm(FilePath
, FORM_DRV_ADD_FILE_ID
);