[PATCH v7 15/15] update CAAM MAINTAINER

2021-12-06 Thread Gaurav Jain
updated CAAM driver files maintainer.

Signed-off-by: Gaurav Jain 
---
 MAINTAINERS | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 6db5354322..c5bb2b861b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1296,3 +1296,9 @@ T:git https://source.denx.de/u-boot/u-boot.git
 F: configs/tools-only_defconfig
 F: *
 F: */
+
+CAAM
+M: Gaurav Jain 
+S: Maintained
+F: drivers/crypto/fsl/
+F: include/fsl_sec.h
-- 
2.17.1



[PATCH v7 14/15] PPC: Enable Job ring driver model in U-Boot

2021-12-06 Thread Gaurav Jain
removed sec_init() call and CONFIG_FSL_CAAM from defconfig.
sec is initialized based on job ring information processed
from device tree.

Signed-off-by: Gaurav Jain 
Reviewed-by: Priyanka Jain 
---
 arch/powerpc/cpu/mpc85xx/Kconfig  | 33 +++
 arch/powerpc/cpu/mpc85xx/cpu_init.c   | 17 --
 arch/powerpc/include/asm/u-boot-ppc.h | 17 ++
 arch/powerpc/include/asm/u-boot.h |  1 +
 configs/P2041RDB_defconfig|  1 -
 configs/P3041DS_defconfig |  1 -
 configs/P4080DS_defconfig |  1 -
 configs/P5040DS_defconfig |  1 -
 configs/T1024RDB_defconfig|  1 -
 configs/T1042D4RDB_defconfig  |  1 -
 configs/T2080QDS_defconfig|  1 -
 configs/T2080RDB_defconfig|  1 -
 configs/T2080RDB_revD_defconfig   |  1 -
 configs/T4240RDB_defconfig|  1 -
 14 files changed, 66 insertions(+), 12 deletions(-)
 create mode 100644 arch/powerpc/include/asm/u-boot-ppc.h

diff --git a/arch/powerpc/cpu/mpc85xx/Kconfig b/arch/powerpc/cpu/mpc85xx/Kconfig
index 836aeddbe2..b05c372086 100644
--- a/arch/powerpc/cpu/mpc85xx/Kconfig
+++ b/arch/powerpc/cpu/mpc85xx/Kconfig
@@ -25,6 +25,9 @@ config TARGET_P3041DS
select PHYS_64BIT
select ARCH_P3041
select BOARD_LATE_INIT if CHAIN_OF_TRUST
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
imply CMD_SATA
imply PANIC_HANG
 
@@ -33,6 +36,9 @@ config TARGET_P4080DS
select PHYS_64BIT
select ARCH_P4080
select BOARD_LATE_INIT if CHAIN_OF_TRUST
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
imply CMD_SATA
imply PANIC_HANG
 
@@ -41,6 +47,9 @@ config TARGET_P5040DS
select PHYS_64BIT
select ARCH_P5040
select BOARD_LATE_INIT if CHAIN_OF_TRUST
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
imply CMD_SATA
imply PANIC_HANG
 
@@ -102,6 +111,9 @@ config TARGET_P2041RDB
select ARCH_P2041
select BOARD_LATE_INIT if CHAIN_OF_TRUST
select PHYS_64BIT
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
imply CMD_SATA
imply FSL_SATA
 
@@ -117,6 +129,9 @@ config TARGET_T1024RDB
select SUPPORT_SPL
select PHYS_64BIT
select FSL_DDR_INTERACTIVE
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
imply CMD_EEPROM
imply PANIC_HANG
 
@@ -126,6 +141,9 @@ config TARGET_T1042RDB
select BOARD_LATE_INIT if CHAIN_OF_TRUST
select SUPPORT_SPL
select PHYS_64BIT
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
 
 config TARGET_T1042D4RDB
bool "Support T1042D4RDB"
@@ -133,6 +151,9 @@ config TARGET_T1042D4RDB
select BOARD_LATE_INIT if CHAIN_OF_TRUST
select SUPPORT_SPL
select PHYS_64BIT
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
imply PANIC_HANG
 
 config TARGET_T1042RDB_PI
@@ -141,6 +162,9 @@ config TARGET_T1042RDB_PI
select BOARD_LATE_INIT if CHAIN_OF_TRUST
select SUPPORT_SPL
select PHYS_64BIT
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
imply PANIC_HANG
 
 config TARGET_T2080QDS
@@ -151,6 +175,9 @@ config TARGET_T2080QDS
select PHYS_64BIT
select FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
select FSL_DDR_INTERACTIVE
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
imply CMD_SATA
 
 config TARGET_T2080RDB
@@ -159,6 +186,9 @@ config TARGET_T2080RDB
select BOARD_LATE_INIT if CHAIN_OF_TRUST
select SUPPORT_SPL
select PHYS_64BIT
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
imply CMD_SATA
imply PANIC_HANG
 
@@ -168,6 +198,9 @@ config TARGET_T4240RDB
select SUPPORT_SPL
select PHYS_64BIT
select FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
imply CMD_SATA
imply PANIC_HANG
 
diff --git a/arch/powerpc/cpu/mpc85xx/cpu_init.c 
b/arch/powerpc/cpu/mpc85xx/cpu_init.c
index e920e01b25..728c6447a8 100644
--- a/arch/powerpc/cpu/mpc85xx/cpu_init.c
+++ b/arch/powerpc/cpu/mpc85xx/cpu_init.c
@@ -56,6 +56,7 @@
 #ifdef CONFIG_U_QE
 #include 
 #endif
+#include 
 
 #ifdef CONFIG_SYS_FSL_SINGLE_SOURCE_CLK
 /*
@@ -974,8 +975,6 @@ int cpu_init_r(void)
 #endif
 
 #ifdef CONFIG_FSL_CAAM
-   sec_init();
-
 #if defined(CONFIG_ARCH_C29X)
if ((SVR_SOC_VER(svr) == SVR_C292) ||
(SVR_SOC_VER(svr) == SVR_C293))
@@ -1014,6 +1013,20 @@ int cpu_init_r(void)
return 0;
 }
 
+#ifdef CONFIG_ARCH_MISC_INIT
+int arch_misc_init(void)
+{
+   struct udevice *dev;
+   int ret;
+
+   ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), 
);
+   if (ret)
+   

[PATCH v7 13/15] PPC: Add crypto node in device tree

2021-12-06 Thread Gaurav Jain
device tree imported from linux kernel.
c500bee1c5b2 (tag: v5.14-rc4) Linux 5.14-rc4

Signed-off-by: Gaurav Jain 
Reviewed-by: Priyanka Jain 
---
 arch/powerpc/dts/p2041si-post.dtsi   |  1 +
 arch/powerpc/dts/p3041si-post.dtsi   |  1 +
 arch/powerpc/dts/p4080si-post.dtsi   |  1 +
 arch/powerpc/dts/p5040si-post.dtsi   |  1 +
 arch/powerpc/dts/qoriq-sec4.0-0.dtsi | 74 ++
 arch/powerpc/dts/qoriq-sec4.2-0.dtsi | 83 +
 arch/powerpc/dts/qoriq-sec5.2-0.dtsi | 92 
 arch/powerpc/dts/t1023si-post.dtsi   |  1 +
 arch/powerpc/dts/t1042si-post.dtsi   |  1 +
 arch/powerpc/dts/t2080si-post.dtsi   |  1 +
 arch/powerpc/dts/t4240si-post.dtsi   |  1 +
 11 files changed, 257 insertions(+)
 create mode 100644 arch/powerpc/dts/qoriq-sec4.0-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-sec4.2-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-sec5.2-0.dtsi

diff --git a/arch/powerpc/dts/p2041si-post.dtsi 
b/arch/powerpc/dts/p2041si-post.dtsi
index 01ab395950..8819199646 100644
--- a/arch/powerpc/dts/p2041si-post.dtsi
+++ b/arch/powerpc/dts/p2041si-post.dtsi
@@ -11,6 +11,7 @@
 
 /include/ "qoriq-clockgen1.dtsi"
 /include/ "qoriq-gpio-0.dtsi"
+/include/ "qoriq-sec4.2-0.dtsi"
 
 /* include used FMan blocks */
 /include/ "qoriq-fman-0.dtsi"
diff --git a/arch/powerpc/dts/p3041si-post.dtsi 
b/arch/powerpc/dts/p3041si-post.dtsi
index 21f322f06f..a3e8088d25 100644
--- a/arch/powerpc/dts/p3041si-post.dtsi
+++ b/arch/powerpc/dts/p3041si-post.dtsi
@@ -11,6 +11,7 @@
 
 /include/ "qoriq-clockgen1.dtsi"
 /include/ "qoriq-gpio-0.dtsi"
+/include/ "qoriq-sec4.2-0.dtsi"
 
 /* include used FMan blocks */
 /include/ "qoriq-fman-0.dtsi"
diff --git a/arch/powerpc/dts/p4080si-post.dtsi 
b/arch/powerpc/dts/p4080si-post.dtsi
index 7c3f2fb92e..56b79b14f4 100644
--- a/arch/powerpc/dts/p4080si-post.dtsi
+++ b/arch/powerpc/dts/p4080si-post.dtsi
@@ -11,6 +11,7 @@
 
 /include/ "qoriq-clockgen1.dtsi"
 /include/ "qoriq-gpio-0.dtsi"
+/include/ "qoriq-sec4.0-0.dtsi"
 
 /* include used FMan blocks */
 /include/ "qoriq-fman-0.dtsi"
diff --git a/arch/powerpc/dts/p5040si-post.dtsi 
b/arch/powerpc/dts/p5040si-post.dtsi
index 1efad2d017..fae3ed31a5 100644
--- a/arch/powerpc/dts/p5040si-post.dtsi
+++ b/arch/powerpc/dts/p5040si-post.dtsi
@@ -11,6 +11,7 @@
 
 /include/ "qoriq-clockgen1.dtsi"
 /include/ "qoriq-gpio-0.dtsi"
+/include/ "qoriq-sec5.2-0.dtsi"
 
 /* include used FMan blocks */
 /include/ "qoriq-fman-0.dtsi"
diff --git a/arch/powerpc/dts/qoriq-sec4.0-0.dtsi 
b/arch/powerpc/dts/qoriq-sec4.0-0.dtsi
new file mode 100644
index 00..ff348d70f1
--- /dev/null
+++ b/arch/powerpc/dts/qoriq-sec4.0-0.dtsi
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-3-Clause)
+/*
+ * QorIQ Sec/Crypto 4.0 device tree stub [ controller @ offset 0x30 ]
+ *
+ * Copyright 2011 Freescale Semiconductor Inc.
+ */
+
+crypto: crypto@30 {
+   compatible = "fsl,sec-v4.0";
+   fsl,sec-era = <1>;
+   #address-cells = <1>;
+   #size-cells = <1>;
+   reg = <0x30 0x1>;
+   ranges = <0 0x30 0x1>;
+   interrupts = <92 2 0 0>;
+
+   sec_jr0: jr@1000 {
+   compatible = "fsl,sec-v4.0-job-ring";
+   reg = <0x1000 0x1000>;
+   interrupts = <88 2 0 0>;
+   };
+
+   sec_jr1: jr@2000 {
+   compatible = "fsl,sec-v4.0-job-ring";
+   reg = <0x2000 0x1000>;
+   interrupts = <89 2 0 0>;
+   };
+
+   sec_jr2: jr@3000 {
+   compatible = "fsl,sec-v4.0-job-ring";
+   reg = <0x3000 0x1000>;
+   interrupts = <90 2 0 0>;
+   };
+
+   sec_jr3: jr@4000 {
+   compatible = "fsl,sec-v4.0-job-ring";
+   reg = <0x4000 0x1000>;
+   interrupts = <91 2 0 0>;
+   };
+
+   rtic@6000 {
+   compatible = "fsl,sec-v4.0-rtic";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   reg = <0x6000 0x100>;
+   ranges = <0x0 0x6100 0xe00>;
+
+   rtic_a: rtic-a@0 {
+   compatible = "fsl,sec-v4.0-rtic-memory";
+   reg = <0x00 0x20 0x100 0x80>;
+   };
+
+   rtic_b: rtic-b@20 {
+   compatible = "fsl,sec-v4.0-rtic-memory";
+   reg = <0x20 0x20 0x200 0x80>;
+   };
+
+   rtic_c: rtic-c@40 {
+   compatible = "fsl,sec-v4.0-rtic-memory";
+   reg = <0x40 0x20 0x300 0x80>;
+   };
+
+   rtic_d: rtic-d@60 {
+   compatible = "fsl,sec-v4.0-rtic-memory";
+   reg = <0x60 0x20 0x500 0x80>;
+   };
+   };
+};
+
+sec_mon: sec_mon@314000 {
+   compatible = "fsl,sec-v4.0-mon";
+   reg = <0x314000 0x1000>;
+   interrupts = <93 2 0 0>;
+};
diff --git a/arch/powerpc/dts/qoriq-sec4.2-0.dtsi 

[PATCH v7 12/15] Layerscape: Enable Job ring driver model in U-Boot.

2021-12-06 Thread Gaurav Jain
LS(1021/1012/1028/1043/1046/1088/2088), LX2160, LX2162
platforms are enabled with JR driver model.

removed sec_init() call from board files.
removed CONFIG_FSL_CAAM from defconfig files.
sec is initialized based on job ring information processed
from device tree.

Signed-off-by: Gaurav Jain 
Reviewed-by: Priyanka Jain 
---
 arch/arm/Kconfig|  4 
 arch/arm/cpu/armv7/ls102xa/Kconfig  |  3 +++
 arch/arm/cpu/armv7/ls102xa/cpu.c| 16 
 arch/arm/cpu/armv8/fsl-layerscape/Kconfig   | 17 +
 arch/arm/cpu/armv8/fsl-layerscape/cpu.c | 10 +-
 board/freescale/ls1012afrdm/ls1012afrdm.c   |  7 +--
 board/freescale/ls1012aqds/ls1012aqds.c |  6 +-
 board/freescale/ls1012ardb/ls1012ardb.c |  6 +-
 board/freescale/ls1021aiot/ls1021aiot.c |  6 ++
 board/freescale/ls1021aqds/ls1021aqds.c |  6 +-
 board/freescale/ls1021atsn/ls1021atsn.c |  7 ++-
 board/freescale/ls1021atwr/ls1021atwr.c |  8 ++--
 board/freescale/ls1028a/ls1028a.c   |  6 +-
 board/freescale/ls1043ardb/ls1043ardb.c |  6 +-
 board/freescale/ls1046afrwy/ls1046afrwy.c   |  7 +--
 board/freescale/ls1046aqds/ls1046aqds.c |  7 +--
 board/freescale/ls1046ardb/ls1046ardb.c |  6 +-
 board/freescale/ls1088a/ls1088a.c   |  6 +-
 board/freescale/ls2080aqds/ls2080aqds.c |  6 +-
 board/freescale/ls2080ardb/ls2080ardb.c |  9 +
 board/freescale/lx2160a/lx2160a.c   |  5 -
 board/kontron/sl28/sl28.c   |  3 ---
 configs/ls1021aiot_qspi_defconfig   |  1 -
 configs/ls1021aqds_nor_defconfig|  1 -
 configs/ls1021aqds_qspi_defconfig   |  1 -
 configs/ls1021atsn_qspi_defconfig   |  1 -
 configs/ls1021atwr_nor_defconfig|  1 -
 .../ls1021atwr_sdcard_ifc_SECURE_BOOT_defconfig |  1 +
 configs/ls1028ardb_tfa_defconfig|  1 -
 configs/ls1043ardb_tfa_defconfig|  1 -
 configs/ls1046afrwy_tfa_defconfig   |  1 -
 configs/ls1046aqds_tfa_defconfig|  1 -
 configs/ls1046ardb_tfa_defconfig|  1 -
 configs/ls2088aqds_tfa_defconfig|  1 -
 configs/ls2088ardb_tfa_defconfig|  1 -
 configs/lx2160aqds_tfa_defconfig|  1 -
 configs/lx2160ardb_tfa_defconfig|  1 -
 configs/lx2162aqds_tfa_defconfig|  1 -
 38 files changed, 68 insertions(+), 105 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 7ce2bbc954..30a34bdd08 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1504,6 +1504,8 @@ config TARGET_LS1028AQDS
select ARCH_SUPPORT_TFABOOT
select BOARD_LATE_INIT
select GPIO_EXTRA_HEADER
+   select FSL_CAAM
+   select MISC
help
  Support for Freescale LS1028AQDS platform
  The LS1028A Development System (QDS) is a high-performance
@@ -1518,6 +1520,8 @@ config TARGET_LS1028ARDB
select ARCH_SUPPORT_TFABOOT
select BOARD_LATE_INIT
select GPIO_EXTRA_HEADER
+   select FSL_CAAM
+   select MISC
help
  Support for Freescale LS1028ARDB platform
  The LS1028A Development System (RDB) is a high-performance
diff --git a/arch/arm/cpu/armv7/ls102xa/Kconfig 
b/arch/arm/cpu/armv7/ls102xa/Kconfig
index f919d02db4..ca006e069f 100644
--- a/arch/arm/cpu/armv7/ls102xa/Kconfig
+++ b/arch/arm/cpu/armv7/ls102xa/Kconfig
@@ -21,6 +21,9 @@ config ARCH_LS1021A
select SYS_FSL_SRDS_1
select SYS_HAS_SERDES
select SYS_I2C_MXC
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
imply CMD_PCI
imply SCSI
imply SCSI_AHCI
diff --git a/arch/arm/cpu/armv7/ls102xa/cpu.c b/arch/arm/cpu/armv7/ls102xa/cpu.c
index d863c9625a..4904592703 100644
--- a/arch/arm/cpu/armv7/ls102xa/cpu.c
+++ b/arch/arm/cpu/armv7/ls102xa/cpu.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2014 Freescale Semiconductor, Inc.
+ * Copyright 2021 NXP
  */
 
 #include 
@@ -20,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "fsl_epu.h"
 
@@ -397,3 +399,17 @@ void arch_preboot_os(void)
ctrl &= ~ARCH_TIMER_CTRL_ENABLE;
asm("mcr p15, 0, %0, c14, c2, 1" : : "r" (ctrl));
 }
+
+#ifdef CONFIG_ARCH_MISC_INIT
+int arch_misc_init(void)
+{
+   struct udevice *dev;
+   int ret;
+
+   ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), 
);
+   if (ret)
+   printf("Failed to initialize %s: %d\n", dev->name, ret);
+
+   return 0;
+}
+#endif
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig 
b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
index 1a057f7059..75d9876dfc 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
+++ 

[PATCH v7 11/15] Layerscape: Add crypto node in device tree

2021-12-06 Thread Gaurav Jain
LS(1021/1012/1028/1043/1046/1088/2088), LX2160 - updated device tree

Signed-off-by: Gaurav Jain 
Reviewed-by: Priyanka Jain 
---
 arch/arm/dts/fsl-ls1012a.dtsi | 46 ++-
 arch/arm/dts/fsl-ls1043a.dtsi | 45 +-
 arch/arm/dts/fsl-ls1046a.dtsi | 44 +
 arch/arm/dts/fsl-ls1088a.dtsi | 39 +
 arch/arm/dts/fsl-ls2080a.dtsi | 39 +
 arch/arm/dts/fsl-lx2160a.dtsi | 41 ++-
 arch/arm/dts/ls1021a.dtsi | 40 ++
 7 files changed, 291 insertions(+), 3 deletions(-)

diff --git a/arch/arm/dts/fsl-ls1012a.dtsi b/arch/arm/dts/fsl-ls1012a.dtsi
index 0ea899c7d7..1cdcc99c1e 100644
--- a/arch/arm/dts/fsl-ls1012a.dtsi
+++ b/arch/arm/dts/fsl-ls1012a.dtsi
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+ OR X11
 /*
- * Copyright 2020 NXP
+ * Copyright 2020-2021 NXP
  * Copyright 2016 Freescale Semiconductor
  */
 
@@ -71,6 +71,50 @@
bus-width = <4>;
};
 
+   crypto: crypto@170 {
+   compatible = "fsl,sec-v5.4", "fsl,sec-v5.0",
+"fsl,sec-v4.0";
+   fsl,sec-era = <8>;
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0x0 0x00 0x170 0x10>;
+   reg = <0x00 0x170 0x0 0x10>;
+   interrupts = <0 75 0x4>;
+   dma-coherent;
+
+   sec_jr0: jr@1 {
+   compatible = "fsl,sec-v5.4-job-ring",
+"fsl,sec-v5.0-job-ring",
+"fsl,sec-v4.0-job-ring";
+   reg= <0x1 0x1>;
+   interrupts = <0 71 0x4>;
+   };
+
+   sec_jr1: jr@2 {
+   compatible = "fsl,sec-v5.4-job-ring",
+"fsl,sec-v5.0-job-ring",
+"fsl,sec-v4.0-job-ring";
+   reg= <0x2 0x1>;
+   interrupts = <0 72 0x4>;
+   };
+
+   sec_jr2: jr@3 {
+   compatible = "fsl,sec-v5.4-job-ring",
+"fsl,sec-v5.0-job-ring",
+"fsl,sec-v4.0-job-ring";
+   reg= <0x3 0x1>;
+   interrupts = <0 73 0x4>;
+   };
+
+   sec_jr3: jr@4 {
+   compatible = "fsl,sec-v5.4-job-ring",
+"fsl,sec-v5.0-job-ring",
+"fsl,sec-v4.0-job-ring";
+   reg= <0x4 0x1>;
+   interrupts = <0 74 0x4>;
+   };
+   };
+
gpio0: gpio@230 {
compatible = "fsl,qoriq-gpio";
reg = <0x0 0x230 0x0 0x1>;
diff --git a/arch/arm/dts/fsl-ls1043a.dtsi b/arch/arm/dts/fsl-ls1043a.dtsi
index 52dc5a9638..72877d2ff5 100644
--- a/arch/arm/dts/fsl-ls1043a.dtsi
+++ b/arch/arm/dts/fsl-ls1043a.dtsi
@@ -2,7 +2,7 @@
 /*
  * Device Tree Include file for NXP Layerscape-1043A family SoC.
  *
- * Copyright 2020 NXP
+ * Copyright 2020-2021 NXP
  * Copyright (C) 2014-2015, Freescale Semiconductor
  *
  * Mingkai Hu 
@@ -125,6 +125,49 @@
interrupts = <0 43 0x4>;
};
 
+   crypto: crypto@170 {
+   compatible = "fsl,sec-v5.4", "fsl,sec-v5.0",
+"fsl,sec-v4.0";
+   fsl,sec-era = <3>;
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0x0 0x00 0x170 0x10>;
+   reg = <0x00 0x170 0x0 0x10>;
+   interrupts = <0 75 0x4>;
+
+   sec_jr0: jr@1 {
+   compatible = "fsl,sec-v5.4-job-ring",
+"fsl,sec-v5.0-job-ring",
+"fsl,sec-v4.0-job-ring";
+   reg= <0x1 0x1>;
+   interrupts = <0 71 0x4>;
+   };
+
+   sec_jr1: jr@2 {
+   compatible = "fsl,sec-v5.4-job-ring",
+"fsl,sec-v5.0-job-ring",
+

[PATCH v7 10/15] crypto/fsl: Improve hwrng performance in kernel

2021-12-06 Thread Gaurav Jain
From: Ye Li 

RNG parameters are reconfigured.
- For TRNG to generate 256 bits of entropy, RNG TRNG Seed Control register
  is configured to have reduced SAMP_SIZE from default 2500 to 512. it is
  number of entropy samples that will be taken during Entropy generation.
- self-test registers(Monobit Limit, Poker Range, Run Length Limit)
  are synchronized with new RTSDCTL[SAMP_SIZE] of 512.

TRNG time is caluculated based on sample size.
time required to generate entropy is reduced and
hwrng performance improved from 0.3 kB/s to 1.3 kB/s.

Signed-off-by: Ye Li 
Acked-by: Gaurav Jain >
---
 drivers/crypto/fsl/jr.c | 102 +---
 include/fsl_sec.h   |   1 +
 2 files changed, 87 insertions(+), 16 deletions(-)

diff --git a/drivers/crypto/fsl/jr.c b/drivers/crypto/fsl/jr.c
index 084a61c684..15f5fd0d05 100644
--- a/drivers/crypto/fsl/jr.c
+++ b/drivers/crypto/fsl/jr.c
@@ -603,30 +603,100 @@ static u8 get_rng_vid(ccsr_sec_t *sec)
  */
 static void kick_trng(int ent_delay, ccsr_sec_t *sec)
 {
+   u32 samples  = 512; /* number of bits to generate and test */
+   u32 mono_min = 195;
+   u32 mono_max = 317;
+   u32 mono_range  = mono_max - mono_min;
+   u32 poker_min = 1031;
+   u32 poker_max = 1600;
+   u32 poker_range = poker_max - poker_min + 1;
+   u32 retries= 2;
+   u32 lrun_max   = 32;
+   s32 run_1_min   = 27;
+   s32 run_1_max   = 107;
+   s32 run_1_range = run_1_max - run_1_min;
+   s32 run_2_min   = 7;
+   s32 run_2_max   = 62;
+   s32 run_2_range = run_2_max - run_2_min;
+   s32 run_3_min   = 0;
+   s32 run_3_max   = 39;
+   s32 run_3_range = run_3_max - run_3_min;
+   s32 run_4_min   = -1;
+   s32 run_4_max   = 26;
+   s32 run_4_range = run_4_max - run_4_min;
+   s32 run_5_min   = -1;
+   s32 run_5_max   = 18;
+   s32 run_5_range = run_5_max - run_5_min;
+   s32 run_6_min   = -1;
+   s32 run_6_max   = 17;
+   s32 run_6_range = run_6_max - run_6_min;
+   u32 val;
+
struct rng4tst __iomem *rng =
(struct rng4tst __iomem *)>rng;
-   u32 val;
 
-   /* put RNG4 into program mode */
-   sec_setbits32(>rtmctl, RTMCTL_PRGM);
-   /* rtsdctl bits 0-15 contain "Entropy Delay, which defines the
-* length (in system clocks) of each Entropy sample taken
-* */
+   /* Put RNG in program mode */
+   /* Setting both RTMCTL:PRGM and RTMCTL:TRNG_ACC causes TRNG to
+* properly invalidate the entropy in the entropy register and
+* force re-generation.
+*/
+   sec_setbits32(>rtmctl, RTMCTL_PRGM | RTMCTL_ACC);
+
+   /* Configure the RNG Entropy Delay
+* Performance-wise, it does not make sense to
+* set the delay to a value that is lower
+* than the last one that worked (i.e. the state handles
+* were instantiated properly. Thus, instead of wasting
+* time trying to set the values controlling the sample
+* frequency, the function simply returns.
+*/
val = sec_in32(>rtsdctl);
-   val = (val & ~RTSDCTL_ENT_DLY_MASK) |
- (ent_delay << RTSDCTL_ENT_DLY_SHIFT);
+   val &= RTSDCTL_ENT_DLY_MASK;
+   val >>= RTSDCTL_ENT_DLY_SHIFT;
+   if (ent_delay < val) {
+   /* Put RNG4 into run mode */
+   sec_clrbits32(>rtmctl, RTMCTL_PRGM | RTMCTL_ACC);
+   return;
+   }
+
+   val = (ent_delay << RTSDCTL_ENT_DLY_SHIFT) | samples;
sec_out32(>rtsdctl, val);
-   /* min. freq. count, equal to 1/4 of the entropy sample length */
-   sec_out32(>rtfreqmin, ent_delay >> 2);
-   /* disable maximum frequency count */
-   sec_out32(>rtfreqmax, RTFRQMAX_DISABLE);
+
+   /*
+* Recommended margins (min,max) for freq. count:
+*   freq_mul = RO_freq / TRNG_clk_freq
+*   rtfrqmin = (ent_delay x freq_mul) >> 1;
+*   rtfrqmax = (ent_delay x freq_mul) << 3;
+* Given current deployments of CAAM in i.MX SoCs, and to simplify
+* the configuration, we consider [1,16] to be a safe interval
+* for the freq_mul and the limits of the interval are used to compute
+* rtfrqmin, rtfrqmax
+*/
+   sec_out32(>rtfreqmin, ent_delay >> 1);
+   sec_out32(>rtfreqmax, ent_delay << 7);
+
+   sec_out32(>rtscmisc, (retries << 16) | lrun_max);
+   sec_out32(>rtpkrmax, poker_max);
+   sec_out32(>rtpkrrng, poker_range);
+   sec_out32(>rsvd1[0], (mono_range << 16) | mono_max);
+   sec_out32(>rsvd1[1], (run_1_range << 16) | run_1_max);
+   sec_out32(>rsvd1[2], (run_2_range << 16) | run_2_max);
+   sec_out32(>rsvd1[3], (run_3_range << 16) | run_3_max);
+   sec_out32(>rsvd1[4], (run_4_range << 16) | run_4_max);
+   sec_out32(>rsvd1[5], (run_5_range << 16) | run_5_max);
+   sec_out32(>rsvd1[6], (run_6_range << 16) | run_6_max);
+
+   val = sec_in32(>rtmctl);
   

[PATCH v7 09/15] crypto/fsl: i.MX8: Enable Job ring driver model in SPL and U-Boot.

2021-12-06 Thread Gaurav Jain
i.MX8(QM/QXP) - added support for JR driver model.
sec is initialized based on job ring information processed
from device tree.

Signed-off-by: Gaurav Jain 
Signed-off-by: Horia Geantă 
Reviewed-by: Ye Li 
---
 arch/arm/Kconfig  |  3 ++
 arch/arm/include/asm/arch-imx8/imx-regs.h |  5 ++-
 arch/arm/mach-imx/cmd_dek.c   |  1 +
 arch/arm/mach-imx/imx8/Kconfig|  7 
 arch/arm/mach-imx/imx8/cpu.c  | 16 +++-
 board/freescale/imx8qm_mek/spl.c  |  6 ++-
 board/freescale/imx8qxp_mek/spl.c |  6 ++-
 drivers/crypto/fsl/Kconfig|  2 +-
 drivers/crypto/fsl/jr.c   | 47 ++-
 include/fsl_sec.h | 12 +++---
 10 files changed, 89 insertions(+), 16 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 524a2204eb..7ce2bbc954 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -804,6 +804,9 @@ config ARCH_LPC32XX
 config ARCH_IMX8
bool "NXP i.MX8 platform"
select ARM64
+   select SYS_FSL_HAS_SEC
+   select SYS_FSL_SEC_COMPAT_4
+   select SYS_FSL_SEC_LE
select DM
select GPIO_EXTRA_HEADER
select MACH_IMX
diff --git a/arch/arm/include/asm/arch-imx8/imx-regs.h 
b/arch/arm/include/asm/arch-imx8/imx-regs.h
index ed6e05e556..2d64b0604b 100644
--- a/arch/arm/include/asm/arch-imx8/imx-regs.h
+++ b/arch/arm/include/asm/arch-imx8/imx-regs.h
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0+ */
 /*
- * Copyright 2018 NXP
+ * Copyright 2018, 2021 NXP
  */
 
 #ifndef __ASM_ARCH_IMX8_REGS_H__
@@ -47,4 +47,7 @@
 #define USB_BASE_ADDR  0x5b0d
 #define USB_PHY0_BASE_ADDR 0x5b10
 
+#define CONFIG_SYS_FSL_SEC_ADDR (0x3140)
+#define CONFIG_SYS_FSL_MAX_NUM_OF_SEC  1
+
 #endif /* __ASM_ARCH_IMX8_REGS_H__ */
diff --git a/arch/arm/mach-imx/cmd_dek.c b/arch/arm/mach-imx/cmd_dek.c
index 89da89c51d..04c4b20a84 100644
--- a/arch/arm/mach-imx/cmd_dek.c
+++ b/arch/arm/mach-imx/cmd_dek.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/mach-imx/imx8/Kconfig b/arch/arm/mach-imx/imx8/Kconfig
index b43739e5c6..f969833bab 100644
--- a/arch/arm/mach-imx/imx8/Kconfig
+++ b/arch/arm/mach-imx/imx8/Kconfig
@@ -8,6 +8,7 @@ config AHAB_BOOT
 
 config IMX8
bool
+   select HAS_CAAM
 
 config MU_BASE_SPL
hex "MU base address used in SPL"
@@ -72,6 +73,9 @@ config TARGET_IMX8QM_MEK
bool "Support i.MX8QM MEK board"
select BOARD_LATE_INIT
select IMX8QM
+   select FSL_CAAM
+   select ARCH_MISC_INIT
+   select SPL_CRYPTO if SPL
 
 config TARGET_CONGA_QMX8
bool "Support congatec conga-QMX8 board"
@@ -89,6 +93,9 @@ config TARGET_IMX8QXP_MEK
bool "Support i.MX8QXP MEK board"
select BOARD_LATE_INIT
select IMX8QXP
+   select FSL_CAAM
+   select ARCH_MISC_INIT
+   select SPL_CRYPTO if SPL
 
 endchoice
 
diff --git a/arch/arm/mach-imx/imx8/cpu.c b/arch/arm/mach-imx/imx8/cpu.c
index ee5cc47903..5140c93a37 100644
--- a/arch/arm/mach-imx/imx8/cpu.c
+++ b/arch/arm/mach-imx/imx8/cpu.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright 2018 NXP
+ * Copyright 2018, 2021 NXP
  */
 
 #include 
@@ -89,6 +89,20 @@ int arch_cpu_init_dm(void)
return 0;
 }
 
+#if defined(CONFIG_ARCH_MISC_INIT)
+int arch_misc_init(void)
+{
+   struct udevice *dev;
+   int ret;
+
+   ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), 
);
+   if (ret)
+   printf("Failed to initialize %s: %d\n", dev->name, ret);
+
+   return 0;
+}
+#endif
+
 int print_bootinfo(void)
 {
enum boot_device bt_dev = get_boot_device();
diff --git a/board/freescale/imx8qm_mek/spl.c b/board/freescale/imx8qm_mek/spl.c
index 944ba745c0..332a662dee 100644
--- a/board/freescale/imx8qm_mek/spl.c
+++ b/board/freescale/imx8qm_mek/spl.c
@@ -1,7 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright 2018 NXP
+ * Copyright 2018, 2021 NXP
  *
- * SPDX-License-Identifier:GPL-2.0+
  */
 
 #include 
@@ -24,6 +24,8 @@ void spl_board_init(void)
 {
struct udevice *dev;
 
+   uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(imx8_scu), );
+
uclass_find_first_device(UCLASS_MISC, );
 
for (; dev; uclass_find_next_device()) {
diff --git a/board/freescale/imx8qxp_mek/spl.c 
b/board/freescale/imx8qxp_mek/spl.c
index ae6b64ff6e..2fa6840056 100644
--- a/board/freescale/imx8qxp_mek/spl.c
+++ b/board/freescale/imx8qxp_mek/spl.c
@@ -1,7 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright 2018 NXP
+ * Copyright 2018, 2021 NXP
  *
- * SPDX-License-Identifier:GPL-2.0+
  */
 
 #include 
@@ -39,6 +39,8 @@ void spl_board_init(void)
 {
struct udevice *dev;
 
+   uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(imx8_scu), );
+
uclass_find_first_device(UCLASS_MISC, );
 
   

[PATCH v7 08/15] i.MX8: Add crypto node in device tree

2021-12-06 Thread Gaurav Jain
i.MX8(QM/QXP) - updated device tree for supporting DM in SPL.

disabled use of JR1 in SPL and uboot, as JR1 is reserved
for SECO FW.

Signed-off-by: Gaurav Jain 
Reviewed-by: Ye Li 
---
 arch/arm/dts/fsl-imx8dx.dtsi | 61 +++-
 arch/arm/dts/fsl-imx8qm-mek-u-boot.dtsi  | 34 -
 arch/arm/dts/fsl-imx8qm.dtsi | 61 +++-
 arch/arm/dts/fsl-imx8qxp-mek-u-boot.dtsi | 34 -
 4 files changed, 186 insertions(+), 4 deletions(-)

diff --git a/arch/arm/dts/fsl-imx8dx.dtsi b/arch/arm/dts/fsl-imx8dx.dtsi
index 7d95cf0b7d..63a56699b5 100644
--- a/arch/arm/dts/fsl-imx8dx.dtsi
+++ b/arch/arm/dts/fsl-imx8dx.dtsi
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright 2018 NXP
+ * Copyright 2018, 2021 NXP
  */
 
 #include 
@@ -261,6 +261,30 @@
power-domains = <_dma>;
};
};
+
+   pd_caam: PD_CAAM {
+   compatible = "nxp,imx8-pd";
+   reg = ;
+   #power-domain-cells = <0>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   pd_caam_jr1: PD_CAAM_JR1 {
+   reg = ;
+   #power-domain-cells = <0>;
+   power-domains = <_caam>;
+   };
+   pd_caam_jr2: PD_CAAM_JR2 {
+   reg = ;
+   #power-domain-cells = <0>;
+   power-domains = <_caam>;
+   };
+   pd_caam_jr3: PD_CAAM_JR3 {
+   reg = ;
+   #power-domain-cells = <0>;
+   power-domains = <_caam>;
+   };
+   };
};
 
i2c0: i2c@5a80 {
@@ -609,6 +633,41 @@
};
};
};
+
+   crypto: caam@0x3140 {
+   compatible = "fsl,sec-v4.0";
+   reg = <0 0x3140 0 0x40>;
+   interrupts = ;
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0 0 0x3140 0x40>;
+   fsl,first-jr-index = <2>;
+   fsl,sec-era = <9>;
+
+   sec_jr1: jr1@0x2 {
+   compatible = "fsl,sec-v4.0-job-ring";
+   reg = <0x2 0x1000>;
+   interrupts = ;
+   power-domains = <_caam_jr1>;
+   status = "disabled";
+   };
+
+   sec_jr2: jr2@3 {
+   compatible = "fsl,sec-v4.0-job-ring";
+   reg = <0x3 0x1000>;
+   interrupts = ;
+   power-domains = <_caam_jr2>;
+   status = "okay";
+   };
+
+   sec_jr3: jr3@4 {
+   compatible = "fsl,sec-v4.0-job-ring";
+   reg = <0x4 0x1000>;
+   interrupts = ;
+   power-domains = <_caam_jr3>;
+   status = "okay";
+   };
+   };
 };
 
 _0 {
diff --git a/arch/arm/dts/fsl-imx8qm-mek-u-boot.dtsi 
b/arch/arm/dts/fsl-imx8qm-mek-u-boot.dtsi
index 9e0d264b71..a95209e141 100644
--- a/arch/arm/dts/fsl-imx8qm-mek-u-boot.dtsi
+++ b/arch/arm/dts/fsl-imx8qm-mek-u-boot.dtsi
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright 2018 NXP
+ * Copyright 2018, 2021 NXP
  */
 
 &{/imx8qm-pm} {
@@ -80,6 +80,22 @@
u-boot,dm-spl;
 };
 
+_caam {
+   u-boot,dm-spl;
+};
+
+_caam_jr1 {
+   u-boot,dm-spl;
+};
+
+_caam_jr2 {
+   u-boot,dm-spl;
+};
+
+_caam_jr3 {
+   u-boot,dm-spl;
+};
+
  {
u-boot,dm-spl;
 };
@@ -126,3 +142,19 @@
sd-uhs-sdr104;
sd-uhs-ddr50;
 };
