]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
board: toradex: smarc-imx95: detect RAM sizes
authorEmanuele Ghidoli <emanuele.ghidoli@toradex.com>
Fri, 10 Jul 2026 13:39:08 +0000 (15:39 +0200)
committerFabio Estevam <festevam@gmail.com>
Mon, 27 Jul 2026 16:05:07 +0000 (13:05 -0300)
Use alias-based RAM probing to detect different memory configurations
on Toradex SMARC iMX95. The address wrap-around is not linear: address
bits above the module capacity alias back with some low address bits
XORed (bit 32 -> XOR 0xc000), as measured on 4GB and 8GB modules.

During probing, skip the first 256MB, since that region is reserved.

Signed-off-by: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>
board/toradex/smarc-imx95/smarc-imx95.c
include/configs/toradex-smarc-imx95.h

index 6040c49975a3771dfc4ca89e1f96932e83950a43..d09ce8a52abe197f0279e32f9186afe1f9a3e03b 100644 (file)
@@ -3,14 +3,35 @@
 
 #include <asm/arch/clock.h>
 #include <asm/arch/sys_proto.h>
+#include <errno.h>
 #include <fdt_support.h>
 #include <init.h>
 
 #include "../common/tdx-cfg-block.h"
 
+/*
+ * The address wrap-around is not linear: address bits above the module
+ * capacity alias back to the base with some low address bits XORed, as
+ * measured on 4GB and 8GB modules (bit 32 -> XOR 0xc000, bit 33 -> XOR
+ * 0x2000).
+ */
+static const struct ram_alias_check ram_alias_checks[] = {
+       { (void *)((uintptr_t)PHYS_SDRAM + SZ_4G), (void *)((uintptr_t)PHYS_SDRAM + 0xc000), SZ_8G },
+       { (void *)((uintptr_t)PHYS_SDRAM + SZ_2G), (void *)(PHYS_SDRAM), SZ_4G },
+       { NULL }
+};
+
 int board_phys_sdram_size(phys_size_t *size)
 {
-       *size = PHYS_SDRAM_SIZE + PHYS_SDRAM_2_SIZE;
+       phys_size_t sz;
+
+       sz = probe_ram_size_by_alias(ram_alias_checks);
+       if (!sz) {
+               puts("## WARNING: Less than 4GB RAM detected\n");
+               return -EINVAL;
+       }
+
+       *size = sz - PHYS_SDRAM_FW_RSVD;
 
        return 0;
 }
index 8a880b9650389224f1f690c9d9e82d6ca4279b2d..97e3322ac2824a61ebfeff5652f69a246d6dd201 100644 (file)
@@ -7,16 +7,19 @@
 #include <linux/sizes.h>
 #include <asm/arch/imx-regs.h>
 
-/* module has 8GB, 2GB from 0x80000000..0xffffffff, 6GB above */
+/* module has 8GB, 2GB from 0x80000000..0xffffffff, 6GB above.
+ * Actual size is determined at runtime.
+ */
 #define SZ_6G  _AC(0x180000000, ULL)
 
-/* first 256MB reserved for firmware */
-#define CFG_SYS_INIT_RAM_ADDR  0x90000000
+/* The first 256MB of SDRAM is reserved for firmware (Cortex M7) */
+#define PHYS_SDRAM_FW_RSVD     SZ_256M
+#define CFG_SYS_INIT_RAM_ADDR  PHYS_SDRAM
 #define CFG_SYS_INIT_RAM_SIZE  SZ_2M
 
-#define CFG_SYS_SDRAM_BASE     0x90000000
-#define PHYS_SDRAM             0x90000000
-#define PHYS_SDRAM_SIZE                (SZ_2G - SZ_256M)
+#define CFG_SYS_SDRAM_BASE     PHYS_SDRAM
+#define PHYS_SDRAM             (0x80000000 + PHYS_SDRAM_FW_RSVD)
+#define PHYS_SDRAM_SIZE                (SZ_2G - PHYS_SDRAM_FW_RSVD)
 #define PHYS_SDRAM_2_SIZE      SZ_6G
 
 #endif