3 Copyright (c) 2004 - 2008, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 The platform boot manager reference implement
22 #include "BootManager.h"
25 EFI_GUID mBootManagerGuid
= BOOT_MANAGER_FORMSET_GUID
;
26 LIST_ENTRY
*mBootOptionsList
;
27 BDS_COMMON_OPTION
*gOption
;
29 BOOT_MANAGER_CALLBACK_DATA gBootManagerPrivate
= {
30 BOOT_MANAGER_CALLBACK_DATA_SIGNATURE
,
43 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
44 IN EFI_BROWSER_ACTION Action
,
45 IN EFI_QUESTION_ID QuestionId
,
47 IN EFI_IFR_TYPE_VALUE
*Value
,
48 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
53 This function processes the results of changes in configuration.
56 This - Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
57 Action - Specifies the type of action taken by the browser.
58 QuestionId - A unique value which is sent to the original exporting driver
59 so that it can identify the type of data to expect.
60 Type - The type of value for the question.
61 Value - A pointer to the data being sent to the original exporting driver.
62 ActionRequest - On return, points to the action requested by the callback function.
65 EFI_SUCCESS - The callback successfully handled the action.
66 EFI_OUT_OF_RESOURCES - Not enough storage is available to hold the variable and its data.
67 EFI_DEVICE_ERROR - The variable could not be saved.
68 EFI_UNSUPPORTED - The specified Action is not supported by the callback.
72 BDS_COMMON_OPTION
*Option
;
76 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
77 return EFI_INVALID_PARAMETER
;
81 // Initialize the key count
85 for (Link
= mBootOptionsList
->ForwardLink
; Link
!= mBootOptionsList
; Link
= Link
->ForwardLink
) {
86 Option
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
93 // Is this device the one chosen?
95 if (KeyCount
== QuestionId
) {
97 // Assigning the returned Key to a global allows the original routine to know what was chosen
99 mKeyInput
= QuestionId
;
102 // Request to exit SendForm(), so that we could boot the selected option
104 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
113 InitializeBootManager (
120 Initialize HII information for the FrontPage
130 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
133 // Create driver handle used by HII database
135 Status
= HiiLibCreateHiiDriverHandle (&gBootManagerPrivate
.DriverHandle
);
136 if (EFI_ERROR (Status
)) {
141 // Install Config Access protocol to driver handle
143 Status
= gBS
->InstallProtocolInterface (
144 &gBootManagerPrivate
.DriverHandle
,
145 &gEfiHiiConfigAccessProtocolGuid
,
146 EFI_NATIVE_INTERFACE
,
147 &gBootManagerPrivate
.ConfigAccess
149 ASSERT_EFI_ERROR (Status
);
152 // Publish our HII data
154 PackageList
= PreparePackageList (2, &mBootManagerGuid
, BootManagerVfrBin
, BdsStrings
);
155 ASSERT (PackageList
!= NULL
);
157 Status
= gHiiDatabase
->NewPackageList (
160 gBootManagerPrivate
.DriverHandle
,
161 &gBootManagerPrivate
.HiiHandle
163 FreePool (PackageList
);
175 Hook to enable UI timeout override behavior.
178 BdsDeviceList - Device List that BDS needs to connect.
180 Entry - Pointer to current Boot Entry.
188 BDS_COMMON_OPTION
*Option
;
190 EFI_HII_UPDATE_DATA UpdateData
;
195 LIST_ENTRY BdsBootOptionList
;
197 EFI_STRING_ID HelpToken
;
199 EFI_HII_HANDLE HiiHandle
;
200 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
204 InitializeListHead (&BdsBootOptionList
);
207 // Connect all prior to entering the platform setup menu.
209 if (!gConnectAllHappened
) {
210 BdsLibConnectAllDriversToAllControllers ();
211 gConnectAllHappened
= TRUE
;
214 // BugBug: Here we can not remove the legacy refresh macro, so we need
215 // get the boot order every time from "BootOrder" variable.
216 // Recreate the boot option list base on the BootOrder variable
218 BdsLibEnumerateAllBootOption (&BdsBootOptionList
);
220 mBootOptionsList
= &BdsBootOptionList
;
222 HiiHandle
= gBootManagerPrivate
.HiiHandle
;
225 // Allocate space for creation of UpdateData Buffer
227 UpdateData
.BufferSize
= 0x1000;
228 UpdateData
.Offset
= 0;
229 UpdateData
.Data
= AllocateZeroPool (0x1000);
230 ASSERT (UpdateData
.Data
!= NULL
);
234 for (Link
= BdsBootOptionList
.ForwardLink
; Link
!= &BdsBootOptionList
; Link
= Link
->ForwardLink
) {
235 Option
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
238 // At this stage we are creating a menu entry, thus the Keys are reproduceable
243 // Don't display the boot option marked as LOAD_OPTION_HIDDEN
245 if (Option
->Attribute
& LOAD_OPTION_HIDDEN
) {
249 IfrLibNewString (HiiHandle
, &Token
, Option
->Description
);
251 TempStr
= DevicePathToStr (Option
->DevicePath
);
252 TempSize
= StrSize (TempStr
);
253 HelpString
= AllocateZeroPool (TempSize
+ StrSize (L
"Device Path : "));
254 StrCat (HelpString
, L
"Device Path : ");
255 StrCat (HelpString
, TempStr
);
257 IfrLibNewString (HiiHandle
, &HelpToken
, HelpString
);
263 EFI_IFR_FLAG_CALLBACK
,
272 BOOT_MANAGER_FORM_ID
,
277 FreePool (UpdateData
.Data
);
280 // Drop the TPL level from TPL_APPLICATION to TPL_APPLICATION
282 gBS
->RestoreTPL (TPL_APPLICATION
);
284 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
285 Status
= gFormBrowser2
->SendForm (
294 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
295 EnableResetRequired ();
298 if (gOption
== NULL
) {
299 gBS
->RaiseTPL (TPL_APPLICATION
);
304 //Will leave browser, check any reset required change is applied? if yes, reset system
306 SetupResetReminder ();
309 // Raise the TPL level back to TPL_APPLICATION
311 gBS
->RaiseTPL (TPL_APPLICATION
);
314 // parse the selected option
316 Status
= BdsLibBootViaBootOption (gOption
, gOption
->DevicePath
, &ExitDataSize
, &ExitData
);
318 if (!EFI_ERROR (Status
)) {
319 gOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED
));
320 PlatformBdsBootSuccess (gOption
);
322 gOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_FAILED
));
323 PlatformBdsBootFail (gOption
, Status
, ExitData
, ExitDataSize
);
324 gST
->ConOut
->OutputString (
326 GetStringById (STRING_TOKEN (STR_ANY_KEY_CONTINUE
))
328 gBS
->RestoreTPL (TPL_APPLICATION
);
330 // BdsLibUiWaitForSingleEvent (gST->ConIn->WaitForKey, 0);
332 gBS
->RaiseTPL (TPL_APPLICATION
);
333 gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);