+
+ {
+   u-boot,dm-spl;
+};
+
+_jr1 {
+   u-boot,dm-spl;
+};
+
+_jr2 {
+   u-boot,dm-spl;
+};
+
+_jr3 {
+   u-boot,dm-spl;
+};
diff --git a/arch/arm/dts/fsl-imx8qm.dtsi b/arch/arm/dts/fsl-imx8qm.dtsi
index 88aeaf65b3..517fb13cad 100644
--- a/arch/arm/dts/fsl-imx8qm.dtsi
+++ b/arch/arm/dts/fsl-imx8qm.dtsi
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright 2018 NXP
+ * Copyright 2018, 2021 NXP
  */
 
 #include 
@@ -235,6 +235,30 @@
wakeup-irq = <349>;
};
};
+
+   pd_caam: PD_CAAM {
+   compatible = "nxp,imx8-pd";
+   reg = ;
+   #power-domain-cells = <0>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   pd_caam_jr1: PD_CAAM_JR1 {
+   reg = ;
+   #power-domain-cells = <0>;
+  

[PATCH v7 07/15] i.MX7ULP: Enable Job ring driver model in U-Boot.

2021-12-06 Thread Gaurav Jain
added crypto node in device tree.
sec is initialized based on job ring information processed
from device tree.

Signed-off-by: Gaurav Jain 
Reviewed-by: Ye Li 
---
 arch/arm/Kconfig |  2 +-
 arch/arm/dts/imx7ulp.dtsi| 24 
 arch/arm/mach-imx/mx7ulp/Kconfig |  3 +++
 arch/arm/mach-imx/mx7ulp/soc.c   | 16 
 4 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 516e1b5a8f..524a2204eb 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -870,7 +870,7 @@ config ARCH_MX7ULP
select CPU_V7A
select GPIO_EXTRA_HEADER
select MACH_IMX
-   select SYS_FSL_HAS_SEC if IMX_HAB
+   select SYS_FSL_HAS_SEC
select SYS_FSL_SEC_COMPAT_4
select SYS_FSL_SEC_LE
select ROM_UNIFIED_SECTIONS
diff --git a/arch/arm/dts/imx7ulp.dtsi b/arch/arm/dts/imx7ulp.dtsi
index 7bcd2cc346..494b9d98b2 100644
--- a/arch/arm/dts/imx7ulp.dtsi
+++ b/arch/arm/dts/imx7ulp.dtsi
@@ -1,5 +1,6 @@
 /*
  * Copyright 2015-2016 Freescale Semiconductor, Inc.
+ * Copyright 2021 NXP
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -198,6 +199,29 @@
};
};
 
+   crypto: crypto@4024 {
+   compatible = "fsl,sec-v4.0";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   reg = <0x4024 0x1>;
+   ranges = <0 0x4024 0x1>;
+   clocks = < IMX7ULP_CLK_CAAM>,
+< IMX7ULP_CLK_NIC1_BUS_DIV>;
+   clock-names = "aclk", "ipg";
+
+   sec_jr0: jr@1000 {
+   compatible = "fsl,sec-v4.0-job-ring";
+   reg = <0x1000 0x1000>;
+   interrupts = ;
+   };
+
+   sec_jr1: jr@2000 {
+   compatible = "fsl,sec-v4.0-job-ring";
+   reg = <0x2000 0x1000>;
+   interrupts = ;
+   };
+   };
+
tpm5: tpm@4026 {
compatible = "fsl,imx7ulp-tpm";
reg = <0x4026 0x1000>;
diff --git a/arch/arm/mach-imx/mx7ulp/Kconfig b/arch/arm/mach-imx/mx7ulp/Kconfig
index 2ffac9cf7c..fbd2de5e3d 100644
--- a/arch/arm/mach-imx/mx7ulp/Kconfig
+++ b/arch/arm/mach-imx/mx7ulp/Kconfig
@@ -25,6 +25,9 @@ config TARGET_MX7ULP_EVK
bool "Support mx7ulp EVK board"
select MX7ULP
select SYS_ARCH_TIMER
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
 
 endchoice
 
diff --git a/arch/arm/mach-imx/mx7ulp/soc.c b/arch/arm/mach-imx/mx7ulp/soc.c
index c90ce22404..c1e55e7260 100644
--- a/arch/arm/mach-imx/mx7ulp/soc.c
+++ b/arch/arm/mach-imx/mx7ulp/soc.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2016 Freescale Semiconductor, Inc.
+ * Copyright 2021 NXP
  */
 
 #include 
@@ -15,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define PMC0_BASE_ADDR 0x410a1000
 #define PMC0_CTRL  0x28
@@ -80,6 +82,20 @@ int arch_cpu_init(void)
return 0;
 }
 
+#if defined(CONFIG_ARCH_MISC_INIT)
+int arch_misc_init(void)
+{
+   struct udevice *dev;
+   int ret;
+
+   ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), 
);
+   if (ret)
+   printf("Failed to initialize %s: %d\n", dev->name, ret);
+
+   return 0;
+}
+#endif
+
 #ifdef CONFIG_BOARD_POSTCLK_INIT
 int board_postclk_init(void)
 {
-- 
2.17.1



[PATCH v7 06/15] i.MX7: Enable Job ring driver model in U-Boot.

2021-12-06 Thread Gaurav Jain
i.MX7D - added support for JR driver model.

removed sec_init() call, sec is initialized based on
job ring information processed from device tree.

Signed-off-by: Gaurav Jain 
Reviewed-by: Ye Li 
---
 arch/arm/Kconfig  |  2 +-
 arch/arm/mach-imx/mx7/Kconfig |  2 ++
 arch/arm/mach-imx/mx7/soc.c   | 11 +++
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 550f884077..516e1b5a8f 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -883,7 +883,7 @@ config ARCH_MX7
select CPU_V7A
select GPIO_EXTRA_HEADER
select MACH_IMX
-   select SYS_FSL_HAS_SEC if IMX_HAB
+   select SYS_FSL_HAS_SEC
select SYS_FSL_SEC_COMPAT_4
select SYS_FSL_SEC_LE
imply BOARD_EARLY_INIT_F
diff --git a/arch/arm/mach-imx/mx7/Kconfig b/arch/arm/mach-imx/mx7/Kconfig
index 0cad825287..b2d532dacd 100644
--- a/arch/arm/mach-imx/mx7/Kconfig
+++ b/arch/arm/mach-imx/mx7/Kconfig
@@ -68,6 +68,8 @@ config TARGET_MX7DSABRESD
select DM_THERMAL
select MX7D
imply CMD_DM
+   select FSL_CAAM
+   select MISC
 
 config TARGET_PICO_IMX7D
bool "pico-imx7d"
diff --git a/arch/arm/mach-imx/mx7/soc.c b/arch/arm/mach-imx/mx7/soc.c
index 21690072e1..6c991a6cb1 100644
--- a/arch/arm/mach-imx/mx7/soc.c
+++ b/arch/arm/mach-imx/mx7/soc.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2015 Freescale Semiconductor, Inc.
+ * Copyright 2021 NXP
  */
 
 #include 
@@ -19,7 +20,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
@@ -337,6 +337,9 @@ int arch_cpu_init(void)
 #ifdef CONFIG_ARCH_MISC_INIT
 int arch_misc_init(void)
 {
+   struct udevice *dev;
+   int ret;
+
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
struct tag_serialnr serialnr;
char serial_string[0x20];
@@ -353,9 +356,9 @@ int arch_misc_init(void)
env_set("serial#", serial_string);
 #endif
 
-#ifdef CONFIG_FSL_CAAM
-   sec_init();
-#endif
+   ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), 
);
+   if (ret)
+   printf("Failed to initialize %s: %d\n", dev->name, ret);
 
return 0;
 }
-- 
2.17.1



[PATCH v7 05/15] i.MX6: Enable Job ring driver model in U-Boot.

2021-12-06 Thread Gaurav Jain
i.MX6,i.MX6SX,i.MX6UL - added support for JR driver model.

removed sec_init() call, sec is initialized based on
job ring information processed from device tree.

Signed-off-by: Gaurav Jain 
Reviewed-by: Ye Li 
---
 arch/arm/mach-imx/mx6/Kconfig | 15 +++
 arch/arm/mach-imx/mx6/soc.c   | 12 
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-imx/mx6/Kconfig b/arch/arm/mach-imx/mx6/Kconfig
index 62de942a32..8ccb3b6e35 100644
--- a/arch/arm/mach-imx/mx6/Kconfig
+++ b/arch/arm/mach-imx/mx6/Kconfig
@@ -354,6 +354,9 @@ config TARGET_MX6SABREAUTO
select DM_THERMAL
select SUPPORT_SPL
imply CMD_DM
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
 
 config TARGET_MX6SABRESD
bool "mx6sabresd"
@@ -364,6 +367,9 @@ config TARGET_MX6SABRESD
select DM_THERMAL
select SUPPORT_SPL
imply CMD_DM
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
 
 config TARGET_MX6SLEVK
bool "mx6slevk"
@@ -386,6 +392,9 @@ config TARGET_MX6SXSABRESD
select DM
select DM_THERMAL
select SUPPORT_SPL
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
 
 config TARGET_MX6SXSABREAUTO
bool "mx6sxsabreauto"
@@ -404,6 +413,9 @@ config TARGET_MX6UL_9X9_EVK
select DM_THERMAL
select SUPPORT_SPL
imply CMD_DM
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
 
 config TARGET_MX6UL_14X14_EVK
bool "mx6ul_14x14_evk"
@@ -413,6 +425,9 @@ config TARGET_MX6UL_14X14_EVK
select DM_THERMAL
select SUPPORT_SPL
imply CMD_DM
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
 
 config TARGET_MX6UL_ENGICAM
bool "Support Engicam GEAM6UL/Is.IoT"
diff --git a/arch/arm/mach-imx/mx6/soc.c b/arch/arm/mach-imx/mx6/soc.c
index aacfc854a2..fa6c3778bb 100644
--- a/arch/arm/mach-imx/mx6/soc.c
+++ b/arch/arm/mach-imx/mx6/soc.c
@@ -4,6 +4,7 @@
  * Sascha Hauer, Pengutronix
  *
  * (C) Copyright 2009 Freescale Semiconductor, Inc.
+ * Copyright 2021 NXP
  */
 
 #include 
@@ -23,7 +24,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
@@ -734,9 +734,13 @@ static void setup_serial_number(void)
 
 int arch_misc_init(void)
 {
-#ifdef CONFIG_FSL_CAAM
-   sec_init();
-#endif
+   struct udevice *dev;
+   int ret;
+
+   ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), 
);
+   if (ret)
+   printf("Failed to initialize %s: %d\n", dev->name, ret);
+
setup_serial_number();
return 0;
 }
-- 
2.17.1



[PATCH v7 04/15] mx6sabre: Remove unnecessary SPL configs

2021-12-06 Thread Gaurav Jain
From: Ye Li 

Because we don't use SPL_DM on mx6sabresd and mx6sabreauto, so it is
unnecessary to have SPL DTB related configs and SPL_OF_CONTROL enabled.

Signed-off-by: Ye Li 
Reviewed-by: Fabio Estevam 
Reviewed-by: Gaurav Jain 
---
 configs/mx6sabreauto_defconfig | 2 --
 configs/mx6sabresd_defconfig   | 4 
 2 files changed, 6 deletions(-)

diff --git a/configs/mx6sabreauto_defconfig b/configs/mx6sabreauto_defconfig
index c5cdc3ac17..2b8b4f6b9f 100644
--- a/configs/mx6sabreauto_defconfig
+++ b/configs/mx6sabreauto_defconfig
@@ -60,10 +60,8 @@ CONFIG_CMD_EXT4_WRITE=y
 CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
 CONFIG_OF_CONTROL=y
-CONFIG_SPL_OF_CONTROL=y
 CONFIG_OF_LIST="imx6dl-sabreauto imx6q-sabreauto imx6qp-sabreauto"
 CONFIG_MULTI_DTB_FIT=y
-CONFIG_SPL_MULTI_DTB_FIT=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_MMC=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
diff --git a/configs/mx6sabresd_defconfig b/configs/mx6sabresd_defconfig
index 6733038060..f40401d279 100644
--- a/configs/mx6sabresd_defconfig
+++ b/configs/mx6sabresd_defconfig
@@ -63,12 +63,8 @@ CONFIG_CMD_FS_GENERIC=y
 CONFIG_EFI_PARTITION=y
 # CONFIG_SPL_EFI_PARTITION is not set
 CONFIG_OF_CONTROL=y
-CONFIG_SPL_OF_CONTROL=y
 CONFIG_OF_LIST="imx6q-sabresd imx6qp-sabresd imx6dl-sabresd"
 CONFIG_MULTI_DTB_FIT=y
-CONFIG_SPL_MULTI_DTB_FIT=y
-CONFIG_SPL_OF_LIST="imx6dl-sabresd imx6q-sabresd imx6qp-sabresd"
-CONFIG_SPL_MULTI_DTB_FIT_NO_COMPRESSION=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_MMC=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
-- 
2.17.1



[PATCH v7 03/15] crypto/fsl: i.MX8M: Enable Job ring driver model in SPL and U-Boot.

2021-12-06 Thread Gaurav Jain
i.MX8MM/MN/MP/MQ - added support for JR driver model.
sec is initialized based on job ring information processed
from device tree.

Signed-off-by: Gaurav Jain 
Reviewed-by: Ye Li 
---
 arch/arm/Kconfig   |  2 +-
 arch/arm/include/asm/arch-imx8m/imx-regs.h |  1 +
 arch/arm/mach-imx/imx8m/Kconfig| 18 ++
 arch/arm/mach-imx/imx8m/soc.c  | 10 +-
 board/freescale/imx8mm_evk/spl.c   |  9 -
 board/freescale/imx8mn_evk/spl.c   |  8 ++--
 board/freescale/imx8mp_evk/spl.c   | 13 +++--
 board/freescale/imx8mq_evk/spl.c   |  9 +++--
 drivers/crypto/fsl/jr.c| 14 +++---
 scripts/config_whitelist.txt   |  1 +
 10 files changed, 73 insertions(+), 12 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index f7f03837fe..550f884077 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -815,7 +815,7 @@ config ARCH_IMX8M
select ARM64
select GPIO_EXTRA_HEADER
select MACH_IMX
-   select SYS_FSL_HAS_SEC if IMX_HAB
+   select SYS_FSL_HAS_SEC
select SYS_FSL_SEC_COMPAT_4
select SYS_FSL_SEC_LE
select SYS_I2C_MXC
diff --git a/arch/arm/include/asm/arch-imx8m/imx-regs.h 
b/arch/arm/include/asm/arch-imx8m/imx-regs.h
index b800da13a1..ff8de53f67 100644
--- a/arch/arm/include/asm/arch-imx8m/imx-regs.h
+++ b/arch/arm/include/asm/arch-imx8m/imx-regs.h
@@ -72,6 +72,7 @@
 #define CONFIG_SYS_FSL_SEC_ADDR (CAAM_IPS_BASE_ADDR + \
 CONFIG_SYS_FSL_SEC_OFFSET)
 #define CONFIG_SYS_FSL_JR0_OFFSET   (0x1000)
+#define CONFIG_SYS_FSL_JR1_OFFSET   (0x2000)
 #define CONFIG_SYS_FSL_JR0_ADDR (CONFIG_SYS_FSL_SEC_ADDR + \
 CONFIG_SYS_FSL_JR0_OFFSET)
 #define CONFIG_SYS_FSL_MAX_NUM_OF_SEC   1
diff --git a/arch/arm/mach-imx/imx8m/Kconfig b/arch/arm/mach-imx/imx8m/Kconfig
index 276b8bd974..a9acf6474f 100644
--- a/arch/arm/mach-imx/imx8m/Kconfig
+++ b/arch/arm/mach-imx/imx8m/Kconfig
@@ -38,6 +38,10 @@ config TARGET_IMX8MQ_EVK
bool "imx8mq_evk"
select IMX8MQ
select IMX8M_LPDDR4
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
+   select SPL_CRYPTO if SPL
 
 config TARGET_IMX8MQ_PHANBELL
 bool "imx8mq_phanbell"
@@ -50,6 +54,10 @@ config TARGET_IMX8MM_EVK
select IMX8MM
select SUPPORT_SPL
select IMX8M_LPDDR4
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
+   select SPL_CRYPTO if SPL
 
 config TARGET_IMX8MM_ICORE_MX8MM
bool "Engicam i.Core MX8M Mini SOM"
@@ -88,6 +96,9 @@ config TARGET_IMX8MN_EVK
select IMX8MN
select SUPPORT_SPL
select IMX8M_LPDDR4
+   select FSL_CAAM
+   select MISC
+   select SPL_CRYPTO if SPL
 
 config TARGET_IMX8MN_DDR4_EVK
bool "imx8mn DDR4 EVK board"
@@ -95,6 +106,9 @@ config TARGET_IMX8MN_DDR4_EVK
select IMX8MN
select SUPPORT_SPL
select IMX8M_DDR4
+   select FSL_CAAM
+   select MISC
+   select SPL_CRYPTO if SPL
 
 config TARGET_IMX8MP_EVK
bool "imx8mp LPDDR4 EVK board"
@@ -102,6 +116,10 @@ config TARGET_IMX8MP_EVK
select IMX8MP
select SUPPORT_SPL
select IMX8M_LPDDR4
+   select FSL_CAAM
+   select MISC
+   select ARCH_MISC_INIT
+   select SPL_CRYPTO if SPL
 
 config TARGET_PICO_IMX8MQ
bool "Support Technexion Pico iMX8MQ"
diff --git a/arch/arm/mach-imx/imx8m/soc.c b/arch/arm/mach-imx/imx8m/soc.c
index 863508776d..0f9bd77354 100644
--- a/arch/arm/mach-imx/imx8m/soc.c
+++ b/arch/arm/mach-imx/imx8m/soc.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright 2017-2019 NXP
+ * Copyright 2017-2019, 2021 NXP
  *
  * Peng Fan 
  */
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1197,6 +1198,13 @@ static void acquire_buildinfo(void)
 
 int arch_misc_init(void)
 {
+   struct udevice *dev;
+   int ret;
+
+   ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), 
);
+   if (ret)
+   printf("Failed to initialize %s: %d\n", dev->name, ret);
+
acquire_buildinfo();
 
return 0;
diff --git a/board/freescale/imx8mm_evk/spl.c b/board/freescale/imx8mm_evk/spl.c
index 4ef7f6f180..c81128f442 100644
--- a/board/freescale/imx8mm_evk/spl.c
+++ b/board/freescale/imx8mm_evk/spl.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright 2019 NXP
+ * Copyright 2019, 2021 NXP
  */
 
 #include 
@@ -51,6 +51,13 @@ static void spl_dram_init(void)
 
 void spl_board_init(void)
 {
+   struct udevice *dev;
+   int ret;
+
+   ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), 
);
+   if (ret)
+   printf("Failed to initialize %s: %d\n", dev->name, ret);
+
puts("Normal Boot\n");
 }
 
diff --git 

[PATCH v7 02/15] i.MX8M: crypto: updated device tree for supporting DM in SPL

2021-12-06 Thread Gaurav Jain
disabled use of JR0 in SPL and uboot, as JR0 is reserved
for secure boot.

Signed-off-by: Gaurav Jain 
Reviewed-by: Ye Li 
---
 arch/arm/dts/imx8mm-evk-u-boot.dtsi  | 19 ++-
 arch/arm/dts/imx8mn-ddr4-evk-u-boot.dtsi | 19 ++-
 arch/arm/dts/imx8mp-evk-u-boot.dtsi  | 19 ++-
 arch/arm/dts/imx8mq-evk-u-boot.dtsi  |  4 
 4 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/arch/arm/dts/imx8mm-evk-u-boot.dtsi 
b/arch/arm/dts/imx8mm-evk-u-boot.dtsi
index 3c75415e8f..83517de52b 100644
--- a/arch/arm/dts/imx8mm-evk-u-boot.dtsi
+++ b/arch/arm/dts/imx8mm-evk-u-boot.dtsi
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright 2019 NXP
+ * Copyright 2019, 2021 NXP
  */
 
 #include "imx8mm-u-boot.dtsi"
@@ -72,6 +72,23 @@
u-boot,dm-spl;
 };
 
+ {
+   u-boot,dm-spl;
+};
+
+_jr0 {
+   u-boot,dm-spl;
+   status = "disabled";
+};
+
+_jr1 {
+   u-boot,dm-spl;
+};
+
+_jr2 {
+   u-boot,dm-spl;
+};
+
  {
u-boot,dm-spl;
 };
diff --git a/arch/arm/dts/imx8mn-ddr4-evk-u-boot.dtsi 
b/arch/arm/dts/imx8mn-ddr4-evk-u-boot.dtsi
index 1d3844437d..d8df863083 100644
--- a/arch/arm/dts/imx8mn-ddr4-evk-u-boot.dtsi
+++ b/arch/arm/dts/imx8mn-ddr4-evk-u-boot.dtsi
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright 2019 NXP
+ * Copyright 2019, 2021 NXP
  */
 
 / {
@@ -104,6 +104,23 @@
u-boot,dm-spl;
 };
 
+ {
+   u-boot,dm-spl;
+};
+
+_jr0 {
+   u-boot,dm-spl;
+   status = "disabled";
+};
+
+_jr1 {
+   u-boot,dm-spl;
+};
+
+_jr2 {
+   u-boot,dm-spl;
+};
+
  {
u-boot,dm-spl;
 };
diff --git a/arch/arm/dts/imx8mp-evk-u-boot.dtsi 
b/arch/arm/dts/imx8mp-evk-u-boot.dtsi
index ab849ebaac..f3f83ba303 100644
--- a/arch/arm/dts/imx8mp-evk-u-boot.dtsi
+++ b/arch/arm/dts/imx8mp-evk-u-boot.dtsi
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright 2019 NXP
+ * Copyright 2019, 2021 NXP
  */
 
 #include "imx8mp-u-boot.dtsi"
@@ -67,6 +67,23 @@
u-boot,dm-spl;
 };
 
+ {
+   u-boot,dm-spl;
+};
+
+_jr0 {
+   u-boot,dm-spl;
+   status = "disabled";
+};
+
+_jr1 {
+   u-boot,dm-spl;
+};
+
+_jr2 {
+   u-boot,dm-spl;
+};
+
  {
u-boot,dm-spl;
 };
diff --git a/arch/arm/dts/imx8mq-evk-u-boot.dtsi 
b/arch/arm/dts/imx8mq-evk-u-boot.dtsi
index 2cfc12b7e0..23a3ffa18f 100644
--- a/arch/arm/dts/imx8mq-evk-u-boot.dtsi
+++ b/arch/arm/dts/imx8mq-evk-u-boot.dtsi
@@ -8,3 +8,7 @@
sd-uhs-sdr104;
sd-uhs-ddr50;
 };
+
+_jr0 {
+   status = "disabled";
+};
-- 
2.17.1



[PATCH v7 01/15] crypto/fsl: Add support for CAAM Job ring driver model

2021-12-06 Thread Gaurav Jain
added device tree support for job ring driver.
sec is initialized based on job ring information processed
from device tree.

Signed-off-by: Gaurav Jain 
Reviewed-by: Ye Li 
---
 drivers/crypto/fsl/jr.c | 323 ++--
 drivers/crypto/fsl/jr.h |  19 +++
 2 files changed, 231 insertions(+), 111 deletions(-)

diff --git a/drivers/crypto/fsl/jr.c b/drivers/crypto/fsl/jr.c
index 22b649219e..441550f348 100644
--- a/drivers/crypto/fsl/jr.c
+++ b/drivers/crypto/fsl/jr.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2008-2014 Freescale Semiconductor, Inc.
- * Copyright 2018 NXP
+ * Copyright 2018, 2021 NXP
  *
  * Based on CAAM driver in drivers/crypto/caam in Linux
  */
@@ -11,7 +11,6 @@
 #include 
 #include 
 #include 
-#include "fsl_sec.h"
 #include "jr.h"
 #include "jobdesc.h"
 #include "desc_constr.h"
@@ -21,8 +20,11 @@
 #include 
 #include 
 #endif
+#include 
 #include 
 #include 
+#include 
+#include 
 
 #define CIRC_CNT(head, tail, size) (((head) - (tail)) & (size - 1))
 #define CIRC_SPACE(head, tail, size)   CIRC_CNT((tail), (head) + 1, (size))
@@ -35,20 +37,29 @@ uint32_t sec_offset[CONFIG_SYS_FSL_MAX_NUM_OF_SEC] = {
 #endif
 };
 
+#if CONFIG_IS_ENABLED(DM)
+struct udevice *caam_dev;
+#else
 #define SEC_ADDR(idx)  \
(ulong)((CONFIG_SYS_FSL_SEC_ADDR + sec_offset[idx]))
 
 #define SEC_JR0_ADDR(idx)  \
(ulong)(SEC_ADDR(idx) + \
 (CONFIG_SYS_FSL_JR0_OFFSET - CONFIG_SYS_FSL_SEC_OFFSET))
+struct caam_regs caam_st;
+#endif
 
-struct jobring jr0[CONFIG_SYS_FSL_MAX_NUM_OF_SEC];
+static inline u32 jr_start_reg(u8 jrid)
+{
+   return (1 << jrid);
+}
 
-static inline void start_jr0(uint8_t sec_idx)
+static inline void start_jr(struct caam_regs *caam)
 {
-   ccsr_sec_t *sec = (void *)SEC_ADDR(sec_idx);
+   ccsr_sec_t *sec = caam->sec;
u32 ctpr_ms = sec_in32(>ctpr_ms);
u32 scfgr = sec_in32(>scfgr);
+   u32 jrstart = jr_start_reg(caam->jrid);
 
if (ctpr_ms & SEC_CTPR_MS_VIRT_EN_INCL) {
/* VIRT_EN_INCL = 1 & VIRT_EN_POR = 1 or
@@ -56,23 +67,16 @@ static inline void start_jr0(uint8_t sec_idx)
 */
if ((ctpr_ms & SEC_CTPR_MS_VIRT_EN_POR) ||
(scfgr & SEC_SCFGR_VIRT_EN))
-   sec_out32(>jrstartr, CONFIG_JRSTARTR_JR0);
+   sec_out32(>jrstartr, jrstart);
} else {
/* VIRT_EN_INCL = 0 && VIRT_EN_POR_VALUE = 1 */
if (ctpr_ms & SEC_CTPR_MS_VIRT_EN_POR)
-   sec_out32(>jrstartr, CONFIG_JRSTARTR_JR0);
+   sec_out32(>jrstartr, jrstart);
}
 }
 
-static inline void jr_reset_liodn(uint8_t sec_idx)
+static inline void jr_disable_irq(struct jr_regs *regs)
 {
-   ccsr_sec_t *sec = (void *)SEC_ADDR(sec_idx);
-   sec_out32(>jrliodnr[0].ls, 0);
-}
-
-static inline void jr_disable_irq(uint8_t sec_idx)
-{
-   struct jr_regs *regs = (struct jr_regs *)SEC_JR0_ADDR(sec_idx);
uint32_t jrcfg = sec_in32(>jrcfg1);
 
jrcfg = jrcfg | JR_INTMASK;
@@ -80,10 +84,10 @@ static inline void jr_disable_irq(uint8_t sec_idx)
sec_out32(>jrcfg1, jrcfg);
 }
 
-static void jr_initregs(uint8_t sec_idx)
+static void jr_initregs(uint8_t sec_idx, struct caam_regs *caam)
 {
-   struct jr_regs *regs = (struct jr_regs *)SEC_JR0_ADDR(sec_idx);
-   struct jobring *jr = [sec_idx];
+   struct jr_regs *regs = caam->regs;
+   struct jobring *jr = >jr[sec_idx];
caam_dma_addr_t ip_base = virt_to_phys((void *)jr->input_ring);
caam_dma_addr_t op_base = virt_to_phys((void *)jr->output_ring);
 
@@ -103,16 +107,16 @@ static void jr_initregs(uint8_t sec_idx)
sec_out32(>irs, JR_SIZE);
 
if (!jr->irq)
-   jr_disable_irq(sec_idx);
+   jr_disable_irq(regs);
 }
 
-static int jr_init(uint8_t sec_idx)
+static int jr_init(uint8_t sec_idx, struct caam_regs *caam)
 {
-   struct jobring *jr = [sec_idx];
+   struct jobring *jr = >jr[sec_idx];
 
memset(jr, 0, sizeof(struct jobring));
 
-   jr->jq_id = DEFAULT_JR_ID;
+   jr->jq_id = caam->jrid;
jr->irq = DEFAULT_IRQ;
 
 #ifdef CONFIG_FSL_CORENET
@@ -134,53 +138,8 @@ static int jr_init(uint8_t sec_idx)
memset(jr->input_ring, 0, JR_SIZE * sizeof(caam_dma_addr_t));
memset(jr->output_ring, 0, jr->op_size);
 
-   start_jr0(sec_idx);
-
-   jr_initregs(sec_idx);
-
-   return 0;
-}
-
-static int jr_sw_cleanup(uint8_t sec_idx)
-{
-   struct jobring *jr = [sec_idx];
-
-   jr->head = 0;
-   jr->tail = 0;
-   jr->read_idx = 0;
-   jr->write_idx = 0;
-   memset(jr->info, 0, sizeof(jr->info));
-   memset(jr->input_ring, 0, jr->size * sizeof(caam_dma_addr_t));
-   memset(jr->output_ring, 0, jr->size * sizeof(struct op_ring));
-
-   return 0;
-}
-
-static int jr_hw_reset(uint8_t sec_idx)
-{
-   struct jr_regs *regs = (struct jr_regs 

[PATCH v7 00/15] Add CAAM driver model support

2021-12-06 Thread Gaurav Jain
This patchset adds the support for following:
1) CAAM Driver model for all i.MX, layerscape, PPC platforms.
2) Added crypto node in device tree files.
3) fix build issue for mx6sabre: Remove SPL DTB related configs and 
SPL_OF_CONTROL.
4) improve hwrng performance in kernel.

i.MX platforms:
i.MX6, i.MX7, i.MX7ULP, i.MX8MM/MN/MP/MQ, i.MX8QM/QXP

Layerscape platforms:
LS1021, LS1012, LS1028, LS1043, LS1046, LS1088, LS2088, LX2160, LX2162

Powerpc platforms:
P3041, P4080, P5040, P2041, T1024, T1042, T2080, T4240

changes since v6:
 - rebase to latest master
 - added caam_jr_ioctl() operation which calls run_descriptor_jr().
 - removed CONFIG_ARCH_IMX8 config from JR driver.
 - removed FSL_BLOB config

changes since v5:
 - rebase to latest master
 - updated BIT() macro for JRDID in drivers/crypto/fsl/jr.h
 - removed auto select FSL_BLOB from CMD_BLOB config.
 - removed patch for blob key encryption key(bkek), random number generation.
 - updated patch description for improving hwrng performance in kernel.
 - removed sec_init() from kontron/sl28.
 - for LS1028A architecture, enable CAAM only for LS1028AQDS and LS1028ARDB.

changes since v4:
 - rebase to latest master
 - updated caam_jr_probe() with livetree APIs.
 - imx8m: moved jr0 disable code to *-uboot.dtsi files.

changes since v3:
 - rebase to latest master
 - fixed build error when new file arch/powerpc/include/asm/u-boot-ppc.h is
   included from assembly files.
 - removed arch/arm/dts/fsl-ls1028a.dtsi as it is conflicting with the series
   https://lore.kernel.org/u-boot/20211013161427.612033-1-mich...@walle.cc/

Gaurav Jain (13):
  crypto/fsl: Add support for CAAM Job ring driver model
  i.MX8M: crypto: updated device tree for supporting DM in SPL
  crypto/fsl: i.MX8M: Enable Job ring driver model in SPL and U-Boot.
  i.MX6: Enable Job ring driver model in U-Boot.
  i.MX7: Enable Job ring driver model in U-Boot.
  i.MX7ULP: Enable Job ring driver model in U-Boot.
  i.MX8: Add crypto node in device tree
  crypto/fsl: i.MX8: Enable Job ring driver model in SPL and U-Boot.
  Layerscape: Add crypto node in device tree
  Layerscape: Enable Job ring driver model in U-Boot.
  PPC: Add crypto node in device tree
  PPC: Enable Job ring driver model in U-Boot
  update CAAM MAINTAINER

Ye Li (2):
  mx6sabre: Remove unnecessary SPL configs
  crypto/fsl: Improve hwrng performance in kernel

 MAINTAINERS   |   6 +
 arch/arm/Kconfig  |  13 +-
 arch/arm/cpu/armv7/ls102xa/Kconfig|   3 +
 arch/arm/cpu/armv7/ls102xa/cpu.c  |  16 +
 arch/arm/cpu/armv8/fsl-layerscape/Kconfig |  17 +
 arch/arm/cpu/armv8/fsl-layerscape/cpu.c   |  10 +-
 arch/arm/dts/fsl-imx8dx.dtsi  |  61 ++-
 arch/arm/dts/fsl-imx8qm-mek-u-boot.dtsi   |  34 +-
 arch/arm/dts/fsl-imx8qm.dtsi  |  61 ++-
 arch/arm/dts/fsl-imx8qxp-mek-u-boot.dtsi  |  34 +-
 arch/arm/dts/fsl-ls1012a.dtsi |  46 +-
 arch/arm/dts/fsl-ls1043a.dtsi |  45 +-
 arch/arm/dts/fsl-ls1046a.dtsi |  44 ++
 arch/arm/dts/fsl-ls1088a.dtsi |  39 ++
 arch/arm/dts/fsl-ls2080a.dtsi |  39 ++
 arch/arm/dts/fsl-lx2160a.dtsi |  41 +-
 arch/arm/dts/imx7ulp.dtsi |  24 +
 arch/arm/dts/imx8mm-evk-u-boot.dtsi   |  19 +-
 arch/arm/dts/imx8mn-ddr4-evk-u-boot.dtsi  |  19 +-
 arch/arm/dts/imx8mp-evk-u-boot.dtsi   |  19 +-
 arch/arm/dts/imx8mq-evk-u-boot.dtsi   |   4 +
 arch/arm/dts/ls1021a.dtsi |  40 ++
 arch/arm/include/asm/arch-imx8/imx-regs.h |   5 +-
 arch/arm/include/asm/arch-imx8m/imx-regs.h|   1 +
 arch/arm/mach-imx/cmd_dek.c   |   1 +
 arch/arm/mach-imx/imx8/Kconfig|   7 +
 arch/arm/mach-imx/imx8/cpu.c  |  16 +-
 arch/arm/mach-imx/imx8m/Kconfig   |  18 +
 arch/arm/mach-imx/imx8m/soc.c |  10 +-
 arch/arm/mach-imx/mx6/Kconfig |  15 +
 arch/arm/mach-imx/mx6/soc.c   |  12 +-
 arch/arm/mach-imx/mx7/Kconfig |   2 +
 arch/arm/mach-imx/mx7/soc.c   |  11 +-
 arch/arm/mach-imx/mx7ulp/Kconfig  |   3 +
 arch/arm/mach-imx/mx7ulp/soc.c|  16 +
 arch/powerpc/cpu/mpc85xx/Kconfig  |  33 ++
 arch/powerpc/cpu/mpc85xx/cpu_init.c   |  17 +-
 arch/powerpc/dts/p2041si-post.dtsi|   1 +
 arch/powerpc/dts/p3041si-post.dtsi|   1 +
 arch/powerpc/dts/p4080si-post.dtsi|   1 +
 arch/powerpc/dts/p5040si-post.dtsi|   1 +
 arch/powerpc/dts/qoriq-sec4.0-0.dtsi  |  74 +++
 arch/powerpc/dts/qoriq-sec4.2-0.dtsi  |  83 +++
 arch/powerpc/dts/qoriq-sec5.2-0.dtsi  |  92 
 arch/powerpc/dts/t1023si-post.dtsi|   1 +
 arch/powerpc/dts/t1042si-post.dtsi|   1 +
 arch/powerpc/dts/t2080si-post.dtsi|   1 +
 

[PATCH] Braces added to the if

2021-12-06 Thread Javad Rahimi
Signed-off-by: Javad Rahimi 
---

 board/sunxi/board.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index ff80283702..62d32b6329 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -1017,9 +1017,10 @@ void __led_init (led_id_t mask, int state)
 
ret = gpio_lookup_name(CUBIE2_LED_BOOT_GPIO, NULL, NULL, 
_boot_led);
 
-   if (ret)
+   if (ret) {
debug("[gpio_lookup_name]LED Err: %d", ret);
return;
+   }
 
gpio_request(gpio_boot_led, "boot_led");
gpio_direction_output(gpio_boot_led, 1);
-- 
2.25.1



[PATCH] LED BOOT support added for Cubieboard2.

2021-12-06 Thread Javad Rahimi
PH20 and PH21 are two LED on the board which users
can select to be turn on at boot time.

Signed-off-by: Javad Rahimi 
---

 board/sunxi/board.c | 42 ++
 1 file changed, 42 insertions(+)

diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index 4f5747c34a..ff80283702 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -1002,3 +1002,45 @@ int board_fit_config_name_match(const char *name)
return ret;
 }
 #endif
