u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] fsl-layerscape: add dtb overlay feature
@ 2021-11-17  6:23 Sahil Malhotra
  2021-11-17  6:23 ` [PATCH 2/2] configs: enabled DTB overlay feature for LS SoCs Sahil Malhotra
  2021-11-17  7:53 ` [PATCH 1/2] fsl-layerscape: add dtb overlay feature Michael Walle
  0 siblings, 2 replies; 26+ messages in thread
From: Sahil Malhotra @ 2021-11-17  6:23 UTC (permalink / raw)
  To: u-boot, v.sethi, priyanka.jain, ye.li, clement.faure,
	gaurav.jain, pankaj.gupta
  Cc: Sahil Malhotra

From: Sahil Malhotra <sahil.malhotra@nxp.com>

This patch enables the DTB overlay feature for LS platforms.

Signed-off-by: Sahil Malhotra <sahil.malhotra@nxp.com>
---
 arch/arm/cpu/armv8/fsl-layerscape/Makefile    |  1 +
 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c  | 39 +++++++++++++++++++
 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h  | 10 +++++
 arch/arm/cpu/armv8/fsl-layerscape/fdt.c       | 12 ++++++
 .../cpu/armv8/fsl-layerscape/lowlevel_init.S  | 25 ++++++++++++
 5 files changed, 87 insertions(+)
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Makefile b/arch/arm/cpu/armv8/fsl-layerscape/Makefile
index 598c36ee66..97f1f291dd 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Makefile
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Makefile
@@ -7,6 +7,7 @@ obj-y += lowlevel.o
 obj-y += soc.o
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_MP) += mp.o spintable.o
+obj-$(CONFIG_OF_LIBFDT_OVERLAY) += lowlevel_init.o dt_optee.o
 obj-$(CONFIG_OF_LIBFDT) += fdt.o
 endif
 obj-$(CONFIG_SPL) += spl.o
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
new file mode 100644
index 0000000000..2418ad09c7
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2021 NXP
+ */
+#include <common.h>
+#include <errno.h>
+#include <fdt_support.h>
+#include <linux/sizes.h>
+#include "dt_optee.h"
+
+int ft_add_optee_overlay(void *fdt, struct bd_info *bd)
+{
+	int ret = 0;
+
+	/*
+	 * No BL32_BASE passed means no TEE running, so no
+	 * need to add optee node in dts
+	 */
+	if (!rom_pointer[0]) {
+		debug("No BL32_BASE passed means no TEE running\n");
+		return ret;
+	}
+
+	if (rom_pointer[2]) {
+		debug("OP-TEE: applying overlay on 0x%lx\n", rom_pointer[2]);
+		ret = fdt_check_header((void *)rom_pointer[2]);
+		if (ret == 0) {
+			/* Copy the fdt overlay to next 1M and use copied overlay */
+			memcpy((void *)(rom_pointer[2] + SZ_1M), (void *)rom_pointer[2],
+			       fdt_totalsize((void *)rom_pointer[2]));
+			ret = fdt_overlay_apply_verbose(fdt, (void *)(rom_pointer[2] + SZ_1M));
+			if (ret == 0) {
+				debug("Overlay applied with success");
+				fdt_pack(fdt);
+			}
+		}
+	}
+	return ret;
+}
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
new file mode 100644
index 0000000000..d1ff25d531
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2021 NXP
+ */
+#ifndef __DT_OPTEE_H__
+#define __DT_OPTEE_H__
+
+extern unsigned long rom_pointer[];
+int ft_add_optee_overlay(void *fdt, struct bd_info *bd);
+#endif
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
index f1624ff30a..0824c62264 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
@@ -31,6 +31,7 @@
 #endif
 #include <asm/arch/speed.h>
 #include <fsl_qbman.h>
+#include "dt_optee.h"
 
 int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
 {
@@ -698,3 +699,14 @@ void ft_cpu_setup(void *blob, struct bd_info *bd)
 	fdt_fixup_ecam(blob);
 #endif
 }
+
+#ifdef CONFIG_OF_SYSTEM_SETUP
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+#ifdef CONFIG_OF_LIBFDT_OVERLAY
+	return ft_add_optee_overlay(blob, bd);
+#else
+	return 0;
+#endif
+}
+#endif
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S
new file mode 100644
index 0000000000..1d6a2d85fa
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2021 NXP
+ */
+
+#include <config.h>
+
+.align 8
+.global rom_pointer
+rom_pointer:
+	.space 32
+
+/*
+ * Routine: save_boot_params (called after reset from start.S)
+ */
+
+.global save_boot_params
+save_boot_params:
+	/* The firmware provided FDT address can be found in r2/x0 */
+	adr	x0, rom_pointer
+	stp	x1, x2, [x0], #16
+	stp	x3, x4, [x0], #16
+
+	ldr	x1, =save_boot_params_ret
+	br	x1
-- 
2.17.1


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

* [PATCH 2/2] configs: enabled DTB overlay feature for LS SoCs
  2021-11-17  6:23 [PATCH 1/2] fsl-layerscape: add dtb overlay feature Sahil Malhotra
@ 2021-11-17  6:23 ` Sahil Malhotra
  2021-11-17  7:53 ` [PATCH 1/2] fsl-layerscape: add dtb overlay feature Michael Walle
  1 sibling, 0 replies; 26+ messages in thread
From: Sahil Malhotra @ 2021-11-17  6:23 UTC (permalink / raw)
  To: u-boot, v.sethi, priyanka.jain, ye.li, clement.faure,
	gaurav.jain, pankaj.gupta
  Cc: Sahil Malhotra

From: Sahil Malhotra <sahil.malhotra@nxp.com>

SoCs enabled for DTB Overlay features are:
LS1046A-RDB
LS1043A-RDB
LS1012A-RDB
LS1028A-RDB
LS1088A-RDB
LS2088A-RDB

Signed-off-by: Sahil Malhotra <sahil.malhotra@nxp.com>
---
 configs/ls1012ardb_tfa_defconfig | 2 ++
 configs/ls1028ardb_tfa_defconfig | 1 +
 configs/ls1043ardb_tfa_defconfig | 2 ++
 configs/ls1046ardb_tfa_defconfig | 2 ++
 configs/ls1088ardb_tfa_defconfig | 2 ++
 configs/ls2088ardb_tfa_defconfig | 2 ++
 6 files changed, 11 insertions(+)

diff --git a/configs/ls1012ardb_tfa_defconfig b/configs/ls1012ardb_tfa_defconfig
index c52359e51d..49ee762e38 100644
--- a/configs/ls1012ardb_tfa_defconfig
+++ b/configs/ls1012ardb_tfa_defconfig
@@ -69,3 +69,5 @@ CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
+CONFIG_OF_LIBFDT_OVERLAY=y
+CONFIG_OF_SYSTEM_SETUP=y
diff --git a/configs/ls1028ardb_tfa_defconfig b/configs/ls1028ardb_tfa_defconfig
index 8ce9da5b4f..b360427eb3 100644
--- a/configs/ls1028ardb_tfa_defconfig
+++ b/configs/ls1028ardb_tfa_defconfig
@@ -95,3 +95,4 @@ CONFIG_OF_LIBFDT_OVERLAY=y
 CONFIG_EFI_LOADER_BOUNCE_BUFFER=y
 CONFIG_VIDEO=y
 CONFIG_VIDEO_LS_HDP_LOAD=y
+CONFIG_OF_SYSTEM_SETUP=y
diff --git a/configs/ls1043ardb_tfa_defconfig b/configs/ls1043ardb_tfa_defconfig
index de3db3e2c4..a64df243f9 100644
--- a/configs/ls1043ardb_tfa_defconfig
+++ b/configs/ls1043ardb_tfa_defconfig
@@ -67,3 +67,5 @@ CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_EFI_LOADER_BOUNCE_BUFFER=y
+CONFIG_OF_LIBFDT_OVERLAY=y
+CONFIG_OF_SYSTEM_SETUP=y
diff --git a/configs/ls1046ardb_tfa_defconfig b/configs/ls1046ardb_tfa_defconfig
index e9e2efb210..55b6016e74 100644
--- a/configs/ls1046ardb_tfa_defconfig
+++ b/configs/ls1046ardb_tfa_defconfig
@@ -71,3 +71,5 @@ CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_EFI_LOADER_BOUNCE_BUFFER=y
+CONFIG_OF_LIBFDT_OVERLAY=y
+CONFIG_OF_SYSTEM_SETUP=y
diff --git a/configs/ls1088ardb_tfa_defconfig b/configs/ls1088ardb_tfa_defconfig
index 2e99e337c8..2351749d7d 100644
--- a/configs/ls1088ardb_tfa_defconfig
+++ b/configs/ls1088ardb_tfa_defconfig
@@ -94,3 +94,5 @@ CONFIG_USB_ETHER_ASIX=y
 CONFIG_USB_ETHER_ASIX88179=y
 CONFIG_USB_ETHER_RTL8152=y
 CONFIG_EFI_LOADER_BOUNCE_BUFFER=y
+CONFIG_OF_LIBFDT_OVERLAY=y
+CONFIG_OF_SYSTEM_SETUP=y
diff --git a/configs/ls2088ardb_tfa_defconfig b/configs/ls2088ardb_tfa_defconfig
index de57235284..d1b6e7f7ae 100644
--- a/configs/ls2088ardb_tfa_defconfig
+++ b/configs/ls2088ardb_tfa_defconfig
@@ -89,3 +89,5 @@ CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_EFI_LOADER_BOUNCE_BUFFER=y
+CONFIG_OF_LIBFDT_OVERLAY=y
+CONFIG_OF_SYSTEM_SETUP=y
-- 
2.17.1


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

* Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2021-11-17  6:23 [PATCH 1/2] fsl-layerscape: add dtb overlay feature Sahil Malhotra
  2021-11-17  6:23 ` [PATCH 2/2] configs: enabled DTB overlay feature for LS SoCs Sahil Malhotra
@ 2021-11-17  7:53 ` Michael Walle
  2021-11-17 18:11   ` Sahil Malhotra (OSS)
  1 sibling, 1 reply; 26+ messages in thread
From: Michael Walle @ 2021-11-17  7:53 UTC (permalink / raw)
  To: sahil.malhotra
  Cc: clement.faure, gaurav.jain, pankaj.gupta, priyanka.jain,
	sahil.malhotra, u-boot, v.sethi, ye.li, Michael Walle

> From: Sahil Malhotra <sahil.malhotra@nxp.com>
> 
> This patch enables the DTB overlay feature for LS platforms.

Could you please add some description what this is doing and for what
this is intended? To have a "DTB overlay feature", it is enough to just
enable CONFIG_OF_LIBFDT_OVERLAY.

Apparently you're adding an overlay passed by optee. Doesn't this have to
be applied to u-boot's control dtb too?

-michael

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

* RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2021-11-17  7:53 ` [PATCH 1/2] fsl-layerscape: add dtb overlay feature Michael Walle
@ 2021-11-17 18:11   ` Sahil Malhotra (OSS)
  2021-11-17 18:20     ` Michael Walle
  0 siblings, 1 reply; 26+ messages in thread
From: Sahil Malhotra (OSS) @ 2021-11-17 18:11 UTC (permalink / raw)
  To: Michael Walle, Sahil Malhotra (OSS)
  Cc: Clément Faure, Gaurav Jain, Pankaj Gupta, Priyanka Jain,
	u-boot, Varun Sethi, Ye Li

Hi Michael,

-----Original Message-----
From: Michael Walle <michael@walle.cc> 
Sent: Wednesday, November 17, 2021 1:23 PM
To: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
Cc: Clément Faure <clement.faure@nxp.com>; Gaurav Jain <gaurav.jain@nxp.com>; Pankaj Gupta <pankaj.gupta@nxp.com>; Priyanka Jain <priyanka.jain@nxp.com>; Sahil Malhotra <sahil.malhotra@nxp.com>; u-boot@lists.denx.de; Varun Sethi <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>; Michael Walle <michael@walle.cc>
Subject: Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature

> From: Sahil Malhotra <sahil.malhotra@nxp.com>
> 
> This patch enables the DTB overlay feature for LS platforms.

> Could you please add some description what this is doing and for what this is intended? To have a "DTB overlay feature", it is enough to just enable CONFIG_OF_LIBFDT_OVERLAY.
I will add some description, and yes for DTB overlay feature, it is enough to enable CONFIG_OF_LIBFDT_OVERLAY but we need to do this step before booting the kernel that's why also have to enable CONFIG_OF_SYSTEM_SETUP.

>Apparently you're adding an overlay passed by optee. Doesn't this have to be applied to u-boot's control dtb too?
Yes, we will be applying the overlay passed by optee, yes it will be applied to dtb which will be passed to uboot for kernel booting.

-michael

Regards,
Sahil Malhotra

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

* Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2021-11-17 18:11   ` Sahil Malhotra (OSS)
@ 2021-11-17 18:20     ` Michael Walle
  2021-11-29 11:55       ` Sahil Malhotra (OSS)
  0 siblings, 1 reply; 26+ messages in thread
From: Michael Walle @ 2021-11-17 18:20 UTC (permalink / raw)
  To: Sahil Malhotra (OSS)
  Cc: Clément Faure, Gaurav Jain, Pankaj Gupta, Priyanka Jain,
	u-boot, Varun Sethi, Ye Li, ZHIZHIKIN Andrey

Hi Sahil,

Am 2021-11-17 19:11, schrieb Sahil Malhotra (OSS):
>> Could you please add some description what this is doing and for what
>> this is intended? To have a "DTB overlay feature", it is enough to 
>> just
>> enable CONFIG_OF_LIBFDT_OVERLAY.
> I will add some description, and yes for DTB overlay feature, it is
> enough to enable CONFIG_OF_LIBFDT_OVERLAY but we need to do this step
> before booting the kernel that's why also have to enable
> CONFIG_OF_SYSTEM_SETUP.

Ok. What will the overlay do? Could you give an example?

>> Apparently you're adding an overlay passed by optee. Doesn't this
>> have to be applied to u-boot's control dtb too?
> Yes, we will be applying the overlay passed by optee, yes it will be
> applied to dtb which will be passed to uboot for kernel booting.

If I read this patch correctly, you're modifying the DT before you
jump to linux. But I was asking whether you also have to modify
the DT which is used by u-boot. Eg. if you disable some kind of
crypto nodes (because optee will use them in secure world), this
also have to communicated to u-boot, not only linux, no?

But until you've explained what this is about, this is only
guesswork.

-michael

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

* RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2021-11-17 18:20     ` Michael Walle
@ 2021-11-29 11:55       ` Sahil Malhotra (OSS)
  2021-11-29 17:47         ` Michael Walle
  0 siblings, 1 reply; 26+ messages in thread
