All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] Use device tree to get DRAM for sama5d27_som1_ek/sama5d2_xplained
@ 2021-08-02 12:39 Clément Léger
  2021-08-02 12:39 ` [PATCH 1/5] board: sama5d27_som1_ek: Get dram size and base from device tree Clément Léger
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Clément Léger @ 2021-08-02 12:39 UTC (permalink / raw)
  To: u-boot, Eugen Hristev; +Cc: Clément Léger, Wenyou Yang, Nicolas Ferre

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(-)

-- 
2.32.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/5] board: sama5d27_som1_ek: Get dram size and base from device tree
  2021-08-02 12:39 [PATCH 0/5] Use device tree to get DRAM for sama5d27_som1_ek/sama5d2_xplained Clément Léger
@ 2021-08-02 12:39 ` Clément Léger
  2021-08-02 12:39 ` [PATCH 2/5] board: sama5d27_som1_ek: Modify load addresses Clément Léger
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Clément Léger @ 2021-08-02 12:39 UTC (permalink / raw)
  To: u-boot, Eugen Hristev; +Cc: Clément Léger, Wenyou Yang, Nicolas Ferre

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.

Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
 board/atmel/sama5d27_som1_ek/sama5d27_som1_ek.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/board/atmel/sama5d27_som1_ek/sama5d27_som1_ek.c b/board/atmel/sama5d27_som1_ek/sama5d27_som1_ek.c
index 1b7d946b50..8c0cf3da54 100644
--- a/board/atmel/sama5d27_som1_ek/sama5d27_som1_ek.c
+++ b/board/atmel/sama5d27_som1_ek/sama5d27_som1_ek.c
@@ -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
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/5] board: sama5d27_som1_ek: Modify load addresses
  2021-08-02 12:39 [PATCH 0/5] Use device tree to get DRAM for sama5d27_som1_ek/sama5d2_xplained Clément Léger
  2021-08-02 12:39 ` [PATCH 1/5] board: sama5d27_som1_ek: Get dram size and base from device tree Clément Léger
@ 2021-08-02 12:39 ` Clément Léger
  2021-08-02 12:39 ` [PATCH 3/5] ARM: dts: at91: sama5d2: Add memory node in devicetree Clément Léger
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Clément Léger @ 2021-08-02 12:39 UTC (permalink / raw)
  To: u-boot, Eugen Hristev; +Cc: Clément Léger, Wenyou Yang, Nicolas Ferre

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.

Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
 include/configs/sama5d27_som1_ek.h | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/include/configs/sama5d27_som1_ek.h b/include/configs/sama5d27_som1_ek.h
index 8942d15934..2e937c8309 100644
--- a/include/configs/sama5d27_som1_ek.h
+++ b/include/configs/sama5d27_som1_ek.h
@@ -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 */
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/5] ARM: dts: at91: sama5d2: Add memory node in devicetree
  2021-08-02 12:39 [PATCH 0/5] Use device tree to get DRAM for sama5d27_som1_ek/sama5d2_xplained Clément Léger
  2021-08-02 12:39 ` [PATCH 1/5] board: sama5d27_som1_ek: Get dram size and base from device tree Clément Léger
  2021-08-02 12:39 ` [PATCH 2/5] board: sama5d27_som1_ek: Modify load addresses Clément Léger
@ 2021-08-02 12:39 ` Clément Léger
  2021-08-03  8:58   ` Eugen.Hristev
  2021-08-02 12:39 ` [PATCH 4/5] board: sama5d2_xplained: Get dram size and base from device tree Clément Léger
  2021-08-02 12:39 ` [PATCH 5/5] board: sama5d2_xplained: Modify load addresses Clément Léger
  4 siblings, 1 reply; 8+ messages in thread
From: Clément Léger @ 2021-08-02 12:39 UTC (permalink / raw)
  To: u-boot, Eugen Hristev; +Cc: Clément Léger, Wenyou Yang, Nicolas Ferre

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.

Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
 arch/arm/dts/sama5d2.dtsi | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/dts/sama5d2.dtsi b/arch/arm/dts/sama5d2.dtsi
index 6fb2cb25f9..299aefc496 100644
--- a/arch/arm/dts/sama5d2.dtsi
+++ b/arch/arm/dts/sama5d2.dtsi
@@ -4,6 +4,10 @@
 	model = "Atmel SAMA5D2 family SoC";
 	compatible = "atmel,sama5d2";
 
+	memory {
+		reg = <0x20000000 0x20000000>;
+	};
+
 	aliases {
 		spi0 = &spi0;
 		spi1 = &qspi0;
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/5] board: sama5d2_xplained: Get dram size and base from device tree
  2021-08-02 12:39 [PATCH 0/5] Use device tree to get DRAM for sama5d27_som1_ek/sama5d2_xplained Clément Léger
                   ` (2 preceding siblings ...)
  2021-08-02 12:39 ` [PATCH 3/5] ARM: dts: at91: sama5d2: Add memory node in devicetree Clément Léger
@ 2021-08-02 12:39 ` Clément Léger
  2021-08-02 12:39 ` [PATCH 5/5] board: sama5d2_xplained: Modify load addresses Clément Léger
  4 siblings, 0 replies; 8+ messages in thread
