From 065349ecf62e0ec8b0cb40384bf43e6af863a4de Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Fri, 5 May 2017 04:26:47 +0200 Subject: [PATCH 2/2] wip Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.h | 10 +++++++-- OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c | 23 +++++++++++--------- OvmfPkg/PlatformPei/Platform.c | 5 ++--- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.h b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.h index f34fad2cdd48..090b218aaf55 100644 --- a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.h +++ b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.h @@ -58,8 +58,14 @@ typedef struct { // // Constants // -#define EMU_FVB_BLOCK_SIZE (FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize)) -#define EMU_FVB_SIZE (2 * FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize)) +#define EMU_FVB_BLOCK_SIZE \ + EFI_PAGE_SIZE +#define EMU_FVB_NUM_SPARE_BLOCKS \ + EFI_SIZE_TO_PAGES ((UINTN)FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize)) +#define EMU_FVB_NUM_TOTAL_BLOCKS \ + (2 * EMU_FVB_NUM_SPARE_BLOCKS) +#define EMU_FVB_SIZE \ + (EMU_FVB_NUM_TOTAL_BLOCKS * EMU_FVB_BLOCK_SIZE) #define FTW_WRITE_QUEUE_SIZE \ (FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) - \ sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER)) diff --git a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c index dec6d4af50df..990910deb227 100644 --- a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c +++ b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c @@ -74,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, @@ -185,14 +185,14 @@ FvbProtocolGetBlockSize ( { EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; - if (Lba > 1) { + if (Lba > EMU_FVB_NUM_TOTAL_BLOCKS - 1) { return EFI_INVALID_PARAMETER; } FvbDevice = FVB_DEVICE_FROM_THIS (This); *BlockSize = FvbDevice->BlockSize; - *NumberOfBlocks = (UINTN) (2 - (UINTN) Lba); + *NumberOfBlocks = (UINTN) (EMU_FVB_NUM_TOTAL_BLOCKS - (UINTN) Lba); return EFI_SUCCESS; } @@ -345,7 +345,9 @@ FvbProtocolEraseBlocks ( // // Check input parameters // - if ((NumOfLba == 0) || (StartingLba > 1) || ((StartingLba + NumOfLba) > 2)) { + if ((NumOfLba == 0) || + (StartingLba > EMU_FVB_NUM_TOTAL_BLOCKS - 1) || + ((StartingLba + NumOfLba) > EMU_FVB_NUM_TOTAL_BLOCKS)) { VA_END (args); return EFI_INVALID_PARAMETER; } @@ -353,7 +355,7 @@ FvbProtocolEraseBlocks ( if (StartingLba == 0) { Erase = (UINT8) (Erase | BIT0); } - if ((StartingLba + NumOfLba) == 2) { + if ((StartingLba + NumOfLba) == EMU_FVB_NUM_TOTAL_BLOCKS) { Erase = (UINT8) (Erase | BIT1); } @@ -663,7 +665,7 @@ InitializeFvAndVariableStoreHeaders ( // EFI_FV_BLOCK_MAP_ENTRY BlockMap[1]; { { - 2, // UINT32 NumBlocks; + EMU_FVB_NUM_TOTAL_BLOCKS, // UINT32 NumBlocks; EMU_FVB_BLOCK_SIZE // UINT32 Length; } } @@ -732,7 +734,7 @@ InitializeFvAndVariableStoreHeaders ( // EFI_FV_BLOCK_MAP_ENTRY BlockMap[1]; { { - 2, // UINT32 NumBlocks; + EMU_FVB_NUM_TOTAL_BLOCKS, // UINT32 NumBlocks; EMU_FVB_BLOCK_SIZE // UINT32 Length; } } @@ -814,7 +816,7 @@ FvbInitialize ( (PcdGet32 (PcdVariableStoreSize) + PcdGet32 (PcdFlashNvStorageFtwWorkingSize) ) > - EMU_FVB_BLOCK_SIZE + EMU_FVB_BLOCK_SIZE * EMU_FVB_NUM_SPARE_BLOCKS ) { DEBUG ((EFI_D_ERROR, "EMU Variable invalid PCD sizes\n")); return EFI_INVALID_PARAMETER; @@ -877,7 +879,8 @@ FvbInitialize ( // // Initialize the Fault Tolerant Write spare block // - SubPtr = (VOID*) ((UINT8*) Ptr + EMU_FVB_BLOCK_SIZE); + SubPtr = (VOID*) ((UINT8*) Ptr + + EMU_FVB_BLOCK_SIZE * EMU_FVB_NUM_SPARE_BLOCKS); PcdStatus = PcdSet32S (PcdFlashNvStorageFtwSpareBase, (UINT32)(UINTN) SubPtr); ASSERT_RETURN_ERROR (PcdStatus); diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index 77a8a16c15b8..c2829dbcf5c7 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -513,9 +513,8 @@ ReserveEmuVariableNvStore ( // VariableStore = (EFI_PHYSICAL_ADDRESS)(UINTN) - AllocateAlignedRuntimePages ( - EFI_SIZE_TO_PAGES (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)), - PcdGet32 (PcdFlashNvStorageFtwSpareSize) + AllocateRuntimePages ( + EFI_SIZE_TO_PAGES (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) ); DEBUG ((EFI_D_INFO, "Reserved variable store memory: 0x%lX; size: %dkb\n", -- 2.9.3