Skip to contentSkip to conversation

Use device tree to get DRAM for sama5d27_som1_ek/sama5d2_xplained

PATCH Superseded Clément Léger 2 participants 8 messages Aug 2, 2021 – Aug 3, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Use device tree to get DRAM for sama5d27_som1_ek/sama5d2_xplained

Loading U-Boot after OP-TEE requires to move the base address of the DRAM and reduce its size. Indeed, OP-TEE will be loaded at start of DRAM for these platforms and this DRAM will be secured and thus not accessible to U-Boot.

Currently, addresses are hardcoded in board configs. This series adds memory property when missing to existing device tree and modify init code to fetch DRAM size from devicetree. This will allow to modify only the device tree to reduce DRAM when needed.

Memory addresses have been chosen to have a 32Mb hole at the start of DRAM which allows to put OP-TEE and necessary exchange memory zones.

Clément Léger (5):
board: sama5d27_som1_ek: Get dram size and base from device tree
board: sama5d27_som1_ek: Modify load addresses
ARM: dts: at91: sama5d2: Add memory node in devicetree
board: sama5d2_xplained: Get dram size and base from device tree
board: sama5d2_xplained: Modify load addresses

 arch/arm/dts/sama5d2.dtsi                     |  4 ++++
 .../atmel/sama5d27_som1_ek/sama5d27_som1_ek.c | 12 ++++++----
 .../atmel/sama5d2_xplained/sama5d2_xplained.c | 11 +++++----
 include/configs/sama5d27_som1_ek.h            | 12 ++++------
 include/configs/sama5d2_xplained.h            | 24 ++++++++-----------
 5 files changed, 33 insertions(+), 30 deletions(-)
Signature · 1 line
2.32.0
#1 lore raw

PATCH 1/5 board: sama5d27_som1_ek: Get dram size and base from device tree

In order to make it more flexible and allow modifying the base address of DRAM without recompiling U-Boot, use memory node from device tree with fdtdec functions.

---
 board/atmel/sama5d27_som1_ek/sama5d27_som1_ek.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
board/atmel/sama5d27_som1_ek/sama5d27_som1_ek.c +8 -4
index 1b7d946b50..8c0cf3da54 100644
@@ -6,6 +6,7 @@
 
 #include <common.h>
 #include <debug_uart.h>
+#include <fdtdec.h>
 #include <init.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
@@ -68,7 +69,7 @@ int board_early_init_f(void)
 int board_init(void)
 {
 	/* address of boot parameters */
-	gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
+	gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100;
 
 #ifdef CONFIG_CMD_USB
 	board_usb_hw_init();
@@ -77,11 +78,14 @@ int board_init(void)
 	return 0;
 }
 
+int dram_init_banksize(void)
+{
+	return fdtdec_setup_memory_banksize();
+}
+
 int dram_init(void)
 {
-	gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
-				    CONFIG_SYS_SDRAM_SIZE);
-	return 0;
+	return fdtdec_setup_mem_size_base();
 }
 
 #define MAC24AA_MAC_OFFSET	0xfa
Signature · 1 line
2.32.0
#2 lore raw

PATCH 2/5 board: sama5d27_som1_ek: Modify load addresses

In reply to Clément Léger

When using OP-TEE, address range [0x20000000 - 0x22000000] is reserved. This modification allows to have a system which always work even when OP-TEE is present.

---
 include/configs/sama5d27_som1_ek.h | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
include/configs/sama5d27_som1_ek.h +4 -8
index 8942d15934..2e937c8309 100644
@@ -14,15 +14,11 @@
 #undef CONFIG_SYS_AT91_MAIN_CLOCK
 #define CONFIG_SYS_AT91_MAIN_CLOCK      24000000 /* from 24 MHz crystal */
 
-/* SDRAM */
-#define CONFIG_SYS_SDRAM_BASE		0x20000000
-#define CONFIG_SYS_SDRAM_SIZE		0x8000000
-
 #ifdef CONFIG_SPL_BUILD
 #define CONFIG_SYS_INIT_SP_ADDR		0x218000
 #else
 #define CONFIG_SYS_INIT_SP_ADDR \
-	(CONFIG_SYS_SDRAM_BASE + 16 * 1024 - GENERATED_GBL_DATA_SIZE)
+	(0x22000000 + 16 * 1024 - GENERATED_GBL_DATA_SIZE)
 #endif
 
 #define CONFIG_SYS_LOAD_ADDR		0x22000000 /* load address */
@@ -30,10 +26,10 @@
 #undef CONFIG_BOOTCOMMAND
 #ifdef CONFIG_SD_BOOT
 /* bootstrap + u-boot + env in sd card */
-#define CONFIG_BOOTCOMMAND	"fatload mmc " CONFIG_ENV_FAT_DEVICE_AND_PART " 0x21000000 " \
+#define CONFIG_BOOTCOMMAND	"fatload mmc " CONFIG_ENV_FAT_DEVICE_AND_PART " 0x22000000 " \
 				CONFIG_DEFAULT_DEVICE_TREE ".dtb; " \
