summaryrefslogtreecommitdiffstats
path: root/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c
diff options
context:
space:
mode:
authorOlivier Martin <olivier.martin@arm.com>2014-04-08 18:02:32 +0000
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>2014-04-08 18:02:32 +0000
commit2dff0c1ab2be86979ccb99db8b17bd3347b98b59 (patch)
tree664464d0350ca3d1814a11d870e825beadecd568 /ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c
parent000f80f77ba442329b62dc28c0bdd13c3e083ab0 (diff)
downloadedk2-2dff0c1ab2be86979ccb99db8b17bd3347b98b59.tar.gz
edk2-2dff0c1ab2be86979ccb99db8b17bd3347b98b59.tar.bz2
edk2-2dff0c1ab2be86979ccb99db8b17bd3347b98b59.zip
ArmPlatformPkg/NorFlashDxe: Fix coding mistakes that would prevent Runtime mode
- No allocation during Runtime mode (post ExitBootServices()) - Allocate all the persistent data into runtime space - Do not access BootServices API during Runtime mode Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Olivier Martin <olivier.martin@arm.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15437 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c')
-rw-r--r--ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c49
1 files changed, 15 insertions, 34 deletions
diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c
index 4b56f2a40a..b9230c1ee0 100644
--- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c
+++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c
@@ -1,6 +1,6 @@
/*++ @file NorFlashFvbDxe.c
- Copyright (c) 2011-201333, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -417,7 +417,6 @@ FvbRead (
EFI_STATUS Status;
EFI_STATUS TempStatus;
UINTN BlockSize;
- UINT8 *BlockBuffer;
NOR_FLASH_INSTANCE *Instance;
Instance = INSTANCE_FROM_FVB_THIS(This);
@@ -450,32 +449,24 @@ FvbRead (
return EFI_BAD_BUFFER_SIZE;
}
- // FixMe: Allow an arbitrary number of bytes to be read out, not just a multiple of block size.
-
- // Allocate runtime memory to read in the NOR Flash data. Variable Services are runtime.
- BlockBuffer = AllocateRuntimePool (BlockSize);
-
- // Check if the memory allocation was successful
- if (BlockBuffer == NULL) {
- DEBUG ((EFI_D_ERROR, "FvbRead: ERROR - Could not allocate BlockBuffer @ 0x%08x.\n", BlockBuffer));
+ // Check we did get some memory
+ if (Instance->FvbBuffer == NULL) {
+ DEBUG ((EFI_D_ERROR, "FvbRead: ERROR - Buffer not ready\n"));
return EFI_DEVICE_ERROR;
}
// Read NOR Flash data into shadow buffer
- TempStatus = NorFlashReadBlocks (Instance, Instance->StartLba + Lba, BlockSize, BlockBuffer);
+ TempStatus = NorFlashReadBlocks (Instance, Instance->StartLba + Lba, BlockSize, Instance->FvbBuffer);
if (EFI_ERROR (TempStatus)) {
// Return one of the pre-approved error statuses
- Status = EFI_DEVICE_ERROR;
- goto FREE_MEMORY;
+ return EFI_DEVICE_ERROR;
}
// Put the data at the appropriate location inside the buffer area
- DEBUG ((DEBUG_BLKIO, "FvbRead: CopyMem( Dst=0x%08x, Src=0x%08x, Size=0x%x ).\n", Buffer, BlockBuffer + Offset, *NumBytes));
+ DEBUG ((DEBUG_BLKIO, "FvbRead: CopyMem( Dst=0x%08x, Src=0x%08x, Size=0x%x ).\n", Buffer, (UINTN)Instance->FvbBuffer + Offset, *NumBytes));
- CopyMem(Buffer, BlockBuffer + Offset, *NumBytes);
+ CopyMem (Buffer, (VOID*)((UINTN)Instance->FvbBuffer + Offset), *NumBytes);
-FREE_MEMORY:
- FreePool(BlockBuffer);
return Status;
}
@@ -546,7 +537,6 @@ FvbWrite (
EFI_STATUS Status;
EFI_STATUS TempStatus;
UINTN BlockSize;
- UINT8 *BlockBuffer;
NOR_FLASH_INSTANCE *Instance;
Instance = INSTANCE_FROM_FVB_THIS(This);
@@ -585,38 +575,29 @@ FvbWrite (
return EFI_BAD_BUFFER_SIZE;
}
- // Allocate runtime memory to read in the NOR Flash data.
- // Since the intention is to use this with Variable Services and since these are runtime,
- // allocate the memory from the runtime pool.
- BlockBuffer = AllocateRuntimePool (BlockSize);
-
// Check we did get some memory
- if( BlockBuffer == NULL ) {
- DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - Can not allocate BlockBuffer @ 0x%08x.\n", BlockBuffer));
+ if (Instance->FvbBuffer == NULL) {
+ DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - Buffer not ready\n"));
return EFI_DEVICE_ERROR;
}
// Read NOR Flash data into shadow buffer
- TempStatus = NorFlashReadBlocks (Instance, Instance->StartLba + Lba, BlockSize, BlockBuffer);
+ TempStatus = NorFlashReadBlocks (Instance, Instance->StartLba + Lba, BlockSize, Instance->FvbBuffer);
if (EFI_ERROR (TempStatus)) {
// Return one of the pre-approved error statuses
- Status = EFI_DEVICE_ERROR;
- goto FREE_MEMORY;
+ return EFI_DEVICE_ERROR;
}
// Put the data at the appropriate location inside the buffer area
- CopyMem((BlockBuffer + Offset), Buffer, *NumBytes);
+ CopyMem ((VOID*)((UINTN)Instance->FvbBuffer + Offset), Buffer, *NumBytes);
// Write the modified buffer back to the NorFlash
- TempStatus = NorFlashWriteBlocks (Instance, Instance->StartLba + Lba, BlockSize, BlockBuffer);
+ TempStatus = NorFlashWriteBlocks (Instance, Instance->StartLba + Lba, BlockSize, Instance->FvbBuffer);
if (EFI_ERROR (TempStatus)) {
// Return one of the pre-approved error statuses
- Status = EFI_DEVICE_ERROR;
- goto FREE_MEMORY;
+ return EFI_DEVICE_ERROR;
}
-FREE_MEMORY:
- FreePool(BlockBuffer);
return Status;
}