From: Stefan Eichenberger Date: Fri, 14 Mar 2025 10:06:49 +0000 (+0100) Subject: common/memsize.c: Fix get_ram_size() original data restore X-Git-Tag: v2026.04-rc4~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8d24789abed0822fbe41a2f9d72cf19650159dc6;p=thirdparty%2Fu-boot.git common/memsize.c: Fix get_ram_size() original data restore The get_ram_size() function fails to restore the original RAM data when the data cache is enabled. This issue was observed on an AM625 R5 SPL with 512MB of RAM and is a regression that became visible with commit bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled"). Observed boot failure messages: Warning: Did not detect image signing certificate. Skipping authentication to prevent boot failure. This will fail on Security Enforcing(HS-SE) devices Authentication passed Starting ATF on ARM64 core... The system then hangs. This indicates that without a data cache flush, data in the cache is not coherent with RAM, preventing the system from booting. This was verified by printing the content of this address when the issue occurs. Add a data cache flush after each restore operation to resolve this issue. Fixes: bc07851897bd ("board: ti: Pull redundant DDR functions to a common location and Fixup DDR size when ECC is enabled") Fixes: 1c64b98c1ec4 ("common/memsize.c: Fix get_ram_size() when cache is enabled") Signed-off-by: Stefan Eichenberger Reviewed-by: Emanuele Ghidoli Tested-by: Francesco Dolcini # Toradex Verdin AM62 --- diff --git a/common/memsize.c b/common/memsize.c index 3c3ae6f1eba..1abf3fc47d7 100644 --- a/common/memsize.c +++ b/common/memsize.c @@ -85,6 +85,8 @@ long get_ram_size(long *base, long maxsize) addr = base + cnt; sync(); *addr = save[--i]; + if (dcache_en) + dcache_flush_invalidate(addr); } return (0); } @@ -93,6 +95,8 @@ long get_ram_size(long *base, long maxsize) addr = base + cnt; /* pointer arith! */ val = *addr; *addr = save[--i]; + if (dcache_en) + dcache_flush_invalidate(addr); if (val != ~cnt) { size = cnt * sizeof(long); /* @@ -104,6 +108,8 @@ long get_ram_size(long *base, long maxsize) cnt <<= 1) { addr = base + cnt; *addr = save[--i]; + if (dcache_en) + dcache_flush_invalidate(addr); } /* warning: don't restore save_base in this case, * it is already done in the loop because @@ -115,6 +121,8 @@ long get_ram_size(long *base, long maxsize) } } *base = save_base; + if (dcache_en) + dcache_flush_invalidate(base); return (maxsize); }