From: Sahil Malhotra (OSS) @ 2021-11-29 11:55 UTC (permalink / raw)
  To: Michael Walle, Sahil Malhotra (OSS)
  Cc: Clément Faure, Gaurav Jain, Pankaj Gupta, Priyanka Jain,
	u-boot, Varun Sethi, Ye Li, ZHIZHIKIN Andrey

Hi Michael,


-----Original Message-----
From: Michael Walle <michael@walle.cc> 
Sent: Wednesday, November 17, 2021 11:51 PM
To: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
Cc: Clément Faure <clement.faure@nxp.com>; Gaurav Jain <gaurav.jain@nxp.com>; Pankaj Gupta <pankaj.gupta@nxp.com>; Priyanka Jain <priyanka.jain@nxp.com>; u-boot@lists.denx.de; Varun Sethi <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>; ZHIZHIKIN Andrey <andrey.zhizhikin@leica-geosystems.com>
Subject: Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature

Hi Sahil,

Am 2021-11-17 19:11, schrieb Sahil Malhotra (OSS):
>> Could you please add some description what this is doing and for what 
>> this is intended? To have a "DTB overlay feature", it is enough to 
>> just enable CONFIG_OF_LIBFDT_OVERLAY.
> I will add some description, and yes for DTB overlay feature, it is 
> enough to enable CONFIG_OF_LIBFDT_OVERLAY but we need to do this step 
> before booting the kernel that's why also have to enable 
> CONFIG_OF_SYSTEM_SETUP.

> Ok. What will the overlay do? Could you give an example?
This overlay will be disabling the crypto nodes which will be used by optee in secure world, so that linux should not use it.


>> Apparently you're adding an overlay passed by optee. Doesn't this 
>> have to be applied to u-boot's control dtb too?
> Yes, we will be applying the overlay passed by optee, yes it will be 
> applied to dtb which will be passed to uboot for kernel booting.

> If I read this patch correctly, you're modifying the DT before you jump to linux. But I was asking whether you also have to modify the DT which is used by u-boot. Eg. if you disable some kind of crypto nodes (because optee will use them in secure world), this also have to communicated to u-boot, not only linux, no?
Yes, I got your point now, and is very valid, but as of now for u-boot we are just using the first available node for communicating with CAAM leaving other job rings as it is. 
So we need not to apply overlay to DTB used by uboot.

Regards,
Sahil Malhotra

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

* Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2021-11-29 11:55       ` Sahil Malhotra (OSS)
@ 2021-11-29 17:47         ` Michael Walle
  2021-12-08  6:12           ` Sahil Malhotra (OSS)
  2021-12-10  7:38           ` François Ozog
  0 siblings, 2 replies; 26+ messages in thread
From: Michael Walle @ 2021-11-29 17:47 UTC (permalink / raw)
  To: Sahil Malhotra (OSS)
  Cc: Clément Faure, Gaurav Jain, Pankaj Gupta, Priyanka Jain,
	u-boot, Varun Sethi, Ye Li, ZHIZHIKIN Andrey

Hi Sahil,

Am 2021-11-29 12:55, schrieb Sahil Malhotra (OSS):
> Am 2021-11-17 19:11, schrieb Sahil Malhotra (OSS):
>>> Could you please add some description what this is doing and for what
>>> this is intended? To have a "DTB overlay feature", it is enough to
>>> just enable CONFIG_OF_LIBFDT_OVERLAY.
>> I will add some description, and yes for DTB overlay feature, it is
>> enough to enable CONFIG_OF_LIBFDT_OVERLAY but we need to do this step
>> before booting the kernel that's why also have to enable
>> CONFIG_OF_SYSTEM_SETUP.
> 
>> Ok. What will the overlay do? Could you give an example?
> This overlay will be disabling the crypto nodes which will be used by
> optee in secure world, so that linux should not use it.
> 
> 
>>> Apparently you're adding an overlay passed by optee. Doesn't this
>>> have to be applied to u-boot's control dtb too?
>> Yes, we will be applying the overlay passed by optee, yes it will be
>> applied to dtb which will be passed to uboot for kernel booting.
> 
>> If I read this patch correctly, you're modifying the DT before you 
>> jump to linux. But I was asking whether you also have to modify the DT 
>> which is used by u-boot. Eg. if you disable some kind of crypto nodes 
>> (because optee will use them in secure world), this also have to 
>> communicated to u-boot, not only linux, no?
> Yes, I got your point now, and is very valid, but as of now for u-boot
> we are just using the first available node for communicating with CAAM
> leaving other job rings as it is.
> So we need not to apply overlay to DTB used by uboot.

But we should do the correct thing, so that u-boot and linux
doesn't see a different version of the device tree.

Also what do you mean with "the first available node"?
There is already a new CAAM driver for u-boot pending,
see
https://lore.kernel.org/u-boot/20211115070014.17586-1-gaurav.jain@nxp.com/

-michael

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

* RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2021-11-29 17:47         ` Michael Walle
@ 2021-12-08  6:12           ` Sahil Malhotra (OSS)
  2021-12-08 10:13             ` ZHIZHIKIN Andrey
  2021-12-10  7:38           ` François Ozog
  1 sibling, 1 reply; 26+ messages in thread
From: Sahil Malhotra (OSS) @ 2021-12-08  6:12 UTC (permalink / raw)
  To: Michael Walle, Sahil Malhotra (OSS)
  Cc: Clément Faure, Gaurav Jain, Pankaj Gupta, Priyanka Jain,
	u-boot, Varun Sethi, Ye Li, ZHIZHIKIN Andrey

Hi Michael,

-----Original Message-----
From: Michael Walle <michael@walle.cc> 
Sent: Monday, November 29, 2021 11:17 PM
To: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
Cc: Clément Faure <clement.faure@nxp.com>; Gaurav Jain <gaurav.jain@nxp.com>; Pankaj Gupta <pankaj.gupta@nxp.com>; Priyanka Jain <priyanka.jain@nxp.com>; u-boot@lists.denx.de; Varun Sethi <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>; ZHIZHIKIN Andrey <andrey.zhizhikin@leica-geosystems.com>
Subject: Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature

Hi Sahil,

Am 2021-11-29 12:55, schrieb Sahil Malhotra (OSS):
> Am 2021-11-17 19:11, schrieb Sahil Malhotra (OSS):
>>> Could you please add some description what this is doing and for 
>>> what this is intended? To have a "DTB overlay feature", it is enough 
>>> to just enable CONFIG_OF_LIBFDT_OVERLAY.
>> I will add some description, and yes for DTB overlay feature, it is 
>> enough to enable CONFIG_OF_LIBFDT_OVERLAY but we need to do this step 
>> before booting the kernel that's why also have to enable 
>> CONFIG_OF_SYSTEM_SETUP.
> 
>> Ok. What will the overlay do? Could you give an example?
> This overlay will be disabling the crypto nodes which will be used by 
> optee in secure world, so that linux should not use it.
> 
> 
>>> Apparently you're adding an overlay passed by optee. Doesn't this 
>>> have to be applied to u-boot's control dtb too?
>> Yes, we will be applying the overlay passed by optee, yes it will be 
>> applied to dtb which will be passed to uboot for kernel booting.
> 
>> If I read this patch correctly, you're modifying the DT before you 
>> jump to linux. But I was asking whether you also have to modify the 
>> DT which is used by u-boot. Eg. if you disable some kind of crypto 
>> nodes (because optee will use them in secure world), this also have 
>> to communicated to u-boot, not only linux, no?
> Yes, I got your point now, and is very valid, but as of now for u-boot 
> we are just using the first available node for communicating with CAAM 
> leaving other job rings as it is.
> So we need not to apply overlay to DTB used by uboot.

> But we should do the correct thing, so that u-boot and linux doesn't see a different version of the device tree.

> Also what do you mean with "the first available node"?
> There is already a new CAAM driver for u-boot pending, see https://lore.kernel.org/u-boot/20211115070014.17586-1-gaurav.jain@nxp.com/

Very first CAAM Job Ring is always used by u-boot, OP-TEE does not use this job ring. Same job ring can be used by Linux once it boots up.

Regards,
Sahil Malhotra


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

* RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2021-12-08  6:12           ` Sahil Malhotra (OSS)
@ 2021-12-08 10:13             ` ZHIZHIKIN Andrey
  2021-12-10  6:33               ` Sahil Malhotra (OSS)
  0 siblings, 1 reply; 26+ messages in thread
From: ZHIZHIKIN Andrey @ 2021-12-08 10:13 UTC (permalink / raw)
  To: Sahil Malhotra (OSS), Michael Walle
  Cc: Clément Faure, Gaurav Jain, Pankaj Gupta, Priyanka Jain,
	u-boot, Varun Sethi, Ye Li

Hello Sahil,

> -----Original Message-----
> From: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
> Sent: Wednesday, December 8, 2021 7:12 AM
> To: Michael Walle <michael@walle.cc>; Sahil Malhotra (OSS)
> <sahil.malhotra@oss.nxp.com>
> Cc: Clément Faure <clement.faure@nxp.com>; Gaurav Jain <gaurav.jain@nxp.com>;
> Pankaj Gupta <pankaj.gupta@nxp.com>; Priyanka Jain <priyanka.jain@nxp.com>; u-
> boot@lists.denx.de; Varun Sethi <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>;
> ZHIZHIKIN Andrey <andrey.zhizhikin@leica-geosystems.com>
> Subject: RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
> 
> 
> Hi Michael,
> 
> -----Original Message-----
> From: Michael Walle <michael@walle.cc>
> Sent: Monday, November 29, 2021 11:17 PM
> To: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
> Cc: Clément Faure <clement.faure@nxp.com>; Gaurav Jain <gaurav.jain@nxp.com>;
> Pankaj Gupta <pankaj.gupta@nxp.com>; Priyanka Jain <priyanka.jain@nxp.com>; u-
> boot@lists.denx.de; Varun Sethi <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>;
> ZHIZHIKIN Andrey <andrey.zhizhikin@leica-geosystems.com>
> Subject: Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
> 
> Hi Sahil,
> 
> Am 2021-11-29 12:55, schrieb Sahil Malhotra (OSS):
> > Am 2021-11-17 19:11, schrieb Sahil Malhotra (OSS):
> >>> Could you please add some description what this is doing and for
> >>> what this is intended? To have a "DTB overlay feature", it is enough
> >>> to just enable CONFIG_OF_LIBFDT_OVERLAY.
> >> I will add some description, and yes for DTB overlay feature, it is
> >> enough to enable CONFIG_OF_LIBFDT_OVERLAY but we need to do this step
> >> before booting the kernel that's why also have to enable
> >> CONFIG_OF_SYSTEM_SETUP.
> >
> >> Ok. What will the overlay do? Could you give an example?
> > This overlay will be disabling the crypto nodes which will be used by
> > optee in secure world, so that linux should not use it.
> >
> >
> >>> Apparently you're adding an overlay passed by optee. Doesn't this
> >>> have to be applied to u-boot's control dtb too?
> >> Yes, we will be applying the overlay passed by optee, yes it will be
> >> applied to dtb which will be passed to uboot for kernel booting.
> >
> >> If I read this patch correctly, you're modifying the DT before you
> >> jump to linux. But I was asking whether you also have to modify the
> >> DT which is used by u-boot. Eg. if you disable some kind of crypto
> >> nodes (because optee will use them in secure world), this also have
> >> to communicated to u-boot, not only linux, no?
> > Yes, I got your point now, and is very valid, but as of now for u-boot
> > we are just using the first available node for communicating with CAAM
> > leaving other job rings as it is.
> > So we need not to apply overlay to DTB used by uboot.
> 
> > But we should do the correct thing, so that u-boot and linux doesn't see a
> different version of the device tree.
> 
> > Also what do you mean with "the first available node"?
> > There is already a new CAAM driver for u-boot pending, see https://lore.kernel.org/u-boot/20211115070014.17586-1-gaurav.jain@nxp.com/
> 
> Very first CAAM Job Ring is always used by u-boot, OP-TEE does not use this job
> ring. Same job ring can be used by Linux once it boots up.

Just for clarification: by saying "Very first CAAM Job Ring" do you
actually mean JR0?

If the BootROM logic with respect to JR reservation for LS family does
not differ from i.MX8M family (which I assume does not), then why can't
the logic be implemented in the same way proposed by Gaurav [1] here as
well?

DT nodes can be statically disabled if we know that they are held by HAB
and are not released to NS World.

OP-TEE does set the status itself via dt_enable_secure_status(), which
should present the properly configured FDT when U-Boot takes over.

This is however valid only if OP-TEE implementation for LS matches to
one from i.MX8M family.

If it OP-TEE does differ, then I suggest this should be rather addressed
there before U-Boot, since OP-TEE have all facilities in place to
reserve JR nodes as they are needed.

> 
> Regards,
> Sahil Malhotra

-- andrey
Link: [1]: https://lore.kernel.org/u-boot/20211207074129.10955-9-gaurav.jain@nxp.com

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

* RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2021-12-08 10:13             ` ZHIZHIKIN Andrey
@ 2021-12-10  6:33               ` Sahil Malhotra (OSS)
  2021-12-17  6:19                 ` Sahil Malhotra (OSS)
  2021-12-20 12:52                 ` Michael Walle
  0 siblings, 2 replies; 26+ messages in thread
From: Sahil Malhotra (OSS) @ 2021-12-10  6:33 UTC (permalink / raw)
  To: ZHIZHIKIN Andrey, Sahil Malhotra (OSS), Michael Walle
  Cc: Clément Faure, Gaurav Jain, Pankaj Gupta, Priyanka Jain,
	u-boot, Varun Sethi, Ye Li

Hi Andrey,

> -----Original Message-----
> From: ZHIZHIKIN Andrey <andrey.zhizhikin@leica-geosystems.com>
> Sent: Wednesday, December 8, 2021 3:43 PM
> To: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>; Michael Walle
> <michael@walle.cc>
> Cc: Clément Faure <clement.faure@nxp.com>; Gaurav Jain
> <gaurav.jain@nxp.com>; Pankaj Gupta <pankaj.gupta@nxp.com>; Priyanka
> Jain <priyanka.jain@nxp.com>; u-boot@lists.denx.de; Varun Sethi
> <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>
> Subject: RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
> 
> Hello Sahil,
> 
> > -----Original Message-----
> > From: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
> > Sent: Wednesday, December 8, 2021 7:12 AM
> > To: Michael Walle <michael@walle.cc>; Sahil Malhotra (OSS)
> > <sahil.malhotra@oss.nxp.com>
> > Cc: Clément Faure <clement.faure@nxp.com>; Gaurav Jain
> > <gaurav.jain@nxp.com>; Pankaj Gupta <pankaj.gupta@nxp.com>;
> Priyanka
> > Jain <priyanka.jain@nxp.com>; u- boot@lists.denx.de; Varun Sethi
> > <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>; ZHIZHIKIN Andrey
> > <andrey.zhizhikin@leica-geosystems.com>
> > Subject: RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
> >
> >
> > Hi Michael,
> >
> > -----Original Message-----
> > From: Michael Walle <michael@walle.cc>
> > Sent: Monday, November 29, 2021 11:17 PM
> > To: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
> > Cc: Clément Faure <clement.faure@nxp.com>; Gaurav Jain
> > <gaurav.jain@nxp.com>; Pankaj Gupta <pankaj.gupta@nxp.com>;
> Priyanka
> > Jain <priyanka.jain@nxp.com>; u- boot@lists.denx.de; Varun Sethi
> > <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>; ZHIZHIKIN Andrey
> > <andrey.zhizhikin@leica-geosystems.com>
> > Subject: Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
> >
> > Hi Sahil,
> >
> > Am 2021-11-29 12:55, schrieb Sahil Malhotra (OSS):
> > > Am 2021-11-17 19:11, schrieb Sahil Malhotra (OSS):
> > >>> Could you please add some description what this is doing and for
> > >>> what this is intended? To have a "DTB overlay feature", it is
> > >>> enough to just enable CONFIG_OF_LIBFDT_OVERLAY.
> > >> I will add some description, and yes for DTB overlay feature, it is
> > >> enough to enable CONFIG_OF_LIBFDT_OVERLAY but we need to do this
> > >> step before booting the kernel that's why also have to enable
> > >> CONFIG_OF_SYSTEM_SETUP.
> > >
> > >> Ok. What will the overlay do? Could you give an example?
> > > This overlay will be disabling the crypto nodes which will be used
> > > by optee in secure world, so that linux should not use it.
> > >
> > >
> > >>> Apparently you're adding an overlay passed by optee. Doesn't this
> > >>> have to be applied to u-boot's control dtb too?
> > >> Yes, we will be applying the overlay passed by optee, yes it will
> > >> be applied to dtb which will be passed to uboot for kernel booting.
> > >
> > >> If I read this patch correctly, you're modifying the DT before you
> > >> jump to linux. But I was asking whether you also have to modify the
> > >> DT which is used by u-boot. Eg. if you disable some kind of crypto
> > >> nodes (because optee will use them in secure world), this also have
> > >> to communicated to u-boot, not only linux, no?
> > > Yes, I got your point now, and is very valid, but as of now for
> > > u-boot we are just using the first available node for communicating
> > > with CAAM leaving other job rings as it is.
> > > So we need not to apply overlay to DTB used by uboot.
> >
> > > But we should do the correct thing, so that u-boot and linux doesn't
> > > see a
> > different version of the device tree.
> >
> > > Also what do you mean with "the first available node"?
> > > There is already a new CAAM driver for u-boot pending, see
> > > https://lore.kernel.org/u-boot/20211115070014.17586-1-gaurav.jain@nx
> > > p.com/
> >
> > Very first CAAM Job Ring is always used by u-boot, OP-TEE does not use
> > this job ring. Same job ring can be used by Linux once it boots up.
> 
> Just for clarification: by saying "Very first CAAM Job Ring" do you actually
> mean JR0?
Yes, Very first CAAM Job Ring means JR0 for Layerscape.

> 
> If the BootROM logic with respect to JR reservation for LS family does not
> differ from i.MX8M family (which I assume does not), then why can't the
> logic be implemented in the same way proposed by Gaurav [1] here as well?
BootROM logic with respect to JR reservation is different for both Layerscape and i.MX8M family.
On Layerscape Platforms we don't have HAB, so we don’t need to reserve JR0.

> 
> DT nodes can be statically disabled if we know that they are held by HAB and
> are not released to NS World.
> 
> OP-TEE does set the status itself via dt_enable_secure_status(), which
> should present the properly configured FDT when U-Boot takes over.
Yes, OP-TEE set the status by dt_enable_secure_status() in DTB overlay which gets merged with DTB provided for Linux bootup and then Linux boots with merged DTB.
But u-boot uses the DTB embedded in its image. How can we modify that DTB or merge DTB overlay passed by OP-TEE with uboot DTB ?

> 
> This is however valid only if OP-TEE implementation for LS matches to one
> from i.MX8M family.
> 
> If it OP-TEE does differ, then I suggest this should be rather addressed there
> before U-Boot, since OP-TEE have all facilities in place to reserve JR nodes as
> they are needed.
OP-TEE reserves the JR node needed by it, but it needs to tell that to Normal World entities and that is being done using DTB overlay for now.

> 
> >
> > Regards,
> > Sahil Malhotra
> 
> -- andrey
> Link: [1]: https://lore.kernel.org/u-boot/20211207074129.10955-9-
> gaurav.jain@nxp.com

Regards,
Sahil Malhotra





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

* Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2021-11-29 17:47         ` Michael Walle
  2021-12-08  6:12           ` Sahil Malhotra (OSS)
@ 2021-12-10  7:38           ` François Ozog
  1 sibling, 0 replies; 26+ messages in thread
From: François Ozog @ 2021-12-10  7:38 UTC (permalink / raw)
  To: Michael Walle
  Cc: Clément Faure, Gaurav Jain, Pankaj Gupta, Priyanka Jain,
	Sahil Malhotra (OSS),
	Varun Sethi, Ye Li, ZHIZHIKIN Andrey, u-boot

Hi Michael

Le lun. 29 nov. 2021 à 18:47, Michael Walle <michael@walle.cc> a écrit :

> Hi Sahil,
>
> Am 2021-11-29 12:55, schrieb Sahil Malhotra (OSS):
> > Am 2021-11-17 19:11, schrieb Sahil Malhotra (OSS):
> >>> Could you please add some description what this is doing and for what
> >>> this is intended? To have a "DTB overlay feature", it is enough to
> >>> just enable CONFIG_OF_LIBFDT_OVERLAY.
> >> I will add some description, and yes for DTB overlay feature, it is
> >> enough to enable CONFIG_OF_LIBFDT_OVERLAY but we need to do this step
> >> before booting the kernel that's why also have to enable
> >> CONFIG_OF_SYSTEM_SETUP.
> >
> >> Ok. What will the overlay do? Could you give an example?
> > This overlay will be disabling the crypto nodes which will be used by
> > optee in secure world, so that linux should not use it.
> >
> >
> >>> Apparently you're adding an overlay passed by optee. Doesn't this
> >>> have to be applied to u-boot's control dtb too?
> >> Yes, we will be applying the overlay passed by optee, yes it will be
> >> applied to dtb which will be passed to uboot for kernel booting.
> >
> >> If I read this patch correctly, you're modifying the DT before you
> >> jump to linux. But I was asking whether you also have to modify the DT
> >> which is used by u-boot. Eg. if you disable some kind of crypto nodes
> >> (because optee will use them in secure world), this also have to
> >> communicated to u-boot, not only linux, no?
> > Yes, I got your point now, and is very valid, but as of now for u-boot
> > we are just using the first available node for communicating with CAAM
> > leaving other job rings as it is.
> > So we need not to apply overlay to DTB used by uboot.
>
> But we should do the correct thing, so that u-boot and linux
> doesn't see a different version of the device tree.


Outside any runtime context there should be a reference for hardware
description.
That non-runtime reference need to be firmware and OS agnostic and document
what devices are seen by each. For instance a board with serdes should have
serdes nodes and disabled nodes that corresponds to possible nodes (pci,
network, storage…) created as a result of the serdes configuration. One
would expect firmware does it but nothing prevent an OS to do it. Those
nodes should not refer to U-Boot or Linux, just firmware and operating
system.
Furthermore, there may be multiple totally independent computing domains on
a single board: Cortex-a + r/m, multiple cortex-a and cortex-r/m and other
cores.
So the reference hardware description should encompass all and provide
consistent description of resources available in multiple domains (say some
hardware mail box and why not some sram). To be consumed by different
operating systems.
Linux, if the operating system of choice for that platform, will only see a
portion of the total hardware description. That part may be further reduced
at runtime for various legislative reasons, one of them being presented by
Sahil.

For your above comment, were you referring to this reference hardware
description of the cortex-a domain of the board ?


> Also what do you mean with "the first available node"?
> There is already a new CAAM driver for u-boot pending,
> see
> https://lore.kernel.org/u-boot/20211115070014.17586-1-gaurav.jain@nxp.com/
>
> -michael
>
-- 
François-Frédéric Ozog | *Director Business Development*
T: +33.67221.6485
francois.ozog@linaro.org | Skype: ffozog

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

* RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2021-12-10  6:33               ` Sahil Malhotra (OSS)
@ 2021-12-17  6:19                 ` Sahil Malhotra (OSS)
  2021-12-17  7:27                   ` Michael Walle
  2021-12-20 12:52                 ` Michael Walle
  1 sibling, 1 reply; 26+ messages in thread
From: Sahil Malhotra (OSS) @ 2021-12-17  6:19 UTC (permalink / raw)
  To: Michael Walle, ZHIZHIKIN Andrey
  Cc: Clément Faure, Gaurav Jain, Pankaj Gupta, Priyanka Jain,
	u-boot, Varun Sethi, Ye Li, Sahil Malhotra (OSS)

Hi Michael/Andrey

Gentle reminder for comment on this patch series.

Regards,
Sahil Malhotra

> -----Original Message-----
> From: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
> Sent: Friday, December 10, 2021 12:03 PM
> To: ZHIZHIKIN Andrey <andrey.zhizhikin@leica-geosystems.com>; Sahil
> Malhotra (OSS) <sahil.malhotra@oss.nxp.com>; Michael Walle
> <michael@walle.cc>
> Cc: Clément Faure <clement.faure@nxp.com>; Gaurav Jain
> <gaurav.jain@nxp.com>; Pankaj Gupta <pankaj.gupta@nxp.com>; Priyanka
> Jain <priyanka.jain@nxp.com>; u-boot@lists.denx.de; Varun Sethi
> <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>
> Subject: RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
> 
> Hi Andrey,
> 
> > -----Original Message-----
> > From: ZHIZHIKIN Andrey <andrey.zhizhikin@leica-geosystems.com>
> > Sent: Wednesday, December 8, 2021 3:43 PM
> > To: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>; Michael Walle
> > <michael@walle.cc>
> > Cc: Clément Faure <clement.faure@nxp.com>; Gaurav Jain
> > <gaurav.jain@nxp.com>; Pankaj Gupta <pankaj.gupta@nxp.com>;
> Priyanka
> > Jain <priyanka.jain@nxp.com>; u-boot@lists.denx.de; Varun Sethi
> > <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>
> > Subject: RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
> >
> > Hello Sahil,
> >
> > > -----Original Message-----
> > > From: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
> > > Sent: Wednesday, December 8, 2021 7:12 AM
> > > To: Michael Walle <michael@walle.cc>; Sahil Malhotra (OSS)
> > > <sahil.malhotra@oss.nxp.com>
> > > Cc: Clément Faure <clement.faure@nxp.com>; Gaurav Jain
> > > <gaurav.jain@nxp.com>; Pankaj Gupta <pankaj.gupta@nxp.com>;
> > Priyanka
> > > Jain <priyanka.jain@nxp.com>; u- boot@lists.denx.de; Varun Sethi
> > > <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>; ZHIZHIKIN Andrey
> > > <andrey.zhizhikin@leica-geosystems.com>
> > > Subject: RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
> > >
> > >
> > > Hi Michael,
> > >
> > > -----Original Message-----
> > > From: Michael Walle <michael@walle.cc>
> > > Sent: Monday, November 29, 2021 11:17 PM
> > > To: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
> > > Cc: Clément Faure <clement.faure@nxp.com>; Gaurav Jain
> > > <gaurav.jain@nxp.com>; Pankaj Gupta <pankaj.gupta@nxp.com>;
> > Priyanka
> > > Jain <priyanka.jain@nxp.com>; u- boot@lists.denx.de; Varun Sethi
> > > <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>; ZHIZHIKIN Andrey
> > > <andrey.zhizhikin@leica-geosystems.com>
> > > Subject: Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
> > >
> > > Hi Sahil,
> > >
> > > Am 2021-11-29 12:55, schrieb Sahil Malhotra (OSS):
> > > > Am 2021-11-17 19:11, schrieb Sahil Malhotra (OSS):
> > > >>> Could you please add some description what this is doing and for
> > > >>> what this is intended? To have a "DTB overlay feature", it is
> > > >>> enough to just enable CONFIG_OF_LIBFDT_OVERLAY.
> > > >> I will add some description, and yes for DTB overlay feature, it
> > > >> is enough to enable CONFIG_OF_LIBFDT_OVERLAY but we need to do
> > > >> this step before booting the kernel that's why also have to
> > > >> enable CONFIG_OF_SYSTEM_SETUP.
> > > >
> > > >> Ok. What will the overlay do? Could you give an example?
> > > > This overlay will be disabling the crypto nodes which will be used
> > > > by optee in secure world, so that linux should not use it.
> > > >
> > > >
> > > >>> Apparently you're adding an overlay passed by optee. Doesn't
> > > >>> this have to be applied to u-boot's control dtb too?
> > > >> Yes, we will be applying the overlay passed by optee, yes it will
> > > >> be applied to dtb which will be passed to uboot for kernel booting.
> > > >
> > > >> If I read this patch correctly, you're modifying the DT before
> > > >> you jump to linux. But I was asking whether you also have to
> > > >> modify the DT which is used by u-boot. Eg. if you disable some
> > > >> kind of crypto nodes (because optee will use them in secure
> > > >> world), this also have to communicated to u-boot, not only linux, no?
> > > > Yes, I got your point now, and is very valid, but as of now for
> > > > u-boot we are just using the first available node for
> > > > communicating with CAAM leaving other job rings as it is.
> > > > So we need not to apply overlay to DTB used by uboot.
> > >
> > > > But we should do the correct thing, so that u-boot and linux
> > > > doesn't see a
> > > different version of the device tree.
> > >
> > > > Also what do you mean with "the first available node"?
> > > > There is already a new CAAM driver for u-boot pending, see
> > > > https://lore.kernel.org/u-boot/20211115070014.17586-1-gaurav.jain@
> > > > nx
> > > > p.com/
> > >
> > > Very first CAAM Job Ring is always used by u-boot, OP-TEE does not
> > > use this job ring. Same job ring can be used by Linux once it boots up.
> >
> > Just for clarification: by saying "Very first CAAM Job Ring" do you
> > actually mean JR0?
> Yes, Very first CAAM Job Ring means JR0 for Layerscape.
> 
> >
> > If the BootROM logic with respect to JR reservation for LS family does
> > not differ from i.MX8M family (which I assume does not), then why
> > can't the logic be implemented in the same way proposed by Gaurav [1]
> here as well?
> BootROM logic with respect to JR reservation is different for both Layerscape
> and i.MX8M family.
> On Layerscape Platforms we don't have HAB, so we don’t need to reserve
> JR0.
> 
> >
> > DT nodes can be statically disabled if we know that they are held by
> > HAB and are not released to NS World.
> >
> > OP-TEE does set the status itself via dt_enable_secure_status(), which
> > should present the properly configured FDT when U-Boot takes over.
> Yes, OP-TEE set the status by dt_enable_secure_status() in DTB overlay
> which gets merged with DTB provided for Linux bootup and then Linux boots
> with merged DTB.
> But u-boot uses the DTB embedded in its image. How can we modify that
> DTB or merge DTB overlay passed by OP-TEE with uboot DTB ?
> 
> >
> > This is however valid only if OP-TEE implementation for LS matches to
> > one from i.MX8M family.
> >
> > If it OP-TEE does differ, then I suggest this should be rather
> > addressed there before U-Boot, since OP-TEE have all facilities in
> > place to reserve JR nodes as they are needed.
> OP-TEE reserves the JR node needed by it, but it needs to tell that to Normal
> World entities and that is being done using DTB overlay for now.
> 
> >
> > >
> > > Regards,
> > > Sahil Malhotra
> >
> > -- andrey
> > Link: [1]: https://lore.kernel.org/u-boot/20211207074129.10955-9-
> > gaurav.jain@nxp.com
> 
> Regards,
> Sahil Malhotra
> 
> 
> 


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

* RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2021-12-17  6:19                 ` Sahil Malhotra (OSS)
@ 2021-12-17  7:27                   ` Michael Walle
  0 siblings, 0 replies; 26+ messages in thread
From: Michael Walle @ 2021-12-17  7:27 UTC (permalink / raw)
  To: Sahil Malhotra (OSS), ZHIZHIKIN Andrey
  Cc: Clément Faure, Gaurav Jain, Pankaj Gupta, Priyanka Jain,
	u-boot, Varun Sethi, Ye Li

Am 17. Dezember 2021 11:19:42 GMT+05:00 schrieb "Sahil Malhotra (OSS)" <sahil.malhotra@oss.nxp.com>:
>Hi Michael/Andrey
>
>Gentle reminder for comment on this patch series.
>
>Regards,
>Sahil Malhotra
>
>> -----Original Message-----
>> From: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
>> Sent: Friday, December 10, 2021 12:03 PM
>> To: ZHIZHIKIN Andrey <andrey.zhizhikin@leica-geosystems.com>; Sahil
>> Malhotra (OSS) <sahil.malhotra@oss.nxp.com>; Michael Walle
>> <michael@walle.cc>
>> Cc: Clément Faure <clement.faure@nxp.com>; Gaurav Jain
>> <gaurav.jain@nxp.com>; Pankaj Gupta <pankaj.gupta@nxp.com>; Priyanka
>> Jain <priyanka.jain@nxp.com>; u-boot@lists.denx.de; Varun Sethi
>> <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>
>> Subject: RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
>> 
>> Hi Andrey,
>> 
>> > -----Original Message-----
>> > From: ZHIZHIKIN Andrey <andrey.zhizhikin@leica-geosystems.com>
>> > Sent: Wednesday, December 8, 2021 3:43 PM
>> > To: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>; Michael Walle
>> > <michael@walle.cc>
>> > Cc: Clément Faure <clement.faure@nxp.com>; Gaurav Jain
>> > <gaurav.jain@nxp.com>; Pankaj Gupta <pankaj.gupta@nxp.com>;
>> Priyanka
>> > Jain <priyanka.jain@nxp.com>; u-boot@lists.denx.de; Varun Sethi
>> > <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>
>> > Subject: RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
>> >
>> > Hello Sahil,
>> >
>> > > -----Original Message-----
>> > > From: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
>> > > Sent: Wednesday, December 8, 2021 7:12 AM
>> > > To: Michael Walle <michael@walle.cc>; Sahil Malhotra (OSS)
>> > > <sahil.malhotra@oss.nxp.com>
>> > > Cc: Clément Faure <clement.faure@nxp.com>; Gaurav Jain
>> > > <gaurav.jain@nxp.com>; Pankaj Gupta <pankaj.gupta@nxp.com>;
>> > Priyanka
>> > > Jain <priyanka.jain@nxp.com>; u- boot@lists.denx.de; Varun Sethi
>> > > <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>; ZHIZHIKIN Andrey
>> > > <andrey.zhizhikin@leica-geosystems.com>
>> > > Subject: RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
>> > >
>> > >
>> > > Hi Michael,
>> > >
>> > > -----Original Message-----
>> > > From: Michael Walle <michael@walle.cc>
>> > > Sent: Monday, November 29, 2021 11:17 PM
>> > > To: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
>> > > Cc: Clément Faure <clement.faure@nxp.com>; Gaurav Jain
>> > > <gaurav.jain@nxp.com>; Pankaj Gupta <pankaj.gupta@nxp.com>;
>> > Priyanka
>> > > Jain <priyanka.jain@nxp.com>; u- boot@lists.denx.de; Varun Sethi
>> > > <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>; ZHIZHIKIN Andrey
>> > > <andrey.zhizhikin@leica-geosystems.com>
>> > > Subject: Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
>> > >
>> > > Hi Sahil,
>> > >
>> > > Am 2021-11-29 12:55, schrieb Sahil Malhotra (OSS):
>> > > > Am 2021-11-17 19:11, schrieb Sahil Malhotra (OSS):
>> > > >>> Could you please add some description what this is doing and for
>> > > >>> what this is intended? To have a "DTB overlay feature", it is
>> > > >>> enough to just enable CONFIG_OF_LIBFDT_OVERLAY.
>> > > >> I will add some description, and yes for DTB overlay feature, it
>> > > >> is enough to enable CONFIG_OF_LIBFDT_OVERLAY but we need to do
>> > > >> this step before booting the kernel that's why also have to
>> > > >> enable CONFIG_OF_SYSTEM_SETUP.
>> > > >
>> > > >> Ok. What will the overlay do? Could you give an example?
>> > > > This overlay will be disabling the crypto nodes which will be used
>> > > > by optee in secure world, so that linux should not use it.
>> > > >
>> > > >
>> > > >>> Apparently you're adding an overlay passed by optee. Doesn't
>> > > >>> this have to be applied to u-boot's control dtb too?
>> > > >> Yes, we will be applying the overlay passed by optee, yes it will
>> > > >> be applied to dtb which will be passed to uboot for kernel booting.
>> > > >
>> > > >> If I read this patch correctly, you're modifying the DT before
>> > > >> you jump to linux. But I was asking whether you also have to
>> > > >> modify the DT which is used by u-boot. Eg. if you disable some
>> > > >> kind of crypto nodes (because optee will use them in secure
>> > > >> world), this also have to communicated to u-boot, not only linux, no?
>> > > > Yes, I got your point now, and is very valid, but as of now for
>> > > > u-boot we are just using the first available node for
>> > > > communicating with CAAM leaving other job rings as it is.
>> > > > So we need not to apply overlay to DTB used by uboot.
>> > >
>> > > > But we should do the correct thing, so that u-boot and linux
>> > > > doesn't see a
>> > > different version of the device tree.
>> > >
>> > > > Also what do you mean with "the first available node"?
>> > > > There is already a new CAAM driver for u-boot pending, see
>> > > > https://lore.kernel.org/u-boot/20211115070014.17586-1-gaurav.jain@
>> > > > nx
>> > > > p.com/
>> > >
>> > > Very first CAAM Job Ring is always used by u-boot, OP-TEE does not
>> > > use this job ring. Same job ring can be used by Linux once it boots up.
>> >
>> > Just for clarification: by saying "Very first CAAM Job Ring" do you
>> > actually mean JR0?
>> Yes, Very first CAAM Job Ring means JR0 for Layerscape.
>> 
>> >
>> > If the BootROM logic with respect to JR reservation for LS family does
>> > not differ from i.MX8M family (which I assume does not), then why
>> > can't the logic be implemented in the same way proposed by Gaurav [1]
>> here as well?
>> BootROM logic with respect to JR reservation is different for both Layerscape
>> and i.MX8M family.
>> On Layerscape Platforms we don't have HAB, so we don’t need to reserve
>> JR0.
>> 
>> >
>> > DT nodes can be statically disabled if we know that they are held by
>> > HAB and are not released to NS World.
>> >
>> > OP-TEE does set the status itself via dt_enable_secure_status(), which
>> > should present the properly configured FDT when U-Boot takes over.
>> Yes, OP-TEE set the status by dt_enable_secure_status() in DTB overlay
>> which gets merged with DTB provided for Linux bootup and then Linux boots
>> with merged DTB.
>> But u-boot uses the DTB embedded in its image. How can we modify that
>> DTB or merge DTB overlay passed by OP-TEE with uboot DTB ?
>> 
>> >
>> > This is however valid only if OP-TEE implementation for LS matches to
>> > one from i.MX8M family.
>> >
>> > If it OP-TEE does differ, then I suggest this should be rather
>> > addressed there before U-Boot, since OP-TEE have all facilities in
>> > place to reserve JR nodes as they are needed.
>> OP-TEE reserves the JR node needed by it, but it needs to tell that to Normal
>> World entities and that is being done using DTB overlay for now.
>> 
>> >
>> > >
>> > > Regards,
>> > > Sahil Malhotra
>> >
>> > -- andrey
>> > Link: [1]: https://lore.kernel.org/u-boot/20211207074129.10955-9-
>> > gaurav.jain@nxp.com
>> 
>> Regards,
>> Sahil Malhotra
>> 
>> 
>> 
>

hey sahil,

I'm on vacation until the end of this week. will comment beginning of next week.

-michael

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

* Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2021-12-10  6:33               ` Sahil Malhotra (OSS)
  2021-12-17  6:19                 ` Sahil Malhotra (OSS)
@ 2021-12-20 12:52                 ` Michael Walle
  2021-12-23  8:46                   ` [EXT] " Sahil Malhotra (OSS)
  1 sibling, 1 reply; 26+ messages in thread
From: Michael Walle @ 2021-12-20 12:52 UTC (permalink / raw)
  To: Sahil Malhotra (OSS)
  Cc: ZHIZHIKIN Andrey, Clément Faure, Gaurav Jain, Pankaj Gupta,
	Priyanka Jain, u-boot, Varun Sethi, Ye Li

Hi Sahil,

Am 2021-12-10 07:33, schrieb Sahil Malhotra (OSS):
>> DT nodes can be statically disabled if we know that they are held by 
>> HAB and
>> are not released to NS World.
>> 
>> OP-TEE does set the status itself via dt_enable_secure_status(), which
>> should present the properly configured FDT when U-Boot takes over.
> Yes, OP-TEE set the status by dt_enable_secure_status() in DTB overlay
> which gets merged with DTB provided for Linux bootup and then Linux
> boots with merged DTB.
> But u-boot uses the DTB embedded in its image. How can we modify that
> DTB or merge DTB overlay passed by OP-TEE with uboot DTB ?

But then u-boot has the "wrong" dtb. What is the reason, there is an
overlay instead of a whole dtb? what if the overlay doesn't match
the dtb?

-michael

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

