2011-06-11 13:58:23 +02:00
|
|
|
/** @file
|
|
|
|
*
|
2014-04-11 13:01:56 +02:00
|
|
|
* Copyright (c) 2011 - 2014, ARM Limited. All rights reserved.
|
2011-06-11 13:58:23 +02:00
|
|
|
*
|
|
|
|
* This program and the accompanying materials
|
|
|
|
* 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 "BdsInternal.h"
|
|
|
|
|
2013-01-28 12:44:50 +01:00
|
|
|
#include <Guid/ArmGlobalVariableHob.h>
|
|
|
|
|
2011-06-11 13:58:23 +02:00
|
|
|
extern BDS_LOAD_OPTION_SUPPORT *BdsLoadOptionSupportList;
|
|
|
|
|
2014-07-29 16:19:57 +02:00
|
|
|
/**
|
|
|
|
Worker function that displays the list of boot options that is passed in.
|
|
|
|
|
|
|
|
The function loops over the entries of the list of boot options that is passed
|
|
|
|
in. For each entry, the boot option description is displayed on a single line
|
|
|
|
along with the position of the option in the list. In debug mode, the UEFI
|
|
|
|
device path and the arguments of the boot option are displayed as well in
|
|
|
|
subsequent lines.
|
|
|
|
|
|
|
|
@param[in] BootOptionsList List of the boot options
|
|
|
|
|
|
|
|
**/
|
|
|
|
STATIC
|
|
|
|
VOID
|
|
|
|
DisplayBootOptions (
|
|
|
|
IN LIST_ENTRY* BootOptionsList
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN BootOptionCount;
|
|
|
|
LIST_ENTRY *Entry;
|
|
|
|
BDS_LOAD_OPTION *BdsLoadOption;
|
|
|
|
BOOLEAN IsUnicode;
|
|
|
|
|
|
|
|
BootOptionCount = 0 ;
|
|
|
|
for (Entry = GetFirstNode (BootOptionsList);
|
|
|
|
!IsNull (BootOptionsList, Entry);
|
|
|
|
Entry = GetNextNode (BootOptionsList, Entry)
|
|
|
|
) {
|
|
|
|
|
|
|
|
BdsLoadOption = LOAD_OPTION_FROM_LINK (Entry);
|
|
|
|
Print (L"[%d] %s\n", ++BootOptionCount, BdsLoadOption->Description);
|
|
|
|
|
|
|
|
DEBUG_CODE_BEGIN ();
|
|
|
|
CHAR16* DevicePathTxt;
|
|
|
|
EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;
|
|
|
|
ARM_BDS_LOADER_TYPE LoaderType;
|
|
|
|
ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;
|
|
|
|
|
|
|
|
Status = gBS->LocateProtocol (
|
|
|
|
&gEfiDevicePathToTextProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
(VOID **)&DevicePathToTextProtocol
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (
|
|
|
|
BdsLoadOption->FilePathList,
|
|
|
|
TRUE,
|
|
|
|
TRUE
|
|
|
|
);
|
|
|
|
Print (L"\t- %s\n", DevicePathTxt);
|
|
|
|
|
|
|
|
OptionalData = BdsLoadOption->OptionalData;
|
|
|
|
if (IS_ARM_BDS_BOOTENTRY (BdsLoadOption)) {
|
|
|
|
LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);
|
|
|
|
if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) ||
|
|
|
|
(LoaderType == BDS_LOADER_KERNEL_LINUX_FDT ) ) {
|
|
|
|
Print (L"\t- Arguments: %a\n", &OptionalData->Arguments.LinuxArguments + 1);
|
|
|
|
}
|
|
|
|
} else if (OptionalData != NULL) {
|
|
|
|
if (IsPrintableString (OptionalData, &IsUnicode)) {
|
|
|
|
if (IsUnicode) {
|
|
|
|
Print (L"\t- Arguments: %s\n", OptionalData);
|
|
|
|
} else {
|
|
|
|
AsciiPrint ("\t- Arguments: %a\n", OptionalData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FreePool (DevicePathTxt);
|
|
|
|
DEBUG_CODE_END ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Worker function that asks for a boot option to be selected and returns a
|
|
|
|
pointer to the structure describing the selected boot option.
|
|
|
|
|
|
|
|
@param[in] BootOptionsList List of the boot options
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Selection succeeded
|
|
|
|
@retval !EFI_SUCCESS Input error or input cancelled
|
|
|
|
|
|
|
|
**/
|
|
|
|
STATIC
|
|
|
|
EFI_STATUS
|
|
|
|
SelectBootOption (
|
|
|
|
IN LIST_ENTRY* BootOptionsList,
|
|
|
|
IN CONST CHAR16* InputStatement,
|
|
|
|
OUT BDS_LOAD_OPTION_ENTRY** BdsLoadOptionEntry
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN BootOptionCount;
|
|
|
|
UINT16 *BootOrder;
|
|
|
|
LIST_ENTRY* Entry;
|
|
|
|
UINTN BootOptionSelected;
|
|
|
|
UINTN Index;
|
|
|
|
|
|
|
|
// Get the number of boot options
|
|
|
|
Status = GetGlobalEnvironmentVariable (
|
|
|
|
L"BootOrder", NULL, &BootOptionCount, (VOID**)&BootOrder
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ErrorExit;
|
|
|
|
}
|
|
|
|
FreePool (BootOrder);
|
|
|
|
BootOptionCount /= sizeof (UINT16);
|
|
|
|
|
|
|
|
// Check if a valid boot option(s) is found
|
|
|
|
if (BootOptionCount == 0) {
|
|
|
|
if (StrCmp (InputStatement, DELETE_BOOT_ENTRY) == 0) {
|
|
|
|
Print (L"Nothing to remove!\n");
|
|
|
|
} else if (StrCmp (InputStatement, UPDATE_BOOT_ENTRY) == 0) {
|
|
|
|
Print (L"Nothing to update!\n");
|
|
|
|
} else if (StrCmp (InputStatement, MOVE_BOOT_ENTRY) == 0) {
|
|
|
|
Print (L"Nothing to move!\n");
|
|
|
|
} else {
|
|
|
|
Print (L"No supported Boot Entry.\n");
|
|
|
|
}
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the index of the boot device to delete
|
|
|
|
BootOptionSelected = 0;
|
|
|
|
while (BootOptionSelected == 0) {
|
|
|
|
Print (InputStatement);
|
|
|
|
Status = GetHIInputInteger (&BootOptionSelected);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
Print (L"\n");
|
|
|
|
goto ErrorExit;
|
|
|
|
} else if ((BootOptionSelected == 0) || (BootOptionSelected > BootOptionCount)) {
|
|
|
|
Print (L"Invalid input (max %d)\n", BootOptionCount);
|
|
|
|
BootOptionSelected = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the structure of the Boot device to delete
|
|
|
|
Index = 1;
|
|
|
|
for (Entry = GetFirstNode (BootOptionsList);
|
|
|
|
!IsNull (BootOptionsList, Entry);
|
|
|
|
Entry = GetNextNode (BootOptionsList,Entry)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (Index == BootOptionSelected) {
|
|
|
|
*BdsLoadOptionEntry = LOAD_OPTION_ENTRY_FROM_LINK (Entry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Index++;
|
|
|
|
}
|
2013-01-28 12:44:50 +01:00
|
|
|
|
2014-07-29 16:19:57 +02:00
|
|
|
ErrorExit:
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
STATIC
|
2011-06-11 13:58:23 +02:00
|
|
|
EFI_STATUS
|
2011-08-18 15:21:14 +02:00
|
|
|
SelectBootDevice (
|
|
|
|
OUT BDS_SUPPORTED_DEVICE** SupportedBootDevice
|
2011-06-11 13:58:23 +02:00
|
|
|
)
|
|
|
|
{
|
2011-08-18 15:21:14 +02:00
|
|
|
EFI_STATUS Status;
|
2011-06-11 13:58:23 +02:00
|
|
|
LIST_ENTRY SupportedDeviceList;
|
|
|
|
UINTN SupportedDeviceCount;
|
|
|
|
LIST_ENTRY* Entry;
|
|
|
|
UINTN SupportedDeviceSelected;
|
|
|
|
UINTN Index;
|
|
|
|
|
|
|
|
//
|
|
|
|
// List the Boot Devices supported
|
|
|
|
//
|
|
|
|
|
|
|
|
// Start all the drivers first
|
|
|
|
BdsConnectAllDrivers ();
|
|
|
|
|
|
|
|
// List the supported devices
|
|
|
|
Status = BootDeviceListSupportedInit (&SupportedDeviceList);
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
|
|
|
|
SupportedDeviceCount = 0;
|
|
|
|
for (Entry = GetFirstNode (&SupportedDeviceList);
|
|
|
|
!IsNull (&SupportedDeviceList,Entry);
|
|
|
|
Entry = GetNextNode (&SupportedDeviceList,Entry)
|
|
|
|
)
|
|
|
|
{
|
2011-08-18 15:21:14 +02:00
|
|
|
*SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);
|
|
|
|
Print(L"[%d] %s\n",SupportedDeviceCount+1,(*SupportedBootDevice)->Description);
|
2011-06-11 13:58:23 +02:00
|
|
|
|
|
|
|
DEBUG_CODE_BEGIN();
|
|
|
|
CHAR16* DevicePathTxt;
|
|
|
|
EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;
|
|
|
|
|
2011-09-09 12:56:14 +02:00
|
|
|
Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
|
2011-06-11 13:58:23 +02:00
|
|
|
ASSERT_EFI_ERROR(Status);
|
2011-09-09 12:56:14 +02:00
|
|
|
DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText ((*SupportedBootDevice)->DevicePathProtocol,TRUE,TRUE);
|
2011-06-11 13:58:23 +02:00
|
|
|
|
|
|
|
Print(L"\t- %s\n",DevicePathTxt);
|
|
|
|
|
|
|
|
FreePool(DevicePathTxt);
|
|
|
|
DEBUG_CODE_END();
|
|
|
|
|
|
|
|
SupportedDeviceCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SupportedDeviceCount == 0) {
|
|
|
|
Print(L"There is no supported device.\n");
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Select the Boot Device
|
|
|
|
//
|
|
|
|
SupportedDeviceSelected = 0;
|
|
|
|
while (SupportedDeviceSelected == 0) {
|
|
|
|
Print(L"Select the Boot Device: ");
|
|
|
|
Status = GetHIInputInteger (&SupportedDeviceSelected);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto EXIT;
|
|
|
|
} else if ((SupportedDeviceSelected == 0) || (SupportedDeviceSelected > SupportedDeviceCount)) {
|
2011-09-09 12:56:14 +02:00
|
|
|
Print(L"Invalid input (max %d)\n",SupportedDeviceCount);
|
2011-06-11 13:58:23 +02:00
|
|
|
SupportedDeviceSelected = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the Device Path for the selected boot device
|
|
|
|
//
|
|
|
|
Index = 1;
|
|
|
|
for (Entry = GetFirstNode (&SupportedDeviceList);
|
|
|
|
!IsNull (&SupportedDeviceList,Entry);
|
|
|
|
Entry = GetNextNode (&SupportedDeviceList,Entry)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (Index == SupportedDeviceSelected) {
|
2011-08-18 15:21:14 +02:00
|
|
|
*SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);
|
2011-06-11 13:58:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
Index++;
|
|
|
|
}
|
2013-01-28 12:44:50 +01:00
|
|
|
|
2011-08-18 15:21:14 +02:00
|
|
|
EXIT:
|
|
|
|
BootDeviceListSupportedFree (&SupportedDeviceList, *SupportedBootDevice);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
BootMenuAddBootOption (
|
|
|
|
IN LIST_ENTRY *BootOptionsList
|
|
|
|
)
|
|
|
|
{
|
2011-09-09 12:51:13 +02:00
|
|
|
EFI_STATUS Status;
|
|
|
|
BDS_SUPPORTED_DEVICE* SupportedBootDevice;
|
|
|
|
ARM_BDS_LOADER_ARGUMENTS* BootArguments;
|
2011-09-09 12:49:54 +02:00
|
|
|
CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];
|
2014-04-11 12:57:00 +02:00
|
|
|
CHAR8 AsciiCmdLine[BOOT_DEVICE_OPTION_MAX];
|
|
|
|
CHAR16 CmdLine[BOOT_DEVICE_OPTION_MAX];
|
2011-09-09 12:51:13 +02:00
|
|
|
UINT32 Attributes;
|
|
|
|
ARM_BDS_LOADER_TYPE BootType;
|
2011-09-09 12:52:31 +02:00
|
|
|
BDS_LOAD_OPTION_ENTRY *BdsLoadOptionEntry;
|
2011-09-09 12:51:13 +02:00
|
|
|
EFI_DEVICE_PATH *DevicePath;
|
2013-03-12 02:03:23 +01:00
|
|
|
EFI_DEVICE_PATH_PROTOCOL *DevicePathNodes;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *InitrdPathNodes;
|
2011-09-09 12:51:13 +02:00
|
|
|
EFI_DEVICE_PATH_PROTOCOL *InitrdPath;
|
|
|
|
UINTN CmdLineSize;
|
2011-11-02 00:43:37 +01:00
|
|
|
BOOLEAN InitrdSupport;
|
2011-09-09 12:51:13 +02:00
|
|
|
UINTN InitrdSize;
|
2014-04-11 12:56:02 +02:00
|
|
|
UINT8* OptionalData;
|
|
|
|
UINTN OptionalDataSize;
|
2011-08-18 15:21:14 +02:00
|
|
|
|
|
|
|
Attributes = 0;
|
|
|
|
SupportedBootDevice = NULL;
|
|
|
|
|
|
|
|
// List the Boot Devices supported
|
2011-09-09 12:51:13 +02:00
|
|
|
Status = SelectBootDevice (&SupportedBootDevice);
|
2011-08-18 15:21:14 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
2011-06-11 13:58:23 +02:00
|
|
|
|
|
|
|
// Create the specific device path node
|
2014-07-29 16:15:15 +02:00
|
|
|
Status = SupportedBootDevice->Support->CreateDevicePathNode (L"EFI Application or the kernel", &DevicePathNodes);
|
2011-06-11 13:58:23 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
2013-03-12 02:03:23 +01:00
|
|
|
// Append the Device Path to the selected device path
|
|
|
|
DevicePath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)DevicePathNodes);
|
|
|
|
if (DevicePath == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
2011-06-11 13:58:23 +02:00
|
|
|
|
2014-07-29 16:15:15 +02:00
|
|
|
if (SupportedBootDevice->Support->RequestBootType) {
|
2014-04-11 12:57:47 +02:00
|
|
|
Status = BootDeviceGetType (DevicePath, &BootType, &Attributes);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
BootType = BDS_LOADER_EFI_APPLICATION;
|
|
|
|
}
|
|
|
|
|
2011-09-09 12:51:13 +02:00
|
|
|
if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {
|
2011-11-02 00:43:37 +01:00
|
|
|
Print(L"Add an initrd: ");
|
|
|
|
Status = GetHIInputBoolean (&InitrdSupport);
|
|
|
|
if (EFI_ERROR(Status)) {
|
2011-08-18 15:21:14 +02:00
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
|
|
|
|
2011-11-02 00:43:37 +01:00
|
|
|
if (InitrdSupport) {
|
|
|
|
// Create the specific device path node
|
2014-07-29 16:15:15 +02:00
|
|
|
Status = SupportedBootDevice->Support->CreateDevicePathNode (L"initrd", &InitrdPathNodes);
|
2011-11-02 00:43:37 +01:00
|
|
|
if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) { // EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
|
|
|
|
2013-03-12 02:03:23 +01:00
|
|
|
if (InitrdPathNodes != NULL) {
|
|
|
|
// Append the Device Path to the selected device path
|
|
|
|
InitrdPath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNodes);
|
|
|
|
if (InitrdPath == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
2011-11-02 00:43:37 +01:00
|
|
|
} else {
|
|
|
|
InitrdPath = NULL;
|
|
|
|
}
|
2011-08-18 15:21:14 +02:00
|
|
|
} else {
|
2011-09-09 12:51:13 +02:00
|
|
|
InitrdPath = NULL;
|
2011-08-18 15:21:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Print(L"Arguments to pass to the binary: ");
|
2014-04-11 12:57:00 +02:00
|
|
|
Status = GetHIInputAscii (AsciiCmdLine, BOOT_DEVICE_OPTION_MAX);
|
2011-08-18 15:21:14 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto FREE_DEVICE_PATH;
|
|
|
|
}
|
2011-09-09 12:51:13 +02:00
|
|
|
|
2014-04-11 12:57:00 +02:00
|
|
|
CmdLineSize = AsciiStrSize (AsciiCmdLine);
|
2011-09-09 12:51:13 +02:00
|
|
|
InitrdSize = GetDevicePathSize (InitrdPath);
|
|
|
|
|
2014-04-11 12:56:02 +02:00
|
|
|
OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize;
|
|
|
|
BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);
|
2013-01-28 12:44:50 +01:00
|
|
|
|
2011-09-09 12:51:13 +02:00
|
|
|
BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;
|
|
|
|
BootArguments->LinuxArguments.InitrdSize = InitrdSize;
|
2014-05-08 16:53:02 +02:00
|
|
|
CopyMem ((VOID*)(&BootArguments->LinuxArguments + 1), AsciiCmdLine, CmdLineSize);
|
2011-09-09 12:51:13 +02:00
|
|
|
CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);
|
2014-04-11 12:56:02 +02:00
|
|
|
|
|
|
|
OptionalData = (UINT8*)BootArguments;
|
2011-09-09 12:51:13 +02:00
|
|
|
} else {
|
2014-04-11 12:57:00 +02:00
|
|
|
Print (L"Arguments to pass to the EFI Application: ");
|
|
|
|
Status = GetHIInputStr (CmdLine, BOOT_DEVICE_OPTION_MAX);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionalData = (UINT8*)CmdLine;
|
|
|
|
OptionalDataSize = StrSize (CmdLine);
|
2011-06-11 13:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Print(L"Description for this new Entry: ");
|
2011-09-09 12:49:54 +02:00
|
|
|
Status = GetHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);
|
2011-06-11 13:58:23 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto FREE_DEVICE_PATH;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create new entry
|
2011-09-09 12:52:31 +02:00
|
|
|
BdsLoadOptionEntry = (BDS_LOAD_OPTION_ENTRY*)AllocatePool (sizeof(BDS_LOAD_OPTION_ENTRY));
|
2014-04-11 12:56:02 +02:00
|
|
|
Status = BootOptionCreate (Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize, &BdsLoadOptionEntry->BdsLoadOption);
|
2011-06-11 13:58:23 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
2011-09-09 12:52:31 +02:00
|
|
|
InsertTailList (BootOptionsList, &BdsLoadOptionEntry->Link);
|
2011-06-11 13:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FREE_DEVICE_PATH:
|
|
|
|
FreePool (DevicePath);
|
|
|
|
|
|
|
|
EXIT:
|
2011-08-18 15:21:14 +02:00
|
|
|
if (Status == EFI_ABORTED) {
|
|
|
|
Print(L"\n");
|
|
|
|
}
|
|
|
|
FreePool(SupportedBootDevice);
|
2011-06-11 13:58:23 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
BootMenuRemoveBootOption (
|
|
|
|
IN LIST_ENTRY *BootOptionsList
|
|
|
|
)
|
|
|
|
{
|
2011-09-09 12:52:31 +02:00
|
|
|
EFI_STATUS Status;
|
|
|
|
BDS_LOAD_OPTION_ENTRY* BootOptionEntry;
|
2011-06-11 13:58:23 +02:00
|
|
|
|
2014-07-29 16:19:57 +02:00
|
|
|
DisplayBootOptions (BootOptionsList);
|
|
|
|
Status = SelectBootOption (BootOptionsList, DELETE_BOOT_ENTRY, &BootOptionEntry);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2011-06-11 13:58:23 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2011-09-09 12:52:31 +02:00
|
|
|
// If the Boot Option was attached to a list remove it
|
|
|
|
if (!IsListEmpty (&BootOptionEntry->Link)) {
|
|
|
|
// Remove the entry from the list
|
|
|
|
RemoveEntryList (&BootOptionEntry->Link);
|
|
|
|
}
|
|
|
|
|
2011-06-11 13:58:23 +02:00
|
|
|
// Delete the BDS Load option structures
|
2011-09-09 12:52:31 +02:00
|
|
|
BootOptionDelete (BootOptionEntry->BdsLoadOption);
|
2011-06-11 13:58:23 +02:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
BootMenuUpdateBootOption (
|
|
|
|
IN LIST_ENTRY *BootOptionsList
|
|
|
|
)
|
|
|
|
{
|
2011-09-09 12:51:13 +02:00
|
|
|
EFI_STATUS Status;
|
2011-09-09 12:52:31 +02:00
|
|
|
BDS_LOAD_OPTION_ENTRY *BootOptionEntry;
|
2011-09-09 12:51:13 +02:00
|
|
|
BDS_LOAD_OPTION *BootOption;
|
|
|
|
BDS_LOAD_OPTION_SUPPORT* DeviceSupport;
|
|
|
|
ARM_BDS_LOADER_ARGUMENTS* BootArguments;
|
2011-09-09 12:49:54 +02:00
|
|
|
CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];
|
2011-09-09 12:51:13 +02:00
|
|
|
CHAR8 CmdLine[BOOT_DEVICE_OPTION_MAX];
|
2014-04-11 13:01:56 +02:00
|
|
|
CHAR16 UnicodeCmdLine[BOOT_DEVICE_OPTION_MAX];
|
2012-05-02 22:17:36 +02:00
|
|
|
EFI_DEVICE_PATH *DevicePath;
|
|
|
|
EFI_DEVICE_PATH *TempInitrdPath;
|
2011-09-09 12:51:13 +02:00
|
|
|
ARM_BDS_LOADER_TYPE BootType;
|
2014-04-11 12:56:02 +02:00
|
|
|
ARM_BDS_LOADER_OPTIONAL_DATA* LoaderOptionalData;
|
2011-09-09 12:51:13 +02:00
|
|
|
ARM_BDS_LINUX_ARGUMENTS* LinuxArguments;
|
2013-03-12 02:03:23 +01:00
|
|
|
EFI_DEVICE_PATH *InitrdPathNodes;
|
2011-11-02 00:43:37 +01:00
|
|
|
EFI_DEVICE_PATH *InitrdPath;
|
2011-09-09 12:51:13 +02:00
|
|
|
UINTN InitrdSize;
|
|
|
|
UINTN CmdLineSize;
|
2011-11-02 00:43:37 +01:00
|
|
|
BOOLEAN InitrdSupport;
|
2014-04-11 12:56:02 +02:00
|
|
|
UINT8* OptionalData;
|
|
|
|
UINTN OptionalDataSize;
|
2014-04-11 13:01:56 +02:00
|
|
|
BOOLEAN IsPrintable;
|
|
|
|
BOOLEAN IsUnicode;
|
2011-06-11 13:58:23 +02:00
|
|
|
|
2014-07-29 16:19:57 +02:00
|
|
|
DisplayBootOptions (BootOptionsList);
|
|
|
|
Status = SelectBootOption (BootOptionsList, UPDATE_BOOT_ENTRY, &BootOptionEntry);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2011-06-11 13:58:23 +02:00
|
|
|
return Status;
|
|
|
|
}
|
2011-09-09 12:52:31 +02:00
|
|
|
BootOption = BootOptionEntry->BdsLoadOption;
|
2011-06-11 13:58:23 +02:00
|
|
|
|
|
|
|
// Get the device support for this Boot Option
|
2011-11-02 00:43:37 +01:00
|
|
|
Status = BootDeviceGetDeviceSupport (BootOption->FilePathList, &DeviceSupport);
|
2011-06-11 13:58:23 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
2011-09-09 12:56:14 +02:00
|
|
|
Print(L"Not possible to retrieve the supported device for the update\n");
|
2011-06-11 13:58:23 +02:00
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
2014-07-29 16:15:15 +02:00
|
|
|
Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, L"EFI Application or the kernel", &DevicePath);
|
2011-06-11 13:58:23 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
|
|
|
|
2014-07-29 16:15:15 +02:00
|
|
|
if (DeviceSupport->RequestBootType) {
|
2014-04-11 12:57:47 +02:00
|
|
|
Status = BootDeviceGetType (DevicePath, &BootType, &BootOption->Attributes);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-11 12:56:02 +02:00
|
|
|
LoaderOptionalData = BootOption->OptionalData;
|
2014-04-11 13:01:56 +02:00
|
|
|
if (LoaderOptionalData != NULL) {
|
|
|
|
BootType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((UINT32 *)(&LoaderOptionalData->Header.LoaderType));
|
|
|
|
} else {
|
|
|
|
BootType = BDS_LOADER_EFI_APPLICATION;
|
|
|
|
}
|
2011-08-18 15:21:14 +02:00
|
|
|
|
2011-09-09 12:51:13 +02:00
|
|
|
if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {
|
2014-04-11 12:56:02 +02:00
|
|
|
LinuxArguments = &LoaderOptionalData->Arguments.LinuxArguments;
|
2011-09-09 12:51:13 +02:00
|
|
|
|
|
|
|
CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);
|
|
|
|
|
2011-09-13 11:03:10 +02:00
|
|
|
InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);
|
|
|
|
if (InitrdSize > 0) {
|
2011-11-02 00:43:37 +01:00
|
|
|
Print(L"Keep the initrd: ");
|
|
|
|
} else {
|
|
|
|
Print(L"Add an initrd: ");
|
|
|
|
}
|
|
|
|
Status = GetHIInputBoolean (&InitrdSupport);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (InitrdSupport) {
|
|
|
|
if (InitrdSize > 0) {
|
|
|
|
// Case we update the initrd device path
|
2014-07-29 16:15:15 +02:00
|
|
|
Status = DeviceSupport->UpdateDevicePathNode ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize), L"initrd", &InitrdPath);
|
2011-11-02 00:43:37 +01:00
|
|
|
if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) {// EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
|
|
|
InitrdSize = GetDevicePathSize (InitrdPath);
|
|
|
|
} else {
|
|
|
|
// Case we create the initrd device path
|
|
|
|
|
2014-07-29 16:15:15 +02:00
|
|
|
Status = DeviceSupport->CreateDevicePathNode (L"initrd", &InitrdPathNodes);
|
2011-11-02 00:43:37 +01:00
|
|
|
if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) { // EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
|
|
|
|
2013-03-12 02:03:23 +01:00
|
|
|
if (InitrdPathNodes != NULL) {
|
2011-11-02 00:43:37 +01:00
|
|
|
// Duplicate Linux kernel Device Path
|
2012-05-02 22:17:36 +02:00
|
|
|
TempInitrdPath = DuplicateDevicePath (BootOption->FilePathList);
|
2011-11-02 00:43:37 +01:00
|
|
|
// Replace Linux kernel Node by EndNode
|
2012-05-02 22:17:36 +02:00
|
|
|
SetDevicePathEndNode (GetLastDevicePathNode (TempInitrdPath));
|
2013-03-12 02:03:23 +01:00
|
|
|
// Append the Device Path to the selected device path
|
|
|
|
InitrdPath = AppendDevicePath (TempInitrdPath, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNodes);
|
2012-05-02 22:17:36 +02:00
|
|
|
FreePool (TempInitrdPath);
|
2013-03-12 02:03:23 +01:00
|
|
|
if (InitrdPath == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
2012-05-02 22:17:36 +02:00
|
|
|
InitrdSize = GetDevicePathSize (InitrdPath);
|
2011-11-02 00:43:37 +01:00
|
|
|
} else {
|
|
|
|
InitrdPath = NULL;
|
|
|
|
}
|
2011-09-13 11:03:10 +02:00
|
|
|
}
|
2011-11-02 00:43:37 +01:00
|
|
|
} else {
|
|
|
|
InitrdSize = 0;
|
2011-08-18 15:21:14 +02:00
|
|
|
}
|
|
|
|
|
2013-01-28 12:44:50 +01:00
|
|
|
Print(L"Arguments to pass to the binary: ");
|
2011-09-09 12:51:13 +02:00
|
|
|
if (CmdLineSize > 0) {
|
|
|
|
AsciiStrnCpy(CmdLine, (CONST CHAR8*)(LinuxArguments + 1), CmdLineSize);
|
2011-08-18 15:21:14 +02:00
|
|
|
} else {
|
2011-09-09 12:51:13 +02:00
|
|
|
CmdLine[0] = '\0';
|
2011-08-18 15:21:14 +02:00
|
|
|
}
|
2011-09-09 12:51:13 +02:00
|
|
|
Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);
|
2011-08-18 15:21:14 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto FREE_DEVICE_PATH;
|
|
|
|
}
|
2011-09-09 12:51:13 +02:00
|
|
|
|
|
|
|
CmdLineSize = AsciiStrSize (CmdLine);
|
|
|
|
|
2014-04-11 12:56:02 +02:00
|
|
|
OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize;
|
|
|
|
BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);
|
2011-09-09 12:51:13 +02:00
|
|
|
BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;
|
|
|
|
BootArguments->LinuxArguments.InitrdSize = InitrdSize;
|
|
|
|
CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize);
|
2012-02-09 16:33:02 +01:00
|
|
|
CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);
|
2014-04-11 12:56:02 +02:00
|
|
|
|
|
|
|
OptionalData = (UINT8*)BootArguments;
|
2011-09-09 12:51:13 +02:00
|
|
|
} else {
|
2014-04-11 13:01:56 +02:00
|
|
|
Print (L"Arguments to pass to the EFI Application: ");
|
|
|
|
|
|
|
|
if (BootOption->OptionalDataSize > 0) {
|
|
|
|
IsPrintable = IsPrintableString (BootOption->OptionalData, &IsUnicode);
|
|
|
|
if (IsPrintable) {
|
|
|
|
if (IsUnicode) {
|
|
|
|
StrnCpy (UnicodeCmdLine, BootOption->OptionalData, BootOption->OptionalDataSize / 2);
|
|
|
|
} else {
|
|
|
|
AsciiStrnCpy (CmdLine, BootOption->OptionalData, BootOption->OptionalDataSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
UnicodeCmdLine[0] = L'\0';
|
|
|
|
IsPrintable = TRUE;
|
|
|
|
IsUnicode = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We do not request arguments for OptionalData that cannot be printed
|
|
|
|
if (IsPrintable) {
|
|
|
|
if (IsUnicode) {
|
|
|
|
Status = EditHIInputStr (UnicodeCmdLine, BOOT_DEVICE_OPTION_MAX);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto FREE_DEVICE_PATH;
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionalData = (UINT8*)UnicodeCmdLine;
|
|
|
|
OptionalDataSize = StrSize (UnicodeCmdLine);
|
|
|
|
} else {
|
|
|
|
Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto FREE_DEVICE_PATH;
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionalData = (UINT8*)CmdLine;
|
|
|
|
OptionalDataSize = AsciiStrSize (CmdLine);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We keep the former OptionalData
|
|
|
|
OptionalData = BootOption->OptionalData;
|
|
|
|
OptionalDataSize = BootOption->OptionalDataSize;
|
|
|
|
}
|
2011-06-11 13:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Print(L"Description for this new Entry: ");
|
2011-09-13 11:03:10 +02:00
|
|
|
StrnCpy (BootDescription, BootOption->Description, BOOT_DEVICE_DESCRIPTION_MAX);
|
2011-09-09 12:49:54 +02:00
|
|
|
Status = EditHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);
|
2011-06-11 13:58:23 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto FREE_DEVICE_PATH;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the entry
|
2014-04-11 12:56:02 +02:00
|
|
|
Status = BootOptionUpdate (BootOption, BootOption->Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize);
|
2011-06-11 13:58:23 +02:00
|
|
|
|
|
|
|
FREE_DEVICE_PATH:
|
|
|
|
FreePool (DevicePath);
|
|
|
|
|
|
|
|
EXIT:
|
2011-08-18 13:29:26 +02:00
|
|
|
if (Status == EFI_ABORTED) {
|
|
|
|
Print(L"\n");
|
|
|
|
}
|
2011-06-11 13:58:23 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2014-07-29 16:19:57 +02:00
|
|
|
/**
|
|
|
|
Reorder boot options
|
|
|
|
|
|
|
|
Ask for the boot option to move and then move it when up or down arrows
|
|
|
|
are pressed. This function is called when the user selects the "Reorder Boot
|
|
|
|
Device Entries" entry in the boot manager menu.
|
|
|
|
The order of the boot options in BootOptionList and in the UEFI BootOrder
|
|
|
|
global variable are kept coherent until the user confirm his reordering (ie:
|
|
|
|
he does not exit by pressing escape).
|
|
|
|
|
|
|
|
@param[in] BootOptionsList List of the boot devices constructed in
|
|
|
|
BootMenuMain()
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS No error encountered.
|
|
|
|
@retval !EFI_SUCCESS An error has occured either in the selection of the
|
|
|
|
boot option to move or while interacting with the user.
|
|
|
|
|
|
|
|
**/
|
|
|
|
STATIC
|
|
|
|
EFI_STATUS
|
|
|
|
BootMenuReorderBootOptions (
|
|
|
|
IN LIST_ENTRY *BootOptionsList
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
BDS_LOAD_OPTION_ENTRY *BootOptionEntry;
|
|
|
|
LIST_ENTRY *SelectedEntry;
|
|
|
|
LIST_ENTRY *PrevEntry;
|
|
|
|
BOOLEAN Move;
|
|
|
|
BOOLEAN Save;
|
|
|
|
BOOLEAN Cancel;
|
|
|
|
UINTN WaitIndex;
|
|
|
|
EFI_INPUT_KEY Key;
|
|
|
|
LIST_ENTRY *SecondEntry;
|
|
|
|
UINTN BootOrderSize;
|
|
|
|
UINT16 *BootOrder;
|
|
|
|
LIST_ENTRY *Entry;
|
|
|
|
UINTN Index;
|
|
|
|
|
|
|
|
DisplayBootOptions (BootOptionsList);
|
|
|
|
|
|
|
|
// Ask to select the boot option to move
|
|
|
|
while (TRUE) {
|
|
|
|
Status = SelectBootOption (BootOptionsList, MOVE_BOOT_ENTRY, &BootOptionEntry);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ErrorExit;
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectedEntry = &BootOptionEntry->Link;
|
|
|
|
// Note down the previous entry in the list to be able to cancel changes
|
|
|
|
PrevEntry = GetPreviousNode (BootOptionsList, SelectedEntry);
|
|
|
|
|
|
|
|
// Start of interaction
|
|
|
|
while (TRUE) {
|
|
|
|
Print (
|
|
|
|
L"* Use up/down arrows to move the entry '%s'",
|
|
|
|
BootOptionEntry->BdsLoadOption->Description
|
|
|
|
);
|
|
|
|
|
|
|
|
// Wait for a move, save or cancel request
|
|
|
|
Move = FALSE;
|
|
|
|
Save = FALSE;
|
|
|
|
Cancel = FALSE;
|
|
|
|
do {
|
|
|
|
Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &WaitIndex);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
|
|
|
|
}
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
Print (L"\n");
|
|
|
|
goto ErrorExit;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Key.ScanCode) {
|
|
|
|
case SCAN_NULL:
|
|
|
|
Save = (Key.UnicodeChar == CHAR_LINEFEED) ||
|
|
|
|
(Key.UnicodeChar == CHAR_CARRIAGE_RETURN) ||
|
|
|
|
(Key.UnicodeChar == 0x7f);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCAN_UP:
|
|
|
|
SecondEntry = GetPreviousNode (BootOptionsList, SelectedEntry);
|
|
|
|
Move = SecondEntry != BootOptionsList;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCAN_DOWN:
|
|
|
|
SecondEntry = GetNextNode (BootOptionsList, SelectedEntry);
|
|
|
|
Move = SecondEntry != BootOptionsList;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCAN_ESC:
|
|
|
|
Cancel = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while ((!Move) && (!Save) && (!Cancel));
|
|
|
|
|
|
|
|
if (Move) {
|
|
|
|
SwapListEntries (SelectedEntry, SecondEntry);
|
|
|
|
} else {
|
|
|
|
if (Save) {
|
|
|
|
Status = GetGlobalEnvironmentVariable (
|
|
|
|
L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder
|
|
|
|
);
|
|
|
|
BootOrderSize /= sizeof (UINT16);
|
|
|
|
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
// The order of the boot options in the 'BootOptionsList' is the
|
|
|
|
// new order that has been just defined by the user. Save this new
|
|
|
|
// order in "BootOrder" UEFI global variable.
|
|
|
|
Entry = GetFirstNode (BootOptionsList);
|
|
|
|
for (Index = 0; Index < BootOrderSize; Index++) {
|
|
|
|
BootOrder[Index] = (LOAD_OPTION_FROM_LINK (Entry))->LoadOptionIndex;
|
|
|
|
Entry = GetNextNode (BootOptionsList, Entry);
|
|
|
|
}
|
|
|
|
Status = gRT->SetVariable (
|
|
|
|
(CHAR16*)L"BootOrder",
|
|
|
|
&gEfiGlobalVariableGuid,
|
|
|
|
EFI_VARIABLE_NON_VOLATILE |
|
|
|
|
EFI_VARIABLE_BOOTSERVICE_ACCESS |
|
|
|
|
EFI_VARIABLE_RUNTIME_ACCESS,
|
|
|
|
BootOrderSize * sizeof (UINT16),
|
|
|
|
BootOrder
|
|
|
|
);
|
|
|
|
FreePool (BootOrder);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
Print (L"\nAn error occurred, move not completed!\n");
|
|
|
|
Cancel = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Cancel) {
|
|
|
|
//
|
|
|
|
// Restore initial position of the selected boot option
|
|
|
|
//
|
|
|
|
RemoveEntryList (SelectedEntry);
|
|
|
|
InsertHeadList (PrevEntry, SelectedEntry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Print (L"\n");
|
|
|
|
DisplayBootOptions (BootOptionsList);
|
|
|
|
// Saved or cancelled, back to the choice of boot option to move
|
|
|
|
if (!Move) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorExit:
|
|
|
|
return Status ;
|
|
|
|
}
|
|
|
|
|
2011-09-23 01:23:19 +02:00
|
|
|
EFI_STATUS
|
|
|
|
UpdateFdtPath (
|
|
|
|
IN LIST_ENTRY *BootOptionsList
|
|
|
|
)
|
|
|
|
{
|
2011-11-02 00:44:05 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN FdtDevicePathSize;
|
|
|
|
BDS_SUPPORTED_DEVICE *SupportedBootDevice;
|
2013-03-12 02:03:23 +01:00
|
|
|
EFI_DEVICE_PATH_PROTOCOL *FdtDevicePathNodes;
|
2011-11-02 00:44:05 +01:00
|
|
|
EFI_DEVICE_PATH_PROTOCOL *FdtDevicePath;
|
2011-09-23 01:23:19 +02:00
|
|
|
|
|
|
|
Status = SelectBootDevice (&SupportedBootDevice);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the specific device path node
|
2014-07-29 16:15:15 +02:00
|
|
|
Status = SupportedBootDevice->Support->CreateDevicePathNode (L"FDT blob", &FdtDevicePathNodes);
|
2011-09-23 01:23:19 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
Status = EFI_ABORTED;
|
|
|
|
goto EXIT;
|
|
|
|
}
|
|
|
|
|
2013-03-12 02:03:23 +01:00
|
|
|
if (FdtDevicePathNodes != NULL) {
|
2011-09-23 01:23:19 +02:00
|
|
|
// Append the Device Path node to the select device path
|
2013-03-12 02:03:23 +01:00
|
|
|
FdtDevicePath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, FdtDevicePathNodes);
|
2011-11-02 00:44:05 +01:00
|
|
|
FdtDevicePathSize = GetDevicePathSize (FdtDevicePath);
|
2013-01-28 12:44:50 +01:00
|
|
|
Status = gRT->SetVariable (
|
|
|
|
(CHAR16*)L"Fdt",
|
|
|
|
&gArmGlobalVariableGuid,
|
|
|
|
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
|
|
|
FdtDevicePathSize,
|
|
|
|
FdtDevicePath
|
|
|
|
);
|
2011-09-23 01:23:19 +02:00
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
} else {
|
2013-01-28 12:44:50 +01:00
|
|
|
gRT->SetVariable (
|
|
|
|
(CHAR16*)L"Fdt",
|
|
|
|
&gArmGlobalVariableGuid,
|
|
|
|
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
|
|
|
0,
|
|
|
|
NULL
|
|
|
|
);
|
2011-09-23 01:23:19 +02:00
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXIT:
|
|
|
|
if (Status == EFI_ABORTED) {
|
|
|
|
Print(L"\n");
|
|
|
|
}
|
|
|
|
FreePool(SupportedBootDevice);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2014-07-04 16:46:21 +02:00
|
|
|
/**
|
|
|
|
Set boot timeout
|
|
|
|
|
|
|
|
Ask for the boot timeout in seconds and if the input succeeds assign the
|
|
|
|
input value to the UEFI global variable "Timeout". This function is called
|
|
|
|
when the user selects the "Set Boot Timeout" of the boot manager menu.
|
|
|
|
|
|
|
|
@param[in] BootOptionsList List of the boot devices, not used here
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Boot timeout in second retrieved from the standard
|
|
|
|
input and assigned to the UEFI "Timeout" global
|
|
|
|
variable
|
|
|
|
@retval !EFI_SUCCESS Either the input or the setting of the UEFI global
|
|
|
|
variable "Timeout" has failed.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
STATIC
|
|
|
|
BootMenuSetBootTimeout (
|
|
|
|
IN LIST_ENTRY *BootOptionsList
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN Input;
|
|
|
|
UINT16 Timeout;
|
|
|
|
|
|
|
|
Print (L"Timeout duration (in seconds): ");
|
|
|
|
Status = GetHIInputInteger (&Input);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
Print (L"\n");
|
|
|
|
goto ErrorExit;
|
|
|
|
}
|
|
|
|
|
|
|
|
Timeout = Input;
|
|
|
|
Status = gRT->SetVariable (
|
|
|
|
(CHAR16*)L"Timeout",
|
|
|
|
&gEfiGlobalVariableGuid,
|
|
|
|
EFI_VARIABLE_NON_VOLATILE |
|
|
|
|
EFI_VARIABLE_BOOTSERVICE_ACCESS |
|
|
|
|
EFI_VARIABLE_RUNTIME_ACCESS,
|
|
|
|
sizeof (UINT16),
|
|
|
|
&Timeout
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
ErrorExit:
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2011-06-11 13:58:23 +02:00
|
|
|
struct BOOT_MANAGER_ENTRY {
|
|
|
|
CONST CHAR16* Description;
|
|
|
|
EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);
|
|
|
|
} BootManagerEntries[] = {
|
|
|
|
{ L"Add Boot Device Entry", BootMenuAddBootOption },
|
|
|
|
{ L"Update Boot Device Entry", BootMenuUpdateBootOption },
|
|
|
|
{ L"Remove Boot Device Entry", BootMenuRemoveBootOption },
|
2014-07-29 16:19:57 +02:00
|
|
|
{ L"Reorder Boot Device Entries", BootMenuReorderBootOptions },
|
2011-09-23 01:23:19 +02:00
|
|
|
{ L"Update FDT path", UpdateFdtPath },
|
2014-07-04 16:46:21 +02:00
|
|
|
{ L"Set Boot Timeout", BootMenuSetBootTimeout },
|
2011-06-11 13:58:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
BootMenuManager (
|
|
|
|
IN LIST_ENTRY *BootOptionsList
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN Index;
|
|
|
|
UINTN OptionSelected;
|
|
|
|
UINTN BootManagerEntryCount;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
BootManagerEntryCount = sizeof(BootManagerEntries) / sizeof(struct BOOT_MANAGER_ENTRY);
|
|
|
|
|
|
|
|
while (TRUE) {
|
|
|
|
// Display Boot Manager menu
|
|
|
|
for (Index = 0; Index < BootManagerEntryCount; Index++) {
|
|
|
|
Print(L"[%d] %s\n",Index+1,BootManagerEntries[Index]);
|
|
|
|
}
|
|
|
|
Print(L"[%d] Return to main menu\n",Index+1);
|
|
|
|
|
|
|
|
// Select which entry to call
|
|
|
|
Print(L"Choice: ");
|
|
|
|
Status = GetHIInputInteger (&OptionSelected);
|
|
|
|
if (EFI_ERROR(Status) || (OptionSelected == (BootManagerEntryCount+1))) {
|
2011-08-18 13:29:26 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
Print(L"\n");
|
|
|
|
}
|
2011-06-11 13:58:23 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
} else if ((OptionSelected > 0) && (OptionSelected <= BootManagerEntryCount)) {
|
2011-09-09 12:56:14 +02:00
|
|
|
BootManagerEntries[OptionSelected-1].Callback (BootOptionsList);
|
2011-06-11 13:58:23 +02:00
|
|
|
}
|
|
|
|
}
|
2011-09-23 00:53:54 +02:00
|
|
|
// Should never go here
|
2011-06-11 13:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
2012-09-27 17:33:10 +02:00
|
|
|
BootShell (
|
2011-06-11 13:58:23 +02:00
|
|
|
IN LIST_ENTRY *BootOptionsList
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
// Start EFI Shell
|
2014-08-01 20:33:17 +02:00
|
|
|
Status = BdsLoadApplication (gImageHandle, L"Shell", 0, NULL);
|
2011-06-11 13:58:23 +02:00
|
|
|
if (Status == EFI_NOT_FOUND) {
|
|
|
|
Print (L"Error: EFI Application not found.\n");
|
|
|
|
} else if (EFI_ERROR(Status)) {
|
|
|
|
Print (L"Error: Status Code: 0x%X\n",(UINT32)Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct BOOT_MAIN_ENTRY {
|
|
|
|
CONST CHAR16* Description;
|
|
|
|
EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);
|
|
|
|
} BootMainEntries[] = {
|
2012-09-27 17:33:10 +02:00
|
|
|
{ L"Shell", BootShell },
|
2011-06-11 13:58:23 +02:00
|
|
|
{ L"Boot Manager", BootMenuManager },
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
BootMenuMain (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
2011-09-09 12:51:13 +02:00
|
|
|
LIST_ENTRY BootOptionsList;
|
|
|
|
UINTN OptionCount;
|
|
|
|
UINTN BootOptionCount;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
LIST_ENTRY* Entry;
|
|
|
|
BDS_LOAD_OPTION* BootOption;
|
|
|
|
UINTN BootOptionSelected;
|
|
|
|
UINTN Index;
|
|
|
|
UINTN BootMainEntryCount;
|
2014-04-11 13:00:47 +02:00
|
|
|
BOOLEAN IsUnicode;
|
2011-06-11 13:58:23 +02:00
|
|
|
|
2014-04-11 13:00:47 +02:00
|
|
|
BootOption = NULL;
|
2011-06-11 13:58:23 +02:00
|
|
|
BootMainEntryCount = sizeof(BootMainEntries) / sizeof(struct BOOT_MAIN_ENTRY);
|
2011-07-06 18:07:54 +02:00
|
|
|
|
2011-06-11 13:58:23 +02:00
|
|
|
while (TRUE) {
|
2011-09-09 12:52:31 +02:00
|
|
|
// Get Boot#### list
|
|
|
|
BootOptionList (&BootOptionsList);
|
|
|
|
|
2011-06-11 13:58:23 +02:00
|
|
|
OptionCount = 1;
|
|
|
|
|
|
|
|
// Display the Boot options
|
|
|
|
for (Entry = GetFirstNode (&BootOptionsList);
|
|
|
|
!IsNull (&BootOptionsList,Entry);
|
|
|
|
Entry = GetNextNode (&BootOptionsList,Entry)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
BootOption = LOAD_OPTION_FROM_LINK(Entry);
|
|
|
|
|
2011-09-09 12:56:14 +02:00
|
|
|
Print(L"[%d] %s\n", OptionCount, BootOption->Description);
|
2011-06-11 13:58:23 +02:00
|
|
|
|
|
|
|
DEBUG_CODE_BEGIN();
|
|
|
|
CHAR16* DevicePathTxt;
|
|
|
|
EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;
|
2011-09-09 12:51:13 +02:00
|
|
|
ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;
|
|
|
|
UINTN CmdLineSize;
|
2011-09-13 11:03:10 +02:00
|
|
|
ARM_BDS_LOADER_TYPE LoaderType;
|
2011-06-11 13:58:23 +02:00
|
|
|
|
2011-09-09 12:56:14 +02:00
|
|
|
Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
|
2011-06-28 13:50:32 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
// You must provide an implementation of DevicePathToTextProtocol in your firmware (eg: DevicePathDxe)
|
|
|
|
DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathToTextProtocol\n"));
|
|
|
|
return Status;
|
|
|
|
}
|
2011-09-09 12:56:14 +02:00
|
|
|
DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (BootOption->FilePathList, TRUE, TRUE);
|
2011-06-11 13:58:23 +02:00
|
|
|
|
|
|
|
Print(L"\t- %s\n",DevicePathTxt);
|
2011-09-09 12:51:13 +02:00
|
|
|
|
|
|
|
// If it is a supported BootEntry then print its details
|
|
|
|
if (IS_ARM_BDS_BOOTENTRY (BootOption)) {
|
|
|
|
OptionalData = BootOption->OptionalData;
|
|
|
|
LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);
|
|
|
|
if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {
|
|
|
|
if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.InitrdSize) > 0) {
|
|
|
|
CmdLineSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize);
|
|
|
|
DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (
|
|
|
|
GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(&OptionalData->Arguments.LinuxArguments + 1) + CmdLineSize)), TRUE, TRUE);
|
|
|
|
Print(L"\t- Initrd: %s\n", DevicePathTxt);
|
|
|
|
}
|
2014-04-22 12:13:38 +02:00
|
|
|
if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize) > 0) {
|
|
|
|
Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));
|
|
|
|
}
|
2011-06-11 13:58:23 +02:00
|
|
|
}
|
2013-03-12 01:41:52 +01:00
|
|
|
|
|
|
|
switch (LoaderType) {
|
|
|
|
case BDS_LOADER_EFI_APPLICATION:
|
|
|
|
Print(L"\t- LoaderType: EFI Application\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BDS_LOADER_KERNEL_LINUX_ATAG:
|
|
|
|
Print(L"\t- LoaderType: Linux kernel with ATAG support\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BDS_LOADER_KERNEL_LINUX_FDT:
|
|
|
|
Print(L"\t- LoaderType: Linux kernel with FDT support\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Print(L"\t- LoaderType: Not recognized (%d)\n", LoaderType);
|
|
|
|
}
|
2014-04-11 13:00:47 +02:00
|
|
|
} else if (BootOption->OptionalData != NULL) {
|
|
|
|
if (IsPrintableString (BootOption->OptionalData, &IsUnicode)) {
|
|
|
|
if (IsUnicode) {
|
|
|
|
Print (L"\t- Arguments: %s\n", BootOption->OptionalData);
|
|
|
|
} else {
|
|
|
|
AsciiPrint ("\t- Arguments: %a\n", BootOption->OptionalData);
|
|
|
|
}
|
|
|
|
}
|
2011-06-11 13:58:23 +02:00
|
|
|
}
|
|
|
|
FreePool(DevicePathTxt);
|
|
|
|
DEBUG_CODE_END();
|
|
|
|
|
|
|
|
OptionCount++;
|
|
|
|
}
|
|
|
|
BootOptionCount = OptionCount-1;
|
|
|
|
|
|
|
|
// Display the hardcoded Boot entries
|
|
|
|
for (Index = 0; Index < BootMainEntryCount; Index++) {
|
|
|
|
Print(L"[%d] %s\n",OptionCount,BootMainEntries[Index]);
|
|
|
|
OptionCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Request the boot entry from the user
|
|
|
|
BootOptionSelected = 0;
|
|
|
|
while (BootOptionSelected == 0) {
|
|
|
|
Print(L"Start: ");
|
|
|
|
Status = GetHIInputInteger (&BootOptionSelected);
|
|
|
|
if (EFI_ERROR(Status) || (BootOptionSelected == 0) || (BootOptionSelected > OptionCount)) {
|
|
|
|
Print(L"Invalid input (max %d)\n",(OptionCount-1));
|
|
|
|
BootOptionSelected = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start the selected entry
|
|
|
|
if (BootOptionSelected > BootOptionCount) {
|
|
|
|
// Start the hardcoded entry
|
|
|
|
Status = BootMainEntries[BootOptionSelected - BootOptionCount - 1].Callback (&BootOptionsList);
|
|
|
|
} else {
|
|
|
|
// Find the selected entry from the Boot#### list
|
|
|
|
Index = 1;
|
|
|
|
for (Entry = GetFirstNode (&BootOptionsList);
|
|
|
|
!IsNull (&BootOptionsList,Entry);
|
|
|
|
Entry = GetNextNode (&BootOptionsList,Entry)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (Index == BootOptionSelected) {
|
|
|
|
BootOption = LOAD_OPTION_FROM_LINK(Entry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = BootOptionStart (BootOption);
|
|
|
|
}
|
|
|
|
}
|
2011-09-23 00:53:54 +02:00
|
|
|
// Should never go here
|
2011-06-11 13:58:23 +02:00
|
|
|
}
|