]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
ddr: altera: arria10: Add DRAM size checking
authorAlif Zakuan Yuslaimi <alif.zakuan.yuslaimi@altera.com>
Tue, 16 Dec 2025 08:46:22 +0000 (00:46 -0800)
committerTom Rini <trini@konsulko.com>
Sat, 14 Feb 2026 17:06:46 +0000 (11:06 -0600)
Add DRAM size checking compare between size from device tree and actual
hardware.

Trigger hang if DRAM size from device tree is greater than actual hardware.
Display warning message if DRAM size mismatch between device tree and
actual hardware.

Signed-off-by: Alif Zakuan Yuslaimi <alif.zakuan.yuslaimi@altera.com>
Reviewed-by: Tien Fong Chee <tien.fong.chee@altera.com> Best regards,
drivers/ddr/altera/sdram_arria10.c

index d3305a6c82dfabd6aff95c7c263eb132c24c9315..c281f711fdfd9fadb5e13515d93f2eb5cf2216bb 100644 (file)
@@ -8,6 +8,7 @@
 #include <fdtdec.h>
 #include <init.h>
 #include <log.h>
+#include <hang.h>
 #include <malloc.h>
 #include <wait_bit.h>
 #include <watchdog.h>
@@ -667,6 +668,22 @@ static int of_sdram_firewall_setup(const void *blob)
        return 0;
 }
 
+static void sdram_size_check(void)
+{
+       phys_size_t ram_check = 0;
+
+       debug("DDR: Running SDRAM size sanity check\n");
+
+       ram_check = get_ram_size((long *)gd->bd->bi_dram[0].start,
+                                gd->bd->bi_dram[0].size);
+       if (ram_check != gd->bd->bi_dram[0].size) {
+               puts("DDR: SDRAM size check failed!\n");
+               hang();
+       }
+
+       debug("DDR: SDRAM size check passed!\n");
+}
+
 int ddr_calibration_sequence(void)
 {
        schedule();
@@ -702,11 +719,26 @@ int ddr_calibration_sequence(void)
        /* setup the dram info within bd */
        dram_init_banksize();
 
+       if (gd->ram_size != gd->bd->bi_dram[0].size) {
+               printf("DDR: Warning: DRAM size from device tree (%ld MiB)\n",
+                      gd->bd->bi_dram[0].size >> 20);
+               printf(" mismatch with hardware (%ld MiB).\n",
+                      gd->ram_size >> 20);
+       }
+
+       if (gd->bd->bi_dram[0].size > gd->ram_size) {
+               printf("DDR: Error: DRAM size from device tree is greater\n");
+               printf(" than hardware size.\n");
+               hang();
+       }
+
        if (of_sdram_firewall_setup(gd->fdt_blob))
                puts("FW: Error Configuring Firewall\n");
 
        if (sdram_is_ecc_enabled())
                sdram_init_ecc_bits(gd->ram_size);
 
+       sdram_size_check();
+
        return 0;
 }