]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPlatformPkg/NorFlashDxe: Change Flash memory attributes before writes
authorAchin Gupta <achin.gupta@arm.com>
Fri, 20 Jan 2017 11:54:59 +0000 (11:54 +0000)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 20 Jan 2017 11:57:38 +0000 (11:57 +0000)
In NorFlashFvbInitialize() if a valid Firmware Volume header is not found at the
start of NOR Flash, the Flash memory is written before it has been remapped with
EFI_MEMORY_UC attributes to allow write commands. Since the flash memory was
previously mapped with Normal and possibly cacheable memory attributes, the
Flash commands might never reach the device.

This patch fixes this issue by remapping the Flash memory region with correct
memory attributes before writing to it.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Achin Gupta <achin.gupta@arm.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c

index 42be5c2a2dade7fd4de677e37b4cd44b6ecde4ef..12a861267a86e8846e963c1bc0b96fbbaa653d0b 100644 (file)
@@ -719,6 +719,29 @@ NorFlashFvbInitialize (
   UINTN       RuntimeMmioRegionSize;\r
 \r
   DEBUG((DEBUG_BLKIO,"NorFlashFvbInitialize\n"));\r
+  ASSERT((Instance != NULL));\r
+\r
+  //\r
+  // Declare the Non-Volatile storage as EFI_MEMORY_RUNTIME\r
+  //\r
+\r
+  // Note: all the NOR Flash region needs to be reserved into the UEFI Runtime memory;\r
+  //       even if we only use the small block region at the top of the NOR Flash.\r
+  //       The reason is when the NOR Flash memory is set into program mode, the command\r
+  //       is written as the base of the flash region (ie: Instance->DeviceBaseAddress)\r
+  RuntimeMmioRegionSize = (Instance->RegionBaseAddress - Instance->DeviceBaseAddress) + Instance->Size;\r
+\r
+  Status = gDS->AddMemorySpace (\r
+      EfiGcdMemoryTypeMemoryMappedIo,\r
+      Instance->DeviceBaseAddress, RuntimeMmioRegionSize,\r
+      EFI_MEMORY_UC | EFI_MEMORY_RUNTIME\r
+      );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = gDS->SetMemorySpaceAttributes (\r
+      Instance->DeviceBaseAddress, RuntimeMmioRegionSize,\r
+      EFI_MEMORY_UC | EFI_MEMORY_RUNTIME);\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   Instance->Initialized = TRUE;\r
   mFlashNvStorageVariableBase = FixedPcdGet32 (PcdFlashNvStorageVariableBase);\r
@@ -756,28 +779,6 @@ NorFlashFvbInitialize (
     }\r
   }\r
 \r
-  //\r
-  // Declare the Non-Volatile storage as EFI_MEMORY_RUNTIME\r
-  //\r
-\r
-  // Note: all the NOR Flash region needs to be reserved into the UEFI Runtime memory;\r
-  //       even if we only use the small block region at the top of the NOR Flash.\r
-  //       The reason is when the NOR Flash memory is set into program mode, the command\r
-  //       is written as the base of the flash region (ie: Instance->DeviceBaseAddress)\r
-  RuntimeMmioRegionSize = (Instance->RegionBaseAddress - Instance->DeviceBaseAddress) + Instance->Size;\r
-\r
-  Status = gDS->AddMemorySpace (\r
-      EfiGcdMemoryTypeMemoryMappedIo,\r
-      Instance->DeviceBaseAddress, RuntimeMmioRegionSize,\r
-      EFI_MEMORY_UC | EFI_MEMORY_RUNTIME\r
-      );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  Status = gDS->SetMemorySpaceAttributes (\r
-      Instance->DeviceBaseAddress, RuntimeMmioRegionSize,\r
-      EFI_MEMORY_UC | EFI_MEMORY_RUNTIME);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
   //\r
   // Register for the virtual address change event\r
   //\r