2 The platform boot manager reference implementation
4 Copyright (c) 2004 - 2010, 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 HII_VENDOR_DEVICE_PATH mBootManagerHiiVendorDevicePath
= {
28 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
29 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
33 // {1DDDBE15-481D-4d2b-8277-B191EAF66525}
35 { 0x1dddbe15, 0x481d, 0x4d2b, { 0x82, 0x77, 0xb1, 0x91, 0xea, 0xf6, 0x65, 0x25 } }
39 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
41 (UINT8
) (END_DEVICE_PATH_LENGTH
),
42 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
47 BOOT_MANAGER_CALLBACK_DATA gBootManagerPrivate
= {
48 BOOT_MANAGER_CALLBACK_DATA_SIGNATURE
,
59 This call back function is registered with Boot Manager formset.
60 When user selects a boot option, this call back function will
61 be triggered. The boot option is saved for later processing.
64 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
65 @param Action Specifies the type of action taken by the browser.
66 @param QuestionId A unique value which is sent to the original exporting driver
67 so that it can identify the type of data to expect.
68 @param Type The type of value for the question.
69 @param Value A pointer to the data being sent to the original exporting driver.
70 @param ActionRequest On return, points to the action requested by the callback function.
72 @retval EFI_SUCCESS The callback successfully handled the action.
73 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
79 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
80 IN EFI_BROWSER_ACTION Action
,
81 IN EFI_QUESTION_ID QuestionId
,
83 IN EFI_IFR_TYPE_VALUE
*Value
,
84 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
87 BDS_COMMON_OPTION
*Option
;
91 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
92 return EFI_INVALID_PARAMETER
;
96 // Initialize the key count
100 for (Link
= mBootOptionsList
->ForwardLink
; Link
!= mBootOptionsList
; Link
= Link
->ForwardLink
) {
101 Option
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
108 // Is this device the one chosen?
110 if (KeyCount
== QuestionId
) {
112 // Assigning the returned Key to a global allows the original routine to know what was chosen
114 mKeyInput
= QuestionId
;
117 // Request to exit SendForm(), so that we could boot the selected option
119 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
129 Registers HII packages for the Boot Manger to HII Database.
130 It also registers the browser call back function.
132 @retval EFI_SUCCESS HII packages for the Boot Manager were registered successfully.
133 @retval EFI_OUT_OF_RESOURCES HII packages for the Boot Manager failed to be registered.
137 InitializeBootManager (
144 // Install Device Path Protocol and Config Access protocol to driver handle
146 Status
= gBS
->InstallMultipleProtocolInterfaces (
147 &gBootManagerPrivate
.DriverHandle
,
148 &gEfiDevicePathProtocolGuid
,
149 &mBootManagerHiiVendorDevicePath
,
150 &gEfiHiiConfigAccessProtocolGuid
,
151 &gBootManagerPrivate
.ConfigAccess
,
154 ASSERT_EFI_ERROR (Status
);
157 // Publish our HII data
159 gBootManagerPrivate
.HiiHandle
= HiiAddPackages (
161 gBootManagerPrivate
.DriverHandle
,
166 if (gBootManagerPrivate
.HiiHandle
== NULL
) {
167 Status
= EFI_OUT_OF_RESOURCES
;
169 Status
= EFI_SUCCESS
;
175 This function invokes Boot Manager. If all devices have not a chance to be connected,
176 the connect all will be triggered. It then enumerate all boot options. If
177 a boot option from the Boot Manager page is selected, Boot Manager will boot
178 from this boot option.
187 BDS_COMMON_OPTION
*Option
;
193 LIST_ENTRY BdsBootOptionList
;
195 EFI_STRING_ID HelpToken
;
197 EFI_HII_HANDLE HiiHandle
;
198 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
200 VOID
*StartOpCodeHandle
;
201 VOID
*EndOpCodeHandle
;
202 EFI_IFR_GUID_LABEL
*StartLabel
;
203 EFI_IFR_GUID_LABEL
*EndLabel
;
205 CHAR16
*BootStringNumber
;
206 UINTN DevicePathType
;
210 InitializeListHead (&BdsBootOptionList
);
213 // Connect all prior to entering the platform setup menu.
215 if (!gConnectAllHappened
) {
216 BdsLibConnectAllDriversToAllControllers ();
217 gConnectAllHappened
= TRUE
;
220 // BugBug: Here we can not remove the legacy refresh macro, so we need
221 // get the boot order every time from "BootOrder" variable.
222 // Recreate the boot option list base on the BootOrder variable
224 BdsLibEnumerateAllBootOption (&BdsBootOptionList
);
226 mBootOptionsList
= &BdsBootOptionList
;
228 HiiHandle
= gBootManagerPrivate
.HiiHandle
;
231 // Allocate space for creation of UpdateData Buffer
233 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
234 ASSERT (StartOpCodeHandle
!= NULL
);
236 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
237 ASSERT (EndOpCodeHandle
!= NULL
);
240 // Create Hii Extend Label OpCode as the start opcode
242 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
243 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
244 StartLabel
->Number
= LABEL_BOOT_OPTION
;
247 // Create Hii Extend Label OpCode as the end opcode
249 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
250 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
251 EndLabel
->Number
= LABEL_BOOT_OPTION_END
;
255 for (Link
= BdsBootOptionList
.ForwardLink
; Link
!= &BdsBootOptionList
; Link
= Link
->ForwardLink
) {
256 Option
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
259 // At this stage we are creating a menu entry, thus the Keys are reproduceable
264 // Don't display the boot option marked as LOAD_OPTION_HIDDEN
266 if ((Option
->Attribute
& LOAD_OPTION_HIDDEN
) != 0) {
271 // Replace description string with UNI file string.
273 BootStringNumber
= NULL
;
275 DevicePathType
= BdsGetBootTypeFromDevicePath (Option
->DevicePath
);
278 // store number string of boot option temporary.
281 switch (DevicePathType
) {
282 case BDS_EFI_ACPI_FLOPPY_BOOT
:
283 HiiString
= GetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY
));
285 case BDS_EFI_MEDIA_CDROM_BOOT
:
286 case BDS_EFI_MESSAGE_SATA_BOOT
:
287 case BDS_EFI_MESSAGE_ATAPI_BOOT
:
288 HiiString
= GetStringById (STRING_TOKEN (STR_DESCRIPTION_DVD
));
290 case BDS_EFI_MESSAGE_USB_DEVICE_BOOT
:
291 HiiString
= GetStringById (STRING_TOKEN (STR_DESCRIPTION_USB
));
293 case BDS_EFI_MESSAGE_SCSI_BOOT
:
294 HiiString
= GetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI
));
296 case BDS_EFI_MESSAGE_MISC_BOOT
:
297 HiiString
= GetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC
));
299 case BDS_EFI_MESSAGE_MAC_BOOT
:
300 HiiString
= GetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK
));
302 case BBS_DEVICE_PATH
:
304 // Do nothing for legacy boot option.
308 DEBUG((EFI_D_INFO
, "Can not find HiiString for given device path type 0x%x\n", DevicePathType
));
312 // If found Hii description string then cat Hii string with original description.
314 if (HiiString
!= NULL
) {
315 BootStringNumber
= Option
->Description
;
316 BufferSize
= StrSize(BootStringNumber
);
317 BufferSize
+= StrSize(HiiString
);
318 Option
->Description
= AllocateZeroPool(BufferSize
);
319 ASSERT (Option
->Description
!= NULL
);
320 StrCpy (Option
->Description
, HiiString
);
321 if (StrnCmp (BootStringNumber
, L
"0", 1) != 0) {
322 StrCat (Option
->Description
, L
" ");
323 StrCat (Option
->Description
, BootStringNumber
);
326 FreePool (HiiString
);
327 FreePool (BootStringNumber
);
330 ASSERT (Option
->Description
!= NULL
);
332 Token
= HiiSetString (HiiHandle
, 0, Option
->Description
, NULL
);
334 TempStr
= DevicePathToStr (Option
->DevicePath
);
335 TempSize
= StrSize (TempStr
);
336 HelpString
= AllocateZeroPool (TempSize
+ StrSize (L
"Device Path : "));
337 ASSERT (HelpString
!= NULL
);
338 StrCat (HelpString
, L
"Device Path : ");
339 StrCat (HelpString
, TempStr
);
341 HelpToken
= HiiSetString (HiiHandle
, 0, HelpString
, NULL
);
343 HiiCreateActionOpCode (
348 EFI_IFR_FLAG_CALLBACK
,
356 BOOT_MANAGER_FORM_ID
,
361 HiiFreeOpCodeHandle (StartOpCodeHandle
);
362 HiiFreeOpCodeHandle (EndOpCodeHandle
);
364 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
365 Status
= gFormBrowser2
->SendForm (
374 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
375 EnableResetRequired ();
378 if (gOption
== NULL
) {
383 // Will leave browser, check any reset required change is applied? if yes, reset system
385 SetupResetReminder ();
388 // parse the selected option
390 Status
= BdsLibBootViaBootOption (gOption
, gOption
->DevicePath
, &ExitDataSize
, &ExitData
);
392 if (!EFI_ERROR (Status
)) {
393 gOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED
));
394 PlatformBdsBootSuccess (gOption
);
396 gOption
->StatusString
= GetStringById (STRING_TOKEN (STR_BOOT_FAILED
));
397 PlatformBdsBootFail (gOption
, Status
, ExitData
, ExitDataSize
);
398 gST
->ConOut
->OutputString (
400 GetStringById (STRING_TOKEN (STR_ANY_KEY_CONTINUE
))
402 gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);