}\r
},\r
NULL, // BufferPtr\r
- FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize), // BlockSize\r
- 2 * FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize), // Size\r
+ EMU_FVB_BLOCK_SIZE, // BlockSize\r
+ EMU_FVB_SIZE, // Size\r
{ // FwVolBlockInstance\r
FvbProtocolGetAttributes,\r
FvbProtocolSetAttributes,\r
{\r
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
\r
- if (Lba > 1) {\r
+ if (Lba >= EMU_FVB_NUM_TOTAL_BLOCKS) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
\r
*BlockSize = FvbDevice->BlockSize;\r
- *NumberOfBlocks = (UINTN) (2 - (UINTN) Lba);\r
+ *NumberOfBlocks = (UINTN)(EMU_FVB_NUM_TOTAL_BLOCKS - Lba);\r
\r
return EFI_SUCCESS;\r
}\r
)\r
{\r
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
- VA_LIST args;\r
+ VA_LIST Args;\r
EFI_LBA StartingLba;\r
UINTN NumOfLba;\r
- UINT8 Erase;\r
- VOID *ErasePtr;\r
+ UINT8 *ErasePtr;\r
UINTN EraseSize;\r
\r
FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
- Erase = 0;\r
-\r
- VA_START (args, This);\r
\r
+ //\r
+ // Check input parameters\r
+ //\r
+ VA_START (Args, This);\r
do {\r
- StartingLba = VA_ARG (args, EFI_LBA);\r
+ StartingLba = VA_ARG (Args, EFI_LBA);\r
if (StartingLba == EFI_LBA_LIST_TERMINATOR) {\r
break;\r
}\r
+ NumOfLba = VA_ARG (Args, UINTN);\r
\r
- NumOfLba = VA_ARG (args, UINTN);\r
-\r
- //\r
- // Check input parameters\r
- //\r
- if ((NumOfLba == 0) || (StartingLba > 1) || ((StartingLba + NumOfLba) > 2)) {\r
- VA_END (args);\r
+ if (StartingLba > EMU_FVB_NUM_TOTAL_BLOCKS ||\r
+ NumOfLba > EMU_FVB_NUM_TOTAL_BLOCKS - StartingLba) {\r
+ VA_END (Args);\r
return EFI_INVALID_PARAMETER;\r
}\r
-\r
- if (StartingLba == 0) {\r
- Erase = (UINT8) (Erase | BIT0);\r
- }\r
- if ((StartingLba + NumOfLba) == 2) {\r
- Erase = (UINT8) (Erase | BIT1);\r
- }\r
-\r
} while (1);\r
+ VA_END (Args);\r
\r
- VA_END (args);\r
-\r
- ErasePtr = (UINT8*) FvbDevice->BufferPtr;\r
- EraseSize = 0;\r
+ //\r
+ // Erase blocks\r
+ //\r
+ VA_START (Args, This);\r
+ do {\r
+ StartingLba = VA_ARG (Args, EFI_LBA);\r
+ if (StartingLba == EFI_LBA_LIST_TERMINATOR) {\r
+ break;\r
+ }\r
+ NumOfLba = VA_ARG (Args, UINTN);\r
\r
- if ((Erase & BIT0) != 0) {\r
- EraseSize = EraseSize + FvbDevice->BlockSize;\r
- } else {\r
- ErasePtr = (VOID*) ((UINT8*)ErasePtr + FvbDevice->BlockSize);\r
- }\r
+ ErasePtr = FvbDevice->BufferPtr;\r
+ ErasePtr += (UINTN)StartingLba * FvbDevice->BlockSize;\r
+ EraseSize = NumOfLba * FvbDevice->BlockSize;\r
\r
- if ((Erase & BIT1) != 0) {\r
- EraseSize = EraseSize + FvbDevice->BlockSize;\r
- }\r
+ SetMem (ErasePtr, EraseSize, ERASED_UINT8);\r
+ } while (1);\r
+ VA_END (Args);\r
\r
- if (EraseSize != 0) {\r
- SetMem (\r
- (VOID*) ErasePtr,\r
- EraseSize,\r
- ERASED_UINT8\r
- );\r
- VA_START (args, This);\r
- PlatformFvbBlocksErased (This, args);\r
- VA_END (args);\r
- }\r
+ //\r
+ // Call platform hook\r
+ //\r
+ VA_START (Args, This);\r
+ PlatformFvbBlocksErased (This, Args);\r
+ VA_END (Args);\r
\r
return EFI_SUCCESS;\r
}\r
IN UINT8 *Buffer\r
)\r
{\r
-\r
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
UINT8 *FvbDataPtr;\r
+ EFI_STATUS Status;\r
\r
FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
\r
- if ((Lba > 1) || (Offset > FvbDevice->BlockSize)) {\r
+ if (Lba >= EMU_FVB_NUM_TOTAL_BLOCKS ||\r
+ Offset > FvbDevice->BlockSize) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
- if ((Offset + *NumBytes) > FvbDevice->BlockSize) {\r
+ Status = EFI_SUCCESS;\r
+ if (*NumBytes > FvbDevice->BlockSize - Offset) {\r
*NumBytes = FvbDevice->BlockSize - Offset;\r
+ Status = EFI_BAD_BUFFER_SIZE;\r
}\r
\r
- FvbDataPtr =\r
- (UINT8*) FvbDevice->BufferPtr +\r
- MultU64x32 (Lba, (UINT32) FvbDevice->BlockSize) +\r
- Offset;\r
-\r
- if (*NumBytes > 0) {\r
- CopyMem (FvbDataPtr, Buffer, *NumBytes);\r
- PlatformFvbDataWritten (This, Lba, Offset, *NumBytes, Buffer);\r
- }\r
+ FvbDataPtr = FvbDevice->BufferPtr;\r
+ FvbDataPtr += (UINTN)Lba * FvbDevice->BlockSize;\r
+ FvbDataPtr += Offset;\r
\r
- return EFI_SUCCESS;\r
+ CopyMem (FvbDataPtr, Buffer, *NumBytes);\r
+ PlatformFvbDataWritten (This, Lba, Offset, *NumBytes, Buffer);\r
+ return Status;\r
}\r
\r
\r
{\r
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
UINT8 *FvbDataPtr;\r
+ EFI_STATUS Status;\r
\r
FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
\r
- if ((Lba > 1) || (Offset > FvbDevice->BlockSize)) {\r
+ if (Lba >= EMU_FVB_NUM_TOTAL_BLOCKS ||\r
+ Offset > FvbDevice->BlockSize) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
- if ((Offset + *NumBytes) > FvbDevice->BlockSize) {\r
+ Status = EFI_SUCCESS;\r
+ if (*NumBytes > FvbDevice->BlockSize - Offset) {\r
*NumBytes = FvbDevice->BlockSize - Offset;\r
+ Status = EFI_BAD_BUFFER_SIZE;\r
}\r
\r
- FvbDataPtr =\r
- (UINT8*) FvbDevice->BufferPtr +\r
- MultU64x32 (Lba, (UINT32) FvbDevice->BlockSize) +\r
- Offset;\r
+ FvbDataPtr = FvbDevice->BufferPtr;\r
+ FvbDataPtr += (UINTN)Lba * FvbDevice->BlockSize;\r
+ FvbDataPtr += Offset;\r
\r
- if (*NumBytes > 0) {\r
- CopyMem (Buffer, FvbDataPtr, *NumBytes);\r
- PlatformFvbDataRead (This, Lba, Offset, *NumBytes, Buffer);\r
- }\r
-\r
- return EFI_SUCCESS;\r
+ CopyMem (Buffer, FvbDataPtr, *NumBytes);\r
+ PlatformFvbDataRead (This, Lba, Offset, *NumBytes, Buffer);\r
+ return Status;\r
}\r
\r
\r
// EFI_FV_BLOCK_MAP_ENTRY BlockMap[1];\r
{\r
{\r
- 2, // UINT32 NumBlocks;\r
+ EMU_FVB_NUM_TOTAL_BLOCKS, // UINT32 NumBlocks;\r
EMU_FVB_BLOCK_SIZE // UINT32 Length;\r
}\r
}\r
//\r
// Verify that the PCD's are set correctly.\r
//\r
+ ASSERT (FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) %\r
+ EMU_FVB_BLOCK_SIZE == 0);\r
if (\r
(PcdGet32 (PcdVariableStoreSize) +\r
PcdGet32 (PcdFlashNvStorageFtwWorkingSize)\r
) >\r
- EMU_FVB_BLOCK_SIZE\r
+ EMU_FVB_NUM_SPARE_BLOCKS * EMU_FVB_BLOCK_SIZE\r
) {\r
DEBUG ((EFI_D_ERROR, "EMU Variable invalid PCD sizes\n"));\r
return EFI_INVALID_PARAMETER;\r
Initialize = FALSE;\r
}\r
} else {\r
- Ptr = AllocateAlignedRuntimePages (\r
- EFI_SIZE_TO_PAGES (EMU_FVB_SIZE),\r
- SIZE_64KB\r
- );\r
+ Ptr = AllocateRuntimePages (EFI_SIZE_TO_PAGES (EMU_FVB_SIZE));\r
}\r
\r
mEmuVarsFvb.BufferPtr = Ptr;\r
//\r
// Initialize the Fault Tolerant Write spare block\r
//\r
- SubPtr = (VOID*) ((UINT8*) Ptr + EMU_FVB_BLOCK_SIZE);\r
+ SubPtr = (VOID*) ((UINT8*) Ptr +\r
+ EMU_FVB_NUM_SPARE_BLOCKS * EMU_FVB_BLOCK_SIZE);\r
PcdStatus = PcdSet32S (PcdFlashNvStorageFtwSpareBase,\r
(UINT32)(UINTN) SubPtr);\r
ASSERT_RETURN_ERROR (PcdStatus);\r