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 EFI_GUID mBootManagerGuid
= BOOT_MANAGER_FORMSET_GUID
;
19 LIST_ENTRY mBootOptionsList
;
20 BDS_COMMON_OPTION
*gOption
;
21 CHAR16
*mDeviceTypeStr
[] = {
28 L
"Legacy Embedded Network",
29 L
"Legacy Unknown Device"
33 HII_VENDOR_DEVICE_PATH mBootManagerHiiVendorDevicePath
= {
39 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
40 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
44 // {1DDDBE15-481D-4d2b-8277-B191EAF66525}
46 { 0x1dddbe15, 0x481d, 0x4d2b, { 0x82, 0x77, 0xb1, 0x91, 0xea, 0xf6, 0x65, 0x25 } }
50 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
52 (UINT8
) (END_DEVICE_PATH_LENGTH
),
53 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
58 BOOT_MANAGER_CALLBACK_DATA gBootManagerPrivate
= {
59 BOOT_MANAGER_CALLBACK_DATA_SIGNATURE
,
70 This call back function is registered with Boot Manager formset.
71 When user selects a boot option, this call back function will
72 be triggered. The boot option is saved for later processing.
75 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
76 @param Action Specifies the type of action taken by the browser.
77 @param QuestionId A unique value which is sent to the original exporting driver
78 so that it can identify the type of data to expect.
79 @param Type The type of value for the question.
80 @param Value A pointer to the data being sent to the original exporting driver.
81 @param ActionRequest On return, points to the action requested by the callback function.
83 @retval EFI_SUCCESS The callback successfully handled the action.
84 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
90 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
91 IN EFI_BROWSER_ACTION Action
,
92 IN EFI_QUESTION_ID QuestionId
,
94 IN EFI_IFR_TYPE_VALUE
*Value
,
95 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
98 BDS_COMMON_OPTION
*Option
;
102 if ((Action
== EFI_BROWSER_ACTION_FORM_OPEN
) || (Action
== EFI_BROWSER_ACTION_FORM_CLOSE
)) {
104 // Do nothing for UEFI OPEN/CLOSE Action
109 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
110 return EFI_INVALID_PARAMETER
;
114 // Initialize the key count
118 for (Link
= GetFirstNode (&mBootOptionsList
); !IsNull (&mBootOptionsList
, Link
); Link
= GetNextNode (&mBootOptionsList
, Link
)) {
119 Option
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
126 // Is this device the one chosen?
128 if (KeyCount
== QuestionId
) {
130 // Assigning the returned Key to a global allows the original routine to know what was chosen
132 mKeyInput
= QuestionId
;
135 // Request to exit SendForm(), so that we could boot the selected option
137 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
147 Registers HII packages for the Boot Manger to HII Database.
148 It also registers the browser call back function.
150 @retval EFI_SUCCESS HII packages for the Boot Manager were registered successfully.
151 @retval EFI_OUT_OF_RESOURCES HII packages for the Boot Manager failed to be registered.
155 InitializeBootManager (
162 // Install Device Path Protocol and Config Access protocol to driver handle
164 Status
= gBS
->InstallMultipleProtocolInterfaces (
165 &gBootManagerPrivate
.DriverHandle
,
166 &gEfiDevicePathProtocolGuid
,
167 &mBootManagerHiiVendorDevicePath
,
168 &gEfiHiiConfigAccessProtocolGuid
,
169 &gBootManagerPrivate
.ConfigAccess
,
172 ASSERT_EFI_ERROR (Status
);
175 // Publish our HII data
177 gBootManagerPrivate
.HiiHandle
= HiiAddPackages (
179 gBootManagerPrivate
.DriverHandle
,
184 if (gBootManagerPrivate
.HiiHandle
== NULL
) {
185 Status
= EFI_OUT_OF_RESOURCES
;
187 Status
= EFI_SUCCESS
;
193 This function invokes Boot Manager. If all devices have not a chance to be connected,
194 the connect all will be triggered. It then enumerate all boot options. If
195 a boot option from the Boot Manager page is selected, Boot Manager will boot
196 from this boot option.
205 BDS_COMMON_OPTION
*Option
;
212 EFI_STRING_ID HelpToken
;
214 EFI_HII_HANDLE HiiHandle
;
215 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
217 VOID
*StartOpCodeHandle
;
218 VOID
*EndOpCodeHandle
;
219 EFI_IFR_GUID_LABEL
*StartLabel
;
220 EFI_IFR_GUID_LABEL
*EndLabel
;
222 BOOLEAN IsLegacyOption
;
225 DeviceType
= (UINT16
) -1;
227 InitializeListHead (&mBootOptionsList
);
230 // Connect all prior to entering the platform setup menu.
232 if (!gConnectAllHappened
) {
233 BdsLibConnectAllDriversToAllControllers ();
234 gConnectAllHappened
= TRUE
;
237 BdsLibEnumerateAllBootOption (&mBootOptionsList
);
239 HiiHandle
= gBootManagerPrivate
.HiiHandle
;
242 // Allocate space for creation of UpdateData Buffer
244 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
245 ASSERT (StartOpCodeHandle
!= NULL
);
247 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
248 ASSERT (EndOpCodeHandle
!= NULL
);
251 // Create Hii Extend Label OpCode as the start opcode
253 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
254 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
255 StartLabel
->Number
= LABEL_BOOT_OPTION
;
258 // Create Hii Extend Label OpCode as the end opcode
260 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
261 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
262 EndLabel
->Number
= LABEL_BOOT_OPTION_END
;
266 for (Link
= GetFirstNode (&mBootOptionsList
); !IsNull (&mBootOptionsList
, Link
); Link
= GetNextNode (&mBootOptionsList
, Link
)) {
267 Option
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
270 // At this stage we are creating a menu entry, thus the Keys are reproduceable
275 // Don't display the boot option marked as LOAD_OPTION_HIDDEN
277 if ((Option
->Attribute
& LOAD_OPTION_HIDDEN
) != 0) {
282 // Group the legacy boot option in the sub title created dynamically
284 IsLegacyOption
= (BOOLEAN
) (
285 (DevicePathType (Option
->DevicePath
) == BBS_DEVICE_PATH
) &&
286 (DevicePathSubType (Option
->DevicePath
) == BBS_BBS_DP
)
289 if (!IsLegacyOption
&& NeedEndOp
) {
291 HiiCreateEndOpCode (StartOpCodeHandle
);
294 if (IsLegacyOption
&& DeviceType
!= ((BBS_BBS_DEVICE_PATH
*) Option
->DevicePath
)->DeviceType
) {
296 HiiCreateEndOpCode (StartOpCodeHandle
);
299 DeviceType
= ((BBS_BBS_DEVICE_PATH
*) Option
->DevicePath
)->DeviceType
;
300 Token
= HiiSetString (
304 MIN (DeviceType
& 0xF, sizeof (mDeviceTypeStr
) / sizeof (mDeviceTypeStr
[0]) - 1)
308 HiiCreateSubTitleOpCode (StartOpCodeHandle
, Token
, 0, 0, 1);
312 ASSERT (Option
->Description
!= NULL
);
314 Token
= HiiSetString (HiiHandle
, 0, Option
->Description
, NULL
);
316 TempStr
= DevicePathToStr (Option
->DevicePath
);
317 TempSize
= StrSize (TempStr
);
318 HelpString
= AllocateZeroPool (TempSize
+ StrSize (L
"Device Path : "));
319 ASSERT (HelpString
!= NULL
);
320 StrCat (HelpString
, L
"Device Path : ");
321 StrCat (HelpString
, TempStr
);
323 HelpToken
= HiiSetString (HiiHandle
, 0, HelpString
, NULL
);
325 HiiCreateActionOpCode (
330 EFI_IFR_FLAG_CALLBACK
,
336 HiiCreateEndOpCode (StartOpCodeHandle
);
342 BOOT_MANAGER_FORM_ID
,
347 HiiFreeOpCodeHandle (StartOpCodeHandle
);
348 HiiFreeOpCodeHandle (EndOpCodeHandle
);
350 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
351 Status
= gFormBrowser2
->SendForm (
360 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
361 EnableResetRequired ();
364 if (gOption
== NULL
) {
369 // Will leave browser, check any reset required change is applied? if yes, reset system
371 SetupResetReminder ();
374 // parse the selected option
376 Status
= BdsLibBootViaBootOption (gOption
, gOption
->DevicePath
, &ExitDataSize
, &ExitData
);
378 if (!EFI_ERROR (Status
)) {
379 gOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED
));
380 PlatformBdsBootSuccess (gOption
);
382 gOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_FAILED
));
383 PlatformBdsBootFail (gOption
, Status
, ExitData
, ExitDataSize
);
384 gST
->ConOut
->OutputString (
386 GetStringById (STRING_TOKEN (STR_ANY_KEY_CONTINUE
))
388 gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);