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 function processes the results of changes in configuration.
37 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
38 @param Action Specifies the type of action taken by the browser.
39 @param QuestionId A unique value which is sent to the original exporting driver
40 so that it can identify the type of data to expect.
41 @param Type The type of value for the question.
42 @param Value A pointer to the data being sent to the original exporting driver.
43 @param ActionRequest On return, points to the action requested by the callback function.
45 @retval EFI_SUCCESS The callback successfully handled the action.
46 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
47 @retval EFI_DEVICE_ERROR The variable could not be saved.
48 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
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 Initialize HII information for the FrontPage
107 @param VOID EDES_TODO: Add parameter description
109 @return EDES_TODO: Add description for return value
113 InitializeBootManager (
118 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
121 // Create driver handle used by HII database
123 Status
= HiiLibCreateHiiDriverHandle (&gBootManagerPrivate
.DriverHandle
);
124 if (EFI_ERROR (Status
)) {
129 // Install Config Access protocol to driver handle
131 Status
= gBS
->InstallProtocolInterface (
132 &gBootManagerPrivate
.DriverHandle
,
133 &gEfiHiiConfigAccessProtocolGuid
,
134 EFI_NATIVE_INTERFACE
,
135 &gBootManagerPrivate
.ConfigAccess
137 ASSERT_EFI_ERROR (Status
);
140 // Publish our HII data
142 PackageList
= HiiLibPreparePackageList (2, &mBootManagerGuid
, BootManagerVfrBin
, BdsDxeStrings
);
143 ASSERT (PackageList
!= NULL
);
145 Status
= gHiiDatabase
->NewPackageList (
148 gBootManagerPrivate
.DriverHandle
,
149 &gBootManagerPrivate
.HiiHandle
151 FreePool (PackageList
);
157 Invoke Boot Manager. Hook to enable UI timeout override behavior.
166 BDS_COMMON_OPTION
*Option
;
168 EFI_HII_UPDATE_DATA UpdateData
;
173 LIST_ENTRY BdsBootOptionList
;
175 EFI_STRING_ID HelpToken
;
177 EFI_HII_HANDLE HiiHandle
;
178 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
182 InitializeListHead (&BdsBootOptionList
);
185 // Connect all prior to entering the platform setup menu.
187 if (!gConnectAllHappened
) {
188 BdsLibConnectAllDriversToAllControllers ();
189 gConnectAllHappened
= TRUE
;
192 // BugBug: Here we can not remove the legacy refresh macro, so we need
193 // get the boot order every time from "BootOrder" variable.
194 // Recreate the boot option list base on the BootOrder variable
196 BdsLibEnumerateAllBootOption (&BdsBootOptionList
);
198 mBootOptionsList
= &BdsBootOptionList
;
200 HiiHandle
= gBootManagerPrivate
.HiiHandle
;
203 // Allocate space for creation of UpdateData Buffer
205 UpdateData
.BufferSize
= 0x1000;
206 UpdateData
.Offset
= 0;
207 UpdateData
.Data
= AllocateZeroPool (0x1000);
208 ASSERT (UpdateData
.Data
!= NULL
);
212 for (Link
= BdsBootOptionList
.ForwardLink
; Link
!= &BdsBootOptionList
; Link
= Link
->ForwardLink
) {
213 Option
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
216 // At this stage we are creating a menu entry, thus the Keys are reproduceable
221 // Don't display the boot option marked as LOAD_OPTION_HIDDEN
223 if (Option
->Attribute
& LOAD_OPTION_HIDDEN
) {
227 HiiLibNewString (HiiHandle
, &Token
, Option
->Description
);
229 TempStr
= DevicePathToStr (Option
->DevicePath
);
230 TempSize
= StrSize (TempStr
);
231 HelpString
= AllocateZeroPool (TempSize
+ StrSize (L
"Device Path : "));
232 StrCat (HelpString
, L
"Device Path : ");
233 StrCat (HelpString
, TempStr
);
235 HiiLibNewString (HiiHandle
, &HelpToken
, HelpString
);
241 EFI_IFR_FLAG_CALLBACK
,
250 BOOT_MANAGER_FORM_ID
,
255 FreePool (UpdateData
.Data
);
258 // Drop the TPL level from TPL_APPLICATION to TPL_APPLICATION
260 gBS
->RestoreTPL (TPL_APPLICATION
);
262 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
263 Status
= gFormBrowser2
->SendForm (
272 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
273 EnableResetRequired ();
276 if (gOption
== NULL
) {
277 gBS
->RaiseTPL (TPL_APPLICATION
);
282 //Will leave browser, check any reset required change is applied? if yes, reset system
284 SetupResetReminder ();
287 // Raise the TPL level back to TPL_APPLICATION
289 gBS
->RaiseTPL (TPL_APPLICATION
);
292 // parse the selected option
294 Status
= BdsLibBootViaBootOption (gOption
, gOption
->DevicePath
, &ExitDataSize
, &ExitData
);
296 if (!EFI_ERROR (Status
)) {
297 gOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED
));
298 PlatformBdsBootSuccess (gOption
);
300 gOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_FAILED
));
301 PlatformBdsBootFail (gOption
, Status
, ExitData
, ExitDataSize
);
302 gST
->ConOut
->OutputString (
304 GetStringById (STRING_TOKEN (STR_ANY_KEY_CONTINUE
))
306 gBS
->RestoreTPL (TPL_APPLICATION
);
308 // BdsLibUiWaitForSingleEvent (gST->ConIn->WaitForKey, 0);
310 gBS
->RaiseTPL (TPL_APPLICATION
);
311 gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);