Move VariablePei/VariableDxe/EmuVarible to /Variable folder of MdeModulePkg.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3370 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
yshang1
2007-07-19 10:09:07 +00:00
parent 6357d9edf0
commit 8d3a5c82a4
21 changed files with 4740 additions and 9 deletions

View File

@@ -0,0 +1,229 @@
/*++
Copyright (c) 2006 - 2007, Intel Corporation
All rights reserved. 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.
Module Name:
InitVariable.c
Abstract:
Revision History
--*/
#include "Variable.h"
//
// Event for Exit Boot Services Callback
//
STATIC EFI_EVENT mExitBootServicesEvent = NULL;
//
// Don't use module globals after the SetVirtualAddress map is signaled
//
extern ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;
EFI_STATUS
EFIAPI
RuntimeServiceGetVariable (
IN CHAR16 *VariableName,
IN EFI_GUID * VendorGuid,
OUT UINT32 *Attributes OPTIONAL,
IN OUT UINTN *DataSize,
OUT VOID *Data
)
/*++
Routine Description:
Arguments:
Returns:
--*/
{
return GetVariable (
VariableName,
VendorGuid,
Attributes OPTIONAL,
DataSize,
Data,
&mVariableModuleGlobal->VariableGlobal[Physical],
mVariableModuleGlobal->FvbInstance
);
}
EFI_STATUS
EFIAPI
RuntimeServiceGetNextVariableName (
IN OUT UINTN *VariableNameSize,
IN OUT CHAR16 *VariableName,
IN OUT EFI_GUID *VendorGuid
)
/*++
Routine Description:
Arguments:
Returns:
--*/
{
return GetNextVariableName (
VariableNameSize,
VariableName,
VendorGuid,
&mVariableModuleGlobal->VariableGlobal[Physical],
mVariableModuleGlobal->FvbInstance
);
}
EFI_STATUS
EFIAPI
RuntimeServiceSetVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
)
/*++
Routine Description:
Arguments:
Returns:
--*/
{
return SetVariable (
VariableName,
VendorGuid,
Attributes,
DataSize,
Data,
&mVariableModuleGlobal->VariableGlobal[Physical],
&mVariableModuleGlobal->VolatileLastVariableOffset,
&mVariableModuleGlobal->NonVolatileLastVariableOffset,
mVariableModuleGlobal->FvbInstance
);
}
EFI_STATUS
EFIAPI
RuntimeServiceQueryVariableInfo (
IN UINT32 Attributes,
OUT UINT64 *MaximumVariableStorageSize,
OUT UINT64 *RemainingVariableStorageSize,
OUT UINT64 *MaximumVariableSize
)
/*++
Routine Description:
Arguments:
Returns:
--*/
{
return QueryVariableInfo (
Attributes,
MaximumVariableStorageSize,
RemainingVariableStorageSize,
MaximumVariableSize,
&mVariableModuleGlobal->VariableGlobal[Physical],
mVariableModuleGlobal->FvbInstance
);
}
VOID
EFIAPI
VariableClassAddressChangeEvent (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
Arguments:
Returns:
--*/
{
EfiConvertPointer (
0x0,
(VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase
);
EfiConvertPointer (
0x0,
(VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].VolatileVariableBase
);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);
}
EFI_STATUS
EFIAPI
VariableServiceInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
Arguments:
Returns:
--*/
{
EFI_HANDLE NewHandle;
EFI_STATUS Status;
Status = VariableCommonInitialize (ImageHandle, SystemTable);
ASSERT_EFI_ERROR (Status);
SystemTable->RuntimeServices->GetVariable = RuntimeServiceGetVariable;
SystemTable->RuntimeServices->GetNextVariableName = RuntimeServiceGetNextVariableName;
SystemTable->RuntimeServices->SetVariable = RuntimeServiceSetVariable;
SystemTable->RuntimeServices->QueryVariableInfo = RuntimeServiceQueryVariableInfo;
//
// Now install the Variable Runtime Architectural Protocol on a new handle
//
NewHandle = NULL;
Status = gBS->InstallMultipleProtocolInterfaces (
&NewHandle,
&gEfiVariableArchProtocolGuid,
NULL,
&gEfiVariableWriteArchProtocolGuid,
NULL,
NULL
);
ASSERT_EFI_ERROR (Status);
Status = gBS->CreateEvent (
EVT_SIGNAL_EXIT_BOOT_SERVICES,
TPL_NOTIFY,
VariableClassAddressChangeEvent,
NULL,
&mExitBootServicesEvent
);
ASSERT_EFI_ERROR (Status);
return EFI_SUCCESS;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,175 @@
/*++
Copyright (c) 2006 - 2007, Intel Corporation
All rights reserved. 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.
Module Name:
Variable.h
Abstract:
--*/
#ifndef _VARIABLE_H
#define _VARIABLE_H
#include <PiDxe.h>
#include <Protocol/VariableWrite.h>
#include <Protocol/FaultTolerantWriteLite.h>
#include <Protocol/FirmwareVolumeBlock.h>
#include <Protocol/Variable.h>
#include <Library/PcdLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/UefiRuntimeLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/FvbServiceLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/BaseLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/HobLib.h>
#include <Common/FlashMap.h>
#include <Guid/FlashMapHob.h>
//
// BugBug: We need relcate the head file.
//
#include <Common/Variable.h>
#define VARIABLE_RECLAIM_THRESHOLD (1024)
#define VARIABLE_STORE_SIZE (64 * 1024)
#define SCRATCH_SIZE (4 * 1024)
//
// Define GET_PAD_SIZE to optimize compiler
//
#if ((ALIGNMENT == 0) || (ALIGNMENT == 1))
#define GET_PAD_SIZE(a) (0)
#else
#define GET_PAD_SIZE(a) (((~a) + 1) & (ALIGNMENT - 1))
#endif
#define GET_VARIABLE_NAME_PTR(a) (CHAR16 *) ((UINTN) (a) + sizeof (VARIABLE_HEADER))
typedef enum {
Physical,
Virtual
} VARIABLE_POINTER_TYPE;
typedef struct {
VARIABLE_HEADER *CurrPtr;
VARIABLE_HEADER *EndPtr;
VARIABLE_HEADER *StartPtr;
BOOLEAN Volatile;
} VARIABLE_POINTER_TRACK;
typedef struct {
EFI_PHYSICAL_ADDRESS VolatileVariableBase;
EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;
EFI_LOCK VariableServicesLock;
} VARIABLE_GLOBAL;
typedef struct {
VARIABLE_GLOBAL VariableGlobal[2];
UINTN VolatileLastVariableOffset;
UINTN NonVolatileLastVariableOffset;
UINT32 FvbInstance;
} ESAL_VARIABLE_GLOBAL;
extern ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;
//
// Functions
//
EFI_STATUS
EFIAPI
VariableCommonInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
EFI_STATUS
EFIAPI
VariableServiceInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
VOID
EFIAPI
VariableClassAddressChangeEvent (
IN EFI_EVENT Event,
IN VOID *Context
);
EFI_STATUS
EFIAPI
GetVariable (
IN CHAR16 *VariableName,
IN EFI_GUID * VendorGuid,
OUT UINT32 *Attributes OPTIONAL,
IN OUT UINTN *DataSize,
OUT VOID *Data,
IN VARIABLE_GLOBAL * Global,
IN UINT32 Instance
);
EFI_STATUS
EFIAPI
GetNextVariableName (
IN OUT UINTN *VariableNameSize,
IN OUT CHAR16 *VariableName,
IN OUT EFI_GUID *VendorGuid,
IN VARIABLE_GLOBAL *Global,
IN UINT32 Instance
);
EFI_STATUS
EFIAPI
SetVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data,
IN VARIABLE_GLOBAL *Global,
IN UINTN *VolatileOffset,
IN UINTN *NonVolatileOffset,
IN UINT32 Instance
);
EFI_STATUS
EFIAPI
QueryVariableInfo (
IN UINT32 Attributes,
OUT UINT64 *MaximumVariableStorageSize,
OUT UINT64 *RemainingVariableStorageSize,
OUT UINT64 *MaximumVariableSize,
IN VARIABLE_GLOBAL *Global,
IN UINT32 Instance
);
EFI_STATUS
GetFvbHandleByAddress (
IN EFI_PHYSICAL_ADDRESS VariableStoreBase,
OUT EFI_HANDLE *FvbHandle
);
EFI_STATUS
FtwVariableSpace (
IN EFI_PHYSICAL_ADDRESS VariableBaseAddress,
IN UINT8 *Buffer,
IN UINTN BufferSize
);
#endif

View File

@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MsaHeader>
<ModuleName>Variable</ModuleName>
<ModuleType>DXE_RUNTIME_DRIVER</ModuleType>
<GuidValue>CBD2E4D5-7068-4FF5-B462-9822B4AD8D60</GuidValue>
<Version>1.0</Version>
<Abstract>Component description file for Variable module.</Abstract>
<Description>This module installs three EFI_RUNTIME_SERVICES: SetVariable, GetVariable, GetNextVariableName.</Description>
<Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>
<License>All rights reserved. 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.</License>
<Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>
</MsaHeader>
<ModuleDefinitions>
<SupportedArchitectures>IA32 X64</SupportedArchitectures>
<BinaryModule>false</BinaryModule>
<OutputFileBasename>Variable</OutputFileBasename>
</ModuleDefinitions>
<LibraryClassDefinitions>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>PcdLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiDriverEntryPoint</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>DxeServicesTableLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiRuntimeLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>DebugLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>BaseMemoryLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>EdkFvbServiceLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiBootServicesTableLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>BaseLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>MemoryAllocationLib</Keyword>
</LibraryClass>
</LibraryClassDefinitions>
<SourceFiles>
<Filename>Variable.h</Filename>
<Filename>Variable.c</Filename>
<Filename>reclaim.h</Filename>
<Filename>reclaim.c</Filename>
<Filename>InitVariable.c</Filename>
<Filename>Variable.dxs</Filename>
</SourceFiles>
<PackageDependencies>
<Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
<Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>
</PackageDependencies>
<Protocols>
<Protocol Usage="ALWAYS_PRODUCED">
<ProtocolCName>gEfiVariableArchProtocolGuid</ProtocolCName>
</Protocol>
<Protocol Usage="ALWAYS_PRODUCED">
<ProtocolCName>gEfiVariableWriteArchProtocolGuid</ProtocolCName>
</Protocol>
<Protocol Usage="SOMETIMES_CONSUMED">
<ProtocolCName>gEfiFaultTolerantWriteLiteProtocolGuid</ProtocolCName>
</Protocol>
<Protocol Usage="SOMETIMES_CONSUMED">
<ProtocolCName>gEfiFirmwareVolumeBlockProtocolGuid</ProtocolCName>
</Protocol>
</Protocols>
<Externs>
<Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
<Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
<Extern>
<ModuleEntryPoint>VariableServiceInitialize</ModuleEntryPoint>
</Extern>
<Extern>
<SetVirtualAddressMapCallBack>VariableClassAddressChangeEvent</SetVirtualAddressMapCallBack>
</Extern>
</Externs>
<PcdCoded>
<PcdEntry PcdItemType="DYNAMIC">
<C_Name>PcdFlashNvStorageVariableBase</C_Name>
<TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>
<HelpText>The driver gets the Variable store base address from this PCD. This base address point to
an EFI_FIRMWARE_VOLUMN_HEADER struct.</HelpText>
</PcdEntry>
<PcdEntry PcdItemType="DYNAMIC">
<C_Name>PcdFlashNvStorageVariableSize</C_Name>
<TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>
<HelpText>The driver gets the NvStorage Variable Size from this PCD.</HelpText>
</PcdEntry>
</PcdCoded>
</ModuleSurfaceArea>

View File

@@ -0,0 +1,74 @@
#/** @file
# Component description file for Variable module.
#
# This module installs three EFI_RUNTIME_SERVICES: SetVariable, GetVariable, GetNextVariableName.
# Copyright (c) 2006 - 2007, Intel Corporation
#
# All rights reserved. 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.
#
#
#**/
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = VariableRuntimeDxe
FILE_GUID = CBD2E4D5-7068-4FF5-B462-9822B4AD8D60
MODULE_TYPE = DXE_RUNTIME_DRIVER
VERSION_STRING = 1.0
EDK_RELEASE_VERSION = 0x00020000
EFI_SPECIFICATION_VERSION = 0x00020000
ENTRY_POINT = VariableServiceInitialize
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64
#
# VIRTUAL_ADDRESS_MAP_CALLBACK = VariableClassAddressChangeEvent
#
[Sources.common]
InitVariable.c
reclaim.c
Variable.c
Variable.h
[Packages]
MdePkg/MdePkg.dec
[LibraryClasses]
MemoryAllocationLib
BaseLib
UefiLib
UefiBootServicesTableLib
FvbServiceLib
BaseMemoryLib
DebugLib
UefiRuntimeLib
DxeServicesTableLib
UefiDriverEntryPoint
PcdLib
HobLib
[Guids]
gEfiFlashMapHobGuid
[Protocols]
gEfiFirmwareVolumeBlockProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
gEfiFaultTolerantWriteLiteProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
gEfiVariableWriteArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED
gEfiVariableArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED
[PcdsDynamic.common]
PcdFlashNvStorageVariableSize|gEfiMdeModulePkgTokenSpaceGuid
PcdFlashNvStorageVariableBase|gEfiMdeModulePkgTokenSpaceGuid
[Depex]
gEfiFirmwareVolumeBlockProtocolGuid AND gEfiAlternateFvBlockGuid AND gEfiFaultTolerantWriteLiteProtocolGuid

View File

@@ -0,0 +1,242 @@
/*++
Copyright (c) 2006 - 2007, Intel Corporation
All rights reserved. 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.
Module Name:
reclaim.c
Abstract:
Handles non-volatile variable store garbage collection, using FTW
(Fault Tolerant Write) protocol.
Revision History
--*/
#include <Variable.h>
#include "Common/Variable.h"
EFI_STATUS
GetFvbHandleByAddress (
IN EFI_PHYSICAL_ADDRESS Address,
OUT EFI_HANDLE *FvbHandle
)
{
EFI_STATUS Status;
EFI_HANDLE *HandleBuffer;
UINTN HandleCount;
UINTN Index;
EFI_PHYSICAL_ADDRESS FvbBaseAddress;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
*FvbHandle = NULL;
//
// Locate all handles of Fvb protocol
//
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiFirmwareVolumeBlockProtocolGuid,
NULL,
&HandleCount,
&HandleBuffer
);
if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND;
}
//
// Get the FVB to access variable store
//
for (Index = 0; Index < HandleCount; Index += 1) {
Status = gBS->HandleProtocol (
HandleBuffer[Index],
&gEfiFirmwareVolumeBlockProtocolGuid,
(VOID **) &Fvb
);
if (EFI_ERROR (Status)) {
Status = EFI_NOT_FOUND;
break;
}
//
// Compare the address and select the right one
//
Status = Fvb->GetPhysicalAddress (Fvb, &FvbBaseAddress);
if (EFI_ERROR (Status)) {
continue;
}
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvbBaseAddress);
if ((Address >= FvbBaseAddress) && (Address <= (FvbBaseAddress + FwVolHeader->FvLength))) {
*FvbHandle = HandleBuffer[Index];
Status = EFI_SUCCESS;
break;
}
}
FreePool (HandleBuffer);
return Status;
}
STATIC
EFI_STATUS
GetLbaAndOffsetByAddress (
IN EFI_PHYSICAL_ADDRESS Address,
OUT EFI_LBA *Lba,
OUT UINTN *Offset
)
{
EFI_STATUS Status;
EFI_HANDLE FvbHandle;
EFI_PHYSICAL_ADDRESS FvbBaseAddress;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
EFI_FV_BLOCK_MAP_ENTRY *FvbMapEntry;
UINT32 LbaIndex;
*Lba = (EFI_LBA) (-1);
*Offset = 0;
//
// Get the proper FVB
//
Status = GetFvbHandleByAddress (Address, &FvbHandle);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->HandleProtocol (
FvbHandle,
&gEfiFirmwareVolumeBlockProtocolGuid,
(VOID **) &Fvb
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Get the Base Address of FV
//
Status = Fvb->GetPhysicalAddress (Fvb, &FvbBaseAddress);
if (EFI_ERROR (Status)) {
return Status;
}
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvbBaseAddress);
//
// Get the (LBA, Offset) of Address
//
if ((Address >= FvbBaseAddress) && (Address <= (FvbBaseAddress + FwVolHeader->FvLength))) {
if ((FwVolHeader->FvLength) > (FwVolHeader->HeaderLength)) {
//
// BUGBUG: Assume one FV has one type of BlockLength
//
FvbMapEntry = &FwVolHeader->BlockMap[0];
for (LbaIndex = 1; LbaIndex <= FvbMapEntry->NumBlocks; LbaIndex += 1) {
if (Address < (FvbBaseAddress + FvbMapEntry->Length * LbaIndex)) {
//
// Found the (Lba, Offset)
//
*Lba = LbaIndex - 1;
*Offset = (UINTN) (Address - (FvbBaseAddress + FvbMapEntry->Length * (LbaIndex - 1)));
return EFI_SUCCESS;
}
}
}
}
return EFI_ABORTED;
}
EFI_STATUS
FtwVariableSpace (
IN EFI_PHYSICAL_ADDRESS VariableBase,
IN UINT8 *Buffer,
IN UINTN BufferSize
)
/*++
Routine Description:
Write a buffer to Variable space, in the working block.
Arguments:
FvbHandle - Indicates a handle to FVB to access variable store
Buffer - Point to the input buffer
BufferSize - The number of bytes of the input Buffer
Returns:
EFI_SUCCESS - The function completed successfully
EFI_ABORTED - The function could not complete successfully
EFI_NOT_FOUND - Locate FVB protocol by handle fails
--*/
{
EFI_STATUS Status;
EFI_HANDLE FvbHandle;
EFI_FTW_LITE_PROTOCOL *FtwLiteProtocol;
EFI_LBA VarLba;
UINTN VarOffset;
UINT8 *FtwBuffer;
UINTN FtwBufferSize;
//
// Locate fault tolerant write protocol
//
Status = gBS->LocateProtocol (
&gEfiFaultTolerantWriteLiteProtocolGuid,
NULL,
(VOID **) &FtwLiteProtocol
);
if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND;
}
//
// Locate Fvb handle by address
//
Status = GetFvbHandleByAddress (VariableBase, &FvbHandle);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Get LBA and Offset by address
//
Status = GetLbaAndOffsetByAddress (VariableBase, &VarLba, &VarOffset);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
//
// Prepare for the variable data
//
FtwBufferSize = ((VARIABLE_STORE_HEADER *) ((UINTN) VariableBase))->Size;
FtwBuffer = AllocateRuntimePool (FtwBufferSize);
if (FtwBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
SetMem (FtwBuffer, FtwBufferSize, (UINT8) 0xff);
CopyMem (FtwBuffer, Buffer, BufferSize);
//
// FTW write record
//
Status = FtwLiteProtocol->Write (
FtwLiteProtocol,
FvbHandle,
VarLba, // LBA
VarOffset, // Offset
&FtwBufferSize, // NumBytes,
FtwBuffer
);
FreePool (FtwBuffer);
return Status;
}