Support Variable driver (EmuRuntimeDxe) to support the default variable data stored in HOB.

Signed-off-by: niruiyu
Reviewed-by: lgao4

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12553 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
niruiyu 2011-10-19 09:30:43 +00:00
parent 8598a1ed33
commit f68af18ee9
4 changed files with 59 additions and 9 deletions

View File

@ -186,7 +186,7 @@ GetNextPotentialVariablePtr (
//
// Be careful about pad size for alignment
//
VarHeader = (VARIABLE_HEADER *) (GetVariableDataPtr (Variable) + Variable->DataSize + GET_PAD_SIZE (Variable->DataSize));
VarHeader = (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) GetVariableDataPtr (Variable) + Variable->DataSize + GET_PAD_SIZE (Variable->DataSize));
return VarHeader;
}
@ -999,12 +999,12 @@ UpdateVariable (
NextVariable = (VARIABLE_HEADER *) (UINT8 *) (mVariableModuleGlobal->NonVolatileLastVariableOffset
+ (UINTN) Global->NonVolatileVariableBase);
mVariableModuleGlobal->NonVolatileLastVariableOffset += VarSize;
mVariableModuleGlobal->NonVolatileLastVariableOffset += HEADER_ALIGN (VarSize);
if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != 0) {
mVariableModuleGlobal->HwErrVariableTotalSize += VarSize;
mVariableModuleGlobal->HwErrVariableTotalSize += HEADER_ALIGN (VarSize);
} else {
mVariableModuleGlobal->CommonVariableTotalSize += VarSize;
mVariableModuleGlobal->CommonVariableTotalSize += HEADER_ALIGN (VarSize);
}
} else {
if ((UINT32) (VarSize + mVariableModuleGlobal->VolatileLastVariableOffset) >
@ -1016,7 +1016,7 @@ UpdateVariable (
NextVariable = (VARIABLE_HEADER *) (UINT8 *) (mVariableModuleGlobal->VolatileLastVariableOffset
+ (UINTN) Global->VolatileVariableBase);
mVariableModuleGlobal->VolatileLastVariableOffset += VarSize;
mVariableModuleGlobal->VolatileLastVariableOffset += HEADER_ALIGN (VarSize);
}
NextVariable->StartId = VARIABLE_DATA;
@ -1609,10 +1609,15 @@ InitializeVariableStore (
IN BOOLEAN VolatileStore
)
{
EFI_STATUS Status;
VARIABLE_STORE_HEADER *VariableStore;
BOOLEAN FullyInitializeStore;
EFI_PHYSICAL_ADDRESS *VariableBase;
UINTN *LastVariableOffset;
VARIABLE_STORE_HEADER *VariableStoreHeader;
VARIABLE_HEADER *Variable;
VOID *VariableData;
EFI_HOB_GUID_TYPE *GuidHob;
FullyInitializeStore = TRUE;
@ -1681,6 +1686,44 @@ InitializeVariableStore (
VariableStore->Reserved = 0;
VariableStore->Reserved1 = 0;
if (!VolatileStore) {
//
// Get HOB variable store.
//
GuidHob = GetFirstGuidHob (&gEfiVariableGuid);
if (GuidHob != NULL) {
VariableStoreHeader = (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (GuidHob);
if (CompareGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid) &&
(VariableStoreHeader->Format == VARIABLE_STORE_FORMATTED) &&
(VariableStoreHeader->State == VARIABLE_STORE_HEALTHY)
) {
DEBUG ((EFI_D_INFO, "HOB Variable Store appears to be valid.\n"));
//
// Flush the HOB variable to Emulation Variable storage.
//
for ( Variable = (VARIABLE_HEADER *) (VariableStoreHeader + 1)
; (Variable < GetEndPointer (VariableStoreHeader) && (Variable != NULL))
; Variable = GetNextVariablePtr (Variable)
) {
ASSERT (Variable->State == VAR_ADDED);
ASSERT ((Variable->Attributes & EFI_VARIABLE_NON_VOLATILE) != 0);
VariableData = GetVariableDataPtr (Variable);
Status = EmuSetVariable (
GET_VARIABLE_NAME_PTR (Variable),
&Variable->VendorGuid,
Variable->Attributes,
Variable->DataSize,
VariableData,
&mVariableModuleGlobal->VariableGlobal[Physical],
&mVariableModuleGlobal->VolatileLastVariableOffset,
&mVariableModuleGlobal->NonVolatileLastVariableOffset
);
ASSERT_EFI_ERROR (Status);
}
}
}
}
return EFI_SUCCESS;
}

View File

@ -2,7 +2,7 @@
# Emulation Variable for EFI_RUNTIME_SERVICES.
#
# This module provides three EFI_RUNTIME_SERVICES: SetVariable, GetVariable, GetNextVariableName
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@ -48,6 +48,7 @@
DebugLib
MemoryAllocationLib
BaseMemoryLib
HobLib
[Protocols]

View File

@ -3,7 +3,7 @@
The internal header file includes the common header files, defines
internal structure and functions used by EmuVariable module.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
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
@ -31,6 +31,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/UefiLib.h>
#include <Library/BaseLib.h>
#include <Library/PcdLib.h>
#include <Library/HobLib.h>
#include <Guid/VariableFormat.h>
#include <Guid/GlobalVariable.h>

View File

@ -2421,7 +2421,12 @@ VariableCommonInitialize (
//
GuidHob = GetFirstGuidHob (&gEfiVariableGuid);
if (GuidHob != NULL) {
mVariableModuleGlobal->VariableGlobal.HobVariableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) GET_GUID_HOB_DATA (GuidHob);
VariableStoreHeader = GET_GUID_HOB_DATA (GuidHob);
if (GetVariableStoreStatus (VariableStoreHeader) == EfiValid) {
mVariableModuleGlobal->VariableGlobal.HobVariableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) VariableStoreHeader;
} else {
DEBUG ((EFI_D_ERROR, "HOB Variable Store header is corrupted!\n"));
}
}
//