2009-01-23 08:24:55 +01:00
|
|
|
/** @file
|
|
|
|
The platform boot manager reference implementation
|
|
|
|
|
2010-04-23 18:28:26 +02:00
|
|
|
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
|
|
|
|
This program and the accompanying materials
|
2009-01-23 08:24:55 +01:00
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "BootManager.h"
|
|
|
|
|
|
|
|
UINT16 mKeyInput;
|
|
|
|
EFI_GUID mBootManagerGuid = BOOT_MANAGER_FORMSET_GUID;
|
2010-05-21 09:40:24 +02:00
|
|
|
LIST_ENTRY mBootOptionsList;
|
2009-01-23 08:24:55 +01:00
|
|
|
BDS_COMMON_OPTION *gOption;
|
|
|
|
|
2009-04-02 10:48:03 +02:00
|
|
|
HII_VENDOR_DEVICE_PATH mBootManagerHiiVendorDevicePath = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HARDWARE_DEVICE_PATH,
|
|
|
|
HW_VENDOR_DP,
|
|
|
|
{
|
|
|
|
(UINT8) (sizeof (VENDOR_DEVICE_PATH)),
|
|
|
|
(UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
//
|
|
|
|
// {1DDDBE15-481D-4d2b-8277-B191EAF66525}
|
|
|
|
//
|
|
|
|
{ 0x1dddbe15, 0x481d, 0x4d2b, { 0x82, 0x77, 0xb1, 0x91, 0xea, 0xf6, 0x65, 0x25 } }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
END_DEVICE_PATH_TYPE,
|
|
|
|
END_ENTIRE_DEVICE_PATH_SUBTYPE,
|
|
|
|
{
|
|
|
|
(UINT8) (END_DEVICE_PATH_LENGTH),
|
|
|
|
(UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-01-23 08:24:55 +01:00
|
|
|
BOOT_MANAGER_CALLBACK_DATA gBootManagerPrivate = {
|
|
|
|
BOOT_MANAGER_CALLBACK_DATA_SIGNATURE,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
{
|
|
|
|
FakeExtractConfig,
|
|
|
|
FakeRouteConfig,
|
|
|
|
BootManagerCallback
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2009-12-04 04:35:56 +01:00
|
|
|
This call back function is registered with Boot Manager formset.
|
2009-01-23 08:24:55 +01:00
|
|
|
When user selects a boot option, this call back function will
|
|
|
|
be triggered. The boot option is saved for later processing.
|
|
|
|
|
|
|
|
|
|
|
|
@param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
|
|
|
|
@param Action Specifies the type of action taken by the browser.
|
|
|
|
@param QuestionId A unique value which is sent to the original exporting driver
|
|
|
|
so that it can identify the type of data to expect.
|
|
|
|
@param Type The type of value for the question.
|
|
|
|
@param Value A pointer to the data being sent to the original exporting driver.
|
|
|
|
@param ActionRequest On return, points to the action requested by the callback function.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The callback successfully handled the action.
|
|
|
|
@retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
BootManagerCallback (
|
|
|
|
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
|
|
|
|
IN EFI_BROWSER_ACTION Action,
|
|
|
|
IN EFI_QUESTION_ID QuestionId,
|
|
|
|
IN UINT8 Type,
|
|
|
|
IN EFI_IFR_TYPE_VALUE *Value,
|
|
|
|
OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
|
|
|
|
)
|
|
|
|
{
|
|
|
|
BDS_COMMON_OPTION *Option;
|
|
|
|
LIST_ENTRY *Link;
|
|
|
|
UINT16 KeyCount;
|
|
|
|
|
2010-06-02 04:06:01 +02:00
|
|
|
if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {
|
|
|
|
//
|
|
|
|
// Do nothing for UEFI OPEN/CLOSE Action
|
|
|
|
//
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-01-23 08:24:55 +01:00
|
|
|
if ((Value == NULL) || (ActionRequest == NULL)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initialize the key count
|
|
|
|
//
|
|
|
|
KeyCount = 0;
|
|
|
|
|
2010-05-21 09:40:24 +02:00
|
|
|
for (Link = GetFirstNode (&mBootOptionsList); !IsNull (&mBootOptionsList, Link); Link = GetNextNode (&mBootOptionsList, Link)) {
|
2009-01-23 08:24:55 +01:00
|
|
|
Option = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);
|
|
|
|
|
|
|
|
KeyCount++;
|
|
|
|
|
|
|
|
gOption = Option;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Is this device the one chosen?
|
|
|
|
//
|
|
|
|
if (KeyCount == QuestionId) {
|
|
|
|
//
|
|
|
|
// Assigning the returned Key to a global allows the original routine to know what was chosen
|
|
|
|
//
|
|
|
|
mKeyInput = QuestionId;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Request to exit SendForm(), so that we could boot the selected option
|
|
|
|
//
|
|
|
|
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
Registers HII packages for the Boot Manger to HII Database.
|
|
|
|
It also registers the browser call back function.
|
|
|
|
|
2009-04-14 12:47:19 +02:00
|
|
|
@retval EFI_SUCCESS HII packages for the Boot Manager were registered successfully.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES HII packages for the Boot Manager failed to be registered.
|
2009-01-23 08:24:55 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
InitializeBootManager (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
//
|
2009-04-02 10:48:03 +02:00
|
|
|
// Install Device Path Protocol and Config Access protocol to driver handle
|
2009-01-23 08:24:55 +01:00
|
|
|
//
|
2009-04-02 10:48:03 +02:00
|
|
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
2009-01-23 08:24:55 +01:00
|
|
|
&gBootManagerPrivate.DriverHandle,
|
2009-04-02 10:48:03 +02:00
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
&mBootManagerHiiVendorDevicePath,
|
2009-01-23 08:24:55 +01:00
|
|
|
&gEfiHiiConfigAccessProtocolGuid,
|
2009-04-02 10:48:03 +02:00
|
|
|
&gBootManagerPrivate.ConfigAccess,
|
|
|
|
NULL
|
2009-01-23 08:24:55 +01:00
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Publish our HII data
|
|
|
|
//
|
2009-04-14 12:47:19 +02:00
|
|
|
gBootManagerPrivate.HiiHandle = HiiAddPackages (
|
|
|
|
&mBootManagerGuid,
|
|
|
|
gBootManagerPrivate.DriverHandle,
|
|
|
|
BootManagerVfrBin,
|
|
|
|
BdsDxeStrings,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
if (gBootManagerPrivate.HiiHandle == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
} else {
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
}
|
2009-01-23 08:24:55 +01:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 04:35:56 +01:00
|
|
|
This function invokes Boot Manager. If all devices have not a chance to be connected,
|
2009-01-23 08:24:55 +01:00
|
|
|
the connect all will be triggered. It then enumerate all boot options. If
|
|
|
|
a boot option from the Boot Manager page is selected, Boot Manager will boot
|
|
|
|
from this boot option.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
CallBootManager (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
BDS_COMMON_OPTION *Option;
|
|
|
|
LIST_ENTRY *Link;
|
|
|
|
CHAR16 *ExitData;
|
|
|
|
UINTN ExitDataSize;
|
|
|
|
EFI_STRING_ID Token;
|
|
|
|
EFI_INPUT_KEY Key;
|
|
|
|
CHAR16 *HelpString;
|
|
|
|
EFI_STRING_ID HelpToken;
|
|
|
|
UINT16 *TempStr;
|
|
|
|
EFI_HII_HANDLE HiiHandle;
|
|
|
|
EFI_BROWSER_ACTION_REQUEST ActionRequest;
|
|
|
|
UINTN TempSize;
|
2009-04-17 07:31:38 +02:00
|
|
|
VOID *StartOpCodeHandle;
|
|
|
|
VOID *EndOpCodeHandle;
|
|
|
|
EFI_IFR_GUID_LABEL *StartLabel;
|
|
|
|
EFI_IFR_GUID_LABEL *EndLabel;
|
2009-01-23 08:24:55 +01:00
|
|
|
|
|
|
|
gOption = NULL;
|
2010-05-21 09:40:24 +02:00
|
|
|
InitializeListHead (&mBootOptionsList);
|
2009-01-23 08:24:55 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Connect all prior to entering the platform setup menu.
|
|
|
|
//
|
|
|
|
if (!gConnectAllHappened) {
|
|
|
|
BdsLibConnectAllDriversToAllControllers ();
|
|
|
|
gConnectAllHappened = TRUE;
|
|
|
|
}
|
|
|
|
|
2010-05-21 09:40:24 +02:00
|
|
|
BdsLibEnumerateAllBootOption (&mBootOptionsList);
|
2009-01-23 08:24:55 +01:00
|
|
|
|
|
|
|
HiiHandle = gBootManagerPrivate.HiiHandle;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate space for creation of UpdateData Buffer
|
|
|
|
//
|
2009-04-17 07:31:38 +02:00
|
|
|
StartOpCodeHandle = HiiAllocateOpCodeHandle ();
|
|
|
|
ASSERT (StartOpCodeHandle != NULL);
|
|
|
|
|
|
|
|
EndOpCodeHandle = HiiAllocateOpCodeHandle ();
|
|
|
|
ASSERT (EndOpCodeHandle != NULL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create Hii Extend Label OpCode as the start opcode
|
|
|
|
//
|
|
|
|
StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
|
|
|
|
StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
|
|
|
|
StartLabel->Number = LABEL_BOOT_OPTION;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create Hii Extend Label OpCode as the end opcode
|
|
|
|
//
|
|
|
|
EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
|
|
|
|
EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
|
|
|
|
EndLabel->Number = LABEL_BOOT_OPTION_END;
|
2009-01-23 08:24:55 +01:00
|
|
|
|
|
|
|
mKeyInput = 0;
|
|
|
|
|
2010-05-21 09:40:24 +02:00
|
|
|
for (Link = GetFirstNode (&mBootOptionsList); !IsNull (&mBootOptionsList, Link); Link = GetNextNode (&mBootOptionsList, Link)) {
|
2009-01-23 08:24:55 +01:00
|
|
|
Option = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);
|
|
|
|
|
|
|
|
//
|
|
|
|
// At this stage we are creating a menu entry, thus the Keys are reproduceable
|
|
|
|
//
|
|
|
|
mKeyInput++;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Don't display the boot option marked as LOAD_OPTION_HIDDEN
|
|
|
|
//
|
2009-06-24 10:41:14 +02:00
|
|
|
if ((Option->Attribute & LOAD_OPTION_HIDDEN) != 0) {
|
2009-01-23 08:24:55 +01:00
|
|
|
continue;
|
|
|
|
}
|
2009-07-13 12:20:09 +02:00
|
|
|
|
2009-07-16 08:54:41 +02:00
|
|
|
ASSERT (Option->Description != NULL);
|
|
|
|
|
2009-04-14 12:47:19 +02:00
|
|
|
Token = HiiSetString (HiiHandle, 0, Option->Description, NULL);
|
2009-01-23 08:24:55 +01:00
|
|
|
|
|
|
|
TempStr = DevicePathToStr (Option->DevicePath);
|
|
|
|
TempSize = StrSize (TempStr);
|
|
|
|
HelpString = AllocateZeroPool (TempSize + StrSize (L"Device Path : "));
|
|
|
|
ASSERT (HelpString != NULL);
|
|
|
|
StrCat (HelpString, L"Device Path : ");
|
|
|
|
StrCat (HelpString, TempStr);
|
|
|
|
|
2009-04-14 12:47:19 +02:00
|
|
|
HelpToken = HiiSetString (HiiHandle, 0, HelpString, NULL);
|
2009-01-23 08:24:55 +01:00
|
|
|
|
2009-04-17 07:31:38 +02:00
|
|
|
HiiCreateActionOpCode (
|
|
|
|
StartOpCodeHandle,
|
2009-01-23 08:24:55 +01:00
|
|
|
mKeyInput,
|
|
|
|
Token,
|
|
|
|
HelpToken,
|
|
|
|
EFI_IFR_FLAG_CALLBACK,
|
2009-04-17 07:31:38 +02:00
|
|
|
0
|
2009-01-23 08:24:55 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2009-04-17 07:31:38 +02:00
|
|
|
HiiUpdateForm (
|
2009-01-23 08:24:55 +01:00
|
|
|
HiiHandle,
|
|
|
|
&mBootManagerGuid,
|
|
|
|
BOOT_MANAGER_FORM_ID,
|
2009-04-17 07:31:38 +02:00
|
|
|
StartOpCodeHandle,
|
|
|
|
EndOpCodeHandle
|
2009-01-23 08:24:55 +01:00
|
|
|
);
|
2009-04-17 07:31:38 +02:00
|
|
|
|
|
|
|
HiiFreeOpCodeHandle (StartOpCodeHandle);
|
|
|
|
HiiFreeOpCodeHandle (EndOpCodeHandle);
|
2009-01-23 08:24:55 +01:00
|
|
|
|
|
|
|
ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
|
|
|
|
Status = gFormBrowser2->SendForm (
|
|
|
|
gFormBrowser2,
|
|
|
|
&HiiHandle,
|
|
|
|
1,
|
2009-04-17 07:31:38 +02:00
|
|
|
&mBootManagerGuid,
|
2009-01-23 08:24:55 +01:00
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
&ActionRequest
|
|
|
|
);
|
|
|
|
if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
|
|
|
|
EnableResetRequired ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gOption == NULL) {
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2009-12-04 04:35:56 +01:00
|
|
|
// Will leave browser, check any reset required change is applied? if yes, reset system
|
2009-01-23 08:24:55 +01:00
|
|
|
//
|
|
|
|
SetupResetReminder ();
|
|
|
|
|
|
|
|
//
|
|
|
|
// parse the selected option
|
|
|
|
//
|
|
|
|
Status = BdsLibBootViaBootOption (gOption, gOption->DevicePath, &ExitDataSize, &ExitData);
|
|
|
|
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
gOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED));
|
|
|
|
PlatformBdsBootSuccess (gOption);
|
|
|
|
} else {
|
|
|
|
gOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_FAILED));
|
|
|
|
PlatformBdsBootFail (gOption, Status, ExitData, ExitDataSize);
|
|
|
|
gST->ConOut->OutputString (
|
|
|
|
gST->ConOut,
|
|
|
|
GetStringById (STRING_TOKEN (STR_ANY_KEY_CONTINUE))
|
|
|
|
);
|
|
|
|
gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
|
|
|
|
}
|
|
|
|
}
|