2 The platform boot manager reference implementation
4 Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
5 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 LIST_ENTRY mBootOptionsList
;
19 BDS_COMMON_OPTION
*gOption
;
20 CHAR16
*mDeviceTypeStr
[] = {
27 L
"Legacy Embedded Network",
28 L
"Legacy Unknown Device"
32 HII_VENDOR_DEVICE_PATH mBootManagerHiiVendorDevicePath
= {
38 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
39 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
42 BOOT_MANAGER_FORMSET_GUID
46 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
48 (UINT8
) (END_DEVICE_PATH_LENGTH
),
49 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
54 BOOT_MANAGER_CALLBACK_DATA gBootManagerPrivate
= {
55 BOOT_MANAGER_CALLBACK_DATA_SIGNATURE
,
66 This call back function is registered with Boot Manager formset.
67 When user selects a boot option, this call back function will
68 be triggered. The boot option is saved for later processing.
71 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
72 @param Action Specifies the type of action taken by the browser.
73 @param QuestionId A unique value which is sent to the original exporting driver
74 so that it can identify the type of data to expect.
75 @param Type The type of value for the question.
76 @param Value A pointer to the data being sent to the original exporting driver.
77 @param ActionRequest On return, points to the action requested by the callback function.
79 @retval EFI_SUCCESS The callback successfully handled the action.
80 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
86 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
87 IN EFI_BROWSER_ACTION Action
,
88 IN EFI_QUESTION_ID QuestionId
,
90 IN EFI_IFR_TYPE_VALUE
*Value
,
91 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
94 BDS_COMMON_OPTION
*Option
;
98 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
99 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
100 return EFI_INVALID_PARAMETER
;
104 // Initialize the key count
108 for (Link
= GetFirstNode (&mBootOptionsList
); !IsNull (&mBootOptionsList
, Link
); Link
= GetNextNode (&mBootOptionsList
, Link
)) {
109 Option
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
116 // Is this device the one chosen?
118 if (KeyCount
== QuestionId
) {
120 // Assigning the returned Key to a global allows the original routine to know what was chosen
122 mKeyInput
= QuestionId
;
125 // Request to exit SendForm(), so that we could boot the selected option
127 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
136 // All other action return unsupported.
138 return EFI_UNSUPPORTED
;
143 Registers HII packages for the Boot Manger to HII Database.
144 It also registers the browser call back function.
146 @retval EFI_SUCCESS HII packages for the Boot Manager were registered successfully.
147 @retval EFI_OUT_OF_RESOURCES HII packages for the Boot Manager failed to be registered.
151 InitializeBootManager (
158 // Install Device Path Protocol and Config Access protocol to driver handle
160 Status
= gBS
->InstallMultipleProtocolInterfaces (
161 &gBootManagerPrivate
.DriverHandle
,
162 &gEfiDevicePathProtocolGuid
,
163 &mBootManagerHiiVendorDevicePath
,
164 &gEfiHiiConfigAccessProtocolGuid
,
165 &gBootManagerPrivate
.ConfigAccess
,
168 ASSERT_EFI_ERROR (Status
);
171 // Publish our HII data
173 gBootManagerPrivate
.HiiHandle
= HiiAddPackages (
174 &gBootManagerFormSetGuid
,
175 gBootManagerPrivate
.DriverHandle
,
180 if (gBootManagerPrivate
.HiiHandle
== NULL
) {
181 Status
= EFI_OUT_OF_RESOURCES
;
183 Status
= EFI_SUCCESS
;
189 This function invokes Boot Manager. If all devices have not a chance to be connected,
190 the connect all will be triggered. It then enumerate all boot options. If
191 a boot option from the Boot Manager page is selected, Boot Manager will boot
192 from this boot option.
201 BDS_COMMON_OPTION
*Option
;
208 EFI_STRING_ID HelpToken
;
210 EFI_HII_HANDLE HiiHandle
;
211 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
213 VOID
*StartOpCodeHandle
;
214 VOID
*EndOpCodeHandle
;
215 EFI_IFR_GUID_LABEL
*StartLabel
;
216 EFI_IFR_GUID_LABEL
*EndLabel
;
218 BOOLEAN IsLegacyOption
;
221 DeviceType
= (UINT16
) -1;
223 InitializeListHead (&mBootOptionsList
);
226 // Connect all prior to entering the platform setup menu.
228 if (!gConnectAllHappened
) {
229 BdsLibConnectAllDriversToAllControllers ();
230 gConnectAllHappened
= TRUE
;
233 BdsLibEnumerateAllBootOption (&mBootOptionsList
);
235 HiiHandle
= gBootManagerPrivate
.HiiHandle
;
238 // Allocate space for creation of UpdateData Buffer
240 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
241 ASSERT (StartOpCodeHandle
!= NULL
);
243 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
244 ASSERT (EndOpCodeHandle
!= NULL
);
247 // Create Hii Extend Label OpCode as the start opcode
249 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
250 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
251 StartLabel
->Number
= LABEL_BOOT_OPTION
;
254 // Create Hii Extend Label OpCode as the end opcode
256 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
257 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
258 EndLabel
->Number
= LABEL_BOOT_OPTION_END
;
262 for (Link
= GetFirstNode (&mBootOptionsList
); !IsNull (&mBootOptionsList
, Link
); Link
= GetNextNode (&mBootOptionsList
, Link
)) {
263 Option
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
266 // At this stage we are creating a menu entry, thus the Keys are reproduceable
271 // Don't display the boot option marked as LOAD_OPTION_HIDDEN
273 if ((Option
->Attribute
& LOAD_OPTION_HIDDEN
) != 0) {
278 // Group the legacy boot option in the sub title created dynamically
280 IsLegacyOption
= (BOOLEAN
) (
281 (DevicePathType (Option
->DevicePath
) == BBS_DEVICE_PATH
) &&
282 (DevicePathSubType (Option
->DevicePath
) == BBS_BBS_DP
)
285 if (!IsLegacyOption
&& NeedEndOp
) {
287 HiiCreateEndOpCode (StartOpCodeHandle
);
290 if (IsLegacyOption
&& DeviceType
!= ((BBS_BBS_DEVICE_PATH
*) Option
->DevicePath
)->DeviceType
) {
292 HiiCreateEndOpCode (StartOpCodeHandle
);
295 DeviceType
= ((BBS_BBS_DEVICE_PATH
*) Option
->DevicePath
)->DeviceType
;
296 Token
= HiiSetString (
300 MIN (DeviceType
& 0xF, sizeof (mDeviceTypeStr
) / sizeof (mDeviceTypeStr
[0]) - 1)
304 HiiCreateSubTitleOpCode (StartOpCodeHandle
, Token
, 0, 0, 1);
308 ASSERT (Option
->Description
!= NULL
);
310 Token
= HiiSetString (HiiHandle
, 0, Option
->Description
, NULL
);
312 TempStr
= DevicePathToStr (Option
->DevicePath
);
313 TempSize
= StrSize (TempStr
);
314 HelpString
= AllocateZeroPool (TempSize
+ StrSize (L
"Device Path : "));
315 ASSERT (HelpString
!= NULL
);
316 StrCat (HelpString
, L
"Device Path : ");
317 StrCat (HelpString
, TempStr
);
319 HelpToken
= HiiSetString (HiiHandle
, 0, HelpString
, NULL
);
321 HiiCreateActionOpCode (
326 EFI_IFR_FLAG_CALLBACK
,
332 HiiCreateEndOpCode (StartOpCodeHandle
);
337 &gBootManagerFormSetGuid
,
338 BOOT_MANAGER_FORM_ID
,
343 HiiFreeOpCodeHandle (StartOpCodeHandle
);
344 HiiFreeOpCodeHandle (EndOpCodeHandle
);
346 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
347 Status
= gFormBrowser2
->SendForm (
351 &gBootManagerFormSetGuid
,
356 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
357 EnableResetRequired ();
360 if (gOption
== NULL
) {
365 // Will leave browser, check any reset required change is applied? if yes, reset system
367 SetupResetReminder ();
370 // parse the selected option
372 Status
= BdsLibBootViaBootOption (gOption
, gOption
->DevicePath
, &ExitDataSize
, &ExitData
);
374 if (!EFI_ERROR (Status
)) {
375 gOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED
));
376 PlatformBdsBootSuccess (gOption
);
378 gOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_FAILED
));
379 PlatformBdsBootFail (gOption
, Status
, ExitData
, ExitDataSize
);
380 gST
->ConOut
->OutputString (
382 GetStringById (STRING_TOKEN (STR_ANY_KEY_CONTINUE
))
384 gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);