summaryrefslogtreecommitdiff
path: root/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c
diff options
context:
space:
mode:
authorHarry Liebel <Harry.Liebel@arm.com>2014-05-08 14:48:55 +0000
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>2014-05-08 14:48:55 +0000
commit518c243d42731389502431a0fbf14b932f838888 (patch)
treece814179515ce1f4e253b4492c59e10f7fb8962c /ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c
parent0fb7e718a8587cf836266e16b9d091e0cd5a8498 (diff)
ArmPlatformPkg/NorFlashDxe: Optimise FVB protocol
- Only read what needs reading, don't read the whole block. - Don't write back buffers containing no data after an erase. - Reduce number of NOR erases when writing data. Only erase the block when required. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Harry Liebel <Harry.Liebel@arm.com> Reviewed-by: Olivier Martin <olivier.martin@arm.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15500 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c')
-rw-r--r--ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c67
1 files changed, 64 insertions, 3 deletions
diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c
index a03bf5749e..82b9f3f742 100644
--- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c
+++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c
@@ -586,6 +586,7 @@ NorFlashWriteSingleBlock (
UINTN BuffersInBlock;
UINTN RemainingWords;
EFI_TPL OriginalTPL;
+ UINTN Cnt;
Status = EFI_SUCCESS;
@@ -619,13 +620,22 @@ NorFlashWriteSingleBlock (
BuffersInBlock = (UINTN)(BlockSizeInWords * 4) / P30_MAX_BUFFER_SIZE_IN_BYTES;
// Then feed each buffer chunk to the NOR Flash
+ // If a buffer does not contain any data, don't write it.
for(BufferIndex=0;
BufferIndex < BuffersInBlock;
BufferIndex++, WordAddress += P30_MAX_BUFFER_SIZE_IN_BYTES, DataBuffer += P30_MAX_BUFFER_SIZE_IN_WORDS
) {
- Status = NorFlashWriteBuffer (Instance, WordAddress, P30_MAX_BUFFER_SIZE_IN_BYTES, DataBuffer);
- if (EFI_ERROR(Status)) {
- goto EXIT;
+ // Check the buffer to see if it contains any data (not set all 1s).
+ for (Cnt = 0; Cnt < P30_MAX_BUFFER_SIZE_IN_WORDS; Cnt++) {
+ if (~DataBuffer[Cnt] != 0 ) {
+ // Some data found, write the buffer.
+ Status = NorFlashWriteBuffer (Instance, WordAddress, P30_MAX_BUFFER_SIZE_IN_BYTES,
+ DataBuffer);
+ if (EFI_ERROR(Status)) {
+ goto EXIT;
+ }
+ break;
+ }
}
}
@@ -785,6 +795,57 @@ NorFlashReadBlocks (
}
EFI_STATUS
+NorFlashRead (
+ IN NOR_FLASH_INSTANCE *Instance,
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN UINTN BufferSizeInBytes,
+ OUT VOID *Buffer
+ )
+{
+ UINT32 NumBlocks;
+ UINTN StartAddress;
+
+ // The buffer must be valid
+ if (Buffer == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Return if we have not any byte to read
+ if (BufferSizeInBytes == 0) {
+ return EFI_SUCCESS;
+ }
+
+ // All blocks must be within the device
+ NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ;
+
+ if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {
+ DEBUG ((EFI_D_ERROR, "NorFlashRead: ERROR - Read will exceed last block\n"));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (Offset + BufferSizeInBytes >= Instance->Size) {
+ DEBUG ((EFI_D_ERROR, "NorFlashRead: ERROR - Read will exceed device size.\n"));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Get the address to start reading from
+ StartAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress,
+ Lba,
+ Instance->Media.BlockSize
+ );
+
+ // Put the device into Read Array mode
+ SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
+
+ // Readout the data
+ CopyMem (Buffer, (UINTN *)(StartAddress + Offset), BufferSizeInBytes);
+
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
NorFlashReset (
IN NOR_FLASH_INSTANCE *Instance
)