2 Provide boot option support for Application "BootMaint"
4 Include file system navigation, system handle selection
6 Boot option manipulation
8 Copyright (c) 2004 - 2015, 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.
27 Create a menu entry by given menu type.
29 @param MenuType The Menu type to be created.
31 @retval NULL If failed to create the menu.
32 @return the new menu entry.
36 BOpt_CreateMenuEntry (
40 BM_MENU_ENTRY
*MenuEntry
;
44 // Get context size according to menu type
47 case BM_LOAD_CONTEXT_SELECT
:
48 ContextSize
= sizeof (BM_LOAD_CONTEXT
);
51 case BM_FILE_CONTEXT_SELECT
:
52 ContextSize
= sizeof (BM_FILE_CONTEXT
);
55 case BM_CONSOLE_CONTEXT_SELECT
:
56 ContextSize
= sizeof (BM_CONSOLE_CONTEXT
);
59 case BM_TERMINAL_CONTEXT_SELECT
:
60 ContextSize
= sizeof (BM_TERMINAL_CONTEXT
);
63 case BM_HANDLE_CONTEXT_SELECT
:
64 ContextSize
= sizeof (BM_HANDLE_CONTEXT
);
72 if (ContextSize
== 0) {
77 // Create new menu entry
79 MenuEntry
= AllocateZeroPool (sizeof (BM_MENU_ENTRY
));
80 if (MenuEntry
== NULL
) {
84 MenuEntry
->VariableContext
= AllocateZeroPool (ContextSize
);
85 if (MenuEntry
->VariableContext
== NULL
) {
90 MenuEntry
->Signature
= BM_MENU_ENTRY_SIGNATURE
;
91 MenuEntry
->ContextSelection
= MenuType
;
96 Free up all resource allocated for a BM_MENU_ENTRY.
98 @param MenuEntry A pointer to BM_MENU_ENTRY.
102 BOpt_DestroyMenuEntry (
103 BM_MENU_ENTRY
*MenuEntry
106 BM_LOAD_CONTEXT
*LoadContext
;
107 BM_FILE_CONTEXT
*FileContext
;
108 BM_CONSOLE_CONTEXT
*ConsoleContext
;
109 BM_TERMINAL_CONTEXT
*TerminalContext
;
110 BM_HANDLE_CONTEXT
*HandleContext
;
113 // Select by the type in Menu entry for current context type
115 switch (MenuEntry
->ContextSelection
) {
116 case BM_LOAD_CONTEXT_SELECT
:
117 LoadContext
= (BM_LOAD_CONTEXT
*) MenuEntry
->VariableContext
;
118 FreePool (LoadContext
->FilePathList
);
119 FreePool (LoadContext
->LoadOption
);
120 if (LoadContext
->OptionalData
!= NULL
) {
121 FreePool (LoadContext
->OptionalData
);
123 FreePool (LoadContext
);
126 case BM_FILE_CONTEXT_SELECT
:
127 FileContext
= (BM_FILE_CONTEXT
*) MenuEntry
->VariableContext
;
129 if (!FileContext
->IsRoot
) {
130 FreePool (FileContext
->DevicePath
);
132 if (FileContext
->FHandle
!= NULL
) {
133 FileContext
->FHandle
->Close (FileContext
->FHandle
);
137 if (FileContext
->FileName
!= NULL
) {
138 FreePool (FileContext
->FileName
);
140 if (FileContext
->Info
!= NULL
) {
141 FreePool (FileContext
->Info
);
143 FreePool (FileContext
);
146 case BM_CONSOLE_CONTEXT_SELECT
:
147 ConsoleContext
= (BM_CONSOLE_CONTEXT
*) MenuEntry
->VariableContext
;
148 FreePool (ConsoleContext
->DevicePath
);
149 FreePool (ConsoleContext
);
152 case BM_TERMINAL_CONTEXT_SELECT
:
153 TerminalContext
= (BM_TERMINAL_CONTEXT
*) MenuEntry
->VariableContext
;
154 FreePool (TerminalContext
->DevicePath
);
155 FreePool (TerminalContext
);
158 case BM_HANDLE_CONTEXT_SELECT
:
159 HandleContext
= (BM_HANDLE_CONTEXT
*) MenuEntry
->VariableContext
;
160 FreePool (HandleContext
);
167 FreePool (MenuEntry
->DisplayString
);
168 if (MenuEntry
->HelpString
!= NULL
) {
169 FreePool (MenuEntry
->HelpString
);
172 FreePool (MenuEntry
);
176 Get the Menu Entry from the list in Menu Entry List.
178 If MenuNumber is great or equal to the number of Menu
179 Entry in the list, then ASSERT.
181 @param MenuOption The Menu Entry List to read the menu entry.
182 @param MenuNumber The index of Menu Entry.
184 @return The Menu Entry.
189 BM_MENU_OPTION
*MenuOption
,
193 BM_MENU_ENTRY
*NewMenuEntry
;
197 ASSERT (MenuNumber
< MenuOption
->MenuNumber
);
199 List
= MenuOption
->Head
.ForwardLink
;
200 for (Index
= 0; Index
< MenuNumber
; Index
++) {
201 List
= List
->ForwardLink
;
204 NewMenuEntry
= CR (List
, BM_MENU_ENTRY
, Link
, BM_MENU_ENTRY_SIGNATURE
);
210 Free resources allocated in Allocate Rountine.
212 @param FreeMenu Menu to be freed
216 BM_MENU_OPTION
*FreeMenu
219 BM_MENU_ENTRY
*MenuEntry
;
220 while (!IsListEmpty (&FreeMenu
->Head
)) {
222 FreeMenu
->Head
.ForwardLink
,
225 BM_MENU_ENTRY_SIGNATURE
227 RemoveEntryList (&MenuEntry
->Link
);
228 BOpt_DestroyMenuEntry (MenuEntry
);
230 FreeMenu
->MenuNumber
= 0;
235 Build the BootOptionMenu according to BootOrder Variable.
236 This Routine will access the Boot#### to get EFI_LOAD_OPTION.
238 @param CallbackData The BMM context data.
240 @return EFI_NOT_FOUND Fail to find "BootOrder" variable.
241 @return EFI_SUCESS Success build boot option menu.
245 BOpt_GetBootOptions (
246 IN BMM_CALLBACK_DATA
*CallbackData
250 UINT16 BootString
[10];
251 UINT8
*LoadOptionFromVar
;
253 UINTN BootOptionSize
;
254 BOOLEAN BootNextFlag
;
255 UINT16
*BootOrderList
;
256 UINTN BootOrderListSize
;
259 BM_MENU_ENTRY
*NewMenuEntry
;
260 BM_LOAD_CONTEXT
*NewLoadContext
;
261 UINT8
*LoadOptionPtr
;
263 UINTN OptionalDataSize
;
264 UINT8
*LoadOptionEnd
;
265 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
268 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
;
269 UINTN BootOptionCount
;
272 BootOrderListSize
= 0;
274 BootOrderList
= NULL
;
276 LoadOptionFromVar
= NULL
;
277 BOpt_FreeMenu (&BootOptionMenu
);
278 InitializeListHead (&BootOptionMenu
.Head
);
281 // Get the BootOrder from the Var
283 GetEfiGlobalVariable2 (L
"BootOrder", (VOID
**) &BootOrderList
, &BootOrderListSize
);
284 if (BootOrderList
== NULL
) {
285 return EFI_NOT_FOUND
;
289 // Get the BootNext from the Var
291 GetEfiGlobalVariable2 (L
"BootNext", (VOID
**) &BootNext
, &BootNextSize
);
292 if (BootNext
!= NULL
) {
293 if (BootNextSize
!= sizeof (UINT16
)) {
298 BootOption
= EfiBootManagerGetLoadOptions (&BootOptionCount
, LoadOptionTypeBoot
);
299 for (Index
= 0; Index
< BootOrderListSize
/ sizeof (UINT16
); Index
++) {
301 // Don't display the hidden/inactive boot option
303 if (((BootOption
[Index
].Attributes
& LOAD_OPTION_HIDDEN
) != 0) || ((BootOption
[Index
].Attributes
& LOAD_OPTION_ACTIVE
) == 0)) {
307 UnicodeSPrint (BootString
, sizeof (BootString
), L
"Boot%04x", BootOrderList
[Index
]);
309 // Get all loadoptions from the VAR
311 GetEfiGlobalVariable2 (BootString
, (VOID
**) &LoadOptionFromVar
, &BootOptionSize
);
312 if (LoadOptionFromVar
== NULL
) {
316 LoadOption
= AllocateZeroPool (BootOptionSize
);
317 if (LoadOption
== NULL
) {
321 CopyMem (LoadOption
, LoadOptionFromVar
, BootOptionSize
);
322 FreePool (LoadOptionFromVar
);
324 if (BootNext
!= NULL
) {
325 BootNextFlag
= (BOOLEAN
) (*BootNext
== BootOrderList
[Index
]);
327 BootNextFlag
= FALSE
;
330 NewMenuEntry
= BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT
);
331 ASSERT (NULL
!= NewMenuEntry
);
333 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
335 LoadOptionPtr
= LoadOption
;
336 LoadOptionEnd
= LoadOption
+ BootOptionSize
;
338 NewMenuEntry
->OptionNumber
= BootOrderList
[Index
];
339 NewLoadContext
->LoadOptionModified
= FALSE
;
340 NewLoadContext
->Deleted
= FALSE
;
341 NewLoadContext
->IsBootNext
= BootNextFlag
;
344 // Is a Legacy Device?
346 Ptr
= (UINT8
*) LoadOption
;
349 // Attribute = *(UINT32 *)Ptr;
351 Ptr
+= sizeof (UINT32
);
354 // FilePathSize = *(UINT16 *)Ptr;
356 Ptr
+= sizeof (UINT16
);
359 // Description = (CHAR16 *)Ptr;
361 Ptr
+= StrSize ((CHAR16
*) Ptr
);
364 // Now Ptr point to Device Path
366 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) Ptr
;
367 if ((BBS_DEVICE_PATH
== DevicePath
->Type
) && (BBS_BBS_DP
== DevicePath
->SubType
)) {
368 NewLoadContext
->IsLegacy
= TRUE
;
370 NewLoadContext
->IsLegacy
= FALSE
;
373 // LoadOption is a pointer type of UINT8
374 // for easy use with following LOAD_OPTION
375 // embedded in this struct
377 NewLoadContext
->LoadOption
= LoadOption
;
378 NewLoadContext
->LoadOptionSize
= BootOptionSize
;
380 NewLoadContext
->Attributes
= *(UINT32
*) LoadOptionPtr
;
381 NewLoadContext
->IsActive
= (BOOLEAN
) (NewLoadContext
->Attributes
& LOAD_OPTION_ACTIVE
);
383 NewLoadContext
->ForceReconnect
= (BOOLEAN
) (NewLoadContext
->Attributes
& LOAD_OPTION_FORCE_RECONNECT
);
385 LoadOptionPtr
+= sizeof (UINT32
);
387 NewLoadContext
->FilePathListLength
= *(UINT16
*) LoadOptionPtr
;
388 LoadOptionPtr
+= sizeof (UINT16
);
390 StringSize
= StrSize((UINT16
*)LoadOptionPtr
);
392 NewLoadContext
->Description
= AllocateZeroPool (StrSize((UINT16
*)LoadOptionPtr
));
393 ASSERT (NewLoadContext
->Description
!= NULL
);
394 StrCpyS (NewLoadContext
->Description
, StrSize((UINT16
*)LoadOptionPtr
) / sizeof (UINT16
), (UINT16
*)LoadOptionPtr
);
396 ASSERT (NewLoadContext
->Description
!= NULL
);
397 NewMenuEntry
->DisplayString
= NewLoadContext
->Description
;
398 NewMenuEntry
->DisplayStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->DisplayString
, NULL
);
400 LoadOptionPtr
+= StringSize
;
402 NewLoadContext
->FilePathList
= AllocateZeroPool (NewLoadContext
->FilePathListLength
);
403 ASSERT (NewLoadContext
->FilePathList
!= NULL
);
405 NewLoadContext
->FilePathList
,
406 (EFI_DEVICE_PATH_PROTOCOL
*) LoadOptionPtr
,
407 NewLoadContext
->FilePathListLength
410 NewMenuEntry
->HelpString
= UiDevicePathToStr (NewLoadContext
->FilePathList
);
411 NewMenuEntry
->HelpStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->HelpString
, NULL
);
413 LoadOptionPtr
+= NewLoadContext
->FilePathListLength
;
415 if (LoadOptionPtr
< LoadOptionEnd
) {
416 OptionalDataSize
= BootOptionSize
-
420 NewLoadContext
->FilePathListLength
;
422 NewLoadContext
->OptionalData
= AllocateZeroPool (OptionalDataSize
);
423 ASSERT (NewLoadContext
->OptionalData
!= NULL
);
425 NewLoadContext
->OptionalData
,
430 NewLoadContext
->OptionalDataSize
= OptionalDataSize
;
433 InsertTailList (&BootOptionMenu
.Head
, &NewMenuEntry
->Link
);
436 EfiBootManagerFreeLoadOptions (BootOption
, BootOptionCount
);
438 if (BootNext
!= NULL
) {
441 if (BootOrderList
!= NULL
) {
442 FreePool (BootOrderList
);
444 BootOptionMenu
.MenuNumber
= MenuCount
;
450 Find drivers that will be added as Driver#### variables from handles
451 in current system environment
452 All valid handles in the system except those consume SimpleFs, LoadFile
453 are stored in DriverMenu for future use.
455 @retval EFI_SUCCESS The function complets successfully.
456 @return Other value if failed to build the DriverMenu.
464 UINTN NoDevicePathHandles
;
465 EFI_HANDLE
*DevicePathHandle
;
468 BM_MENU_ENTRY
*NewMenuEntry
;
469 BM_HANDLE_CONTEXT
*NewHandleContext
;
470 EFI_HANDLE CurHandle
;
472 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*SimpleFs
;
473 EFI_LOAD_FILE_PROTOCOL
*LoadFile
;
478 InitializeListHead (&DriverMenu
.Head
);
481 // At first, get all handles that support Device Path
482 // protocol which is the basic requirement for
485 Status
= gBS
->LocateHandleBuffer (
487 &gEfiDevicePathProtocolGuid
,
489 &NoDevicePathHandles
,
492 if (EFI_ERROR (Status
)) {
497 for (Index
= 0; Index
< NoDevicePathHandles
; Index
++) {
498 CurHandle
= DevicePathHandle
[Index
];
500 Status
= gBS
->HandleProtocol (
502 &gEfiSimpleFileSystemProtocolGuid
,
505 if (Status
== EFI_SUCCESS
) {
509 Status
= gBS
->HandleProtocol (
511 &gEfiLoadFileProtocolGuid
,
514 if (Status
== EFI_SUCCESS
) {
518 NewMenuEntry
= BOpt_CreateMenuEntry (BM_HANDLE_CONTEXT_SELECT
);
519 if (NULL
== NewMenuEntry
) {
520 FreePool (DevicePathHandle
);
521 return EFI_OUT_OF_RESOURCES
;
524 NewHandleContext
= (BM_HANDLE_CONTEXT
*) NewMenuEntry
->VariableContext
;
525 NewHandleContext
->Handle
= CurHandle
;
526 NewHandleContext
->DevicePath
= DevicePathFromHandle (CurHandle
);
527 NewMenuEntry
->DisplayString
= UiDevicePathToStr (NewHandleContext
->DevicePath
);
528 NewMenuEntry
->DisplayStringToken
= HiiSetString (mBmmCallbackInfo
->BmmHiiHandle
,0,NewMenuEntry
->DisplayString
,NULL
);
529 NewMenuEntry
->HelpString
= NULL
;
530 NewMenuEntry
->HelpStringToken
= NewMenuEntry
->DisplayStringToken
;
531 NewMenuEntry
->OptionNumber
= OptionNumber
;
533 InsertTailList (&DriverMenu
.Head
, &NewMenuEntry
->Link
);
537 if (DevicePathHandle
!= NULL
) {
538 FreePool (DevicePathHandle
);
541 DriverMenu
.MenuNumber
= OptionNumber
;
547 Get the Option Number that has not been allocated for use.
549 @param Type The type of Option.
551 @return The available Option Number.
555 BOpt_GetOptionNumber (
563 UINT16
*OptionBuffer
;
572 UnicodeSPrint (StrTemp
, sizeof (StrTemp
), L
"%sOrder", Type
);
574 GetEfiGlobalVariable2 (StrTemp
, (VOID
**) &OrderList
, &OrderListSize
);
575 for (OptionNumber
= 0; ; OptionNumber
++) {
576 if (OrderList
!= NULL
) {
577 for (Index
= 0; Index
< OrderListSize
/ sizeof (UINT16
); Index
++) {
578 if (OptionNumber
== OrderList
[Index
]) {
584 if (Index
< OrderListSize
/ sizeof (UINT16
)) {
586 // The OptionNumber occurs in the OrderList, continue to use next one
590 UnicodeSPrint (StrTemp
, sizeof (StrTemp
), L
"%s%04x", Type
, (UINTN
) OptionNumber
);
591 DEBUG((EFI_D_ERROR
,"Option = %s\n", StrTemp
));
592 GetEfiGlobalVariable2 (StrTemp
, (VOID
**) &OptionBuffer
, &OptionSize
);
593 if (NULL
== OptionBuffer
) {
595 // The Boot[OptionNumber] / Driver[OptionNumber] NOT occurs, we found it
606 Get the Option Number for Boot#### that does not used.
608 @return The available Option Number.
612 BOpt_GetBootOptionNumber (
616 return BOpt_GetOptionNumber (L
"Boot");
621 Get the Option Number for Driver#### that does not used.
623 @return The unused Option Number.
627 BOpt_GetDriverOptionNumber (
631 return BOpt_GetOptionNumber (L
"Driver");
636 Build up all DriverOptionMenu
638 @param CallbackData The BMM context data.
640 @retval EFI_SUCESS The functin completes successfully.
641 @retval EFI_OUT_OF_RESOURCES Not enough memory to compete the operation.
642 @retval EFI_NOT_FOUND Fail to get "DriverOrder" variable.
646 BOpt_GetDriverOptions (
647 IN BMM_CALLBACK_DATA
*CallbackData
651 UINT16 DriverString
[12];
652 UINT8
*LoadOptionFromVar
;
654 UINTN DriverOptionSize
;
656 UINT16
*DriverOrderList
;
657 UINTN DriverOrderListSize
;
658 BM_MENU_ENTRY
*NewMenuEntry
;
659 BM_LOAD_CONTEXT
*NewLoadContext
;
660 UINT8
*LoadOptionPtr
;
662 UINTN OptionalDataSize
;
663 UINT8
*LoadOptionEnd
;
665 DriverOrderListSize
= 0;
666 DriverOrderList
= NULL
;
667 DriverOptionSize
= 0;
668 LoadOptionFromVar
= NULL
;
669 BOpt_FreeMenu (&DriverOptionMenu
);
670 InitializeListHead (&DriverOptionMenu
.Head
);
672 // Get the DriverOrder from the Var
674 GetEfiGlobalVariable2 (L
"DriverOrder", (VOID
**) &DriverOrderList
, &DriverOrderListSize
);
675 if (DriverOrderList
== NULL
) {
676 return EFI_NOT_FOUND
;
679 for (Index
= 0; Index
< DriverOrderListSize
/ sizeof (UINT16
); Index
++) {
682 sizeof (DriverString
),
684 DriverOrderList
[Index
]
687 // Get all loadoptions from the VAR
689 GetEfiGlobalVariable2 (DriverString
, (VOID
**) &LoadOptionFromVar
, &DriverOptionSize
);
690 if (LoadOptionFromVar
== NULL
) {
694 LoadOption
= AllocateZeroPool (DriverOptionSize
);
695 if (LoadOption
== NULL
) {
699 CopyMem (LoadOption
, LoadOptionFromVar
, DriverOptionSize
);
700 FreePool (LoadOptionFromVar
);
702 NewMenuEntry
= BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT
);
703 if (NULL
== NewMenuEntry
) {
704 return EFI_OUT_OF_RESOURCES
;
707 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
708 LoadOptionPtr
= LoadOption
;
709 LoadOptionEnd
= LoadOption
+ DriverOptionSize
;
710 NewMenuEntry
->OptionNumber
= DriverOrderList
[Index
];
711 NewLoadContext
->LoadOptionModified
= FALSE
;
712 NewLoadContext
->Deleted
= FALSE
;
713 NewLoadContext
->IsLegacy
= FALSE
;
716 // LoadOption is a pointer type of UINT8
717 // for easy use with following LOAD_OPTION
718 // embedded in this struct
720 NewLoadContext
->LoadOption
= LoadOption
;
721 NewLoadContext
->LoadOptionSize
= DriverOptionSize
;
723 NewLoadContext
->Attributes
= *(UINT32
*) LoadOptionPtr
;
724 NewLoadContext
->IsActive
= (BOOLEAN
) (NewLoadContext
->Attributes
& LOAD_OPTION_ACTIVE
);
726 NewLoadContext
->ForceReconnect
= (BOOLEAN
) (NewLoadContext
->Attributes
& LOAD_OPTION_FORCE_RECONNECT
);
728 LoadOptionPtr
+= sizeof (UINT32
);
730 NewLoadContext
->FilePathListLength
= *(UINT16
*) LoadOptionPtr
;
731 LoadOptionPtr
+= sizeof (UINT16
);
733 StringSize
= StrSize ((UINT16
*) LoadOptionPtr
);
734 NewLoadContext
->Description
= AllocateZeroPool (StringSize
);
735 ASSERT (NewLoadContext
->Description
!= NULL
);
737 NewLoadContext
->Description
,
738 (UINT16
*) LoadOptionPtr
,
741 NewMenuEntry
->DisplayString
= NewLoadContext
->Description
;
742 NewMenuEntry
->DisplayStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->DisplayString
, NULL
);
744 LoadOptionPtr
+= StringSize
;
746 NewLoadContext
->FilePathList
= AllocateZeroPool (NewLoadContext
->FilePathListLength
);
747 ASSERT (NewLoadContext
->FilePathList
!= NULL
);
749 NewLoadContext
->FilePathList
,
750 (EFI_DEVICE_PATH_PROTOCOL
*) LoadOptionPtr
,
751 NewLoadContext
->FilePathListLength
754 NewMenuEntry
->HelpString
= UiDevicePathToStr (NewLoadContext
->FilePathList
);
755 NewMenuEntry
->HelpStringToken
= HiiSetString (CallbackData
->BmmHiiHandle
, 0, NewMenuEntry
->HelpString
, NULL
);
757 LoadOptionPtr
+= NewLoadContext
->FilePathListLength
;
759 if (LoadOptionPtr
< LoadOptionEnd
) {
760 OptionalDataSize
= DriverOptionSize
-
764 NewLoadContext
->FilePathListLength
;
766 NewLoadContext
->OptionalData
= AllocateZeroPool (OptionalDataSize
);
767 ASSERT (NewLoadContext
->OptionalData
!= NULL
);
769 NewLoadContext
->OptionalData
,
774 NewLoadContext
->OptionalDataSize
= OptionalDataSize
;
777 InsertTailList (&DriverOptionMenu
.Head
, &NewMenuEntry
->Link
);
781 if (DriverOrderList
!= NULL
) {
782 FreePool (DriverOrderList
);
784 DriverOptionMenu
.MenuNumber
= Index
;
790 Get option number according to Boot#### and BootOrder variable.
791 The value is saved as #### + 1.
793 @param CallbackData The BMM context data.
797 IN BMM_CALLBACK_DATA
*CallbackData
800 BMM_FAKE_NV_DATA
*BmmConfig
;
802 UINT16 OptionOrderIndex
;
804 BM_MENU_ENTRY
*NewMenuEntry
;
805 BM_LOAD_CONTEXT
*NewLoadContext
;
807 ASSERT (CallbackData
!= NULL
);
809 DeviceType
= (UINTN
) -1;
810 BmmConfig
= &CallbackData
->BmmFakeNvData
;
811 ZeroMem (BmmConfig
->BootOptionOrder
, sizeof (BmmConfig
->BootOptionOrder
));
813 for (Index
= 0, OptionOrderIndex
= 0; ((Index
< BootOptionMenu
.MenuNumber
) &&
814 (OptionOrderIndex
< (sizeof (BmmConfig
->BootOptionOrder
) / sizeof (BmmConfig
->BootOptionOrder
[0]))));
816 NewMenuEntry
= BOpt_GetMenuEntry (&BootOptionMenu
, Index
);
817 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
819 if (NewLoadContext
->IsLegacy
) {
820 if (((BBS_BBS_DEVICE_PATH
*) NewLoadContext
->FilePathList
)->DeviceType
!= DeviceType
) {
821 DeviceType
= ((BBS_BBS_DEVICE_PATH
*) NewLoadContext
->FilePathList
)->DeviceType
;
824 // Only show one legacy boot option for the same device type
825 // assuming the boot options are grouped by the device type
830 BmmConfig
->BootOptionOrder
[OptionOrderIndex
++] = (UINT32
) (NewMenuEntry
->OptionNumber
+ 1);
835 Get driver option order from globalc DriverOptionMenu.
837 @param CallbackData The BMM context data.
842 IN BMM_CALLBACK_DATA
*CallbackData
845 BMM_FAKE_NV_DATA
*BmmConfig
;
847 UINT16 OptionOrderIndex
;
849 BM_MENU_ENTRY
*NewMenuEntry
;
850 BM_LOAD_CONTEXT
*NewLoadContext
;
853 ASSERT (CallbackData
!= NULL
);
855 DeviceType
= (UINTN
) -1;
856 BmmConfig
= &CallbackData
->BmmFakeNvData
;
857 ZeroMem (BmmConfig
->DriverOptionOrder
, sizeof (BmmConfig
->DriverOptionOrder
));
859 for (Index
= 0, OptionOrderIndex
= 0; ((Index
< DriverOptionMenu
.MenuNumber
) &&
860 (OptionOrderIndex
< (sizeof (BmmConfig
->DriverOptionOrder
) / sizeof (BmmConfig
->DriverOptionOrder
[0]))));
862 NewMenuEntry
= BOpt_GetMenuEntry (&DriverOptionMenu
, Index
);
863 NewLoadContext
= (BM_LOAD_CONTEXT
*) NewMenuEntry
->VariableContext
;
865 if (NewLoadContext
->IsLegacy
) {
866 if (((BBS_BBS_DEVICE_PATH
*) NewLoadContext
->FilePathList
)->DeviceType
!= DeviceType
) {
867 DeviceType
= ((BBS_BBS_DEVICE_PATH
*) NewLoadContext
->FilePathList
)->DeviceType
;
870 // Only show one legacy boot option for the same device type
871 // assuming the boot options are grouped by the device type
876 BmmConfig
->DriverOptionOrder
[OptionOrderIndex
++] = (UINT32
) (NewMenuEntry
->OptionNumber
+ 1);
881 Boot the file specified by the input file path info.
883 @param FilePath Point to the file path.
885 @retval TRUE Exit caller function.
886 @retval FALSE Not exit caller function.
890 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
893 EFI_BOOT_MANAGER_LOAD_OPTION BootOption
;
896 FileName
= ExtractFileNameFromDevicePath(FilePath
);
897 EfiBootManagerInitializeLoadOption (
908 // Since current no boot from removable media directly is allowed */
910 gST
->ConOut
->ClearScreen (gST
->ConOut
);
912 BmmBdsSetConsoleMode (FALSE
);
913 EfiBootManagerBoot (&BootOption
);
914 BmmBdsSetConsoleMode (TRUE
);
918 EfiBootManagerFreeLoadOption (&BootOption
);
924 Display the form base on the selected file.
926 @param FilePath Point to the file path.
927 @param FormId The form need to display.
932 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
933 IN EFI_FORM_ID FormId
936 gBootMaintenancePrivate
.LoadContext
->FilePathList
= FilePath
;
938 UpdateOptionPage(&gBootMaintenancePrivate
, FormId
, FilePath
);
940 gBootMaintenancePrivate
.FormBrowser2
->SendForm (
941 gBootMaintenancePrivate
.FormBrowser2
,
942 &gBootMaintenancePrivate
.BmmHiiHandle
,
953 Create boot option base on the input file path info.
955 @param FilePath Point to the file path.
957 @retval TRUE Exit caller function.
958 @retval FALSE Not exit caller function.
961 CreateBootOptionFromFile (
962 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
965 return ReSendForm(FilePath
, FORM_BOOT_ADD_ID
);
969 Create driver option base on the input file path info.
971 @param FilePath Point to the file path.
973 @retval TRUE Exit caller function.
974 @retval FALSE Not exit caller function.
978 CreateDriverOptionFromFile (
979 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
982 return ReSendForm(FilePath
, FORM_DRV_ADD_FILE_ID
);