2 The boot manager reference implementation
4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "BootManager.h"
12 EFI_GUID mBootManagerGuid
= BOOT_MANAGER_FORMSET_GUID
;
14 // Boot video resolution and text mode.
16 UINT32 mBmBootHorizontalResolution
= 0;
17 UINT32 mBmBootVerticalResolution
= 0;
18 UINT32 mBmBootTextModeColumn
= 0;
19 UINT32 mBmBootTextModeRow
= 0;
21 // BIOS setup video resolution and text mode.
23 UINT32 mBmSetupTextModeColumn
= 0;
24 UINT32 mBmSetupTextModeRow
= 0;
25 UINT32 mBmSetupHorizontalResolution
= 0;
26 UINT32 mBmSetupVerticalResolution
= 0;
28 BOOLEAN mBmModeInitialized
= FALSE
;
30 CHAR16
*mDeviceTypeStr
[] = {
37 L
"Legacy Embedded Network",
38 L
"Legacy Unknown Device"
41 HII_VENDOR_DEVICE_PATH mBootManagerHiiVendorDevicePath
= {
47 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
48 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
52 // {1DDDBE15-481D-4d2b-8277-B191EAF66525}
54 { 0x1dddbe15, 0x481d, 0x4d2b, { 0x82, 0x77, 0xb1, 0x91, 0xea, 0xf6, 0x65, 0x25 } }
58 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
60 (UINT8
) (END_DEVICE_PATH_LENGTH
),
61 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
66 BOOT_MANAGER_CALLBACK_DATA gBootManagerPrivate
= {
67 BOOT_MANAGER_CALLBACK_DATA_SIGNATURE
,
71 BootManagerExtractConfig
,
72 BootManagerRouteConfig
,
78 This function will change video resolution and text mode
79 according to defined setup mode or defined boot mode
81 @param IsSetupMode Indicate mode is changed to setup mode or boot mode.
83 @retval EFI_SUCCESS Mode is changed successfully.
84 @retval Others Mode failed to be changed.
92 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
93 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
95 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
99 UINT32 NewHorizontalResolution
;
100 UINT32 NewVerticalResolution
;
104 EFI_HANDLE
*HandleBuffer
;
114 // Get current video resolution and text mode
116 Status
= gBS
->HandleProtocol (
117 gST
->ConsoleOutHandle
,
118 &gEfiGraphicsOutputProtocolGuid
,
119 (VOID
**)&GraphicsOutput
121 if (EFI_ERROR (Status
)) {
122 GraphicsOutput
= NULL
;
125 Status
= gBS
->HandleProtocol (
126 gST
->ConsoleOutHandle
,
127 &gEfiSimpleTextOutProtocolGuid
,
128 (VOID
**)&SimpleTextOut
130 if (EFI_ERROR (Status
)) {
131 SimpleTextOut
= NULL
;
134 if ((GraphicsOutput
== NULL
) || (SimpleTextOut
== NULL
)) {
135 return EFI_UNSUPPORTED
;
140 // The required resolution and text mode is setup mode.
142 NewHorizontalResolution
= mBmSetupHorizontalResolution
;
143 NewVerticalResolution
= mBmSetupVerticalResolution
;
144 NewColumns
= mBmSetupTextModeColumn
;
145 NewRows
= mBmSetupTextModeRow
;
148 // The required resolution and text mode is boot mode.
150 NewHorizontalResolution
= mBmBootHorizontalResolution
;
151 NewVerticalResolution
= mBmBootVerticalResolution
;
152 NewColumns
= mBmBootTextModeColumn
;
153 NewRows
= mBmBootTextModeRow
;
156 if (GraphicsOutput
!= NULL
) {
157 MaxGopMode
= GraphicsOutput
->Mode
->MaxMode
;
160 if (SimpleTextOut
!= NULL
) {
161 MaxTextMode
= SimpleTextOut
->Mode
->MaxMode
;
165 // 1. If current video resolution is same with required video resolution,
166 // video resolution need not be changed.
167 // 1.1. If current text mode is same with required text mode, text mode need not be changed.
168 // 1.2. If current text mode is different from required text mode, text mode need be changed.
169 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.
171 for (ModeNumber
= 0; ModeNumber
< MaxGopMode
; ModeNumber
++) {
172 Status
= GraphicsOutput
->QueryMode (
178 if (!EFI_ERROR (Status
)) {
179 if ((Info
->HorizontalResolution
== NewHorizontalResolution
) &&
180 (Info
->VerticalResolution
== NewVerticalResolution
)) {
181 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== NewHorizontalResolution
) &&
182 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== NewVerticalResolution
)) {
184 // Current resolution is same with required resolution, check if text mode need be set
186 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, SimpleTextOut
->Mode
->Mode
, &CurrentColumn
, &CurrentRow
);
187 ASSERT_EFI_ERROR (Status
);
188 if (CurrentColumn
== NewColumns
&& CurrentRow
== NewRows
) {
190 // If current text mode is same with required text mode. Do nothing
196 // If current text mode is different from required text mode. Set new video mode
198 for (Index
= 0; Index
< MaxTextMode
; Index
++) {
199 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, Index
, &CurrentColumn
, &CurrentRow
);
200 if (!EFI_ERROR(Status
)) {
201 if ((CurrentColumn
== NewColumns
) && (CurrentRow
== NewRows
)) {
203 // Required text mode is supported, set it.
205 Status
= SimpleTextOut
->SetMode (SimpleTextOut
, Index
);
206 ASSERT_EFI_ERROR (Status
);
208 // Update text mode PCD.
210 Status
= PcdSet32S (PcdConOutColumn
, mBmSetupTextModeColumn
);
211 ASSERT_EFI_ERROR (Status
);
212 Status
= PcdSet32S (PcdConOutRow
, mBmSetupTextModeRow
);
213 ASSERT_EFI_ERROR (Status
);
219 if (Index
== MaxTextMode
) {
221 // If required text mode is not supported, return error.
224 return EFI_UNSUPPORTED
;
229 // If current video resolution is not same with the new one, set new video resolution.
230 // In this case, the driver which produces simple text out need be restarted.
232 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
233 if (!EFI_ERROR (Status
)) {
243 if (ModeNumber
== MaxGopMode
) {
245 // If the resolution is not supported, return error.
247 return EFI_UNSUPPORTED
;
251 // Set PCD to Inform GraphicsConsole to change video resolution.
252 // Set PCD to Inform Consplitter to change text mode.
254 Status
= PcdSet32S (PcdVideoHorizontalResolution
, NewHorizontalResolution
);
255 ASSERT_EFI_ERROR (Status
);
256 Status
= PcdSet32S (PcdVideoVerticalResolution
, NewVerticalResolution
);
257 ASSERT_EFI_ERROR (Status
);
258 Status
= PcdSet32S (PcdConOutColumn
, NewColumns
);
259 ASSERT_EFI_ERROR (Status
);
260 Status
= PcdSet32S (PcdConOutRow
, NewRows
);
261 ASSERT_EFI_ERROR (Status
);
264 // Video mode is changed, so restart graphics console driver and higher level driver.
265 // Reconnect graphics console driver and higher level driver.
266 // Locate all the handles with GOP protocol and reconnect it.
268 Status
= gBS
->LocateHandleBuffer (
270 &gEfiSimpleTextOutProtocolGuid
,
275 if (!EFI_ERROR (Status
)) {
276 for (Index
= 0; Index
< HandleCount
; Index
++) {
277 gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
279 for (Index
= 0; Index
< HandleCount
; Index
++) {
280 gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
282 if (HandleBuffer
!= NULL
) {
283 FreePool (HandleBuffer
);
292 Check whether a reset is needed,if reset is needed, Popup a menu to notice user.
296 BmSetupResetReminder (
301 CHAR16
*StringBuffer1
;
302 CHAR16
*StringBuffer2
;
304 EDKII_FORM_BROWSER_EXTENSION2_PROTOCOL
*FormBrowserEx2
;
307 // Use BrowserEx2 protocol to check whether reset is required.
309 Status
= gBS
->LocateProtocol (&gEdkiiFormBrowserEx2ProtocolGuid
, NULL
, (VOID
**) &FormBrowserEx2
);
311 //check any reset required change is applied? if yes, reset system
313 if (!EFI_ERROR(Status
) && FormBrowserEx2
->IsResetRequired ()) {
314 StringBuffer1
= AllocateZeroPool (MAX_STRING_LEN
* sizeof (CHAR16
));
315 ASSERT (StringBuffer1
!= NULL
);
316 StringBuffer2
= AllocateZeroPool (MAX_STRING_LEN
* sizeof (CHAR16
));
317 ASSERT (StringBuffer2
!= NULL
);
318 StrCpyS (StringBuffer1
, MAX_STRING_LEN
, L
"Configuration changed. Reset to apply it Now.");
319 StrCpyS (StringBuffer2
, MAX_STRING_LEN
, L
"Press ENTER to reset");
321 // Popup a menu to notice user
324 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, StringBuffer1
, StringBuffer2
, NULL
);
325 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
327 FreePool (StringBuffer1
);
328 FreePool (StringBuffer2
);
330 gRT
->ResetSystem (EfiResetCold
, EFI_SUCCESS
, 0, NULL
);
335 Group the legacy boot options in the BootOption.
337 The routine assumes the boot options in the beginning that covers all the device
338 types are ordered properly and re-position the following boot options just after
339 the corresponding boot options with the same device type.
341 1. Input = [Harddisk1 CdRom2 Efi1 Harddisk0 CdRom0 CdRom1 Harddisk2 Efi0]
342 Assuming [Harddisk1 CdRom2 Efi1] is ordered properly
343 Output = [Harddisk1 Harddisk0 Harddisk2 CdRom2 CdRom0 CdRom1 Efi1 Efi0]
345 2. Input = [Efi1 Efi0 CdRom1 Harddisk0 Harddisk1 Harddisk2 CdRom0 CdRom2]
346 Assuming [Efi1 Efi0 CdRom1 Harddisk0] is ordered properly
347 Output = [Efi1 Efi0 CdRom1 CdRom0 CdRom2 Harddisk0 Harddisk1 Harddisk2]
351 GroupMultipleLegacyBootOption4SameType (
358 UINTN DeviceTypeIndex
[7];
363 CHAR16 OptionName
[sizeof ("Boot####")];
364 EFI_BOOT_MANAGER_LOAD_OPTION BootOption
;
366 SetMem (DeviceTypeIndex
, sizeof (DeviceTypeIndex
), 0xff);
368 GetEfiGlobalVariable2 (L
"BootOrder", (VOID
**) &BootOrder
, &BootOrderSize
);
369 if (BootOrder
== NULL
) {
373 for (Index
= 0; Index
< BootOrderSize
/ sizeof (UINT16
); Index
++) {
374 UnicodeSPrint (OptionName
, sizeof (OptionName
), L
"Boot%04x", BootOrder
[Index
]);
375 Status
= EfiBootManagerVariableToLoadOption (OptionName
, &BootOption
);
376 ASSERT_EFI_ERROR (Status
);
378 if ((DevicePathType (BootOption
.FilePath
) == BBS_DEVICE_PATH
) &&
379 (DevicePathSubType (BootOption
.FilePath
) == BBS_BBS_DP
)) {
381 // Legacy Boot Option
383 DEBUG ((EFI_D_ERROR
, "[BootManagerDxe] ==== Find Legacy Boot Option 0x%x! ==== \n", Index
));
384 ASSERT ((((BBS_BBS_DEVICE_PATH
*) BootOption
.FilePath
)->DeviceType
& 0xF) < ARRAY_SIZE (DeviceTypeIndex
));
385 NextIndex
= &DeviceTypeIndex
[((BBS_BBS_DEVICE_PATH
*) BootOption
.FilePath
)->DeviceType
& 0xF];
387 if (*NextIndex
== (UINTN
) -1) {
389 // *NextIndex is the Index in BootOrder to put the next Option Number for the same type
391 *NextIndex
= Index
+ 1;
394 // insert the current boot option before *NextIndex, causing [*Next .. Index] shift right one position
396 OptionNumber
= BootOrder
[Index
];
397 CopyMem (&BootOrder
[*NextIndex
+ 1], &BootOrder
[*NextIndex
], (Index
- *NextIndex
) * sizeof (UINT16
));
398 BootOrder
[*NextIndex
] = OptionNumber
;
401 // Update the DeviceTypeIndex array to reflect the right shift operation
403 for (DeviceIndex
= 0; DeviceIndex
< ARRAY_SIZE (DeviceTypeIndex
); DeviceIndex
++) {
404 if (DeviceTypeIndex
[DeviceIndex
] != (UINTN
) -1 && DeviceTypeIndex
[DeviceIndex
] >= *NextIndex
) {
405 DeviceTypeIndex
[DeviceIndex
]++;
410 EfiBootManagerFreeLoadOption (&BootOption
);
415 &gEfiGlobalVariableGuid
,
420 FreePool (BootOrder
);
424 This function converts an input device structure to a Unicode string.
426 @param DevPath A pointer to the device path structure.
428 @return A new allocated Unicode string that represents the device path.
433 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
438 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
*DevPathToText
;
440 if (DevPath
== NULL
) {
444 Status
= gBS
->LocateProtocol (
445 &gEfiDevicePathToTextProtocolGuid
,
447 (VOID
**) &DevPathToText
449 ASSERT_EFI_ERROR (Status
);
450 ToText
= DevPathToText
->ConvertDevicePathToText (
455 ASSERT (ToText
!= NULL
);
460 This function invokes Boot Manager. It then enumerate all boot options. If
461 a boot option from the Boot Manager page is selected, Boot Manager will boot
462 from this boot option.
471 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
;
472 UINTN BootOptionCount
;
475 EFI_STRING_ID HelpToken
;
477 EFI_HII_HANDLE HiiHandle
;
479 VOID
*StartOpCodeHandle
;
480 VOID
*EndOpCodeHandle
;
481 EFI_IFR_GUID_LABEL
*StartLabel
;
482 EFI_IFR_GUID_LABEL
*EndLabel
;
484 BOOLEAN IsLegacyOption
;
488 DeviceType
= (UINT16
) -1;
491 // for better user experience
492 // 1. User changes HD configuration (e.g.: unplug HDD), here we have a chance to remove the HDD boot option
493 // 2. User enables/disables UEFI PXE, here we have a chance to add/remove EFI Network boot option
495 EfiBootManagerRefreshAllBootOption ();
498 // BdsDxe doesn't group the legacy boot options for the same device type
501 GroupMultipleLegacyBootOption4SameType ();
503 BootOption
= EfiBootManagerGetLoadOptions (&BootOptionCount
, LoadOptionTypeBoot
);
505 HiiHandle
= gBootManagerPrivate
.HiiHandle
;
508 // Allocate space for creation of UpdateData Buffer
510 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
511 ASSERT (StartOpCodeHandle
!= NULL
);
513 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
514 ASSERT (EndOpCodeHandle
!= NULL
);
517 // Create Hii Extend Label OpCode as the start opcode
519 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
520 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
521 StartLabel
->Number
= LABEL_BOOT_OPTION
;
524 // Create Hii Extend Label OpCode as the end opcode
526 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
527 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
528 EndLabel
->Number
= LABEL_BOOT_OPTION_END
;
531 for (Index
= 0; Index
< BootOptionCount
; Index
++) {
533 // At this stage we are creating a menu entry, thus the Keys are reproduceable
538 // Don't display the hidden/inactive boot option
540 if (((BootOption
[Index
].Attributes
& LOAD_OPTION_HIDDEN
) != 0) || ((BootOption
[Index
].Attributes
& LOAD_OPTION_ACTIVE
) == 0)) {
545 // Group the legacy boot option in the sub title created dynamically
547 IsLegacyOption
= (BOOLEAN
) (
548 (DevicePathType (BootOption
[Index
].FilePath
) == BBS_DEVICE_PATH
) &&
549 (DevicePathSubType (BootOption
[Index
].FilePath
) == BBS_BBS_DP
)
552 if (!IsLegacyOption
&& NeedEndOp
) {
554 HiiCreateEndOpCode (StartOpCodeHandle
);
557 if (IsLegacyOption
&& DeviceType
!= ((BBS_BBS_DEVICE_PATH
*) BootOption
[Index
].FilePath
)->DeviceType
) {
559 HiiCreateEndOpCode (StartOpCodeHandle
);
562 DeviceType
= ((BBS_BBS_DEVICE_PATH
*) BootOption
[Index
].FilePath
)->DeviceType
;
563 Token
= HiiSetString (
567 MIN (DeviceType
& 0xF, ARRAY_SIZE (mDeviceTypeStr
) - 1)
571 HiiCreateSubTitleOpCode (StartOpCodeHandle
, Token
, 0, 0, 1);
575 ASSERT (BootOption
[Index
].Description
!= NULL
);
577 Token
= HiiSetString (HiiHandle
, 0, BootOption
[Index
].Description
, NULL
);
579 TempStr
= BmDevicePathToStr (BootOption
[Index
].FilePath
);
580 TempSize
= StrSize (TempStr
);
581 HelpString
= AllocateZeroPool (TempSize
+ StrSize (L
"Device Path : "));
582 MaxLen
= (TempSize
+ StrSize (L
"Device Path : "))/sizeof(CHAR16
);
583 ASSERT (HelpString
!= NULL
);
584 StrCatS (HelpString
, MaxLen
, L
"Device Path : ");
585 StrCatS (HelpString
, MaxLen
, TempStr
);
587 HelpToken
= HiiSetString (HiiHandle
, 0, HelpString
, NULL
);
589 HiiCreateActionOpCode (
594 EFI_IFR_FLAG_CALLBACK
,
600 HiiCreateEndOpCode (StartOpCodeHandle
);
606 BOOT_MANAGER_FORM_ID
,
611 HiiFreeOpCodeHandle (StartOpCodeHandle
);
612 HiiFreeOpCodeHandle (EndOpCodeHandle
);
614 EfiBootManagerFreeLoadOptions (BootOption
, BootOptionCount
);
618 This function allows a caller to extract the current configuration for one
619 or more named elements from the target driver.
622 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
623 @param Request A null-terminated Unicode string in <ConfigRequest> format.
624 @param Progress On return, points to a character in the Request string.
625 Points to the string's null terminator if request was successful.
626 Points to the most recent '&' before the first failing name/value
627 pair (or the beginning of the string if the failure is in the
628 first name/value pair) if the request was not successful.
629 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
630 has all values filled in for the names in the Request string.
631 String to be allocated by the called function.
633 @retval EFI_SUCCESS The Results is filled with the requested values.
634 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
635 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
636 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
641 BootManagerExtractConfig (
642 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
643 IN CONST EFI_STRING Request
,
644 OUT EFI_STRING
*Progress
,
645 OUT EFI_STRING
*Results
648 if (Progress
== NULL
|| Results
== NULL
) {
649 return EFI_INVALID_PARAMETER
;
652 return EFI_NOT_FOUND
;
656 This function processes the results of changes in configuration.
659 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
660 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
661 @param Progress A pointer to a string filled in with the offset of the most
662 recent '&' before the first failing name/value pair (or the
663 beginning of the string if the failure is in the first
664 name/value pair) or the terminating NULL if all was successful.
666 @retval EFI_SUCCESS The Results is processed successfully.
667 @retval EFI_INVALID_PARAMETER Configuration is NULL.
668 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
673 BootManagerRouteConfig (
674 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
675 IN CONST EFI_STRING Configuration
,
676 OUT EFI_STRING
*Progress
679 if (Configuration
== NULL
|| Progress
== NULL
) {
680 return EFI_INVALID_PARAMETER
;
683 *Progress
= Configuration
;
685 return EFI_NOT_FOUND
;
689 Initial the boot mode related parameters.
693 BmInitialBootModeInfo (
698 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
699 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
700 UINTN BootTextColumn
;
703 if (mBmModeInitialized
) {
708 // After the console is ready, get current video resolution
709 // and text mode before launching setup at first time.
711 Status
= gBS
->HandleProtocol (
712 gST
->ConsoleOutHandle
,
713 &gEfiGraphicsOutputProtocolGuid
,
714 (VOID
**)&GraphicsOutput
716 if (EFI_ERROR (Status
)) {
717 GraphicsOutput
= NULL
;
720 Status
= gBS
->HandleProtocol (
721 gST
->ConsoleOutHandle
,
722 &gEfiSimpleTextOutProtocolGuid
,
723 (VOID
**)&SimpleTextOut
725 if (EFI_ERROR (Status
)) {
726 SimpleTextOut
= NULL
;
729 if (GraphicsOutput
!= NULL
) {
731 // Get current video resolution and text mode.
733 mBmBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
734 mBmBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
737 if (SimpleTextOut
!= NULL
) {
738 Status
= SimpleTextOut
->QueryMode (
740 SimpleTextOut
->Mode
->Mode
,
744 mBmBootTextModeColumn
= (UINT32
)BootTextColumn
;
745 mBmBootTextModeRow
= (UINT32
)BootTextRow
;
749 // Get user defined text mode for setup.
751 mBmSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
752 mBmSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
753 mBmSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
754 mBmSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
756 mBmModeInitialized
= TRUE
;
760 This call back function is registered with Boot Manager formset.
761 When user selects a boot option, this call back function will
762 be triggered. The boot option is saved for later processing.
765 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
766 @param Action Specifies the type of action taken by the browser.
767 @param QuestionId A unique value which is sent to the original exporting driver
768 so that it can identify the type of data to expect.
769 @param Type The type of value for the question.
770 @param Value A pointer to the data being sent to the original exporting driver.
771 @param ActionRequest On return, points to the action requested by the callback function.
773 @retval EFI_SUCCESS The callback successfully handled the action.
774 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
779 BootManagerCallback (
780 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
781 IN EFI_BROWSER_ACTION Action
,
782 IN EFI_QUESTION_ID QuestionId
,
784 IN EFI_IFR_TYPE_VALUE
*Value
,
785 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
788 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
;
789 UINTN BootOptionCount
;
792 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
794 //Means enter the boot manager form.
795 //Update the boot manage page,because the boot option may changed.
797 if (QuestionId
== 0x1212){
803 if (Action
!= EFI_BROWSER_ACTION_CHANGED
) {
805 // Do nothing for other UEFI Action. Only do call back when data is changed.
807 return EFI_UNSUPPORTED
;
810 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
811 return EFI_INVALID_PARAMETER
;
814 BootOption
= EfiBootManagerGetLoadOptions (&BootOptionCount
, LoadOptionTypeBoot
);
817 // Clear the screen before.
819 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
820 gST
->ConOut
->ClearScreen (gST
->ConOut
);
823 //check any reset required change is applied? if yes, reset system
825 BmSetupResetReminder ();
828 // parse the selected option
830 BmSetConsoleMode (FALSE
);
831 EfiBootManagerBoot (&BootOption
[QuestionId
- 1]);
832 BmSetConsoleMode (TRUE
);
834 if (EFI_ERROR (BootOption
[QuestionId
- 1].Status
)) {
835 gST
->ConOut
->OutputString (
837 HiiGetString (gBootManagerPrivate
.HiiHandle
, STRING_TOKEN (STR_ANY_KEY_CONTINUE
), NULL
)
839 gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
842 EfiBootManagerFreeLoadOptions (BootOption
, BootOptionCount
);
849 Install Boot Manager Menu driver.
851 @param ImageHandle The image handle.
852 @param SystemTable The system table.
854 @retval EFI_SUCEESS Install Boot manager menu success.
855 @retval Other Return error status.
860 BootManagerUiLibConstructor (
861 IN EFI_HANDLE ImageHandle
,
862 IN EFI_SYSTEM_TABLE
*SystemTable
868 // Install Device Path Protocol and Config Access protocol to driver handle
870 gBootManagerPrivate
.DriverHandle
= NULL
;
871 Status
= gBS
->InstallMultipleProtocolInterfaces (
872 &gBootManagerPrivate
.DriverHandle
,
873 &gEfiDevicePathProtocolGuid
,
874 &mBootManagerHiiVendorDevicePath
,
875 &gEfiHiiConfigAccessProtocolGuid
,
876 &gBootManagerPrivate
.ConfigAccess
,
879 ASSERT_EFI_ERROR (Status
);
882 // Publish our HII data
884 gBootManagerPrivate
.HiiHandle
= HiiAddPackages (
886 gBootManagerPrivate
.DriverHandle
,
888 BootManagerUiLibStrings
,
891 ASSERT (gBootManagerPrivate
.HiiHandle
!= NULL
);
893 BmInitialBootModeInfo ();
899 Unloads the application and its installed protocol.
901 @param[in] ImageHandle Handle that identifies the image to be unloaded.
902 @param[in] SystemTable System Table
904 @retval EFI_SUCCESS The image has been unloaded.
908 BootManagerUiLibDestructor (
909 IN EFI_HANDLE ImageHandle
,
910 IN EFI_SYSTEM_TABLE
*SystemTable
915 Status
= gBS
->UninstallMultipleProtocolInterfaces (
916 gBootManagerPrivate
.DriverHandle
,
917 &gEfiDevicePathProtocolGuid
,
918 &mBootManagerHiiVendorDevicePath
,
919 &gEfiHiiConfigAccessProtocolGuid
,
920 &gBootManagerPrivate
.ConfigAccess
,
923 ASSERT_EFI_ERROR (Status
);
925 HiiRemovePackages (gBootManagerPrivate
.HiiHandle
);