[PATCH] Actions: S700 Calculate SDRAM size

Amit Singh Tomar amittomer25 at gmail.com
Sat May 2 15:25:20 CEST 2020


Calculate the SDRAM size from DDR capacity register registers instead of using
hard-coded value. This is quite useful to get correct size on differnt boards
based on S700 SoC.

There is no documentation available that talks about DDR registers, and this
is very much taken from vendor source.

This commit lets Linux boot on Cubieboard7-lite (based on S700).

Signed-off-by: Amit Singh Tomar <amittomer25 at gmail.com>
---
There is bit of a story about it:
 
Wasn't really aware that working on a board (CubieBoard7-Lite) that actually
has only 1GB of RAM untill I see the Kernel crash[1], and DDR size is
hard-coded to 2GB(as CubieBoard7 comes with 2 GB). With this set-up Kernel
was trying to access the memory that doesn't exist leads to the crash.

[1]:
 
Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
[    0.000000] Linux version 5.6.0-rc6-00012-g7080a8a-dirty (amit at amit-ThinkPad-X230) (gcc version 7.3.1 20180425 [linaro-7.3-2018.05 revision d29120a424ecfbc167ef90065c0eeb7f91977701] (Linaro GCC 7.3-2018.05)) #10 SMP PREEMPT Fri Mar 27 21:52:07 IST 2020
[    0.000000] Machine model: CubieBoard7
[    0.000000] earlycon: owl0 at MMIO 0x00000000e0126000 (options '')
[    0.000000] printk: bootconsole [owl0] enabled
[    0.000000] efi: Getting EFI parameters from FDT:
[    0.000000] efi: UEFI not found.
[    0.000000] cma: Reserved 32 MiB at 0x000000007e000000
[    0.000000] NUMA: No NUMA configuration found
[    0.000000] NUMA: Faking a node at [mem 0x0000000000000000-0x000000007fffffff]
[    0.000000] NUMA: NODE_DATA [mem 0x7dbfb100-0x7dbfcfff]
[    0.000000] Zone ranges:
[    0.000000]   DMA      [mem 0x0000000000000000-0x000000003fffffff]
[    0.000000]   DMA32    [mem 0x0000000040000000-0x000000007fffffff]
[    0.000000]   Normal   empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x000000001effffff]
[    0.000000]   node   0: [mem 0x0000000020000000-0x000000007fffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x000000007fffffff]
[    0.000000] psci: probing for conduit method from DT.
[    0.000000] psci: PSCIv0.2 detected in firmware.
[    0.000000] psci: Using standard PSCI v0.2 function IDs
[    0.000000] psci: Trusted OS migration not required
[    0.000000] percpu: Embedded 23 pages/cpu s53272 r8192 d32744 u94208
[    0.000000] Detected VIPT I-cache on CPU0
[    0.000000] CPU features: detected: ARM erratum 845719
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 512000
[    0.000000] Policy zone: DMA32
[    0.000000] Kernel command line: console=ttyOWL,115200 earlycon=owl,0xe0126000 root=/dev/mmcblk0p2
[    0.000000] Dentry cache hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[    0.000000] Inode-cache hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Unable to handle kernel paging request at virtual address ffff00003de18000
[    0.000000] Mem abort info:
[    0.000000]   ESR = 0x96000047
[    0.000000]   EC = 0x25: DABT (current EL), IL = 32 bits
[    0.000000]   SET = 0, FnV = 0
[    0.000000]   EA = 0, S1PTW = 0
[    0.000000] Data abort info:
[    0.000000]   ISV = 0, ISS = 0x00000047
[    0.000000]   CM = 0, WnR = 1
[    0.000000] swapper pgtable: 4k pages, 48-bit VAs, pgdp=0000000001399000
  
---
 arch/arm/mach-owl/soc.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/arch/arm/mach-owl/soc.c b/arch/arm/mach-owl/soc.c
index 409cbd3..f63f1a8 100644
--- a/arch/arm/mach-owl/soc.c
+++ b/arch/arm/mach-owl/soc.c
@@ -13,15 +13,38 @@
 #include <asm/mach-types.h>
 #include <asm/psci.h>
 
+#define DMM_INTERLEAVE_PER_CH_CFG       (0xe0290028)
+
 DECLARE_GLOBAL_DATA_PTR;
 
+unsigned int get_owl_ram_size(void)
+{
+	unsigned int val, cap;
+
+	/* ddr capacity register initialized by ddr driver
+	 * in early bootloader
+	 * DMM_INTERLEAVE_PER_CH_CFG  bit[10:8]
+	 * (val + 1) * 256
+	 */
+	val = (readl(DMM_INTERLEAVE_PER_CH_CFG) >> 8) & 0x7;
+	cap =  (val + 1) * 256;
+
+	return cap;
+}
+
 /*
  * dram_init - sets uboots idea of sdram size
  */
 int dram_init(void)
 {
 	gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
+
+#if defined(CONFIG_MACH_S700)
+	gd->ram_size = get_owl_ram_size() * 1024 * 1024;
+#endif
+
 	return 0;
+
 }
 
 /* This is called after dram_init() so use get_ram_size result */
-- 
2.7.4



More information about the U-Boot mailing list