+
+#if defined(CONFIG_LED_STATUS) && defined(CONFIG_LED_STATUS_BOOT) && 
defined(CONFIG_LED_STATUS_BOARD_SPECIFIC)
+
+#define CUBIE2_LED_BOOT_GPIO  "PH20"
+static int gpio_boot_led;
+
+void __led_init (led_id_t mask, int state)
+{
+   int ret;
+
+   if (CONFIG_LED_STATUS_BOOT != mask)
+   return;
+
+   ret = gpio_lookup_name(CUBIE2_LED_BOOT_GPIO, NULL, NULL, 
_boot_led);
+
+   if (ret)
+   debug("[gpio_lookup_name]LED Err: %d", ret);
+   return;
+
+   gpio_request(gpio_boot_led, "boot_led");
+   gpio_direction_output(gpio_boot_led, 1);
+   __led_set(mask, state);
+}
+
+void __led_set(led_id_t mask, int state)
+{
+   if (CONFIG_LED_STATUS_BOOT != mask)
+   return;
+
+   debug("[__led_set]LED Mask:%ld, STATE:%d\n", mask, state);
+   gpio_set_value(gpio_boot_led, state);
+}
+
+void __led_toggle(led_id_t mask)
+{
+   if (CONFIG_LED_STATUS_BOOT != mask)
+   return;
+
+   gpio_set_value(gpio_boot_led, ~gpio_get_value(gpio_boot_led));
+}
+
+#endif
-- 
2.25.1



Re: [PATCH v3] sunxi: h3: enable clock support for r_pio gpios

