mirror of https://github.com/acidanthera/audk.git
ArmPkg/BdsLib: Move some functions used to create/update BDS Boot Entry from ArmPlatformPkg/Bds to ArmPkg/BdsLib
These functions can be reused by any EFI application to add/update a BDS Boot Entry. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12314 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
2755d844f9
commit
4aa2417061
|
@ -66,6 +66,36 @@ BdsConnectAllDrivers (
|
||||||
VOID
|
VOID
|
||||||
);
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
GetEnvironmentVariable (
|
||||||
|
IN CONST CHAR16* VariableName,
|
||||||
|
IN VOID* DefaultValue,
|
||||||
|
IN OUT UINTN* Size,
|
||||||
|
OUT VOID** Value
|
||||||
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
BootOptionFromLoadOptionIndex (
|
||||||
|
IN UINT16 LoadOptionIndex,
|
||||||
|
OUT BDS_LOAD_OPTION** BdsLoadOption
|
||||||
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
BootOptionFromLoadOptionVariable (
|
||||||
|
IN CHAR16* BootVariableName,
|
||||||
|
OUT BDS_LOAD_OPTION** BdsLoadOption
|
||||||
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
BootOptionToLoadOptionVariable (
|
||||||
|
IN BDS_LOAD_OPTION* BdsLoadOption
|
||||||
|
);
|
||||||
|
|
||||||
|
UINT16
|
||||||
|
BootOptionAllocateBootIndex (
|
||||||
|
VOID
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Start a Linux kernel from a Device Path
|
Start a Linux kernel from a Device Path
|
||||||
|
|
||||||
|
@ -123,4 +153,12 @@ BdsLoadApplication (
|
||||||
IN VOID* LoadOptions
|
IN VOID* LoadOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
BdsLoadImage (
|
||||||
|
IN EFI_DEVICE_PATH *DevicePath,
|
||||||
|
IN EFI_ALLOCATE_TYPE Type,
|
||||||
|
IN OUT EFI_PHYSICAL_ADDRESS* Image,
|
||||||
|
OUT UINTN *FileSize
|
||||||
|
);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -289,3 +289,56 @@ PrintPerformance (
|
||||||
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Total Time = %ld ms\n\n", DivU64x64Remainder (MultU64x32 (TimeStamp, 1000), TicksPerSecond, NULL));
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Total Time = %ld ms\n\n", DivU64x64Remainder (MultU64x32 (TimeStamp, 1000), TicksPerSecond, NULL));
|
||||||
SerialPortWrite ((UINT8 *) Buffer, CharCount);
|
SerialPortWrite ((UINT8 *) Buffer, CharCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
GetEnvironmentVariable (
|
||||||
|
IN CONST CHAR16* VariableName,
|
||||||
|
IN VOID* DefaultValue,
|
||||||
|
IN OUT UINTN* Size,
|
||||||
|
OUT VOID** Value
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
UINTN VariableSize;
|
||||||
|
|
||||||
|
// Try to get the variable size.
|
||||||
|
*Value = NULL;
|
||||||
|
VariableSize = 0;
|
||||||
|
Status = gRT->GetVariable ((CHAR16 *) VariableName, &gEfiGlobalVariableGuid, NULL, &VariableSize, *Value);
|
||||||
|
if (Status == EFI_NOT_FOUND) {
|
||||||
|
if ((DefaultValue != NULL) && (Size != NULL) && (*Size != 0)) {
|
||||||
|
// If the environment variable does not exist yet then set it with the default value
|
||||||
|
Status = gRT->SetVariable (
|
||||||
|
(CHAR16*)VariableName,
|
||||||
|
&gEfiGlobalVariableGuid,
|
||||||
|
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
|
||||||
|
*Size,
|
||||||
|
DefaultValue
|
||||||
|
);
|
||||||
|
*Value = DefaultValue;
|
||||||
|
} else {
|
||||||
|
return EFI_NOT_FOUND;
|
||||||
|
}
|
||||||
|
} else if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||||
|
// Get the environment variable value
|
||||||
|
*Value = AllocatePool (VariableSize);
|
||||||
|
if (*Value == NULL) {
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = gRT->GetVariable ((CHAR16 *)VariableName, &gEfiGlobalVariableGuid, NULL, &VariableSize, *Value);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
FreePool(*Value);
|
||||||
|
return EFI_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Size) {
|
||||||
|
*Size = VariableSize;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
*Value = DefaultValue;
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
|
@ -25,7 +25,10 @@
|
||||||
#include <Library/DebugLib.h>
|
#include <Library/DebugLib.h>
|
||||||
#include <Library/BdsLib.h>
|
#include <Library/BdsLib.h>
|
||||||
#include <Library/PerformanceLib.h>
|
#include <Library/PerformanceLib.h>
|
||||||
|
#include <Library/PrintLib.h>
|
||||||
|
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||||
|
|
||||||
|
#include <Guid/GlobalVariable.h>
|
||||||
#include <Guid/FileInfo.h>
|
#include <Guid/FileInfo.h>
|
||||||
|
|
||||||
#include <Protocol/DevicePath.h>
|
#include <Protocol/DevicePath.h>
|
||||||
|
@ -37,19 +40,19 @@
|
||||||
|
|
||||||
|
|
||||||
typedef BOOLEAN (*BDS_FILE_LOADER_SUPPORT) (
|
typedef BOOLEAN (*BDS_FILE_LOADER_SUPPORT) (
|
||||||
IN EFI_DEVICE_PATH *DevicePath,
|
IN EFI_DEVICE_PATH *DevicePath,
|
||||||
IN EFI_HANDLE Handle,
|
IN EFI_HANDLE Handle,
|
||||||
IN EFI_DEVICE_PATH *RemainingDevicePath
|
IN EFI_DEVICE_PATH *RemainingDevicePath
|
||||||
);
|
);
|
||||||
|
|
||||||
typedef EFI_STATUS (*BDS_FILE_LOADER_LOAD_IMAGE) (
|
typedef EFI_STATUS (*BDS_FILE_LOADER_LOAD_IMAGE) (
|
||||||
IN EFI_DEVICE_PATH *DevicePath,
|
IN EFI_DEVICE_PATH *DevicePath,
|
||||||
IN EFI_HANDLE Handle,
|
IN EFI_HANDLE Handle,
|
||||||
IN EFI_DEVICE_PATH *RemainingDevicePath,
|
IN EFI_DEVICE_PATH *RemainingDevicePath,
|
||||||
IN EFI_ALLOCATE_TYPE Type,
|
IN EFI_ALLOCATE_TYPE Type,
|
||||||
IN OUT EFI_PHYSICAL_ADDRESS* Image,
|
IN OUT EFI_PHYSICAL_ADDRESS* Image,
|
||||||
OUT UINTN *ImageSize
|
OUT UINTN *ImageSize
|
||||||
);
|
);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
BDS_FILE_LOADER_SUPPORT Support;
|
BDS_FILE_LOADER_SUPPORT Support;
|
||||||
|
@ -78,6 +81,7 @@ VOID
|
||||||
PrintPerformance (
|
PrintPerformance (
|
||||||
VOID
|
VOID
|
||||||
);
|
);
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
BdsLoadImage (
|
BdsLoadImage (
|
||||||
IN EFI_DEVICE_PATH *DevicePath,
|
IN EFI_DEVICE_PATH *DevicePath,
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
BdsLinuxLoader.c
|
BdsLinuxLoader.c
|
||||||
BdsAppLoader.c
|
BdsAppLoader.c
|
||||||
BdsHelper.c
|
BdsHelper.c
|
||||||
|
BdsLoadOption.c
|
||||||
|
|
||||||
[Packages]
|
[Packages]
|
||||||
MdePkg/MdePkg.dec
|
MdePkg/MdePkg.dec
|
||||||
|
@ -52,6 +53,7 @@
|
||||||
gEfiPxeBaseCodeProtocolGuid
|
gEfiPxeBaseCodeProtocolGuid
|
||||||
gEfiDiskIoProtocolGuid
|
gEfiDiskIoProtocolGuid
|
||||||
gEfiUsbIoProtocolGuid
|
gEfiUsbIoProtocolGuid
|
||||||
|
gEfiLoadedImageProtocolGuid
|
||||||
|
|
||||||
[FeaturePcd]
|
[FeaturePcd]
|
||||||
|
|
||||||
|
|
|
@ -14,59 +14,6 @@
|
||||||
|
|
||||||
#include "BdsInternal.h"
|
#include "BdsInternal.h"
|
||||||
|
|
||||||
EFI_STATUS
|
|
||||||
GetEnvironmentVariable (
|
|
||||||
IN CONST CHAR16* VariableName,
|
|
||||||
IN VOID* DefaultValue,
|
|
||||||
IN OUT UINTN* Size,
|
|
||||||
OUT VOID** Value
|
|
||||||
)
|
|
||||||
{
|
|
||||||
EFI_STATUS Status;
|
|
||||||
UINTN VariableSize;
|
|
||||||
|
|
||||||
// Try to get the variable size.
|
|
||||||
*Value = NULL;
|
|
||||||
VariableSize = 0;
|
|
||||||
Status = gRT->GetVariable ((CHAR16 *) VariableName, &gEfiGlobalVariableGuid, NULL, &VariableSize, *Value);
|
|
||||||
if (Status == EFI_NOT_FOUND) {
|
|
||||||
if ((DefaultValue != NULL) && (Size != NULL) && (*Size != 0)) {
|
|
||||||
// If the environment variable does not exist yet then set it with the default value
|
|
||||||
Status = gRT->SetVariable (
|
|
||||||
(CHAR16*)VariableName,
|
|
||||||
&gEfiGlobalVariableGuid,
|
|
||||||
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
|
|
||||||
*Size,
|
|
||||||
DefaultValue
|
|
||||||
);
|
|
||||||
*Value = DefaultValue;
|
|
||||||
} else {
|
|
||||||
return EFI_NOT_FOUND;
|
|
||||||
}
|
|
||||||
} else if (Status == EFI_BUFFER_TOO_SMALL) {
|
|
||||||
// Get the environment variable value
|
|
||||||
*Value = AllocatePool (VariableSize);
|
|
||||||
if (*Value == NULL) {
|
|
||||||
return EFI_OUT_OF_RESOURCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
Status = gRT->GetVariable ((CHAR16 *)VariableName, &gEfiGlobalVariableGuid, NULL, &VariableSize, *Value);
|
|
||||||
if (EFI_ERROR (Status)) {
|
|
||||||
FreePool(*Value);
|
|
||||||
return EFI_INVALID_PARAMETER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Size) {
|
|
||||||
*Size = VariableSize;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
*Value = DefaultValue;
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EditHIInputStr (
|
EditHIInputStr (
|
||||||
IN OUT CHAR16 *CmdLine,
|
IN OUT CHAR16 *CmdLine,
|
||||||
|
@ -321,17 +268,12 @@ BdsStartBootOption (
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
EFI_LOAD_OPTION EfiLoadOption;
|
|
||||||
UINTN EfiLoadOptionSize;
|
|
||||||
BDS_LOAD_OPTION *BdsLoadOption;
|
BDS_LOAD_OPTION *BdsLoadOption;
|
||||||
|
|
||||||
Status = GetEnvironmentVariable (BootOption, NULL, &EfiLoadOptionSize, (VOID**)&EfiLoadOption);
|
Status = BootOptionFromLoadOptionVariable (BootOption, &BdsLoadOption);
|
||||||
if (!EFI_ERROR(Status)) {
|
if (!EFI_ERROR(Status)) {
|
||||||
Status = BootOptionParseLoadOption (EfiLoadOption, EfiLoadOptionSize, &BdsLoadOption);
|
Status = BootOptionStart (BdsLoadOption);
|
||||||
if (!EFI_ERROR(Status)) {
|
FreePool (BdsLoadOption);
|
||||||
Status = BootOptionStart (BdsLoadOption);
|
|
||||||
FreePool (BdsLoadOption);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!EFI_ERROR(Status)) {
|
if (!EFI_ERROR(Status)) {
|
||||||
Status = EFI_SUCCESS;
|
Status = EFI_SUCCESS;
|
||||||
|
|
|
@ -91,73 +91,6 @@ BootOptionStart (
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
EFI_STATUS
|
|
||||||
BootOptionParseLoadOption (
|
|
||||||
IN EFI_LOAD_OPTION EfiLoadOption,
|
|
||||||
IN UINTN EfiLoadOptionSize,
|
|
||||||
OUT BDS_LOAD_OPTION **BdsLoadOption
|
|
||||||
)
|
|
||||||
{
|
|
||||||
BDS_LOAD_OPTION *LoadOption;
|
|
||||||
UINTN FilePathListLength;
|
|
||||||
UINTN DescriptionLength;
|
|
||||||
|
|
||||||
if (EfiLoadOption == NULL) {
|
|
||||||
return EFI_INVALID_PARAMETER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EfiLoadOptionSize < sizeof(UINT32) + sizeof(UINT16) + sizeof(CHAR16) + sizeof(EFI_DEVICE_PATH_PROTOCOL)) {
|
|
||||||
return EFI_BAD_BUFFER_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadOption = (BDS_LOAD_OPTION*)AllocatePool(sizeof(BDS_LOAD_OPTION));
|
|
||||||
if (LoadOption == NULL) {
|
|
||||||
return EFI_OUT_OF_RESOURCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadOption->LoadOption = EfiLoadOption;
|
|
||||||
LoadOption->LoadOptionSize = EfiLoadOptionSize;
|
|
||||||
|
|
||||||
LoadOption->Attributes = *(UINT32*)EfiLoadOption;
|
|
||||||
FilePathListLength = *(UINT16*)(EfiLoadOption + sizeof(UINT32));
|
|
||||||
LoadOption->Description = (CHAR16*)(EfiLoadOption + sizeof(UINT32) + sizeof(UINT16));
|
|
||||||
DescriptionLength = StrSize (LoadOption->Description);
|
|
||||||
LoadOption->FilePathList = (EFI_DEVICE_PATH_PROTOCOL*)(EfiLoadOption + sizeof(UINT32) + sizeof(UINT16) + DescriptionLength);
|
|
||||||
|
|
||||||
if ((UINTN)((UINT8*)LoadOption->FilePathList + FilePathListLength - EfiLoadOption) == EfiLoadOptionSize) {
|
|
||||||
LoadOption->OptionalData = NULL;
|
|
||||||
} else {
|
|
||||||
LoadOption->OptionalData = (BDS_LOADER_OPTIONAL_DATA *)((UINT8*)LoadOption->FilePathList + FilePathListLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
*BdsLoadOption = LoadOption;
|
|
||||||
return EFI_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
EFI_STATUS
|
|
||||||
BootOptionFromLoadOptionVariable (
|
|
||||||
IN UINT16 LoadOptionIndex,
|
|
||||||
OUT BDS_LOAD_OPTION **BdsLoadOption
|
|
||||||
)
|
|
||||||
{
|
|
||||||
EFI_STATUS Status;
|
|
||||||
CHAR16 BootVariableName[9];
|
|
||||||
EFI_LOAD_OPTION EfiLoadOption;
|
|
||||||
UINTN EfiLoadOptionSize;
|
|
||||||
|
|
||||||
UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", LoadOptionIndex);
|
|
||||||
|
|
||||||
Status = GetEnvironmentVariable (BootVariableName, NULL, &EfiLoadOptionSize, (VOID**)&EfiLoadOption);
|
|
||||||
if (!EFI_ERROR(Status)) {
|
|
||||||
Status = BootOptionParseLoadOption (EfiLoadOption,EfiLoadOptionSize,BdsLoadOption);
|
|
||||||
if (!EFI_ERROR(Status)) {
|
|
||||||
(*BdsLoadOption)->LoadOptionIndex = LoadOptionIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
BootOptionList (
|
BootOptionList (
|
||||||
IN OUT LIST_ENTRY *BootOptionList
|
IN OUT LIST_ENTRY *BootOptionList
|
||||||
|
@ -179,7 +112,7 @@ BootOptionList (
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {
|
for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {
|
||||||
Status = BootOptionFromLoadOptionVariable (BootOrder[Index],&BdsLoadOption);
|
Status = BootOptionFromLoadOptionIndex (BootOrder[Index], &BdsLoadOption);
|
||||||
if (!EFI_ERROR(Status)) {
|
if (!EFI_ERROR(Status)) {
|
||||||
BdsLoadOptionEntry = (BDS_LOAD_OPTION_ENTRY*)AllocatePool(sizeof(BDS_LOAD_OPTION_ENTRY));
|
BdsLoadOptionEntry = (BDS_LOAD_OPTION_ENTRY*)AllocatePool(sizeof(BDS_LOAD_OPTION_ENTRY));
|
||||||
BdsLoadOptionEntry->BdsLoadOption = BdsLoadOption;
|
BdsLoadOptionEntry->BdsLoadOption = BdsLoadOption;
|
||||||
|
@ -190,38 +123,6 @@ BootOptionList (
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT16
|
|
||||||
BootOptionAllocateBootIndex (
|
|
||||||
VOID
|
|
||||||
)
|
|
||||||
{
|
|
||||||
EFI_STATUS Status;
|
|
||||||
UINTN Index;
|
|
||||||
UINT32 BootIndex;
|
|
||||||
UINT16 *BootOrder;
|
|
||||||
UINTN BootOrderSize;
|
|
||||||
BOOLEAN Found;
|
|
||||||
|
|
||||||
// Get the Boot Option Order from the environment variable
|
|
||||||
Status = GetEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder);
|
|
||||||
if (!EFI_ERROR(Status)) {
|
|
||||||
for (BootIndex = 0; BootIndex <= 0xFFFF; BootIndex++) {
|
|
||||||
Found = FALSE;
|
|
||||||
for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {
|
|
||||||
if (BootOrder[Index] == BootIndex) {
|
|
||||||
Found = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!Found) {
|
|
||||||
return BootIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Return the first index
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
BootOptionSetFields (
|
BootOptionSetFields (
|
||||||
|
|
Loading…
Reference in New Issue