[PATCH] arm: sunxi: dram: restore previous value in DRAM

Andrei Lalaev andrei.lalaev at emlid.com
Sun Feb 13 16:10:14 CET 2022


It's better to restore previous value at offset because otherwise the
function can corrupt memory reserved by Linux (e.g. ramoops).

Signed-off-by: Andrei Lalaev <andrei.lalaev at emlid.com>
---
 arch/arm/mach-sunxi/dram_helpers.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-sunxi/dram_helpers.c b/arch/arm/mach-sunxi/dram_helpers.c
index 2c873192e6..ed6db14f3c 100644
--- a/arch/arm/mach-sunxi/dram_helpers.c
+++ b/arch/arm/mach-sunxi/dram_helpers.c
@@ -32,12 +32,20 @@ void mctl_await_completion(u32 *reg, u32 mask, u32 val)
 #ifndef CONFIG_MACH_SUNIV
 bool mctl_mem_matches(u32 offset)
 {
+	ulong addr = CONFIG_SYS_SDRAM_BASE + offset;
+	u32 prev_val = readl(addr);
+	bool ret = false;
+
 	/* Try to write different values to RAM at two addresses */
 	writel(0, CONFIG_SYS_SDRAM_BASE);
-	writel(0xaa55aa55, (ulong)CONFIG_SYS_SDRAM_BASE + offset);
+	writel(0xaa55aa55, addr);
 	dsb();
 	/* Check if the same value is actually observed when reading back */
-	return readl(CONFIG_SYS_SDRAM_BASE) ==
-	       readl((ulong)CONFIG_SYS_SDRAM_BASE + offset);
+	ret = readl(CONFIG_SYS_SDRAM_BASE) == readl(addr);
+
+	/* Restore previous value */
+	writel(prev_val, addr);
+
+	return ret;
 }
 #endif
-- 
2.25.1



More information about the U-Boot mailing list