-				"fatload mmc " CONFIG_ENV_FAT_DEVICE_AND_PART " 0x22000000 zImage; " \
-				"bootz 0x22000000 - 0x21000000"
+				"fatload mmc " CONFIG_ENV_FAT_DEVICE_AND_PART " 0x23000000 zImage; " \
+				"bootz 0x23000000 - 0x22000000"
 #endif
 
 /* SPL */
Signature · 1 line
2.32.0
#3 lore raw

PATCH 3/5 ARM: dts: at91: sama5d2: Add memory node in devicetree

In reply to Clément Léger

sama5d2 support from DRAM will be modified to use device tree instead of hardcoded addresses. In order to prepare that, add the memory node to sama5d2.dtsi file since the boards supported by U-Boot with sama5d2 all contains 512Mb of DDR.

---
 arch/arm/dts/sama5d2.dtsi | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/dts/sama5d2.dtsi +4 -0
index 6fb2cb25f9..299aefc496 100644
@@ -4,6 +4,10 @@
 	model = "Atmel SAMA5D2 family SoC";
 	compatible = "atmel,sama5d2";
 
+	memory {
+		reg = <0x20000000 0x20000000>;
+	};
+
 	aliases {
 		spi0 = &spi0;
 		spi1 = &qspi0;
Signature · 1 line
2.32.0
#4 lore raw

Re: [PATCH 3/5] ARM: dts: at91: sama5d2: Add memory node in devicetree

Quoted 15 lines · Clément Léger

sama5d2 support from DRAM will be modified to use device tree instead of hardcoded addresses. In order to prepare that, add the memory node to sama5d2.dtsi file since the boards supported by U-Boot with sama5d2 all contains 512Mb of DDR.

---
  arch/arm/dts/sama5d2.dtsi | 4 ++++
  1 file changed, 4 insertions(+)
arch/arm/dts/sama5d2.dtsi +0 -0
index 6fb2cb25f9..299aefc496 100644

arch/arm/dts/sama5d2.dtsi line 9

Quoted 6 lines
arch/arm/dts/sama5d2.dtsi +3 -0
@@ -4,6 +4,10 @@
         model = "Atmel SAMA5D2 family SoC";
         compatible = "atmel,sama5d2";
 
+       memory {
+               reg = <0x20000000 0x20000000>;
+       };

Hi,

Memory is external to the SoC. You have to move this node to the board specific DTS.

Even if all current boards have 512 MB of DRAM , this does not belong here.

And by the way this is not true, since this SoC can work in a SiP with only 256 or 128 MB of DRAM for example and this is true for certain boards ( wlsom1_ek comes to my mind now).

Eugen

Quoted 7 lines
arch/arm/dts/sama5d2.dtsi +1 -1
+
         aliases {
                 spi0 = &spi0;
                 spi1 = &qspi0;
--

2.32.0

#5 lore raw

Re: [PATCH 3/5] ARM: dts: at91: sama5d2: Add memory node in devicetree

Quoted 19 lines · Le Tue, 3 Aug 2021 08:58:17 +0000, <[email protected]> a écrit :
Quoted 18 lines · Clément Léger

sama5d2 support from DRAM will be modified to use device tree instead of hardcoded addresses. In order to prepare that, add the memory node to sama5d2.dtsi file since the boards supported by U-Boot with sama5d2 all contains 512Mb of DDR.

---
  arch/arm/dts/sama5d2.dtsi | 4 ++++
  1 file changed, 4 insertions(+)
arch/arm/dts/sama5d2.dtsi +0 -0
index 6fb2cb25f9..299aefc496 100644
@@ -4,6 +4,10 @@
         model = "Atmel SAMA5D2 family SoC";
         compatible = "atmel,sama5d2";
 
Quoted 8 lines

arch/arm/dts/sama5d2.dtsi line 9

Quoted 3 lines
arch/arm/dts/sama5d2.dtsi +3 -0
+       memory {
+               reg = <0x20000000 0x20000000>;
+       };  

Hi,

Memory is external to the SoC. You have to move this node to the board specific DTS.

Ok, I'll move this to sama5d2_xplained only since this series has been made and tested on sama5d2_xplained/sama5d27_som1_ek.

Clément

Quoted 18 lines

Even if all current boards have 512 MB of DRAM , this does not belong here.

And by the way this is not true, since this SoC can work in a SiP with only 256 or 128 MB of DRAM for example and this is true for certain boards ( wlsom1_ek comes to my mind now).

Eugen

Quoted 7 lines
arch/arm/dts/sama5d2.dtsi +1 -1
+
         aliases {
                 spi0 = &spi0;
                 spi1 = &qspi0;
--

2.32.0

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#6 lore raw

PATCH 4/5 board: sama5d2_xplained: Get dram size and base from device tree

In reply to Clément Léger

In order to make it more flexible and allow modifying the base address of DRAM without recompiling U-Boot, use memory node from device tree with fdtdec functions.

---
 board/atmel/sama5d2_xplained/sama5d2_xplained.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
board/atmel/sama5d2_xplained/sama5d2_xplained.c +7 -4
index 5110ec8969..8b5cd533d0 100644
@@ -68,7 +68,7 @@ int board_early_init_f(void)
 int board_init(void)
 {
 	/* address of boot parameters */
-	gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
+	gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100;
 
 #ifdef CONFIG_CMD_USB
 	board_usb_hw_init();
@@ -77,11 +77,14 @@ int board_init(void)
 	return 0;
 }
 
+int dram_init_banksize(void)
+{
+	return fdtdec_setup_memory_banksize();
+}
+
 int dram_init(void)
 {
-	gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
-				    CONFIG_SYS_SDRAM_SIZE);
-	return 0;
+	return fdtdec_setup_mem_size_base();
 }
 
 #define AT24MAC_MAC_OFFSET	0x9a
Signature · 1 line
2.32.0
#7 lore raw

PATCH 5/5 board: sama5d2_xplained: Modify load addresses

In reply to Clément Léger

When using OP-TEE, address range [0x20000000 - 0x22000000] is reserved. This modification allows to have a system which always work even when OP-TEE is present.

---
 include/configs/sama5d2_xplained.h | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)
include/configs/sama5d2_xplained.h +10 -14
index 4f5ceca780..d00017353a 100644
@@ -11,15 +11,11 @@
 
 #include "at91-sama5_common.h"
 
-/* SDRAM */
-#define CONFIG_SYS_SDRAM_BASE           0x20000000
-#define CONFIG_SYS_SDRAM_SIZE		0x20000000
-
 #ifdef CONFIG_SPL_BUILD
 #define CONFIG_SYS_INIT_SP_ADDR		0x218000
 #else
 #define CONFIG_SYS_INIT_SP_ADDR \
-	(CONFIG_SYS_SDRAM_BASE + 16 * 1024 - GENERATED_GBL_DATA_SIZE)
+	(0x22000000 + 16 * 1024 - GENERATED_GBL_DATA_SIZE)
 #endif
 
 #define CONFIG_SYS_LOAD_ADDR		0x22000000 /* load address */
@@ -31,18 +27,18 @@
 /* bootstrap + u-boot + env in sd card */
 #undef CONFIG_BOOTCOMMAND
 
-#define CONFIG_BOOTCOMMAND	"fatload mmc " CONFIG_ENV_FAT_DEVICE_AND_PART " 0x21000000 at91-sama5d2_xplained.dtb; " \
-				"fatload mmc " CONFIG_ENV_FAT_DEVICE_AND_PART " 0x22000000 zImage; " \
-				"bootz 0x22000000 - 0x21000000"
+#define CONFIG_BOOTCOMMAND	"fatload mmc " CONFIG_ENV_FAT_DEVICE_AND_PART " 0x22000000 at91-sama5d2_xplained.dtb; " \
+				"fatload mmc " CONFIG_ENV_FAT_DEVICE_AND_PART " 0x23000000 zImage; " \
+				"bootz 0x23000000 - 0x22000000"
 
 #elif CONFIG_SPI_BOOT
 
 /* bootstrap + u-boot + env in sd card, but kernel + dtb in eMMC */
 #undef CONFIG_BOOTCOMMAND
 
-#define CONFIG_BOOTCOMMAND	"ext4load mmc 0:1 0x21000000 /boot/at91-sama5d2_xplained.dtb; " \
-				"ext4load mmc 0:1 0x22000000 /boot/zImage; " \
-				"bootz 0x22000000 - 0x21000000"
+#define CONFIG_BOOTCOMMAND	"ext4load mmc 0:1 0x22000000 /boot/at91-sama5d2_xplained.dtb; " \
+				"ext4load mmc 0:1 0x23000000 /boot/zImage; " \
+				"bootz 0x23000000 - 0x22000000"
 
 #endif
 
@@ -51,9 +47,9 @@
 #undef CONFIG_BOOTCOMMAND
 #define CONFIG_ENV_SPI_BUS	1
 #define CONFIG_BOOTCOMMAND	"sf probe 1:0; "			\
-				"sf read 0x21000000 0x180000 0x80000; "	\
-				"sf read 0x22000000 0x200000 0x600000; "\
-				"bootz 0x22000000 - 0x21000000"
+				"sf read 0x22000000 0x180000 0x80000; "	\
+				"sf read 0x23000000 0x200000 0x600000; "\
+				"bootz 0x23000000 - 0x22000000"
 
 #endif
 
Signature · 1 line
2.32.0