2 The platform boot manager reference implement
4 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "BootManager.h"
18 EFI_GUID mBootManagerGuid
= BOOT_MANAGER_FORMSET_GUID
;
19 LIST_ENTRY
*mBootOptionsList
;
20 BDS_COMMON_OPTION
*gOption
;
22 BOOT_MANAGER_CALLBACK_DATA gBootManagerPrivate
= {
23 BOOT_MANAGER_CALLBACK_DATA_SIGNATURE
,
34 This call back funtion is registered with Boot Manager formset.
35 When user selects a boot option, this call back function will
36 be triggered. The boot option is saved for later processing.
39 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
40 @param Action Specifies the type of action taken by the browser.
41 @param QuestionId A unique value which is sent to the original exporting driver
42 so that it can identify the type of data to expect.
43 @param Type The type of value for the question.
44 @param Value A pointer to the data being sent to the original exporting driver.
45 @param ActionRequest On return, points to the action requested by the callback function.
47 @retval EFI_SUCCESS The callback successfully handled the action.
48 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
54 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
55 IN EFI_BROWSER_ACTION Action
,
56 IN EFI_QUESTION_ID QuestionId
,
58 IN EFI_IFR_TYPE_VALUE
*Value
,
59 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
62 BDS_COMMON_OPTION
*Option
;
66 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
67 return EFI_INVALID_PARAMETER
;
71 // Initialize the key count
75 for (Link
= mBootOptionsList
->ForwardLink
; Link
!= mBootOptionsList
; Link
= Link
->ForwardLink
) {
76 Option
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
83 // Is this device the one chosen?
85 if (KeyCount
== QuestionId
) {
87 // Assigning the returned Key to a global allows the original routine to know what was chosen
89 mKeyInput
= QuestionId
;
92 // Request to exit SendForm(), so that we could boot the selected option
94 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
104 Registers HII packages for the Boot Manger to HII Database.
105 It also registers the browser call back function.
108 @return EDES_TODO: Add description for return value
112 InitializeBootManager (
117 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
120 // Create driver handle used by HII database
122 Status
= HiiLibCreateHiiDriverHandle (&gBootManagerPrivate
.DriverHandle
);
123 if (EFI_ERROR (Status
)) {
128 // Install Config Access protocol to driver handle
130 Status
= gBS
->InstallProtocolInterface (
131 &gBootManagerPrivate
.DriverHandle
,
132 &gEfiHiiConfigAccessProtocolGuid
,
133 EFI_NATIVE_INTERFACE
,
134 &gBootManagerPrivate
.ConfigAccess
136 ASSERT_EFI_ERROR (Status
);
139 // Publish our HII data
141 PackageList
= HiiLibPreparePackageList (2, &mBootManagerGuid
, BootManagerVfrBin
, BdsDxeStrings
);
142 ASSERT (PackageList
!= NULL
);
144 Status
= gHiiDatabase
->NewPackageList (
147 gBootManagerPrivate
.DriverHandle
,
148 &gBootManagerPrivate
.HiiHandle
150 FreePool (PackageList
);
156 This funtion invokees Boot Manager. If all devices have not a chance to be connected,
157 the connect all will be triggered. It then enumerate all boot options. If
158 a boot option from the Boot Manager page is selected, Boot Manager will boot
159 from this boot option.
168 BDS_COMMON_OPTION
*Option
;
170 EFI_HII_UPDATE_DATA UpdateData
;
175 LIST_ENTRY BdsBootOptionList
;
177 EFI_STRING_ID HelpToken
;
179 EFI_HII_HANDLE HiiHandle
;
180 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
184 InitializeListHead (&BdsBootOptionList
);
187 // Connect all prior to entering the platform setup menu.
189 if (!gConnectAllHappened
) {
190 BdsLibConnectAllDriversToAllControllers ();
191 gConnectAllHappened
= TRUE
;
194 // BugBug: Here we can not remove the legacy refresh macro, so we need
195 // get the boot order every time from "BootOrder" variable.
196 // Recreate the boot option list base on the BootOrder variable
198 BdsLibEnumerateAllBootOption (&BdsBootOptionList
);
200 mBootOptionsList
= &BdsBootOptionList
;
202 HiiHandle
= gBootManagerPrivate
.HiiHandle
;
205 // Allocate space for creation of UpdateData Buffer
207 UpdateData
.BufferSize
= 0x1000;
208 UpdateData
.Offset
= 0;
209 UpdateData
.Data
= AllocateZeroPool (0x1000);
210 ASSERT (UpdateData
.Data
!= NULL
);
214 for (Link
= BdsBootOptionList
.ForwardLink
; Link
!= &BdsBootOptionList
; Link
= Link
->ForwardLink
) {
215 Option
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
218 // At this stage we are creating a menu entry, thus the Keys are reproduceable
223 // Don't display the boot option marked as LOAD_OPTION_HIDDEN
225 if (Option
->Attribute
& LOAD_OPTION_HIDDEN
) {
229 HiiLibNewString (HiiHandle
, &Token
, Option
->Description
);
231 TempStr
= DevicePathToStr (Option
->DevicePath
);
232 TempSize
= StrSize (TempStr
);
233 HelpString
= AllocateZeroPool (TempSize
+ StrSize (L
"Device Path : "));
234 StrCat (HelpString
, L
"Device Path : ");
235 StrCat (HelpString
, TempStr
);
237 HiiLibNewString (HiiHandle
, &HelpToken
, HelpString
);
243 EFI_IFR_FLAG_CALLBACK
,
252 BOOT_MANAGER_FORM_ID
,
257 FreePool (UpdateData
.Data
);
260 // Drop the TPL level from TPL_APPLICATION to TPL_APPLICATION
262 gBS
->RestoreTPL (TPL_APPLICATION
);
264 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
265 Status
= gFormBrowser2
->SendForm (
274 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
275 EnableResetRequired ();
278 if (gOption
== NULL
) {
279 gBS
->RaiseTPL (TPL_APPLICATION
);
284 //Will leave browser, check any reset required change is applied? if yes, reset system
286 SetupResetReminder ();
289 // Raise the TPL level back to TPL_APPLICATION
291 gBS
->RaiseTPL (TPL_APPLICATION
);
294 // parse the selected option
296 Status
= BdsLibBootViaBootOption (gOption
, gOption
->DevicePath
, &ExitDataSize
, &ExitData
);
298 if (!EFI_ERROR (Status
)) {
299 gOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED
));
300 PlatformBdsBootSuccess (gOption
);
302 gOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_FAILED
));
303 PlatformBdsBootFail (gOption
, Status
, ExitData
, ExitDataSize
);
304 gST
->ConOut
->OutputString (
306 GetStringById (STRING_TOKEN (STR_ANY_KEY_CONTINUE
))
308 gBS
->RestoreTPL (TPL_APPLICATION
);
310 // BdsLibUiWaitForSingleEvent (gST->ConIn->WaitForKey, 0);
312 gBS
->RaiseTPL (TPL_APPLICATION
);
313 gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);