* RE: [EXT] Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2021-12-20 12:52                 ` Michael Walle
@ 2021-12-23  8:46                   ` Sahil Malhotra (OSS)
  2021-12-23  9:34                     ` Michael Walle
  0 siblings, 1 reply; 26+ messages in thread
From: Sahil Malhotra (OSS) @ 2021-12-23  8:46 UTC (permalink / raw)
  To: Michael Walle, Sahil Malhotra (OSS)
  Cc: ZHIZHIKIN Andrey, Clément Faure, Gaurav Jain, Pankaj Gupta,
	Priyanka Jain, u-boot, Varun Sethi, Ye Li

Hi Michael,

> -----Original Message-----
> From: U-Boot <u-boot-bounces@lists.denx.de> On Behalf Of Michael Walle
> Sent: Monday, December 20, 2021 6:23 PM
> To: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
> Cc: ZHIZHIKIN Andrey <andrey.zhizhikin@leica-geosystems.com>; Clément
> Faure <clement.faure@nxp.com>; Gaurav Jain <gaurav.jain@nxp.com>;
> Pankaj Gupta <pankaj.gupta@nxp.com>; Priyanka Jain
> <priyanka.jain@nxp.com>; u-boot@lists.denx.de; Varun Sethi
> <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>
> Subject: [EXT] Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
> 
> Caution: EXT Email
> 
> Hi Sahil,
> 
> Am 2021-12-10 07:33, schrieb Sahil Malhotra (OSS):
> >> DT nodes can be statically disabled if we know that they are held by
> >> HAB and are not released to NS World.
> >>
> >> OP-TEE does set the status itself via dt_enable_secure_status(),
> >> which should present the properly configured FDT when U-Boot takes
> over.
> > Yes, OP-TEE set the status by dt_enable_secure_status() in DTB overlay
> > which gets merged with DTB provided for Linux bootup and then Linux
> > boots with merged DTB.
> > But u-boot uses the DTB embedded in its image. How can we modify that
> > DTB or merge DTB overlay passed by OP-TEE with uboot DTB ?
> 
> But then u-boot has the "wrong" dtb. What is the reason, there is an overlay
> instead of a whole dtb? what if the overlay doesn't match the dtb?
"wrong" dtb means that uboot will not be aware of CAAM job ring which is taken by
OP-TEE and uboot on LS platforms currently use JR0, which is not being used by any other
entity in LS bootflow.

We don't use DTB in OP-TEE, but when we use CAAM in OP-TEE, OP-TEE reserves
One Job Ring for its use and that is communicated to Kernel using DTB overlay.

> what if the overlay doesn't match the dtb?
I didn't get this point, can you please elaborate a little.

Regards,
Sahil Malhotra

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

* Re: [EXT] Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2021-12-23  8:46                   ` [EXT] " Sahil Malhotra (OSS)
@ 2021-12-23  9:34                     ` Michael Walle
  0 siblings, 0 replies; 26+ messages in thread
From: Michael Walle @ 2021-12-23  9:34 UTC (permalink / raw)
  To: Sahil Malhotra (OSS)
  Cc: ZHIZHIKIN Andrey, Clément Faure, Gaurav Jain, Pankaj Gupta,
	Priyanka Jain, u-boot, Varun Sethi, Ye Li

Hi Sahil,

Am 2021-12-23 09:46, schrieb Sahil Malhotra (OSS):
>> -----Original Message-----
>> From: U-Boot <u-boot-bounces@lists.denx.de> On Behalf Of Michael Walle
>> Sent: Monday, December 20, 2021 6:23 PM
>> To: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
>> Cc: ZHIZHIKIN Andrey <andrey.zhizhikin@leica-geosystems.com>; Clément
>> Faure <clement.faure@nxp.com>; Gaurav Jain <gaurav.jain@nxp.com>;
>> Pankaj Gupta <pankaj.gupta@nxp.com>; Priyanka Jain
>> <priyanka.jain@nxp.com>; u-boot@lists.denx.de; Varun Sethi
>> <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>
>> Subject: [EXT] Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
>> 
>> Caution: EXT Email
>> 
>> Hi Sahil,
>> 
>> Am 2021-12-10 07:33, schrieb Sahil Malhotra (OSS):
>> >> DT nodes can be statically disabled if we know that they are held by
>> >> HAB and are not released to NS World.
>> >>
>> >> OP-TEE does set the status itself via dt_enable_secure_status(),
>> >> which should present the properly configured FDT when U-Boot takes
>> over.
>> > Yes, OP-TEE set the status by dt_enable_secure_status() in DTB overlay
>> > which gets merged with DTB provided for Linux bootup and then Linux
>> > boots with merged DTB.
>> > But u-boot uses the DTB embedded in its image. How can we modify that
>> > DTB or merge DTB overlay passed by OP-TEE with uboot DTB ?
>> 
>> But then u-boot has the "wrong" dtb. What is the reason, there is an 
>> overlay
>> instead of a whole dtb? what if the overlay doesn't match the dtb?
> "wrong" dtb means that uboot will not be aware of CAAM job ring which
> is taken by
> OP-TEE and uboot on LS platforms currently use JR0, which is not being
> used by any other
> entity in LS bootflow.

I don't know I follow. u-boot and linux should have the same device 
tree;
regardless if that device is used or not. So applying the overlay just 
for
linux isn't enough here.

> We don't use DTB in OP-TEE, but when we use CAAM in OP-TEE, OP-TEE 
> reserves
> One Job Ring for its use and that is communicated to Kernel using DTB 
> overlay.
> 
>> what if the overlay doesn't match the dtb?
> I didn't get this point, can you please elaborate a little.

You are merging a dtb fragment with an unknown dtb, right? Who says they
match? you might have an old dtb where the supplied dtb fragment doesn't
make any sense.

I might be missing something here. Eg. where is the linux dtb supposed 
to
come from? This patchset is really missing an example and a description 
how
things should work.

-michael

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

* Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2022-02-24 10:59     ` Sahil Malhotra (OSS)
@ 2022-02-24 12:33       ` Michael Walle
  0 siblings, 0 replies; 26+ messages in thread
From: Michael Walle @ 2022-02-24 12:33 UTC (permalink / raw)
  To: Sahil Malhotra (OSS), Tom Rini
  Cc: ZHIZHIKIN Andrey, Clément Faure, Gaurav Jain, Pankaj Gupta,
	Priyanka Jain, u-boot, Varun Sethi, Ye Li

Hi Sahil,

sorry I missed this. I'm also putting Tom on CC because I don't really
have an answer or maybe I'm lacking the whole picture, too.

>> > >> I don't know I follow. u-boot and linux should have the same device
>> > >> tree; regardless if that device is used or not. So applying the
>> > >> overlay just for linux isn't enough here.
>> > > Ok, I don't think that as of now, in all platforms uboot and linux
>> > > have same devie tree.
>> >
>> > That doesn't mean it is ok to diverge again. I put a lot of effort in
>> > syncing uboot's LS1028A device tree with linux.
>> Yes, that’s true we should not diverge again if they are already 
>> synced.
>> 
>> 
>> > > But I will try to address your concern, but I don’t know how to
>> > > apply overlay to dtb which is embedded in u-boot binary, Can you
>> > > please point me to one reference which is doing this thing, I will
>> > > take reference from there.
>> >
>> > Sorry I can't advise you with that. There is board_fix_fdt() maybe
>> > that will help. But I'm not conviced this is the correct approach, see below.
>> Ok, I looked at the board_fix_fdt() and in that we can put the code 
>> for
>> modifying the uboot DTB.
>> But the same overlay which we are going to apply on linux DTB should 
>> get
>> applied On uboot DTB, and that can happen only when we have same DTBs
>> both in Linux and u-boot.
>> 
>> I checked the uboot and Linux DTBs for LS platforms, except LS1028, 
>> all other
>> platforms have a lot of difference in them.
>> 
>> So we will not be able to apply the same DTB overaly which we get from 
>> OP-
>> TEE on both Linux and uboot.
>> 
>> For now this can only happen for LS1028 platform, if you want we can 
>> do this,
>> But it will be incomplete in my opinion as it will not enable all the 
>> boards.
>> We need to work on them again.


>> 
>> >
>> > >> > We don't use DTB in OP-TEE, but when we use CAAM in OP-TEE,
>> > >> > OP-TEE reserves One Job Ring for its use and that is communicated
>> > >> > to Kernel using DTB overlay.
>> > >> >
>> > >> >> what if the overlay doesn't match the dtb?
>> > >> > I didn't get this point, can you please elaborate a little.
>> > >>
>> > >> You are merging a dtb fragment with an unknown dtb, right? Who says
>> > >> they match? you might have an old dtb where the supplied dtb
>> > >> fragment doesn't make any sense.
>> > >>
>> > >> I might be missing something here. Eg. where is the linux dtb
>> > >> supposed to come from? This patchset is really missing an example
>> > >> and a description how things should work.
>> > > If supplied DTB does not match with DTB overlay fragment. then
>> > > overlay will not get applied.
>> >
>> > I don't think this is what happens here. fdt_overlay_apply() will mark
>> > the fdt as damaged and there will be no fdt at all.
>> Ok, got your point, If we have fragment in DTB overlay to modify let's 
>> say
>> `status` of CAAM job ring, and CAAM job ring node does not exist in 
>> the DTB
>> on which overlay is going to be applied, In that case the DTB will be 
>> marked as
>> damaged and it will stop booting of the board, right ?

At least without touching that code path, yes, that is how i read
the current code.

>> But how can we make sure that DTB overlay and DTB on which DTB overlay 
>> is
>> applied are compatible ?

I doubt you can do that and therefore, I'm not sure about this whole
optee passes us an overlay and we apply it thing. Why don't you just
pass the device tree to optee and optee will change it. Because that
isn't ready at the moment for any boards but the LS1028A? I'd advise
on working on that then and syncing the device trees and use a common
one for u-boot and linux (and optee?).

>> Maybe some DTB version check or something like that, when OP-TEE 
>> creates
>> a DTB overlay, It indicates in the overlay that this can be applied on 
>> only DTBs
>> with version more than `X`

You'd need to get Rob's opinion on that.

>> > > We don't have any control on where user picks the DTB, but we can only
>> > > make sure DTB overlay feature must work with DTBs which are
>> upstreamed
>> > > If user makes its own customized DTB, we cannot make sure that things
>> > > will work.
>> >
>> > Again. Is there any documentation on how this should all work together?
>> > Where does optee get its device tree from? Shouldn't it be the same
>> device
>> > tree as u-boot and linux? Shouldn't optee modify the device tree in place
>> > before jumping back to u-boot?
>> Here on LS platforms: Boot Flow is like ATF-> OP-TEE-> ATF->Uboot-> 
>> Linux

Or at least on the sl28 (LS1028A) it is:
   u-boot spl -> u-boot -> linux
or
   u-boot spl -> atf bl31 [-> optee]* -> u-boot -> linux

* I'm really not sure about the optee part though. I just tested
   it briefly some time ago.

>> Currently for LS platforms, OP-TEE don't use DTBs except for LX2160A.
>> And I am talking about the other platforms except LX2160 for now.
>> So all peripherals base addresses are currently hardcoded.
>> 
>> But OP-TEE uses some of the peripherals, and this information needs to
>> be passed to following components uboot and linux so that they don't 
>> use
>> the same peripherals.
>> 
>> One of the case is CAAM Job Ring. OP-TEE always use CAAM Job Ring 3, 
>> and it
>> needs to communicate this thing to following components uboot so that 
>> they
>> don’t
>> try to use the same peripherals as used by OP-TEE,
>> So, we enabled DTB_OVERLAY option in OP-TEE and will write CAAM Job 
>> Ring
>> 3 to be
>> disabled in that DTB overlay.

Yeah, I noticed last time that this DTB_OVERLAY is a thing in optee,
thus I wrote in the beginning of this mail. I might not have the
complete picture here; as in how the dtb is passed around u-boot,
optee and linux and where the dtb even comes from. TBH this
patch looks like what can we do with what we have *right now*.
Like a shortcut to getting the problem solved. But IMHO it is
creating a much wider range of different problems then.

>> The address where this DTB overlay will be created is passed by ATF 
>> which
>> ATF will
>> pass on to uboot also.
>> 
>> When control reaches uboot, It  will use that DTB overlay and apply it 
>> on
>> Linux DTB
>> which we passed via tftp on board.
>> 
>> Currently there is no common DTB which is being used by all the 
>> components,
>> OP-TEE, Uboot, Linux all are using their own copies of DTB.

This is not true for the LS1028A and it is doable for the other
layerscape SoCs too. Ok, I'm not sure about optee here.

>> 
>> Hope I answered your queries, Please let me know if you need more
>> information.
>> 
>> > Andrey, do you know how this works on imx?
>> Actually, I took reference from imx only, They are also just applying 
>> DTB
>> overlay on linux DTB as of now.
>> They are not modifying the uboot DTB according to the DTB overlay.

I'm not sure about the latest CAAM patches for u-boot which are
going to use the device tree in u-boot, so they have the same
problem I guess?

-michael

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

* RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2022-02-04 11:27   ` Sahil Malhotra (OSS)
@ 2022-02-24 10:59     ` Sahil Malhotra (OSS)
  2022-02-24 12:33       ` Michael Walle
  0 siblings, 1 reply; 26+ messages in thread
From: Sahil Malhotra (OSS) @ 2022-02-24 10:59 UTC (permalink / raw)
  To: Sahil Malhotra (OSS), Michael Walle
  Cc: ZHIZHIKIN Andrey, Clément Faure, Gaurav Jain, Pankaj Gupta,
	Priyanka Jain, u-boot, Varun Sethi, Ye Li

Hi Michael,

Gentle reminder on this patch set.

