From 4aa2417061f832009b92aac786ed7307ce088503 Mon Sep 17 00:00:00 2001 From: oliviermartin Date: Fri, 9 Sep 2011 10:54:33 +0000 Subject: 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 --- ArmPkg/Include/Library/BdsLib.h | 38 ++++++++++++++++++++++++++ ArmPkg/Library/BdsLib/BdsHelper.c | 53 +++++++++++++++++++++++++++++++++++++ ArmPkg/Library/BdsLib/BdsInternal.h | 26 ++++++++++-------- ArmPkg/Library/BdsLib/BdsLib.inf | 2 ++ 4 files changed, 108 insertions(+), 11 deletions(-) (limited to 'ArmPkg') diff --git a/ArmPkg/Include/Library/BdsLib.h b/ArmPkg/Include/Library/BdsLib.h index bbbdae8..e9337d6 100644 --- a/ArmPkg/Include/Library/BdsLib.h +++ b/ArmPkg/Include/Library/BdsLib.h @@ -66,6 +66,36 @@ BdsConnectAllDrivers ( 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 @@ -123,4 +153,12 @@ BdsLoadApplication ( 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 diff --git a/ArmPkg/Library/BdsLib/BdsHelper.c b/ArmPkg/Library/BdsLib/BdsHelper.c index a006e90..d971a76 100644 --- a/ArmPkg/Library/BdsLib/BdsHelper.c +++ b/ArmPkg/Library/BdsLib/BdsHelper.c @@ -289,3 +289,56 @@ PrintPerformance ( CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Total Time = %ld ms\n\n", DivU64x64Remainder (MultU64x32 (TimeStamp, 1000), TicksPerSecond, NULL)); 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; +} diff --git a/ArmPkg/Library/BdsLib/BdsInternal.h b/ArmPkg/Library/BdsLib/BdsInternal.h index af69049..d450e8e 100644 --- a/ArmPkg/Library/BdsLib/BdsInternal.h +++ b/ArmPkg/Library/BdsLib/BdsInternal.h @@ -25,7 +25,10 @@ #include #include #include +#include +#include +#include #include #include @@ -37,19 +40,19 @@ typedef BOOLEAN (*BDS_FILE_LOADER_SUPPORT) ( - IN EFI_DEVICE_PATH *DevicePath, - IN EFI_HANDLE Handle, - IN EFI_DEVICE_PATH *RemainingDevicePath - ); + IN EFI_DEVICE_PATH *DevicePath, + IN EFI_HANDLE Handle, + IN EFI_DEVICE_PATH *RemainingDevicePath + ); typedef EFI_STATUS (*BDS_FILE_LOADER_LOAD_IMAGE) ( - IN EFI_DEVICE_PATH *DevicePath, - IN EFI_HANDLE Handle, - IN EFI_DEVICE_PATH *RemainingDevicePath, - IN EFI_ALLOCATE_TYPE Type, - IN OUT EFI_PHYSICAL_ADDRESS* Image, - OUT UINTN *ImageSize - ); + IN EFI_DEVICE_PATH *DevicePath, + IN EFI_HANDLE Handle, + IN EFI_DEVICE_PATH *RemainingDevicePath, + IN EFI_ALLOCATE_TYPE Type, + IN OUT EFI_PHYSICAL_ADDRESS* Image, + OUT UINTN *ImageSize + ); typedef struct { BDS_FILE_LOADER_SUPPORT Support; @@ -78,6 +81,7 @@ VOID PrintPerformance ( VOID ); + EFI_STATUS BdsLoadImage ( IN EFI_DEVICE_PATH *DevicePath, diff --git a/ArmPkg/Library/BdsLib/BdsLib.inf b/ArmPkg/Library/BdsLib/BdsLib.inf index b9b2006..595e943 100644 --- a/ArmPkg/Library/BdsLib/BdsLib.inf +++ b/ArmPkg/Library/BdsLib/BdsLib.inf @@ -24,6 +24,7 @@ BdsLinuxLoader.c BdsAppLoader.c BdsHelper.c + BdsLoadOption.c [Packages] MdePkg/MdePkg.dec @@ -52,6 +53,7 @@ gEfiPxeBaseCodeProtocolGuid gEfiDiskIoProtocolGuid gEfiUsbIoProtocolGuid + gEfiLoadedImageProtocolGuid [FeaturePcd] -- cgit v1.1