2021-12-06 Thread Jagan Teki
On Thu, Oct 28, 2021 at 3:27 PM Manuel Dipolt  wrote:
>
> This patch enables clock for the r_pio gpios for the h3
> r_pio is required to access gpios from port L
>
> readout or setting of gpio PL10 (for example to control a led):
>
> => gpio input PL10
> gpio: pin PL10 (gpio 298) value is 0
> => gpio set PL10
> gpio: pin PL10 (gpio 298) value is 1
>
> before:
>
> => gpio input PL10
> gpio: pin PL10 (gpio 298) value is 0
> => gpio set PL10
> gpio: pin PL10 (gpio 298) value is 1
>Warning: value of pin is still 0
>
>
> Signed-off-by: Manuel Dipolt 
> ---
>  drivers/gpio/sunxi_gpio.c | 8 
>  1 file changed, 8 insertions(+)
>
> diff --git a/drivers/gpio/sunxi_gpio.c b/drivers/gpio/sunxi_gpio.c
> index cdbc40d48f..0185eda70d 100644
> --- a/drivers/gpio/sunxi_gpio.c
> +++ b/drivers/gpio/sunxi_gpio.c
> @@ -14,6 +14,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -245,6 +246,13 @@ static int gpio_sunxi_probe(struct udevice *dev)
>  {
> struct sunxi_gpio_plat *plat = dev_get_plat(dev);
> struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
> +   struct clk gate_clk;
> +   int ret;
> +
> +   ret = clk_get_by_name(dev, "apb", _clk);
> +
> +   if (!ret)
> +   clk_enable(_clk);

I'm wondering any of the sunxi driver or coding using this apb clock
via CLK framework, if yes would you pointed it out.

Jagan.


Re: [PATCH] sunxi: Remove misleading USB-OTG charger message

2021-12-06 Thread Jagan Teki
On Thu, Nov 4, 2021 at 6:32 AM Andre Przywara  wrote:
>
> The sunxi MUSB glue driver has some code to check for external VBUS
> presence when it's going to use the MUSB host mode, and it warns if
> there is VBUS provided through the cable (in sunxi_musb_enable()).
>
> This code was apparently copied to the USB gadget detection code
> (g_dnl_board_usb_cable_connected()), but here we actually *expect*
> external VBUS power, so a warning is wrong and confusing.
> So far this message rarely triggered, but a recent patch (6fa41cdd19b9)
> changed this:
> ===
> => ums 0 mmc 2
> UMS: LUN 0, dev mmc 2, hwpart 0, sector 0x0, count 0xe9
> A charger is plugged into the OTG
> /A charger is plugged into the OTG
> \A charger is plugged into the OTG
> |A charger is plugged into the OTG
> -A charger is plugged into the OTG
> 
> ===
>
> Remove the message for the gadget cable detection call, and just return
> the status of the VBUS detection, as this is what the callers are after.
>
> Signed-off-by: Andre Przywara 
> ---

Reviewed-by: Jagan Teki 


Re: [PATCH] sunxi: call fdt_fixup_ethernet again to set macaddr for more aliases

2021-12-06 Thread Jagan Teki
On Sat, Sep 11, 2021 at 11:09 PM Jernej Skrabec
 wrote:
>
> From: Icenowy Zheng 
>
> Sometimes some ethernet aliases do not exist in U-Boot DT but they
> exist in the DT used to boot the system (for example, modified via DT
> overlays). In this situation setup_environment is called again in
> ft_board_setup() to generate macaddr environment variable for them.
> However now the call to fdt_fixup_ethernet() is moved before the call
> of ft_board_setup().
>
> Call fdt_fixup_ethernet() again to add MAC addresses for the extra
> ethernet aliases.
>
> Signed-off-by: Icenowy Zheng 
> [updated commit message]
> Signed-off-by: Jernej Skrabec 
> ---
>
> Hi all,
>
> this is effectively resend of:
> https://patchwork.ozlabs.org/project/uboot/patch/20171027093439.12414-1-icen...@aosc.io/
>
> On at least one board, namely BananaPi M2 Zero, adding ethernet connector is
> pretty popular after market modification. Since this is not something that is
> already present on the board, ethernet node will never be part of upstream DT.
> Thus, the only sensible solution is to use DT overlay, which adds node to DT
> (maintaining patches is tedious). However, when overlays are used, U-Boot
> misses injecting MAC address, as described in commit message.
>
> Please reconsider this patch for inclusion in upstream.
>
> Best regards,
> Jernej
>
>  board/sunxi/board.c | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/board/sunxi/board.c b/board/sunxi/board.c
> index 1a46100e408d..97554d4642ed 100644
> --- a/board/sunxi/board.c
> +++ b/board/sunxi/board.c
> @@ -997,10 +997,12 @@ int ft_board_setup(void *blob, struct bd_info *bd)
> int __maybe_unused r;
>
> /*
> -* Call setup_environment again in case the boot fdt has
> -* ethernet aliases the u-boot copy does not have.
> +* Call setup_environment and fdt_fixup_ethernet again
> +* in case the boot fdt has ethernet aliases the u-boot
> +* copy does not have.
>  */
> setup_environment(blob);
> +   fdt_fixup_ethernet(blob);

Reviewed-by: Jagan Teki 


Re: [PATCH 2/3] dts: bpi-m2u: Enable USB_OTG by default

2021-12-06 Thread Jagan Teki
On Wed, Jun 30, 2021 at 1:09 PM  wrote:
>
> From: qianfan Zhao 
>
> bpi-m2u has a hardware usb_otg, let's enable it in dts.
>
> Signed-off-by: qianfan Zhao 
> ---

Better Sync dts from linux instead of intermediate changes.

Jagan.


Re: [PATCH v2 1/3] phy-sun4i-usb: Fix sun8i_r40_cfg

2021-12-06 Thread Jagan Teki
On Wed, Jun 30, 2021 at 1:09 PM  wrote:
>
> From: qianfan Zhao 
>
> the r40 has the same configurations with a33, disable enable_pmu_unk1 and
> phy0_dual_route feature.
>
> Signed-off-by: qianfan Zhao 
> ---

Reviewed-by: Jagan Teki 


Re: [PATCH v2 4/6] net: sun8i-emac: add v3s variant

2021-12-06 Thread Jagan Teki
On Sun, May 23, 2021 at 4:52 AM Andreas Rehn  wrote:
>
> Add variant V3S_EMAC.
> Handle pinmux compile time error by skipping goio setup, because
> V3s uses internal phy and don't expose pins.
>
> Signed-off-by: Andreas Rehn 
> ---
> Changes in v2:
> - skip pinmux and add proper description
> - Add V3S variant add it to compatible list
> - Skip (R)GMII flags and handle sun8i_handle_internal_phy
>
>  drivers/net/sun8i_emac.c | 15 ---
>  1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/sun8i_emac.c b/drivers/net/sun8i_emac.c
> index 5a1b38bf80..ab9f61994c 100644
> --- a/drivers/net/sun8i_emac.c
> +++ b/drivers/net/sun8i_emac.c
> @@ -145,6 +145,7 @@ enum emac_variant {
> A64_EMAC,
> R40_GMAC,
> H6_EMAC,
> +   V3S_EMAC,
>  };
>
>  struct emac_dma_desc {
> @@ -303,7 +304,7 @@ static void sun8i_adjust_link(struct emac_eth_dev *priv,
>  static u32 sun8i_emac_set_syscon_ephy(struct emac_eth_dev *priv, u32 reg)
>  {
> if (priv->use_internal_phy) {
> -   /* H3 based SoC's that has an Internal 100MBit PHY
> +   /* H3 and V3s based SoC's that has an Internal 100MBit PHY
>  * needs to be configured and powered up before use
> */
> reg &= ~H3_EPHY_DEFAULT_MASK;
> @@ -354,7 +355,8 @@ static int sun8i_emac_set_syscon(struct sun8i_eth_pdata 
> *pdata,
> case PHY_INTERFACE_MODE_RGMII_ID:
> case PHY_INTERFACE_MODE_RGMII_RXID:
> case PHY_INTERFACE_MODE_RGMII_TXID:
> -   reg |= SC_EPIT | SC_ETCS_INT_GMII;
> +   if (priv->variant != V3S_EMAC)
> +   reg |= SC_EPIT | SC_ETCS_INT_GMII;
> break;
> case PHY_INTERFACE_MODE_RMII:
> if (priv->variant == H3_EMAC ||
> @@ -566,6 +568,10 @@ static int parse_phy_pins(struct udevice *dev)
> iomux = SUN8I_IOMUX;
> else if (IS_ENABLED(CONFIG_MACH_SUN50I))
> iomux = SUN8I_IOMUX;
> +   else if (IS_ENABLED(CONFIG_MACH_SUN8I_V3S))
> +   // V3s does not expose any MAC pins,
> +   // but case is required to handle BUILD_BUG_ON_MSG.

Wrong multi-line comment. please fix it?

Jagan.


Re: [PATCH v2 5/6] dts: sunxi: v3s: enable emac

2021-12-06 Thread Jagan Teki
On Sat, May 22, 2021 at 1:36 AM Andreas Rehn  wrote:
>
> Enable emac for licheepi-zero-dock as it provides a ethernet port
>
> Signed-off-by: Andreas Rehn 
> ---
>  arch/arm/dts/sun8i-v3s-licheepi-zero-dock.dts | 9 +
>  1 file changed, 9 insertions(+)
>
> diff --git a/arch/arm/dts/sun8i-v3s-licheepi-zero-dock.dts 
> b/arch/arm/dts/sun8i-v3s-licheepi-zero-dock.dts
> index db5cd0b857..4d564028f2 100644
> --- a/arch/arm/dts/sun8i-v3s-licheepi-zero-dock.dts
> +++ b/arch/arm/dts/sun8i-v3s-licheepi-zero-dock.dts
> @@ -49,6 +49,10 @@
> compatible = "licheepi,licheepi-zero-dock", "licheepi,licheepi-zero",
>  "allwinner,sun8i-v3s";
>
> +   aliases {
> +   ethernet0 = 
> +   };
> +
> leds {
> /* The LEDs use PG0~2 pins, which conflict with MMC1 */
> status = "disabled";
> @@ -94,3 +98,8 @@
> voltage = <80>;
> };
>  };
> +
> + {
> +   allwinner,leds-active-low;
> +   status = "okay";
> +};

We (atleast on sunXi) cannot support intermediate dst changes, better
sync any specific tag or commit from upstream linux.

Jagan.


Re: [PATCH] spi: atmel-quadspi: Add support for SAMA7G5 QSPI

2021-12-06 Thread Jagan Teki
On Mon, Dec 6, 2021 at 10:21 PM  wrote:
>
> Hello Jagan,
>
> Do you wish to review this patch before I take it through the at91 tree ?
> I am skimming through the patches for the next cycle merge window.

Yes, please take it.

Jagan.


Re: [PATCH] spi: atmel-quadspi: Add support for SAMA7G5 QSPI

2021-12-06 Thread Jagan Teki
On Wed, Nov 3, 2021 at 10:17 PM Tudor Ambarus
 wrote:
>
> sama7g5 QSPI has:
> 1/ One Octal Serial Peripheral Interfaces (QSPI0) Supporting Up to
>200 MHz DDR. Octal, TwinQuad, Hyperflash and OctaFlash Protocols Supported
> 2/ One Quad Serial Peripheral Interfaces (QSPI1) Supporting Up to
>90 MHz DDR/133 MHz SDR
>
> The QSPI controller of SAMA7G5 uses different clock domains, hence extra
> synchronization operations must be performed before accessing some
> registers. Differentiate between the versions of the IP using has_gclk.
> Differentiate between QSPI0 and QSPI1 with has_octal.
>
> Signed-off-by: Tudor Ambarus 
> ---

Reviewed-by: Jagan Teki 


Re: [PATCH v7 09/31] arm: xenguest_arm64: Add a empty devicetree file

2021-12-06 Thread Oleksandr Andrushchenko
Hi, Simon!

On 07.12.21 02:11, Simon Glass wrote:
> Add an empty file to prevent build errors when building with
> CONFIG_OF_SEPARATE enabled.
>
> The build instructions in U-Boot do not provide enough detail to build a
> useful devicetree, unfortunately.
There is no such instruction exists as the device tree is built at run-time
by the hypervisor itself depending on virtual machine configuration:
I have already pointed that, e.g. U-boot is no different from any other
kernel/binary running in a virtual machine.

Thus I do not agree with the sentence above as it misleads.
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v7:
> - Use 'empty' instead of 'fake'
>
>   arch/arm/dts/Makefile|  2 ++
>   arch/arm/dts/xenguest-arm64.dts  | 15 +++
>   configs/xenguest_arm64_defconfig |  2 +-
>   3 files changed, 18 insertions(+), 1 deletion(-)
>   create mode 100644 arch/arm/dts/xenguest-arm64.dts
>
> diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> index d53bae2c350..f6345988c8c 100644
> --- a/arch/arm/dts/Makefile
> +++ b/arch/arm/dts/Makefile
> @@ -1140,6 +1140,8 @@ dtb-$(CONFIG_ARCH_MEDIATEK) += \
>   mt8516-pumpkin.dtb \
>   mt8518-ap1-emmc.dtb
>   
> +dtb-$(CONFIG_XEN) += xenguest-arm64.dtb
> +
>   dtb-$(CONFIG_TARGET_GE_BX50V3) += \
>   imx6q-bx50v3.dtb \
>   imx6q-b850v3.dtb \
> diff --git a/arch/arm/dts/xenguest-arm64.dts b/arch/arm/dts/xenguest-arm64.dts
> new file mode 100644
> index 000..d8734433763
> --- /dev/null
> +++ b/arch/arm/dts/xenguest-arm64.dts
> @@ -0,0 +1,15 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Empty devicetree file for xenguest_arm64
> + *
> + * This is required to make the board build with CONFIG OF_SEPARATE
> + * Build instructions at xenguest_arm64.rst are inadequate for obtaining a 
> real
> + * devicetree.
ditto. I will not provide any instruction as this is internal to Xen 
implementation
and may change depending on Xen version and virtual machine configuration.
If someone wants that she can dig into relevant Xen sources to see how the
device tree constructed. But this may be different between Xen versions and/or
virtual machine settings.

Please rephrase to reflect the dynamic nature of the device tree instead

Thank you,
Oleksandr
> + *
> + * Copyright 2021 Google LLC
> + */
> +
> +/dts-v1/;
> +
> +/ {
> +};
> diff --git a/configs/xenguest_arm64_defconfig 
> b/configs/xenguest_arm64_defconfig
> index 8d9d9133a2e..edce34346d3 100644
> --- a/configs/xenguest_arm64_defconfig
> +++ b/configs/xenguest_arm64_defconfig
> @@ -3,7 +3,7 @@ CONFIG_POSITION_INDEPENDENT=y
>   CONFIG_TARGET_XENGUEST_ARM64=y
>   CONFIG_SYS_TEXT_BASE=0x4008
>   CONFIG_SYS_MALLOC_LEN=0x200
> -CONFIG_SYS_MALLOC_F_LEN=0x2000
> +CONFIG_DEFAULT_DEVICE_TREE="xenguest-arm64"
>   CONFIG_IDENT_STRING=" xenguest"
>   CONFIG_SYS_LOAD_ADDR=0x4000
>   CONFIG_BOOTDELAY=10


[PATCH v2 3/3] efi_loader: correctly handle no tpm device error

2021-12-06 Thread Masahisa Kojima
When the TCG2 protocol is installed in efi_tcg2_register(),
TPM2 device must be present.
tcg2_measure_pe_image() expects that TCP2 protocol is installed
and TPM device is available. If TCG2 Protocol is installed but
TPM device is not found, tcg2_measure_pe_image() returns
EFI_SECURITY_VIOLATION and efi_load_image() ends with failure.

The same error handling is applied to
efi_tcg2_measure_efi_app_invocation().

Signed-off-by: Masahisa Kojima 
---

Changes in v2:
- EFI_SECURITY_VIOLATION is returned in
  efi_tcg2_measure_efi_app_invocation()

 lib/efi_loader/efi_boottime.c |  9 ++---
 lib/efi_loader/efi_image_loader.c | 13 ++---
 lib/efi_loader/efi_tcg2.c |  4 ++--
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index 8492b732f3..20b69699fe 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -3016,9 +3016,12 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t 
image_handle,
if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) {
if (image_obj->image_type == IMAGE_SUBSYSTEM_EFI_APPLICATION) {
ret = efi_tcg2_measure_efi_app_invocation(image_obj);
-   if (ret != EFI_SUCCESS) {
-   log_warning("tcg2 measurement fails(0x%lx)\n",
-   ret);
+   if (ret == EFI_SECURITY_VIOLATION) {
+   /*
+* TCG2 Protocol is installed but no TPM device 
found,
+* this is not expected.
+*/
+   return EFI_EXIT(EFI_SECURITY_VIOLATION);
}
}
}
diff --git a/lib/efi_loader/efi_image_loader.c 
b/lib/efi_loader/efi_image_loader.c
index eb95580538..773bd0677c 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -934,9 +934,16 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj 
*handle,
 
 #if CONFIG_IS_ENABLED(EFI_TCG2_PROTOCOL)
/* Measure an PE/COFF image */
-   if (tcg2_measure_pe_image(efi, efi_size, handle,
- loaded_image_info))
-   log_err("PE image measurement failed\n");
+   ret = tcg2_measure_pe_image(efi, efi_size, handle, loaded_image_info);
+   if (ret == EFI_SECURITY_VIOLATION) {
+   /*
+* TCG2 Protocol is installed but no TPM device found,
+* this is not expected.
+*/
+   log_err("PE image measurement failed, no tpm device found\n");
+   goto err;
+   }
+
 #endif
 
/* Copy PE headers */
diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c
index 59bce85028..0ae07ef083 100644
--- a/lib/efi_loader/efi_tcg2.c
+++ b/lib/efi_loader/efi_tcg2.c
@@ -977,7 +977,7 @@ efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size,
 
ret = platform_get_tpm2_device();
if (ret != EFI_SUCCESS)
-   return ret;
+   return EFI_SECURITY_VIOLATION;
 
switch (handle->image_type) {
case IMAGE_SUBSYSTEM_EFI_APPLICATION:
@@ -2200,7 +2200,7 @@ efi_status_t efi_tcg2_measure_efi_app_invocation(struct 
efi_loaded_image_obj *ha
 
ret = platform_get_tpm2_device();
if (ret != EFI_SUCCESS)
-   return ret;
+   return EFI_SECURITY_VIOLATION;
 
ret = tcg2_measure_boot_variable(dev);
if (ret != EFI_SUCCESS)
-- 
2.17.1



[PATCH v2 2/3] efi_loader: check tcg2 protocol installation outside the TCG protocol

2021-12-06 Thread Masahisa Kojima
There are functions that calls tcg2_agile_log_append() outside
of the TCG protocol invocation (e.g tcg2_measure_pe_image).
These functions must to check that TCG2 protocol is installed.
If not, measurement shall be skipped.

Signed-off-by: Masahisa Kojima 
---

No update since v1

 lib/efi_loader/efi_tcg2.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c
index bdfd9a37b5..59bce85028 100644
--- a/lib/efi_loader/efi_tcg2.c
+++ b/lib/efi_loader/efi_tcg2.c
@@ -972,6 +972,9 @@ efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size,
IMAGE_NT_HEADERS32 *nt;
struct efi_handler *handler;
 
+   if (!is_tcg2_protocol_installed())
+   return EFI_SUCCESS;
+
ret = platform_get_tpm2_device();
if (ret != EFI_SUCCESS)
return ret;
@@ -2189,6 +2192,9 @@ efi_status_t efi_tcg2_measure_efi_app_invocation(struct 
efi_loaded_image_obj *ha
u32 event = 0;
struct smbios_entry *entry;
 
+   if (!is_tcg2_protocol_installed())
+   return EFI_SUCCESS;
+
if (tcg2_efi_app_invoked)
return EFI_SUCCESS;
 
@@ -2239,6 +2245,9 @@ efi_status_t efi_tcg2_measure_efi_app_exit(void)
efi_status_t ret;
struct udevice *dev;
 
+   if (!is_tcg2_protocol_installed())
+   return EFI_SUCCESS;
+
ret = platform_get_tpm2_device();
if (ret != EFI_SUCCESS)
return ret;
@@ -2264,6 +2273,12 @@ efi_tcg2_notify_exit_boot_services(struct efi_event 
*event, void *context)
EFI_ENTRY("%p, %p", event, context);
 
event_log.ebs_called = true;
+
+   if (!is_tcg2_protocol_installed()) {
+   ret = EFI_SUCCESS;
+   goto out;
+   }
+
ret = platform_get_tpm2_device();
if (ret != EFI_SUCCESS)
goto out;
@@ -2293,6 +2308,9 @@ efi_status_t 
efi_tcg2_notify_exit_boot_services_failed(void)
struct udevice *dev;
efi_status_t ret;
 
+   if (!is_tcg2_protocol_installed())
+   return EFI_SUCCESS;
+
ret = platform_get_tpm2_device();
if (ret != EFI_SUCCESS)
goto out;
-- 
2.17.1



[PATCH v2 1/3] efi_loader: efi_tcg2_register returns appropriate error

2021-12-06 Thread Masahisa Kojima
This commit modify efi_tcg2_register() to return the
appropriate error.
With this fix, sandbox will not boot because efi_tcg2_register()
fails due to some missing feature in GetCapabilities.
So disable sandbox if EFI_TCG2_PROTOCOL is enabled.

UEFI secure boot variable measurement is not directly related
to TCG2 protocol installation, tcg2_measure_secure_boot_variable()
is moved to the separate function.

Signed-off-by: Masahisa Kojima 
---

Changes in v2:
- return EFI_SECURITY_VIOLATION if there is no tpm device found
  in efi_tcg2_do_initial_measurement()

 include/efi_loader.h   |  2 ++
 lib/efi_loader/Kconfig |  2 ++
 lib/efi_loader/efi_setup.c |  4 +++
 lib/efi_loader/efi_tcg2.c  | 65 +++---
 4 files changed, 55 insertions(+), 18 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 67c40ca57a..f4860e87fc 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -525,6 +525,8 @@ efi_status_t efi_disk_register(void);
 efi_status_t efi_rng_register(void);
 /* Called by efi_init_obj_list() to install EFI_TCG2_PROTOCOL */
 efi_status_t efi_tcg2_register(void);
+/* Called by efi_init_obj_list() to do initial measurement */
+efi_status_t efi_tcg2_do_initial_measurement(void);
 /* measure the pe-coff image, extend PCR and add Event Log */
 efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size,
   struct efi_loaded_image_obj *handle,
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 700dc838dd..24f9a2bb75 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -308,6 +308,8 @@ config EFI_TCG2_PROTOCOL
bool "EFI_TCG2_PROTOCOL support"
default y
depends on TPM_V2
+   # Sandbox TPM currently fails on GetCapabilities needed for TCG2
+   depends on !SANDBOX
select SHA1
select SHA256
select SHA384
diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index 1aba71cd96..49172e3579 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -241,6 +241,10 @@ efi_status_t efi_init_obj_list(void)
ret = efi_tcg2_register();
if (ret != EFI_SUCCESS)
goto out;
+
+   ret = efi_tcg2_do_initial_measurement();
+   if (ret == EFI_SECURITY_VIOLATION)
+   goto out;
}
 
/* Secure boot */
diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c
index 5f71b188a0..bdfd9a37b5 100644
--- a/lib/efi_loader/efi_tcg2.c
+++ b/lib/efi_loader/efi_tcg2.c
@@ -153,6 +153,15 @@ static u16 alg_to_len(u16 hash_alg)
return 0;
 }
 
+static bool is_tcg2_protocol_installed(void)
+{
+   struct efi_handler *handler;
+   efi_status_t ret;
+
+   ret = efi_search_protocol(efi_root, _guid_tcg2_protocol, );
+   return ret == EFI_SUCCESS;
+}
+
 static u32 tcg_event_final_size(struct tpml_digest_values *digest_list)
 {
u32 len;
@@ -1664,6 +1673,14 @@ void tcg2_uninit(void)
event_log.buffer = NULL;
efi_free_pool(event_log.final_buffer);
event_log.final_buffer = NULL;
+
+   if (!is_tcg2_protocol_installed())
+   return;
+
+   ret = efi_remove_protocol(efi_root, _guid_tcg2_protocol,
+ (void *)_tcg2_protocol);
+   if (ret != EFI_SUCCESS)
+   log_err("Failed to remove EFI TCG2 protocol\n");
 }
 
 /**
@@ -2345,12 +2362,37 @@ error:
return ret;
 }
 
+/**
+ * efi_tcg2_do_initial_measurement() - do initial measurement
+ *
+ * Return: status code
+ */
+efi_status_t efi_tcg2_do_initial_measurement(void)
+{
+   efi_status_t ret;
+   struct udevice *dev;
+
+   if (!is_tcg2_protocol_installed())
+   return EFI_SUCCESS;
+
+   ret = platform_get_tpm2_device();
+   if (ret != EFI_SUCCESS)
+   return EFI_SECURITY_VIOLATION;
+
+   ret = tcg2_measure_secure_boot_variable(dev);
+   if (ret != EFI_SUCCESS)
+   goto out;
+
+out:
+   return ret;
+}
+
 /**
  * efi_tcg2_register() - register EFI_TCG2_PROTOCOL
  *
  * If a TPM2 device is available, the TPM TCG2 Protocol is registered
  *
- * Return: An error status is only returned if adding the protocol fails.
+ * Return: status code
  */
 efi_status_t efi_tcg2_register(void)
 {
@@ -2373,8 +2415,10 @@ efi_status_t efi_tcg2_register(void)
}
 
ret = efi_init_event_log();
-   if (ret != EFI_SUCCESS)
+   if (ret != EFI_SUCCESS) {
+   tcg2_uninit();
goto fail;
+   }
 
ret = efi_add_protocol(efi_root, _guid_tcg2_protocol,
   (void *)_tcg2_protocol);
@@ -2391,24 +2435,9 @@ efi_status_t efi_tcg2_register(void)
goto fail;
}
 
-   ret = tcg2_measure_secure_boot_variable(dev);
-   if (ret != EFI_SUCCESS) {
-   tcg2_uninit();
-   goto fail;
-   }
-
  

[PATCH v2 0/3] fix TCG2 error handling

2021-12-06 Thread Masahisa Kojima
This series fix the efi_tcg2.c error handling.

Masahisa Kojima (3):
  efi_loader: efi_tcg2_register returns appropriate error
  efi_loader: check tcg2 protocol installation outside the TCG protocol
  efi_loader: correctly handle no tpm device error

 include/efi_loader.h  |  2 +
 lib/efi_loader/Kconfig|  2 +
 lib/efi_loader/efi_boottime.c |  9 ++--
 lib/efi_loader/efi_image_loader.c | 13 +++--
 lib/efi_loader/efi_setup.c|  4 ++
 lib/efi_loader/efi_tcg2.c | 87 ---
 6 files changed, 91 insertions(+), 26 deletions(-)

-- 
2.17.1



RE: [PATCH 15/15] arm: dts: ls1028a-qds: declare in-band autoneg for Ethernet ports

2021-12-06 Thread Priyanka Jain



>-Original Message-
>From: Vladimir Oltean 
>Sent: Thursday, December 2, 2021 8:24 PM
>To: u-boot@lists.denx.de
>Cc: Michael Walle ; Tom Rini ;
>Priyanka Jain ; Leo Li ; Ramon
>Fried 
>Subject: [PATCH 15/15] arm: dts: ls1028a-qds: declare in-band autoneg for
>Ethernet ports
>
>As explained in the previous patch "arm: dts: ls1028a-rdb: sync Ethernet
>device tree nodes with Linux", the commit below broke traffic through switch
>ports where the SERDES protocol requires in-band autoneg: SGMII, QSGMII,
>USXGMII (with 2500Base-X, in-band autoneg isn't supported).
>
Please write description independent of other patch or mention commit details
for better readability at later point.

>The LS1028A-QDS boards are not yet ready for syncing their device trees with
>Linux, since Ethernet is missing there (but has been submitted):
>https://lore.kernel.org/lkml/2022223457.10599-11-leoyang...@nxp.com/
>
>When agreement is reached for the Ethernet support in Linux, there will be a
>sync for these boards as well. For now, just enable in-band autoneg to fix the
>breakage.
>
>Fixes: e3789a726269 ("net: dsa: felix: configure the in-band autoneg property
>based on OF node info")
>Cc: Ramon Fried 
>Signed-off-by: Vladimir Oltean 
>---

Some minor comments on description, rest looks fine

Reviewed-by: Priyanka Jain 


RE: [PATCH 14/15] arm: dts: ls1028a-rdb: sync device tree with Linux

2021-12-06 Thread Priyanka Jain



>-Original Message-
>From: Vladimir Oltean 
>Sent: Thursday, December 2, 2021 8:24 PM
>To: u-boot@lists.denx.de
>Cc: Michael Walle ; Tom Rini ;
>Priyanka Jain ; Leo Li 
>Subject: [PATCH 14/15] arm: dts: ls1028a-rdb: sync device tree with Linux
>
>Allow device trees to be reused between Linux and U-Boot.
>The source for these device trees is today's linux-next plus these changes that
>have been made so that the sources can be shared. These other patches are
>currently in flight:
>https://lore.kernel.org/linux-arm-kernel/20211202141528.2450169-5-
>vladimir.olt...@nxp.com/T/#m6f63c92e75fa79a01144b2c2c6dc4776e7971395
>
>Signed-off-by: Vladimir Oltean 
>---


Reviewed-by: Priyanka Jain 


RE: [PATCH 12/15] arm: dts: ls1028a-rdb: disable I2C buses 1 through 7

2021-12-06 Thread Priyanka Jain



>-Original Message-
>From: Vladimir Oltean 
>Sent: Thursday, December 2, 2021 8:24 PM
>To: u-boot@lists.denx.de
>Cc: Michael Walle ; Tom Rini ;
>Priyanka Jain ; Leo Li 
>Subject: [PATCH 12/15] arm: dts: ls1028a-rdb: disable I2C buses 1 through 7
>
>There is no I2C peripheral on these buses on the reference design board, and
>the Linux device tree does not enable them either.
>
>Signed-off-by: Vladimir Oltean 
>---
> arch/arm/dts/fsl-ls1028a-rdb.dts | 28 
> 1 file changed, 28 deletions(-)
>
>diff --git a/arch/arm/dts/fsl-ls1028a-rdb.dts b/arch/arm/dts/fsl-ls1028a-
>rdb.dts
>index 5a3f404d0040..c346ad9b881c 100644
>--- a/arch/arm/dts/fsl-ls1028a-rdb.dts
>+++ b/arch/arm/dts/fsl-ls1028a-rdb.dts
>@@ -112,34 +112,6 @@
>   };
> };
>

Reviewed-by: Priyanka Jain 


RE: [PATCH 11/15] arm: dts: ls1028a-rdb: disable DSPI nodes

2021-12-06 Thread Priyanka Jain



>-Original Message-
>From: Vladimir Oltean 
>Sent: Thursday, December 2, 2021 8:24 PM
>To: u-boot@lists.denx.de
>Cc: Michael Walle ; Tom Rini ;
>Priyanka Jain ; Leo Li 
>Subject: [PATCH 11/15] arm: dts: ls1028a-rdb: disable DSPI nodes
>
>There is no SPI peripheral on the LS1028A-RDB, therefore no reason to enable
>these nodes in the U-Boot device tree (and Linux does not enable them
>either).
>
>Signed-off-by: Vladimir Oltean 
>---
Reviewed-by: Priyanka Jain 


RE: [PATCH 10/15] arm: dts: ls1028a-rdb: sync Ethernet device tree nodes with Linux

2021-12-06 Thread Priyanka Jain



>-Original Message-
>From: Vladimir Oltean 
>Sent: Thursday, December 2, 2021 8:24 PM
>To: u-boot@lists.denx.de
>Cc: Michael Walle ; Tom Rini ;
>Priyanka Jain ; Leo Li ; Ramon
>Fried 
>Subject: [PATCH 10/15] arm: dts: ls1028a-rdb: sync Ethernet device tree nodes
>with Linux
>
>In a bit of a blunder, the blamed commit made the mscc_felix switch driver
Please be specific about which commit 

>look at the 'managed = "in-band-status"' device tree property, forgetting that
>the U-Boot device tree had not been updated to include that property,
>whereas the Linux one does.
>
>The switch is therefore described in the device tree as not requiring in-band
>autoneg, but the PHY driver for VSC8514 (drivers/net/phy/mscc.c) still enables
>that feature. This results in a mismatch => no traffic.
>
>This patch is a copy-paste of the Ethernet device tree nodes from Linux, which
>resolves that issue. The device tree update also renames the Ethernet PHY
>labels.
>
>Fixes: e3789a726269 ("net: dsa: felix: configure the in-band autoneg property
>based on OF node info")

I see the commit details now, can you please this statement in start while 
talking about this

>Cc: Ramon Fried 
>Signed-off-by: Vladimir Oltean 
>---


Some minor comments on patch description. Rest looks fine

Reviewed-by: Priyanka Jain 


RE: [PATCH 09/15] arm: dts: ls1028a-rdb: sort nodes alphabetically

2021-12-06 Thread Priyanka Jain



>-Original Message-
>From: Vladimir Oltean 
>Sent: Thursday, December 2, 2021 8:24 PM
>To: u-boot@lists.denx.de
>Cc: Michael Walle ; Tom Rini ;
>Priyanka Jain ; Leo Li 
>Subject: [PATCH 09/15] arm: dts: ls1028a-rdb: sort nodes alphabetically
>
>The nodes in the NXP LS1028A-RDB device tree are out of order, regroup
>them alphabetically to have a simple delta when the Linux device tree is
>brought in.
>
>Signed-off-by: Vladimir Oltean 
>---


Reviewed-by: Priyanka Jain 


RE: [PATCH 08/15] rtc: pcf2127: remove U-Boot specific compatible string

2021-12-06 Thread Priyanka Jain



>-Original Message-
>From: Vladimir Oltean 
>Sent: Thursday, December 2, 2021 8:24 PM
>To: u-boot@lists.denx.de
>Cc: Michael Walle ; Tom Rini ;
>Priyanka Jain ; Leo Li ; Simon
>Glass 
>Subject: [PATCH 08/15] rtc: pcf2127: remove U-Boot specific compatible string
>
>Now that all in-tree boards have been converted to the compatible strings
>from Linux, delete the support for the ad-hoc "pcf2127-rtc" one.
>
>Cc: Simon Glass 
>Signed-off-by: Vladimir Oltean 
>---
> drivers/rtc/pcf2127.c | 1 -
> 1 file changed, 1 deletion(-)
>
>diff --git a/drivers/rtc/pcf2127.c b/drivers/rtc/pcf2127.c index
>291ef0329a3e..2f3fafb4968f 100644
>--- a/drivers/rtc/pcf2127.c
>+++ b/drivers/rtc/pcf2127.c
>@@ -120,7 +120,6 @@ static const struct rtc_ops pcf2127_rtc_ops = {  };
>
> static const struct udevice_id pcf2127_rtc_ids[] = {
>-  { .compatible = "pcf2127-rtc" },
>   { .compatible = "nxp,pcf2127" },
>   { .compatible = "nxp,pcf2129" },
>   { .compatible = "nxp,pca2129" },
>--
>2.25.1

Kindly confirm no existing platform uses this?
Is build tested pass for all platforms?

Regards
Priyanka




RE: [PATCH 07/15] arm: dts: lx2160a-rdb: use Linux compatible string for RTC

2021-12-06 Thread Priyanka Jain



>-Original Message-
>From: Vladimir Oltean 
>Sent: Thursday, December 2, 2021 8:24 PM
>To: u-boot@lists.denx.de
>Cc: Michael Walle ; Tom Rini ;
>Priyanka Jain ; Leo Li 
>Subject: [PATCH 07/15] arm: dts: lx2160a-rdb: use Linux compatible string for
>RTC
>
>During the LS1028A-RDB sync with Linux device trees, it was observed that the
>same RTC is present on the two boards, and the wrong compatible string is
>used in both places. This change updates the RTC from the LX2160A-RDB to
>use the compatible string that was established in Linux.
>
>Signed-off-by: Vladimir Oltean 
>---
> arch/arm/dts/fsl-lx2160a-rdb.dts | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/arch/arm/dts/fsl-lx2160a-rdb.dts b/arch/arm/dts/fsl-lx2160a-
>rdb.dts
>index 5fbdd907017c..8ca4afa7eaea 100644
>--- a/arch/arm/dts/fsl-lx2160a-rdb.dts
>+++ b/arch/arm/dts/fsl-lx2160a-rdb.dts
>@@ -117,7 +117,7 @@
>   status = "okay";
>
>   rtc@51 {
>-  compatible = "pcf2127-rtc";
>+  compatible = "nxp,pcf2129";
>   reg = <0x51>;
>   };
> };
>--
>2.25.1
Reviewed-by: Priyanka Jain 



RE: [PATCH 06/15] arm: lx2160a-qds: use Linux compatible string for RTC

2021-12-06 Thread Priyanka Jain



>-Original Message-
>From: Vladimir Oltean 
>Sent: Thursday, December 2, 2021 8:24 PM
>To: u-boot@lists.denx.de
>Cc: Michael Walle ; Tom Rini ;
>Priyanka Jain ; Leo Li 
>Subject: [PATCH 06/15] arm: lx2160a-qds: use Linux compatible string for RTC
>
>During the LS1028A-RDB sync with Linux device trees, it was observed that the
>same RTC is present on the two boards, and the wrong compatible string is
>used in both places. This change updates the RTC from the LX2160A-QDS to
>use the compatible string that was established in Linux.
>
>Signed-off-by: Vladimir Oltean 
>---
> arch/arm/dts/fsl-lx2160a-qds.dtsi | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/arch/arm/dts/fsl-lx2160a-qds.dtsi b/arch/arm/dts/fsl-lx2160a-
>qds.dtsi
>index 288607c0347b..69e11cca2da1 100644
>--- a/arch/arm/dts/fsl-lx2160a-qds.dtsi
>+++ b/arch/arm/dts/fsl-lx2160a-qds.dtsi
>@@ -250,7 +250,7 @@
>   reg = <0x3>;
>
>   rtc@51 {
>-  compatible = "pcf2127-rtc";
>+  compatible = "nxp,pcf2129";
>   reg = <0x51>;
>   };
>   };
>--
>2.25.1
Reviewed-by: Priyanka Jain 



RE: [PATCH 05/15] arm: ls1088a-rdb: use Linux compatible string for RTC

2021-12-06 Thread Priyanka Jain



>-Original Message-
>From: Vladimir Oltean 
>Sent: Thursday, December 2, 2021 8:24 PM
>To: u-boot@lists.denx.de
>Cc: Michael Walle ; Tom Rini ;
>Priyanka Jain ; Leo Li 
>Subject: [PATCH 05/15] arm: ls1088a-rdb: use Linux compatible string for RTC
>
>During the LS1028A-RDB sync with Linux device trees, it was observed that the
>same RTC is present on the two boards, and the wrong compatible string is
>used in both places. This change updates the RTC from the LS1088A-RDB to
>use the compatible string that was established in Linux.
>
>Signed-off-by: Vladimir Oltean 
>---
> arch/arm/dts/fsl-ls1088a-rdb.dts | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/arch/arm/dts/fsl-ls1088a-rdb.dts b/arch/arm/dts/fsl-ls1088a-
>rdb.dts
>index de92bf22e203..5cdd59815234 100644
>--- a/arch/arm/dts/fsl-ls1088a-rdb.dts
>+++ b/arch/arm/dts/fsl-ls1088a-rdb.dts
>@@ -135,7 +135,7 @@
>   reg = <0x3>;
>
>   rtc@51 {
>-  compatible = "pcf2127-rtc";
>+  compatible = "nxp,pcf2129";
>   reg = <0x51>;
>   };
>   };
>--
>2.25.1
Reviewed-by: Priyanka Jain 



RE: [PATCH 04/15] arm: ls1088a-qds: use Linux compatible string for RTC

2021-12-06 Thread Priyanka Jain


>-Original Message-
>From: Vladimir Oltean 
>Sent: Thursday, December 2, 2021 8:24 PM
>To: u-boot@lists.denx.de
>Cc: Michael Walle ; Tom Rini ;
>Priyanka Jain ; Leo Li 
>Subject: [PATCH 04/15] arm: ls1088a-qds: use Linux compatible string for RTC
>
>During the LS1028A-RDB sync with Linux device trees, it was observed that the
>same RTC is present on the two boards, and the wrong compatible string is
>used in both places. This change updates the RTC from the LS1088A-QDS to
>use the compatible string that was established in Linux.
>
>Signed-off-by: Vladimir Oltean 
>---

Reviewed-by: Priyanka Jain 


RE: [PATCH 03/15] arm: dts: ls1028a-qds: use Linux compatible string for RTC

2021-12-06 Thread Priyanka Jain



>-Original Message-
>From: Vladimir Oltean 
>Sent: Thursday, December 2, 2021 8:24 PM
>To: u-boot@lists.denx.de
>Cc: Michael Walle ; Tom Rini ;
>Priyanka Jain ; Leo Li 
>Subject: [PATCH 03/15] arm: dts: ls1028a-qds: use Linux compatible string for 
>RTC
>
>The LS1028A-QDS board won't be synced with the Linux device trees right now,
>since those are currently still in progress (Ethernet is missing).
>
>However, while we're at converting the RDB, it can be observed that the same
>RTC is present on the two boards, and the wrong compatible string is used in 
>both
>places. This change updates the RTC from the QDS to use the compatible string
>that was established in Linux.
>
>Signed-off-by: Vladimir Oltean 
>---


Reviewed-by: Priyanka Jain 


RE: [PATCH 01/15] i2c: muxes: pca954x: add PCA9847 variant

2021-12-06 Thread Priyanka Jain



>-Original Message-
>From: Vladimir Oltean 
>Sent: Thursday, December 2, 2021 8:24 PM
>To: u-boot@lists.denx.de
>Cc: Michael Walle ; Tom Rini ;
>Priyanka Jain ; Leo Li ; Heiko
>Schocher 
>Subject: [PATCH 01/15] i2c: muxes: pca954x: add PCA9847 variant
>
>This seems to be very similar to the already existing PCA9547, save for the 
>fact
>that it supports 0.8V and doesn't support 5V. In fact, it is so similar to the
>PCA9547 that the NXP LS1028A-RDB board has been driving this chip using a
>"nxp,pca9547" compatible string.
>
>Create a new compatible for the PCA9847 (which is the same as in Linux) and
>define the same operating parameters for it as for PCA9547.
>
>Cc: Heiko Schocher 
>Signed-off-by: Vladimir Oltean 
>---

Reviewed-by: Priyanka Jain 


Re: [PATCH 1/3] efi_loader: efi_tcg2_register returns appropriate error

2021-12-06 Thread Masahisa Kojima
On Mon, 6 Dec 2021 at 23:08, Ilias Apalodimas
 wrote:
>
> On Fri, Dec 03, 2021 at 12:58:13PM +0900, Masahisa Kojima wrote:
> > This commit modify efi_tcg2_register() to return the
> > appropriate error.
> > With this fix, sandbox will not boot because efi_tcg2_register()
> > fails due to some missing feature in GetCapabilities.
> > So disable sandbox if EFI_TCG2_PROTOCOL is enabled.
> >
> > UEFI secure boot variable measurement is not directly related
> > to TCG2 protocol installation, tcg2_measure_secure_boot_variable()
> > is moved to the separate function.
> >
> > Signed-off-by: Masahisa Kojima 
> > ---
> >  include/efi_loader.h   |  2 ++
> >  lib/efi_loader/Kconfig |  2 ++
> >  lib/efi_loader/efi_setup.c |  2 ++
> >  lib/efi_loader/efi_tcg2.c  | 65 +++---
> >  4 files changed, 53 insertions(+), 18 deletions(-)
> >
> > diff --git a/include/efi_loader.h b/include/efi_loader.h
> > index 67c40ca57a..f4860e87fc 100644
> > --- a/include/efi_loader.h
> > +++ b/include/efi_loader.h
> > @@ -525,6 +525,8 @@ efi_status_t efi_disk_register(void);
> >  efi_status_t efi_rng_register(void);
> >  /* Called by efi_init_obj_list() to install EFI_TCG2_PROTOCOL */
> >  efi_status_t efi_tcg2_register(void);
> > +/* Called by efi_init_obj_list() to do initial measurement */
> > +efi_status_t efi_tcg2_do_initial_measurement(void);
> >  /* measure the pe-coff image, extend PCR and add Event Log */
> >  efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size,
> >  struct efi_loaded_image_obj *handle,
> > diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
> > index 700dc838dd..24f9a2bb75 100644
> > --- a/lib/efi_loader/Kconfig
> > +++ b/lib/efi_loader/Kconfig
> > @@ -308,6 +308,8 @@ config EFI_TCG2_PROTOCOL
> >   bool "EFI_TCG2_PROTOCOL support"
> >   default y
> >   depends on TPM_V2
> > + # Sandbox TPM currently fails on GetCapabilities needed for TCG2
> > + depends on !SANDBOX
> >   select SHA1
> >   select SHA256
> >   select SHA384
> > diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
> > index 1aba71cd96..f58a4afa7f 100644
> > --- a/lib/efi_loader/efi_setup.c
> > +++ b/lib/efi_loader/efi_setup.c
> > @@ -241,6 +241,8 @@ efi_status_t efi_init_obj_list(void)
> >   ret = efi_tcg2_register();
> >   if (ret != EFI_SUCCESS)
> >   goto out;
> > +
> > + efi_tcg2_do_initial_measurement();
> >   }
> >
> >   /* Secure boot */
> > diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c
> > index 5f71b188a0..6dbdd35f29 100644
> > --- a/lib/efi_loader/efi_tcg2.c
> > +++ b/lib/efi_loader/efi_tcg2.c
> > @@ -153,6 +153,15 @@ static u16 alg_to_len(u16 hash_alg)
> >   return 0;
> >  }
> >
> > +static bool is_tcg2_protocol_installed(void)
> > +{
> > + struct efi_handler *handler;
> > + efi_status_t ret;
> > +
> > + ret = efi_search_protocol(efi_root, _guid_tcg2_protocol, 
> > );
> > + return ret == EFI_SUCCESS;
> > +}
> > +
> >  static u32 tcg_event_final_size(struct tpml_digest_values *digest_list)
> >  {
> >   u32 len;
> > @@ -1664,6 +1673,14 @@ void tcg2_uninit(void)
> >   event_log.buffer = NULL;
> >   efi_free_pool(event_log.final_buffer);
> >   event_log.final_buffer = NULL;
> > +
> > + if (!is_tcg2_protocol_installed())
> > + return;
> > +
> > + ret = efi_remove_protocol(efi_root, _guid_tcg2_protocol,
> > +   (void *)_tcg2_protocol);
> > + if (ret != EFI_SUCCESS)
> > + log_err("Failed to remove EFI TCG2 protocol\n");
> >  }
> >
> >  /**
> > @@ -2345,12 +2362,37 @@ error:
> >   return ret;
> >  }
> >
> > +/**
> > + * efi_tcg2_do_initial_measurement() - do initial measurement
> > + *
> > + * Return:   status code
> > + */
> > +efi_status_t efi_tcg2_do_initial_measurement(void)
> > +{
> > + efi_status_t ret;
> > + struct udevice *dev;
> > +
> > + if (!is_tcg2_protocol_installed())
> > + return EFI_SUCCESS;
> > +
> > + ret = platform_get_tpm2_device();
> > + if (ret != EFI_SUCCESS)
> > + goto out;
> > +
>
> Would it make more sense to return a security violation here and treat this
> error similarly to patch [3/3]?

Yes, I agree. I also add the similar check for
efi_tcg2_measure_efi_app_invocation().

Thanks,
Masahisa Kojima

>
> > + ret = tcg2_measure_secure_boot_variable(dev);
> > + if (ret != EFI_SUCCESS)
> > + goto out;
> > +
> > +out:
> > + return ret;
> > +}
> > +
> >  /**
> >   * efi_tcg2_register() - register EFI_TCG2_PROTOCOL
> >   *
> >   * If a TPM2 device is available, the TPM TCG2 Protocol is registered
> >   *
> > - * Return:   An error status is only returned if adding the protocol fails.
> > + * Return:   status code
> >   */
> >  efi_status_t efi_tcg2_register(void)
> >  {
> > @@ -2373,8 +2415,10 @@ efi_status_t efi_tcg2_register(void)
> >   

Bootargs received by a uImage but not by a FIT

2021-12-06 Thread Richard Thanki
Hi all, I’m reaching out on this list as my problem spans U-Boot and Openwrt. 
In essence the very same kernel (5.4 and 5.10 - built using latest Openwrt), 
packaged in a FIT, is not receiving bootlogs from latest U-Boot and it’s also 
not being informed of the presence of the location and existence of an external 
initramfs. I suspect the issue is with my packaging, or Openwrt, but I wondered 
if there were any subtleties of how bootargs might be being passed differently 
between both types of image container? Why might this happen from a U-Boot 
perspective?

Rich

PS. The details of my issue are set out below in my post to the OpenWrt forum.

I'm seeing a very odd difference between a single build, deployed on an ath79 
device in two different ways. In short, when deployed as an OpenWrt built 
sysupgrade-squashfs the kernel picks up the command line arguments provided by 
the bootloader. However, when packaged as a FIT image the kernel does not pick 
up the bootargs. I think this is why my FIT packed kernel image cannot find the 
packaged external initramfs.

My device is a very standard ath79 qca9531 board from ZBT - works great on 
mainline OpenWrt + mainline U-Boot with minimal DTS. I've tried adding my 
target to both ath79-generic and ath79-tiny targets and the results are the 
same. It's also the same with kernel 5.4 and 5.10. In each case I'm using 
mainline U-Boot (which with a few changes works well on QCA9531!). 

## Steps I've taken

The main patches I've made to OpenWrt are all configuration:

enabling lzma for the external initramfs:
```
diff --git a/target/linux/ath79/config-5.4 b/target/linux/ath79/config-5.4
index 60f57692e2..8d521e4193 100644
--- a/target/linux/ath79/config-5.4
+++ b/target/linux/ath79/config-5.4
@@ -52,6 +52,7 @@ CONFIG_CPU_SUPPORTS_HIGHMEM=y
 CONFIG_CPU_SUPPORTS_MSA=y
 CONFIG_CRYPTO_RNG2=y
 CONFIG_CSRC_R4K=y
+CONFIG_DECOMPRESS_LZMA=y
 CONFIG_DMA_NONCOHERENT=y
 CONFIG_DMA_NONCOHERENT_CACHE_SYNC=y
 CONFIG_DTC=y
@@ -211,6 +212,7 @@ CONFIG_PHYLIB=y
 # CONFIG_PHY_ATH79_USB is not set
 CONFIG_PINCTRL=y
 CONFIG_RATIONAL=y
+CONFIG_RD_LZMA=y
 CONFIG_REGMAP=y
 CONFIG_REGMAP_MMIO=y
 CONFIG_RESET_ATH79=y
-- 
2.24.3 (Apple Git-128)
```

enabling mips kernel to extend the dtb bootargs with those from the bootloader:
```
diff --git a/target/linux/ath79/config-5.4 b/target/linux/ath79/config-5.4
index 8d521e4193..4898190a02 100644
--- a/target/linux/ath79/config-5.4
+++ b/target/linux/ath79/config-5.4
@@ -158,9 +158,9 @@ CONFIG_MIPS_ASID_BITS=8
 CONFIG_MIPS_ASID_SHIFT=0
 CONFIG_MIPS_CLOCK_VSYSCALL=y
 # CONFIG_MIPS_CMDLINE_BUILTIN_EXTEND is not set
-# CONFIG_MIPS_CMDLINE_DTB_EXTEND is not set
+CONFIG_MIPS_CMDLINE_DTB_EXTEND=y
 # CONFIG_MIPS_CMDLINE_FROM_BOOTLOADER is not set
-CONFIG_MIPS_CMDLINE_FROM_DTB=y
+# CONFIG_MIPS_CMDLINE_FROM_DTB is not set
 # CONFIG_MIPS_ELF_APPENDED_DTB is not set
 CONFIG_MIPS_L1_CACHE_SHIFT=5
 # CONFIG_MIPS_NO_APPENDED_DTB is not set
-- 
2.24.3 (Apple Git-128)
```

I've even tried backporting this patch 
http://lkml.iu.edu/hypermail/linux/kernel/2003.2/01736.html to 5.4 and made no 
difference: the squashfs image picked up the args no problem (even when 
launched from $loadaddr/0x810) and the FIT packaging which doesn't

Here's my u-boot environment:

```
Environment size: 342/8187 bytes
baudrate=115200
bootargs=foo=bar
bootcmd=sf probe;mtdparts default;bootm 0x9f05
bootcount=1
bootdelay=3
bootlimit=3
fdtcontroladdr=87f6caa0
ipaddr=192.168.0.234
loadaddr=0x8100
serverip=192.168.0.6
stderr=uart@1802
stdin=uart@1802
stdout=uart@1802
```

Here's the bootlog from the squashfs image which picks up the bootargs (ignore 
the error at the end, image was running from memory):

```
getbox # bootm 0x8100
## Booting kernel from Legacy Image at 8100 ...
   Image Name:   MIPS OpenWrt Linux-5.4.158
   Image Type:   MIPS Linux Kernel Image (lzma compressed)
   Data Size:1538183 Bytes = 1.5 MiB
   Load Address: 8006
   Entry Point:  8006
   Verifying Checksum ... OK
   Uncompressing Kernel Image
[0.00] Linux version 5.4.158 (vscode@d0b09531f99b) (gcc version 8.4.0 
(OpenWrt GCC 8.4.0 r0+16397-266890bb12)) #0 Fri Dec 3 10:13:01 2021
[0.00] printk: bootconsole [early0] enabled
[0.00] CPU0 revision is: 00019374 (MIPS 24Kc)
[0.00] MIPS: machine is Jangala Get Box (Tiny)
[0.00] SoC: Qualcomm Atheros QCA9533 ver 2 rev 0
[0.00] Initrd not found or empty - disabling initrd
[0.00] Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
[0.00] Primary data cache 32kB, 4-way, VIPT, cache aliases, linesize 32 
bytes
[0.00] Zone ranges:
[0.00]   Normal   [mem 0x-0x07ff]
[0.00] Movable zone start for each node
[0.00] Early memory node ranges
[0.00]   node   0: [mem 0x-0x07ff]
[0.00] Initmem setup node 0 [mem 0x-0x07ff]
[0.00] Built 1 

Re: [PATCH v7 08/31] arm: vexpress: Add a devicetree files for juno

2021-12-06 Thread Linus Walleij
On Tue, Dec 7, 2021 at 1:12 AM Simon Glass  wrote:

> Sync these file, obtained from Linux v5.15.
>
> Add a note for the maintainer, and SPDX lines where they are missing.
> The added lines are:
>
>SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
>
> Note, this matches the text in those files, but is not the same as the
> GPL-2.0 of some files.
>
> [1] https://releases.linaro.org/android/reference-lcr/juno/7.1-17.05/
>
> Signed-off-by: Simon Glass 

Overall fine!

But:

> +++ b/arch/arm/dts/juno-motherboard.dtsi
(...)
> +   bus@800 {
> +   compatible = "simple-bus";
(...)
> +   motherboard-bus@800 {
> +   compatible = "arm,vexpress,v2p-p1", "simple-bus";
(...)
> +   flash@0 {
> +   /* 2 * 32MiB NOR Flash memory mounted on CS0 
> */
> +   compatible = "arm,vexpress-flash", 
> "cfi-flash";
> +   reg = <0 0x 0x0400>;
> +   bank-width = <4>;
> +   /*
> +* Unfortunately, accessing the flash disturbs
> +* the CPU idle states (suspend) and CPU
> +* hotplug of the platform. For this reason,
> +* flash hardware access is disabled by 
> default.
> +*/
> +   status = "disabled";
> +   partitions {
> +   compatible = "arm,arm-firmware-suite";
> +   };
> +   };

This should not be marked "disabled" in U-boot. The boot loader is not
using some CPU idle states and hotplug but may be very interested
in accessing the flash.

Yours,
Linus Walleij


Re: [BUG] efi_loader: incorrect creation of device paths

2021-12-06 Thread AKASHI Takahiro
Hi Mark,

Thank you for the comment.

On Mon, Dec 06, 2021 at 12:41:28PM +0100, Mark Kettenis wrote:
> > Date: Mon, 6 Dec 2021 13:16:23 +0900
> > From: AKASHI Takahiro 
> > 
> > On Fri, Dec 03, 2021 at 05:32:49PM +0100, Heinrich Schuchardt wrote:
> > > On 11/25/21 06:44, AKASHI Takahiro wrote:
> > > > Heinrich,
> > > > 
> > > > On Wed, Nov 24, 2021 at 12:10:32PM +0900, AKASHI Takahiro wrote:
> > > > > On Sat, Nov 20, 2021 at 01:54:30PM +0100, Heinrich Schuchardt wrote:
> > > > > > Hello Takahiro,
> > > > > > 
> > > > > > in a prior mail we have discussed the creation of device paths for 
> > > > > > USB
> > > > > > mass storage devices.
> > > > > > 
> > > > > > On the sand boxyou get the following devices after 'usb start':
> > > > > > 
> > > > > >   Class Index  Probed  DriverName
> > > > > > ---
> > > > > >   usb   0  [ + ]   usb_sandbox   |-- usb@1
> > > > > >   usb_hub   0  [ + ]   usb_hub   |   `-- hub
> > > > > >   usb_mass_s0  [ + ]   usb_mass_storage  |   |--
> > > > > > usb_mass_storage
> > > > > >   blk   3  [   ]   usb_storage_blk   |   |   `--
> > > > > > usb_mass_storage.lun0
> > > > > >   usb_mass_s1  [ + ]   usb_mass_storage  |   |--
> > > > > > usb_mass_storage
> > > > > >   blk   4  [   ]   usb_storage_blk   |   |   `--
> > > > > > usb_mass_storage.lun0
> > > > > >   usb_mass_s2  [ + ]   usb_mass_storage  |   `--
> > > > > > usb_mass_storage
> > > > > >   blk   5  [   ]   usb_storage_blk   |   `--
> > > > > > usb_mass_storage.lun0
> > > > > > 
> > > > > > For of these storage devices we try to create the same device path 
> > > > > > which
> > > > > > is not allowable:
> > > > > > 
> > > > > > => usb start
> > > > > > starting USB...
> > > > > > Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found
> > > > > > scanning usb for storage devices... 3 Storage Device(s) 
> > > > > > found
> > > > > > =>
> > > > > > => efidebug dh
> > > > > > Scanning disk mmc2.blk...
> > > > > > handle 15e34f00,
> > > > > > /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(2)/SD(0)
> > > > > > Scanning disk mmc1.blk...
> > > > > > handle 15e36b30,
> > > > > > /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(1)/SD(1)
> > > > > > Scanning disk mmc0.blk...
> > > > > > handle 15e35b00,
> > > > > > /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(2)
> > > > > > Scanning disk usb_mass_storage.lun0...
> > > > > > handle 15e35c10,
> > > > > > /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/UsbClass(0x1234,0x5678,0x9,0x0,0x0)/UsbClass(0x1234,0x5678,0x0,0x0,0x0)
> > > > > > fs_devread read outside partition 2
> > > > > > Failed to mount ext2 filesystem...
> > > > > > BTRFS: superblock end 69632 is larger than device size 512
> > > > > > Scanning disk usb_mass_storage.lun0...
> > > > > > handle 15e361f0,
> > > > > > /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/UsbClass(0x1234,0x5678,0x9,0x0,0x0)/UsbClass(0x1234,0x5678,0x0,0x0,0x0)
> > > > > > ERROR: failure to add disk device usb_mass_storage.lun0, r = 20
> > > > > > Error: Cannot initialize UEFI sub-system, r = 20
> > > > > > 
> > > > > > I will provide a patch that will allow the first USB device to be 
> > > > > > used
> > > > > > and avoids stopping the boot process. But we really have to walk 
> > > > > > the dm
> > > > > > tree to create a device patch for USB devices based on port IDs.
> > > > > > 
> > > > > > We should add a new field to struct uclass_driver:
> > > > > > 
> > > > > > struct efi_device_path *get_node(udevice *dev);
> > > > > > 
> > > > > > This function shall return a pointer to an freshly allocated buffer 
> > > > > > with
> > > > > > the device node for the device. To build the devicepath we can then 
> > > > > > walk
> > > > > > the dm tree.
> > > > > 
> > > > > I'm not sure this is an acceptable solution.
> > > > > 
> > > > > Let me make sure:
> > > > > The goal would be to create a device path like
> > > > > .../USB(0x1,0x0)/HD(1,...)
> > > > > instead of
> > > > > 
> > > > > .../UsbHub(0x0,0x0,0x0,0x3)/UsbMassStorage(0x46f4,0x1,0x0,0x0)/HD(1,...)
> > > > > as we already see this format for SCSI:
> > > > > .../Scsi(0,0)/HD(1,..)
> > > > > 
> > > > > Right?
> > > > 
> > > > Please try the tweak attached below.
> > > > (I think what I did here is trivial.)
> > > > 
> > > > If you like, I will post it as a patch.
> > > > (See "10.3.4.5.1 USB Device Path Example".)
> > > > 
> > > > -Takahiro Akashi
> > > > 
> > > > > > >  From cda91e9d8144f89f0d73738b338289a7940bbe0e Mon Sep 17 
> > > > > > > 00:00:00 2001
> > > > > > > From: AKASHI Takahiro 
> > > > > > > Date: Thu, 25 Nov 2021 14:20:08 +0900
> > > > > > > Subject: [PATCH] efi_loader: disk: usb mass-storage
> > > > 
> > > > - use path_usb instead of path_usb_class for existing USB dp nodes
> > > > - add a dp node for UCLASS_USB
> > 

Re: [PATCH v7 14/31] arm: highbank: Add devicetree files

2021-12-06 Thread Andre Przywara
On Mon,  6 Dec 2021 17:11:52 -0700
Simon Glass  wrote:

> Sync these files, obtained from Linux v5.15.

Sorry, but this would be wrong.
How do you know which board it is? Highbank or Midway? We use the
same binary for both, and decide either by the DT nodes we find in DRAM
or by some autodetection (Cortex-A9 vs. Cortex-A15) if there are
differences. The memory size would possibly be wrong (it's a DIMM slot).
If you need *some* DT for build reasons, whatever, but at least go with
the empty stub.

And I still don't get this whole development argument: Why would
anyone need some random or partial DT sample in the U-Boot tree to do
development?
If people develop a driver, the document to code against is the
*binding* documentation, which describes what to expect from the DT
nodes. Then you *test* it against an actual tree, but on the actual
hardware, in which case you get the actual DTB, from the board.
If a developer needs to take a sneak peek into an actual DTB,
there are so many simple ways to do that: QEMU's dumpdtb, RPi's SD
card content, U-Boot's "fdt addr $fdtcontroladdr; fdt print", the
kernel's /sys/firmware/devicetree/base, ... When you port U-Boot to a
board, getting hands on the actual DT is probably the least of your
problems.

So why would we need some mostly wrong DTs in the U-Boot tree?
It seems to suggest that you can hack the DT to make things work, but
this sounds bonkers, as the real DTB comes from somewhere else (SPI
flash, SD card, generated based on command line), and patching U-Boot's
copy to make things work is just wishful thinking.

I can see the hacker's desire to play around with the DTB from time
to time (What happens if the GPIO is wrong? Can we deal with two
instances of the same device?), but for those experiments there are
plenty of ways to achieve this - and be it temporarily replacing the
empty DT stub. I just feel that bending the (board's) DT design ideas
for a hacker's pleasure is not justified.

Cheers,
Andre

> 
> Signed-off-by: Simon Glass 
> ---
> 
> Changes in v7:
> - Bring in files from Linux instead
> 
>  arch/arm/dts/Makefile|   2 +
>  arch/arm/dts/ecx-common.dtsi | 231 +++
>  arch/arm/dts/highbank.dts| 158 
>  configs/highbank_defconfig   |   2 +-
>  4 files changed, 392 insertions(+), 1 deletion(-)
>  create mode 100644 arch/arm/dts/ecx-common.dtsi
>  create mode 100644 arch/arm/dts/highbank.dts
> 
> diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> index 8bb15b96cc7..453e2fd1a98 100644
> --- a/arch/arm/dts/Makefile
> +++ b/arch/arm/dts/Makefile
> @@ -871,6 +871,8 @@ dtb-$(CONFIG_MX7) += imx7d-sdb.dtb \
>  dtb-$(CONFIG_ARCH_MX7ULP) += imx7ulp-com.dtb \
>   imx7ulp-evk.dtb
>  
> +dtb-$(CONFIG_ARCH_HIGHBANK) += highbank.dtb
> +
>  dtb-$(CONFIG_ARCH_IMX8) += \
>   fsl-imx8qm-apalis.dtb \
>   fsl-imx8qm-mek.dtb \
> diff --git a/arch/arm/dts/ecx-common.dtsi b/arch/arm/dts/ecx-common.dtsi
> new file mode 100644
> index 000..57a028a6937
> --- /dev/null
> +++ b/arch/arm/dts/ecx-common.dtsi
> @@ -0,0 +1,231 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright 2011-2012 Calxeda, Inc.
> + */
> +
> +/ {
> + chosen {
> + bootargs = "console=ttyAMA0";
> + };
> +
> + psci {
> + compatible  = "arm,psci";
> + method  = "smc";
> + cpu_suspend = <0x8402>;
> + cpu_off = <0x8404>;
> + cpu_on  = <0x8406>;
> + };
> +
> + soc {
> + #address-cells = <1>;
> + #size-cells = <1>;
> + compatible = "simple-bus";
> + interrupt-parent = <>;
> +
> + sata@ffe08000 {
> + compatible = "calxeda,hb-ahci";
> + reg = <0xffe08000 0x1>;
> + interrupts = <0 83 4>;
> + dma-coherent;
> + calxeda,port-phys = <  0>, < 0>,
> +  < 1>, < 2>,
> +  < 3>;
> + calxeda,sgpio-gpio =< 5 1>, < 6 1>,
> + < 7 1>;
> + calxeda,led-order = <4 0 1 2 3>;
> + };
> +
> + sdhci@ffe0e000 {
> + compatible = "calxeda,hb-sdhci";
> + reg = <0xffe0e000 0x1000>;
> + interrupts = <0 90 4>;
> + clocks = <>;
> + status = "disabled";
> + };
> +
> + ipc@fff2 {
> + compatible = "arm,pl320", "arm,primecell";
> + reg = <0xfff2 0x1000>;
> + interrupts = <0 7 4>;
> + clocks = <>;
> + clock-names = "apb_pclk";
> + };
> +
> + gpioe: gpio@fff3 {
> + #gpio-cells = <2>;
> +   

Re: [PATCH v7 02/31] arm: qemu: Mention -nographic in the docs

2021-12-06 Thread Heinrich Schuchardt

On 12/6/21 16:11, Simon Glass wrote:

Without this option QEMU appears to hang. Add it to avoid confusion.

Signed-off-by: Simon Glass 


I think there was some work to get a virtio framebuffer working. But
adding -nographic is ok.

Reviewed-by: Heinrich Schuchardt 


---

(no changes since v1)

  doc/board/emulation/qemu-arm.rst | 7 ---
  1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/doc/board/emulation/qemu-arm.rst b/doc/board/emulation/qemu-arm.rst
index 584ef0a7e15..8bd7b60cdb4 100644
--- a/doc/board/emulation/qemu-arm.rst
+++ b/doc/board/emulation/qemu-arm.rst
@@ -41,14 +41,15 @@ The minimal QEMU command line to get U-Boot up and running 
is:

  - For ARM::

-qemu-system-arm -machine virt -bios u-boot.bin
+qemu-system-arm -machine virt -nographic -bios u-boot.bin

  - For AArch64::

-qemu-system-aarch64 -machine virt -cpu cortex-a57 -bios u-boot.bin
+qemu-system-aarch64 -machine virt -nographic -cpu cortex-a57 -bios 
u-boot.bin

  Note that for some odd reason qemu-system-aarch64 needs to be explicitly
-told to use a 64-bit CPU or it will boot in 32-bit mode.
+told to use a 64-bit CPU or it will boot in 32-bit mode. The -nographic 
argument
+ensures that output appears on the terminal. Use Ctrl-A X to quit.

  Additional persistent U-boot environment support can be added as follows:






Re: [PATCH v7 01/31] doc: Add documentation about devicetree usage

2021-12-06 Thread Heinrich Schuchardt

On 12/6/21 16:11, Simon Glass wrote:

At present some of the ideas and techniques behind devicetree in U-Boot
are assumed, implied or unsaid. Add some documentation to cover how
devicetree is build, how it can be modified and the rules about using
the various CONFIG_OF_... options.

Signed-off-by: Simon Glass 
Reviewed-by: Marcel Ziswiler 
---
This patch attracted quite a bit of discussion here:

https://patchwork.ozlabs.org/project/uboot/patch/20210909201033.755713-4-...@chromium.org/

I have not included the text suggested by François. While I agree that
it would be useful to have an introduction in this space, I do not agree
that we should have two devicetrees or that U-Boot should not have its own
things in the devicetree, so it is not clear to me what we should actually
write.

The 'Devicetree Control in U-Boot' docs were recently merged and these
provide some base info, for now.


As you already remarked part of this text has not been agreed upon.

Please, either remove this part of the text or mark it as your private
opinion.

Best regards

Heinrich



Changes in v7:
- Fix 'linst' typo

Changes in v6:
- Fix description of OF_BOARD so it refers just to the current state
- Explain that the 'two devicetrees' refers to two *control* devicetrees

Changes in v5:
- Bring into the OF_BOARD series
- Rebase to master and drop mention of OF_PRIOR_STAGE, since removed
- Refer to the 'control' DTB in the first paragraph
- Use QEMU instead of qemu

Changes in v3:
- Clarify the 'bug' refered to at the top
- Reword 'This means that there' paragraph to explain U-Boot-specific things
- Move to doc/develop/devicetree now that OF_CONTROL is in the docs

Changes in v2:
- Fix typos per Sean (thank you!) and a few others
- Add a 'Use of U-Boot /config node' section
- Drop mention of dm-verity since that actually uses the kernel cmdline
- Explain that OF_BOARD will still work after these changes (in
   'Once this bug is fixed...' paragraph)
- Expand a bit on the reason why the 'Current situation' is bad
- Clarify in a second place that Linux and U-Boot use the same devicetree
   in 'To be clear, while U-Boot...'
- Expand on why we should have rules for other projects in
   'Devicetree in another project'
- Add a comment as to why devicetree in U-Boot is not 'bad design'
- Reword 'in-tree U-Boot devicetree' to 'devicetree source in U-Boot'
- Rewrite 'Devicetree generated on-the-fly in another project' to cover
   points raised on v1
- Add 'Why does U-Boot have its nodes and properties?'
- Add 'Why not have two devicetrees?'

  doc/develop/devicetree/dt_update.rst | 555 +++
  doc/develop/devicetree/index.rst |   1 +
  2 files changed, 556 insertions(+)
  create mode 100644 doc/develop/devicetree/dt_update.rst

diff --git a/doc/develop/devicetree/dt_update.rst 
b/doc/develop/devicetree/dt_update.rst
new file mode 100644
index 000..e3b65f6fa66
--- /dev/null
+++ b/doc/develop/devicetree/dt_update.rst
@@ -0,0 +1,555 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Updating the devicetree
+===
+
+U-Boot uses devicetree for runtime configuration and storing required blobs or
+any other information it needs to operate. This is called the 'control'
+devicetree since it controls U-Boot. It is possible to update the control
+devicetree separately from actually building U-Boot. This provides a good 
degree
+of control and flexibility for firmware that uses U-Boot in conjunction with
+other project.
+
+There are many reasons why it is useful to modify the devicetree after building
+it:
+
+- Configuration can be changed, e.g. which UART to use
+- A serial number can be added
+- Public keys can be added to allow image verification
+- Console output can be changed (e.g. to select serial or vidconsole)
+
+This section describes how to work with devicetree to accomplish your goals.
+
+See also :doc:`../devicetree/control` for a basic summary of the available
+features.
+
+
+Devicetree source
+-
+
+Every board in U-Boot must include a devicetree sufficient to build and boot
+that board on suitable hardware (or emulation). This is specified using the
+`CONFIG DEFAULT_DEVICE_TREE` option.
+
+
+Current situation (October 2021)
+~~
+
+As an aside, at present U-Boot allows `CONFIG_DEFAULT_DEVICE_TREE` to be empty,
+e.g. if `CONFIG_OF_BOARD` is used. This has unfortunately created an enormous
+amount of confusion and some wasted effort. This was not intended. Support for
+an empty `CONFIG_DEFAULT_DEVICE_TREE` will be dropped soon.
+
+Some of the problems created are:
+
+- It is not obvious that the devicetree is coming from another project
+
+- There is no way to see even a sample devicetree for these platform in U-Boot,
+  so it is hard to know what is going on, e.g. which devices are typically
+  present
+
+- The other project may not provide a way to support U-Boot's requirements for
+  devicetree, such as the /config node. Note: On the U-Boot 

[PATCH v7 31/31] fdt: Show build/runtime warnings based on devicetree source

2021-12-06 Thread Simon Glass
Show a warning at build time if the devicetree is built for a board which
normally should get it from a prior stage:

   Warning: Devicetree was built but is not normally used on this board

When running, if the devicetree failed to come from the expected source,
show a warning then also, e.g:

   U-Boot ...

   DRAM:  128 MiB
   Core:  42 devices, 11 uclasses, devicetree: separate
   Warning: Unexpected devicetree source (not from a prior stage)
   Warning: U-Boot may not function properly
   Flash: 64 MiB
   ...

These warnings should only appear if the board config has been changed, or
the prior stage is broken.

Signed-off-by: Simon Glass 

---

(no changes since v1)

 Makefile | 3 +++
 common/board_r.c | 6 ++
 2 files changed, 9 insertions(+)

diff --git a/Makefile b/Makefile
index a3f018f01e0..0059f10cbca 100644
--- a/Makefile
+++ b/Makefile
@@ -1107,6 +1107,9 @@ endif
 ifeq ($(CONFIG_DEPRECATED),y)
$(warning "You have deprecated configuration options enabled in your 
.config! Please check your configuration.")
 endif
+ifeq ($(CONFIG_OF_HAS_PRIOR_STAGE).$(CONFIG_OF_OMIT_DTB),y.)
+   @echo >&2 "Warning: Devicetree was built but is not normally used on 
this board"
+endif
 ifeq ($(CONFIG_OF_EMBED)$(CONFIG_EFI_APP),y)
@echo >&2 "= WARNING =="
@echo >&2 "CONFIG_OF_EMBED is enabled. This option should only"
diff --git a/common/board_r.c b/common/board_r.c
index 99adff14b39..6d520662dbb 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -598,6 +598,12 @@ static int dm_announce(void)
if (CONFIG_IS_ENABLED(OF_REAL))
printf(", devicetree: %s", fdtdec_get_srcname());
printf("\n");
+   if (IS_ENABLED(CONFIG_OF_HAS_PRIOR_STAGE) &&
+   (gd->fdt_src == FDTSRC_SEPARATE ||
+gd->fdt_src == FDTSRC_EMBED)) {
+   printf("Warning: Unexpected devicetree source (not from 
a prior stage)");
+   printf("Warning: U-Boot may not function properly\n");
+   }
}
 
return 0;
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 30/31] fdt: Avoid emitting an device tree when not needed

2021-12-06 Thread Simon Glass
U-Boot always needs some sort of a device tree. Some boards never actually
use this, at least in production systems, since a prior firmware stage
sets one up and passes it to U-Boot. At present the only mechanism to do
that is with custom function (OF_BOARD), but future work will include a
standard way of doing this ('standard passage').

It can be confusing to see a device tree emitted from the U-Boot build in
this situation. Add an option to drop it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 Makefile|  6 +-
 dts/Kconfig | 10 ++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 6671c5d9e2f..a3f018f01e0 100644
--- a/Makefile
+++ b/Makefile
@@ -952,7 +952,11 @@ INPUTS-$(CONFIG_SPL_FRAMEWORK) += u-boot.img
 endif
 endif
 INPUTS-$(CONFIG_TPL) += tpl/u-boot-tpl.bin
+
+# Allow omitting the .dtb output if it is not normally used
+ifndef CONFIG_OF_OMIT_DTB
 INPUTS-$(CONFIG_OF_SEPARATE) += u-boot.dtb
+endif
 ifeq ($(CONFIG_SPL_FRAMEWORK),y)
 INPUTS-$(CONFIG_OF_SEPARATE) += u-boot-dtb.img
 endif
@@ -1192,7 +1196,7 @@ u-boot.bin: u-boot-fit-dtb.bin FORCE
 u-boot-dtb.bin: u-boot-nodtb.bin dts/dt.dtb FORCE
$(call if_changed,cat)
 
-else ifeq ($(CONFIG_OF_SEPARATE),y)
+else ifeq ($(CONFIG_OF_SEPARATE).$(CONFIG_OF_OMIT_DTB),y.)
 u-boot-dtb.bin: u-boot-nodtb.bin dts/dt.dtb FORCE
$(call if_changed,cat)
 
diff --git a/dts/Kconfig b/dts/Kconfig
index 803d0899556..fd2829ad708 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -129,6 +129,16 @@ config OF_HAS_PRIOR_STAGE
  Note: This option must be set in Kconfig and cannot be enabled or
  disabled in the board's defconfig file.
 
+config OF_OMIT_DTB
+   bool "Omit the device tree output when building"
+   default y if OF_HAS_PRIOR_STAGE && !BINMAN
+   help
+ As a special case, avoid writing a device tree file u-boot.dtb when
+ building. Also don't include that file in u-boot.bin
+
+ This is used for boards which normally provide a devicetree via a
+ runtime mechanism (such as OF_BOARD), to avoid confusion.
+
 config DEFAULT_DEVICE_TREE
string "Default Device Tree for DT control"
depends on OF_CONTROL
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 26/31] dm: core: Allow getting some basic stats

2021-12-06 Thread Simon Glass
Add a function that returns some basic stats about driver model. For now
we only have two.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/core/device.c| 11 ++
 drivers/core/root.c  |  7 ++
 drivers/core/uclass.c| 13 
 include/dm/device.h  | 11 +-
 include/dm/root.h|  8 +++
 include/dm/uclass-internal.h |  7 ++
 test/dm/core.c   | 41 
 7 files changed, 97 insertions(+), 1 deletion(-)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 74374ff881c..4873c47d10b 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -739,6 +739,17 @@ int device_get_child_count(const struct udevice *parent)
return count;
 }
 
+int device_get_decendent_count(const struct udevice *parent)
+{
+   const struct udevice *dev;
+   int count = 1;
+
+   list_for_each_entry(dev, >child_head, sibling_node)
+   count += device_get_decendent_count(dev);
+
+   return count;
+}
+
 int device_find_child_by_seq(const struct udevice *parent, int seq,
 struct udevice **devp)
 {
diff --git a/drivers/core/root.c b/drivers/core/root.c
index 26b8195faa3..815173f86eb 100644
--- a/drivers/core/root.c
+++ b/drivers/core/root.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -407,6 +408,12 @@ int dm_init_and_scan(bool pre_reloc_only)
return 0;
 }
 
+void dm_get_stats(int *device_countp, int *uclass_countp)
+{
+   *device_countp = device_get_decendent_count(gd->dm_root);
+   *uclass_countp = uclass_get_count();
+}
+
 #ifdef CONFIG_ACPIGEN
 static int root_acpi_get_name(const struct udevice *dev, char *out_name)
 {
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 2aa21430775..336ea8d243d 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -643,6 +643,19 @@ int uclass_next_device_check(struct udevice **devp)
return device_probe(*devp);
 }
 
+int uclass_get_count(void)
+{
+   const struct uclass *uc;
+   int count = 0;
+
+   if (gd->dm_root) {
+   list_for_each_entry(uc, gd->uclass_root, sibling_node)
+   count++;
+   }
+
+   return count;
+}
+
 int uclass_first_device_drvdata(enum uclass_id id, ulong driver_data,
struct udevice **devp)
 {
diff --git a/include/dm/device.h b/include/dm/device.h
index daf28a0a457..19d37e0e76c 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -593,7 +593,7 @@ int device_get_child(const struct udevice *parent, int 
index,
 struct udevice **devp);
 
 /**
- * device_get_child_count() - Get the available child count of a device
+ * device_get_child_count() - Get the child count of a device
  *
  * Returns the number of children to a device.
  *
@@ -601,6 +601,15 @@ int device_get_child(const struct udevice *parent, int 
index,
  */
 int device_get_child_count(const struct udevice *parent);
 
+/**
+ * device_get_decendent_count() - Get the total number of decendents of a 
device
+ *
+ * Returns the total number of decendents, including all children
+ *
+ * @parent:Parent device to check
+ */
+int device_get_decendent_count(const struct udevice *parent);
+
 /**
  * device_find_child_by_seq() - Find a child device based on a sequence
  *
diff --git a/include/dm/root.h b/include/dm/root.h
index 42510b106ab..780f269db65 100644
--- a/include/dm/root.h
+++ b/include/dm/root.h
@@ -131,4 +131,12 @@ int dm_remove_devices_flags(uint flags);
 static inline int dm_remove_devices_flags(uint flags) { return 0; }
 #endif
 
+/**
+ * dm_get_stats() - Get some stats for driver mode
+ *
+ * @device_countp: Returns total number of devices that are bound
+ * @uclass_countp: Returns total number of uclasses in use
+ */
+void dm_get_stats(int *device_countp, int *uclass_countp);
+
 #endif
diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h
index 49808c5c856..fb0edcc2969 100644
--- a/include/dm/uclass-internal.h
+++ b/include/dm/uclass-internal.h
@@ -306,6 +306,13 @@ int uclass_pre_remove_device(struct udevice *dev);
 static inline int uclass_pre_remove_device(struct udevice *dev) { return 0; }
 #endif
 
+/**
+ * uclass_get_count() - Get the number of uclasses
+ *
+ * Returns the number of uclasses instantiated in driver model
+ */
+int uclass_get_count(void);
+
 /**
  * uclass_find() - Find uclass by its id
  *
diff --git a/test/dm/core.c b/test/dm/core.c
index c9a760c..c76dfdb1651 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -307,11 +307,15 @@ static int dm_test_lifecycle(struct unit_test_state *uts)
 {
int op_count[DM_TEST_OP_COUNT];
struct udevice *dev, *test_dev;
+   int start_dev_count, start_uc_count;
+   int dev_count, uc_count;
int pingret;
int ret;
 
memcpy(op_count, dm_testdrv_op_count, sizeof(op_count));
 
+   

[PATCH v7 27/31] fdt: Record where the devicetree came from

2021-12-06 Thread Simon Glass
Keep track of where the devicetree came from, so we can report this later.

Signed-off-by: Simon Glass 
---

Changes in v7:
- Drop FDTSRC_PASSAGE for now

 include/asm-generic/global_data.h |  4 
 include/fdtdec.h  | 32 +++
 lib/fdtdec.c  | 20 ++-
 3 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/include/asm-generic/global_data.h 
b/include/asm-generic/global_data.h
index 99daa20c765..104282bd479 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -244,6 +244,10 @@ struct global_data {
 * @fdt_size: space reserved for relocated device space
 */
unsigned long fdt_size;
+   /**
+* @fdt_src: Source of FDT
+*/
+   enum fdt_source_t fdt_src;
 #if CONFIG_IS_ENABLED(OF_LIVE)
/**
 * @of_root: root node of the live tree
diff --git a/include/fdtdec.h b/include/fdtdec.h
index 68a36f10583..09525ce510a 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -55,6 +55,31 @@ struct bd_info;
 #define SPL_BUILD  0
 #endif
 
+/**
+ * enum fdt_source_t - indicates where the devicetree came from
+ *
+ * These are listed in approximate order of desirability after FDTSRC_NONE
+ *
+ * @FDTSRC_SEPARATE: Appended to U-Boot. This is the normal approach if U-Boot
+ * is the only firmware being booted
+ * @FDTSRC_FIT: Found in a multi-dtb FIT. This should be used when U-Boot must
+ * select a devicetree from many options
+ * @FDTSRC_BOARD: Located by custom board code. This should only be used when
+ * the prior stage does not support FDTSRC_PASSAGE
+ * @FDTSRC_EMBED: Embedded into U-Boot executable. This should onyl be used 
when
+ * U-Boot is packaged as an ELF file, e.g. for debugging purposes
+ * @FDTSRC_ENV: Provided by the fdtcontroladdr environment variable. This 
should
+ * be used for debugging/development only
+ * @FDTSRC_NONE: No devicetree at all
+ */
+enum fdt_source_t {
+   FDTSRC_SEPARATE,
+   FDTSRC_FIT,
+   FDTSRC_BOARD,
+   FDTSRC_EMBED,
+   FDTSRC_ENV,
+};
+
 /*
  * Information about a resource. start is the first address of the resource
  * and end is the last address (inclusive). The length of the resource will
@@ -1215,4 +1240,11 @@ int fdtdec_decode_ram_size(const void *blob, const char 
*area, int board_id,
   phys_addr_t *basep, phys_size_t *sizep,
   struct bd_info *bd);
 
+/**
+ * fdtdec_get_srcname() - Get the name of where the devicetree comes from
+ *
+ * @return source name
+ */
+const char *fdtdec_get_srcname(void);
+
 #endif
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 31a509bc221..8cfa958fb96 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1618,6 +1618,7 @@ static void setup_multi_dtb_fit(void)
if (blob) {
gd_set_multi_dtb_fit(gd->fdt_blob);
gd->fdt_blob = blob;
+   gd->fdt_src = FDTSRC_FIT;
}
 }
 
@@ -1626,22 +1627,31 @@ int fdtdec_setup(void)
int ret;
 
/* The devicetree is typically appended to U-Boot */
-   if (IS_ENABLED(CONFIG_OF_SEPARATE))
+   if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
gd->fdt_blob = fdt_find_separate();
-   else /* embed dtb in ELF file for testing / development */
+   gd->fdt_src = FDTSRC_SEPARATE;
+   } else { /* embed dtb in ELF file for testing / development */
gd->fdt_blob = dtb_dt_embedded();
+   gd->fdt_src = FDTSRC_EMBED;
+   }
 
/* Allow the board to override the fdt address. */
if (IS_ENABLED(CONFIG_OF_BOARD)) {
gd->fdt_blob = board_fdt_blob_setup();
if (ret)
return ret;
+   gd->fdt_src = FDTSRC_BOARD;
}
 
+   /* Allow the early environment to override the fdt address */
if (!IS_ENABLED(CONFIG_SPL_BUILD)) {
-   /* Allow the early environment to override the fdt address */
-   gd->fdt_blob = map_sysmem(env_get_ulong("fdtcontroladdr", 16,
-  (unsigned long)map_to_sysmem(gd->fdt_blob)), 0);
+   ulong addr;
+
+   addr = env_get_hex("fdtcontroladdr", 0);
+   if (addr) {
+   gd->fdt_blob = map_sysmem(addr, 0);
+   gd->fdt_src = FDTSRC_ENV;
+   }
}
 
if (CONFIG_IS_ENABLED(MULTI_DTB_FIT))
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 29/31] fdt: Add a Kconfig for boards with a prior stage

2021-12-06 Thread Simon Glass
When U-Boot is started from another firmware program, not just a prior
phase of U-Boot, special behaviour is typically used. In particular, the
device tree may come from that prior stage.

At present this is sort-of indicated by OF_BOARD, although the
correlation is not 1:1, since that option simply means that the board has
a custom mechanism for obtaining the device tree. For example, sandbox
defines OF_BOARD. Also the board_fdt_blob_setup() function can in fact
make use of the devicetree in U-Boot if it wishes, as used by
dragonboard410c until very recently.

Add an explicit Kconfig for this situation. Define it for boards which
use this feature. Update the OF_BOARD option to more-accurately reflect
what it is doing, e.g. for sandbox.

Signed-off-by: Simon Glass 
---

Changes in v7:
- Add new patch to add a Kconfig for boards with a prior stage

 arch/arm/Kconfig   |  8 
 arch/arm/mach-bcm283x/Kconfig  |  1 +
 board/emulation/qemu-riscv/Kconfig |  1 +
 dts/Kconfig| 31 ++
 lib/fdtdec.c   |  1 +
 5 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index eed27af74e8..d26461029af 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -635,6 +635,7 @@ config ARCH_BCMSTB
select GPIO_EXTRA_HEADER
select OF_CONTROL
imply CMD_DM
+   imply OF_HAS_PRIOR_STAGE
help
  This enables support for Broadcom ARM-based set-top box
  chipsets, including the 7445 family of chips.
@@ -713,6 +714,7 @@ config ARCH_HIGHBANK
select AHCI
select DM_ETH
select PHYS_64BIT
+   imply OF_HAS_PRIOR_STAGE
 
 config ARCH_INTEGRATOR
bool "ARM Ltd. Integrator family"
@@ -966,6 +968,7 @@ config ARCH_QEMU
imply DM_RNG
imply DM_RTC
imply RTC_PL031
+   imply OF_HAS_PRIOR_STAGE
 
 config ARCH_RMOBILE
bool "Renesas ARM SoCs"
@@ -1251,6 +1254,7 @@ config TARGET_VEXPRESS64_JUNO
select DM_ETH
select BLK
select USB
+   imply OF_HAS_PRIOR_STAGE
 
 config TARGET_TOTAL_COMPUTE
bool "Support Total Compute Platform"
@@ -1907,6 +1911,7 @@ config ARCH_OCTEONTX
select OF_LIVE
select BOARD_LATE_INIT
select SYS_CACHE_SHIFT_7
+   imply OF_HAS_PRIOR_STAGE
 
 config ARCH_OCTEONTX2
bool "Support OcteonTX2 SoCs"
@@ -1918,6 +1923,7 @@ config ARCH_OCTEONTX2
select OF_LIVE
select BOARD_LATE_INIT
select SYS_CACHE_SHIFT_7
+   imply OF_HAS_PRIOR_STAGE
 
 config TARGET_THUNDERX_88XX
bool "Support ThunderX 88xx"
@@ -1954,6 +1960,8 @@ config TARGET_XENGUEST_ARM64
select LINUX_KERNEL_IMAGE_HEADER
select XEN_SERIAL
select SSCANF
+   imply OF_HAS_PRIOR_STAGE
+
 endchoice
 
 config SUPPORT_PASSING_ATAGS
diff --git a/arch/arm/mach-bcm283x/Kconfig b/arch/arm/mach-bcm283x/Kconfig
index b3287ce8bce..2eb3802d9ae 100644
--- a/arch/arm/mach-bcm283x/Kconfig
+++ b/arch/arm/mach-bcm283x/Kconfig
@@ -188,6 +188,7 @@ config TARGET_RPI_4
 
  This option creates a build targeting the ARMv8/AArch64 ISA.
select BCM2711_64B
+   imply OF_HAS_PRIOR_STAGE
 
 config TARGET_RPI_ARM64
bool "Raspberry Pi one binary 64-bit build"
diff --git a/board/emulation/qemu-riscv/Kconfig 
b/board/emulation/qemu-riscv/Kconfig
index 1bbf1bc84af..a380db61a0f 100644
--- a/board/emulation/qemu-riscv/Kconfig
+++ b/board/emulation/qemu-riscv/Kconfig
@@ -65,5 +65,6 @@ config BOARD_SPECIFIC_OPTIONS # dummy
imply VIRTIO_BLK
imply MTD_NOR_FLASH
imply CFI_FLASH
+   imply OF_HAS_PRIOR_STAGE
 
 endif
diff --git a/dts/Kconfig b/dts/Kconfig
index 5dcc79d5192..803d0899556 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -100,11 +100,34 @@ config OF_BOARD
bool "Provided by the board (e.g a previous loader) at runtime"
default y if SANDBOX
help
- If this option is enabled, the device tree will be provided by
- the board at runtime if the board supports it. The device tree bundled
- with the image (if any) will be overridden / ignored.
+ If this option is enabled, the device tree is provided at runtime by
+ a custom function called board_fdt_blob_setup(). The board must
+ implement this function if it wishes to provide special behaviour.
 
- A device tree file must be provided in the tree.
+ With this option, the device tree build by U-Boot may be overridden or
+ ignored. See OF_HAS_PRIOR_STAGE.
+
+ Note: Boards which use this to handle a device tree passed from an
+ earlier stage should enable OF_HAS_PRIOR_STAGE.
+
+config OF_HAS_PRIOR_STAGE
+   bool
+   help
+ Indicates that a prior stage of the firmware (before U-Boot proper)
+ makes use of device tree and this board normally boots with that prior
+ stage, that provides a devicetree to 

[PATCH v7 25/31] fdt: Don't call board_fdt_blob_setup() without OF_BOARD

2021-12-06 Thread Simon Glass
At present this override function is called even when OF_BOARD is not
enabled. This makes it impossible to disable this feature and in fact
makes the OF_BOARD option useless.

Reinstate its intended purpose, so that it is possible to switch between
the appended devicetree and one provided by the board's custom function.

Signed-off-by: Simon Glass 
---

Changes in v7:
- Fix 'Is' typo in commit message

Changes in v5:
- Add new patches to clean up fdtdec_setup() and surrounds

 include/fdtdec.h |  7 +--
 lib/fdtdec.c | 21 -
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/include/fdtdec.h b/include/fdtdec.h
index 68786111a44..68a36f10583 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -1170,10 +1170,13 @@ int fdtdec_resetup(int *rescan);
 
 /**
  * Board-specific FDT initialization. Returns the address to a device tree 
blob.
- * Called when CONFIG_OF_BOARD is defined, or if CONFIG_OF_SEPARATE is defined
- * and the board implements it.
+ *
+ * Called when CONFIG_OF_BOARD is defined.
+ *
+ * The existing devicetree is available at gd->fdt_blob
  *
  * @err internal error code if we fail to setup a DTB
+ * @returns new devicetree blob pointer
  */
 void *board_fdt_blob_setup(int *err);
 
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index a7f62123a94..31a509bc221 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1203,15 +1203,15 @@ static int uncompress_blob(const void *src, ulong 
sz_src, void **dstp)
return 0;
 }
 
-/*
- * For CONFIG_OF_SEPARATE, the board may optionally implement this to
- * provide and/or fixup the fdt.
+/**
+ * fdt_find_separate() - Find a devicetree at the end of the image
+ *
+ * @return pointer to FDT blob
  */
-__weak void *board_fdt_blob_setup(int *err)
+static void *fdt_find_separate(void)
 {
void *fdt_blob = NULL;
 
-   *err = 0;
 #ifdef CONFIG_SPL_BUILD
/* FDT is at end of BSS unless it is in a different memory region */
if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS))
@@ -1626,13 +1626,16 @@ int fdtdec_setup(void)
int ret;
 
/* The devicetree is typically appended to U-Boot */
-   if (IS_ENABLED(CONFIG_OF_SEPARATE) || IS_ENABLED(CONFIG_OF_BOARD)) {
-   /* Allow the board to override the fdt address. */
+   if (IS_ENABLED(CONFIG_OF_SEPARATE))
+   gd->fdt_blob = fdt_find_separate();
+   else /* embed dtb in ELF file for testing / development */
+   gd->fdt_blob = dtb_dt_embedded();
+
+   /* Allow the board to override the fdt address. */
+   if (IS_ENABLED(CONFIG_OF_BOARD)) {
gd->fdt_blob = board_fdt_blob_setup();
if (ret)
return ret;
-   } else { /* embed dtb in ELF file for testing / development */
-   gd->fdt_blob = dtb_dt_embedded();
}
 
if (!IS_ENABLED(CONFIG_SPL_BUILD)) {
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 28/31] fdt: Report the devicetree source

2021-12-06 Thread Simon Glass
It can be confusing to figure out where the devicetree came from. It seems
important enough to warrant a message during boot. Add information about
the number of devices and uclasses too since it is helpful to have some
idea what is going on with driver model.

Report the devicetree source in bdinfo too.

This looks something like this, with > marking the new line.

   U-Boot 2021.10-00190 (Oct 30 2021 - 09:01:29 -0600)

   DRAM:  128 MiB
>  Core:  42 devices, 11 uclasses, devicetree: passage
   Flash: 64 MiB

Signed-off-by: Simon Glass 
---

Changes in v7:
- Drop FDTSRC_PASSAGE for now

 cmd/bdinfo.c |  2 ++
 common/board_r.c | 18 ++
 lib/fdtdec.c | 13 +
 3 files changed, 33 insertions(+)

diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c
index bf63cc6d649..c56b3f4f6ec 100644
--- a/cmd/bdinfo.c
+++ b/cmd/bdinfo.c
@@ -128,6 +128,8 @@ int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[])
 
lmb_init_and_reserve(, gd->bd, (void *)gd->fdt_blob);
lmb_dump_all_force();
+   if (IS_ENABLED(CONFIG_OF_REAL))
+   printf("devicetree  = %s\n", fdtdec_get_srcname());
}
 