Regards,
Sahil Malhotra
> -----Original Message-----
> From: Sahil Malhotra (OSS)
> Sent: Friday, February 4, 2022 4:58 PM
> To: Michael Walle <michael@walle.cc>; Sahil Malhotra (OSS)
> <sahil.malhotra@oss.nxp.com>
> Cc: ZHIZHIKIN Andrey <andrey.zhizhikin@leica-geosystems.com>; Clément
> Faure <clement.faure@nxp.com>; Gaurav Jain <gaurav.jain@nxp.com>;
> Pankaj Gupta <pankaj.gupta@nxp.com>; Priyanka Jain
> <priyanka.jain@nxp.com>; u-boot@lists.denx.de; Varun Sethi
> <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>
> Subject: RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
> 
> Hi Michael,
> 
> Sorry for delayed response.
> Please find my response inline.
> 
> > -----Original Message-----
> > From: Michael Walle <michael@walle.cc>
> > Sent: Thursday, January 6, 2022 1:10 PM
> > To: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
> > Cc: ZHIZHIKIN Andrey <andrey.zhizhikin@leica-geosystems.com>; Clément
> > Faure <clement.faure@nxp.com>; Gaurav Jain <gaurav.jain@nxp.com>;
> > Pankaj Gupta <pankaj.gupta@nxp.com>; Priyanka Jain
> > <priyanka.jain@nxp.com>; u-boot@lists.denx.de; Varun Sethi
> > <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>
> > Subject: Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
> >
> > Hi Sahil,
> >
> > Am 2022-01-06 07:09, schrieb Sahil Malhotra (OSS):
> >
> > >> I don't know I follow. u-boot and linux should have the same device
> > >> tree; regardless if that device is used or not. So applying the
> > >> overlay just for linux isn't enough here.
> > > Ok, I don't think that as of now, in all platforms uboot and linux
> > > have same devie tree.
> >
> > That doesn't mean it is ok to diverge again. I put a lot of effort in
> > syncing uboot's LS1028A device tree with linux.
> Yes, that’s true we should not diverge again if they are already synced.
> 
> 
> > > But I will try to address your concern, but I don’t know how to
> > > apply overlay to dtb which is embedded in u-boot binary, Can you
> > > please point me to one reference which is doing this thing, I will
> > > take reference from there.
> >
> > Sorry I can't advise you with that. There is board_fix_fdt() maybe
> > that will help. But I'm not conviced this is the correct approach, see below.
> Ok, I looked at the board_fix_fdt() and in that we can put the code for
> modifying the uboot DTB.
> But the same overlay which we are going to apply on linux DTB should get
> applied On uboot DTB, and that can happen only when we have same DTBs
> both in Linux and u-boot.
> 
> I checked the uboot and Linux DTBs for LS platforms, except LS1028, all other
> platforms have a lot of difference in them.
> 
> So we will not be able to apply the same DTB overaly which we get from OP-
> TEE on both Linux and uboot.
> 
> For now this can only happen for LS1028 platform, if you want we can do this,
> But it will be incomplete in my opinion as it will not enable all the boards.
> We need to work on them again.
> 
> >
> > >> > We don't use DTB in OP-TEE, but when we use CAAM in OP-TEE,
> > >> > OP-TEE reserves One Job Ring for its use and that is communicated
> > >> > to Kernel using DTB overlay.
> > >> >
> > >> >> what if the overlay doesn't match the dtb?
> > >> > I didn't get this point, can you please elaborate a little.
> > >>
> > >> You are merging a dtb fragment with an unknown dtb, right? Who says
> > >> they match? you might have an old dtb where the supplied dtb
> > >> fragment doesn't make any sense.
> > >>
> > >> I might be missing something here. Eg. where is the linux dtb
> > >> supposed to come from? This patchset is really missing an example
> > >> and a description how things should work.
> > > If supplied DTB does not match with DTB overlay fragment. then
> > > overlay will not get applied.
> >
> > I don't think this is what happens here. fdt_overlay_apply() will mark
> > the fdt as damaged and there will be no fdt at all.
> Ok, got your point, If we have fragment in DTB overlay to modify let's say
> `status` of CAAM job ring, and CAAM job ring node does not exist in the DTB
> on which overlay is going to be applied, In that case the DTB will be marked as
> damaged and it will stop booting of the board, right ?
> But how can we make sure that DTB overlay and DTB on which DTB overlay is
> applied are compatible ?
> Maybe some DTB version check or something like that, when OP-TEE creates
> a DTB overlay, It indicates in the overlay that this can be applied on only DTBs
> with version more than `X`
> 
> 
> > > We don't have any control on where user picks the DTB, but we can only
> > > make sure DTB overlay feature must work with DTBs which are
> upstreamed
> > > If user makes its own customized DTB, we cannot make sure that things
> > > will work.
> >
> > Again. Is there any documentation on how this should all work together?
> > Where does optee get its device tree from? Shouldn't it be the same
> device
> > tree as u-boot and linux? Shouldn't optee modify the device tree in place
> > before jumping back to u-boot?
> Here on LS platforms: Boot Flow is like ATF-> OP-TEE-> ATF->Uboot-> Linux
> 
> Currently for LS platforms, OP-TEE don't use DTBs except for LX2160A.
> And I am talking about the other platforms except LX2160 for now.
> So all peripherals base addresses are currently hardcoded.
> 
> But OP-TEE uses some of the peripherals, and this information needs to
> be passed to following components uboot and linux so that they don't use
> the same peripherals.
> 
> One of the case is CAAM Job Ring. OP-TEE always use CAAM Job Ring 3, and it
> needs to communicate this thing to following components uboot so that they
> don’t
> try to use the same peripherals as used by OP-TEE,
> So, we enabled DTB_OVERLAY option in OP-TEE and will write CAAM Job Ring
> 3 to be
> disabled in that DTB overlay.
> 
> The address where this DTB overlay will be created is passed by ATF which
> ATF will
> pass on to uboot also.
> 
> When control reaches uboot, It  will use that DTB overlay and apply it on
> Linux DTB
> which we passed via tftp on board.
> 
> Currently there is no common DTB which is being used by all the components,
> OP-TEE, Uboot, Linux all are using their own copies of DTB.
> 
> Hope I answered your queries, Please let me know if you need more
> information.
> 
> > Andrey, do you know how this works on imx?
> Actually, I took reference from imx only, They are also just applying DTB
> overlay on linux DTB as of now.
> They are not modifying the uboot DTB according to the DTB overlay.
> 
> 
> Regards,
> Sahil Malhotra

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

