X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=OvmfPkg%2FEmuVariableFvbRuntimeDxe%2FFvb.c;h=9480d879c9353cb518daabeb174242b68108b8ce;hp=48d0555abc968e0ae4e1c809432db76f079dfcdc;hb=c5d917158d963ba4809be2d34e8ac2317007a002;hpb=670d495b19abebaed3ffde1e9293eb270a68ca3c
diff --git a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c
index 48d0555abc..9480d879c9 100644
--- a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c
+++ b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c
@@ -2,8 +2,8 @@
Firmware Block Services to support emulating non-volatile variables
by pretending that a memory buffer is storage for the NV variables.
- Copyright (c) 2006 - 2009, Intel Corporation
- All rights reserved. This program and the accompanying materials
+ Copyright (c) 2006 - 2013, 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
@@ -34,6 +34,9 @@
#include
#include "Fvb.h"
+#define EFI_AUTHENTICATED_VARIABLE_GUID \
+{ 0xaaf32c78, 0x947b, 0x439a, { 0xa1, 0x80, 0x2e, 0x14, 0x4e, 0xc3, 0x77, 0x92 } }
+
//
// Virtual Address Change Event
//
@@ -71,8 +74,8 @@ EFI_FW_VOL_BLOCK_DEVICE mEmuVarsFvb = {
}
},
NULL, // BufferPtr
- FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize), // BlockSize
- 2 * FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize), // Size
+ EMU_FVB_BLOCK_SIZE, // BlockSize
+ EMU_FVB_SIZE, // Size
{ // FwVolBlockInstance
FvbProtocolGetAttributes,
FvbProtocolSetAttributes,
@@ -116,22 +119,22 @@ FvbVirtualAddressChangeEvent (
a memory-mapped firmware volume. This function should be called
only for memory-mapped firmware volumes.
- @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL instance.
-
+ @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
+
@param Address Pointer to a caller-allocated
EFI_PHYSICAL_ADDRESS that, on successful
return from GetPhysicalAddress(), contains the
base address of the firmware volume.
-
+
@retval EFI_SUCCESS The firmware volume base address is returned.
-
+
@retval EFI_NOT_SUPPORTED The firmware volume is not memory mapped.
**/
EFI_STATUS
EFIAPI
FvbProtocolGetPhysicalAddress (
- IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
OUT EFI_PHYSICAL_ADDRESS *Address
)
{
@@ -152,7 +155,7 @@ FvbProtocolGetPhysicalAddress (
retrieve the block map (see EFI_FIRMWARE_VOLUME_HEADER).
- @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL instance.
+ @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
@param Lba Indicates the block for which to return the size.
@@ -165,16 +168,16 @@ FvbProtocolGetPhysicalAddress (
blocks in this range have a size of
BlockSize.
-
+
@retval EFI_SUCCESS The firmware volume base address is returned.
-
+
@retval EFI_INVALID_PARAMETER The requested LBA is out of range.
**/
EFI_STATUS
EFIAPI
FvbProtocolGetBlockSize (
- IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN EFI_LBA Lba,
OUT UINTN *BlockSize,
OUT UINTN *NumberOfBlocks
@@ -182,14 +185,14 @@ FvbProtocolGetBlockSize (
{
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
- if (Lba > 1) {
+ if (Lba >= EMU_FVB_NUM_TOTAL_BLOCKS) {
return EFI_INVALID_PARAMETER;
}
FvbDevice = FVB_DEVICE_FROM_THIS (This);
*BlockSize = FvbDevice->BlockSize;
- *NumberOfBlocks = 2 - Lba;
+ *NumberOfBlocks = (UINTN)(EMU_FVB_NUM_TOTAL_BLOCKS - Lba);
return EFI_SUCCESS;
}
@@ -199,7 +202,7 @@ FvbProtocolGetBlockSize (
The GetAttributes() function retrieves the attributes and
current settings of the block. Status Codes Returned
- @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL instance.
+ @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
@param Attributes Pointer to EFI_FVB_ATTRIBUTES_2 in which the
attributes and current settings are
@@ -213,7 +216,7 @@ FvbProtocolGetBlockSize (
EFI_STATUS
EFIAPI
FvbProtocolGetAttributes (
- IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
OUT EFI_FVB_ATTRIBUTES_2 *Attributes
)
{
@@ -234,7 +237,7 @@ FvbProtocolGetAttributes (
The SetAttributes() function sets configurable firmware volume
attributes and returns the new settings of the firmware volume.
- @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL instance.
+ @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
@param Attributes On input, Attributes is a pointer to
EFI_FVB_ATTRIBUTES_2 that contains the
@@ -243,7 +246,7 @@ FvbProtocolGetAttributes (
settings of the firmware volume. Type
EFI_FVB_ATTRIBUTES_2 is defined in
EFI_FIRMWARE_VOLUME_HEADER.
-
+
@retval EFI_SUCCESS The firmware volume attributes were returned.
@retval EFI_INVALID_PARAMETER The attributes requested are in
@@ -255,7 +258,7 @@ FvbProtocolGetAttributes (
EFI_STATUS
EFIAPI
FvbProtocolSetAttributes (
- IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
)
{
@@ -281,7 +284,7 @@ FvbProtocolSetAttributes (
flushed to the hardware before the EraseBlocks() service
returns.
- @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
+ @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL
instance.
@param ... The variable argument list is a list of tuples.
@@ -299,7 +302,7 @@ FvbProtocolSetAttributes (
@retval EFI_SUCCESS The erase request was successfully
completed.
-
+
@retval EFI_ACCESS_DENIED The firmware volume is in the
WriteDisabled state.
@retval EFI_DEVICE_ERROR The block device is not functioning
@@ -308,76 +311,69 @@ FvbProtocolSetAttributes (
partially erased.
@retval EFI_INVALID_PARAMETER One or more of the LBAs listed
in the variable argument list do
- not exist in the firmware volume.
+ not exist in the firmware volume.
**/
EFI_STATUS
EFIAPI
FvbProtocolEraseBlocks (
- IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
...
)
{
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
- VA_LIST args;
+ VA_LIST Args;
EFI_LBA StartingLba;
UINTN NumOfLba;
- UINT8 Erase;
- VOID *ErasePtr;
+ UINT8 *ErasePtr;
UINTN EraseSize;
FvbDevice = FVB_DEVICE_FROM_THIS (This);
- Erase = 0;
-
- VA_START (args, This);
+ //
+ // Check input parameters
+ //
+ VA_START (Args, This);
do {
- StartingLba = VA_ARG (args, EFI_LBA);
+ StartingLba = VA_ARG (Args, EFI_LBA);
if (StartingLba == EFI_LBA_LIST_TERMINATOR) {
break;
}
+ NumOfLba = VA_ARG (Args, UINTN);
- NumOfLba = VA_ARG (args, UINT32);
-
- //
- // Check input parameters
- //
- if ((NumOfLba == 0) || (StartingLba > 1) || ((StartingLba + NumOfLba) > 2)) {
- VA_END (args);
+ if (StartingLba > EMU_FVB_NUM_TOTAL_BLOCKS ||
+ NumOfLba > EMU_FVB_NUM_TOTAL_BLOCKS - StartingLba) {
+ VA_END (Args);
return EFI_INVALID_PARAMETER;
}
-
- if (StartingLba == 0) {
- Erase = (UINT8) (Erase | BIT0);
- }
- if ((StartingLba + NumOfLba) == 2) {
- Erase = (UINT8) (Erase | BIT1);
- }
-
} while (1);
+ VA_END (Args);
- VA_END (args);
-
- ErasePtr = (UINT8*) FvbDevice->BufferPtr;
- EraseSize = 0;
+ //
+ // Erase blocks
+ //
+ VA_START (Args, This);
+ do {
+ StartingLba = VA_ARG (Args, EFI_LBA);
+ if (StartingLba == EFI_LBA_LIST_TERMINATOR) {
+ break;
+ }
+ NumOfLba = VA_ARG (Args, UINTN);
- if ((Erase & BIT0) != 0) {
- EraseSize = EraseSize + FvbDevice->BlockSize;
- } else {
- ErasePtr = ErasePtr + FvbDevice->BlockSize;
- }
+ ErasePtr = FvbDevice->BufferPtr;
+ ErasePtr += (UINTN)StartingLba * FvbDevice->BlockSize;
+ EraseSize = NumOfLba * FvbDevice->BlockSize;
- if ((Erase & BIT1) != 0) {
- EraseSize = EraseSize + FvbDevice->BlockSize;
- }
+ SetMem (ErasePtr, EraseSize, ERASED_UINT8);
+ } while (1);
+ VA_END (Args);
- if (EraseSize != 0) {
- SetMem (
- (VOID*) ErasePtr,
- EraseSize,
- ERASED_UINT8
- );
- }
+ //
+ // Call platform hook
+ //
+ VA_START (Args, This);
+ PlatformFvbBlocksErased (This, Args);
+ VA_END (Args);
return EFI_SUCCESS;
}
@@ -413,30 +409,30 @@ FvbProtocolEraseBlocks (
fully flushed to the hardware before the Write() service
returns.
- @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL instance.
-
+ @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
+
@param Lba The starting logical block index to write to.
-
+
@param Offset Offset into the block at which to begin writing.
-
+
@param NumBytes Pointer to a UINTN. At entry, *NumBytes
contains the total size of the buffer. At
exit, *NumBytes contains the total number of
bytes actually written.
-
+
@param Buffer Pointer to a caller-allocated buffer that
contains the source for the write.
-
+
@retval EFI_SUCCESS The firmware volume was written successfully.
-
+
@retval EFI_BAD_BUFFER_SIZE The write was attempted across an
LBA boundary. On output, NumBytes
contains the total number of bytes
actually written.
-
+
@retval EFI_ACCESS_DENIED The firmware volume is in the
WriteDisabled state.
-
+
@retval EFI_DEVICE_ERROR The block device is malfunctioning
and could not be written.
@@ -445,38 +441,37 @@ FvbProtocolEraseBlocks (
EFI_STATUS
EFIAPI
FvbProtocolWrite (
- IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN EFI_LBA Lba,
IN UINTN Offset,
IN OUT UINTN *NumBytes,
IN UINT8 *Buffer
)
{
-
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
UINT8 *FvbDataPtr;
+ EFI_STATUS Status;
FvbDevice = FVB_DEVICE_FROM_THIS (This);
- if ((Lba > 1) || (Offset > FvbDevice->BlockSize)) {
+ if (Lba >= EMU_FVB_NUM_TOTAL_BLOCKS ||
+ Offset > FvbDevice->BlockSize) {
return EFI_INVALID_PARAMETER;
}
- if ((Offset + *NumBytes) > FvbDevice->BlockSize) {
+ Status = EFI_SUCCESS;
+ if (*NumBytes > FvbDevice->BlockSize - Offset) {
*NumBytes = FvbDevice->BlockSize - Offset;
+ Status = EFI_BAD_BUFFER_SIZE;
}
- FvbDataPtr =
- (UINT8*) FvbDevice->BufferPtr +
- MultU64x32 (Lba, FvbDevice->BlockSize) +
- Offset;
-
- if (*NumBytes > 0) {
- CopyMem (FvbDataPtr, Buffer, *NumBytes);
- PlatformFvbDataWritten (This, Lba);
- }
+ FvbDataPtr = FvbDevice->BufferPtr;
+ FvbDataPtr += (UINTN)Lba * FvbDevice->BlockSize;
+ FvbDataPtr += Offset;
- return EFI_SUCCESS;
+ CopyMem (FvbDataPtr, Buffer, *NumBytes);
+ PlatformFvbDataWritten (This, Lba, Offset, *NumBytes, Buffer);
+ return Status;
}
@@ -496,8 +491,8 @@ FvbProtocolWrite (
indicate the number of bytes actually read. The caller must be
aware that a read may be partially completed.
- @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL instance.
-
+ @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
+
@param Lba The starting logical block index
from which to read.
@@ -513,15 +508,15 @@ FvbProtocolWrite (
@retval EFI_SUCCESS The firmware volume was read successfully
and contents are in Buffer.
-
+
@retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA
boundary. On output, NumBytes
contains the total number of bytes
returned in Buffer.
-
+
@retval EFI_ACCESS_DENIED The firmware volume is in the
ReadDisabled state.
-
+
@retval EFI_DEVICE_ERROR The block device is not
functioning correctly and could
not be read.
@@ -530,7 +525,7 @@ FvbProtocolWrite (
EFI_STATUS
EFIAPI
FvbProtocolRead (
- IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN EFI_LBA Lba,
IN UINTN Offset,
IN OUT UINTN *NumBytes,
@@ -539,27 +534,28 @@ FvbProtocolRead (
{
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
UINT8 *FvbDataPtr;
+ EFI_STATUS Status;
FvbDevice = FVB_DEVICE_FROM_THIS (This);
- if ((Lba > 1) || (Offset > FvbDevice->BlockSize)) {
+ if (Lba >= EMU_FVB_NUM_TOTAL_BLOCKS ||
+ Offset > FvbDevice->BlockSize) {
return EFI_INVALID_PARAMETER;
}
- if ((Offset + *NumBytes) > FvbDevice->BlockSize) {
+ Status = EFI_SUCCESS;
+ if (*NumBytes > FvbDevice->BlockSize - Offset) {
*NumBytes = FvbDevice->BlockSize - Offset;
+ Status = EFI_BAD_BUFFER_SIZE;
}
- FvbDataPtr =
- (UINT8*) FvbDevice->BufferPtr +
- MultU64x32 (Lba, FvbDevice->BlockSize) +
- Offset;
+ FvbDataPtr = FvbDevice->BufferPtr;
+ FvbDataPtr += (UINTN)Lba * FvbDevice->BlockSize;
+ FvbDataPtr += Offset;
- if (*NumBytes > 0) {
- CopyMem (Buffer, FvbDataPtr, *NumBytes);
- }
-
- return EFI_SUCCESS;
+ CopyMem (Buffer, FvbDataPtr, *NumBytes);
+ PlatformFvbDataRead (This, Lba, Offset, *NumBytes, Buffer);
+ return Status;
}
@@ -618,7 +614,10 @@ InitializeFvAndVariableStoreHeaders (
IN VOID *Ptr
)
{
- STATIC FVB_FV_HDR_AND_VARS_TEMPLATE FvAndVarTemplate = {
+ //
+ // Templates for authenticated variable FV header
+ //
+ STATIC FVB_FV_HDR_AND_VARS_TEMPLATE FvAndAuthenticatedVarTemplate = {
{ // EFI_FIRMWARE_VOLUME_HEADER FvHdr;
// UINT8 ZeroVector[16];
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
@@ -645,25 +644,28 @@ InitializeFvAndVariableStoreHeaders (
0,
// UINT8 Reserved[1];
- 0,
+ {0},
// UINT8 Revision;
EFI_FVH_REVISION,
// EFI_FV_BLOCK_MAP_ENTRY BlockMap[1];
- { 2, // UINT32 NumBlocks;
- EMU_FVB_BLOCK_SIZE // UINT32 Length;
+ {
+ {
+ EMU_FVB_NUM_TOTAL_BLOCKS, // UINT32 NumBlocks;
+ EMU_FVB_BLOCK_SIZE // UINT32 Length;
+ }
}
},
// EFI_FV_BLOCK_MAP_ENTRY EndBlockMap;
{ 0, 0 }, // End of block map
{ // VARIABLE_STORE_HEADER VarHdr;
- // EFI_GUID Signature;
- EFI_VARIABLE_GUID,
+ // EFI_GUID Signature; // need authenticated variables for secure boot
+ EFI_AUTHENTICATED_VARIABLE_GUID,
// UINT32 Size;
(
- FixedPcdGet32 (PcdVariableStoreSize) -
+ FixedPcdGet32 (PcdFlashNvStorageVariableSize) -
OFFSET_OF (FVB_FV_HDR_AND_VARS_TEMPLATE, VarHdr)
),
@@ -680,12 +682,17 @@ InitializeFvAndVariableStoreHeaders (
0
}
};
+
EFI_FIRMWARE_VOLUME_HEADER *Fv;
//
// Copy the template structure into the location
//
- CopyMem (Ptr, (VOID*)&FvAndVarTemplate, sizeof (FvAndVarTemplate));
+ CopyMem (
+ Ptr,
+ &FvAndAuthenticatedVarTemplate,
+ sizeof FvAndAuthenticatedVarTemplate
+ );
//
// Update the checksum for the FV header
@@ -694,58 +701,12 @@ InitializeFvAndVariableStoreHeaders (
Fv->Checksum = CalculateCheckSum16 (Ptr, Fv->HeaderLength);
}
-
-/**
- Initializes the Fault Tolerant Write data structure
-
- This data structure is used by the Fault Tolerant Write driver.
-
- @param[in] Buffer - Location for the FTW data structure
-
-**/
-VOID
-InitializeFtwState (
- IN VOID *Buffer
- )
-{
- EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *Hdr;
- UINT32 TempCrc;
- STATIC EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER DefaultFtw = {
- EFI_SYSTEM_NV_DATA_FV_GUID, // EFI_GUID Signature;
- ERASED_UINT32, // UINT32 Crc;
- ERASED_BIT, // UINT8 WorkingBlockValid : 1;
- ERASED_BIT, // UINT8 WorkingBlockInvalid : 1;
- 0, // UINT8 Reserved : 6;
- { 0, 0, 0 }, // UINT8 Reserved3[3];
- FTW_WRITE_QUEUE_SIZE // UINT64 WriteQueueSize;
- };
-
- CopyMem (Buffer, (VOID*) &DefaultFtw, sizeof (DefaultFtw));
-
- Hdr = (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER*) Buffer;
-
- //
- // Calculate checksum.
- //
- // The Crc, WorkingBlockValid and WorkingBlockInvalid bits should
- // be set to the erased state before computing the checksum.
- //
- gBS->CalculateCrc32 (Buffer, sizeof (DefaultFtw), &TempCrc);
- Hdr->Crc = TempCrc;
-
- //
- // Mark as valid.
- //
- Hdr->WorkingBlockValid = NOT_ERASED_BIT;
-}
-
-
/**
Main entry point.
- @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
-
+
@retval EFI_SUCCESS Successfully initialized.
**/
@@ -762,22 +723,31 @@ FvbInitialize (
BOOLEAN Initialize;
EFI_HANDLE Handle;
EFI_PHYSICAL_ADDRESS Address;
+ RETURN_STATUS PcdStatus;
DEBUG ((EFI_D_INFO, "EMU Variable FVB Started\n"));
//
// Verify that the PCD's are set correctly.
//
+ ASSERT (FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) %
+ EMU_FVB_BLOCK_SIZE == 0);
if (
- (FixedPcdGet32 (PcdVariableStoreSize) +
- FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize)
+ (PcdGet32 (PcdFlashNvStorageVariableSize) +
+ PcdGet32 (PcdFlashNvStorageFtwWorkingSize)
) >
- EMU_FVB_BLOCK_SIZE
+ EMU_FVB_NUM_SPARE_BLOCKS * EMU_FVB_BLOCK_SIZE
) {
DEBUG ((EFI_D_ERROR, "EMU Variable invalid PCD sizes\n"));
return EFI_INVALID_PARAMETER;
}
+ if (PcdGet64 (PcdFlashNvStorageVariableBase64) != 0) {
+ DEBUG ((EFI_D_INFO, "Disabling EMU Variable FVB since "
+ "flash variables appear to be supported.\n"));
+ return EFI_ABORTED;
+ }
+
//
// By default we will initialize the FV contents. But, if
// PcdEmuVariableNvStoreReserved is non-zero, then we will
@@ -800,10 +770,7 @@ FvbInitialize (
Initialize = FALSE;
}
} else {
- Ptr = AllocateAlignedRuntimePages (
- EFI_SIZE_TO_PAGES (EMU_FVB_SIZE),
- SIZE_64KB
- );
+ Ptr = AllocateRuntimePages (EFI_SIZE_TO_PAGES (EMU_FVB_SIZE));
}
mEmuVarsFvb.BufferPtr = Ptr;
@@ -815,22 +782,25 @@ FvbInitialize (
SetMem (Ptr, EMU_FVB_SIZE, ERASED_UINT8);
InitializeFvAndVariableStoreHeaders (Ptr);
}
- PcdSet32 (PcdFlashNvStorageVariableBase, (UINT32)(UINTN) Ptr);
+ PcdStatus = PcdSet64S (PcdFlashNvStorageVariableBase64, (UINT32)(UINTN) Ptr);
+ ASSERT_RETURN_ERROR (PcdStatus);
//
// Initialize the Fault Tolerant Write data area
//
- SubPtr = (VOID*) ((UINT8*) Ptr + FixedPcdGet32 (PcdVariableStoreSize));
- if (Initialize) {
- InitializeFtwState (SubPtr);
- }
- PcdSet32 (PcdFlashNvStorageFtwWorkingBase, (UINT32)(UINTN) SubPtr);
+ SubPtr = (VOID*) ((UINT8*) Ptr + PcdGet32 (PcdFlashNvStorageVariableSize));
+ PcdStatus = PcdSet32S (PcdFlashNvStorageFtwWorkingBase,
+ (UINT32)(UINTN) SubPtr);
+ ASSERT_RETURN_ERROR (PcdStatus);
//
// Initialize the Fault Tolerant Write spare block
//
- SubPtr = (VOID*) ((UINT8*) Ptr + EMU_FVB_BLOCK_SIZE);
- PcdSet32 (PcdFlashNvStorageFtwSpareBase, (UINT32)(UINTN) SubPtr);
+ SubPtr = (VOID*) ((UINT8*) Ptr +
+ EMU_FVB_NUM_SPARE_BLOCKS * EMU_FVB_BLOCK_SIZE);
+ PcdStatus = PcdSet32S (PcdFlashNvStorageFtwSpareBase,
+ (UINT32)(UINTN) SubPtr);
+ ASSERT_RETURN_ERROR (PcdStatus);
//
// Setup FVB device path
@@ -846,7 +816,7 @@ FvbInitialize (
Handle = 0;
Status = gBS->InstallMultipleProtocolInterfaces (
&Handle,
- &gEfiFirmwareVolumeBlockProtocolGuid,
+ &gEfiFirmwareVolumeBlock2ProtocolGuid,
&mEmuVarsFvb.FwVolBlockInstance,
&gEfiDevicePathProtocolGuid,
&mEmuVarsFvb.DevicePath,