summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Universal/Variable
diff options
context:
space:
mode:
authorlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>2012-08-06 03:20:10 +0000
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>2012-08-06 03:20:10 +0000
commit8f3a9e58626b72e837dc5f389016a39ecadffcc5 (patch)
tree85ef1cf84650c8f2a9b5897920d3278cfb0533f2 /MdeModulePkg/Universal/Variable
parent40ef06fc2a95bd55ea04f63cff53952bec6e1971 (diff)
downloadedk2-platforms-8f3a9e58626b72e837dc5f389016a39ecadffcc5.tar.xz
LastVariableOffset is wrongly set to 0 when FtwVariableSpace() fails. Recalculate the HwErrVariableTotalSize, HwErrVariableTotalSize and LastVariableOffset when FtwVariableSpace() fails.
Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Guo Dong <guo.dong@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13593 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Universal/Variable')
-rw-r--r--MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
index 54126782a0..3aa45c2dd2 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
@@ -537,15 +537,13 @@ Reclaim (
EFI_STATUS Status;
CHAR16 *VariableNamePtr;
CHAR16 *UpdatingVariableNamePtr;
+ UINTN CommonVariableTotalSize;
+ UINTN HwErrVariableTotalSize;
VariableStoreHeader = (VARIABLE_STORE_HEADER *) ((UINTN) VariableBase);
- //
- // Recalculate the total size of Common/HwErr type variables in non-volatile area.
- //
- if (!IsVolatile) {
- mVariableModuleGlobal->CommonVariableTotalSize = 0;
- mVariableModuleGlobal->HwErrVariableTotalSize = 0;
- }
+
+ CommonVariableTotalSize = 0;
+ HwErrVariableTotalSize = 0;
//
// Start Pointers for the variable.
@@ -612,9 +610,9 @@ Reclaim (
CopyMem (CurrPtr, (UINT8 *) Variable, VariableSize);
CurrPtr += VariableSize;
if ((!IsVolatile) && ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
- mVariableModuleGlobal->HwErrVariableTotalSize += VariableSize;
+ HwErrVariableTotalSize += VariableSize;
} else if ((!IsVolatile) && ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
- mVariableModuleGlobal->CommonVariableTotalSize += VariableSize;
+ CommonVariableTotalSize += VariableSize;
}
}
Variable = NextVariable;
@@ -628,9 +626,9 @@ Reclaim (
CopyMem (CurrPtr, (UINT8 *) UpdatingVariable, VariableSize);
CurrPtr += VariableSize;
if ((!IsVolatile) && ((UpdatingVariable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
- mVariableModuleGlobal->HwErrVariableTotalSize += VariableSize;
+ HwErrVariableTotalSize += VariableSize;
} else if ((!IsVolatile) && ((UpdatingVariable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
- mVariableModuleGlobal->CommonVariableTotalSize += VariableSize;
+ CommonVariableTotalSize += VariableSize;
}
}
@@ -674,9 +672,9 @@ Reclaim (
((VARIABLE_HEADER *) CurrPtr)->State = VAR_ADDED;
CurrPtr += VariableSize;
if ((!IsVolatile) && ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
- mVariableModuleGlobal->HwErrVariableTotalSize += VariableSize;
+ HwErrVariableTotalSize += VariableSize;
} else if ((!IsVolatile) && ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
- mVariableModuleGlobal->CommonVariableTotalSize += VariableSize;
+ CommonVariableTotalSize += VariableSize;
}
}
}
@@ -704,8 +702,23 @@ Reclaim (
}
if (!EFI_ERROR (Status)) {
*LastVariableOffset = (UINTN) (CurrPtr - (UINT8 *) ValidBuffer);
+ if (!IsVolatile) {
+ mVariableModuleGlobal->HwErrVariableTotalSize = HwErrVariableTotalSize;
+ mVariableModuleGlobal->CommonVariableTotalSize = CommonVariableTotalSize;
+ }
} else {
- *LastVariableOffset = 0;
+ NextVariable = GetStartPointer ((VARIABLE_STORE_HEADER *)(UINTN)VariableBase);
+ while (IsValidVariableHeader (NextVariable)) {
+ VariableSize = NextVariable->NameSize + NextVariable->DataSize + sizeof (VARIABLE_HEADER);
+ if ((!IsVolatile) && ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
+ mVariableModuleGlobal->HwErrVariableTotalSize += HEADER_ALIGN (VariableSize);
+ } else if ((!IsVolatile) && ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
+ mVariableModuleGlobal->CommonVariableTotalSize += HEADER_ALIGN (VariableSize);
+ }
+
+ NextVariable = GetNextVariablePtr (NextVariable);
+ }
+ *LastVariableOffset = (UINTN) NextVariable - (UINTN) VariableBase;
}
FreePool (ValidBuffer);