]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c
ArmPlatformPkg/NorFlashDxe: Fix coding mistakes that would prevent Runtime mode
[mirror_edk2.git] / ArmPlatformPkg / Drivers / NorFlashDxe / NorFlashFvbDxe.c
index 4b56f2a40a4f4c404e906ca6f73fb16269316710..b9230c1ee007c8f147bbb86b565e1b5b8a40b65e 100644 (file)
@@ -1,6 +1,6 @@
 /*++ @file  NorFlashFvbDxe.c\r
 \r
- Copyright (c) 2011-201333, ARM Ltd. All rights reserved.<BR>\r
+ Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>\r
 \r
  This program and the accompanying materials\r
  are licensed and made available under the terms and conditions of the BSD License\r
@@ -417,7 +417,6 @@ FvbRead (
   EFI_STATUS    Status;\r
   EFI_STATUS    TempStatus;\r
   UINTN         BlockSize;\r
-  UINT8         *BlockBuffer;\r
   NOR_FLASH_INSTANCE *Instance;\r
 \r
   Instance = INSTANCE_FROM_FVB_THIS(This);\r
@@ -450,32 +449,24 @@ FvbRead (
     return EFI_BAD_BUFFER_SIZE;\r
   }\r
 \r
-  // FixMe: Allow an arbitrary number of bytes to be read out, not just a multiple of block size.\r
-\r
-  // Allocate runtime memory to read in the NOR Flash data. Variable Services are runtime.\r
-  BlockBuffer = AllocateRuntimePool (BlockSize);\r
-\r
-  // Check if the memory allocation was successful\r
-  if (BlockBuffer == NULL) {\r
-    DEBUG ((EFI_D_ERROR, "FvbRead: ERROR - Could not allocate BlockBuffer @ 0x%08x.\n", BlockBuffer));\r
+  // Check we did get some memory\r
+  if (Instance->FvbBuffer == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "FvbRead: ERROR - Buffer not ready\n"));\r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
   // Read NOR Flash data into shadow buffer\r
-  TempStatus = NorFlashReadBlocks (Instance, Instance->StartLba + Lba, BlockSize, BlockBuffer);\r
+  TempStatus = NorFlashReadBlocks (Instance, Instance->StartLba + Lba, BlockSize, Instance->FvbBuffer);\r
   if (EFI_ERROR (TempStatus)) {\r
     // Return one of the pre-approved error statuses\r
-    Status = EFI_DEVICE_ERROR;\r
-    goto FREE_MEMORY;\r
+    return EFI_DEVICE_ERROR;\r
   }\r
 \r
   // Put the data at the appropriate location inside the buffer area\r
-  DEBUG ((DEBUG_BLKIO, "FvbRead: CopyMem( Dst=0x%08x, Src=0x%08x, Size=0x%x ).\n", Buffer, BlockBuffer + Offset, *NumBytes));\r
+  DEBUG ((DEBUG_BLKIO, "FvbRead: CopyMem( Dst=0x%08x, Src=0x%08x, Size=0x%x ).\n", Buffer, (UINTN)Instance->FvbBuffer + Offset, *NumBytes));\r
 \r
-  CopyMem(Buffer, BlockBuffer + Offset, *NumBytes);\r
+  CopyMem (Buffer, (VOID*)((UINTN)Instance->FvbBuffer + Offset), *NumBytes);\r
 \r
-FREE_MEMORY:\r
-  FreePool(BlockBuffer);\r
   return Status;\r
 }\r
 \r
@@ -546,7 +537,6 @@ FvbWrite (
   EFI_STATUS  Status;\r
   EFI_STATUS  TempStatus;\r
   UINTN       BlockSize;\r
-  UINT8       *BlockBuffer;\r
   NOR_FLASH_INSTANCE *Instance;\r
 \r
   Instance = INSTANCE_FROM_FVB_THIS(This);\r
@@ -585,38 +575,29 @@ FvbWrite (
     return EFI_BAD_BUFFER_SIZE;\r
   }\r
 \r
-  // Allocate runtime memory to read in the NOR Flash data.\r
-  // Since the intention is to use this with Variable Services and since these are runtime,\r
-  // allocate the memory from the runtime pool.\r
-  BlockBuffer = AllocateRuntimePool (BlockSize);\r
-\r
   // Check we did get some memory\r
-  if( BlockBuffer == NULL ) {\r
-    DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - Can not allocate BlockBuffer @ 0x%08x.\n", BlockBuffer));\r
+  if (Instance->FvbBuffer == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - Buffer not ready\n"));\r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
   // Read NOR Flash data into shadow buffer\r
-  TempStatus = NorFlashReadBlocks (Instance, Instance->StartLba + Lba, BlockSize, BlockBuffer);\r
+  TempStatus = NorFlashReadBlocks (Instance, Instance->StartLba + Lba, BlockSize, Instance->FvbBuffer);\r
   if (EFI_ERROR (TempStatus)) {\r
     // Return one of the pre-approved error statuses\r
-    Status = EFI_DEVICE_ERROR;\r
-    goto FREE_MEMORY;\r
+    return EFI_DEVICE_ERROR;\r
   }\r
 \r
   // Put the data at the appropriate location inside the buffer area\r
-  CopyMem((BlockBuffer + Offset), Buffer, *NumBytes);\r
+  CopyMem ((VOID*)((UINTN)Instance->FvbBuffer + Offset), Buffer, *NumBytes);\r
 \r
   // Write the modified buffer back to the NorFlash\r
-  TempStatus = NorFlashWriteBlocks (Instance, Instance->StartLba + Lba, BlockSize, BlockBuffer);\r
+  TempStatus = NorFlashWriteBlocks (Instance, Instance->StartLba + Lba, BlockSize, Instance->FvbBuffer);\r
   if (EFI_ERROR (TempStatus)) {\r
     // Return one of the pre-approved error statuses\r
-    Status = EFI_DEVICE_ERROR;\r
-    goto FREE_MEMORY;\r
+    return EFI_DEVICE_ERROR;\r
   }\r
 \r
-FREE_MEMORY:\r
-  FreePool(BlockBuffer);\r
   return Status;\r
 }\r
 \r