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: Naresh Kumar Ravulapalli <nareshkumar.ravulapa...@altera.com>
---
 drivers/ddr/altera/sdram_arria10.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/ddr/altera/sdram_arria10.c 
b/drivers/ddr/altera/sdram_arria10.c
index d3305a6c82d..d75203a1d2a 100644
--- a/drivers/ddr/altera/sdram_arria10.c
+++ b/drivers/ddr/altera/sdram_arria10.c
@@ -1,12 +1,14 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (C) 2017 Intel Corporation <www.intel.com>
+ * Copyright (C) 2025 Altera Corporation <www.altera.com>
  */
 
 #include <cpu_func.h>
 #include <errno.h>
 #include <fdtdec.h>
 #include <init.h>
+#include <hang.h>
 #include <log.h>
 #include <malloc.h>
 #include <wait_bit.h>
@@ -702,6 +704,18 @@ 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 than 
hardware size.\n");
+               hang();
+       }
+
        if (of_sdram_firewall_setup(gd->fdt_blob))
                puts("FW: Error Configuring Firewall\n");
 
-- 
2.35.3

Reply via email to