2 The platform boot manager reference implementation
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.
107 @return Status of HiiLibCreateHiiDriverHandle() and gHiiDatabase->NewPackageList()
111 InitializeBootManager (
116 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
119 // Create driver handle used by HII database
121 Status
= HiiLibCreateHiiDriverHandle (&gBootManagerPrivate
.DriverHandle
);
122 if (EFI_ERROR (Status
)) {
127 // Install Config Access protocol to driver handle
129 Status
= gBS
->InstallProtocolInterface (
130 &gBootManagerPrivate
.DriverHandle
,
131 &gEfiHiiConfigAccessProtocolGuid
,
132 EFI_NATIVE_INTERFACE
,
133 &gBootManagerPrivate
.ConfigAccess
135 ASSERT_EFI_ERROR (Status
);
138 // Publish our HII data
140 PackageList
= HiiLibPreparePackageList (2, &mBootManagerGuid
, BootManagerVfrBin
, BdsDxeStrings
);
141 ASSERT (PackageList
!= NULL
);
143 Status
= gHiiDatabase
->NewPackageList (
146 gBootManagerPrivate
.DriverHandle
,
147 &gBootManagerPrivate
.HiiHandle
149 FreePool (PackageList
);
155 This funtion invokees Boot Manager. If all devices have not a chance to be connected,
156 the connect all will be triggered. It then enumerate all boot options. If
157 a boot option from the Boot Manager page is selected, Boot Manager will boot
158 from this boot option.
167 BDS_COMMON_OPTION
*Option
;
169 EFI_HII_UPDATE_DATA UpdateData
;
174 LIST_ENTRY BdsBootOptionList
;
176 EFI_STRING_ID HelpToken
;
178 EFI_HII_HANDLE HiiHandle
;
179 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
183 InitializeListHead (&BdsBootOptionList
);
186 // Connect all prior to entering the platform setup menu.
188 if (!gConnectAllHappened
) {
189 BdsLibConnectAllDriversToAllControllers ();
190 gConnectAllHappened
= TRUE
;
193 // BugBug: Here we can not remove the legacy refresh macro, so we need
194 // get the boot order every time from "BootOrder" variable.
195 // Recreate the boot option list base on the BootOrder variable
197 BdsLibEnumerateAllBootOption (&BdsBootOptionList
);
199 mBootOptionsList
= &BdsBootOptionList
;
201 HiiHandle
= gBootManagerPrivate
.HiiHandle
;
204 // Allocate space for creation of UpdateData Buffer
206 UpdateData
.BufferSize
= 0x1000;
207 UpdateData
.Offset
= 0;
208 UpdateData
.Data
= AllocateZeroPool (0x1000);
209 ASSERT (UpdateData
.Data
!= NULL
);
213 for (Link
= BdsBootOptionList
.ForwardLink
; Link
!= &BdsBootOptionList
; Link
= Link
->ForwardLink
) {
214 Option
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
217 // At this stage we are creating a menu entry, thus the Keys are reproduceable
222 // Don't display the boot option marked as LOAD_OPTION_HIDDEN
224 if (Option
->Attribute
& LOAD_OPTION_HIDDEN
) {
228 HiiLibNewString (HiiHandle
, &Token
, Option
->Description
);
230 TempStr
= DevicePathToStr (Option
->DevicePath
);
231 TempSize
= StrSize (TempStr
);
232 HelpString
= AllocateZeroPool (TempSize
+ StrSize (L
"Device Path : "));
233 ASSERT (HelpString
!= NULL
);
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
);
259 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
260 Status
= gFormBrowser2
->SendForm (
269 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
270 EnableResetRequired ();
273 if (gOption
== NULL
) {
278 //Will leave browser, check any reset required change is applied? if yes, reset system
280 SetupResetReminder ();
283 // parse the selected option
285 Status
= BdsLibBootViaBootOption (gOption
, gOption
->DevicePath
, &ExitDataSize
, &ExitData
);
287 if (!EFI_ERROR (Status
)) {
288 gOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED
));
289 PlatformBdsBootSuccess (gOption
);
291 gOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_FAILED
));
292 PlatformBdsBootFail (gOption
, Status
, ExitData
, ExitDataSize
);
293 gST
->ConOut
->OutputString (
295 GetStringById (STRING_TOKEN (STR_ANY_KEY_CONTINUE
))
297 gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);