From: Clément Léger @ 2021-08-02 12:39 UTC (permalink / raw)
  To: u-boot, Eugen Hristev; +Cc: Clément Léger, Wenyou Yang, Nicolas Ferre

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.

Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
 board/atmel/sama5d2_xplained/sama5d2_xplained.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/board/atmel/sama5d2_xplained/sama5d2_xplained.c b/board/atmel/sama5d2_xplained/sama5d2_xplained.c
index 5110ec8969..8b5cd533d0 100644
--- a/board/atmel/sama5d2_xplained/sama5d2_xplained.c
+++ b/board/atmel/sama5d2_xplained/sama5d2_xplained.c
@@ -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
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/5] board: sama5d2_xplained: Modify load addresses
  2021-08-02 12:39 [PATCH 0/5] Use device tree to get DRAM for sama5d27_som1_ek/sama5d2_xplained Clément Léger
                   ` (3 preceding siblings ...)
  2021-08-02 12:39 ` [PATCH 4/5] board: sama5d2_xplained: Get dram size and base from device tree Clément Léger
@ 2021-08-02 12:39 ` Clément Léger
  4 siblings, 0 replies; 8+ messages in thread
From: Clément Léger @ 2021-08-02 12:39 UTC (permalink / raw)
  To: u-boot, Eugen Hristev; +Cc: Clément Léger, Wenyou Yang, Nicolas Ferre

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.

Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
 include/configs/sama5d2_xplained.h | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/include/configs/sama5d2_xplained.h b/include/configs/sama5d2_xplained.h
index 4f5ceca780..d00017353a 100644
--- a/include/configs/sama5d2_xplained.h
+++ b/include/configs/sama5d2_xplained.h
@@ -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
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/5] ARM: dts: at91: sama5d2: Add memory node in devicetree
  2021-08-02 12:39 ` [PATCH 3/5] ARM: dts: at91: sama5d2: Add memory node in devicetree Clément Léger
@ 2021-08-03  8:58   ` Eugen.Hristev
  2021-08-03  9:05     ` Clément Léger
  0 siblings, 1 reply; 8+ messages in thread
From: Eugen.Hristev @ 2021-08-03  8:58 UTC (permalink / raw)
  To: clement.leger, u-boot; +Cc: wenyou.yang, Nicolas.Ferre

On 8/2/21 3:39 PM, Clément Léger wrote:
> 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.
> 
> Signed-off-by: Clément Léger <clement.leger@bootlin.com>
> ---
>   arch/arm/dts/sama5d2.dtsi | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/arch/arm/dts/sama5d2.dtsi b/arch/arm/dts/sama5d2.dtsi
> index 6fb2cb25f9..299aefc496 100644
> --- a/arch/arm/dts/sama5d2.dtsi
> +++ b/arch/arm/dts/sama5d2.dtsi
> @@ -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

> +
>          aliases {
>                  spi0 = &spi0;
>                  spi1 = &qspi0;
> --
> 2.32.0
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/5] ARM: dts: at91: sama5d2: Add memory node in devicetree
  2021-08-03  8:58   ` Eugen.Hristev
@ 2021-08-03  9:05     ` Clément Léger
  0 siblings, 0 replies; 8+ messages in thread
From: Clément Léger @ 2021-08-03  9:05 UTC (permalink / raw)
  To: Eugen.Hristev; +Cc: u-boot, wenyou.yang, Nicolas.Ferre

Le Tue, 3 Aug 2021 08:58:17 +0000,
<Eugen.Hristev@microchip.com> a écrit :

> On 8/2/21 3:39 PM, Clément Léger wrote:
> > 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.
> > 
> > Signed-off-by: Clément Léger <clement.leger@bootlin.com>
> > ---
> >   arch/arm/dts/sama5d2.dtsi | 4 ++++
> >   1 file changed, 4 insertions(+)
> > 
> > diff --git a/arch/arm/dts/sama5d2.dtsi b/arch/arm/dts/sama5d2.dtsi
> > index 6fb2cb25f9..299aefc496 100644
> > --- a/arch/arm/dts/sama5d2.dtsi
> > +++ b/arch/arm/dts/sama5d2.dtsi
> > @@ -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.

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

> 
> 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
> 
> > +
> >          aliases {
> >                  spi0 = &spi0;
> >                  spi1 = &qspi0;
> > --
> > 2.32.0
> >   
> 



-- 
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-08-03  9:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-02 12:39 [PATCH 0/5] Use device tree to get DRAM for sama5d27_som1_ek/sama5d2_xplained Clément Léger
2021-08-02 12:39 ` [PATCH 1/5] board: sama5d27_som1_ek: Get dram size and base from device tree Clément Léger
2021-08-02 12:39 ` [PATCH 2/5] board: sama5d27_som1_ek: Modify load addresses Clément Léger
2021-08-02 12:39 ` [PATCH 3/5] ARM: dts: at91: sama5d2: Add memory node in devicetree Clément Léger
2021-08-03  8:58   ` Eugen.Hristev
2021-08-03  9:05     ` Clément Léger
2021-08-02 12:39 ` [PATCH 4/5] board: sama5d2_xplained: Get dram size and base from device tree Clément Léger
2021-08-02 12:39 ` [PATCH 5/5] board: sama5d2_xplained: Modify load addresses Clément Léger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.