arch_print_bdinfo();
diff --git a/common/board_r.c b/common/board_r.c
index 31a59c585a8..99adff14b39 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -586,6 +586,23 @@ int initr_mem(void)
 }
 #endif
 
+static int dm_announce(void)
+{
+   int device_count;
+   int uclass_count;
+
+   if (IS_ENABLED(CONFIG_DM)) {
+   dm_get_stats(_count, _count);
+   printf("Core:  %d devices, %d uclasses", device_count,
+  uclass_count);
+   if (CONFIG_IS_ENABLED(OF_REAL))
+   printf(", devicetree: %s", fdtdec_get_srcname());
+   printf("\n");
+   }
+
+   return 0;
+}
+
 static int run_main_loop(void)
 {
 #ifdef CONFIG_SANDBOX
@@ -661,6 +678,7 @@ static init_fnc_t init_sequence_r[] = {
stdio_init_tables,
serial_initialize,
initr_announce,
+   dm_announce,
 #if CONFIG_IS_ENABLED(WDT)
initr_watchdog,
 #endif
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 8cfa958fb96..118c100b389 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -76,6 +76,19 @@ static const char * const compat_names[COMPAT_COUNT] = {
COMPAT(ALTERA_SOCFPGA_CLK_INIT, "altr,socfpga-a10-clk-init")
 };
 
+static const char *const fdt_src_name[] = {
+   [FDTSRC_SEPARATE] = "separate",
+   [FDTSRC_FIT] = "fit",
+   [FDTSRC_BOARD] = "board",
+   [FDTSRC_EMBED] = "embed",
+   [FDTSRC_ENV] = "env",
+};
+
+const char *fdtdec_get_srcname(void)
+{
+   return fdt_src_name[gd->fdt_src];
+}
+
 const char *fdtdec_get_compatible(enum fdt_compat_id id)
 {
/* We allow reading of the 'unknown' ID for testing purposes */
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 23/31] fdt: Drop OF_CONTROL check in fdtdec_setup()

2021-12-06 Thread Simon Glass
This function should only be called when OF_CONTROL is enabled. It
fails in fdtdec_prepare_fdt() anyway, since gd->fdt_blob stays as NULL
if OF_CONTROL is not enabled.

Drop this useless check.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 lib/fdtdec.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 659aeffd82e..5b31064cee2 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1624,16 +1624,15 @@ static void setup_multi_dtb_fit(void)
 int fdtdec_setup(void)
 {
int ret;
-#if CONFIG_IS_ENABLED(OF_CONTROL)
-# ifdef CONFIG_OF_EMBED
+#ifdef CONFIG_OF_EMBED
/* Get a pointer to the FDT */
gd->fdt_blob = dtb_dt_embedded();
-# elif defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
+#elif defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
/* Allow the board to override the fdt address. */
gd->fdt_blob = board_fdt_blob_setup();
if (ret)
return ret;
-# endif
+#endif
if (!IS_ENABLED(CONFIG_SPL_BUILD)) {
/* Allow the early environment to override the fdt address */
gd->fdt_blob = map_sysmem(env_get_ulong("fdtcontroladdr", 16,
@@ -1642,7 +1641,6 @@ int fdtdec_setup(void)
 
if (CONFIG_IS_ENABLED(MULTI_DTB_FIT))
setup_multi_dtb_fit();
-#endif
 
ret = fdtdec_prepare_fdt();
if (!ret)
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 24/31] fdt: Drop remaining preprocessor macros in fdtdec_setup()

2021-12-06 Thread Simon Glass
We only have two choices for obtaining the devicetree. Simplify the code
to make that clear.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 lib/fdtdec.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 5b31064cee2..a7f62123a94 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1624,15 +1624,17 @@ static void setup_multi_dtb_fit(void)
 int fdtdec_setup(void)
 {
int ret;
-#ifdef CONFIG_OF_EMBED
-   /* Get a pointer to the FDT */
-   gd->fdt_blob = dtb_dt_embedded();
-#elif defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
-   /* Allow the board to override the fdt address. */
-   gd->fdt_blob = board_fdt_blob_setup();
-   if (ret)
-   return ret;
-#endif
+
+   /* The devicetree is typically appended to U-Boot */
+   if (IS_ENABLED(CONFIG_OF_SEPARATE) || IS_ENABLED(CONFIG_OF_BOARD)) {
+   /* Allow the board to override the fdt address. */
+   gd->fdt_blob = board_fdt_blob_setup();
+   if (ret)
+   return ret;
+   } else { /* embed dtb in ELF file for testing / development */
+   gd->fdt_blob = dtb_dt_embedded();
+   }
+
if (!IS_ENABLED(CONFIG_SPL_BUILD)) {
/* Allow the early environment to override the fdt address */
gd->fdt_blob = map_sysmem(env_get_ulong("fdtcontroladdr", 16,
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 17/31] doc: Update info on devicetree update

2021-12-06 Thread Simon Glass
Since OF_BOARD has been corrected to be a run-time option, we can drop
the historical info from this documentation.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 doc/develop/devicetree/dt_update.rst | 74 +++-
 1 file changed, 7 insertions(+), 67 deletions(-)

diff --git a/doc/develop/devicetree/dt_update.rst 
b/doc/develop/devicetree/dt_update.rst
index e3b65f6fa66..10a2dfcfd39 100644
--- a/doc/develop/devicetree/dt_update.rst
+++ b/doc/develop/devicetree/dt_update.rst
@@ -32,66 +32,6 @@ that board on suitable hardware (or emulation). This is 
specified using the
 `CONFIG DEFAULT_DEVICE_TREE` option.
 
 
-Current situation (October 2021)
-~~
-
-As an aside, at present U-Boot allows `CONFIG_DEFAULT_DEVICE_TREE` to be empty,
-e.g. if `CONFIG_OF_BOARD` is used. This has unfortunately created an enormous
-amount of confusion and some wasted effort. This was not intended. Support for
-an empty `CONFIG_DEFAULT_DEVICE_TREE` will be dropped soon.
-
-Some of the problems created are:
-
-- It is not obvious that the devicetree is coming from another project
-
-- There is no way to see even a sample devicetree for these platform in U-Boot,
-  so it is hard to know what is going on, e.g. which devices are typically
-  present
-
-- The other project may not provide a way to support U-Boot's requirements for
-  devicetree, such as the /config node. Note: On the U-Boot mailing list, this
-  was only discovered after weeks of discussion and confusion
-
-- For QEMU specifically, consulting two QEMU source files is required, for 
which
-  there are no references in U-Boot documentation. The code is generating a
-  devicetree, but it is not clear what controls affect this generation.
-
-Specifically on the changes in U-Bootm `CONFIG_OF_BOARD` was added in
-rpi_patch_ for Raspberry Pi, which does have an in-tree devicetree, but this
-feature has since been used for boards that don't
-
-Once this bug is fixed, CONFIG_OF_BOARD will override (at runtime) the
-evicetree suppled with U-Boot, but will otherwise use CONFIG_OF_SEPARATE for 
the
-in-tree build. So these two will become options, moving out of the 'choice' in
-`dts/Kconfig`.
-
-This means that there is a basic devicetree build in the U-Boot tree, for
-build-testing, consistency and documentation purposes, but at runtime U-Boot 
can
-accept its devicetree from another source. The in-tree devicetree may contain
-U-Boot-specific features (in u-boot*.dtsi files) and this may prove useful for
-the other project, so it can ensure that U-Boot functions correctly and 
supports
-all its expected features.
-
-To be clear, while U-Boot has its own copy of the devicetree source for each
-board, this must match the Linux source, perhaps with some u-boot.dtsi
-additions. The intent here is not to create a separate binding, just to provide
-a representative devicetree in U-Boot.
-
-Offending boards are:
-
-- rpi_4 and rpi_4_32b (other rpi boards do have an in-tree devicetree)
-- qemu_arm64
-- qemu_arm
-- qemu-ppce500
-- qemu-riscv32
-- qemu-riscv32_smode
-- qemu-riscv64
-- qemu-riscv64_smode
-
-All of these need to have a devicetree added in-tree. This is targeted to be
-fixed in the 2022.01 release.
-
-
 Building the devicetree
 ---
 
@@ -198,17 +138,18 @@ The /config node is similar in concept to the `/chosen 
node`_ except that it is
 for passing information *into* firmware instead of from firmware to the
 Operating System. Also, while Linux has a (sometimes extremely long) command
 line, U-Boot does not support this. The devicetree provides a more structured
-approach in any case.
+approach in any case. Upstreaming of this node (as /options) has begun as of
+November 2021.
 
 
 Devicetree in another project
 -
 
-In some cases U-Boot receive its devicetree at runtime from a program that 
calls
-it. For example ARM's Trusted Firmware A (`TF-A`_) may have a devicetree that 
it
-passes to U-Boot. This overrides any devicetree build by U-Boot. When packaging
-the firmware, the U-Boot devicetree may in fact be left out if it can be
-guaranteed that it will receive one from another project.
+In some cases U-Boot receives its devicetree at runtime from a program that
+calls it. For example ARM's Trusted Firmware A (`TF-A`_) may have a devicetree
+that it passes to U-Boot. This overrides any devicetree build by U-Boot. When
+packaging the firmware, the U-Boot devicetree may in fact be left out if it can
+be guaranteed that it will receive one from another project.
 
 In this case, the devicetree in the other project must track U-Boot's use of
 device tree, for the following reasons:
@@ -546,7 +487,6 @@ Overall, adding a second devicetree would create enormous 
confusion and
 complexity. It seems a lot cheaper to solve this by a change of attitude.
 
 
-.. _rpi_patch: 
https://patchwork.ozlabs.org/project/uboot/patch/20170402082520.32546-1-de...@google.com/
 .. _`TF-A`: 

[PATCH v7 22/31] fdt: Use if() for fdtcontroladdr check

2021-12-06 Thread Simon Glass
Change this to use if() instead of #if

Signed-off-by: Simon Glass 
---

(no changes since v1)

 lib/fdtdec.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 299a2c3a32f..659aeffd82e 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1634,12 +1634,11 @@ int fdtdec_setup(void)
if (ret)
return ret;
 # endif
-# ifndef CONFIG_SPL_BUILD
-   /* Allow the early environment to override the fdt address */
-   gd->fdt_blob = map_sysmem
-   (env_get_ulong("fdtcontroladdr", 16,
+   if (!IS_ENABLED(CONFIG_SPL_BUILD)) {
+   /* Allow the early environment to override the fdt address */
+   gd->fdt_blob = map_sysmem(env_get_ulong("fdtcontroladdr", 16,
   (unsigned long)map_to_sysmem(gd->fdt_blob)), 0);
-# endif
+   }
 
if (CONFIG_IS_ENABLED(MULTI_DTB_FIT))
setup_multi_dtb_fit();
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 19/31] fdt: Drop #ifdefs with MULTI_DTB_FIT

2021-12-06 Thread Simon Glass
Refactor the code to drop the #ifdefs for this feature.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 dts/Kconfig   |  1 -
 include/asm-generic/global_data.h |  8 
 lib/fdtdec.c  | 31 +++
 3 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/dts/Kconfig b/dts/Kconfig
index 6ebbac2a649..5dcc79d5192 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -177,7 +177,6 @@ endchoice
 
 config MULTI_DTB_FIT_UNCOMPRESS_SZ
hex "Size of memory reserved to uncompress the DTBs"
-   depends on (MULTI_DTB_FIT_GZIP || MULTI_DTB_FIT_LZO)
default 0x8000
help
   This is the size of this area where the DTBs are uncompressed.
diff --git a/include/asm-generic/global_data.h 
b/include/asm-generic/global_data.h
index 16fd305a65c..99daa20c765 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -512,6 +512,14 @@ static_assert(sizeof(struct global_data) == GD_SIZE);
 #define gd_acpi_ctx()  NULL
 #endif
 
+#if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
+#define gd_multi_dtb_fit() gd->multi_dtb_fit
+#define gd_set_multi_dtb_fit(_dtb) gd->multi_dtb_fit = _dtb
+#else
+#define gd_multi_dtb_fit() NULL
+#define gd_set_multi_dtb_fit(_dtb)
+#endif
+
 /**
  * enum gd_flags - global data flags
  *
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index e0ce2532f95..4967ab87075 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1146,11 +1146,10 @@ int fdtdec_setup_mem_size_base_lowest(void)
return 0;
 }
 
-#if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
-# if CONFIG_IS_ENABLED(MULTI_DTB_FIT_GZIP) ||\
-   CONFIG_IS_ENABLED(MULTI_DTB_FIT_LZO)
 static int uncompress_blob(const void *src, ulong sz_src, void **dstp)
 {
+#if CONFIG_IS_ENABLED(MULTI_DTB_FIT_GZIP) ||\
+   CONFIG_IS_ENABLED(MULTI_DTB_FIT_LZO)
size_t sz_out = CONFIG_VAL(MULTI_DTB_FIT_UNCOMPRESS_SZ);
bool gzip = 0, lzo = 0;
ulong sz_in = sz_src;
@@ -1175,11 +1174,11 @@ static int uncompress_blob(const void *src, ulong 
sz_src, void **dstp)
return -ENOMEM;
}
} else  {
-#  if CONFIG_IS_ENABLED(MULTI_DTB_FIT_USER_DEFINED_AREA)
+# if CONFIG_IS_ENABLED(MULTI_DTB_FIT_USER_DEFINED_AREA)
dst = (void *)CONFIG_VAL(MULTI_DTB_FIT_USER_DEF_ADDR);
-#  else
+# else
return -ENOTSUPP;
-#  endif
+# endif
}
 
if (CONFIG_IS_ENABLED(GZIP) && gzip)
@@ -1197,16 +1196,12 @@ static int uncompress_blob(const void *src, ulong 
sz_src, void **dstp)
return -EBADMSG;
}
*dstp = dst;
-   return 0;
-}
-# else
-static int uncompress_blob(const void *src, ulong sz_src, void **dstp)
-{
+#else
+   *dstp = (void *)src;
*dstp = (void *)src;
+#endif
return 0;
 }
-# endif
-#endif
 
 #if defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
 /*
@@ -1606,7 +1601,6 @@ __weak int fdtdec_board_setup(const void *fdt_blob)
  */
 static void setup_multi_dtb_fit(void)
 {
-# if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
void *blob;
 
/*
@@ -1624,10 +1618,9 @@ static void setup_multi_dtb_fit(void)
 */
blob = locate_dtb_in_fit(gd->fdt_blob);
if (blob) {
-   gd->multi_dtb_fit = gd->fdt_blob;
+   gd_set_multi_dtb_fit(gd->fdt_blob);
gd->fdt_blob = blob;
}
-#endif /* # MULTI_DTB_FIT */
 }
 
 int fdtdec_setup(void)
@@ -1664,7 +1657,6 @@ int fdtdec_setup(void)
return ret;
 }
 
-#if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
 int fdtdec_resetup(int *rescan)
 {
void *fdt_blob;
@@ -1675,8 +1667,8 @@ int fdtdec_resetup(int *rescan)
 * FIT image stillpresent there. Save the time and space
 * required to uncompress it again.
 */
-   if (gd->multi_dtb_fit) {
-   fdt_blob = locate_dtb_in_fit(gd->multi_dtb_fit);
+   if (gd_multi_dtb_fit()) {
+   fdt_blob = locate_dtb_in_fit(gd_multi_dtb_fit());
 
if (fdt_blob == gd->fdt_blob) {
/*
@@ -1700,7 +1692,6 @@ int fdtdec_resetup(int *rescan)
*rescan = 0;
return 0;
 }
-#endif
 
 int fdtdec_decode_ram_size(const void *blob, const char *area, int board_id,
   phys_addr_t *basep, phys_size_t *sizep,
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 21/31] fdt: Drop #ifdef around board_fdt_blob_setup()

2021-12-06 Thread Simon Glass
This serves no purpose. Drop it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 lib/fdtdec.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index fbdc92c0813..299a2c3a32f 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1203,7 +1203,6 @@ static int uncompress_blob(const void *src, ulong sz_src, 
void **dstp)
return 0;
 }
 
-#if defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
 /*
  * For CONFIG_OF_SEPARATE, the board may optionally implement this to
  * provide and/or fixup the fdt.
@@ -1226,7 +1225,6 @@ __weak void *board_fdt_blob_setup(int *err)
 
return fdt_blob;
 }
-#endif
 
 int fdtdec_set_ethernet_mac_address(void *fdt, const u8 *mac, size_t size)
 {
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 20/31] fdt: Drop CONFIG_SPL_BUILD check in fdtdec_setup()

2021-12-06 Thread Simon Glass
Move this to the header file to clean up the C code.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/fdtdec.h | 14 ++
 lib/fdtdec.c |  6 +-
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/include/fdtdec.h b/include/fdtdec.h
index 6c7ab887b20..68786111a44 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -111,6 +111,20 @@ struct fdt_pci_addr {
 extern u8 __dtb_dt_begin[];/* embedded device tree blob */
 extern u8 __dtb_dt_spl_begin[];/* embedded device tree blob for 
SPL/TPL */
 
+/* Get a pointer to the embedded devicetree, if there is one, else NULL */
+static inline u8 *dtb_dt_embedded(void)
+{
+#ifdef CONFIG_OF_EMBED
+# ifdef CONFIG_SPL_BUILD
+   return __dtb_dt_spl_begin;
+# else
+   return __dtb_dt_begin;
+# endif
+#else
+   return NULL;
+#endif
+}
+
 /**
  * Compute the size of a resource.
  *
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 4967ab87075..fbdc92c0813 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1629,11 +1629,7 @@ int fdtdec_setup(void)
 #if CONFIG_IS_ENABLED(OF_CONTROL)
 # ifdef CONFIG_OF_EMBED
/* Get a pointer to the FDT */
-#  ifdef CONFIG_SPL_BUILD
-   gd->fdt_blob = __dtb_dt_spl_begin;
-#  else
-   gd->fdt_blob = __dtb_dt_begin;
-#  endif
+   gd->fdt_blob = dtb_dt_embedded();
 # elif defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
/* Allow the board to override the fdt address. */
gd->fdt_blob = board_fdt_blob_setup();
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 18/31] fdt: Move MULTI_DTB_FIT handling out of fdtdec_setup()

2021-12-06 Thread Simon Glass
This logic is a bit convoluted for one function. Move the mulit-FIT part
into its own function.

Signed-off-by: Simon Glass 
Reviewed-by: Ilias Apalodimas 
---

(no changes since v1)

 lib/fdtdec.c | 62 
 1 file changed, 38 insertions(+), 24 deletions(-)

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 7681f272d27..e0ce2532f95 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1594,13 +1594,46 @@ __weak int fdtdec_board_setup(const void *fdt_blob)
return 0;
 }
 
+/**
+ * setup_multi_dtb_fit() - locate the correct dtb from a FIT
+ *
+ * This supports the CONFIG_MULTI_DTB_FIT feature, looking for the dtb in a
+ * supplied FIT
+ *
+ * It accepts the current value of gd->fdt_blob, which points to the FIT, then
+ * updates that gd->fdt_blob, to point to the chosen dtb so that U-Boot uses 
the
+ * correct one
+ */
+static void setup_multi_dtb_fit(void)
+{
+# if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
+   void *blob;
+
+   /*
+* Try and uncompress the blob.
+* Unfortunately there is no way to know how big the input blob really
+* is. So let us set the maximum input size arbitrarily high. 16MB
+* ought to be more than enough for packed DTBs.
+*/
+   if (uncompress_blob(gd->fdt_blob, 0x100, ) == 0)
+   gd->fdt_blob = blob;
+
+   /*
+* Check if blob is a FIT images containings DTBs.
+* If so, pick the most relevant
+*/
+   blob = locate_dtb_in_fit(gd->fdt_blob);
+   if (blob) {
+   gd->multi_dtb_fit = gd->fdt_blob;
+   gd->fdt_blob = blob;
+   }
+#endif /* # MULTI_DTB_FIT */
+}
+
 int fdtdec_setup(void)
 {
int ret;
 #if CONFIG_IS_ENABLED(OF_CONTROL)
-# if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
-   void *fdt_blob;
-# endif
 # ifdef CONFIG_OF_EMBED
/* Get a pointer to the FDT */
 #  ifdef CONFIG_SPL_BUILD
@@ -1621,27 +1654,8 @@ int fdtdec_setup(void)
   (unsigned long)map_to_sysmem(gd->fdt_blob)), 0);
 # endif
 
-# if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
-   /*
-* Try and uncompress the blob.
-* Unfortunately there is no way to know how big the input blob really
-* is. So let us set the maximum input size arbitrarily high. 16MB
-* ought to be more than enough for packed DTBs.
-*/
-   if (uncompress_blob(gd->fdt_blob, 0x100, _blob) == 0)
-   gd->fdt_blob = fdt_blob;
-
-   /*
-* Check if blob is a FIT images containings DTBs.
-* If so, pick the most relevant
-*/
-   fdt_blob = locate_dtb_in_fit(gd->fdt_blob);
-   if (fdt_blob) {
-   gd->multi_dtb_fit = gd->fdt_blob;
-   gd->fdt_blob = fdt_blob;
-   }
-
-# endif
+   if (CONFIG_IS_ENABLED(MULTI_DTB_FIT))
+   setup_multi_dtb_fit();
 #endif
 
ret = fdtdec_prepare_fdt();
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 16/31] Drop CONFIG_BINMAN_STANDALONE_FDT

2021-12-06 Thread Simon Glass
This was added as a hack to work around not having an in-tree devicetree.
Now that this is fixed it is not needed.

Drop it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 Makefile|  3 +--
 dts/Kconfig | 18 --
 tools/binman/binman.rst | 20 
 3 files changed, 1 insertion(+), 40 deletions(-)

diff --git a/Makefile b/Makefile
index 043af9a5dcd..6671c5d9e2f 100644
--- a/Makefile
+++ b/Makefile
@@ -953,7 +953,6 @@ endif
 endif
 INPUTS-$(CONFIG_TPL) += tpl/u-boot-tpl.bin
 INPUTS-$(CONFIG_OF_SEPARATE) += u-boot.dtb
-INPUTS-$(CONFIG_BINMAN_STANDALONE_FDT) += u-boot.dtb
 ifeq ($(CONFIG_SPL_FRAMEWORK),y)
 INPUTS-$(CONFIG_OF_SEPARATE) += u-boot-dtb.img
 endif
@@ -1427,7 +1426,7 @@ u-boot-lzma.img: u-boot.bin.lzma FORCE
 
 u-boot-dtb.img u-boot.img u-boot.kwb u-boot.pbl u-boot-ivt.img: \
$(if $(CONFIG_SPL_LOAD_FIT),u-boot-nodtb.bin \
-   $(if 
$(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SANDBOX)$(CONFIG_BINMAN_STANDALONE_FDT),dts/dt.dtb)
 \
+   $(if 
$(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SANDBOX),dts/dt.dtb) \
,$(UBOOT_BIN)) FORCE
$(call if_changed,mkimage)
$(BOARD_SIZE_CHECK)
diff --git a/dts/Kconfig b/dts/Kconfig
index 9994ab13dcb..6ebbac2a649 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -16,24 +16,6 @@ config BINMAN
bool
select DTOC
 
-config BINMAN_STANDALONE_FDT
-   bool
-   depends on BINMAN
-   default y if OF_BOARD
-   help
- This option tells U-Boot build system that a standalone device tree
- source is explicitly required when using binman to package U-Boot.
-
- This is not necessary in a common scenario where a device tree source
- that contains the binman node is provided in the arch//dts
- directory for a specific board. Such device tree sources are built for
- OF_SEPARATE or OF_EMBED. However for a scenario like the board device
- tree blob is not provided in the U-Boot build tree, but fed to U-Boot
- in the runtime, e.g.: in the OF_BOARD case that it is passed by
- a prior stage bootloader. For such scenario, a standalone device tree
- blob containing binman node to describe how to package U-Boot should
- be provided explicitly.
-
 menu "Device Tree Control"
depends on SUPPORT_OF_CONTROL
 
diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst
index 10389a52c4b..56f865800e6 100644
--- a/tools/binman/binman.rst
+++ b/tools/binman/binman.rst
@@ -232,26 +232,6 @@ You can use other, more specific CONFIG options - see 
'Automatic .dtsi
 inclusion' below.
 
 
-Using binman with OF_BOARD
-
-
-Normally binman is used with a board configured with OF_SEPARATE or OF_EMBED.
-This is a typical scenario where a device tree source that contains the binman
-node is provided in the arch//dts directory for a specific board.
-
-However for a board configured with OF_BOARD, no device tree blob is provided
-in the U-Boot build phase hence the binman node information is not available.
-In order to support such use case, a new Kconfig option BINMAN_STANDALONE_FDT
-is introduced, to tell the build system that a standalone device tree blob
-containing binman node is explicitly required.
-
-Note there is a Kconfig option BINMAN_FDT which enables U-Boot run time to
-access information about binman entries, stored in the device tree in a binman
-node. Generally speaking, this option makes sense for OF_SEPARATE or OF_EMBED.
-For the other OF_CONTROL methods, it's quite possible binman node is not
-available as binman is invoked during the build phase, thus this option is not
-turned on by default for these OF_CONTROL methods.
-
 Access to binman entry offsets at run time (symbols)
 
 
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 15/31] fdt: Make OF_BOARD a bool option

2021-12-06 Thread Simon Glass
This should not be a separate option from OF_SEPARATE. It is a run-time
option to override the devicetree, even if present.

Move the option out of the choice.

Disable BINMAN_FDT for a few boards which don't actually use it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 configs/qemu-ppce500_defconfig |  1 +
 configs/qemu-riscv32_spl_defconfig |  2 ++
 configs/qemu-riscv64_spl_defconfig |  1 +
 dts/Kconfig| 11 ++-
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/configs/qemu-ppce500_defconfig b/configs/qemu-ppce500_defconfig
index ae4cd8b9618..81d12d5f3c1 100644
--- a/configs/qemu-ppce500_defconfig
+++ b/configs/qemu-ppce500_defconfig
@@ -56,4 +56,5 @@ CONFIG_VIRTIO_PCI=y
 CONFIG_VIRTIO_NET=y
 CONFIG_VIRTIO_BLK=y
 CONFIG_ADDR_MAP=y
+# CONFIG_BINMAN_FDT is not set
 CONFIG_PANIC_HANG=y
diff --git a/configs/qemu-riscv32_spl_defconfig 
b/configs/qemu-riscv32_spl_defconfig
index c4422969c61..8889b028c6b 100644
--- a/configs/qemu-riscv32_spl_defconfig
+++ b/configs/qemu-riscv32_spl_defconfig
@@ -6,6 +6,7 @@ CONFIG_DEFAULT_DEVICE_TREE="qemu-virt32"
 CONFIG_SPL=y
 CONFIG_TARGET_QEMU_VIRT=y
 CONFIG_RISCV_SMODE=y
+# CONFIG_OF_BOARD_FIXUP is not set
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_SYS_LOAD_ADDR=0x8020
 CONFIG_FIT=y
@@ -18,3 +19,4 @@ CONFIG_OF_BOARD=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_DM_MTD=y
 CONFIG_SYSRESET_SBI=y
+# CONFIG_BINMAN_FDT is not set
diff --git a/configs/qemu-riscv64_spl_defconfig 
b/configs/qemu-riscv64_spl_defconfig
index e02ca3a1465..8f875949ec0 100644
--- a/configs/qemu-riscv64_spl_defconfig
+++ b/configs/qemu-riscv64_spl_defconfig
@@ -19,3 +19,4 @@ CONFIG_OF_BOARD=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_DM_MTD=y
 CONFIG_SYSRESET_SBI=y
+# CONFIG_BINMAN_FDT is not set
diff --git a/dts/Kconfig b/dts/Kconfig
index b7c4a2fec03..9994ab13dcb 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -97,11 +97,9 @@ config OF_LIVE
 choice
prompt "Provider of DTB for DT control"
depends on OF_CONTROL
-   default OF_BOARD if SANDBOX
 
 config OF_SEPARATE
bool "Separate DTB for DT control"
-   depends on !SANDBOX
help
  If this option is enabled, the device tree will be built and
  placed as a separate u-boot.dtb file alongside the U-Boot image.
@@ -114,14 +112,17 @@ config OF_EMBED
  and development only and is not recommended for production devices.
  Boards in the mainline U-Boot tree should not use it.
 
+endchoice
+
 config OF_BOARD
bool "Provided by the board (e.g a previous loader) at runtime"
+   default y if SANDBOX
help
  If this option is enabled, the device tree will be provided by
- the board at runtime if the board supports it, instead of being
- bundled with the image.
+ the board at runtime if the board supports it. The device tree bundled
+ with the image (if any) will be overridden / ignored.
 
-endchoice
+ A device tree file must be provided in the tree.
 
 config DEFAULT_DEVICE_TREE
string "Default Device Tree for DT control"
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 07/31] arm: rpi: Sync rpi dts files from Linux

2021-12-06 Thread Simon Glass
Sync these files, obtained from Linux v5.15.

This adds a devicetree file for rpi_4 which was not there before.

Testing shows no change so far as I can see:
- boots to U-Boot prompt on rpi0, rpi2
- boots to distro on rpi3
- boots to distro on rpi4

I am assuming that syncing with Linux is safe, but the maintainer should
know for sure.

Signed-off-by: Simon Glass 
---

Changes in v7:
- Bring in files from Linux instead

 arch/arm/dts/Makefile|3 +-
 arch/arm/dts/bcm2711-rpi-4-b.dts |  262 +
 arch/arm/dts/bcm2711-rpi.dtsi|   74 ++
 arch/arm/dts/bcm2711.dtsi| 1100 ++
 arch/arm/dts/bcm2835-common.dtsi |  207 
 arch/arm/dts/bcm2835-rpi-a-plus.dts  |   18 +-
 arch/arm/dts/bcm2835-rpi-a.dts   |   16 +-
 arch/arm/dts/bcm2835-rpi-b-plus.dts  |   18 +-
 arch/arm/dts/bcm2835-rpi-b-rev2.dts  |   16 +-
 arch/arm/dts/bcm2835-rpi-b.dts   |   16 +-
 arch/arm/dts/bcm2835-rpi-cm1-io1.dts |9 +
 arch/arm/dts/bcm2835-rpi-cm1.dtsi|7 +-
 arch/arm/dts/bcm2835-rpi-common.dtsi |   12 +
 arch/arm/dts/bcm2835-rpi-zero-w.dts  |   20 +-
 arch/arm/dts/bcm2835-rpi-zero.dts|   16 +-
 arch/arm/dts/bcm2835-rpi.dtsi|   35 +-
 arch/arm/dts/bcm2835.dtsi|2 +
 arch/arm/dts/bcm2836-rpi-2-b.dts |   14 +-
 arch/arm/dts/bcm2836.dtsi|2 +
 arch/arm/dts/bcm2837-rpi-3-a-plus.dts|9 +-
 arch/arm/dts/bcm2837-rpi-3-b-plus.dts|9 +-
 arch/arm/dts/bcm2837-rpi-3-b.dts |5 +-
 arch/arm/dts/bcm2837-rpi-cm3-io3.dts |9 +
 arch/arm/dts/bcm2837-rpi-cm3.dtsi|9 +
 arch/arm/dts/bcm2837.dtsi|2 +
 arch/arm/dts/bcm283x-rpi-usb-peripheral.dtsi |7 +
 arch/arm/dts/bcm283x.dtsi|  224 +---
 configs/rpi_4_32b_defconfig  |1 +
 configs/rpi_4_defconfig  |1 +
 configs/rpi_arm64_defconfig  |1 +
 include/dt-bindings/clock/bcm2835.h  |2 +
 31 files changed, 1878 insertions(+), 248 deletions(-)
 create mode 100644 arch/arm/dts/bcm2711-rpi-4-b.dts
 create mode 100644 arch/arm/dts/bcm2711-rpi.dtsi
 create mode 100644 arch/arm/dts/bcm2711.dtsi
 create mode 100644 arch/arm/dts/bcm2835-common.dtsi
 create mode 100644 arch/arm/dts/bcm2835-rpi-common.dtsi
 create mode 100644 arch/arm/dts/bcm283x-rpi-usb-peripheral.dtsi

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 2d92b2f940d..9cddab37207 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1077,7 +1077,8 @@ dtb-$(CONFIG_ARCH_BCM283X) += \
bcm2837-rpi-3-a-plus.dtb \
bcm2837-rpi-3-b.dtb \
bcm2837-rpi-3-b-plus.dtb \
-   bcm2837-rpi-cm3-io3.dtb
+   bcm2837-rpi-cm3-io3.dtb \
+   bcm2711-rpi-4-b.dtb
 
 dtb-$(CONFIG_ARCH_BCM63158) += \
bcm963158.dtb
diff --git a/arch/arm/dts/bcm2711-rpi-4-b.dts b/arch/arm/dts/bcm2711-rpi-4-b.dts
new file mode 100644
index 000..72ce80fbf26
--- /dev/null
+++ b/arch/arm/dts/bcm2711-rpi-4-b.dts
@@ -0,0 +1,262 @@
+// SPDX-License-Identifier: GPL-2.0
+/dts-v1/;
+#include "bcm2711.dtsi"
+#include "bcm2711-rpi.dtsi"
+#include "bcm283x-rpi-usb-peripheral.dtsi"
+
+/ {
+   compatible = "raspberrypi,4-model-b", "brcm,bcm2711";
+   model = "Raspberry Pi 4 Model B";
+
+   chosen {
+   /* 8250 auxiliary UART instead of pl011 */
+   stdout-path = "serial1:115200n8";
+   };
+
+   leds {
+   led-act {
+   gpios = < 42 GPIO_ACTIVE_HIGH>;
+   };
+
+   led-pwr {
+   label = "PWR";
+   gpios = < 2 GPIO_ACTIVE_LOW>;
+   default-state = "keep";
+   linux,default-trigger = "default-on";
+   };
+   };
+
+   wifi_pwrseq: wifi-pwrseq {
+   compatible = "mmc-pwrseq-simple";
+   reset-gpios = < 1 GPIO_ACTIVE_LOW>;
+   };
+
+   sd_io_1v8_reg: sd_io_1v8_reg {
+   compatible = "regulator-gpio";
+   regulator-name = "vdd-sd-io";
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <330>;
+   regulator-boot-on;
+   regulator-always-on;
+   regulator-settling-time-us = <5000>;
+   gpios = < 4 GPIO_ACTIVE_HIGH>;
+   states = <180 0x1>,
+<330 0x0>;
+   status = "okay";
+   };
+
+   sd_vcc_reg: sd_vcc_reg {
+   compatible = "regulator-fixed";
+   regulator-name = "vcc-sd";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-boot-on;
+   enable-active-high;
+   

[PATCH v7 14/31] arm: highbank: Add devicetree files

2021-12-06 Thread Simon Glass
Sync these files, obtained from Linux v5.15.

Signed-off-by: Simon Glass 
---

Changes in v7:
- Bring in files from Linux instead

 arch/arm/dts/Makefile|   2 +
 arch/arm/dts/ecx-common.dtsi | 231 +++
 arch/arm/dts/highbank.dts| 158 
 configs/highbank_defconfig   |   2 +-
 4 files changed, 392 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/ecx-common.dtsi
 create mode 100644 arch/arm/dts/highbank.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 8bb15b96cc7..453e2fd1a98 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -871,6 +871,8 @@ dtb-$(CONFIG_MX7) += imx7d-sdb.dtb \
 dtb-$(CONFIG_ARCH_MX7ULP) += imx7ulp-com.dtb \
imx7ulp-evk.dtb
 
+dtb-$(CONFIG_ARCH_HIGHBANK) += highbank.dtb
+
 dtb-$(CONFIG_ARCH_IMX8) += \
fsl-imx8qm-apalis.dtb \
fsl-imx8qm-mek.dtb \
diff --git a/arch/arm/dts/ecx-common.dtsi b/arch/arm/dts/ecx-common.dtsi
new file mode 100644
index 000..57a028a6937
--- /dev/null
+++ b/arch/arm/dts/ecx-common.dtsi
@@ -0,0 +1,231 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright 2011-2012 Calxeda, Inc.
+ */
+
+/ {
+   chosen {
+   bootargs = "console=ttyAMA0";
+   };
+
+   psci {
+   compatible  = "arm,psci";
+   method  = "smc";
+   cpu_suspend = <0x8402>;
+   cpu_off = <0x8404>;
+   cpu_on  = <0x8406>;
+   };
+
+   soc {
+   #address-cells = <1>;
+   #size-cells = <1>;
+   compatible = "simple-bus";
+   interrupt-parent = <>;
+
+   sata@ffe08000 {
+   compatible = "calxeda,hb-ahci";
+   reg = <0xffe08000 0x1>;
+   interrupts = <0 83 4>;
+   dma-coherent;
+   calxeda,port-phys = <  0>, < 0>,
+< 1>, < 2>,
+< 3>;
+   calxeda,sgpio-gpio =< 5 1>, < 6 1>,
+   < 7 1>;
+   calxeda,led-order = <4 0 1 2 3>;
+   };
+
+   sdhci@ffe0e000 {
+   compatible = "calxeda,hb-sdhci";
+   reg = <0xffe0e000 0x1000>;
+   interrupts = <0 90 4>;
+   clocks = <>;
+   status = "disabled";
+   };
+
+   ipc@fff2 {
+   compatible = "arm,pl320", "arm,primecell";
+   reg = <0xfff2 0x1000>;
+   interrupts = <0 7 4>;
+   clocks = <>;
+   clock-names = "apb_pclk";
+   };
+
+   gpioe: gpio@fff3 {
+   #gpio-cells = <2>;
+   compatible = "arm,pl061", "arm,primecell";
+   gpio-controller;
+   reg = <0xfff3 0x1000>;
+   interrupts = <0 14 4>;
+   clocks = <>;
+   clock-names = "apb_pclk";
+   status = "disabled";
+   };
+
+   gpiof: gpio@fff31000 {
+   #gpio-cells = <2>;
+   compatible = "arm,pl061", "arm,primecell";
+   gpio-controller;
+   reg = <0xfff31000 0x1000>;
+   interrupts = <0 15 4>;
+   clocks = <>;
+   clock-names = "apb_pclk";
+   status = "disabled";
+   };
+
+   gpiog: gpio@fff32000 {
+   #gpio-cells = <2>;
+   compatible = "arm,pl061", "arm,primecell";
+   gpio-controller;
+   reg = <0xfff32000 0x1000>;
+   interrupts = <0 16 4>;
+   clocks = <>;
+   clock-names = "apb_pclk";
+   status = "disabled";
+   };
+
+   gpioh: gpio@fff33000 {
+   #gpio-cells = <2>;
+   compatible = "arm,pl061", "arm,primecell";
+   gpio-controller;
+   reg = <0xfff33000 0x1000>;
+   interrupts = <0 17 4>;
+   clocks = <>;
+   clock-names = "apb_pclk";
+   status = "disabled";
+   };
+
+   timer@fff34000 {
+   compatible = "arm,sp804", "arm,primecell";
+   reg = <0xfff34000 0x1000>;
+   interrupts = <0 18 4>;
+   clocks = <>;
+   clock-names = "apb_pclk";
+   };
+
+   rtc@fff35000 {
+   

[PATCH v7 08/31] arm: vexpress: Add a devicetree files for juno

2021-12-06 Thread Simon Glass
Sync these file, obtained from Linux v5.15.

Add a note for the maintainer, and SPDX lines where they are missing.
The added lines are:

   SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause

Note, this matches the text in those files, but is not the same as the
GPL-2.0 of some files.

[1] https://releases.linaro.org/android/reference-lcr/juno/7.1-17.05/

Signed-off-by: Simon Glass 
---

Changes in v7:
- Bring in files from Linux instead
- Rewrite the commit message

 arch/arm/dts/Makefile  |   3 +
 arch/arm/dts/juno-base.dtsi| 831 +
 arch/arm/dts/juno-clocks.dtsi  |  46 ++
 arch/arm/dts/juno-cs-r1r2.dtsi |  85 +++
 arch/arm/dts/juno-motherboard.dtsi | 303 +
 arch/arm/dts/juno-r2.dts   | 322 ++
 configs/vexpress_aemv8a_juno_defconfig |   1 +
 7 files changed, 1591 insertions(+)
 create mode 100644 arch/arm/dts/juno-base.dtsi
 create mode 100644 arch/arm/dts/juno-clocks.dtsi
 create mode 100644 arch/arm/dts/juno-cs-r1r2.dtsi
 create mode 100644 arch/arm/dts/juno-motherboard.dtsi
 create mode 100644 arch/arm/dts/juno-r2.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 9cddab37207..d53bae2c350 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1149,7 +1149,10 @@ dtb-$(CONFIG_TARGET_GE_BX50V3) += \
 dtb-$(CONFIG_TARGET_GE_B1X5V2) += imx6dl-b1x5v2.dtb
 dtb-$(CONFIG_TARGET_MX53PPD) += imx53-ppd.dtb
 
+# TODO(Linus Walleij ): Should us a single vexpress
+# Kconfig option to build all of these. See examples above.
 dtb-$(CONFIG_TARGET_VEXPRESS_CA9X4) += vexpress-v2p-ca9.dtb
+dtb-$(CONFIG_TARGET_VEXPRESS64_JUNO) += juno-r2.dtb
 
 dtb-$(CONFIG_TARGET_TOTAL_COMPUTE) += total_compute.dtb
 
diff --git a/arch/arm/dts/juno-base.dtsi b/arch/arm/dts/juno-base.dtsi
new file mode 100644
index 000..6288e104a08
--- /dev/null
+++ b/arch/arm/dts/juno-base.dtsi
@@ -0,0 +1,831 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "juno-clocks.dtsi"
+#include "juno-motherboard.dtsi"
+
+/ {
+   /*
+*  Devices shared by all Juno boards
+*/
+
+   memtimer: timer@2a81 {
+   compatible = "arm,armv7-timer-mem";
+   reg = <0x0 0x2a81 0x0 0x1>;
+   clock-frequency = <5000>;
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0 0x0 0x2a82 0x2>;
+   status = "disabled";
+   frame@2a83 {
+   frame-number = <1>;
+   interrupts = ;
+   reg = <0x1 0x1>;
+   };
+   };
+
+   mailbox: mhu@2b1f {
+   compatible = "arm,mhu", "arm,primecell";
+   reg = <0x0 0x2b1f 0x0 0x1000>;
+   interrupts = ,
+;
+   #mbox-cells = <1>;
+   clocks = <_refclk100mhz>;
+   clock-names = "apb_pclk";
+   };
+
+   smmu_gpu: iommu@2b40 {
+   compatible = "arm,mmu-400", "arm,smmu-v1";
+   reg = <0x0 0x2b40 0x0 0x1>;
+   interrupts = ,
+;
+   #iommu-cells = <1>;
+   #global-interrupts = <1>;
+   power-domains = <_devpd 1>;
+   dma-coherent;
+   status = "disabled";
+   };
+
+   smmu_pcie: iommu@2b50 {
+   compatible = "arm,mmu-401", "arm,smmu-v1";
+   reg = <0x0 0x2b50 0x0 0x1>;
+   interrupts = ,
+;
+   #iommu-cells = <1>;
+   #global-interrupts = <1>;
+   dma-coherent;
+   status = "disabled";
+   };
+
+   smmu_etr: iommu@2b60 {
+   compatible = "arm,mmu-401", "arm,smmu-v1";
+   reg = <0x0 0x2b60 0x0 0x1>;
+   interrupts = ,
+;
+   #iommu-cells = <1>;
+   #global-interrupts = <1>;
+   dma-coherent;
+   power-domains = <_devpd 0>;
+   };
+
+   gic: interrupt-controller@2c01 {
+   compatible = "arm,gic-400", "arm,cortex-a15-gic";
+   reg = <0x0 0x2c01 0 0x1000>,
+ <0x0 0x2c02f000 0 0x2000>,
+ <0x0 0x2c04f000 0 0x2000>,
+ <0x0 0x2c06f000 0 0x2000>;
+   #address-cells = <1>;
+   #interrupt-cells = <3>;
+   #size-cells = <1>;
+   interrupt-controller;
+   interrupts = ;
+   ranges = <0 0 0x2c1c 0x4>;
+
+   v2m_0: v2m@0 {
+   compatible = "arm,gic-v2m-frame";
+   msi-controller;
+   reg = <0 0x1>;
+   };
+
+   v2m@1 {
+   compatible = "arm,gic-v2m-frame";
+   msi-controller;
+ 

[PATCH v7 13/31] arm: qemu-ppce500: Add a devicetree file

2021-12-06 Thread Simon Glass
This uses QEMU virt which creates its own devicetree.

Add an empty version of this file, so that we can at least build this
board when devicetrees are required.

Signed-off-by: Simon Glass 
---

Changes in v7:
- Switch to using an empty file for qemu virt

 arch/powerpc/dts/Makefile |  1 +
 arch/powerpc/dts/qemu-ppce500.dts | 10 ++
 configs/qemu-ppce500_defconfig|  1 +
 3 files changed, 12 insertions(+)
 create mode 100644 arch/powerpc/dts/qemu-ppce500.dts

diff --git a/arch/powerpc/dts/Makefile b/arch/powerpc/dts/Makefile
index ceaa8ce5c82..66d22ae8a45 100644
--- a/arch/powerpc/dts/Makefile
+++ b/arch/powerpc/dts/Makefile
@@ -18,6 +18,7 @@ dtb-$(CONFIG_TARGET_P2041RDB) += p2041rdb.dtb
 dtb-$(CONFIG_TARGET_P3041DS) += p3041ds.dtb
 dtb-$(CONFIG_TARGET_P4080DS) += p4080ds.dtb
 dtb-$(CONFIG_TARGET_P5040DS) += p5040ds.dtb
+dtb-$(CONFIG_TARGET_QEMU_PPCE500) += qemu-ppce500.dtb
 dtb-$(CONFIG_TARGET_SOCRATES) += socrates.dtb
 dtb-$(CONFIG_TARGET_T1024RDB) += t1024rdb.dtb
 dtb-$(CONFIG_TARGET_T1042D4RDB) += t1042d4rdb.dtb
diff --git a/arch/powerpc/dts/qemu-ppce500.dts 
b/arch/powerpc/dts/qemu-ppce500.dts
new file mode 100644
index 000..e88e09e1796
--- /dev/null
+++ b/arch/powerpc/dts/qemu-ppce500.dts
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0+ OR MIT
+/*
+ * Empty device tree for qemu-ppce400
+ *
+ * Copyright 2021 Google LLC
+ */
+/dts-v1/;
+
+/ {
+};
diff --git a/configs/qemu-ppce500_defconfig b/configs/qemu-ppce500_defconfig
index f386f526548..ae4cd8b9618 100644
--- a/configs/qemu-ppce500_defconfig
+++ b/configs/qemu-ppce500_defconfig
@@ -1,6 +1,7 @@
 CONFIG_PPC=y
 CONFIG_SYS_TEXT_BASE=0xf01000
 CONFIG_ENV_SIZE=0x2000
+CONFIG_DEFAULT_DEVICE_TREE="qemu-ppce500"
 CONFIG_MPC85xx=y
 # CONFIG_CMD_ERRATA is not set
 CONFIG_TARGET_QEMU_PPCE500=y
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 12/31] arm: bcm7xxx: Add a devicetree file

2021-12-06 Thread Simon Glass
Add a dummy devicetree file for these boards. It seems to be possible to
obtain a real one from another bootloader called 'bolt' but I will leave
this to the maintainer.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arm/dts/Makefile |  2 ++
 arch/arm/dts/bcm7xxx.dts  | 15 +++
 configs/bcm7260_defconfig |  1 +
 configs/bcm7445_defconfig |  1 +
 4 files changed, 19 insertions(+)
 create mode 100644 arch/arm/dts/bcm7xxx.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index b07a1b3378e..8bb15b96cc7 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1092,6 +1092,8 @@ dtb-$(CONFIG_ARCH_BCM6858) += \
 
 dtb-$(CONFIG_TARGET_BCMNS3) += ns3-board.dtb
 
+dtb-$(CONFIG_ARCH_BCMSTB) += bcm7xxx.dtb
+
 dtb-$(CONFIG_ASPEED_AST2500) += ast2500-evb.dtb
 dtb-$(CONFIG_ASPEED_AST2600) += ast2600-evb.dtb
 
diff --git a/arch/arm/dts/bcm7xxx.dts b/arch/arm/dts/bcm7xxx.dts
new file mode 100644
index 000..786ce3ff959
--- /dev/null
+++ b/arch/arm/dts/bcm7xxx.dts
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Empty devicetre file for bcm7260 board
+ *
+ * This is required to make the board build with CONFIG OF_SEPARATE
+ * In-tree document explains how to obtain a real devicetree using 'bolt' but
+ * I did not attempt this.
+ *
+ * Copyright 2021 Google LLC
+ */
+
+/dts-v1/;
+
+/ {
+};
diff --git a/configs/bcm7260_defconfig b/configs/bcm7260_defconfig
index 257d81052a8..2b527b65770 100644
--- a/configs/bcm7260_defconfig
+++ b/configs/bcm7260_defconfig
@@ -7,6 +7,7 @@ CONFIG_TARGET_BCM7260=y
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x1
 CONFIG_ENV_OFFSET=0x814800
+CONFIG_DEFAULT_DEVICE_TREE="bcm7xxx"
 CONFIG_ENV_OFFSET_REDUND=0x824800
 CONFIG_SYS_LOAD_ADDR=0x0200
 CONFIG_FIT=y
diff --git a/configs/bcm7445_defconfig b/configs/bcm7445_defconfig
index 9ffa436e454..3ae678ba56e 100644
--- a/configs/bcm7445_defconfig
+++ b/configs/bcm7445_defconfig
@@ -8,6 +8,7 @@ CONFIG_NR_DRAM_BANKS=3
 CONFIG_ENV_SIZE=0x1
 CONFIG_ENV_OFFSET=0x1E
 CONFIG_ENV_SECT_SIZE=0x1
+CONFIG_DEFAULT_DEVICE_TREE="bcm7xxx"
 CONFIG_ENV_OFFSET_REDUND=0x1F
 CONFIG_SYS_LOAD_ADDR=0x0200
 CONFIG_FIT=y
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 11/31] arm: xilinx_versal_virt: Add a devicetree file

2021-12-06 Thread Simon Glass
Add an empty file to prevent build errors when building with
CONFIG_OF_SEPARATE enabled.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arm/dts/Makefile|  3 ++-
 arch/arm/dts/xilinx-versal-virt.dts  | 11 +++
 configs/xilinx_versal_virt_defconfig |  1 +
 3 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/xilinx-versal-virt.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 91302118598..b07a1b3378e 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -360,7 +360,8 @@ dtb-$(CONFIG_ARCH_ZYNQMP) += \
 dtb-$(CONFIG_ARCH_VERSAL) += \
versal-mini.dtb \
versal-mini-emmc0.dtb \
-   versal-mini-emmc1.dtb
+   versal-mini-emmc1.dtb \
+   xilinx-versal-virt.dtb
 dtb-$(CONFIG_ARCH_ZYNQMP_R5) += \
zynqmp-r5.dtb
 dtb-$(CONFIG_AM33XX) += \
diff --git a/arch/arm/dts/xilinx-versal-virt.dts 
b/arch/arm/dts/xilinx-versal-virt.dts
new file mode 100644
index 000..733e532f987
--- /dev/null
+++ b/arch/arm/dts/xilinx-versal-virt.dts
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0+ OR MIT
+/*
+ * Empty device tree for versal-virt board
+ *
+ * Copyright 2021 Google LLC
+ */
+
+/dts-v1/;
+
+/ {
+};
diff --git a/configs/xilinx_versal_virt_defconfig 
b/configs/xilinx_versal_virt_defconfig
index 11598623954..f0ec2639a38 100644
--- a/configs/xilinx_versal_virt_defconfig
+++ b/configs/xilinx_versal_virt_defconfig
@@ -7,6 +7,7 @@ CONFIG_SYS_MALLOC_F_LEN=0x10
 CONFIG_SYS_MEMTEST_START=0x
 CONFIG_SYS_MEMTEST_END=0x1000
 CONFIG_DM_GPIO=y
+CONFIG_DEFAULT_DEVICE_TREE="xilinx-versal-virt"
 CONFIG_CMD_FRU=y
 CONFIG_DEFINE_TCM_OCM_MMAP=y
 CONFIG_COUNTER_FREQUENCY=1
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 10/31] arm: octeontx: Add an empty devicetree file

2021-12-06 Thread Simon Glass
Add an empty file to prevent build errors when building with
CONFIG_OF_SEPARATE enabled.

Unfortunately there are no build instructions in the U-Boot tree to enable
a real file to be created.

Signed-off-by: Simon Glass 
---

Changes in v7:
- Use 'empty' instead of 'fake'

 arch/arm/dts/Makefile|  3 +++
 arch/arm/dts/octeontx.dts| 14 ++
 configs/octeontx2_95xx_defconfig |  1 +
 configs/octeontx2_96xx_defconfig |  1 +
 configs/octeontx_81xx_defconfig  |  1 +
 configs/octeontx_83xx_defconfig  |  1 +
 6 files changed, 21 insertions(+)
 create mode 100644 arch/arm/dts/octeontx.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index f6345988c8c..91302118598 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1142,6 +1142,9 @@ dtb-$(CONFIG_ARCH_MEDIATEK) += \
 
 dtb-$(CONFIG_XEN) += xenguest-arm64.dtb
 
+dtb-$(CONFIG_ARCH_OCTEONTX) += octeontx.dtb
+dtb-$(CONFIG_ARCH_OCTEONTX2) += octeontx.dtb
+
 dtb-$(CONFIG_TARGET_GE_BX50V3) += \
imx6q-bx50v3.dtb \
imx6q-b850v3.dtb \
diff --git a/arch/arm/dts/octeontx.dts b/arch/arm/dts/octeontx.dts
new file mode 100644
index 000..60a15f5df23
--- /dev/null
+++ b/arch/arm/dts/octeontx.dts
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Dummy devicetre file for octeontx2 boards
+ *
+ * This is required to make the board build with CONFIG OF_SEPARATE
+ * I could not find any in-tree documentation at all so this is a dummy file.
+ *
+ * Copyright 2021 Google LLC
+ */
+
+/dts-v1/;
+
+/ {
+};
diff --git a/configs/octeontx2_95xx_defconfig b/configs/octeontx2_95xx_defconfig
index e1b86a5a8b6..e3df390c94b 100644
--- a/configs/octeontx2_95xx_defconfig
+++ b/configs/octeontx2_95xx_defconfig
@@ -12,6 +12,7 @@ CONFIG_ENV_OFFSET=0xF0
 CONFIG_ENV_SECT_SIZE=0x1
 CONFIG_TARGET_OCTEONTX2_95XX=y
 CONFIG_DM_GPIO=y
+CONFIG_DEFAULT_DEVICE_TREE="octeontx"
 CONFIG_DEBUG_UART_BASE=0x87e02800
 CONFIG_DEBUG_UART_CLOCK=2400
 CONFIG_DEBUG_UART=y
diff --git a/configs/octeontx2_96xx_defconfig b/configs/octeontx2_96xx_defconfig
index ec03d959771..0478b3068a6 100644
--- a/configs/octeontx2_96xx_defconfig
+++ b/configs/octeontx2_96xx_defconfig
@@ -10,6 +10,7 @@ CONFIG_ENV_OFFSET=0xF0
 CONFIG_ENV_SECT_SIZE=0x1
 CONFIG_TARGET_OCTEONTX2_96XX=y
 CONFIG_DM_GPIO=y
+CONFIG_DEFAULT_DEVICE_TREE="octeontx"
 CONFIG_DEBUG_UART_BASE=0x87e02800
 CONFIG_DEBUG_UART_CLOCK=2400
 CONFIG_DEBUG_UART=y
diff --git a/configs/octeontx_81xx_defconfig b/configs/octeontx_81xx_defconfig
index d0728ac3c67..d871be8f812 100644
--- a/configs/octeontx_81xx_defconfig
+++ b/configs/octeontx_81xx_defconfig
@@ -12,6 +12,7 @@ CONFIG_ENV_OFFSET=0xF0
 CONFIG_ENV_SECT_SIZE=0x1
 CONFIG_TARGET_OCTEONTX_81XX=y
 CONFIG_DM_GPIO=y
+CONFIG_DEFAULT_DEVICE_TREE="octeontx"
 CONFIG_DEBUG_UART_BASE=0x87e02800
 CONFIG_DEBUG_UART_CLOCK=2400
 CONFIG_DEBUG_UART=y
diff --git a/configs/octeontx_83xx_defconfig b/configs/octeontx_83xx_defconfig
index 6c9609b0cd3..94b072bf6fa 100644
--- a/configs/octeontx_83xx_defconfig
+++ b/configs/octeontx_83xx_defconfig
@@ -10,6 +10,7 @@ CONFIG_ENV_OFFSET=0xF0
 CONFIG_ENV_SECT_SIZE=0x1
 CONFIG_TARGET_OCTEONTX_83XX=y
 CONFIG_DM_GPIO=y
+CONFIG_DEFAULT_DEVICE_TREE="octeontx"
 CONFIG_DEBUG_UART_BASE=0x87e02800
 CONFIG_DEBUG_UART_CLOCK=2400
 CONFIG_DEBUG_UART=y
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 09/31] arm: xenguest_arm64: Add a empty devicetree file

2021-12-06 Thread Simon Glass
Add an empty file to prevent build errors when building with
CONFIG_OF_SEPARATE enabled.

The build instructions in U-Boot do not provide enough detail to build a
useful devicetree, unfortunately.

Signed-off-by: Simon Glass 
---

Changes in v7:
- Use 'empty' instead of 'fake'

 arch/arm/dts/Makefile|  2 ++
 arch/arm/dts/xenguest-arm64.dts  | 15 +++
 configs/xenguest_arm64_defconfig |  2 +-
 3 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/xenguest-arm64.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index d53bae2c350..f6345988c8c 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1140,6 +1140,8 @@ dtb-$(CONFIG_ARCH_MEDIATEK) += \
mt8516-pumpkin.dtb \
mt8518-ap1-emmc.dtb
 
+dtb-$(CONFIG_XEN) += xenguest-arm64.dtb
+
 dtb-$(CONFIG_TARGET_GE_BX50V3) += \
imx6q-bx50v3.dtb \
imx6q-b850v3.dtb \
diff --git a/arch/arm/dts/xenguest-arm64.dts b/arch/arm/dts/xenguest-arm64.dts
new file mode 100644
index 000..d8734433763
--- /dev/null
+++ b/arch/arm/dts/xenguest-arm64.dts
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Empty devicetree file for xenguest_arm64
+ *
+ * This is required to make the board build with CONFIG OF_SEPARATE
+ * Build instructions at xenguest_arm64.rst are inadequate for obtaining a real
+ * devicetree.
+ *
+ * Copyright 2021 Google LLC
+ */
+
+/dts-v1/;
+
+/ {
+};
diff --git a/configs/xenguest_arm64_defconfig b/configs/xenguest_arm64_defconfig
index 8d9d9133a2e..edce34346d3 100644
--- a/configs/xenguest_arm64_defconfig
+++ b/configs/xenguest_arm64_defconfig
@@ -3,7 +3,7 @@ CONFIG_POSITION_INDEPENDENT=y
 CONFIG_TARGET_XENGUEST_ARM64=y
 CONFIG_SYS_TEXT_BASE=0x4008
 CONFIG_SYS_MALLOC_LEN=0x200
-CONFIG_SYS_MALLOC_F_LEN=0x2000
+CONFIG_DEFAULT_DEVICE_TREE="xenguest-arm64"
 CONFIG_IDENT_STRING=" xenguest"
 CONFIG_SYS_LOAD_ADDR=0x4000
 CONFIG_BOOTDELAY=10
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 04/31] arm: qemu: Add a devicetree file for qemu_arm

2021-12-06 Thread Simon Glass
This uses QEMU virt which creates its own devicetree.

Add an empty version of this file, so that we can at least build this
board when devicetrees are required.

Tested-by: Heinrich Schuchardt 
Signed-off-by: Simon Glass 
---

Changes in v7:
- Switch to using an empty file for qemu virt

Changes in v6:
- Expand the commit message based on comments

 arch/arm/dts/Makefile  |  2 ++
 arch/arm/dts/qemu-arm.dts  | 11 +++
 configs/qemu_arm_defconfig |  1 +
 3 files changed, 14 insertions(+)
 create mode 100644 arch/arm/dts/qemu-arm.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 7f622fedbda..eaad3b679cc 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1162,6 +1162,8 @@ dtb-$(CONFIG_TARGET_IMX8MM_CL_IOT_GATE_OPTEE) += 
imx8mm-cl-iot-gate-optee.dtb
 
 dtb-$(CONFIG_TARGET_EA_LPC3250DEVKITV2) += lpc3250-ea3250.dtb
 
+dtb-$(CONFIG_ARCH_QEMU) += qemu-arm.dtb
+
 targets += $(dtb-y)
 
 # Add any required device tree compiler flags here
diff --git a/arch/arm/dts/qemu-arm.dts b/arch/arm/dts/qemu-arm.dts
new file mode 100644
index 000..230c630f04f
--- /dev/null
+++ b/arch/arm/dts/qemu-arm.dts
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0+ OR MIT
+/*
+ * Empty device tree for qemu_arm
+
+ * Copyright 2021 Google LLC
+ */
+
+/dts-v1/;
+
+/ {
+};
diff --git a/configs/qemu_arm_defconfig b/configs/qemu_arm_defconfig
index d4f6d0b4373..a644a5f3e79 100644
--- a/configs/qemu_arm_defconfig
+++ b/configs/qemu_arm_defconfig
@@ -5,6 +5,7 @@ CONFIG_SYS_MALLOC_LEN=0x100
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x4
 CONFIG_ENV_SECT_SIZE=0x4
+CONFIG_DEFAULT_DEVICE_TREE="qemu-arm"
 CONFIG_TARGET_QEMU_ARM_32BIT=y
 CONFIG_DEBUG_UART_BASE=0x900
 CONFIG_DEBUG_UART_CLOCK=0
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 03/31] arm: riscv: qemu: Explain how to extract the generated dt

2021-12-06 Thread Simon Glass
QEMU currently generates a devicetree for use with U-Boot. Explain how to
obtain it.

Also explain how to merge it to produce a devicetree with the U-Boot
features included.

Signed-off-by: Simon Glass 
---

(no changes since v5)

Changes in v5:
- Merge RISC-V and ARM patches since they are similar

 doc/board/emulation/qemu-arm.rst   |  3 ++
 doc/board/emulation/qemu-riscv.rst |  3 ++
 doc/develop/devicetree/dt_qemu.rst | 48 ++
 doc/develop/devicetree/index.rst   |  1 +
 4 files changed, 55 insertions(+)
 create mode 100644 doc/develop/devicetree/dt_qemu.rst

diff --git a/doc/board/emulation/qemu-arm.rst b/doc/board/emulation/qemu-arm.rst
index 8bd7b60cdb4..ff64ec08c3e 100644
--- a/doc/board/emulation/qemu-arm.rst
+++ b/doc/board/emulation/qemu-arm.rst
@@ -21,6 +21,9 @@ The 'virt' platform provides the following as the basic 
functionality:
 
 Additionally, a number of optional peripherals can be added to the PCI bus.
 
+See :doc:`../../develop/devicetree/dt_qemu` for information on how to see
+the devicetree actually generated by QEMU.
+
 Building U-Boot
 ---
 Set the CROSS_COMPILE environment variable as usual, and run:
diff --git a/doc/board/emulation/qemu-riscv.rst 
b/doc/board/emulation/qemu-riscv.rst
index 4b8e104a215..3409fff8117 100644
--- a/doc/board/emulation/qemu-riscv.rst
+++ b/doc/board/emulation/qemu-riscv.rst
@@ -13,6 +13,9 @@ The QEMU virt machine models a generic RISC-V virtual machine 
with support for
 the VirtIO standard networking and block storage devices. It has CLINT, PLIC,
 16550A UART devices in addition to VirtIO and it also uses device-tree to pass
 configuration information to guest software. It implements RISC-V privileged
+
+See :doc:`../../develop/devicetree/dt_qemu` for information on how to see
+the devicetree actually generated by QEMU.
 architecture spec v1.10.
 
 Building U-Boot
diff --git a/doc/develop/devicetree/dt_qemu.rst 
b/doc/develop/devicetree/dt_qemu.rst
new file mode 100644
index 000..1392a2cae97
--- /dev/null
+++ b/doc/develop/devicetree/dt_qemu.rst
@@ -0,0 +1,48 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Devicetree in QEMU
+==
+
+For QEMU on ARM, RISC-V and one PPC target, the devicetree is created on the
+fly by QEMU. It is intended for use in Linux but can be used by U-Boot also,
+so long as any nodes/properties needed by U-Boot are merged in.
+
+When `CONFIG_OF_BOARD` is enabled
+
+
+Obtaining the QEMU devicetree
+-
+
+Where QEMU generates its own devicetree to pass to U-Boot tou can use
+`-dtb u-boot.dtb` to force QEMU to use U-Boot's in-tree version.
+
+To obtain the devicetree that qemu generates, add `-machine dumpdtb=qemu.dtb`,
+e.g.::
+
+qemu-system-arm -machine virt -machine dumpdtb=qemu.dtb
+
+qemu-system-aarch64 -machine virt -machine dumpdtb=qemu.dtb
+
+qemu-system-riscv64 -machine virt -machine dumpdtb=qemu.dtb
+
+
+Merging in U-Boot nodes/properties
+--
+
+Various U-Boot features require nodes and properties in the U-Boot devicetree
+and at present QEMU is unaware of these. To use these you must manually merge
+in the appropriate pieces.
+
+One way to do this is with dtc. This command runs dtc on each .dtb file in 
turn,
+to produce a text file. It drops the duplicate header on the qemu one. Then it
+joins them up and runs them through dtc to compile the output::
+
+qemu-system-arm -machine virt -machine dumpdtb=qemu.dtb
+cat  <(dtc -I dtb qemu.dtb) <(dtc -I dtb  u-boot.dtb |grep -v /dts-v1/) 
|dtc - -o merged.dtb
+
+You can then run qemu with the merged devicetree, e.g.::
+
+qemu-system-arm -machine virt -nographic -bios u-boot.bin -dtb merged.dtb
+
+Note that there seems to be a bug in some versions of qemu where the output of
+dumpdtb does not quite match what is provided to U-Boot.
diff --git a/doc/develop/devicetree/index.rst b/doc/develop/devicetree/index.rst
index b5b33dfea0f..fc2fb41b1bb 100644
--- a/doc/develop/devicetree/index.rst
+++ b/doc/develop/devicetree/index.rst
@@ -12,3 +12,4 @@ build-time and runtime configuration.
intro
control
dt_update
+   dt_qemu
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 05/31] arm: qemu: Add a devicetree file for qemu_arm64 virt

2021-12-06 Thread Simon Glass
This uses QEMU virt which creates its own devicetree.

Add an empty version of this file, so that we can at least build this
board when devicetrees are required.

Tested-by: Heinrich Schuchardt 
Signed-off-by: Simon Glass 
---

Changes in v7:
- Switch to using an empty file for qemu virt

Changes in v6:
- Expand the commit message based on comments

 arch/arm/dts/Makefile|  2 +-
 arch/arm/dts/qemu-arm64.dts  | 11 +++
 configs/qemu_arm64_defconfig |  1 +
 3 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/qemu-arm64.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index eaad3b679cc..2d92b2f940d 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1162,7 +1162,7 @@ dtb-$(CONFIG_TARGET_IMX8MM_CL_IOT_GATE_OPTEE) += 
imx8mm-cl-iot-gate-optee.dtb
 
 dtb-$(CONFIG_TARGET_EA_LPC3250DEVKITV2) += lpc3250-ea3250.dtb
 
-dtb-$(CONFIG_ARCH_QEMU) += qemu-arm.dtb
+dtb-$(CONFIG_ARCH_QEMU) += qemu-arm.dtb qemu-arm64.dtb
 
 targets += $(dtb-y)
 
diff --git a/arch/arm/dts/qemu-arm64.dts b/arch/arm/dts/qemu-arm64.dts
new file mode 100644
index 000..096b3910728
--- /dev/null
+++ b/arch/arm/dts/qemu-arm64.dts
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0+ OR MIT
+/*
+ * Empty device tree for qemu_arm64
+
+ * Copyright 2021 Google LLC
+ */
+
+/dts-v1/;
+
+/ {
+};
diff --git a/configs/qemu_arm64_defconfig b/configs/qemu_arm64_defconfig
index 02a5e940c41..a8652f871ca 100644
--- a/configs/qemu_arm64_defconfig
+++ b/configs/qemu_arm64_defconfig
@@ -8,6 +8,7 @@ CONFIG_ENV_SECT_SIZE=0x4
 CONFIG_DEBUG_UART_BASE=0x900
 CONFIG_DEBUG_UART_CLOCK=0
 CONFIG_DEBUG_UART=y
+CONFIG_DEFAULT_DEVICE_TREE="qemu-arm64"
 CONFIG_AHCI=y
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_SYS_LOAD_ADDR=0x4020
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 06/31] riscv: qemu: Split devicetree files for qemu_riscv32/64

2021-12-06 Thread Simon Glass
This uses QEMU virt which creates its own devicetree.

Copy the existing empty version of this file, so splitting the existing
qemu-virt into two, since anyone actually trying to use this will need a
different devicetree for 32- and 64-bit machines.

Tested-by: Heinrich Schuchardt 
Signed-off-by: Simon Glass 
---

Changes in v7:
- Switch to using an empty file for qemu virt
- Reword commit message

 arch/riscv/dts/Makefile   |  2 +-
 arch/riscv/dts/{qemu-virt.dts => qemu-virt32.dts} |  3 +++
 arch/riscv/dts/qemu-virt64.dts| 11 +++
 configs/qemu-riscv32_defconfig|  1 +
 configs/qemu-riscv32_smode_defconfig  |  1 +
 configs/qemu-riscv32_spl_defconfig|  2 +-
 configs/qemu-riscv64_defconfig|  1 +
 configs/qemu-riscv64_smode_defconfig  |  1 +
 configs/qemu-riscv64_spl_defconfig|  2 +-
 9 files changed, 21 insertions(+), 3 deletions(-)
 rename arch/riscv/dts/{qemu-virt.dts => qemu-virt32.dts} (94%)
 create mode 100644 arch/riscv/dts/qemu-virt64.dts

diff --git a/arch/riscv/dts/Makefile b/arch/riscv/dts/Makefile
index b6e9166767b..90d3f35e6e3 100644
--- a/arch/riscv/dts/Makefile
+++ b/arch/riscv/dts/Makefile
@@ -2,7 +2,7 @@
 
 dtb-$(CONFIG_TARGET_AX25_AE350) += ae350_32.dtb ae350_64.dtb
 dtb-$(CONFIG_TARGET_MICROCHIP_ICICLE) += microchip-mpfs-icicle-kit.dtb
-dtb-$(CONFIG_TARGET_QEMU_VIRT) += qemu-virt.dtb
+dtb-$(CONFIG_TARGET_QEMU_VIRT) += qemu-virt32.dtb qemu-virt64.dtb
 dtb-$(CONFIG_TARGET_OPENPITON_RISCV64) += openpiton-riscv64.dtb
 dtb-$(CONFIG_TARGET_SIFIVE_UNLEASHED) += hifive-unleashed-a00.dtb
 dtb-$(CONFIG_TARGET_SIFIVE_UNMATCHED) += hifive-unmatched-a00.dtb
diff --git a/arch/riscv/dts/qemu-virt.dts b/arch/riscv/dts/qemu-virt32.dts
similarity index 94%
rename from arch/riscv/dts/qemu-virt.dts
rename to arch/riscv/dts/qemu-virt32.dts
index fecff542b91..17e2f0dea41 100644
--- a/arch/riscv/dts/qemu-virt.dts
+++ b/arch/riscv/dts/qemu-virt32.dts
@@ -6,3 +6,6 @@
 /dts-v1/;
 
 #include "binman.dtsi"
+
+/ {
+};
diff --git a/arch/riscv/dts/qemu-virt64.dts b/arch/riscv/dts/qemu-virt64.dts
new file mode 100644
index 000..17e2f0dea41
--- /dev/null
+++ b/arch/riscv/dts/qemu-virt64.dts
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021, Bin Meng 
+ */
+
+/dts-v1/;
+
+#include "binman.dtsi"
+
+/ {
+};
diff --git a/configs/qemu-riscv32_defconfig b/configs/qemu-riscv32_defconfig
index 0b8cd191618..4c0f51bd2aa 100644
--- a/configs/qemu-riscv32_defconfig
+++ b/configs/qemu-riscv32_defconfig
@@ -2,6 +2,7 @@ CONFIG_RISCV=y
 CONFIG_SYS_MALLOC_LEN=0x80
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x2
+CONFIG_DEFAULT_DEVICE_TREE="qemu-virt32"
 CONFIG_TARGET_QEMU_VIRT=y
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_SYS_LOAD_ADDR=0x8020
diff --git a/configs/qemu-riscv32_smode_defconfig 
b/configs/qemu-riscv32_smode_defconfig
index 4d65104f7b4..19406080100 100644
--- a/configs/qemu-riscv32_smode_defconfig
+++ b/configs/qemu-riscv32_smode_defconfig
@@ -2,6 +2,7 @@ CONFIG_RISCV=y
 CONFIG_SYS_MALLOC_LEN=0x80
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x2
+CONFIG_DEFAULT_DEVICE_TREE="qemu-virt32"
 CONFIG_TARGET_QEMU_VIRT=y
 CONFIG_RISCV_SMODE=y
 CONFIG_DISTRO_DEFAULTS=y
diff --git a/configs/qemu-riscv32_spl_defconfig 
b/configs/qemu-riscv32_spl_defconfig
index eb64c51a214..c4422969c61 100644
--- a/configs/qemu-riscv32_spl_defconfig
+++ b/configs/qemu-riscv32_spl_defconfig
@@ -2,7 +2,7 @@ CONFIG_RISCV=y
 CONFIG_SYS_MALLOC_LEN=0x80
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x2
-CONFIG_DEFAULT_DEVICE_TREE="qemu-virt"
+CONFIG_DEFAULT_DEVICE_TREE="qemu-virt32"
 CONFIG_SPL=y
 CONFIG_TARGET_QEMU_VIRT=y
 CONFIG_RISCV_SMODE=y
diff --git a/configs/qemu-riscv64_defconfig b/configs/qemu-riscv64_defconfig
index 4faa6dad8d6..cba975d703d 100644
--- a/configs/qemu-riscv64_defconfig
+++ b/configs/qemu-riscv64_defconfig
@@ -2,6 +2,7 @@ CONFIG_RISCV=y
 CONFIG_SYS_MALLOC_LEN=0x80
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x2
+CONFIG_DEFAULT_DEVICE_TREE="qemu-virt64"
 CONFIG_TARGET_QEMU_VIRT=y
 CONFIG_ARCH_RV64I=y
 CONFIG_DISTRO_DEFAULTS=y
diff --git a/configs/qemu-riscv64_smode_defconfig 
b/configs/qemu-riscv64_smode_defconfig
index f575c127b7c..6b7771488fe 100644
--- a/configs/qemu-riscv64_smode_defconfig
+++ b/configs/qemu-riscv64_smode_defconfig
@@ -2,6 +2,7 @@ CONFIG_RISCV=y
 CONFIG_SYS_MALLOC_LEN=0x80
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x2
+CONFIG_DEFAULT_DEVICE_TREE="qemu-virt64"
 CONFIG_TARGET_QEMU_VIRT=y
 CONFIG_ARCH_RV64I=y
 CONFIG_RISCV_SMODE=y
diff --git a/configs/qemu-riscv64_spl_defconfig 
b/configs/qemu-riscv64_spl_defconfig
index 0fbdb7564c6..e02ca3a1465 100644
--- a/configs/qemu-riscv64_spl_defconfig
+++ b/configs/qemu-riscv64_spl_defconfig
@@ -2,7 +2,7 @@ CONFIG_RISCV=y
 CONFIG_SYS_MALLOC_LEN=0x80
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x2
-CONFIG_DEFAULT_DEVICE_TREE="qemu-virt"

[PATCH v7 01/31] doc: Add documentation about devicetree usage

2021-12-06 Thread Simon Glass
At present some of the ideas and techniques behind devicetree in U-Boot
are assumed, implied or unsaid. Add some documentation to cover how
devicetree is build, how it can be modified and the rules about using
the various CONFIG_OF_... options.

Signed-off-by: Simon Glass 
Reviewed-by: Marcel Ziswiler 
---
This patch attracted quite a bit of discussion here:

https://patchwork.ozlabs.org/project/uboot/patch/20210909201033.755713-4-...@chromium.org/

I have not included the text suggested by François. While I agree that
it would be useful to have an introduction in this space, I do not agree
that we should have two devicetrees or that U-Boot should not have its own
things in the devicetree, so it is not clear to me what we should actually
write.

The 'Devicetree Control in U-Boot' docs were recently merged and these
provide some base info, for now.

Changes in v7:
- Fix 'linst' typo

Changes in v6:
- Fix description of OF_BOARD so it refers just to the current state
- Explain that the 'two devicetrees' refers to two *control* devicetrees

Changes in v5:
- Bring into the OF_BOARD series
- Rebase to master and drop mention of OF_PRIOR_STAGE, since removed
- Refer to the 'control' DTB in the first paragraph
- Use QEMU instead of qemu

Changes in v3:
- Clarify the 'bug' refered to at the top
- Reword 'This means that there' paragraph to explain U-Boot-specific things
- Move to doc/develop/devicetree now that OF_CONTROL is in the docs

Changes in v2:
- Fix typos per Sean (thank you!) and a few others
- Add a 'Use of U-Boot /config node' section
- Drop mention of dm-verity since that actually uses the kernel cmdline
- Explain that OF_BOARD will still work after these changes (in
  'Once this bug is fixed...' paragraph)
- Expand a bit on the reason why the 'Current situation' is bad
- Clarify in a second place that Linux and U-Boot use the same devicetree
  in 'To be clear, while U-Boot...'
- Expand on why we should have rules for other projects in
  'Devicetree in another project'
- Add a comment as to why devicetree in U-Boot is not 'bad design'
- Reword 'in-tree U-Boot devicetree' to 'devicetree source in U-Boot'
- Rewrite 'Devicetree generated on-the-fly in another project' to cover
  points raised on v1
- Add 'Why does U-Boot have its nodes and properties?'
- Add 'Why not have two devicetrees?'

 doc/develop/devicetree/dt_update.rst | 555 +++
 doc/develop/devicetree/index.rst |   1 +
 2 files changed, 556 insertions(+)
 create mode 100644 doc/develop/devicetree/dt_update.rst

diff --git a/doc/develop/devicetree/dt_update.rst 
b/doc/develop/devicetree/dt_update.rst
new file mode 100644
index 000..e3b65f6fa66
--- /dev/null
+++ b/doc/develop/devicetree/dt_update.rst
@@ -0,0 +1,555 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Updating the devicetree
+===
+
+U-Boot uses devicetree for runtime configuration and storing required blobs or
+any other information it needs to operate. This is called the 'control'
+devicetree since it controls U-Boot. It is possible to update the control
+devicetree separately from actually building U-Boot. This provides a good 
degree
+of control and flexibility for firmware that uses U-Boot in conjunction with
+other project.
+
+There are many reasons why it is useful to modify the devicetree after building
+it:
+
+- Configuration can be changed, e.g. which UART to use
+- A serial number can be added
+- Public keys can be added to allow image verification
+- Console output can be changed (e.g. to select serial or vidconsole)
+
+This section describes how to work with devicetree to accomplish your goals.
+
+See also :doc:`../devicetree/control` for a basic summary of the available
+features.
+
+
+Devicetree source
+-
+
+Every board in U-Boot must include a devicetree sufficient to build and boot
+that board on suitable hardware (or emulation). This is specified using the
+`CONFIG DEFAULT_DEVICE_TREE` option.
+
+
+Current situation (October 2021)
+~~
+
+As an aside, at present U-Boot allows `CONFIG_DEFAULT_DEVICE_TREE` to be empty,
+e.g. if `CONFIG_OF_BOARD` is used. This has unfortunately created an enormous
+amount of confusion and some wasted effort. This was not intended. Support for
+an empty `CONFIG_DEFAULT_DEVICE_TREE` will be dropped soon.
+
+Some of the problems created are:
+
+- It is not obvious that the devicetree is coming from another project
+
+- There is no way to see even a sample devicetree for these platform in U-Boot,
+  so it is hard to know what is going on, e.g. which devices are typically
+  present
+
+- The other project may not provide a way to support U-Boot's requirements for
+  devicetree, such as the /config node. Note: On the U-Boot mailing list, this
+  was only discovered after weeks of discussion and confusion
+
+- For QEMU specifically, consulting two QEMU source files is required, for 
which
+  there are no references in U-Boot documentation. The 

[PATCH v7 02/31] arm: qemu: Mention -nographic in the docs

2021-12-06 Thread Simon Glass
Without this option QEMU appears to hang. Add it to avoid confusion.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 doc/board/emulation/qemu-arm.rst | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/doc/board/emulation/qemu-arm.rst b/doc/board/emulation/qemu-arm.rst
index 584ef0a7e15..8bd7b60cdb4 100644
--- a/doc/board/emulation/qemu-arm.rst
+++ b/doc/board/emulation/qemu-arm.rst
@@ -41,14 +41,15 @@ The minimal QEMU command line to get U-Boot up and running 
is:
 
 - For ARM::
 
-qemu-system-arm -machine virt -bios u-boot.bin
+qemu-system-arm -machine virt -nographic -bios u-boot.bin
 
 - For AArch64::
 
-qemu-system-aarch64 -machine virt -cpu cortex-a57 -bios u-boot.bin
+qemu-system-aarch64 -machine virt -nographic -cpu cortex-a57 -bios 
u-boot.bin
 
 Note that for some odd reason qemu-system-aarch64 needs to be explicitly
-told to use a 64-bit CPU or it will boot in 32-bit mode.
+told to use a 64-bit CPU or it will boot in 32-bit mode. The -nographic 
argument
+ensures that output appears on the terminal. Use Ctrl-A X to quit.
 
 Additional persistent U-boot environment support can be added as follows:
 
-- 
2.34.1.400.ga245620fadb-goog



[PATCH v7 00/31] fdt: Make OF_BOARD a boolean option

2021-12-06 Thread Simon Glass
With Ilias' efforts we have dropped OF_PRIOR_STAGE and OF_HOSTFILE so
there are only three ways to obtain a devicetree:

   - OF_SEPARATE - the normal way, where the devicetree is built and
  appended to U-Boot
   - OF_EMBED - for development purposes, the devicetree is embedded in
  the ELF file (also used for EFI)
   - OF_BOARD - the board figures it out on its own

The last one is currently set up so that no devicetree is needed at all
in the U-Boot tree. Most boards do provide one, but some don't. Some
don't even provide instructions on how to boot on the board.

The problems with this approach are documented in another patch in this
series: "doc: Add documentation about devicetree usage"

In practice, OF_BOARD is not really distinct from OF_SEPARATE. Any board
can obtain its devicetree at runtime, even it is has a devicetree built
in U-Boot. This is because U-Boot may be a second-stage bootloader and its
caller may have a better idea about the hardware available in the machine.
This is the case with a few QEMU boards, for example.

So it makes no sense to have OF_BOARD as a 'choice'. It should be an
option, available with either OF_SEPARATE or OF_EMBED. This would allow
rpi3, for example, to run with the devicetree provided by the prior
bootloader.

This series makes this change, adding various missing devicetree files
(and placeholders) to make the build work.

It also adds a run-time message showing where the devicetree came from,
as well as warnings if the board's expected flow is not being used. This
comes from the 'standard passage' series, which depends on this series.

It also provides a few qemu clean-ups discovered along the way. The
qemu-riscv64_spl problem is fixed.

Please see [2] for discussion on the v6 series.

I put Heinrich's Tested-by tag[3] for the series onto the three devicetree
patches (ARM and RISC-V) that I think it most affects. It isn't possible
to apply a tag to a whole series at present and in any case there are
changes in v7.

This series is available at u-boot-dm/ofb-working

[1] 
https://patchwork.ozlabs.org/project/uboot/patch/20210919215111.3830278-3-...@chromium.org/
[2] 
https://lore.kernel.org/u-boot/20211205133207.GW1220664@bill-the-cat/T/#mcd8c0258827fbc1bb3000b7ff9ba0929df1ddcb2
[3] 
https://lore.kernel.org/u-boot/93913911-4d20-d28f-ee04-739985184...@canonical.com/raw

Changes in v7:
- Fix 'linst' typo
- Switch to using an empty file for qemu virt
- Switch to using an empty file for qemu virt
- Switch to using an empty file for qemu virt
- Reword commit message
- Bring in files from Linux instead
- Bring in files from Linux instead
- Rewrite the commit message
- Use 'empty' instead of 'fake'
- Use 'empty' instead of 'fake'
- Switch to using an empty file for qemu virt
- Bring in files from Linux instead
- Fix 'Is' typo in commit message
- Drop FDTSRC_PASSAGE for now
- Drop FDTSRC_PASSAGE for now
- Add new patch to add a Kconfig for boards with a prior stage

Changes in v6:
- Fix description of OF_BOARD so it refers just to the current state
- Explain that the 'two devicetrees' refers to two *control* devicetrees
- Expand the commit message based on comments
- Expand the commit message based on comments

Changes in v5:
- Bring into the OF_BOARD series
- Rebase to master and drop mention of OF_PRIOR_STAGE, since removed
- Refer to the 'control' DTB in the first paragraph
- Use QEMU instead of qemu
- Merge RISC-V and ARM patches since they are similar
- Add new patches to clean up fdtdec_setup() and surrounds

Changes in v3:
- Clarify the 'bug' refered to at the top
- Reword 'This means that there' paragraph to explain U-Boot-specific things
- Move to doc/develop/devicetree now that OF_CONTROL is in the docs

Changes in v2:
- Fix typos per Sean (thank you!) and a few others
- Add a 'Use of U-Boot /config node' section
- Drop mention of dm-verity since that actually uses the kernel cmdline
- Explain that OF_BOARD will still work after these changes (in
  'Once this bug is fixed...' paragraph)
- Expand a bit on the reason why the 'Current situation' is bad
- Clarify in a second place that Linux and U-Boot use the same devicetree
  in 'To be clear, while U-Boot...'
- Expand on why we should have rules for other projects in
  'Devicetree in another project'
- Add a comment as to why devicetree in U-Boot is not 'bad design'
- Reword 'in-tree U-Boot devicetree' to 'devicetree source in U-Boot'
- Rewrite 'Devicetree generated on-the-fly in another project' to cover
  points raised on v1
- Add 'Why does U-Boot have its nodes and properties?'
- Add 'Why not have two devicetrees?'

Simon Glass (31):
  doc: Add documentation about devicetree usage
  arm: qemu: Mention -nographic in the docs
  arm: riscv: qemu: Explain how to extract the generated dt
  arm: qemu: Add a devicetree file for qemu_arm
  arm: qemu: Add a devicetree file for qemu_arm64 virt
  riscv: qemu: Split devicetree files for qemu_riscv32/64
  arm: rpi: Sync rpi dts files from Linux
  arm: vexpress: 

Re: [PATCH] imx8mq_evk: configs: add/cleanup variables for distro boot

2021-12-06 Thread Fabio Estevam
Hi Andrey,

On Mon, Dec 6, 2021 at 6:03 PM Andrey Zhizhikin
 wrote:
>
>  Add fdt_addr_r fdtfile which used by distro boot, and cleanup legacy
>  environment variables.
>
> Signed-off-by: Andrey Zhizhikin 

Reviewed-by: Fabio Estevam 


Re: [PATCH v2] imx8mq_evk: switch board to use binman for images

2021-12-06 Thread Fabio Estevam
On Mon, Dec 6, 2021 at 6:46 PM Tom Rini  wrote:

> So this platform doesn't run in to the HDMI blob problem or similar, in
> CI?

imx8mq can happily boot without the HDMI firmware.

Please note that HDMI support for i.MX8MQ in mainline is still not available.


Re: [PATCH v2] imx8mq_evk: switch board to use binman for images

2021-12-06 Thread Tom Rini
On Mon, Dec 06, 2021 at 06:38:00PM -0300, Fabio Estevam wrote:
> Hi Tom,
> 
> On Mon, Dec 6, 2021 at 6:26 PM Tom Rini  wrote:
> 
> > I believe this ends up being blocked on getting binman / CI happy with
> > the files being missing?
> 
> This patch addresses the following build warning:
> 
> = WARNING ==
> This board uses CONFIG_SPL_FIT_GENERATOR. Please migrate
> to binman instead, to avoid the proliferation of
>   UPD include/generated/dt.h
> arch-specific scripts with no tests.
>   UPD include/generated/timestamp_autogenerated.h
> 
> 
> The other issue about missing files is orthogonal to this patch and it is 
> being
> handled by Heiko's patch:
> https://www.mail-archive.com/u-boot@lists.denx.de/msg425275.html
> 
> Andrey's conversion to binman can be safely applied to 2022.01.

So this platform doesn't run in to the HDMI blob problem or similar, in
CI?

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2] imx8mq_evk: switch board to use binman for images

2021-12-06 Thread Fabio Estevam
Hi Tom,

On Mon, Dec 6, 2021 at 6:26 PM Tom Rini  wrote:

> I believe this ends up being blocked on getting binman / CI happy with
> the files being missing?

This patch addresses the following build warning:

= WARNING ==
This board uses CONFIG_SPL_FIT_GENERATOR. Please migrate
to binman instead, to avoid the proliferation of
  UPD include/generated/dt.h
arch-specific scripts with no tests.
  UPD include/generated/timestamp_autogenerated.h


The other issue about missing files is orthogonal to this patch and it is being
handled by Heiko's patch:
https://www.mail-archive.com/u-boot@lists.denx.de/msg425275.html

Andrey's conversion to binman can be safely applied to 2022.01.


Re: [PATCH v2] imx8mq_evk: switch board to use binman for images

2021-12-06 Thread Tom Rini
On Mon, Dec 06, 2021 at 06:05:50PM -0300, Fabio Estevam wrote:
> Hi Tom and Stefano,
> 
> On Fri, Dec 3, 2021 at 1:27 PM Fabio Estevam  wrote:
> >
> > Hi Andrey,
> >
> > On Fri, Dec 3, 2021 at 1:18 PM Andrey Zhizhikin
> >  wrote:
> > >
> > > Currently i.MX8MQ EVK board still targeting the old image generation
> > > approach for image generation, which relies on the FIT generator that
> > > has been dropped from the tree.
> > >
> > > Switch the board to use binman instead, which is a standard image
> > > generator now.
> > >
> > > Update board documentation to correct build command, and advise latest
> > > firmware and TF-A versions to use.
> > >
> > > NOTE: New image produced by binman does not have Signed HDMI FW support,
> > > this has been left on the side and does not interfere with the general
> > > boot flow.
> > >
> > > Tested on: [i.MX8MQ rev2.0]
> > >
> > > Signed-off-by: Andrey Zhizhikin 
> > > ---
> > >
> > > Changes in V2:
> > > - Modify binman and documentation to use single flash.bin file instead
> > >   of flash.bin+u-boot.itb combination, suggested by Fabio Estevam.
> >
> > Thanks for the rework:
> >
> > Reviewed-by: Fabio Estevam 
> 
> Please consider this one for 2022.01.

I believe this ends up being blocked on getting binman / CI happy with
the files being missing?

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2] imx8mq_evk: switch board to use binman for images

2021-12-06 Thread Fabio Estevam
Hi Tom and Stefano,

On Fri, Dec 3, 2021 at 1:27 PM Fabio Estevam  wrote:
>
> Hi Andrey,
>
> On Fri, Dec 3, 2021 at 1:18 PM Andrey Zhizhikin
>  wrote:
> >
> > Currently i.MX8MQ EVK board still targeting the old image generation
> > approach for image generation, which relies on the FIT generator that
> > has been dropped from the tree.
> >
> > Switch the board to use binman instead, which is a standard image
> > generator now.
> >
> > Update board documentation to correct build command, and advise latest
> > firmware and TF-A versions to use.
> >
> > NOTE: New image produced by binman does not have Signed HDMI FW support,
> > this has been left on the side and does not interfere with the general
> > boot flow.
> >
> > Tested on: [i.MX8MQ rev2.0]
> >
> > Signed-off-by: Andrey Zhizhikin 
> > ---
> >
> > Changes in V2:
> > - Modify binman and documentation to use single flash.bin file instead
> >   of flash.bin+u-boot.itb combination, suggested by Fabio Estevam.
>
> Thanks for the rework:
>
> Reviewed-by: Fabio Estevam 

Please consider this one for 2022.01.

Thanks


[PATCH] imx8mq_evk: configs: add/cleanup variables for distro boot

2021-12-06 Thread Andrey Zhizhikin
 Add fdt_addr_r fdtfile which used by distro boot, and cleanup legacy
 environment variables.

Signed-off-by: Andrey Zhizhikin 
---
 include/configs/imx8mq_evk.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/configs/imx8mq_evk.h b/include/configs/imx8mq_evk.h
index 49a9526d96..63539c7649 100644
--- a/include/configs/imx8mq_evk.h
+++ b/include/configs/imx8mq_evk.h
@@ -63,13 +63,13 @@
 /* Initial environment variables */
 #define CONFIG_EXTRA_ENV_SETTINGS  \
BOOTENV \
-   "scriptaddr=0x4350\0" \
-   "kernel_addr_r=0x4088\0" \
+   "scriptaddr=" __stringify(CONFIG_LOADADDR) "\0" \
+   "kernel_addr_r=" __stringify(CONFIG_LOADADDR) "\0" \
"image=Image\0" \
"console=ttymxc0,115200\0" \
-   "fdt_addr=0x4300\0" \
+   "fdt_addr_r=0x4300\0"   \
"boot_fdt=try\0" \
-   "fdt_file=imx8mq-evk.dtb\0" \
+   "fdtfile=imx8mq-evk.dtb\0" \
"initrd_addr=0x4380\0"  \
"bootm_size=0x1000\0" \
"mmcpart=" __stringify(CONFIG_SYS_MMC_IMG_LOAD_PART) "\0" \

base-commit: 558002a0f2230bedf6b38716f3ed86a92fc9010b
prerequisite-patch-id: 59faad9613725a42a9057aba206b92cf084dd1c1
-- 
2.25.1



[PATCH 2/2] ARM: dts: stm32: Add DFU support for DHCOR recovery

2021-12-06 Thread Marek Vasut
This patch configures U-Boot SPL for DHCOR SoM to permit DFU upload of
SPL and subsequent u-boot.itb for recovery or commissioning purposes.

To start U-Boot on DHCOR based board, e.g. Avenger96, proceed as follows:
- Install dfu-util on the host PC (in debian this is package 'dfu-util')

- Power off the Avenger96 board.
- Connect both USB-serial console and USB-OTG microB ports to host PC.
- Switch Avenger96 to USB boot mode -- BOOT0..2 switches all set to 0.
- Power on the Avenger96 board.
- Verify using '$ dmesg' that a new device has been detected as follows:
New USB device found, idVendor=0483, idProduct=df11, bcdDevice= 2.00
New USB device strings: Mfr=1, Product=2, SerialNumber=3
Product: DFU in HS Mode @Device ID /0x500, @Revision ID /0x
Manufacturer: STMicroelectronics

- Upload U-Boot SPL:
$ dfu-util -a 1 -D u-boot-spl.stm32
- Upload U-Boot proper:
$ dfu-util -a 0 -D u-boot.itb

- At this point, SPL will wait for user to press "Ctrl-C" on serial
  console. When ready to interact with U-Boot, press Ctrl-C to start
  the bootloader.

Signed-off-by: Marek Vasut 
Cc: Patrice Chotard 
Cc: Patrick Delaunay 
---
 arch/arm/dts/stm32mp15xx-dhcor-u-boot.dtsi | 42 ++
 configs/stm32mp15_dhcor_basic_defconfig| 14 ++--
 include/configs/stm32mp15_dh_dhsom.h   |  7 
 3 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/arch/arm/dts/stm32mp15xx-dhcor-u-boot.dtsi 
b/arch/arm/dts/stm32mp15xx-dhcor-u-boot.dtsi
index 502cd95da05..71375510b4a 100644
--- a/arch/arm/dts/stm32mp15xx-dhcor-u-boot.dtsi
+++ b/arch/arm/dts/stm32mp15xx-dhcor-u-boot.dtsi
@@ -27,6 +27,7 @@
 
  {
u-boot,dm-pre-reloc;
+   u-boot,dm-spl;
 };
 
 _pins_a {
@@ -38,6 +39,15 @@
 
  {
u-boot,dm-pre-reloc;
+   u-boot,dm-spl;
+
+   regulators {
+   u-boot,dm-spl;
+   };
+};
+
+_regulators {
+   u-boot,dm-spl;
 };
 
  {
@@ -152,3 +162,35 @@
u-boot,dm-pre-reloc;
};
 };
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+_hs {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+_port0 {
+   u-boot,dm-spl;
+};
+
+_port1 {
+   u-boot,dm-spl;
+};
+
+_io {
+   u-boot,dm-spl;
+};
+
+_usb {
+   u-boot,dm-spl;
+};
diff --git a/configs/stm32mp15_dhcor_basic_defconfig 
b/configs/stm32mp15_dhcor_basic_defconfig
index 2356de76baf..87980d2570d 100644
--- a/configs/stm32mp15_dhcor_basic_defconfig
+++ b/configs/stm32mp15_dhcor_basic_defconfig
@@ -16,6 +16,7 @@ CONFIG_DISTRO_DEFAULTS=y
 CONFIG_SYS_LOAD_ADDR=0xc200
 CONFIG_FIT=y
 CONFIG_SPL_LOAD_FIT=y
+CONFIG_SPL_LOAD_FIT_ADDRESS=0xc100
 CONFIG_SPL_FIT_SOURCE="board/dhelectronics/dh_stm32mp1/u-boot-dhcor.its"
 # CONFIG_USE_SPL_FIT_GENERATOR is not set
 CONFIG_BOOTDELAY=1
@@ -25,12 +26,17 @@ CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_SPL_LEGACY_IMAGE_SUPPORT=y
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION=y
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION=3
+CONFIG_SPL_ENV_SUPPORT=y
 CONFIG_SPL_I2C=y
 CONFIG_SPL_MTD_SUPPORT=y
 CONFIG_SPL_DM_SPI_FLASH=y
 CONFIG_SPL_POWER=y
+CONFIG_SPL_RAM_SUPPORT=y
+CONFIG_SPL_RAM_DEVICE=y
 CONFIG_SPL_SPI_FLASH_MTD=y
 CONFIG_SYS_SPI_U_BOOT_OFFS=0x8
+CONFIG_SPL_USB_GADGET=y
+CONFIG_SPL_DFU=y
 CONFIG_SYS_PROMPT="STM32MP> "
 # CONFIG_CMD_ELF is not set
 # CONFIG_CMD_EXPORTENV is not set
@@ -76,6 +82,7 @@ CONFIG_USE_ENV_SPI_MODE=y
 CONFIG_ENV_SPI_MODE=0x0
 CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_SPL_ENV_IS_NOWHERE=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_IP_DEFRAG=y
 CONFIG_TFTP_BLOCKSIZE=1536
@@ -84,7 +91,6 @@ CONFIG_SPL_BLOCK_CACHE=y
 CONFIG_DFU_MMC=y
 CONFIG_DFU_MTD=y
 CONFIG_DFU_RAM=y
-CONFIG_DFU_VIRT=y
 CONFIG_GPIO_HOG=y
 CONFIG_DM_HWSPINLOCK=y
 CONFIG_HWSPINLOCK_STM32=y
@@ -113,18 +119,20 @@ CONFIG_PHY_MICREL_KSZ90X1=y
 CONFIG_DM_ETH=y
 CONFIG_DWC_ETH_QOS=y
 CONFIG_PHY=y
+CONFIG_SPL_PHY=y
 CONFIG_PHY_STM32_USBPHYC=y
 CONFIG_PINCONF=y
 # CONFIG_SPL_PINCTRL_FULL is not set
 CONFIG_PINCTRL_STMFX=y
 CONFIG_DM_PMIC=y
-# CONFIG_SPL_PMIC_CHILDREN is not set
 CONFIG_PMIC_STPMIC1=y
 CONFIG_DM_REGULATOR=y
+CONFIG_SPL_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_REGULATOR_GPIO=y
 CONFIG_DM_REGULATOR_STM32_VREFBUF=y
 CONFIG_DM_REGULATOR_STPMIC1=y
+CONFIG_SPL_DM_REGULATOR_STPMIC1=y
 CONFIG_REMOTEPROC_STM32_COPRO=y
 CONFIG_DM_RTC=y
 CONFIG_RTC_STM32=y
@@ -136,8 +144,10 @@ CONFIG_STM32_SPI=y
 CONFIG_SYSRESET_SYSCON=y
 CONFIG_USB=y
 CONFIG_DM_USB_GADGET=y
+CONFIG_SPL_DM_USB_GADGET=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_EHCI_GENERIC=y
+CONFIG_USB_DWC2=y
 CONFIG_USB_HOST_ETHER=y
 CONFIG_USB_ETHER_ASIX=y
 CONFIG_USB_GADGET=y
diff --git a/include/configs/stm32mp15_dh_dhsom.h 
b/include/configs/stm32mp15_dh_dhsom.h
index d2fe923a33b..9e7d4b8144f 100644
--- a/include/configs/stm32mp15_dh_dhsom.h
+++ b/include/configs/stm32mp15_dh_dhsom.h
@@ -8,6 +8,13 @@
 #ifndef __CONFIG_STM32MP15_DH_DHSOM_H__
 #define __CONFIG_STM32MP15_DH_DHSOM_H__
 
+#ifdef CONFIG_SPL_BUILD
+#define 

[PATCH 1/2] arm: stm32mp: Fix USB boot device report

2021-12-06 Thread Marek Vasut
In case the SoC reports the boot device type is USB, it means the SPL was
loaded via BootROM DFU mode. Currently the spl_boot_device() returns boot
device as USB host, change it to DFU instead, so the SPL can continue the
DFU boot and load U-Boot via DFU.

Signed-off-by: Marek Vasut 
Cc: Patrice Chotard 
Cc: Patrick Delaunay 
---
 arch/arm/mach-stm32mp/spl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-stm32mp/spl.c b/arch/arm/mach-stm32mp/spl.c
index 405eff68a3b..51fe0698fab 100644
--- a/arch/arm/mach-stm32mp/spl.c
+++ b/arch/arm/mach-stm32mp/spl.c
@@ -43,7 +43,7 @@ u32 spl_boot_device(void)
case BOOT_SERIAL_UART_8:
return BOOT_DEVICE_UART;
case BOOT_SERIAL_USB_OTG:
-   return BOOT_DEVICE_USB;
+   return BOOT_DEVICE_DFU;
case BOOT_FLASH_NAND_FMC:
return BOOT_DEVICE_NAND;
case BOOT_FLASH_NOR_QSPI:
-- 
2.33.0



Re: [External] - Raspberry Pi Boot 1b / Uboot boot failure with large initramfs

2021-12-06 Thread Frederik Lotter
Hi Vincent!

On Mon, 6 Dec 2021 at 16:36, Vincent Fazio  wrote:

> Frederick
>
>
> > -Original Message-
> > From: U-Boot  On Behalf Of Frederik Lotter
> > Sent: Monday, December 6, 2021 12:55 AM
> > To: u-boot@lists.denx.de
> > Subject: [External] - Raspberry Pi Boot 1b / Uboot boot failure with
> large
> > initramfs
> >
> > Hi,
> >
> > I am facing intermittend boot failures resulting in a data abort. Boot
> log and
> > environment attached below. The uboot is built with rpi_defconfig with
> > OF_BOARD to get uboot to pass through the FDT.
> >
> > Note:
> >
> > (1) If I boot this image directly using the RPI bootloader, the kernel
> (with
> > initramfs embedded) boots fine consistently.
> >
> > (2) However, I get inconsistent failures with uboot. My gut tells me
> memory
> > is getting corrupted.
> >
> > (3) Sometimes just adding one option to the bootargs breaks the next
> boot.
> >
> > (4) It seems the FDT address changes slightly (see failed vs OK). Not
> sure if
> > this is expected from start.elf (I assume the FDT address is supplied to
> u-
> > boot).
> >
> > (5) Is the size of the image overwriting anything in u-boot? I am not
> that
> > familiar with the u-boot memory map.
> >
> > I boot using the following environment changes:
> > bootargs=bootslot=a console=ttyAMA0,115200 root=/dev/null
> > bootcmd=fatload mmc 0:1 ${kernel_addr_r}  kernel.a.img ;  bootz
> > ${kernel_addr_r} - ${fdtcontroladdr}
>
> Do you have the same problems when using ${fdt_addr}?
>

I found a patch proposal where someone suggested that ${fdtcontroladdr} and
${fdt_addr} could end up being saved in the environment (saveenv), and
causing a old value getting loaded.

This resulted me in doing two things, which fixed the issue:

(1) Remove both these environment variables (env delete) before saving

(2) Using ${fdt_addr} for bootz

Everything now works perfectly.

Would you mind clarifying the difference between ${fdtcontroladdr} and
${fdt_addr}? I got the impression I had to use ${fdtcontroladdr} with
CONFIG_OF_BOARD, but that could have been a faulty source of information.


>
> >
> > Any ideas?
> >
> > Regards,
> > Fred
> >
> > BOOT:
> >
> > DRAM:  448 MiB
> > RPI Model B rev2 (0xe)
> > MMC:   mmc@7e202000: 0
> > Loading Environment from FAT... OK
> > In:serial
> > Out:   vidconsole
> > Err:   vidconsole
> > Net:   No ethernet found.
> > starting USB...
> > Bus usb@7e98: usb dr_mode not found
> > USB DWC2
> > scanning bus usb@7e98 for devices... 3 USB Device(s) found
> >scanning usb for storage devices... 0 Storage Device(s) found Hit
> any key
> > to stop autoboot:  0
> > 70746744 bytes read in 2940 ms (22.9 MiB/s) Kernel image @ 0x08 [
> > 0x00 - 0x4378278 ] ## Flattened Device Tree blob at 1bb500e0
> >Booting using the fdt blob at 0x1bb500e0
> >Using Device Tree in place at 1bb500e0, end 1bb59ebe data abort
> > pc : [<1bf5c4ec>]  lr : [<1bf5c7c4>]
> > reloc pc : [<94ec>]lr : [<97c4>]
> > sp : 1bb4fdb8  ip : 000c fp : 0003
> > r10:   r9 : 1bb56ec0 r8 : 1bb6bad4
> > r7 :   r6 : 0008 r5 : 1bfc5874  r4 : 0400
> > r3 : 0074616d  r2 : 1bb6bad4 r1 : 0400  r0 : 1bfc5874
> > Flags: nzcv  IRQs off  FIQs off  Mode SVC_32
> > Code: e12fff1e e92d4073 e5993000 e5906060 (e5933038) Resetting CPU ...
> >
> > resetting ...
> >
> > ENV:
> >
> > arch=arm
> > baudrate=115200
> > board=rpi
> > board_name=Model B rev2
> > board_rev=0xE
> > board_rev_scheme=0
> > board_revision=0xE
> > boot_a_script=load ${devtype} ${devnum}:${distro_bootpart} ${scriptaddr}
> > ${prefix}${script}; source ${scriptaddr} boot_efi_binary=load ${devtype}
> > ${devnum}:${distro_bootpart} ${kernel_addr_r} efi/boot/bootarm.efi; if
> fdt
> > addr ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${fdt_addr_r};else
> > bootefi ${kernel_addr_r} ${fdtcontroladdr};fi boot_efi_bootmgr=if fdt
> addr
> > ${fdt_addr_r}; then bootefi bootmgr ${fdt_addr_r};else bootefi bootmgr;fi
> > boot_extlinux=sysboot ${devtype} ${devnum}:${distro_bootpart} any
> > ${scriptaddr} ${prefix}${boot_syslinux_conf} boot_net_usb_start=usb start
> > boot_prefixes=/ /boot/ boot_script_dhcp=boot.scr.uimg
> > boot_scripts=boot.scr.uimg boot.scr
> > boot_syslinux_conf=extlinux/extlinux.conf
> > boot_targets=mmc0 mmc1 usb0 pxe dhcp
> > bootargs=bootslot=a console=ttyAMA0,115200 root=/dev/null
> > bootcmd=fatload mmc 0:1 ${kernel_addr_r}  kernel.a.img ;  bootz
> > ${kernel_addr_r} - ${fdtcontroladdr} bootcmd_dhcp=devtype=dhcp; run
> > boot_net_usb_start; if dhcp ${scriptaddr} ${boot_script_dhcp}; then
> source
> > ${scriptaddr}; fi;setenv efi_fdtfile ${fdtfile}; if test -z "${fdtfile}"
> -a -n
> > "${soc}"; then setenv efi_fdtfile ${soc}-${board}${boardver}.dtb; fi;
> setenv
> > efi_old_vci ${bootp_vci};setenv efi_old_arch ${bootp_arch};setenv
> > bootp_vci PXEClient:Arch:00010:UNDI:003000;setenv bootp_arch 0xa;if dhcp
> > ${kernel_addr_r}; then tftpboot ${fdt_addr_r} dtb/${efi_fdtfile};if fdt
> addr

Re: Add BOOT LED support for Cubieboard2

2021-12-06 Thread Alexander Dahl
Hello Javad,

Am Mon, Dec 06, 2021 at 09:53:22PM +0330 schrieb Javad Rahimi:
> I'm still waiting for my email approval, Is something wrong with my message?
> 
> Hello,
> I added LED boot support for my SUN7I based Cubieboard2. I want to send a
> patch for the changes. It is my first contribution and as It has been
> mentioned in the `Patches` pages, I'm asking you before for confirmation
> sending the patch.

I'm not sure which patches pages you are talking about, but it's
usually okay to just send the patch.

Greets
Alex



[PATCH 1/3] arm: dts: apple: Update Apple M1 device trees

2021-12-06 Thread Mark Kettenis
This synchronizes the device trees with those that are in the
process of being upstreamed into Linux 5.16 or proposed for
Linux 5.17.  This includes device trees for machines that were
still missing.

There are still some differences that will hopefully be resolved
soon.

Signed-off-by: Mark Kettenis 
---
 arch/arm/Kconfig |1 +
 arch/arm/dts/Makefile|5 +-
 arch/arm/dts/t8103-j274.dts  |  122 +---
 arch/arm/dts/t8103-j293.dts  |   92 +--
 arch/arm/dts/t8103-j313.dts  |   57 ++
 arch/arm/dts/t8103-j456.dts  |   71 +++
 arch/arm/dts/t8103-j457.dts  |   59 ++
 arch/arm/dts/t8103-jxxx.dtsi |  140 +
 arch/arm/dts/t8103-pmgr.dtsi | 1136 ++
 arch/arm/dts/t8103.dtsi  |  585 +
 drivers/mailbox/Kconfig  |9 +
 drivers/mailbox/Makefile |1 +
 12 files changed, 1850 insertions(+), 428 deletions(-)
 create mode 100644 arch/arm/dts/t8103-j313.dts
 create mode 100644 arch/arm/dts/t8103-j456.dts
 create mode 100644 arch/arm/dts/t8103-j457.dts
 create mode 100644 arch/arm/dts/t8103-jxxx.dtsi
 create mode 100644 arch/arm/dts/t8103-pmgr.dtsi

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 59e031de04..0634e0c5ae 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -929,6 +929,7 @@ config ARCH_APPLE
select DM
select DM_GPIO
select DM_KEYBOARD
+   select DM_MAILBOX
select DM_SERIAL
select DM_USB
select DM_VIDEO
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 7f622fedbd..35872e1574 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -34,7 +34,10 @@ dtb-$(CONFIG_TARGET_A7Y17LTE) += exynos78x0-axy17lte.dtb
 
 dtb-$(CONFIG_ARCH_APPLE) += \
t8103-j274.dtb \
-   t8103-j293.dtb
+   t8103-j293.dtb \
+   t8103-j313.dtb \
+   t8103-j456.dtb \
+   t8103-j457.dtb
 
 dtb-$(CONFIG_ARCH_DAVINCI) += \
da850-evm.dtb \
diff --git a/arch/arm/dts/t8103-j274.dts b/arch/arm/dts/t8103-j274.dts
index aef1ae29b6..2144768147 100644
--- a/arch/arm/dts/t8103-j274.dts
+++ b/arch/arm/dts/t8103-j274.dts
@@ -10,126 +10,48 @@
 /dts-v1/;
 
 #include "t8103.dtsi"
+#include "t8103-jxxx.dtsi"
 
 / {
compatible = "apple,j274", "apple,t8103", "apple,arm-platform";
model = "Apple Mac mini (M1, 2020)";
 
aliases {
-   serial0 = 
-   ethernet0 = 
-   wifi0 = 
-   };
-
-   chosen {
-   #address-cells = <2>;
-   #size-cells = <2>;
-   ranges;
-
-   stdout-path = "serial0";
-
-   framebuffer0: framebuffer@0 {
-   compatible = "apple,simple-framebuffer", 
"simple-framebuffer";
-   reg = <0 0 0 0>; /* To be filled by loader */
-   /* Format properties will be added by loader */
-   status = "disabled";
-   };
-   };
-
-   memory@8 {
-   device_type = "memory";
-   reg = <0x8 0 0x2 0>; /* To be filled by loader */
+   ethernet0 = 
};
 };
 
- {
-   status = "okay";
-};
-
-_dart_0 {
-   status = "okay";
-};
+/*
+ * Provide labels for the USB type C ports.
+ */
 
-_dart_1 {
-   status = "okay";
+ {
+   label = "USB-C Back-left";
 };
 
-_dart_2 {
-   status = "okay";
+ {
+   label = "USB-C Back-right";
 };
 
- {
-   status = "okay";
-
-   pci0: pci@0,0 {
-   device_type = "pci";
-   reg = <0x0 0x0 0x0 0x0 0x0>;
-   pwren-gpios = < 13 0>;
-   reset-gpios = <_ap 152 0>;
-   max-link-speed = <2>;
-
-   #address-cells = <3>;
-   #size-cells = <2>;
-   ranges;
-   };
-
-   pci1: pci@1,0 {
-   device_type = "pci";
-   reg = <0x800 0x0 0x0 0x0 0x0>;
-   reset-gpios = <_ap 153 0>;
-   max-link-speed = <2>;
-
-   #address-cells = <3>;
-   #size-cells = <2>;
-   ranges;
-   };
-
-   pci2: pci@2,0 {
-   device_type = "pci";
-   reg = <0x1000 0x0 0x0 0x0 0x0>;
-   reset-gpios = <_ap 33 0>;
-   max-link-speed = <1>;
+/*
+ * Force the bus number assignments so that we can declare some of the
+ * on-board devices and properties that are populated by the bootloader
+ * (such as MAC addresses).
+ */
 
-   #address-cells = <3>;
-   #size-cells = <2>;
-   ranges;
-   };
+ {
+   bus-range = <2 2>;
 };
 
- {
-   wifi0: network@0,0 {
-   reg = <0x1 0x0 0x0 0x0 0x0>;
-   local-mac-address = [00 00 00 00 00 00];
-   };
-};
-
- {
-   eth0: ethernet@0,0 {
+ {
+   bus-range = <3 3>;
+   ethernet0: ethernet@0,0 {
reg = <0x3 0x0 0x0 0x0 0x0>;
-   local-mac-address = [00 00 00 00 00 00];
+   /* To be 

[PATCH 3/3] power: domain: Add Apple pmgr driver

2021-12-06 Thread Mark Kettenis
This driver supports power domains for the power management
controller found on Apple SoCs.

Signed-off-by: Mark Kettenis 
---
 arch/arm/Kconfig  |   3 +
 drivers/power/domain/Kconfig  |   8 +++
 drivers/power/domain/Makefile |   1 +
 drivers/power/domain/apple-pmgr.c | 113 ++
 4 files changed, 125 insertions(+)
 create mode 100644 drivers/power/domain/apple-pmgr.c

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 0634e0c5ae..0b320385a6 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -939,6 +939,9 @@ config ARCH_APPLE
select OF_BOARD
select PINCTRL
select POSITION_INDEPENDENT
+   select POWER_DOMAIN
+   select REGMAP
+   select SYSCON
select SYSRESET
select SYSRESET_WATCHDOG
select SYSRESET_WATCHDOG_AUTO
diff --git a/drivers/power/domain/Kconfig b/drivers/power/domain/Kconfig
index 99b3f9ae71..6ef7a3b3a7 100644
--- a/drivers/power/domain/Kconfig
+++ b/drivers/power/domain/Kconfig
@@ -9,6 +9,14 @@ config POWER_DOMAIN
  domains). This may be used to save power. This API provides the
  means to control such power management hardware.
 
+config APPLE_PMGR_POWER_DOMAIN
+   bool "Enable the Apple PMGR power domain driver"
+   depends on POWER_DOMAIN
+   default y if ARCH_APPLE
+   help
+ Enable support for manipulating the Apple M1 power domains via
+ MMIO mapped registers.
+
 config BCM6328_POWER_DOMAIN
bool "Enable the BCM6328 power domain driver"
depends on POWER_DOMAIN && ARCH_BMIPS
diff --git a/drivers/power/domain/Makefile b/drivers/power/domain/Makefile
index 3d1e5f073c..530ae35671 100644
--- a/drivers/power/domain/Makefile
+++ b/drivers/power/domain/Makefile
@@ -4,6 +4,7 @@
 #
 
 obj-$(CONFIG_$(SPL_)POWER_DOMAIN) += power-domain-uclass.o
+obj-$(CONFIG_APPLE_PMGR_POWER_DOMAIN) += apple-pmgr.o
 obj-$(CONFIG_BCM6328_POWER_DOMAIN) += bcm6328-power-domain.o
 obj-$(CONFIG_IMX8_POWER_DOMAIN) += imx8-power-domain-legacy.o 
imx8-power-domain.o
 obj-$(CONFIG_IMX8M_POWER_DOMAIN) += imx8m-power-domain.o
diff --git a/drivers/power/domain/apple-pmgr.c 
b/drivers/power/domain/apple-pmgr.c
new file mode 100644
index 00..08a30c8ebf
--- /dev/null
+++ b/drivers/power/domain/apple-pmgr.c
@@ -0,0 +1,113 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021 Mark Kettenis 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define APPLE_PMGR_PS_TARGET   GENMASK(3, 0)
+#define APPLE_PMGR_PS_ACTUAL   GENMASK(7, 4)
+
+#define APPLE_PMGR_PS_ACTIVE   0xf
+#define APPLE_PMGR_PS_PWRGATE  0x0
+
+#define APPLE_PMGR_PS_SET_TIMEOUT  100
+
+struct apple_pmgr_priv {
+   struct regmap *regmap;
+   u32 offset;
+};
+
+static int apple_pmgr_request(struct power_domain *power_domain)
+{
+   return 0;
+}
+
+static int apple_pmgr_rfree(struct power_domain *power_domain)
+{
+   return 0;
+}
+
+static int apple_pmgr_ps_set(struct power_domain *power_domain, u32 pstate)
+{
+   struct apple_pmgr_priv *priv = dev_get_priv(power_domain->dev);
+   uint reg;
+
+   regmap_update_bits(priv->regmap, priv->offset, APPLE_PMGR_PS_TARGET,
+  FIELD_PREP(APPLE_PMGR_PS_TARGET, pstate));
+
+   return regmap_read_poll_timeout(
+   priv->regmap, priv->offset, reg,
+   (FIELD_GET(APPLE_PMGR_PS_ACTUAL, reg) == pstate), 1,
+   APPLE_PMGR_PS_SET_TIMEOUT);
+}
+
+static int apple_pmgr_on(struct power_domain *power_domain)
+{
+   return apple_pmgr_ps_set(power_domain, APPLE_PMGR_PS_ACTIVE);
+}
+
+static int apple_pmgr_off(struct power_domain *power_domain)
+{
+   return 0;
+}
+
+static int apple_pmgr_of_xlate(struct power_domain *power_domain,
+  struct ofnode_phandle_args *args)
+{
+   if (args->args_count != 0) {
+   debug("Invalid args_count: %d\n", args->args_count);
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static const struct udevice_id apple_pmgr_ids[] = {
+   { .compatible = "apple,pmgr-pwrstate" },
+   { /* sentinel */ }
+};
+
+static int apple_pmgr_probe(struct udevice *dev)
+{
+   struct apple_pmgr_priv *priv = dev_get_priv(dev);
+   int ret;
+
+   ret = dev_power_domain_on(dev);
+   if (ret)
+   return ret;
+
+   priv->regmap = syscon_get_regmap(dev->parent);
+   if (IS_ERR(priv->regmap))
+   return PTR_ERR(priv->regmap);
+
+   ret = dev_read_u32(dev, "reg", >offset);
+   if (ret < 0)
+   return ret;
+
+   return 0;
+}
+
+struct power_domain_ops apple_pmgr_ops = {
+   .request = apple_pmgr_request,
+   .rfree = apple_pmgr_rfree,
+   .on = apple_pmgr_on,
+   .off = apple_pmgr_off,
+   .of_xlate = apple_pmgr_of_xlate,
+};
+
+U_BOOT_DRIVER(apple_pmgr) = {
+   .name = "apple_pmgr",
+   .id = UCLASS_POWER_DOMAIN,
+   .of_match = 

[PATCH 2/3] arm: dts: apple: Add u-boot,dm-pre-reloc properties

2021-12-06 Thread Mark Kettenis
These are necessary to make sure the power domains needed for the
serial console are availble in the pre-relocation phase.

Signed-off-by: Mark Kettenis 
---
 arch/arm/dts/t8103-j274-u-boot.dtsi |  1 +
 arch/arm/dts/t8103-j293-u-boot.dtsi |  1 +
 arch/arm/dts/t8103-j313-u-boot.dtsi |  1 +
 arch/arm/dts/t8103-j456-u-boot.dtsi |  1 +
 arch/arm/dts/t8103-j457-u-boot.dtsi |  1 +
 arch/arm/dts/t8103-u-boot.dtsi  | 25 +
 6 files changed, 30 insertions(+)
 create mode 100644 arch/arm/dts/t8103-j274-u-boot.dtsi
 create mode 100644 arch/arm/dts/t8103-j293-u-boot.dtsi
 create mode 100644 arch/arm/dts/t8103-j313-u-boot.dtsi
 create mode 100644 arch/arm/dts/t8103-j456-u-boot.dtsi
 create mode 100644 arch/arm/dts/t8103-j457-u-boot.dtsi
 create mode 100644 arch/arm/dts/t8103-u-boot.dtsi

diff --git a/arch/arm/dts/t8103-j274-u-boot.dtsi 
b/arch/arm/dts/t8103-j274-u-boot.dtsi
new file mode 100644
index 00..6c8dd5a56f
--- /dev/null
+++ b/arch/arm/dts/t8103-j274-u-boot.dtsi
@@ -0,0 +1 @@
+#include "t8103-u-boot.dtsi"
diff --git a/arch/arm/dts/t8103-j293-u-boot.dtsi 
b/arch/arm/dts/t8103-j293-u-boot.dtsi
new file mode 100644
index 00..6c8dd5a56f
--- /dev/null
+++ b/arch/arm/dts/t8103-j293-u-boot.dtsi
@@ -0,0 +1 @@
+#include "t8103-u-boot.dtsi"
diff --git a/arch/arm/dts/t8103-j313-u-boot.dtsi 
b/arch/arm/dts/t8103-j313-u-boot.dtsi
new file mode 100644
index 00..6c8dd5a56f
--- /dev/null
+++ b/arch/arm/dts/t8103-j313-u-boot.dtsi
@@ -0,0 +1 @@
+#include "t8103-u-boot.dtsi"
diff --git a/arch/arm/dts/t8103-j456-u-boot.dtsi 
b/arch/arm/dts/t8103-j456-u-boot.dtsi
new file mode 100644
index 00..6c8dd5a56f
--- /dev/null
+++ b/arch/arm/dts/t8103-j456-u-boot.dtsi
@@ -0,0 +1 @@
+#include "t8103-u-boot.dtsi"
diff --git a/arch/arm/dts/t8103-j457-u-boot.dtsi 
b/arch/arm/dts/t8103-j457-u-boot.dtsi
new file mode 100644
index 00..6c8dd5a56f
--- /dev/null
+++ b/arch/arm/dts/t8103-j457-u-boot.dtsi
@@ -0,0 +1 @@
+#include "t8103-u-boot.dtsi"
diff --git a/arch/arm/dts/t8103-u-boot.dtsi b/arch/arm/dts/t8103-u-boot.dtsi
new file mode 100644
index 00..43f552979d
--- /dev/null
+++ b/arch/arm/dts/t8103-u-boot.dtsi
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0+ OR MIT
+
+ {
+   u-boot,dm-pre-reloc;
+};
+
+ {
+   u-boot,dm-pre-reloc;
+};
+
+_sio_busif {
+   u-boot,dm-pre-reloc;
+};
+
+_sio {
+   u-boot,dm-pre-reloc;
+};
+
+_uart_p {
+   u-boot,dm-pre-reloc;
+};
+
+_uart0 {
+   u-boot,dm-pre-reloc;
+};
-- 
2.34.1



[PATCH 0/3] Apple M1 power management controller support

2021-12-06 Thread Mark Kettenis
This series adds support for the power management controller found on
Apple SoCs based on the device tree bindings submitted to upstream
Linux.  This is needed to enable power domains for devices that
haven't been enabled by earlier boot stages.


Mark Kettenis (3):
  arm: dts: apple: Update Apple M1 device trees
  arm: dts: apple: Add u-boot,dm-pre-reloc properties
  power: domain: Add Apple pmgr driver

 arch/arm/Kconfig|4 +
 arch/arm/dts/Makefile   |5 +-
 arch/arm/dts/t8103-j274-u-boot.dtsi |1 +
 arch/arm/dts/t8103-j274.dts |  122 +--
 arch/arm/dts/t8103-j293-u-boot.dtsi |1 +
 arch/arm/dts/t8103-j293.dts |   92 +--
 arch/arm/dts/t8103-j313-u-boot.dtsi |1 +
 arch/arm/dts/t8103-j313.dts |   57 ++
 arch/arm/dts/t8103-j456-u-boot.dtsi |1 +
 arch/arm/dts/t8103-j456.dts |   71 ++
 arch/arm/dts/t8103-j457-u-boot.dtsi |1 +
 arch/arm/dts/t8103-j457.dts |   59 ++
 arch/arm/dts/t8103-jxxx.dtsi|  140 
 arch/arm/dts/t8103-pmgr.dtsi| 1136 +++
 arch/arm/dts/t8103-u-boot.dtsi  |   25 +
 arch/arm/dts/t8103.dtsi |  585 +++---
 drivers/mailbox/Kconfig |9 +
 drivers/mailbox/Makefile|1 +
 drivers/power/domain/Kconfig|8 +
 drivers/power/domain/Makefile   |1 +
 drivers/power/domain/apple-pmgr.c   |  113 +++
 21 files changed, 2005 insertions(+), 428 deletions(-)
 create mode 100644 arch/arm/dts/t8103-j274-u-boot.dtsi
 create mode 100644 arch/arm/dts/t8103-j293-u-boot.dtsi
 create mode 100644 arch/arm/dts/t8103-j313-u-boot.dtsi
 create mode 100644 arch/arm/dts/t8103-j313.dts
 create mode 100644 arch/arm/dts/t8103-j456-u-boot.dtsi
 create mode 100644 arch/arm/dts/t8103-j456.dts
 create mode 100644 arch/arm/dts/t8103-j457-u-boot.dtsi
 create mode 100644 arch/arm/dts/t8103-j457.dts
 create mode 100644 arch/arm/dts/t8103-jxxx.dtsi
 create mode 100644 arch/arm/dts/t8103-pmgr.dtsi
 create mode 100644 arch/arm/dts/t8103-u-boot.dtsi
 create mode 100644 drivers/power/domain/apple-pmgr.c

-- 
2.34.1



Re: [PATCH v6 24/25] fdt: Drop remaining preprocessor macros in fdtdec_setup()

2021-12-06 Thread Ilias Apalodimas
Hi Simon,

On Thu, 2 Dec 2021 at 18:00, Simon Glass  wrote:
>
> We only have two choices for obtaining the devicetree. Simplify the code
> to make that clear.
>
> Signed-off-by: Simon Glass 
> ---
>
> (no changes since v1)
>
>  lib/fdtdec.c | 20 +++-
>  1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/lib/fdtdec.c b/lib/fdtdec.c
> index 5b31064cee2..a7f62123a94 100644
> --- a/lib/fdtdec.c
> +++ b/lib/fdtdec.c
> @@ -1624,15 +1624,17 @@ static void setup_multi_dtb_fit(void)
>  int fdtdec_setup(void)
>  {
> int ret;
> -#ifdef CONFIG_OF_EMBED
> -   /* Get a pointer to the FDT */
> -   gd->fdt_blob = dtb_dt_embedded();
> -#elif defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
> -   /* Allow the board to override the fdt address. */
> -   gd->fdt_blob = board_fdt_blob_setup();
> -   if (ret)
> -   return ret;
> -#endif
> +
> +   /* The devicetree is typically appended to U-Boot */
> +   if (IS_ENABLED(CONFIG_OF_SEPARATE) || IS_ENABLED(CONFIG_OF_BOARD)) {
> +   /* Allow the board to override the fdt address. */
> +   gd->fdt_blob = board_fdt_blob_setup();
> +   if (ret)
> +   return ret;
> +   } else { /* embed dtb in ELF file for testing / development */
> +   gd->fdt_blob = dtb_dt_embedded();
> +   }
> +
> if (!IS_ENABLED(CONFIG_SPL_BUILD)) {
> /* Allow the early environment to override the fdt address */
> gd->fdt_blob = map_sysmem(env_get_ulong("fdtcontroladdr", 16,
> --
> 2.34.0.rc2.393.gf8c9666880-goog
>

In case you need to resend this can you change the commit message a bit?
This doesn't really simplify the logic, just replaces ifdefs with IS_ENABLED

Other than that
Reviewed-by: Ilias Apalodimas 


  1   2   >