]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c
ArmPlatformPkg/NorFlashDxe: Change Flash memory attributes before writes
[mirror_edk2.git] / 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