* RE: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2022-01-06  7:40 ` Michael Walle
@ 2022-02-04 11:27   ` Sahil Malhotra (OSS)
  2022-02-24 10:59     ` Sahil Malhotra (OSS)
  0 siblings, 1 reply; 26+ messages in thread
From: Sahil Malhotra (OSS) @ 2022-02-04 11:27 UTC (permalink / raw)
  To: Michael Walle, Sahil Malhotra (OSS)
  Cc: ZHIZHIKIN Andrey, Clément Faure, Gaurav Jain, Pankaj Gupta,
	Priyanka Jain, u-boot, Varun Sethi, Ye Li

Hi Michael,

Sorry for delayed response.
Please find my response inline.

> -----Original Message-----
> From: Michael Walle <michael@walle.cc>
> Sent: Thursday, January 6, 2022 1:10 PM
> To: Sahil Malhotra (OSS) <sahil.malhotra@oss.nxp.com>
> Cc: ZHIZHIKIN Andrey <andrey.zhizhikin@leica-geosystems.com>; Clément
> Faure <clement.faure@nxp.com>; Gaurav Jain <gaurav.jain@nxp.com>;
> Pankaj Gupta <pankaj.gupta@nxp.com>; Priyanka Jain
> <priyanka.jain@nxp.com>; u-boot@lists.denx.de; Varun Sethi
> <V.Sethi@nxp.com>; Ye Li <ye.li@nxp.com>
> Subject: Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
> 
> Hi Sahil,
> 
> Am 2022-01-06 07:09, schrieb Sahil Malhotra (OSS):
> 
> >> I don't know I follow. u-boot and linux should have the same device
> >> tree; regardless if that device is used or not. So applying the
> >> overlay just for linux isn't enough here.
> > Ok, I don't think that as of now, in all platforms uboot and linux
> > have same devie tree.
> 
> That doesn't mean it is ok to diverge again. I put a lot of effort in syncing
> uboot's LS1028A device tree with linux.
Yes, that’s true we should not diverge again if they are already synced.


> > But I will try to address your concern, but I don’t know how to apply
> > overlay to dtb which is embedded in u-boot binary, Can you please
> > point me to one reference which is doing this thing, I will take
> > reference from there.
> 
> Sorry I can't advise you with that. There is board_fix_fdt() maybe that will
> help. But I'm not conviced this is the correct approach, see below.
Ok, I looked at the board_fix_fdt() and in that we can put the code for modifying
the uboot DTB.
But the same overlay which we are going to apply on linux DTB should get applied
On uboot DTB, and that can happen only when we have same DTBs both in Linux
and u-boot.

I checked the uboot and Linux DTBs for LS platforms, except LS1028, all other
platforms have a lot of difference in them.

So we will not be able to apply the same DTB overaly which we get from OP-TEE on
both Linux and uboot.

For now this can only happen for LS1028 platform, if you want we can do this,
But it will be incomplete in my opinion as it will not enable all the boards.
We need to work on them again.

> 
> >> > We don't use DTB in OP-TEE, but when we use CAAM in OP-TEE, OP-TEE
> >> > reserves One Job Ring for its use and that is communicated to
> >> > Kernel using DTB overlay.
> >> >
> >> >> what if the overlay doesn't match the dtb?
> >> > I didn't get this point, can you please elaborate a little.
> >>
> >> You are merging a dtb fragment with an unknown dtb, right? Who says
> >> they match? you might have an old dtb where the supplied dtb fragment
> >> doesn't make any sense.
> >>
> >> I might be missing something here. Eg. where is the linux dtb
> >> supposed to come from? This patchset is really missing an example and
> >> a description how things should work.
> > If supplied DTB does not match with DTB overlay fragment. then overlay
> > will not get applied.
> 
> I don't think this is what happens here. fdt_overlay_apply() will mark the fdt
> as damaged and there will be no fdt at all.
Ok, got your point, If we have fragment in DTB overlay to modify let's say `status` of
CAAM job ring, and CAAM job ring node does not exist in the DTB on which overlay is 
going to be applied, In that case the DTB will be marked as damaged and it will stop
booting of the board, right ?
But how can we make sure that DTB overlay and DTB on which DTB overlay is applied
are compatible ?
Maybe some DTB version check or something like that, when OP-TEE creates a DTB overlay,
It indicates in the overlay that this can be applied on only DTBs with version more than `X`


> > We don't have any control on where user picks the DTB, but we can only
> > make sure DTB overlay feature must work with DTBs which are upstreamed
> > If user makes its own customized DTB, we cannot make sure that things
> > will work.
> 
> Again. Is there any documentation on how this should all work together?
> Where does optee get its device tree from? Shouldn't it be the same device
> tree as u-boot and linux? Shouldn't optee modify the device tree in place
> before jumping back to u-boot?
Here on LS platforms: Boot Flow is like ATF-> OP-TEE-> ATF->Uboot-> Linux

Currently for LS platforms, OP-TEE don't use DTBs except for LX2160A.
And I am talking about the other platforms except LX2160 for now.
So all peripherals base addresses are currently hardcoded.

But OP-TEE uses some of the peripherals, and this information needs to 
be passed to following components uboot and linux so that they don't use
the same peripherals.

One of the case is CAAM Job Ring. OP-TEE always use CAAM Job Ring 3, and it
needs to communicate this thing to following components uboot so that they don’t
try to use the same peripherals as used by OP-TEE,
So, we enabled DTB_OVERLAY option in OP-TEE and will write CAAM Job Ring 3 to be
disabled in that DTB overlay.

The address where this DTB overlay will be created is passed by ATF which ATF will
pass on to uboot also.

When control reaches uboot, It  will use that DTB overlay and apply it on Linux DTB
which we passed via tftp on board.

Currently there is no common DTB which is being used by all the components,
OP-TEE, Uboot, Linux all are using their own copies of DTB.

Hope I answered your queries, Please let me know if you need more information.

> Andrey, do you know how this works on imx?
Actually, I took reference from imx only, They are also just applying DTB overlay on linux DTB as of now.
They are not modifying the uboot DTB according to the DTB overlay.


Regards,
Sahil Malhotra

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

* Re: [PATCH 1/2] fsl-layerscape: add dtb overlay feature
  2022-01-06  6:09 Sahil Malhotra (OSS)
@ 2022-01-06  7:40 ` Michael Walle
  2022-02-04 11:27   ` Sahil Malhotra (OSS)
  0 siblings, 1 reply; 26+ messages in thread
From: Michael Walle @ 2022-01-06  7:40 UTC (permalink / raw)
  To: Sahil Malhotra (OSS)
  Cc: ZHIZHIKIN Andrey, Clément Faure, Gaurav Jain, Pankaj Gupta,
	Priyanka Jain, u-boot, Varun Sethi, Ye Li

Hi Sahil,

Am 2022-01-06 07:09, schrieb Sahil Malhotra (OSS):

>> I don't know I follow. u-boot and linux should have the same device 
>> tree;
>> regardless if that device is used or not. So applying the overlay just 
>> for linux isn't
>> enough here.
> Ok, I don't think that as of now, in all platforms uboot and linux
> have same devie
> tree.

That doesn't mean it is ok to diverge again. I put a lot of effort in
syncing uboot's LS1028A device tree with linux.

> But I will try to address your concern, but I don’t know how to apply 
> overlay to
> dtb which is embedded in u-boot binary, Can you please point me to one 
> reference
> which is doing this thing, I will take reference from there.

Sorry I can't advise you with that. There is board_fix_fdt() maybe
that will help. But I'm not conviced this is the correct approach,
see below.

>> > We don't use DTB in OP-TEE, but when we use CAAM in OP-TEE, OP-TEE
>> > reserves One Job Ring for its use and that is communicated to Kernel
>> > using DTB overlay.
>> >
>> >> what if the overlay doesn't match the dtb?
>> > I didn't get this point, can you please elaborate a little.
>> 
>> You are merging a dtb fragment with an unknown dtb, right? Who says 
>> they
>> match? you might have an old dtb where the supplied dtb fragment 
>> doesn't
>> make any sense.
>> 
>> I might be missing something here. Eg. where is the linux dtb supposed 
>> to come
>> from? This patchset is really missing an example and a description how 
>> things
>> should work.
> If supplied DTB does not match with DTB overlay fragment. then overlay
> will not get applied.

I don't think this is what happens here. fdt_overlay_apply() will
mark the fdt as damaged and there will be no fdt at all.

> We don't have any control on where user picks the DTB, but we can only
> make sure DTB
> overlay feature must work with DTBs which are upstreamed
> If user makes its own customized DTB, we cannot make sure that things 
> will work.

Again. Is there any documentation on how this should all work
together? Where does optee get its device tree from? Shouldn't
it be the same device tree as u-boot and linux? Shouldn't optee
modify the device tree in place before jumping back to u-boot?

Andrey, do you know how this works on imx?

-michael

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

* [PATCH 1/2] fsl-layerscape: add dtb overlay feature
@ 2021-11-16 10:16 Sahil Malhotra
  0 siblings, 0 replies; 26+ messages in thread
From: Sahil Malhotra @ 2021-11-16 10:16 UTC (permalink / raw)
  To: u-boot, v.sethi, priyanka.jain, ye.li, clement.faure,
	gaurav.jain, pankaj.gupta
  Cc: Sahil Malhotra

From: Sahil Malhotra <sahil.malhotra@nxp.com>

This patch enables the DTB overlay feature for LS platforms.

Signed-off-by: Sahil Malhotra <sahil.malhotra@nxp.com>
---
 arch/arm/cpu/armv8/fsl-layerscape/Makefile    |  1 +
 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c  | 39 +++++++++++++++++++
 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h  | 10 +++++
 arch/arm/cpu/armv8/fsl-layerscape/fdt.c       | 12 ++++++
 .../cpu/armv8/fsl-layerscape/lowlevel_init.S  | 25 ++++++++++++
 5 files changed, 87 insertions(+)
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Makefile b/arch/arm/cpu/armv8/fsl-layerscape/Makefile
index 598c36ee66..97f1f291dd 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Makefile
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Makefile
@@ -7,6 +7,7 @@ obj-y += lowlevel.o
 obj-y += soc.o
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_MP) += mp.o spintable.o
+obj-$(CONFIG_OF_LIBFDT_OVERLAY) += lowlevel_init.o dt_optee.o
 obj-$(CONFIG_OF_LIBFDT) += fdt.o
 endif
 obj-$(CONFIG_SPL) += spl.o
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
new file mode 100644
index 0000000000..2418ad09c7
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2021 NXP
+ */
+#include <common.h>
+#include <errno.h>
+#include <fdt_support.h>
+#include <linux/sizes.h>
+#include "dt_optee.h"
+
+int ft_add_optee_overlay(void *fdt, struct bd_info *bd)
+{
+	int ret = 0;
+
+	/*
+	 * No BL32_BASE passed means no TEE running, so no
+	 * need to add optee node in dts
+	 */
+	if (!rom_pointer[0]) {
+		debug("No BL32_BASE passed means no TEE running\n");
+		return ret;
+	}
+
+	if (rom_pointer[2]) {
+		debug("OP-TEE: applying overlay on 0x%lx\n", rom_pointer[2]);
+		ret = fdt_check_header((void *)rom_pointer[2]);
+		if (ret == 0) {
+			/* Copy the fdt overlay to next 1M and use copied overlay */
+			memcpy((void *)(rom_pointer[2] + SZ_1M), (void *)rom_pointer[2],
+			       fdt_totalsize((void *)rom_pointer[2]));
+			ret = fdt_overlay_apply_verbose(fdt, (void *)(rom_pointer[2] + SZ_1M));
+			if (ret == 0) {
+				debug("Overlay applied with success");
+				fdt_pack(fdt);
+			}
+		}
+	}
+	return ret;
+}
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
new file mode 100644
index 0000000000..d1ff25d531
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2021 NXP
+ */
+#ifndef __DT_OPTEE_H__
+#define __DT_OPTEE_H__
+
+extern unsigned long rom_pointer[];
+int ft_add_optee_overlay(void *fdt, struct bd_info *bd);
+#endif
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
index f1624ff30a..0824c62264 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
@@ -31,6 +31,7 @@
 #endif
 #include <asm/arch/speed.h>
 #include <fsl_qbman.h>
+#include "dt_optee.h"
 
 int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
 {
@@ -698,3 +699,14 @@ void ft_cpu_setup(void *blob, struct bd_info *bd)
 	fdt_fixup_ecam(blob);
 #endif
 }
+
+#ifdef CONFIG_OF_SYSTEM_SETUP
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+#ifdef CONFIG_OF_LIBFDT_OVERLAY
+	return ft_add_optee_overlay(blob, bd);
+#else
+	return 0;
+#endif
+}
+#endif
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S
new file mode 100644
index 0000000000..1d6a2d85fa
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2021 NXP
+ */
+
+#include <config.h>
+
+.align 8
+.global rom_pointer
+rom_pointer:
+	.space 32
+
+/*
+ * Routine: save_boot_params (called after reset from start.S)
+ */
+
+.global save_boot_params
+save_boot_params:
+	/* The firmware provided FDT address can be found in r2/x0 */
+	adr	x0, rom_pointer
+	stp	x1, x2, [x0], #16
+	stp	x3, x4, [x0], #16
+
+	ldr	x1, =save_boot_params_ret
+	br	x1
-- 
2.17.1


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

* [PATCH 1/2] fsl-layerscape: add dtb overlay feature
@ 2021-11-16  8:34 Sahil Malhotra
  0 siblings, 0 replies; 26+ messages in thread
From: Sahil Malhotra @ 2021-11-16  8:34 UTC (permalink / raw)
  To: u-boot, v.sethi, priyanka.jain, ye.li, clement.faure,
	gaurav.jain, pankaj.gupta
  Cc: Sahil Malhotra

This patch enables the DTB overlay feature for LS platforms.

Signed-off-by: Sahil Malhotra <sahil.malhotra@nxp.com>
---
 arch/arm/cpu/armv8/fsl-layerscape/Makefile    |  1 +
 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c  | 39 +++++++++++++++++++
 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h  | 10 +++++
 arch/arm/cpu/armv8/fsl-layerscape/fdt.c       | 12 ++++++
 .../cpu/armv8/fsl-layerscape/lowlevel_init.S  | 25 ++++++++++++
 5 files changed, 87 insertions(+)
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Makefile b/arch/arm/cpu/armv8/fsl-layerscape/Makefile
index 598c36ee66..97f1f291dd 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Makefile
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Makefile
@@ -7,6 +7,7 @@ obj-y += lowlevel.o
 obj-y += soc.o
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_MP) += mp.o spintable.o
+obj-$(CONFIG_OF_LIBFDT_OVERLAY) += lowlevel_init.o dt_optee.o
 obj-$(CONFIG_OF_LIBFDT) += fdt.o
 endif
 obj-$(CONFIG_SPL) += spl.o
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
new file mode 100644
index 0000000000..2418ad09c7
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2021 NXP
+ */
+#include <common.h>
+#include <errno.h>
+#include <fdt_support.h>
+#include <linux/sizes.h>
+#include "dt_optee.h"
+
+int ft_add_optee_overlay(void *fdt, struct bd_info *bd)
+{
+	int ret = 0;
+
+	/*
+	 * No BL32_BASE passed means no TEE running, so no
+	 * need to add optee node in dts
+	 */
+	if (!rom_pointer[0]) {
+		debug("No BL32_BASE passed means no TEE running\n");
+		return ret;
+	}
+
+	if (rom_pointer[2]) {
+		debug("OP-TEE: applying overlay on 0x%lx\n", rom_pointer[2]);
+		ret = fdt_check_header((void *)rom_pointer[2]);
+		if (ret == 0) {
+			/* Copy the fdt overlay to next 1M and use copied overlay */
+			memcpy((void *)(rom_pointer[2] + SZ_1M), (void *)rom_pointer[2],
+			       fdt_totalsize((void *)rom_pointer[2]));
+			ret = fdt_overlay_apply_verbose(fdt, (void *)(rom_pointer[2] + SZ_1M));
+			if (ret == 0) {
+				debug("Overlay applied with success");
+				fdt_pack(fdt);
+			}
+		}
+	}
+	return ret;
+}
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
new file mode 100644
index 0000000000..d1ff25d531
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2021 NXP
+ */
+#ifndef __DT_OPTEE_H__
+#define __DT_OPTEE_H__
+
+extern unsigned long rom_pointer[];
+int ft_add_optee_overlay(void *fdt, struct bd_info *bd);
+#endif
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
index f1624ff30a..0824c62264 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
@@ -31,6 +31,7 @@
 #endif
 #include <asm/arch/speed.h>
 #include <fsl_qbman.h>
+#include "dt_optee.h"
 
 int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
 {
@@ -698,3 +699,14 @@ void ft_cpu_setup(void *blob, struct bd_info *bd)
 	fdt_fixup_ecam(blob);
 #endif
 }
+
+#ifdef CONFIG_OF_SYSTEM_SETUP
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+#ifdef CONFIG_OF_LIBFDT_OVERLAY
+	return ft_add_optee_overlay(blob, bd);
+#else
+	return 0;
+#endif
+}
+#endif
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S
new file mode 100644
index 0000000000..1d6a2d85fa
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2021 NXP
+ */
+
+#include <config.h>
+
+.align 8
+.global rom_pointer
+rom_pointer:
+	.space 32
+
+/*
+ * Routine: save_boot_params (called after reset from start.S)
+ */
+
+.global save_boot_params
+save_boot_params:
+	/* The firmware provided FDT address can be found in r2/x0 */
+	adr	x0, rom_pointer
+	stp	x1, x2, [x0], #16
+	stp	x3, x4, [x0], #16
+
+	ldr	x1, =save_boot_params_ret
+	br	x1
-- 
2.17.1


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

* [PATCH 1/2] fsl-layerscape: add dtb overlay feature
@ 2021-11-16  8:30 Sahil Malhotra
  0 siblings, 0 replies; 26+ messages in thread
From: Sahil Malhotra @ 2021-11-16  8:30 UTC (permalink / raw)
  To: u-boot, v.sethi, priyanka.jain, ye.li, clement.faure,
	gaurav.jain, pankaj.gupta
  Cc: Sahil Malhotra

From: Sahil Malhotra <sahil.malhotra@nxp.com>

This patch enables the DTB overlay feature for LS platforms.

Signed-off-by: Sahil Malhotra <sahil.malhotra@nxp.com>
---
 arch/arm/cpu/armv8/fsl-layerscape/Makefile    |  1 +
 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c  | 39 +++++++++++++++++++
 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h  | 10 +++++
 arch/arm/cpu/armv8/fsl-layerscape/fdt.c       | 12 ++++++
 .../cpu/armv8/fsl-layerscape/lowlevel_init.S  | 25 ++++++++++++
 5 files changed, 87 insertions(+)
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Makefile b/arch/arm/cpu/armv8/fsl-layerscape/Makefile
index 598c36ee66..97f1f291dd 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Makefile
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Makefile
@@ -7,6 +7,7 @@ obj-y += lowlevel.o
 obj-y += soc.o
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_MP) += mp.o spintable.o
+obj-$(CONFIG_OF_LIBFDT_OVERLAY) += lowlevel_init.o dt_optee.o
 obj-$(CONFIG_OF_LIBFDT) += fdt.o
 endif
 obj-$(CONFIG_SPL) += spl.o
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
new file mode 100644
index 0000000000..2418ad09c7
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2021 NXP
+ */
+#include <common.h>
+#include <errno.h>
+#include <fdt_support.h>
+#include <linux/sizes.h>
+#include "dt_optee.h"
+
+int ft_add_optee_overlay(void *fdt, struct bd_info *bd)
+{
+	int ret = 0;
+
+	/*
+	 * No BL32_BASE passed means no TEE running, so no
+	 * need to add optee node in dts
+	 */
+	if (!rom_pointer[0]) {
+		debug("No BL32_BASE passed means no TEE running\n");
+		return ret;
+	}
+
+	if (rom_pointer[2]) {
+		debug("OP-TEE: applying overlay on 0x%lx\n", rom_pointer[2]);
+		ret = fdt_check_header((void *)rom_pointer[2]);
+		if (ret == 0) {
+			/* Copy the fdt overlay to next 1M and use copied overlay */
+			memcpy((void *)(rom_pointer[2] + SZ_1M), (void *)rom_pointer[2],
+			       fdt_totalsize((void *)rom_pointer[2]));
+			ret = fdt_overlay_apply_verbose(fdt, (void *)(rom_pointer[2] + SZ_1M));
+			if (ret == 0) {
+				debug("Overlay applied with success");
+				fdt_pack(fdt);
+			}
+		}
+	}
+	return ret;
+}
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
new file mode 100644
index 0000000000..d1ff25d531
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2021 NXP
+ */
+#ifndef __DT_OPTEE_H__
+#define __DT_OPTEE_H__
+
+extern unsigned long rom_pointer[];
+int ft_add_optee_overlay(void *fdt, struct bd_info *bd);
+#endif
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
index f1624ff30a..0824c62264 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
@@ -31,6 +31,7 @@
 #endif
 #include <asm/arch/speed.h>
 #include <fsl_qbman.h>
+#include "dt_optee.h"
 
 int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
 {
@@ -698,3 +699,14 @@ void ft_cpu_setup(void *blob, struct bd_info *bd)
 	fdt_fixup_ecam(blob);
 #endif
 }
+
+#ifdef CONFIG_OF_SYSTEM_SETUP
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+#ifdef CONFIG_OF_LIBFDT_OVERLAY
+	return ft_add_optee_overlay(blob, bd);
+#else
+	return 0;
+#endif
+}
+#endif
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S
new file mode 100644
index 0000000000..1d6a2d85fa
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2021 NXP
+ */
+
+#include <config.h>
+
+.align 8
+.global rom_pointer
+rom_pointer:
+	.space 32
+
+/*
+ * Routine: save_boot_params (called after reset from start.S)
+ */
+
+.global save_boot_params
+save_boot_params:
+	/* The firmware provided FDT address can be found in r2/x0 */
+	adr	x0, rom_pointer
+	stp	x1, x2, [x0], #16
+	stp	x3, x4, [x0], #16
+
+	ldr	x1, =save_boot_params_ret
+	br	x1
-- 
2.17.1


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

* [PATCH 1/2] fsl-layerscape: add dtb overlay feature
@ 2021-11-16  6:49 Sahil Malhotra
  0 siblings, 0 replies; 26+ messages in thread
From: Sahil Malhotra @ 2021-11-16  6:49 UTC (permalink / raw)
  To: u-boot, v.sethi, priyanka.jain, ye.li, clement.faure,
	gaurav.jain, pankaj.gupta
  Cc: Sahil Malhotra

This patch enables the DTB overlay feature for LS platforms.

Signed-off-by: Sahil Malhotra <sahil.malhotra@nxp.com>
---
 arch/arm/cpu/armv8/fsl-layerscape/Makefile    |  1 +
 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c  | 39 +++++++++++++++++++
 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h  | 10 +++++
 arch/arm/cpu/armv8/fsl-layerscape/fdt.c       | 12 ++++++
 .../cpu/armv8/fsl-layerscape/lowlevel_init.S  | 25 ++++++++++++
 5 files changed, 87 insertions(+)
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Makefile b/arch/arm/cpu/armv8/fsl-layerscape/Makefile
index 598c36ee66..97f1f291dd 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Makefile
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Makefile
@@ -7,6 +7,7 @@ obj-y += lowlevel.o
 obj-y += soc.o
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_MP) += mp.o spintable.o
+obj-$(CONFIG_OF_LIBFDT_OVERLAY) += lowlevel_init.o dt_optee.o
 obj-$(CONFIG_OF_LIBFDT) += fdt.o
 endif
 obj-$(CONFIG_SPL) += spl.o
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
new file mode 100644
index 0000000000..2418ad09c7
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2021 NXP
+ */
+#include <common.h>
+#include <errno.h>
+#include <fdt_support.h>
+#include <linux/sizes.h>
+#include "dt_optee.h"
+
+int ft_add_optee_overlay(void *fdt, struct bd_info *bd)
+{
+	int ret = 0;
+
+	/*
+	 * No BL32_BASE passed means no TEE running, so no
+	 * need to add optee node in dts
+	 */
+	if (!rom_pointer[0]) {
+		debug("No BL32_BASE passed means no TEE running\n");
+		return ret;
+	}
+
+	if (rom_pointer[2]) {
+		debug("OP-TEE: applying overlay on 0x%lx\n", rom_pointer[2]);
+		ret = fdt_check_header((void *)rom_pointer[2]);
+		if (ret == 0) {
+			/* Copy the fdt overlay to next 1M and use copied overlay */
+			memcpy((void *)(rom_pointer[2] + SZ_1M), (void *)rom_pointer[2],
+			       fdt_totalsize((void *)rom_pointer[2]));
+			ret = fdt_overlay_apply_verbose(fdt, (void *)(rom_pointer[2] + SZ_1M));
+			if (ret == 0) {
+				debug("Overlay applied with success");
+				fdt_pack(fdt);
+			}
+		}
+	}
+	return ret;
+}
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
new file mode 100644
index 0000000000..d1ff25d531
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2021 NXP
+ */
+#ifndef __DT_OPTEE_H__
+#define __DT_OPTEE_H__
+
+extern unsigned long rom_pointer[];
+int ft_add_optee_overlay(void *fdt, struct bd_info *bd);
+#endif
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
index f1624ff30a..0824c62264 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
@@ -31,6 +31,7 @@
 #endif
 #include <asm/arch/speed.h>
 #include <fsl_qbman.h>
+#include "dt_optee.h"
 
 int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
 {
@@ -698,3 +699,14 @@ void ft_cpu_setup(void *blob, struct bd_info *bd)
 	fdt_fixup_ecam(blob);
 #endif
 }
+
+#ifdef CONFIG_OF_SYSTEM_SETUP
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+#ifdef CONFIG_OF_LIBFDT_OVERLAY
+	return ft_add_optee_overlay(blob, bd);
+#else
+	return 0;
+#endif
+}
+#endif
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S
new file mode 100644
index 0000000000..1d6a2d85fa
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2021 NXP
+ */
+
+#include <config.h>
+
+.align 8
+.global rom_pointer
+rom_pointer:
+	.space 32
+
+/*
+ * Routine: save_boot_params (called after reset from start.S)
+ */
+
+.global save_boot_params
+save_boot_params:
+	/* The firmware provided FDT address can be found in r2/x0 */
+	adr	x0, rom_pointer
+	stp	x1, x2, [x0], #16
+	stp	x3, x4, [x0], #16
+
+	ldr	x1, =save_boot_params_ret
+	br	x1
-- 
2.17.1


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

* [PATCH 1/2] fsl-layerscape: add dtb overlay feature
@ 2021-11-16  6:46 Sahil Malhotra
  0 siblings, 0 replies; 26+ messages in thread
From: Sahil Malhotra @ 2021-11-16  6:46 UTC (permalink / raw)
  To: u-boot, v.sethi, priyanka.jain, ye.li, clement.faure,
	gaurav.jain, pankaj.gupta
  Cc: Sahil Malhotra

From: Sahil Malhotra <sahil.malhotra@nxp.com>

This patch enables the DTB overlay feature for LS platforms.

Signed-off-by: Sahil Malhotra <sahil.malhotra@nxp.com>
---
 arch/arm/cpu/armv8/fsl-layerscape/Makefile    |  1 +
 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c  | 39 +++++++++++++++++++
 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h  | 10 +++++
 arch/arm/cpu/armv8/fsl-layerscape/fdt.c       | 12 ++++++
 .../cpu/armv8/fsl-layerscape/lowlevel_init.S  | 25 ++++++++++++
 5 files changed, 87 insertions(+)
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Makefile b/arch/arm/cpu/armv8/fsl-layerscape/Makefile
index 598c36ee66..97f1f291dd 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Makefile
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Makefile
@@ -7,6 +7,7 @@ obj-y += lowlevel.o
 obj-y += soc.o
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_MP) += mp.o spintable.o
+obj-$(CONFIG_OF_LIBFDT_OVERLAY) += lowlevel_init.o dt_optee.o
 obj-$(CONFIG_OF_LIBFDT) += fdt.o
 endif
 obj-$(CONFIG_SPL) += spl.o
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
new file mode 100644
index 0000000000..2418ad09c7
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2021 NXP
+ */
+#include <common.h>
+#include <errno.h>
+#include <fdt_support.h>
+#include <linux/sizes.h>
+#include "dt_optee.h"
+
+int ft_add_optee_overlay(void *fdt, struct bd_info *bd)
+{
+	int ret = 0;
+
+	/*
+	 * No BL32_BASE passed means no TEE running, so no
+	 * need to add optee node in dts
+	 */
+	if (!rom_pointer[0]) {
+		debug("No BL32_BASE passed means no TEE running\n");
+		return ret;
+	}
+
+	if (rom_pointer[2]) {
+		debug("OP-TEE: applying overlay on 0x%lx\n", rom_pointer[2]);
+		ret = fdt_check_header((void *)rom_pointer[2]);
+		if (ret == 0) {
+			/* Copy the fdt overlay to next 1M and use copied overlay */
+			memcpy((void *)(rom_pointer[2] + SZ_1M), (void *)rom_pointer[2],
+			       fdt_totalsize((void *)rom_pointer[2]));
+			ret = fdt_overlay_apply_verbose(fdt, (void *)(rom_pointer[2] + SZ_1M));
+			if (ret == 0) {
+				debug("Overlay applied with success");
+				fdt_pack(fdt);
+			}
+		}
+	}
+	return ret;
+}
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
new file mode 100644
index 0000000000..d1ff25d531
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2021 NXP
+ */
+#ifndef __DT_OPTEE_H__
+#define __DT_OPTEE_H__
+
+extern unsigned long rom_pointer[];
+int ft_add_optee_overlay(void *fdt, struct bd_info *bd);
+#endif
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
index f1624ff30a..0824c62264 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
@@ -31,6 +31,7 @@
 #endif
 #include <asm/arch/speed.h>
 #include <fsl_qbman.h>
+#include "dt_optee.h"
 
 int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
 {
@@ -698,3 +699,14 @@ void ft_cpu_setup(void *blob, struct bd_info *bd)
 	fdt_fixup_ecam(blob);
 #endif
 }
+
+#ifdef CONFIG_OF_SYSTEM_SETUP
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+#ifdef CONFIG_OF_LIBFDT_OVERLAY
+	return ft_add_optee_overlay(blob, bd);
+#else
+	return 0;
+#endif
+}
+#endif
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S
new file mode 100644
index 0000000000..1d6a2d85fa
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2021 NXP
+ */
+
+#include <config.h>
+
+.align 8
+.global rom_pointer
+rom_pointer:
+	.space 32
+
+/*
+ * Routine: save_boot_params (called after reset from start.S)
+ */
+
+.global save_boot_params
+save_boot_params:
+	/* The firmware provided FDT address can be found in r2/x0 */
+	adr	x0, rom_pointer
+	stp	x1, x2, [x0], #16
+	stp	x3, x4, [x0], #16
+
+	ldr	x1, =save_boot_params_ret
+	br	x1
-- 
2.17.1


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

* [PATCH 1/2] fsl-layerscape: add dtb overlay feature
@ 2021-11-16  6:37 Sahil Malhotra
  0 siblings, 0 replies; 26+ messages in thread
From: Sahil Malhotra @ 2021-11-16  6:37 UTC (permalink / raw)
  To: u-boot, v.sethi, priyanka.jain, ye.li, clement.faure,
	gaurav.jain, pankaj.gupta, sahil.malhotra

From: Sahil Malhotra <sahil.malhotra@nxp.com>

This patch enables the DTB overlay feature for LS platforms.

Signed-off-by: Sahil Malhotra <sahil.malhotra@nxp.com>
---
 arch/arm/cpu/armv8/fsl-layerscape/Makefile    |  1 +
 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c  | 39 +++++++++++++++++++
 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h  | 10 +++++
 arch/arm/cpu/armv8/fsl-layerscape/fdt.c       | 12 ++++++
 .../cpu/armv8/fsl-layerscape/lowlevel_init.S  | 25 ++++++++++++
 5 files changed, 87 insertions(+)
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
 create mode 100644 arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Makefile b/arch/arm/cpu/armv8/fsl-layerscape/Makefile
index 598c36ee66..97f1f291dd 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Makefile
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Makefile
@@ -7,6 +7,7 @@ obj-y += lowlevel.o
 obj-y += soc.o
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_MP) += mp.o spintable.o
+obj-$(CONFIG_OF_LIBFDT_OVERLAY) += lowlevel_init.o dt_optee.o
 obj-$(CONFIG_OF_LIBFDT) += fdt.o
 endif
 obj-$(CONFIG_SPL) += spl.o
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
new file mode 100644
index 0000000000..2418ad09c7
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2021 NXP
+ */
+#include <common.h>
+#include <errno.h>
+#include <fdt_support.h>
+#include <linux/sizes.h>
+#include "dt_optee.h"
+
+int ft_add_optee_overlay(void *fdt, struct bd_info *bd)
+{
+	int ret = 0;
+
+	/*
+	 * No BL32_BASE passed means no TEE running, so no
+	 * need to add optee node in dts
+	 */
+	if (!rom_pointer[0]) {
+		debug("No BL32_BASE passed means no TEE running\n");
+		return ret;
+	}
+
+	if (rom_pointer[2]) {
+		debug("OP-TEE: applying overlay on 0x%lx\n", rom_pointer[2]);
+		ret = fdt_check_header((void *)rom_pointer[2]);
+		if (ret == 0) {
+			/* Copy the fdt overlay to next 1M and use copied overlay */
+			memcpy((void *)(rom_pointer[2] + SZ_1M), (void *)rom_pointer[2],
+			       fdt_totalsize((void *)rom_pointer[2]));
+			ret = fdt_overlay_apply_verbose(fdt, (void *)(rom_pointer[2] + SZ_1M));
+			if (ret == 0) {
+				debug("Overlay applied with success");
+				fdt_pack(fdt);
+			}
+		}
+	}
+	return ret;
+}
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
new file mode 100644
index 0000000000..d1ff25d531
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/dt_optee.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2021 NXP
+ */
+#ifndef __DT_OPTEE_H__
+#define __DT_OPTEE_H__
+
+extern unsigned long rom_pointer[];
+int ft_add_optee_overlay(void *fdt, struct bd_info *bd);
+#endif
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
index f1624ff30a..0824c62264 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
@@ -31,6 +31,7 @@
 #endif
 #include <asm/arch/speed.h>
 #include <fsl_qbman.h>
+#include "dt_optee.h"
 
 int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
 {
@@ -698,3 +699,14 @@ void ft_cpu_setup(void *blob, struct bd_info *bd)
 	fdt_fixup_ecam(blob);
 #endif
 }
+
+#ifdef CONFIG_OF_SYSTEM_SETUP
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+#ifdef CONFIG_OF_LIBFDT_OVERLAY
+	return ft_add_optee_overlay(blob, bd);
+#else
+	return 0;
+#endif
+}
+#endif
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S
new file mode 100644
index 0000000000..1d6a2d85fa
--- /dev/null
+++ b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel_init.S
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2021 NXP
+ */
+
+#include <config.h>
+
+.align 8
+.global rom_pointer
+rom_pointer:
+	.space 32
+
+/*
+ * Routine: save_boot_params (called after reset from start.S)
+ */
+
+.global save_boot_params
+save_boot_params:
+	/* The firmware provided FDT address can be found in r2/x0 */
+	adr	x0, rom_pointer
+	stp	x1, x2, [x0], #16
+	stp	x3, x4, [x0], #16
+
+	ldr	x1, =save_boot_params_ret
+	br	x1
-- 
2.17.1


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

end of thread, other threads:[~2022-02-24 12:34 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-17  6:23 [PATCH 1/2] fsl-layerscape: add dtb overlay feature Sahil Malhotra
2021-11-17  6:23 ` [PATCH 2/2] configs: enabled DTB overlay feature for LS SoCs Sahil Malhotra
2021-11-17  7:53 ` [PATCH 1/2] fsl-layerscape: add dtb overlay feature Michael Walle
2021-11-17 18:11   ` Sahil Malhotra (OSS)
2021-11-17 18:20     ` Michael Walle
2021-11-29 11:55       ` Sahil Malhotra (OSS)
2021-11-29 17:47         ` Michael Walle
2021-12-08  6:12           ` Sahil Malhotra (OSS)
2021-12-08 10:13             ` ZHIZHIKIN Andrey
2021-12-10  6:33               ` Sahil Malhotra (OSS)
2021-12-17  6:19                 ` Sahil Malhotra (OSS)
2021-12-17  7:27                   ` Michael Walle
2021-12-20 12:52                 ` Michael Walle
2021-12-23  8:46                   ` [EXT] " Sahil Malhotra (OSS)
2021-12-23  9:34                     ` Michael Walle
2021-12-10  7:38           ` François Ozog
  -- strict thread matches above, loose matches on Subject: below --
2022-01-06  6:09 Sahil Malhotra (OSS)
2022-01-06  7:40 ` Michael Walle
2022-02-04 11:27   ` Sahil Malhotra (OSS)
2022-02-24 10:59     ` Sahil Malhotra (OSS)
2022-02-24 12:33       ` Michael Walle
2021-11-16 10:16 Sahil Malhotra
2021-11-16  8:34 Sahil Malhotra
2021-11-16  8:30 Sahil Malhotra
2021-11-16  6:49 Sahil Malhotra
2021-11-16  6:46 Sahil Malhotra
2021-11-16  6:37 Sahil Malhotra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).