[v6 07/18] arm: socfpga: Add secure register access helper functions for SoC 64bits

2020-12-23 Thread Siew Chin Lim
These secure register access functions allow U-Boot proper running
at EL2 (non-secure) to access System Manager's secure registers
by calling the ATF's PSCI runtime services (EL3/secure).

Signed-off-by: Siew Chin Lim 

---
v5
---
Return error code instead of hang the system if fail to access
the secure register.

---
v6
---
Directly return 'ret' after SMC call in write and update function.
---
 arch/arm/mach-socfpga/Makefile |  1 +
 .../mach-socfpga/include/mach/secure_reg_helper.h  | 19 +
 arch/arm/mach-socfpga/secure_reg_helper.c  | 91 ++
 3 files changed, 111 insertions(+)
 create mode 100644 arch/arm/mach-socfpga/include/mach/secure_reg_helper.h
 create mode 100644 arch/arm/mach-socfpga/secure_reg_helper.c

diff --git a/arch/arm/mach-socfpga/Makefile b/arch/arm/mach-socfpga/Makefile
index 0b05283a7a..82b681d870 100644
--- a/arch/arm/mach-socfpga/Makefile
+++ b/arch/arm/mach-socfpga/Makefile
@@ -73,6 +73,7 @@ obj-y += firewall.o
 obj-y  += spl_agilex.o
 endif
 else
+obj-$(CONFIG_SPL_ATF) += secure_reg_helper.o
 obj-$(CONFIG_SPL_ATF) += smc_api.o
 endif
 
diff --git a/arch/arm/mach-socfpga/include/mach/secure_reg_helper.h 
b/arch/arm/mach-socfpga/include/mach/secure_reg_helper.h
new file mode 100644
index 00..d5a11122c7
--- /dev/null
+++ b/arch/arm/mach-socfpga/include/mach/secure_reg_helper.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2020 Intel Corporation 
+ *
+ */
+
+#ifndef_SECURE_REG_HELPER_H_
+#define_SECURE_REG_HELPER_H_
+
+#define SOCFPGA_SECURE_REG_SYSMGR_SOC64_SDMMC 1
+#define SOCFPGA_SECURE_REG_SYSMGR_SOC64_EMAC0 2
+#define SOCFPGA_SECURE_REG_SYSMGR_SOC64_EMAC1 3
+#define SOCFPGA_SECURE_REG_SYSMGR_SOC64_EMAC2 4
+
+int socfpga_secure_reg_read32(u32 id, u32 *val);
+int socfpga_secure_reg_write32(u32 id, u32 val);
+int socfpga_secure_reg_update32(u32 id, u32 mask, u32 val);
+
+#endif /* _SECURE_REG_HELPER_H_ */
diff --git a/arch/arm/mach-socfpga/secure_reg_helper.c 
b/arch/arm/mach-socfpga/secure_reg_helper.c
new file mode 100644
index 00..816006cb5a
--- /dev/null
+++ b/arch/arm/mach-socfpga/secure_reg_helper.c
@@ -0,0 +1,91 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Intel Corporation 
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int socfpga_secure_convert_reg_id_to_addr(u32 id, phys_addr_t *reg_addr)
+{
+   switch (id) {
+   case SOCFPGA_SECURE_REG_SYSMGR_SOC64_SDMMC:
+   *reg_addr = socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SDMMC;
+   break;
+   case SOCFPGA_SECURE_REG_SYSMGR_SOC64_EMAC0:
+   *reg_addr = socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC0;
+   break;
+   case SOCFPGA_SECURE_REG_SYSMGR_SOC64_EMAC1:
+   *reg_addr = socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC1;
+   break;
+   case SOCFPGA_SECURE_REG_SYSMGR_SOC64_EMAC2:
+   *reg_addr = socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC2;
+   break;
+   default:
+   return -EADDRNOTAVAIL;
+   }
+   return 0;
+}
+
+int socfpga_secure_reg_read32(u32 id, u32 *val)
+{
+   int ret;
+   u64 ret_arg;
+   u64 args[1];
+
+   phys_addr_t reg_addr;
+   ret = socfpga_secure_convert_reg_id_to_addr(id, ®_addr);
+   if (ret)
+   return ret;
+
+   args[0] = (u64)reg_addr;
+   ret = invoke_smc(INTEL_SIP_SMC_REG_READ, args, 1, &ret_arg, 1);
+   if (ret)
+   return ret;
+
+   *val = (u32)ret_arg;
+
+   return 0;
+}
+
+int socfpga_secure_reg_write32(u32 id, u32 val)
+{
+   int ret;
+   u64 args[2];
+
+   phys_addr_t reg_addr;
+   ret = socfpga_secure_convert_reg_id_to_addr(id, ®_addr);
+   if (ret)
+   return ret;
+
+   args[0] = (u64)reg_addr;
+   args[1] = val;
+   ret = invoke_smc(INTEL_SIP_SMC_REG_WRITE, args, 2, NULL, 0);
+   return ret;
+}
+
+int socfpga_secure_reg_update32(u32 id, u32 mask, u32 val)
+{
+   int ret;
+   u64 args[3];
+
+   phys_addr_t reg_addr;
+   ret = socfpga_secure_convert_reg_id_to_addr(id, ®_addr);
+   if (ret)
+   return ret;
+
+   args[0] = (u64)reg_addr;
+   args[1] = mask;
+   args[2] = val;
+   ret = invoke_smc(INTEL_SIP_SMC_REG_UPDATE, args, 3, NULL, 0);
+   return ret;
+}
-- 
2.13.0



[v6 06/18] arm: socfpga: soc64: Define SMC function identifiers for PSCI SiP services

2020-12-23 Thread Siew Chin Lim
From: Chee Hong Ang 

This header file defines the Secure Monitor Call (SMC) message
protocol for ATF (BL31) PSCI runtime services. It includes all
the PSCI SiP function identifiers for the secure runtime services
provided by ATF. The secure runtime services include System Manager's
registers access, 2nd phase bitstream FPGA reconfiguration, Remote
System Update (RSU) and etc.

Signed-off-by: Chee Hong Ang 
Signed-off-by: Siew Chin Lim 
---
 include/linux/intel-smc.h | 573 ++
 1 file changed, 573 insertions(+)
 create mode 100644 include/linux/intel-smc.h

diff --git a/include/linux/intel-smc.h b/include/linux/intel-smc.h
new file mode 100644
index 00..cacb410691
--- /dev/null
+++ b/include/linux/intel-smc.h
@@ -0,0 +1,573 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2017-2018, Intel Corporation
+ */
+
+#ifndef __INTEL_SMC_H
+#define __INTEL_SMC_H
+
+#include 
+#include 
+
+/*
+ * This file defines the Secure Monitor Call (SMC) message protocol used for
+ * service layer driver in normal world (EL1) to communicate with secure
+ * monitor software in Secure Monitor Exception Level 3 (EL3).
+ *
+ * This file is shared with secure firmware (FW) which is out of u-boot tree.
+ *
+ * An ARM SMC instruction takes a function identifier and up to 6 64-bit
+ * register values as arguments, and can return up to 4 64-bit register
+ * values. The operation of the secure monitor is determined by the parameter
+ * values passed in through registers.
+
+ * EL1 and EL3 communicates pointer as physical address rather than the
+ * virtual address.
+ */
+
+/*
+ * Functions specified by ARM SMC Calling convention:
+ *
+ * FAST call executes atomic operations, returns when the requested operation
+ * has completed.
+ * STD call starts a operation which can be preempted by a non-secure
+ * interrupt. The call can return before the requested operation has
+ * completed.
+ *
+ * a0..a7 is used as register names in the descriptions below, on arm32
+ * that translates to r0..r7 and on arm64 to w0..w7.
+ */
+
+#define INTEL_SIP_SMC_STD_CALL_VAL(func_num) \
+   ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_64, \
+   ARM_SMCCC_OWNER_SIP, (func_num))
+
+#define INTEL_SIP_SMC_FAST_CALL_VAL(func_num) \
+   ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64, \
+   ARM_SMCCC_OWNER_SIP, (func_num))
+
+/*
+ * Return values in INTEL_SIP_SMC_* call
+ *
+ * INTEL_SIP_SMC_RETURN_UNKNOWN_FUNCTION:
+ * Secure monitor software doesn't recognize the request.
+ *
+ * INTEL_SIP_SMC_STATUS_OK:
+ * SMC call completed successfully,
+ * In case of FPGA configuration write operation, it means secure monitor
+ * software can accept the next chunk of FPGA configuration data.
+ *
+ * INTEL_SIP_SMC_STATUS_BUSY:
+ * In case of FPGA configuration write operation, it means secure monitor
+ * software is still processing previous data & can't accept the next chunk
+ * of data. Service driver needs to issue
+ * INTEL_SIP_SMC_FPGA_CONFIG_COMPLETED_WRITE call to query the
+ * completed block(s).
+ *
+ * INTEL_SIP_SMC_STATUS_ERROR:
+ * There is error during the SMC call process.
+ *
+ * INTEL_SIP_SMC_REG_ERROR:
+ * There is error during a read or write operation of the protected
+ * registers.
+ */
+#define INTEL_SIP_SMC_RETURN_UNKNOWN_FUNCTION  0x
+#define INTEL_SIP_SMC_STATUS_OK0x0
+#define INTEL_SIP_SMC_STATUS_BUSY  0x1
+#define INTEL_SIP_SMC_STATUS_REJECTED  0x2
+#define INTEL_SIP_SMC_STATUS_ERROR 0x4
+#define INTEL_SIP_SMC_REG_ERROR0x5
+#define INTEL_SIP_SMC_RSU_ERROR0x7
+
+/*
+ * Request INTEL_SIP_SMC_FPGA_CONFIG_START
+ *
+ * Sync call used by service driver at EL1 to request the FPGA in EL3 to
+ * be prepare to receive a new configuration.
+ *
+ * Call register usage:
+ * a0: INTEL_SIP_SMC_FPGA_CONFIG_START.
+ * a1: flag for full or partial configuration
+ *0 full reconfiguration.
+ *1 partial reconfiguration.
+ * a2-7: not used.
+ *
+ * Return status:
+ * a0: INTEL_SIP_SMC_STATUS_OK, or INTEL_SIP_SMC_STATUS_ERROR.
+ * a1-3: not used.
+ */
+#define INTEL_SIP_SMC_FUNCID_FPGA_CONFIG_START 1
+#define INTEL_SIP_SMC_FPGA_CONFIG_START \
+   INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_FPGA_CONFIG_START)
+
+/*
+ * Request INTEL_SIP_SMC_FPGA_CONFIG_WRITE
+ *
+ * Async call used by service driver at EL1 to provide FPGA configuration data
+ * to secure world.
+ *
+ * Call register usage:
+ * a0: INTEL_SIP_SMC_FPGA_CONFIG_WRITE.
+ * a1: 64bit physical address of the configuration data memory block
+ * a2: Size of configuration data block.
+ * a3-7: not used.
+ *
+ * Return status:
+ * a0: INTEL_SIP_SMC_STATUS_OK, INTEL_SIP_SMC_STATUS_BUSY,
+ * INTEL_SIP_SMC_STATUS_REJECTED or INTEL_SIP_SMC_STATUS_ERROR.
+ * a1: 64bit physical address of 1st completed memory block if any completed
+ * block, o

[v6 05/18] arm: socfpga: soc64: Add SMC helper function for Intel SOCFPGA (64bits)

2020-12-23 Thread Siew Chin Lim
From: Chee Hong Ang 

invoke_smc() allow U-Boot proper running in non-secure mode (EL2)
to invoke SMC call to ATF's PSCI runtime services such as
System Manager's registers access, 2nd phase bitstream FPGA
reconfiguration, Remote System Update (RSU) and etc.

smc_send_mailbox() is a send mailbox command helper function which invokes
the ATF's PSCI runtime service (function ID: INTEL_SIP_SMC_MBOX_SEND_CMD)
to send mailbox messages to Secure Device Manager (SDM).

Signed-off-by: Chee Hong Ang 
---
 arch/arm/mach-socfpga/Makefile   |  2 +
 arch/arm/mach-socfpga/include/mach/smc_api.h | 13 +++
 arch/arm/mach-socfpga/smc_api.c  | 56 
 3 files changed, 71 insertions(+)
 create mode 100644 arch/arm/mach-socfpga/include/mach/smc_api.h
 create mode 100644 arch/arm/mach-socfpga/smc_api.c

diff --git a/arch/arm/mach-socfpga/Makefile b/arch/arm/mach-socfpga/Makefile
index c63162a5c6..0b05283a7a 100644
--- a/arch/arm/mach-socfpga/Makefile
+++ b/arch/arm/mach-socfpga/Makefile
@@ -72,6 +72,8 @@ ifdef CONFIG_TARGET_SOCFPGA_AGILEX
 obj-y  += firewall.o
 obj-y  += spl_agilex.o
 endif
+else
+obj-$(CONFIG_SPL_ATF) += smc_api.o
 endif
 
 ifdef CONFIG_TARGET_SOCFPGA_GEN5
diff --git a/arch/arm/mach-socfpga/include/mach/smc_api.h 
b/arch/arm/mach-socfpga/include/mach/smc_api.h
new file mode 100644
index 00..bbefdd8dd9
--- /dev/null
+++ b/arch/arm/mach-socfpga/include/mach/smc_api.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2020 Intel Corporation
+ */
+
+#ifndef _SMC_API_H_
+#define _SMC_API_H_
+
+int invoke_smc(u32 func_id, u64 *args, int arg_len, u64 *ret_arg, int ret_len);
+int smc_send_mailbox(u32 cmd, u32 len, u32 *arg, u8 urgent, u32 *resp_buf_len,
+u32 *resp_buf);
+
+#endif /* _SMC_API_H_ */
diff --git a/arch/arm/mach-socfpga/smc_api.c b/arch/arm/mach-socfpga/smc_api.c
new file mode 100644
index 00..085daba162
--- /dev/null
+++ b/arch/arm/mach-socfpga/smc_api.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Intel Corporation 
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+int invoke_smc(u32 func_id, u64 *args, int arg_len, u64 *ret_arg, int ret_len)
+{
+   struct pt_regs regs;
+
+   memset(®s, 0, sizeof(regs));
+   regs.regs[0] = func_id;
+
+   if (args)
+   memcpy(®s.regs[1], args, arg_len * sizeof(*args));
+
+   smc_call(®s);
+
+   if (ret_arg)
+   memcpy(ret_arg, ®s.regs[1], ret_len * sizeof(*ret_arg));
+
+   return regs.regs[0];
+}
+
+int smc_send_mailbox(u32 cmd, u32 len, u32 *arg, u8 urgent, u32 *resp_buf_len,
+u32 *resp_buf)
+{
+   int ret;
+   u64 args[6];
+   u64 resp[3];
+
+   args[0] = cmd;
+   args[1] = (u64)arg;
+   args[2] = len;
+   args[3] = urgent;
+   args[4] = (u64)resp_buf;
+   if (resp_buf_len)
+   args[5] = *resp_buf_len;
+   else
+   args[5] = 0;
+
+   ret = invoke_smc(INTEL_SIP_SMC_MBOX_SEND_CMD, args, ARRAY_SIZE(args),
+resp, ARRAY_SIZE(resp));
+
+   if (ret == INTEL_SIP_SMC_STATUS_OK && resp_buf && resp_buf_len) {
+   if (!resp[0])
+   *resp_buf_len = resp[1];
+   }
+
+   return (int)resp[0];
+}
-- 
2.13.0



[v6 04/18] arm: socfpga: Disable "spin-table" method for booting Linux

2020-12-23 Thread Siew Chin Lim
From: Chee Hong Ang 

Standard PSCI function "CPU_ON" provided by ATF is now used
by Linux kernel to bring up the secondary CPUs to enable SMP
booting in Linux on SoC 64bits platform.

Signed-off-by: Chee Hong Ang 
---
 arch/arm/mach-socfpga/Kconfig | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/arm/mach-socfpga/Kconfig b/arch/arm/mach-socfpga/Kconfig
index 26f2cf8e47..01f5a1fc41 100644
--- a/arch/arm/mach-socfpga/Kconfig
+++ b/arch/arm/mach-socfpga/Kconfig
@@ -33,7 +33,6 @@ config TARGET_SOCFPGA_AGILEX
bool
select ARMV8_MULTIENTRY
select ARMV8_SET_SMPEN
-   select ARMV8_SPIN_TABLE
select CLK
select FPGA_INTEL_SDM_MAILBOX
select NCORE_CACHE
@@ -79,7 +78,6 @@ config TARGET_SOCFPGA_STRATIX10
bool
select ARMV8_MULTIENTRY
select ARMV8_SET_SMPEN
-   select ARMV8_SPIN_TABLE
select FPGA_INTEL_SDM_MAILBOX
 
 choice
-- 
2.13.0



[v6 03/18] arm: socfpga: soc64: Override 'lowlevel_init' to support ATF

2020-12-23 Thread Siew Chin Lim
From: Chee Hong Ang 

Override 'lowlevel_init' to make sure secondary CPUs trapped
in ATF instead of SPL. After ATF is initialized, it will signal
the secondary CPUs to jump from SPL to ATF waiting to be 'activated'
by Linux OS via PSCI call.

Signed-off-by: Chee Hong Ang 
---
 arch/arm/mach-socfpga/Makefile |  2 ++
 .../arm/mach-socfpga/lowlevel_init_soc64.S | 41 --
 2 files changed, 17 insertions(+), 26 deletions(-)
 copy board/cortina/presidio-asic/lowlevel_init.S => 
arch/arm/mach-socfpga/lowlevel_init_soc64.S (66%)

diff --git a/arch/arm/mach-socfpga/Makefile b/arch/arm/mach-socfpga/Makefile
index 418f543b20..c63162a5c6 100644
--- a/arch/arm/mach-socfpga/Makefile
+++ b/arch/arm/mach-socfpga/Makefile
@@ -29,6 +29,7 @@ endif
 
 ifdef CONFIG_TARGET_SOCFPGA_STRATIX10
 obj-y  += clock_manager_s10.o
+obj-y  += lowlevel_init_soc64.o
 obj-y  += mailbox_s10.o
 obj-y  += misc_s10.o
 obj-y  += mmu-arm64_s10.o
@@ -41,6 +42,7 @@ endif
 
 ifdef CONFIG_TARGET_SOCFPGA_AGILEX
 obj-y  += clock_manager_agilex.o
+obj-y  += lowlevel_init_soc64.o
 obj-y  += mailbox_s10.o
 obj-y  += misc_s10.o
 obj-y  += mmu-arm64_s10.o
diff --git a/board/cortina/presidio-asic/lowlevel_init.S 
b/arch/arm/mach-socfpga/lowlevel_init_soc64.S
similarity index 66%
copy from board/cortina/presidio-asic/lowlevel_init.S
copy to arch/arm/mach-socfpga/lowlevel_init_soc64.S
index 4450a5df79..612ea8a037 100644
--- a/board/cortina/presidio-asic/lowlevel_init.S
+++ b/arch/arm/mach-socfpga/lowlevel_init_soc64.S
@@ -1,43 +1,31 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
 /*
- * Copyright (C) 2020 Cortina-Access
+ * Copyright (C) 2020 Intel Corporation. All rights reserved
  *
+ * SPDX-License-Identifier:GPL-2.0
  */
 
-
 #include 
 #include 
 #include 
 #include 
-#include 
 
-   .globl lowlevel_init
-lowlevel_init:
+ENTRY(lowlevel_init)
mov x29, lr /* Save LR */
 
-#if defined(CONFIG_SOC_CA7774)
-   /* Enable SMPEN in CPUECTLR */
-   mrs x0, s3_1_c15_c2_1
-   tst x0, #0x40
-b.neskip_smp_setup
-   orr x0, x0, #0x40
-   msr s3_1_c15_c2_1, x0
-skip_smp_setup:
-#endif
-
-#if defined(CONFIG_SOC_CA8277B)
-   /* Enable CPU Timer */
-   ldr x0, =CONFIG_SYS_TIMER_BASE
-   mov x1, #1
-   str w1, [x0]
-#endif
-
 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
+#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_ATF)
+wait_for_atf:
+   ldr x4, =CPU_RELEASE_ADDR
+   ldr x5, [x4]
+   cbz x5, slave_wait_atf
+   br  x5
+slave_wait_atf:
+   branch_if_slave x0, wait_for_atf
+#else
branch_if_slave x0, 1f
-#ifndef CONFIG_TARGET_VENUS
+#endif
ldr x0, =GICD_BASE
bl  gic_init_secure
-#endif
 1:
 #if defined(CONFIG_GICV3)
ldr x0, =GICR_BASE
@@ -54,7 +42,7 @@ skip_smp_setup:
 
/*
 * Slave should wait for master clearing spin table.
-* This sync prevent salves observing incorrect
+* This sync prevent slaves observing incorrect
 * value of spin table and jumping to wrong place.
 */
 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
@@ -85,3 +73,4 @@ lowlevel_in_el1:
 2:
mov lr, x29 /* Restore LR */
ret
+ENDPROC(lowlevel_init)
-- 
2.13.0



[v6 02/18] arm: socfpga: soc64: Load FIT image with ATF support

2020-12-23 Thread Siew Chin Lim
From: Chee Hong Ang 

Instead of loading u-boot proper image (u-boot.img), SPL
now loads FIT image (u-boot.itb) which includes u-boot
proper, ATF and u-boot proper's DTB.

For OS, u-boot now loads FIT images (kernel.itb) which
includes Linux Image and Linux's DTB.

Signed-off-by: Chee Hong Ang 
Signed-off-by: Siew Chin Lim 
---
 include/configs/socfpga_soc64_common.h | 19 ++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/include/configs/socfpga_soc64_common.h 
b/include/configs/socfpga_soc64_common.h
index fb5e2e8aaf..990f879b07 100644
--- a/include/configs/socfpga_soc64_common.h
+++ b/include/configs/socfpga_soc64_common.h
@@ -78,12 +78,20 @@ unsigned int cm_get_qspi_controller_clk_hz(void);
  * CONFIG_BOOTARGS goes into the environment value "bootargs".
  * Do note the value will override also the chosen node in FDT blob.
  */
+
+#ifdef CONFIG_FIT
+#define CONFIG_BOOTFILE "kernel.itb"
+#define CONFIG_BOOTCOMMAND "run fatscript; run mmcfitload;run 
linux_qspi_enable;" \
+  "run mmcfitboot"
+#else
+#define CONFIG_BOOTFILE "Image"
 #define CONFIG_BOOTCOMMAND "run fatscript; run mmcload;run linux_qspi_enable;" 
\
   "run mmcboot"
+#endif
 
 #define CONFIG_EXTRA_ENV_SETTINGS \
"loadaddr=" __stringify(CONFIG_SYS_LOAD_ADDR) "\0" \
-   "bootfile=Image\0" \
+   "bootfile=" CONFIG_BOOTFILE "\0" \
"fdt_addr=800\0" \
"fdtimage=" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \
"mmcroot=/dev/mmcblk0p2\0" \
@@ -93,6 +101,11 @@ unsigned int cm_get_qspi_controller_clk_hz(void);
"mmcload=mmc rescan;" \
"load mmc 0:1 ${loadaddr} ${bootfile};" \
"load mmc 0:1 ${fdt_addr} ${fdtimage}\0" \
+   "mmcfitboot=setenv bootargs " CONFIG_BOOTARGS \
+   " root=${mmcroot} rw rootwait;" \
+   "bootm ${loadaddr}\0" \
+   "mmcfitload=mmc rescan;" \
+   "load mmc 0:1 ${loadaddr} ${bootfile}\0" \
"linux_qspi_enable=if sf probe; then " \
"echo Enabling QSPI at Linux DTB...;" \
"fdt addr ${fdt_addr}; fdt resize;" \
@@ -193,6 +206,10 @@ unsigned int cm_get_l4_sys_free_clk_hz(void);
- CONFIG_SYS_SPL_MALLOC_SIZE)
 
 /* SPL SDMMC boot support */
+#ifdef CONFIG_SPL_LOAD_FIT
+#define CONFIG_SPL_FS_LOAD_PAYLOAD_NAME"u-boot.itb"
+#else
 #define CONFIG_SPL_FS_LOAD_PAYLOAD_NAME"u-boot.img"
+#endif
 
 #endif /* __CONFIG_SOCFPGA_SOC64_COMMON_H__ */
-- 
2.13.0



[v6 01/18] arm: socfpga: Add function for checking description from FIT image

2020-12-23 Thread Siew Chin Lim
From: Chee Hong Ang 

Add board_fit_config_name_match() for matching board name with
device tree files in FIT image. This will ensure correct DTB
file is loaded for different board type. Currently, we are not
supporting multiple device tree files in FIT image therefore this
function basically do nothing for now.
Users are allowed to override this 'weak' function in their
specific board implementation.

Signed-off-by: Chee Hong Ang 
---
 arch/arm/mach-socfpga/board.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-socfpga/board.c b/arch/arm/mach-socfpga/board.c
index 340abf9305..7993c27646 100644
--- a/arch/arm/mach-socfpga/board.c
+++ b/arch/arm/mach-socfpga/board.c
@@ -13,7 +13,7 @@
 #include 
 #include 
 #include 
-
+#include 
 #include 
 #include 
 
@@ -87,3 +87,13 @@ int g_dnl_board_usb_cable_connected(void)
return 1;
 }
 #endif
+
+#ifdef CONFIG_SPL_BUILD
+__weak int board_fit_config_name_match(const char *name)
+{
+   /* Just empty function now - can't decide what to choose */
+   debug("%s: %s\n", __func__, name);
+
+   return 0;
+}
+#endif
-- 
2.13.0



[v6 00/18] Enable ARM Trusted Firmware for U-Boot

2020-12-23 Thread Siew Chin Lim
This is the 6th version of patchset to enable ARM Trusted Firmware
for U-Boot for Intel Stratix10 and Agilex platform.

New U-boot flow with ARM Trusted Firmware (ATF) support:
SPL (EL3) -> ATF-BL31 (EL3) -> U-Boot Proper (EL2) -> Linux (EL1)

SPL loads the u-boot.itb which consist of:
1) u-boot-nodtb.bin (U-Boot Proper image)
2) u-boot.dtb (U-Boot Proper DTB)
3) bl31.bin (ATF-BL31 image)


Patch status:
Have changes: Patch 7, 10
Other patches unchanged.

Detail changelog can find in commit message.

v5->v6:

Patch 7:
-  Direct return 'ret' after SMC call in write and update function.

Patch 10:
-  Clean up the code and use socfpga_secure_reg_update32 to update
   PHY related secure registers.


History:

[v1]: 
https://patchwork.ozlabs.org/project/uboot/cover/20200817043431.28718-1-chee.hong@intel.com/
[v2]: 
https://patchwork.ozlabs.org/project/uboot/cover/20201001091614.184612-1-elly.siew.chin@intel.com/
[v3]: 
https://patchwork.ozlabs.org/project/uboot/cover/20201015122955.10259-1-elly.siew.chin@intel.com/
[v4]: 
https://patchwork.ozlabs.org/project/uboot/cover/20201218032853.46839-1-elly.siew.chin@intel.com/
[v5]: 
https://patchwork.ozlabs.org/project/uboot/cover/20201221164942.11640-1-elly.siew.chin@intel.com/


These patchsets have dependency on:
arm: socfpga: soc64: Add timeout waiting for NOC idle ACK
https://lists.denx.de/pipermail/u-boot/2020-August/423029.html

Rename Stratix10 FPGA driver and support Agilex
https://lists.denx.de/pipermail/u-boot/2020-August/422798.html

SoCFPGA mailbox driver fixes and enhancements
https://lists.denx.de/pipermail/u-boot/2020-August/423140.html

arm: socfpga: soc64: Initialize timer in SPL only
https://lists.denx.de/pipermail/u-boot/2020-July/419692.html

arm: socfpga: soc64: Remove PHY interface setup from misc arch init
https://lists.denx.de/pipermail/u-boot/2020-July/419690.html

Enable sysreset support for SoCFPGA SoC64 platforms
https://lists.denx.de/pipermail/u-boot/2020-August/422509.html

arm: socfpga: soc64: Disable CONFIG_PSCI_RESET
https://lists.denx.de/pipermail/u-boot/2020-August/423373.html


Chee Hong Ang (14):
  arm: socfpga: Add function for checking description from FIT image
  arm: socfpga: soc64: Load FIT image with ATF support
  arm: socfpga: soc64: Override 'lowlevel_init' to support ATF
  arm: socfpga: Disable "spin-table" method for booting Linux
  arm: socfpga: soc64: Add SMC helper function for Intel SOCFPGA
(64bits)
  arm: socfpga: soc64: Define SMC function identifiers for PSCI SiP
services
  mmc: dwmmc: socfpga: Add ATF support for MMC driver
  net: designware: socfpga: Add ATF support for MAC driver
  arm: socfpga: soc64: Add ATF support for Reset Manager driver
  arm: socfpga: soc64: Add ATF support for FPGA reconfig driver
  arm: socfpga: mailbox: Add 'SYSTEM_RESET' PSCI support to
mbox_reset_cold()
  arm: socfpga: soc64: SSBL shall not setup stack on OCRAM
  arm: socfpga: soc64: Skip handoff data access in SSBL
  configs: socfpga: Add defconfig for Agilex and Stratix 10 with ATF
support

Siew Chin Lim (4):
  arm: socfpga: Add secure register access helper functions for SoC
64bits
  mmc: dwmmc: Change designware MMC 'clksel' callback function to return
status
  arm: socfpga: dts: soc64: Add binman node of FIT image with ATF
support
  arm: socfpga: soc64: Enable FIT image generation using binman

 arch/arm/dts/socfpga_agilex-u-boot.dtsi|   4 +-
 arch/arm/dts/socfpga_soc64_fit-u-boot.dtsi | 120 +
 arch/arm/dts/socfpga_stratix10-u-boot.dtsi |   8 +
 arch/arm/dts/socfpga_stratix10_socdk-u-boot.dtsi   |   4 +-
 arch/arm/mach-socfpga/Kconfig  |   4 +-
 arch/arm/mach-socfpga/Makefile |   5 +
 arch/arm/mach-socfpga/board.c  |  12 +-
 .../mach-socfpga/include/mach/secure_reg_helper.h  |  19 +
 arch/arm/mach-socfpga/include/mach/smc_api.h   |  13 +
 arch/arm/mach-socfpga/lowlevel_init_soc64.S|  76 +++
 arch/arm/mach-socfpga/mailbox_s10.c|   5 +
 arch/arm/mach-socfpga/reset_manager_s10.c  |  13 +
 arch/arm/mach-socfpga/secure_reg_helper.c  |  91 
 arch/arm/mach-socfpga/smc_api.c|  56 ++
 arch/arm/mach-socfpga/wrap_pll_config_s10.c|   3 +-
 configs/socfpga_agilex_atf_defconfig   |  72 +++
 configs/socfpga_stratix10_atf_defconfig|  74 +++
 drivers/fpga/intel_sdm_mb.c| 139 +
 drivers/mmc/ca_dw_mmc.c|   4 +-
 drivers/mmc/dw_mmc.c   |   9 +-
 drivers/mmc/exynos_dw_mmc.c|   4 +-
 drivers/mmc/nexell_dw_mmc.c|   4 +-
 drivers/mmc/socfpga_dw_mmc.c   |  18 +-
 drivers/net/dwmac_socfpga.c|  37 +-
 include/configs/socfpga_soc64_common.h |  24 +-
 include/dwmmc.h|   2 +-
 include/li

[PATCH v3 8/8] spl: fit: Load devicetree when a Linux payload is found

2020-12-23 Thread Alexandru Gagniuc
When a FIT config specifies a devicetree, we should load it, no
questions asked. In the case of the "simple" FIT loading path, a
difficulty arises in selecting the load address of the FDT.

The default FDT location is right after the "kernel" or "firmware"
image. However, if that is an OP-TEE image, then the FDT may end up in
secure DRAM, and not be accessible to normal world kernels.

Although the best solution is to be more careful about the FDT
address, a viable workaround is to only append the FDT after a u-boot
or Linux image. This is identical to the previous logic, except that
FDT loading is extended to IH_OS_LINUX images.

Signed-off-by: Alexandru Gagniuc 
---
 common/spl/spl_fit.c | 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index f7782ef1a9..5d01e5460a 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -335,6 +335,18 @@ static int spl_load_fit_image(struct spl_load_info *info, 
ulong sector,
return 0;
 }
 
+static bool os_takes_devicetree(uint8_t os)
+{
+   switch (os) {
+   case IH_OS_U_BOOT:
+   return true;
+   case IH_OS_LINUX:
+   return IS_ENABLED(CONFIG_SPL_OS_BOOT);
+   default:
+   return false;
+   }
+}
+
 static int spl_fit_append_fdt(struct spl_image_info *spl_image,
  struct spl_load_info *info, ulong sector,
  const struct spl_fit_info *ctx)
@@ -661,9 +673,9 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 * Booting a next-stage U-Boot may require us to append the FDT.
 * We allow this to fail, as the U-Boot image might embed its FDT.
 */
-   if (spl_image->os == IH_OS_U_BOOT) {
+   if (os_takes_devicetree(spl_image->os)) {
ret = spl_fit_append_fdt(spl_image, info, sector, &ctx);
-   if (!IS_ENABLED(CONFIG_OF_EMBED) && ret < 0)
+   if (ret < 0 && spl_image->os != IH_OS_U_BOOT)
return ret;
}
 
@@ -691,7 +703,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
if (!spl_fit_image_get_os(ctx.fit, node, &os_type))
debug("Loadable is %s\n", genimg_get_os_name(os_type));
 
-   if (os_type == IH_OS_U_BOOT) {
+   if (os_takes_devicetree(os_type)) {
spl_fit_append_fdt(&image_info, info, sector, &ctx);
spl_image->fdt_addr = image_info.fdt_addr;
}
-- 
2.26.2



[PATCH v3 7/8] spl: fit: Replace #ifdef blocks with more readable constructs

2020-12-23 Thread Alexandru Gagniuc
Use the IS_ENABLED() macro to control code flow, instead of the
caveman approach of sprinkling #ifdefs. Code size is not affected, as
the linker garbage-collects unused functions. However, readability is
improved significantly.

Signed-off-by: Alexandru Gagniuc 
Reviewed-by: Simon Glass 
---
 common/spl/spl_fit.c | 53 
 1 file changed, 24 insertions(+), 29 deletions(-)

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index ed5e8b83a1..f7782ef1a9 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -297,18 +297,16 @@ static int spl_load_fit_image(struct spl_load_info *info, 
ulong sector,
src = (void *)data;
}
 
-#ifdef CONFIG_SPL_FIT_SIGNATURE
-   printf("## Checking hash(es) for Image %s ... ",
-  fit_get_name(fit, node, NULL));
-   if (!fit_image_verify_with_data(fit, node,
-src, length))
-   return -EPERM;
-   puts("OK\n");
-#endif
+   if (CONFIG_IS_ENABLED(FIT_SIGNATURE)) {
+   printf("## Checking hash(es) for Image %s ... ",
+  fit_get_name(fit, node, NULL));
+   if (!fit_image_verify_with_data(fit, node, src, length))
+   return -EPERM;
+   puts("OK\n");
+   }
 
-#ifdef CONFIG_SPL_FIT_IMAGE_POST_PROCESS
-   board_fit_image_post_process(&src, &length);
-#endif
+   if (CONFIG_IS_ENABLED(FIT_IMAGE_POST_PROCESS))
+   board_fit_image_post_process(&src, &length);
 
if (IS_ENABLED(CONFIG_SPL_GZIP) && image_comp == IH_COMP_GZIP) {
size = length;
@@ -373,7 +371,9 @@ static int spl_fit_append_fdt(struct spl_image_info 
*spl_image,
 
/* Make the load-address of the FDT available for the SPL framework */
spl_image->fdt_addr = (void *)image_info.load_addr;
-#if !CONFIG_IS_ENABLED(FIT_IMAGE_TINY)
+   if (CONFIG_IS_ENABLED(FIT_IMAGE_TINY))
+   return 0;
+
if (CONFIG_IS_ENABLED(LOAD_FIT_APPLY_OVERLAY)) {
void *tmpbuffer = NULL;
 
@@ -431,7 +431,6 @@ static int spl_fit_append_fdt(struct spl_image_info 
*spl_image,
ret = fdt_shrink_to_minimum(spl_image->fdt_addr, 8192);
if (ret < 0)
return ret;
-#endif
 
return ret;
 }
@@ -440,10 +439,12 @@ static int spl_fit_record_loadable(const struct 
spl_fit_info *ctx, int index,
   void *blob, struct spl_image_info *image)
 {
int ret = 0;
-#if !CONFIG_IS_ENABLED(FIT_IMAGE_TINY)
const char *name;
int node;
 
+   if (CONFIG_IS_ENABLED(FIT_IMAGE_TINY))
+   return 0;
+
ret = spl_fit_get_image_name(ctx, "loadables", index, &name);
if (ret < 0)
return ret;
@@ -454,15 +455,15 @@ static int spl_fit_record_loadable(const struct 
spl_fit_info *ctx, int index,
  image->size, image->entry_point,
  fdt_getprop(ctx->fit, node, "type", NULL),
  fdt_getprop(ctx->fit, node, "os", NULL));
-#endif
return ret;
 }
 
 static int spl_fit_image_get_os(const void *fit, int noffset, uint8_t *os)
 {
-#if CONFIG_IS_ENABLED(FIT_IMAGE_TINY) && !defined(CONFIG_SPL_OS_BOOT)
-   const char *name = fdt_getprop(fit, noffset, FIT_OS_PROP, NULL);
+   if (!CONFIG_IS_ENABLED(FIT_IMAGE_TINY) || CONFIG_IS_ENABLED(OS_BOOT))
+   return fit_image_get_os(fit, noffset, os);
 
+   const char *name = fdt_getprop(fit, noffset, FIT_OS_PROP, NULL);
if (!name)
return -ENOENT;
 
@@ -477,9 +478,6 @@ static int spl_fit_image_get_os(const void *fit, int 
noffset, uint8_t *os)
*os = IH_OS_INVALID;
 
return 0;
-#else
-   return fit_image_get_os(fit, noffset, os);
-#endif
 }
 
 /*
@@ -626,10 +624,10 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 */
if (node < 0)
node = spl_fit_get_image_node(&ctx, FIT_FIRMWARE_PROP, 0);
-#ifdef CONFIG_SPL_OS_BOOT
-   if (node < 0)
+
+   if (node < 0 && IS_ENABLED(CONFIG_SPL_OS_BOOT))
node = spl_fit_get_image_node(&ctx, FIT_KERNEL_PROP, 0);
-#endif
+
if (node < 0) {
debug("could not find firmware image, trying loadables...\n");
node = spl_fit_get_image_node(&ctx, "loadables", 0);
@@ -656,10 +654,8 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 */
if (!spl_fit_image_get_os(ctx.fit, node, &spl_image->os))
debug("Image OS is %s\n", genimg_get_os_name(spl_image->os));
-#if !defined(CONFIG_SPL_OS_BOOT)
-   else
+   else if (!IS_ENABLED(CONFIG_SPL_OS_BOOT))
spl_image->os = IH_OS_U_BOOT;
-#endif
 
/*
 * Booting a next-stage U-Boot may require us to append the FDT.
@@ -725,9 +721,8 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 
spl_ima

[PATCH v3 6/8] image: Do not #if guard board_fit_config_name_match() prototype

2020-12-23 Thread Alexandru Gagniuc
There's no point in guarding function prototypes with #ifdefs. If a
function is not defined, the linker will notice. Having the prototype
does not affect code size.

What the #if guard takes away is the ability to use IS_ENABLED:

if (CONFIG_IS ENABLED(FIT_IMAGE_POST_PROCESS))
board_fit_config_name_match(...)

When the prototype is guarded, the above form cannot be used. This
leads to the proliferation of #ifdefs, and unreadable code. The
opportunity cost of the #if guard outweighs any benefits. Remove it.

Signed-off-by: Alexandru Gagniuc 
Reviewed-by: Simon Glass 
---
 include/image.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/image.h b/include/image.h
index 00bc03bebe..fd8bd43515 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1536,8 +1536,6 @@ bool android_image_print_dtb_contents(ulong hdr_addr);
  */
 int board_fit_config_name_match(const char *name);
 
-#if defined(CONFIG_SPL_FIT_IMAGE_POST_PROCESS) || \
-   defined(CONFIG_FIT_IMAGE_POST_PROCESS)
 /**
  * board_fit_image_post_process() - Do any post-process on FIT binary data
  *
@@ -1552,7 +1550,6 @@ int board_fit_config_name_match(const char *name);
  * @return no return value (failure should be handled internally)
  */
 void board_fit_image_post_process(void **p_image, size_t *p_size);
-#endif /* CONFIG_SPL_FIT_IMAGE_POST_PROCESS */
 
 #define FDT_ERROR  ((ulong)(-1))
 
-- 
2.26.2



[PATCH v3 5/8] spl: fit: Only look up FIT configuration node once

2020-12-23 Thread Alexandru Gagniuc
The configuration node a sub node under "/configurations", which
describes the components to load from "/images". We only need to
locate this node once.

However, for each component, spl_fit_get_image_name() would parse the
FIT image, looking for the correct node. Such work duplication is not
necessary. Instead, once the node is found, cache it, and re-use it.

Signed-off-by: Alexandru Gagniuc 
Reviewed-by: Simon Glass 
---
 common/spl/spl_fit.c | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index adcd6e3fcd..ed5e8b83a1 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -30,6 +30,7 @@ struct spl_fit_info {
const void *fit;/* Pointer to a valid FIT blob */
size_t ext_data_offset; /* Offset to FIT external data (end of FIT) */
int images_node;/* FDT offset to "/images" node */
+   int conf_node;  /* FDT offset to selected configuration node */
 };
 
 __weak void board_spl_fit_post_load(const void *fit)
@@ -83,15 +84,10 @@ static int spl_fit_get_image_name(const struct spl_fit_info 
*ctx,
struct udevice *sysinfo;
const char *name, *str;
__maybe_unused int node;
-   int conf_node;
int len, i;
bool found = true;
 
-   conf_node = fit_find_config_node(ctx->fit);
-   if (conf_node < 0)
-   return conf_node;
-
-   name = fdt_getprop(ctx->fit, conf_node, type, &len);
+   name = fdt_getprop(ctx->fit, ctx->conf_node, type, &len);
if (!name) {
debug("cannot find property '%s': %d\n", type, len);
return -EINVAL;
@@ -550,12 +546,15 @@ static int spl_simple_fit_read(struct spl_fit_info *ctx,
 
 static int spl_simple_fit_parse(struct spl_fit_info *ctx)
 {
-   if (IS_ENABLED(CONFIG_SPL_FIT_SIGNATURE)) {
-   int conf_offset = fit_find_config_node(ctx->fit);
+   /* Find the correct subnode under "/configurations" */
+   ctx->conf_node = fit_find_config_node(ctx->fit);
+   if (ctx->conf_node < 0)
+   return -EINVAL;
 
+   if (IS_ENABLED(CONFIG_SPL_FIT_SIGNATURE)) {
printf("## Checking hash(es) for config %s ... ",
-  fit_get_name(ctx->fit, conf_offset, NULL));
-   if (fit_config_verify(ctx->fit, conf_offset))
+  fit_get_name(ctx->fit, ctx->conf_node, NULL));
+   if (fit_config_verify(ctx->fit, ctx->conf_node))
return -EPERM;
puts("OK\n");
}
-- 
2.26.2



[PATCH v3 3/8] spl: fit: Pass FIT context via a structure pointer

2020-12-23 Thread Alexandru Gagniuc
Several loose arguments describe the FIT image. They are thus related,
and it makes sense to pass them together, in a structure. Examples
include the FIT blob pointer, offset to FDT nodes, and the offset to
external data.

Use a spl_fit_info structure to group these parameters.

Signed-off-by: Alexandru Gagniuc 
Reviewed-by: Simon Glass 
---
 common/spl/spl_fit.c | 101 ++-
 1 file changed, 43 insertions(+), 58 deletions(-)

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index bcc943b0b8..5a06e8a9db 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -76,7 +76,7 @@ static int find_node_from_desc(const void *fit, int node, 
const char *str)
  *
  * Return: 0 on success, or a negative error number
  */
-static int spl_fit_get_image_name(const void *fit, int images,
+static int spl_fit_get_image_name(const struct spl_fit_info *ctx,
  const char *type, int index,
  const char **outname)
 {
@@ -87,21 +87,21 @@ static int spl_fit_get_image_name(const void *fit, int 
images,
int len, i;
bool found = true;
 
-   conf_node = fit_find_config_node(fit);
+   conf_node = fit_find_config_node(ctx->fit);
if (conf_node < 0) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
printf("No matching DT out of these options:\n");
-   for (node = fdt_first_subnode(fit, conf_node);
+   for (node = fdt_first_subnode(ctx->fit, conf_node);
 node >= 0;
-node = fdt_next_subnode(fit, node)) {
-   name = fdt_getprop(fit, node, "description", &len);
+node = fdt_next_subnode(ctx->fit, node)) {
+   name = fdt_getprop(ctx->fit, node, "description", &len);
printf("   %s\n", name);
}
 #endif
return conf_node;
}
 
-   name = fdt_getprop(fit, conf_node, type, &len);
+   name = fdt_getprop(ctx->fit, conf_node, type, &len);
if (!name) {
debug("cannot find property '%s': %d\n", type, len);
return -EINVAL;
@@ -135,11 +135,11 @@ static int spl_fit_get_image_name(const void *fit, int 
images,
 * node name.
 */
int node;
-   int images = fdt_path_offset(fit, FIT_IMAGES_PATH);
+   int images = fdt_path_offset(ctx->fit, FIT_IMAGES_PATH);
 
-   node = find_node_from_desc(fit, images, str);
+   node = find_node_from_desc(ctx->fit, images, str);
if (node > 0)
-   str = fdt_get_name(fit, node, NULL);
+   str = fdt_get_name(ctx->fit, node, NULL);
 
found = true;
}
@@ -166,20 +166,20 @@ static int spl_fit_get_image_name(const void *fit, int 
images,
  * Return: the node offset of the respective image node or a negative
  * error number.
  */
-static int spl_fit_get_image_node(const void *fit, int images,
+static int spl_fit_get_image_node(const struct spl_fit_info *ctx,
  const char *type, int index)
 {
const char *str;
int err;
int node;
 
-   err = spl_fit_get_image_name(fit, images, type, index, &str);
+   err = spl_fit_get_image_name(ctx, type, index, &str);
if (err)
return err;
 
debug("%s: '%s'\n", type, str);
 
-   node = fdt_subnode_offset(fit, images, str);
+   node = fdt_subnode_offset(ctx->fit, ctx->images_node, str);
if (node < 0) {
pr_err("cannot find image node '%s': %d\n", str, node);
return -EINVAL;
@@ -230,10 +230,7 @@ static int get_aligned_image_size(struct spl_load_info 
*info, int data_size,
  * spl_load_fit_image(): load the image described in a certain FIT node
  * @info:  points to information about the device to load data from
  * @sector:the start sector of the FIT image on the device
- * @fit:   points to the flattened device tree blob describing the FIT
- * image
- * @base_offset: the beginning of the data area containing the actual
- * image data, relative to the beginning of the FIT
+ * @ctx:   points to the FIT context structure
  * @node:  offset of the DT node describing the image to load (relative
  * to @fit)
  * @image_info:will be filled with information about the loaded image
@@ -244,7 +241,7 @@ static int get_aligned_image_size(struct spl_load_info 
*info, int data_size,
  * Return: 0 on success or a negative error number.
  */
 static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
- void *fit, ulong base_offset, int node,
+ const struct spl_fit_info *ctx, int node,

[PATCH v3 4/8] spl: fit: Remove useless loop in spl_fit_get_image_name()

2020-12-23 Thread Alexandru Gagniuc
When a desired configuration is not found, conf_node will have a
negative value. Thus the for loop will start at the root "/" node of
the image, print the "/description" property, and stop.

It appears the intent of the loop was to print the names of the
subnodes under "/configurations". We would need the offset to the
"/configurations" node, which is abstracted by fit_find_config_node().

This change agrees that abstracting the node offset is the correct
design, and we shouldn't be parsing the configurations manually. Thus
the loop in spl_fit_get_image_name() is useless. Remove it.

Signed-off-by: Alexandru Gagniuc 
Reviewed-by: Simon Glass 
---
 common/spl/spl_fit.c | 12 +---
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 5a06e8a9db..adcd6e3fcd 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -88,18 +88,8 @@ static int spl_fit_get_image_name(const struct spl_fit_info 
*ctx,
bool found = true;
 
conf_node = fit_find_config_node(ctx->fit);
-   if (conf_node < 0) {
-#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
-   printf("No matching DT out of these options:\n");
-   for (node = fdt_first_subnode(ctx->fit, conf_node);
-node >= 0;
-node = fdt_next_subnode(ctx->fit, node)) {
-   name = fdt_getprop(ctx->fit, node, "description", &len);
-   printf("   %s\n", name);
-   }
-#endif
+   if (conf_node < 0)
return conf_node;
-   }
 
name = fdt_getprop(ctx->fit, conf_node, type, &len);
if (!name) {
-- 
2.26.2



[PATCH v3 2/8] spl: fit: Factor out FIT parsing and use a context struct

2020-12-23 Thread Alexandru Gagniuc
The logical steps in spl_load_simple_fit() are difficult to follow.
I think the long comments, ifdefs, and ungodly number of variables
seriously affect the readability. In particular, it violates section 6
of the coding style, paragraphs (3), and (4).

The purpose of this patch is to improve the situation by
  - Factoring out initialization and parsing to separate functions
  - Reduce the number of variables by using a context structure
This change introduces no functional changes.

Signed-off-by: Alexandru Gagniuc 
---
 common/spl/spl_fit.c | 90 +---
 1 file changed, 60 insertions(+), 30 deletions(-)

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 1b4a7f6b15..bcc943b0b8 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -26,6 +26,12 @@ DECLARE_GLOBAL_DATA_PTR;
 #define CONFIG_SYS_BOOTM_LEN   (64 << 20)
 #endif
 
+struct spl_fit_info {
+   const void *fit;/* Pointer to a valid FIT blob */
+   size_t ext_data_offset; /* Offset to FIT external data (end of FIT) */
+   int images_node;/* FDT offset to "/images" node */
+};
+
 __weak void board_spl_fit_post_load(const void *fit)
 {
 }
@@ -521,28 +527,22 @@ __weak bool spl_load_simple_fit_skip_processing(void)
return false;
 }
 
-int spl_load_simple_fit(struct spl_image_info *spl_image,
-   struct spl_load_info *info, ulong sector, void *fit)
+static int spl_simple_fit_read(struct spl_fit_info *ctx,
+  struct spl_load_info *info, ulong sector,
+  const void *fit_header)
 {
+   unsigned long count, size;
int sectors;
-   ulong size, hsize;
-   unsigned long count;
-   struct spl_image_info image_info;
-   int node = -1;
-   int images, ret;
-   int base_offset;
-   int index = 0;
-   int firmware_node;
+   void *buf;
 
/*
 * For FIT with external data, figure out where the external images
 * start. This is the base for the data-offset properties in each
 * image.
 */
-   size = fdt_totalsize(fit);
-   size = (size + 3) & ~3;
+   size = ALIGN(fdt_totalsize(fit_header), 4);
size = board_spl_fit_size_align(size);
-   base_offset = (size + 3) & ~3;
+   ctx->ext_data_offset = ALIGN(size, 4);
 
/*
 * So far we only have one block of data from the FIT. Read the entire
@@ -552,36 +552,66 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 * For FIT with external data, data is not loaded in this step.
 */
sectors = get_aligned_image_size(info, size, 0);
-   hsize = sectors * info->bl_len;
-   fit = spl_get_fit_load_buffer(hsize);
-   count = info->read(info, sector, sectors, fit);
-   debug("fit read sector %lx, sectors=%d, dst=%p, count=%lu, 
size=0x%lx\n",
- sector, sectors, fit, count, size);
+   buf = spl_get_fit_load_buffer(sectors * info->bl_len);
 
-   if (count == 0)
-   return -EIO;
+   count = info->read(info, sector, sectors, buf);
+   ctx->fit = buf;
+   debug("fit read sector %lx, sectors=%d, dst=%p, count=%lu, 
size=0x%lx\n",
+ sector, sectors, buf, count, size);
 
-   /* skip further processing if requested to enable load-only use cases */
-   if (spl_load_simple_fit_skip_processing())
-   return 0;
+   return (count == 0) ? -EIO : 0;
+}
 
+static int spl_simple_fit_parse(struct spl_fit_info *ctx)
+{
if (IS_ENABLED(CONFIG_SPL_FIT_SIGNATURE)) {
-   int conf_offset = fit_find_config_node(fit);
+   int conf_offset = fit_find_config_node(ctx->fit);
 
printf("## Checking hash(es) for config %s ... ",
-  fit_get_name(fit, conf_offset, NULL));
-   if (fit_config_verify(fit, conf_offset))
+  fit_get_name(ctx->fit, conf_offset, NULL));
+   if (fit_config_verify(ctx->fit, conf_offset))
return -EPERM;
puts("OK\n");
}
 
/* find the node holding the images information */
-   images = fdt_path_offset(fit, FIT_IMAGES_PATH);
-   if (images < 0) {
-   debug("%s: Cannot find /images node: %d\n", __func__, images);
-   return -1;
+   ctx->images_node = fdt_path_offset(ctx->fit, FIT_IMAGES_PATH);
+   if (ctx->images_node < 0) {
+   debug("%s: Cannot find /images node: %d\n", __func__,
+ ctx->images_node);
+   return -EINVAL;
}
 
+   return 0;
+}
+
+int spl_load_simple_fit(struct spl_image_info *spl_image,
+   struct spl_load_info *info, ulong sector, void *fit)
+{
+   struct spl_image_info image_info;
+   struct spl_fit_info ctx;
+   int node = -1;
+   int images, ret;
+   int base_offset;
+   int index = 0;
+   int firmware_node;
+
+ 

[PATCH v3 1/8] spl: fit: Drop 'length' argument to board_spl_fit_post_load()

2020-12-23 Thread Alexandru Gagniuc
The size is derived from the FIT image itself. Any alignment
requirements are machine-specific and known by the board code. Thus
the total length can be derived from the FIT image and knowledge of
the platform. The 'length' argument is redundant. Remove it.

Signed-off-by: Alexandru Gagniuc 
Reviewed-by: Peng Fan 
Reviewed-by: Simon Glass 
---
 arch/arm/mach-imx/spl.c | 5 +++--
 common/spl/spl_fit.c| 4 ++--
 include/spl.h   | 4 ++--
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-imx/spl.c b/arch/arm/mach-imx/spl.c
index aa2686bb92..11255798d3 100644
--- a/arch/arm/mach-imx/spl.c
+++ b/arch/arm/mach-imx/spl.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -318,9 +319,9 @@ ulong board_spl_fit_size_align(ulong size)
return size;
 }
 
-void board_spl_fit_post_load(ulong load_addr, size_t length)
+void board_spl_fit_post_load(const void *fit)
 {
-   u32 offset = length - CONFIG_CSF_SIZE;
+   u32 offset = ALIGN(fdt_totalsize(fit), 0x1000);
 
if (imx_hab_authenticate_image(load_addr,
   offset + IVT_SIZE + CSF_PAD_SIZE,
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 795e2922ce..1b4a7f6b15 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -26,7 +26,7 @@ DECLARE_GLOBAL_DATA_PTR;
 #define CONFIG_SYS_BOOTM_LEN   (64 << 20)
 #endif
 
-__weak void board_spl_fit_post_load(ulong load_addr, size_t length)
+__weak void board_spl_fit_post_load(const void *fit)
 {
 }
 
@@ -722,7 +722,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
spl_image->flags |= SPL_FIT_FOUND;
 
 #ifdef CONFIG_IMX_HAB
-   board_spl_fit_post_load((ulong)fit, size);
+   board_spl_fit_post_load(fit);
 #endif
 
return 0;
diff --git a/include/spl.h b/include/spl.h
index 374a295fa3..cb30ef0827 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -630,9 +630,9 @@ int board_return_to_bootrom(struct spl_image_info 
*spl_image,
 
 /**
  * board_spl_fit_post_load - allow process images after loading finished
- *
+ * @fit: Pointer to a valid Flattened Image Tree blob
  */
-void board_spl_fit_post_load(ulong load_addr, size_t length);
+void board_spl_fit_post_load(const void *fit);
 
 /**
  * board_spl_fit_size_align - specific size align before processing payload
-- 
2.26.2



[PATCH v3 0/8] spl: fit: Play nicely with OP-TEE and Linux

2020-12-23 Thread Alexandru Gagniuc
This patch series is part of a larger effort to get linux to boot
really fast alongside a secure OS. One piece of the puzzle is getting
Linux and OP-TEE to boot straight from SPL. This is where the FIT
image comes in.

The "simple" fit code was mostly ready for this, although it was
quite difficult to navigate. As I was figuring out the required
changes, I realized I had also managed to do some major refactoring.
In fact, of the eight changes, (6) are refactoring patches, and (2)
are functional changes.

I wish I could have written this with a negative line count. I have
unfortunately failed at that, and this series will be adding 11 lines
to u-boot. The takeaway is that the following type FIT can be loaded
from SPL directly:

images {
optee@1 {
type = "tee";
os = "tee";
...
};
kernel@1 {
type = "kernel";
os = "linux";
...
};
f...@devicetree.dtb { ... }
f...@overlay.dto { ... };
};

configurations {
conf@quickboot {
kernel = "optee@1";
fdt = "f...@stm32mp157c-ev1.dtb", "f...@overlay.dto";
loadables = "kernel@1";
};
};


This series is designed to apply to u-boot/next:
  * 8351a29d2d Merge tag 'dm-pull-14dec20' of git://git.denx.de/u-boot-dm into 
next 
  
Changes since v1:
 * Added struct comments (Simon Glass)
 * Added comment do describe args of board_spl_fit_post_load() (Simon Glass)
 * Fixed predicate of if clause on spl_load_simple_fit() (me)
 
Changes since v2:
 * Fixed embarrasing rebase mishap on one of the patches.
 

Alexandru Gagniuc (8):
  spl: fit: Drop 'length' argument to board_spl_fit_post_load()
  spl: fit: Factor out FIT parsing and use a context struct
  spl: fit: Pass FIT context via a structure pointer
  spl: fit: Remove useless loop in spl_fit_get_image_name()
  spl: fit: Only look up FIT configuration node once
  image: Do not #if guard board_fit_config_name_match() prototype
  spl: fit: Replace #ifdef blocks with more readable constructs
  spl: fit: Load devicetree when a Linux payload is found

 arch/arm/mach-imx/spl.c |   5 +-
 common/spl/spl_fit.c| 261 +---
 include/image.h |   3 -
 include/spl.h   |   4 +-
 4 files changed, 141 insertions(+), 132 deletions(-)

-- 
2.26.2



[PATCH] cmd: ubi: don't allow to rename a volume to a name that already exist

2020-12-23 Thread Philippe Reynes
This commits add a check on the command ubi rename. This check avoids
to rename a volume to with a name that is already used on another ubi
volume. If two volumes has the same name, then the ubi device can't be
mounted anymore.

Signed-off-by: Philippe Reynes 
---
 cmd/ubi.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/cmd/ubi.c b/cmd/ubi.c
index 171377cc66..cb14e3e1e7 100644
--- a/cmd/ubi.c
+++ b/cmd/ubi.c
@@ -264,6 +264,11 @@ static int ubi_rename_vol(char *oldname, char *newname)
return ENODEV;
}
 
+   if (!ubi_check(newname)) {
+   printf("%s: volume %s already exist\n", __func__, newname);
+   return EINVAL;
+   }
+
printf("Rename UBI volume %s to %s\n", oldname, newname);
 
if (ubi->ro_mode) {
-- 
2.17.1



RE: [PATCH] imx8mp_evk: Increase CONFIG_SYS_MALLOC_F_LEN

2020-12-23 Thread Peng Fan
> Subject: Re: [PATCH] imx8mp_evk: Increase CONFIG_SYS_MALLOC_F_LEN
> 
> Hi Peng,
> 
> On Wed, Dec 23, 2020 at 4:29 AM Peng Fan  wrote:
> 
> > I am thinking to remove the CLK CCF support for i.MX8M, and use simple
> > CLK DM. Do you agree?
> 
> As a minimal fix for 2021.01, I suggest that we go with my patch.

I agree.

> 
> After 2021.01 is released we can consider using simple CLK DM.

Sure. I need people agree on this before action, then prepare the stuff.

Thanks,
Peng

> 
> Thanks


Re: [PATCH v2] imx: ahab: allow to bypass confirmation for ahab_close cmd

2020-12-23 Thread Oliver Graute
On 21/12/20, Clément Péron wrote:
> Calling ahab_close cmd force the user to interact for confirmation.
> 
> This is not user-friendly when using this cmd during factory process.
> 
> Allow the user to pass '-y' option to bypass this confirmation.
> 
> Signed-off-by: Clément Péron 
Acked-by: Oliver Graute 


[PATCH v3 0/6] Add MBR partition table creation and verify command

2020-12-23 Thread Marek Szyprowski
Hi All,

This patchset adds 'mbr' command to let one to create or verify MBR
(Master Boot Record) partition layout based on the provided text
description. This can be used in scripts to help system flashing
tools/scripts to ensure proper partition layout. It has been inspired by
the 'gpt' command already present in u-boot.

Best regards
Marek Szyprowski
Samsung R&D Institute Poland


Changelog:

v3:
- fixed minor issues in the docs

v2: https://lists.denx.de/pipermail/u-boot/2020-December/435689.html
- added docs and minor fixes in the code style

v1: https://lists.denx.de/pipermail/u-boot/2020-December/435208.html
- initial version


Patch summary:

Marek Szyprowski (6):
  disk: dos: rename write_mbr_partition to write_mbr_sector
  disk: dos: add some defines for the hardcoded numbers
  disk: dos: use generic macro for unaligned le32 access
  disk: dos: make some functions static
  disk: dos: add code for creating MBR partition layout
  cmd: Add MBR partition layout control utility

 cmd/Kconfig   |   8 +
 cmd/Makefile  |   1 +
 cmd/mbr.c | 314 ++
 disk/part_dos.c   | 207 ++---
 disk/part_dos.h   |   5 +
 doc/usage/index.rst   |   1 +
 doc/usage/mbr.rst |  93 +++
 drivers/fastboot/fb_mmc.c |   2 +-
 include/part.h|   9 +-
 9 files changed, 612 insertions(+), 28 deletions(-)
 create mode 100644 cmd/mbr.c
 create mode 100644 doc/usage/mbr.rst

-- 
2.17.1



[PATCH v3 4/6] disk: dos: make some functions static

2020-12-23 Thread Marek Szyprowski
Make functions not used outside this file static.

Signed-off-by: Marek Szyprowski 
---
 disk/part_dos.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/disk/part_dos.c b/disk/part_dos.c
index 3b79b9b1b8..2c4ad0b6ba 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -302,13 +302,13 @@ static int part_get_info_extended(struct blk_desc 
*dev_desc,
return -1;
 }
 
-void part_print_dos(struct blk_desc *dev_desc)
+static void part_print_dos(struct blk_desc *dev_desc)
 {
printf("Part\tStart Sector\tNum Sectors\tUUID\t\tType\n");
print_partition_extended(dev_desc, 0, 0, 1, 0);
 }
 
-int part_get_info_dos(struct blk_desc *dev_desc, int part,
+static int part_get_info_dos(struct blk_desc *dev_desc, int part,
  struct disk_partition *info)
 {
return part_get_info_extended(dev_desc, 0, 0, 1, part, info, 0);
-- 
2.17.1



[PATCH v3 6/6] cmd: Add MBR partition layout control utility

2020-12-23 Thread Marek Szyprowski
Add a 'mbr' command to let users create or verify MBR partition layout
based on the provided text description. The partition layout is
alternatively read from the 'mbr_parts' environment variable. This can be
used in scripts to help system image flashing tools to ensure proper
partition layout.

The syntax of the text description of the partition list is similar to
the one used by the 'gpt' command. Supported parameters are: name
(currently ignored), start (partition start offset in bytes), size (in
bytes or '-' to expand it to the whole free area), bootable (boolean
flag) and id (MBR partition type). If one wants to create more than 4
partitions, an 'Extended' primary partition (with 0x05 ID) has to be
explicitely provided as a one of the first 4 entries.

Here is an example how to create a 6 partitions (3 on the 'extended
volume'), some of the predefined sizes:

> setenv mbr_parts 'name=boot,start=4M,size=128M,bootable,id=0x0e;
  name=rootfs,size=3072M,id=0x83;
  name=system-data,size=512M,id=0x83;
  name=[ext],size=-,id=0x05;
  name=user,size=-,id=0x83;
  name=modules,size=100M,id=0x83;
  name=ramdisk,size=8M,id=0x83'
> mbr write mmc 0

Signed-off-by: Marek Szyprowski 
---
 cmd/Kconfig |   8 ++
 cmd/Makefile|   1 +
 cmd/mbr.c   | 314 
 doc/usage/index.rst |   1 +
 doc/usage/mbr.rst   |  93 +
 5 files changed, 417 insertions(+)
 create mode 100644 cmd/mbr.c
 create mode 100644 doc/usage/mbr.rst

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 1595de999b..2c3358e359 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1025,6 +1025,14 @@ config CMD_LSBLK
  Print list of available block device drivers, and for each, the list
  of known block devices.
 
+config CMD_MBR
+   bool "MBR (Master Boot Record) command"
+   select DOS_PARTITION
+   select HAVE_BLOCK_DEVICE
+   help
+ Enable the 'mbr' command to ready and write MBR (Master Boot Record)
+ style partition tables.
+
 config CMD_MISC
bool "misc"
depends on MISC
diff --git a/cmd/Makefile b/cmd/Makefile
index dd86675bf2..41379d9a0e 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -178,6 +178,7 @@ obj-$(CONFIG_CMD_ZFS) += zfs.o
 
 obj-$(CONFIG_CMD_DFU) += dfu.o
 obj-$(CONFIG_CMD_GPT) += gpt.o
+obj-$(CONFIG_CMD_MBR) += mbr.o
 obj-$(CONFIG_CMD_ETHSW) += ethsw.o
 obj-$(CONFIG_CMD_AXI) += axi.o
 obj-$(CONFIG_CMD_PVBLOCK) += pvblock.o
diff --git a/cmd/mbr.c b/cmd/mbr.c
new file mode 100644
index 00..da2e3a4722
--- /dev/null
+++ b/cmd/mbr.c
@@ -0,0 +1,314 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * cmd_mbr.c -- MBR (Master Boot Record) handling command
+ *
+ * Copyright (C) 2020 Samsung Electronics
+ * author: Marek Szyprowski 
+ *
+ * based on the gpt command.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * extract_val() - Extract a value from the key=value pair list
+ * @str: pointer to string with key=values pairs
+ * @key: pointer to the key to search for
+ *
+ * The list of parameters is come separated, only a value for
+ * the given key is returend.
+ *
+ * Function allocates memory for the value, remember to free!
+ *
+ * Return: Pointer to allocated string with the value.
+ */
+static char *extract_val(const char *str, const char *key)
+{
+   char *v, *k;
+   char *s, *strcopy;
+   char *new = NULL;
+
+   strcopy = strdup(str);
+   if (strcopy == NULL)
+   return NULL;
+
+   s = strcopy;
+   while (s) {
+   v = strsep(&s, ",");
+   if (!v)
+   break;
+   k = strsep(&v, "=");
+   if (!k)
+   break;
+   if  (strcmp(k, key) == 0) {
+   new = strdup(v);
+   break;
+   }
+   }
+
+   free(strcopy);
+
+   return new;
+}
+
+/**
+ * found_key() - Search for a key without a value in the parameter list
+ * @str: pointer to string with key
+ * @key: pointer to the key to search for
+ *
+ * The list of parameters is come separated.
+ *
+ * Return: True if key has been found.
+ */
+static bool found_key(const char *str, const char *key)
+{
+   char *k;
+   char *s, *strcopy;
+   bool result = false;
+
+   strcopy = strdup(str);
+   if (!strcopy)
+   return NULL;
+
+   s = strcopy;
+   while (s) {
+   k = strsep(&s, ",");
+   if (!k)
+   break;
+   if  (strcmp(k, key) == 0) {
+   result = true;
+   break;
+   }
+   }
+
+   free(strcopy);
+
+   return result;
+}
+
+static int str_to_partitions(const char *str_part, int blksz,
+   unsigned long *disk_uuid, struct disk_partition **partitions,
+   int *parts_count)
+{
+   char *tok, *str, *s;
+   int i;
+   char *val, *p;
+   int p_count;
+   struct disk_partition *parts

[PATCH v3 5/6] disk: dos: add code for creating MBR partition layout

2020-12-23 Thread Marek Szyprowski
Add a code for creating and writing MBR partition layout. The code generates
similar layout of EBRs (Exteneded Block Records) and logical volumes as
Linux's fdisk utility.

Signed-off-by: Marek Szyprowski 
---
 disk/part_dos.c | 167 
 disk/part_dos.h |   2 +
 include/part.h  |   5 ++
 3 files changed, 174 insertions(+)

diff --git a/disk/part_dos.c b/disk/part_dos.c
index 2c4ad0b6ba..f77f927995 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -319,6 +319,173 @@ int is_valid_dos_buf(void *buf)
return test_block_type(buf) == DOS_MBR ? 0 : -1;
 }
 
+#if CONFIG_IS_ENABLED(CMD_MBR)
+static void lba_to_chs(lbaint_t lba, unsigned char *rc, unsigned char *rh,
+  unsigned char *rs)
+{
+   unsigned int c, h, s;
+   /* use fixed CHS geometry */
+   unsigned int sectpertrack = 63;
+   unsigned int heads = 255;
+
+   c = (lba + 1) / sectpertrack / heads;
+   h = (lba + 1) / sectpertrack - c * heads;
+   s = (lba + 1) - (c * heads + h) * sectpertrack;
+
+   if (c > 1023) {
+   c = 1023;
+   h = 254;
+   s = 63;
+   }
+
+   *rc = c & 0xff;
+   *rh = h;
+   *rs = s + ((c & 0x300) >> 2);
+}
+
+static void mbr_fill_pt_entry(dos_partition_t *pt, lbaint_t start,
+   lbaint_t relative, lbaint_t size, uchar sys_ind, bool bootable)
+{
+   pt->boot_ind = bootable ? 0x80 : 0x00;
+   pt->sys_ind = sys_ind;
+   lba_to_chs(start, &pt->cyl, &pt->head, &pt->sector);
+   lba_to_chs(start + size - 1, &pt->end_cyl, &pt->end_head, 
&pt->end_sector);
+   put_unaligned_le32(relative, &pt->start4);
+   put_unaligned_le32(size, &pt->size4);
+}
+
+int write_mbr_partitions(struct blk_desc *dev,
+   struct disk_partition *p, int count, unsigned int disksig)
+{
+   ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev->blksz);
+   lbaint_t ext_part_start = 0, ext_part_size = 0, ext_part_sect = 0;
+   dos_partition_t *pt;
+   int i;
+
+   memset(buffer, 0, dev->blksz);
+   buffer[DOS_PART_MAGIC_OFFSET] = 0x55;
+   buffer[DOS_PART_MAGIC_OFFSET + 1] = 0xaa;
+   put_unaligned_le32(disksig, &buffer[DOS_PART_DISKSIG_OFFSET]);
+   pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET);
+
+   /* create all primary partitions */
+   for (i = 0; i < 4 && i < count; i++, pt++) {
+   mbr_fill_pt_entry(pt, p[i].start, p[i].start, p[i].size,
+ p[i].sys_ind, p[i].bootable);
+   if (is_extended(p[i].sys_ind)) {
+   ext_part_start = p[i].start;
+   ext_part_size = p[i].size;
+   ext_part_sect = p[i].start;
+   }
+   }
+
+   if (i < count && !ext_part_start) {
+   printf("%s: extended partition is needed for more than 4 
partitions\n",
+   __func__);
+   return -1;
+   }
+
+   /* write MBR */
+   if (blk_dwrite(dev, 0, 1, buffer) != 1) {
+   printf("%s: failed writing 'MBR' (1 blks at 0x0)\n",
+  __func__);
+   return -1;
+   }
+
+   /* create extended volumes */
+   for (; i < count; i++) {
+   lbaint_t next_ebr = 0;
+
+   memset(buffer, 0, dev->blksz);
+   buffer[DOS_PART_MAGIC_OFFSET] = 0x55;
+   buffer[DOS_PART_MAGIC_OFFSET + 1] = 0xaa;
+   pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET);
+
+   mbr_fill_pt_entry(pt, p[i].start, p[i].start - ext_part_sect,
+ p[i].size, p[i].sys_ind, p[i].bootable);
+
+   if (i + 1 < count) {
+   pt++;
+   next_ebr = p[i].start + p[i].size;
+   mbr_fill_pt_entry(pt, next_ebr,
+ next_ebr - ext_part_start,
+ p[i+1].start + p[i+1].size - next_ebr,
+ DOS_PART_TYPE_EXTENDED, 0);
+   }
+
+   /* write EBR */
+   if (blk_dwrite(dev, ext_part_sect, 1, buffer) != 1) {
+   printf("%s: failed writing 'EBR' (1 blks at 0x%lx)\n",
+  __func__, ext_part_sect);
+   return -1;
+   }
+   ext_part_sect = next_ebr;
+   }
+
+   return 0;
+}
+
+int layout_mbr_partitions(struct disk_partition *p, int count,
+ lbaint_t total_sectors)
+{
+   struct disk_partition *ext = NULL;
+   int i, j;
+   lbaint_t ext_vol_start;
+
+   /* calculate primary partitions start and size if needed */
+   if (!p[0].start)
+   p[0].start = DOS_PART_DEFAULT_GAP;
+   for (i = 0; i < 4 && i < count; i++) {
+   if (!p[i].start)
+   p[i].start = p[i - 1].start + p[

[PATCH v3 2/6] disk: dos: add some defines for the hardcoded numbers

2020-12-23 Thread Marek Szyprowski
Add some handy defines for some hardcoded magic numbers related to
extended partition handling.

Signed-off-by: Marek Szyprowski 
---
 disk/part_dos.c | 6 +++---
 disk/part_dos.h | 3 +++
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/disk/part_dos.c b/disk/part_dos.c
index ef706fb59c..20d35dc9cd 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -42,9 +42,9 @@ static inline unsigned int le32_to_int(unsigned char *le32)
 
 static inline int is_extended(int part_type)
 {
-return (part_type == 0x5 ||
-   part_type == 0xf ||
-   part_type == 0x85);
+return (part_type == DOS_PART_TYPE_EXTENDED ||
+   part_type == DOS_PART_TYPE_EXTENDED_LBA ||
+   part_type == DOS_PART_TYPE_EXTENDED_LINUX);
 }
 
 static int get_bootable(dos_partition_t *p)
diff --git a/disk/part_dos.h b/disk/part_dos.h
index 434b021ae8..dd909a9317 100644
--- a/disk/part_dos.h
+++ b/disk/part_dos.h
@@ -15,6 +15,9 @@
 #define DOS_PBR_MEDIA_TYPE_OFFSET  0x15
 #define DOS_MBR0
 #define DOS_PBR1
+#define DOS_PART_TYPE_EXTENDED 0x05
+#define DOS_PART_TYPE_EXTENDED_LBA 0x0F
+#define DOS_PART_TYPE_EXTENDED_LINUX   0x85
 
 typedef struct dos_partition {
unsigned char boot_ind; /* 0x80 - active
*/
-- 
2.17.1



[PATCH v3 1/6] disk: dos: rename write_mbr_partition to write_mbr_sector

2020-12-23 Thread Marek Szyprowski
write_mbr_partition() function name is a bit misleading, so rename it to
write_mbr_sector(). This is a preparation for adding code for writing a
complete MBR partition layout.

Signed-off-by: Marek Szyprowski 
---
 disk/part_dos.c   | 2 +-
 drivers/fastboot/fb_mmc.c | 2 +-
 include/part.h| 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/disk/part_dos.c b/disk/part_dos.c
index 04f53106f7..ef706fb59c 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -329,7 +329,7 @@ int is_valid_dos_buf(void *buf)
return test_block_type(buf) == DOS_MBR ? 0 : -1;
 }
 
-int write_mbr_partition(struct blk_desc *dev_desc, void *buf)
+int write_mbr_sector(struct blk_desc *dev_desc, void *buf)
 {
if (is_valid_dos_buf(buf))
return -1;
diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index ae8e8e512f..4e26cef941 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -508,7 +508,7 @@ void fastboot_mmc_flash_write(const char *cmd, void 
*download_buffer,
fastboot_fail("invalid MBR partition", response);
return;
}
-   if (write_mbr_partition(dev_desc, download_buffer)) {
+   if (write_mbr_sector(dev_desc, download_buffer)) {
printf("%s: writing MBR partition failed\n", __func__);
fastboot_fail("writing MBR partition failed",
  response);
diff --git a/include/part.h b/include/part.h
index 55be724d20..67b8b2a5cc 100644
--- a/include/part.h
+++ b/include/part.h
@@ -465,14 +465,14 @@ int get_disk_guid(struct blk_desc *dev_desc, char *guid);
 int is_valid_dos_buf(void *buf);
 
 /**
- * write_mbr_partition() - write DOS MBR
+ * write_mbr_sector() - write DOS MBR
  *
  * @param dev_desc - block device descriptor
  * @param buf - buffer which contains the MBR
  *
  * @return - '0' on success, otherwise error
  */
-int write_mbr_partition(struct blk_desc *dev_desc, void *buf);
+int write_mbr_sector(struct blk_desc *dev_desc, void *buf);
 
 #endif
 
-- 
2.17.1



[PATCH v3 3/6] disk: dos: use generic macro for unaligned le32 access

2020-12-23 Thread Marek Szyprowski
Use a generic helper for reading LE32 integers.

Signed-off-by: Marek Szyprowski 
---
 disk/part_dos.c | 28 +---
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/disk/part_dos.c b/disk/part_dos.c
index 20d35dc9cd..3b79b9b1b8 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "part_dos.h"
 #include 
 
@@ -29,17 +30,6 @@
  * to use large numbers of partitions */
 #define MAX_EXT_PARTS 256
 
-/* Convert char[4] in little endian format to the host format integer
- */
-static inline unsigned int le32_to_int(unsigned char *le32)
-{
-return ((le32[3] << 24) +
-   (le32[2] << 16) +
-   (le32[1] << 8) +
-le32[0]
-  );
-}
-
 static inline int is_extended(int part_type)
 {
 return (part_type == DOS_PART_TYPE_EXTENDED ||
@@ -61,8 +51,8 @@ static int get_bootable(dos_partition_t *p)
 static void print_one_part(dos_partition_t *p, lbaint_t ext_part_sector,
   int part_num, unsigned int disksig)
 {
-   lbaint_t lba_start = ext_part_sector + le32_to_int (p->start4);
-   lbaint_t lba_size  = le32_to_int (p->size4);
+   lbaint_t lba_start = ext_part_sector + get_unaligned_le32(p->start4);
+   lbaint_t lba_size  = get_unaligned_le32(p->size4);
 
printf("%3d\t%-10" LBAFlength "u\t%-10" LBAFlength
"u\t%08x-%02x\t%02x%s%s\n",
@@ -171,7 +161,7 @@ static void print_partition_extended(struct blk_desc 
*dev_desc,
}
 
if (!ext_part_sector)
-   disksig = le32_to_int(&buffer[DOS_PART_DISKSIG_OFFSET]);
+   disksig = get_unaligned_le32(&buffer[DOS_PART_DISKSIG_OFFSET]);
 
/* Print all primary/logical partitions */
pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET);
@@ -198,7 +188,7 @@ static void print_partition_extended(struct blk_desc 
*dev_desc,
for (i = 0; i < 4; i++, pt++) {
if (is_extended (pt->sys_ind)) {
lbaint_t lba_start
-   = le32_to_int (pt->start4) + relative;
+   = get_unaligned_le32 (pt->start4) + relative;
 
print_partition_extended(dev_desc, lba_start,
ext_part_sector == 0  ? lba_start : relative,
@@ -244,7 +234,7 @@ static int part_get_info_extended(struct blk_desc *dev_desc,
 
 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
if (!ext_part_sector)
-   disksig = le32_to_int(&buffer[DOS_PART_DISKSIG_OFFSET]);
+   disksig = get_unaligned_le32(&buffer[DOS_PART_DISKSIG_OFFSET]);
 #endif
 
/* Print all primary/logical partitions */
@@ -260,8 +250,8 @@ static int part_get_info_extended(struct blk_desc *dev_desc,
(ext_part_sector == 0 || is_extended(pt->sys_ind) == 0)) {
info->blksz = DOS_PART_DEFAULT_SECTOR;
info->start = (lbaint_t)(ext_part_sector +
-   le32_to_int(pt->start4));
-   info->size  = (lbaint_t)le32_to_int(pt->size4);
+   get_unaligned_le32(pt->start4));
+   info->size  = (lbaint_t)get_unaligned_le32(pt->size4);
part_set_generic_name(dev_desc, part_num,
  (char *)info->name);
/* sprintf(info->type, "%d, pt->sys_ind); */
@@ -286,7 +276,7 @@ static int part_get_info_extended(struct blk_desc *dev_desc,
for (i = 0; i < 4; i++, pt++) {
if (is_extended (pt->sys_ind)) {
lbaint_t lba_start
-   = le32_to_int (pt->start4) + relative;
+   = get_unaligned_le32 (pt->start4) + relative;
 
return part_get_info_extended(dev_desc, lba_start,
 ext_part_sector == 0 ? lba_start : relative,
-- 
2.17.1



Re: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-23 Thread Amit Tomar
Hi,

Thanks again for the detailed review

+

> >  3 files changed, 407 insertions(+)
> >  create mode 100644 drivers/mmc/owl_mmc.c
> >
> > diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
> > index 14d7913..61f9c67 100644
> > --- a/drivers/mmc/Kconfig
> > +++ b/drivers/mmc/Kconfig
> > @@ -289,6 +289,13 @@ config MMC_MXC
> >
> > If unsure, say N.
> >
> > +config MMC_OWL
> > + bool "Actions OWL Multimedia Card Interface support"
> > + depends on ARCH_OWL && DM_MMC && BLK
> > + help
> > +   This selects the OWL SD/MMC host controller found on board
> > +   based on Actions S700 SoC.
>
> And S900 as well?
>
> But as you aware S900 has different DMA requirements, would it be
okay to claim that this works for S900 as well ?

> +
> >  config MMC_MXS
> >   bool "Freescale MXS Multimedia Card Interface support"
> >   depends on MX23 || MX28 || MX6 || MX7
> > diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
> > index 1c849cb..f270f6c 100644
> > --- a/drivers/mmc/Makefile
> > +++ b/drivers/mmc/Makefile
> > @@ -38,6 +38,7 @@ obj-$(CONFIG_MMC_OMAP_HS)   += omap_hsmmc.o
> >  obj-$(CONFIG_MMC_MXC)+= mxcmmc.o
> >  obj-$(CONFIG_MMC_MXS)+= mxsmmc.o
> >  obj-$(CONFIG_MMC_OCTEONTX)   += octeontx_hsmmc.o
> > +obj-$(CONFIG_MMC_OWL)+= owl_mmc.o
> >  obj-$(CONFIG_MMC_PCI)+= pci_mmc.o
> >  obj-$(CONFIG_PXA_MMC_GENERIC) += pxa_mmc_gen.o
> >  obj-$(CONFIG_$(SPL_TPL_)SUPPORT_EMMC_RPMB) += rpmb.o
> > diff --git a/drivers/mmc/owl_mmc.c b/drivers/mmc/owl_mmc.c
> > new file mode 100644
> > index 000..5c48307
> > --- /dev/null
> > +++ b/drivers/mmc/owl_mmc.c
> > @@ -0,0 +1,399 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright (C) 2020 Amit Singh Tomar 
> > + *
> > + * Driver for SD/MMC controller present on Actions Semi S700 SoC, based
> > + * on Linux Driver "drivers/mmc/host/owl-mmc.c".
> > + *
> > + * Though, there is a bit (BSEL, BUS or DMA Special Channel Selection)
> that
> > + * controls the data transfer from SDx_DAT register either using CPU
> AHB Bus
> > + * or DMA channel, but seems like, it only works correctly using
> external DMA
> > + * channel, and those special bits used in this driver is picked from
> vendor
> > + * source exclusively for MMC/SD.
> > + */
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +/*
> > + * SDC registers
> > + */
> > +#define OWL_REG_SD_EN   0x
> > +#define OWL_REG_SD_CTL  0x0004
> > +#define OWL_REG_SD_STATE0x0008
> > +#define OWL_REG_SD_CMD  0x000c
> > +#define OWL_REG_SD_ARG  0x0010
> > +#define OWL_REG_SD_RSPBUF0  0x0014
> > +#define OWL_REG_SD_RSPBUF1  0x0018
> > +#define OWL_REG_SD_RSPBUF2  0x001c
> > +#define OWL_REG_SD_RSPBUF3  0x0020
> > +#define OWL_REG_SD_RSPBUF4  0x0024
> > +#define OWL_REG_SD_DAT  0x0028
> > +#define OWL_REG_SD_BLK_SIZE 0x002c
> > +#define OWL_REG_SD_BLK_NUM  0x0030
> > +#define OWL_REG_SD_BUF_SIZE 0x0034
> > +
> > +/* SD_EN Bits */
> > +#define OWL_SD_EN_RANE  BIT(31)
> > +#define OWL_SD_EN_RESE  BIT(10)
> > +#define OWL_SD_ENABLE   BIT(7)
> > +#define OWL_SD_EN_BSEL  BIT(6)
> > +#define OWL_SD_EN_DATAWID(x)(((x) & 0x3) << 0)
> > +#define OWL_SD_EN_DATAWID_MASK   0x03
> > +
> > +/* SD_CTL Bits */
> > +#define OWL_SD_CTL_TOUTEN   BIT(31)
> > +#define OWL_SD_CTL_DELAY_MSKGENMASK(23, 16)
> > +#define OWL_SD_CTL_RDELAY(x)(((x) & 0xf) << 20)
> > +#define OWL_SD_CTL_WDELAY(x)(((x) & 0xf) << 16)
> > +#define OWL_SD_CTL_TS   BIT(7)
> > +#define OWL_SD_CTL_LBE  BIT(6)
> > +#define OWL_SD_CTL_TM(x)(((x) & 0xf) << 0)
> > +
> > +#define OWL_SD_DELAY_LOW_CLK0x0f
> > +#define OWL_SD_DELAY_MID_CLK0x0a
> > +#define OWL_SD_RDELAY_HIGH   0x08
> > +#define OWL_SD_WDELAY_HIGH   0x09
>
> w/s? Here and elsewhere. I would use tabs everywhere instead.
>

Yeah, just checked I was not consistent with tabs here, will fix it in the
next version.

>
> > +
> > +/* SD_STATE Bits */
> > +#define OWL_SD_STATE_DAT0S  BIT(7)
> > +#define OWL_SD_STATE_CLNR   BIT(4)
> > +#define OWL_SD_STATE_CRC7ER BIT(0)
> > +
> > +#define OWL_MMC_OCR (MMC_VDD_32_33 | MMC_VDD_33_34
> | \
> > +  MMC_VDD_165_195)
> > +
> > +#define DATA_TRANSFER_TIMEOUT3
> > +
> > +/*
> > + * Simple DMA transfer operations defines for MMC/SD car

Re: [PATCH] imx8mp_evk: Increase CONFIG_SYS_MALLOC_F_LEN

2020-12-23 Thread Fabio Estevam
Hi Peng,

On Wed, Dec 23, 2020 at 4:29 AM Peng Fan  wrote:

> I am thinking to remove the CLK CCF support for i.MX8M, and use simple CLK
> DM. Do you agree?

As a minimal fix for 2021.01, I suggest that we go with my patch.

After 2021.01 is released we can consider using simple CLK DM.

Thanks


Re: [PATCH v2] efi_loader: Extra checks while opening an OPTEE session

2020-12-23 Thread Ilias Apalodimas
Apologies for the noise.
This version should be fine! You can pick it up if you like it.

Cheers
/Ilias

On Wed, 23 Dec 2020 at 13:27, Ilias Apalodimas
 wrote:
>
> Heinrich I found a slightly better way to do it and free teh session
> on errors, so we dont have to check it.
> I'll send a v3
>
> Cheers
> /Ilias
>
>
> On Wed, 23 Dec 2020 at 13:25, Ilias Apalodimas
>  wrote:
> >
> > When opening an OP-TEE session we need to check the internal return
> > value of OP-TEE call arguments as well the return code of the
> > function itself.
> > The code was also ignoring to close the OP-TEE session in case the
> > shared memory registration failed.
> >
> > Fixes: f042e47e8fb43 ("efi_loader: Implement EFI variable handling via 
> > OP-TEE")
> > Signed-off-by: Ilias Apalodimas 
> > ---
> > changes since v1:
> > - add a goto tag and use it on fails
> >
> >  lib/efi_loader/efi_variable_tee.c | 20 +++-
> >  1 file changed, 15 insertions(+), 5 deletions(-)
> >
> > diff --git a/lib/efi_loader/efi_variable_tee.c 
> > b/lib/efi_loader/efi_variable_tee.c
> > index be6f3dfad469..b8808fdecad3 100644
> > --- a/lib/efi_loader/efi_variable_tee.c
> > +++ b/lib/efi_loader/efi_variable_tee.c
> > @@ -36,20 +36,29 @@ static int get_connection(struct mm_connection *conn)
> > static const struct tee_optee_ta_uuid uuid = PTA_STMM_UUID;
> > struct udevice *tee = NULL;
> > struct tee_open_session_arg arg;
> > -   int rc;
> > +   int rc = -ENODEV;
> >
> > tee = tee_find_device(tee, NULL, NULL, NULL);
> > if (!tee)
> > -   return -ENODEV;
> > +   goto out;
> >
> > memset(&arg, 0, sizeof(arg));
> > tee_optee_ta_uuid_to_octets(arg.uuid, &uuid);
> > rc = tee_open_session(tee, &arg, 0, NULL);
> > -   if (!rc) {
> > -   conn->tee = tee;
> > -   conn->session = arg.session;
> > +   if (rc)
> > +   goto out;
> > +
> > +   /* Check the internal OP-TEE result */
> > +   if (arg.ret != TEE_SUCCESS) {
> > +   rc = -EIO;
> > +   goto out;
> > }
> >
> > +   conn->tee = tee;
> > +   conn->session = arg.session;
> > +
> > +   return 0;
> > +out:
> > return rc;
> >  }
> >
> > @@ -88,6 +97,7 @@ static efi_status_t optee_mm_communicate(void *comm_buf, 
> > ulong dsize)
> >
> > if (tee_shm_register(conn.tee, comm_buf, buf_size, 0, &shm)) {
> > log_err("Unable to register shared memory\n");
> > +   tee_close_session(conn.tee, conn.session);
> > return EFI_UNSUPPORTED;
> > }
> >
> > --
> > 2.30.0.rc1
> >


Re: [PATCH v2] efi_loader: Extra checks while opening an OPTEE session

2020-12-23 Thread Ilias Apalodimas
Heinrich I found a slightly better way to do it and free teh session
on errors, so we dont have to check it.
I'll send a v3

Cheers
/Ilias


On Wed, 23 Dec 2020 at 13:25, Ilias Apalodimas
 wrote:
>
> When opening an OP-TEE session we need to check the internal return
> value of OP-TEE call arguments as well the return code of the
> function itself.
> The code was also ignoring to close the OP-TEE session in case the
> shared memory registration failed.
>
> Fixes: f042e47e8fb43 ("efi_loader: Implement EFI variable handling via 
> OP-TEE")
> Signed-off-by: Ilias Apalodimas 
> ---
> changes since v1:
> - add a goto tag and use it on fails
>
>  lib/efi_loader/efi_variable_tee.c | 20 +++-
>  1 file changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/lib/efi_loader/efi_variable_tee.c 
> b/lib/efi_loader/efi_variable_tee.c
> index be6f3dfad469..b8808fdecad3 100644
> --- a/lib/efi_loader/efi_variable_tee.c
> +++ b/lib/efi_loader/efi_variable_tee.c
> @@ -36,20 +36,29 @@ static int get_connection(struct mm_connection *conn)
> static const struct tee_optee_ta_uuid uuid = PTA_STMM_UUID;
> struct udevice *tee = NULL;
> struct tee_open_session_arg arg;
> -   int rc;
> +   int rc = -ENODEV;
>
> tee = tee_find_device(tee, NULL, NULL, NULL);
> if (!tee)
> -   return -ENODEV;
> +   goto out;
>
> memset(&arg, 0, sizeof(arg));
> tee_optee_ta_uuid_to_octets(arg.uuid, &uuid);
> rc = tee_open_session(tee, &arg, 0, NULL);
> -   if (!rc) {
> -   conn->tee = tee;
> -   conn->session = arg.session;
> +   if (rc)
> +   goto out;
> +
> +   /* Check the internal OP-TEE result */
> +   if (arg.ret != TEE_SUCCESS) {
> +   rc = -EIO;
> +   goto out;
> }
>
> +   conn->tee = tee;
> +   conn->session = arg.session;
> +
> +   return 0;
> +out:
> return rc;
>  }
>
> @@ -88,6 +97,7 @@ static efi_status_t optee_mm_communicate(void *comm_buf, 
> ulong dsize)
>
> if (tee_shm_register(conn.tee, comm_buf, buf_size, 0, &shm)) {
> log_err("Unable to register shared memory\n");
> +   tee_close_session(conn.tee, conn.session);
> return EFI_UNSUPPORTED;
> }
>
> --
> 2.30.0.rc1
>


[PATCH v2] efi_loader: Extra checks while opening an OPTEE session

2020-12-23 Thread Ilias Apalodimas
When opening an OP-TEE session we need to check the internal return
value of OP-TEE call arguments as well the return code of the
function itself.
The code was also ignoring to close the OP-TEE session in case the
shared memory registration failed.

Fixes: f042e47e8fb43 ("efi_loader: Implement EFI variable handling via OP-TEE")
Signed-off-by: Ilias Apalodimas 
---
changes since v1:
- add a goto tag and use it on fails

 lib/efi_loader/efi_variable_tee.c | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/lib/efi_loader/efi_variable_tee.c 
b/lib/efi_loader/efi_variable_tee.c
index be6f3dfad469..b8808fdecad3 100644
--- a/lib/efi_loader/efi_variable_tee.c
+++ b/lib/efi_loader/efi_variable_tee.c
@@ -36,20 +36,29 @@ static int get_connection(struct mm_connection *conn)
static const struct tee_optee_ta_uuid uuid = PTA_STMM_UUID;
struct udevice *tee = NULL;
struct tee_open_session_arg arg;
-   int rc;
+   int rc = -ENODEV;
 
tee = tee_find_device(tee, NULL, NULL, NULL);
if (!tee)
-   return -ENODEV;
+   goto out;
 
memset(&arg, 0, sizeof(arg));
tee_optee_ta_uuid_to_octets(arg.uuid, &uuid);
rc = tee_open_session(tee, &arg, 0, NULL);
-   if (!rc) {
-   conn->tee = tee;
-   conn->session = arg.session;
+   if (rc)
+   goto out;
+
+   /* Check the internal OP-TEE result */
+   if (arg.ret != TEE_SUCCESS) {
+   rc = -EIO;
+   goto out;
}
 
+   conn->tee = tee;
+   conn->session = arg.session;
+
+   return 0;
+out:
return rc;
 }
 
@@ -88,6 +97,7 @@ static efi_status_t optee_mm_communicate(void *comm_buf, 
ulong dsize)
 
if (tee_shm_register(conn.tee, comm_buf, buf_size, 0, &shm)) {
log_err("Unable to register shared memory\n");
+   tee_close_session(conn.tee, conn.session);
return EFI_UNSUPPORTED;
}
 
-- 
2.30.0.rc1



[PATCH 3/3] arm: mvebu: Espressobin: Set default value for $ethNaddr env variable

2020-12-23 Thread Pali Rohár
On Espressobin board are MAC addresses stored in U-Boot env area. Therefore
they are not present in default_environment[] array constructed at compile
time.

This change puts permanent MAC addresses into default_environment[] array
at board runtime. Espressobin board has enabled DEFAULT_ENV_IS_RW option
and therefore can modify this array.

This change ensure that 'env default -a' does not delete permanent MAC
addresses from Espressobin env storage area.

Signed-off-by: Pali Rohár 
---
 board/Marvell/mvebu_armada-37xx/board.c | 19 +++
 include/configs/mvebu_armada-37xx.h |  4 
 2 files changed, 23 insertions(+)

diff --git a/board/Marvell/mvebu_armada-37xx/board.c 
b/board/Marvell/mvebu_armada-37xx/board.c
index 9297ea0f90..dabd4eefd6 100644
--- a/board/Marvell/mvebu_armada-37xx/board.c
+++ b/board/Marvell/mvebu_armada-37xx/board.c
@@ -88,6 +88,9 @@ int board_late_init(void)
char *ptr = (char *)&default_environment[0];
struct mmc *mmc_dev;
bool ddr4, emmc;
+   const char *mac;
+   char eth[10];
+   int i;
 
if (!of_machine_is_compatible("globalscale,espressobin"))
return 0;
@@ -96,6 +99,22 @@ int board_late_init(void)
while (*ptr != '\0' && *(ptr+1) != '\0') ptr++;
ptr += 2;
 
+   /*
+* Ensure that 'env default -a' does not erase permanent MAC addresses
+* stored in env variables: $ethaddr, $eth1addr, $eth2addr and $eth3addr
+*/
+
+   mac = env_get("ethaddr");
+   if (mac && strlen(mac) <= 17)
+   ptr += sprintf(ptr, "ethaddr=%s", mac) + 1;
+
+   for (i = 1; i <= 3; i++) {
+   sprintf(eth, "eth%daddr", i);
+   mac = env_get(eth);
+   if (mac && strlen(mac) <= 17)
+   ptr += sprintf(ptr, "%s=%s", eth, mac) + 1;
+   }
+
/* If the memory controller has been configured for DDR4, we're running 
on v7 */
ddr4 = ((readl(A3700_CH0_MC_CTRL2_REG) >> 
A3700_MC_CTRL2_SDRAM_TYPE_OFFS)
& A3700_MC_CTRL2_SDRAM_TYPE_MASK) == 
A3700_MC_CTRL2_SDRAM_TYPE_DDR4;
diff --git a/include/configs/mvebu_armada-37xx.h 
b/include/configs/mvebu_armada-37xx.h
index 6df702367c..2ad4325eaf 100644
--- a/include/configs/mvebu_armada-37xx.h
+++ b/include/configs/mvebu_armada-37xx.h
@@ -94,6 +94,10 @@
 
 /* filler for default values filled by board_early_init_f() */
 #define ENV_RW_FILLER \
+   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" /* for 
ethaddr= */ \
+   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" /* for 
eth1addr= */ \
+   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" /* for 
eth2addr= */ \
+   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" /* for 
eth3addr= */ \

"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
 /* for fdtfile= */ \
""
 
-- 
2.20.1



[PATCH 2/3] arm: mvebu: Espressobin: Set default value for $fdtfile env variable

2020-12-23 Thread Pali Rohár
On Espressobin board value for $fdtfile cannot be determined at compile
time and is calculated at board runtime code. This change uses a new option
DEFAULT_ENV_IS_RW to allow modifying default_environment[] array at runtime
and set into it correct value.

This change also ensure that 'env default -a' set correct value to $fdtfile.

Signed-off-by: Pali Rohár 
---
 board/Marvell/mvebu_armada-37xx/board.c | 22 +++---
 include/configs/mvebu_armada-37xx.h | 13 -
 2 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/board/Marvell/mvebu_armada-37xx/board.c 
b/board/Marvell/mvebu_armada-37xx/board.c
index f67b04b78c..9297ea0f90 100644
--- a/board/Marvell/mvebu_armada-37xx/board.c
+++ b/board/Marvell/mvebu_armada-37xx/board.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -84,15 +85,17 @@ int board_init(void)
 #ifdef CONFIG_BOARD_LATE_INIT
 int board_late_init(void)
 {
+   char *ptr = (char *)&default_environment[0];
struct mmc *mmc_dev;
bool ddr4, emmc;
 
-   if (env_get("fdtfile"))
-   return 0;
-
if (!of_machine_is_compatible("globalscale,espressobin"))
return 0;
 
+   /* Find free buffer in default_environment[] for new variables */
+   while (*ptr != '\0' && *(ptr+1) != '\0') ptr++;
+   ptr += 2;
+
/* If the memory controller has been configured for DDR4, we're running 
on v7 */
ddr4 = ((readl(A3700_CH0_MC_CTRL2_REG) >> 
A3700_MC_CTRL2_SDRAM_TYPE_OFFS)
& A3700_MC_CTRL2_SDRAM_TYPE_MASK) == 
A3700_MC_CTRL2_SDRAM_TYPE_DDR4;
@@ -101,14 +104,19 @@ int board_late_init(void)
mmc_dev = find_mmc_device(1);
emmc = (mmc_dev && mmc_init(mmc_dev) == 0);
 
+   /* Ensure that 'env default -a' set correct value to $fdtfile */
if (ddr4 && emmc)
-   env_set("fdtfile", 
"marvell/armada-3720-espressobin-v7-emmc.dtb");
+   strcpy(ptr, 
"fdtfile=marvell/armada-3720-espressobin-v7-emmc.dtb");
else if (ddr4)
-   env_set("fdtfile", "marvell/armada-3720-espressobin-v7.dtb");
+   strcpy(ptr, "fdtfile=marvell/armada-3720-espressobin-v7.dtb");
else if (emmc)
-   env_set("fdtfile", "marvell/armada-3720-espressobin-emmc.dtb");
+   strcpy(ptr, "fdtfile=marvell/armada-3720-espressobin-emmc.dtb");
else
-   env_set("fdtfile", "marvell/armada-3720-espressobin.dtb");
+   strcpy(ptr, "fdtfile=marvell/armada-3720-espressobin.dtb");
+
+   /* If $fdtfile was not set explicitly by user then set default value */
+   if (!env_get("fdtfile"))
+   env_set("fdtfile", ptr + sizeof("fdtfile="));
 
return 0;
 }
diff --git a/include/configs/mvebu_armada-37xx.h 
b/include/configs/mvebu_armada-37xx.h
index 0d585606a7..6df702367c 100644
--- a/include/configs/mvebu_armada-37xx.h
+++ b/include/configs/mvebu_armada-37xx.h
@@ -57,6 +57,11 @@
  */
 #define CONFIG_MTD_PARTITIONS  /* required for UBI partition support */
 
+/*
+ * Environment
+ */
+#define DEFAULT_ENV_IS_RW  /* required for configuring default 
fdtfile= */
+
 /*
  * Ethernet Driver configuration
  */
@@ -87,6 +92,11 @@
 
 #include 
 
+/* filler for default values filled by board_early_init_f() */
+#define ENV_RW_FILLER \
+   
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
 /* for fdtfile= */ \
+   ""
+
 /* fdt_addr and kernel_addr are needed for existing distribution boot scripts 
*/
 #define CONFIG_EXTRA_ENV_SETTINGS  \
"scriptaddr=0x6d0\0"\
@@ -96,6 +106,7 @@
"kernel_addr=0x700\0"   \
"kernel_addr_r=0x700\0" \
"ramdisk_addr_r=0xa00\0"\
-   BOOTENV
+   BOOTENV \
+   ENV_RW_FILLER
 
 #endif /* _CONFIG_MVEBU_ARMADA_37XX_H */
-- 
2.20.1



[PATCH 1/3] env: Allow to set default_environment[] from board code via compile option DEFAULT_ENV_IS_RW

2020-12-23 Thread Pali Rohár
This change allows board code to modify default_environment[] array when
compile option DEFAULT_ENV_IS_RW is specified in board config file.

Some board default variables depend on runtime configuration which is not
known at compile time. Therefore allow to set default_environment[] array
as non-const and allow board code to modify it when it is needed.

Signed-off-by: Pali Rohár 
---
 include/env_default.h  | 2 ++
 include/env_internal.h | 4 
 2 files changed, 6 insertions(+)

diff --git a/include/env_default.h b/include/env_default.h
index 8a0c3057f0..ea31a8eddf 100644
--- a/include/env_default.h
+++ b/include/env_default.h
@@ -19,6 +19,8 @@ env_t embedded_environment __UBOOT_ENV_SECTION__(environment) 
= {
{
 #elif defined(DEFAULT_ENV_INSTANCE_STATIC)
 static char default_environment[] = {
+#elif defined(DEFAULT_ENV_IS_RW)
+uchar default_environment[] = {
 #else
 const uchar default_environment[] = {
 #endif
diff --git a/include/env_internal.h b/include/env_internal.h
index b26dc6239c..708c833a55 100644
--- a/include/env_internal.h
+++ b/include/env_internal.h
@@ -111,7 +111,11 @@ typedef struct environment_s {
 extern env_t embedded_environment;
 #endif /* ENV_IS_EMBEDDED */
 
+#ifdef DEFAULT_ENV_IS_RW
+extern unsigned char default_environment[];
+#else
 extern const unsigned char default_environment[];
+#endif
 
 #ifndef DO_DEPS_ONLY
 
-- 
2.20.1



[PATCH 0/3] arm: mvebu: Espressobin: Set default env values at runtime

2020-12-23 Thread Pali Rohár
This patch series set default env values of $fdtfile and $ethNaddr for
Espressobin board at runtime.

It fixes two main issues on Espressobin board that 'env default -a'
completely erases permanent board MAC addresses and also erase $fdtfile
variable which is needed for booting Linux kernel via distro boot.

Lot of people were complaining about erasing permanent MAC addresses by
U-boot on this board and due to this issue some linux distributions
started using static hardcoded MAC addresses for all Espressobin boards
to workaround this issue. Apparently erase of MAC addresses or usage of
static hardcoded value caused more issues on network (e.g. inability to
connect two of these boards to the same network).

Pali Rohár (3):
  env: Allow to set default_environment[] from board code via compile
option DEFAULT_ENV_IS_RW
  arm: mvebu: Espressobin: Set default value for $fdtfile env variable
  arm: mvebu: Espressobin: Set default value for $ethNaddr env variable

 board/Marvell/mvebu_armada-37xx/board.c | 41 -
 include/configs/mvebu_armada-37xx.h | 17 +-
 include/env_default.h   |  2 ++
 include/env_internal.h  |  4 +++
 4 files changed, 56 insertions(+), 8 deletions(-)

-- 
2.20.1



Re: [PATCH] efi_loader: Extra checks while opening an OPTEE session

2020-12-23 Thread Heinrich Schuchardt
Am 23. Dezember 2020 11:43:19 MEZ schrieb Ilias Apalodimas 
:
>When opening an OP-TEE session we need to check the internal return
>value of OP-TEE call arguments as well the return code of the
>function itself.
>The code was also ignoring to close the OP-TEE session in case the
>shared memory registration failed.
>
>Fixes: f042e47e8fb43 ("efi_loader: Implement EFI variable handling via
>OP-TEE")
>Signed-off-by: Ilias Apalodimas 
>---
> lib/efi_loader/efi_variable_tee.c | 10 ++
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
>diff --git a/lib/efi_loader/efi_variable_tee.c
>b/lib/efi_loader/efi_variable_tee.c
>index be6f3dfad469..717d0b45e7cd 100644
>--- a/lib/efi_loader/efi_variable_tee.c
>+++ b/lib/efi_loader/efi_variable_tee.c
>@@ -45,10 +45,11 @@ static int get_connection(struct mm_connection
>*conn)
>   memset(&arg, 0, sizeof(arg));
>   tee_optee_ta_uuid_to_octets(arg.uuid, &uuid);
>   rc = tee_open_session(tee, &arg, 0, NULL);
>-  if (!rc) {
>-  conn->tee = tee;
>-  conn->session = arg.session;
>-  }
>+  if (rc || arg.ret != TEE_SUCCESS)
>+  return rc == 0 ? -EIO : rc;

 Could you simplify this, please

if (rc)
 return rc;
if (arg.ret != TEE_SUCCESS)
return -EIO;

>+
>+  conn->tee = tee;
>+  conn->session = arg.session;
> 
>   return rc;

return 0;

Best regards

Heinrich

> }
>@@ -88,6 +89,7 @@ static efi_status_t optee_mm_communicate(void
>*comm_buf, ulong dsize)
> 
>   if (tee_shm_register(conn.tee, comm_buf, buf_size, 0, &shm)) {
>   log_err("Unable to register shared memory\n");
>+  tee_close_session(conn.tee, conn.session);
>   return EFI_UNSUPPORTED;
>   }
> 



Re: [PATCH v1] toradex: hand over maintainership

2020-12-23 Thread Oleksandr Suvorov
On Tue, Dec 22, 2020 at 5:57 PM Igor Opaniuk  wrote:
>
> From: Igor Opaniuk 
>
> Hand over maintainership of Toradex SoMs (that I was responsible of) to
> Oleksandr because of my resignation from Toradex, as such I will
> have no immediate involvement with these modules and as a result not
> able to continue maintaining these boards.
>
> CC: Oleksandr Suvorov 
> Signed-off-by: Igor Opaniuk 

Acked-by: Oleksandr Suvorov 

> ---
>
>  board/toradex/apalis-imx8x/MAINTAINERS| 2 +-
>  board/toradex/apalis_imx6/MAINTAINERS | 2 +-
>  board/toradex/colibri-imx6ull/MAINTAINERS | 2 +-
>  board/toradex/colibri_imx6/MAINTAINERS| 2 +-
>  board/toradex/colibri_imx7/MAINTAINERS| 2 +-
>  board/toradex/colibri_t20/MAINTAINERS | 2 +-
>  board/toradex/colibri_t30/MAINTAINERS | 2 +-
>  board/toradex/colibri_vf/MAINTAINERS  | 2 +-
>  board/toradex/verdin-imx8mm/MAINTAINERS   | 2 +-
>  9 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/board/toradex/apalis-imx8x/MAINTAINERS 
> b/board/toradex/apalis-imx8x/MAINTAINERS
> index fbf9379931..5272154447 100644
> --- a/board/toradex/apalis-imx8x/MAINTAINERS
> +++ b/board/toradex/apalis-imx8x/MAINTAINERS
> @@ -1,5 +1,5 @@
>  Apalis iMX8X
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  W: http://developer.toradex.com/software/linux/linux-software
>  S: Maintained
>  F: arch/arm/dts/fsl-imx8x-apalis.dts
> diff --git a/board/toradex/apalis_imx6/MAINTAINERS 
> b/board/toradex/apalis_imx6/MAINTAINERS
> index 4a2707e771..fde4d92dc3 100644
> --- a/board/toradex/apalis_imx6/MAINTAINERS
> +++ b/board/toradex/apalis_imx6/MAINTAINERS
> @@ -1,5 +1,5 @@
>  Apalis iMX6
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  W: http://developer.toradex.com/software/linux/linux-software
>  W:  https://www.toradex.com/community
>  S: Maintained
> diff --git a/board/toradex/colibri-imx6ull/MAINTAINERS 
> b/board/toradex/colibri-imx6ull/MAINTAINERS
> index 4107d29876..899b1ff555 100644
> --- a/board/toradex/colibri-imx6ull/MAINTAINERS
> +++ b/board/toradex/colibri-imx6ull/MAINTAINERS
> @@ -1,5 +1,5 @@
>  Colibri iMX6ULL
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  W: http://developer.toradex.com/software/linux/linux-software
>  W: https://www.toradex.com/community
>  S: Maintained
> diff --git a/board/toradex/colibri_imx6/MAINTAINERS 
> b/board/toradex/colibri_imx6/MAINTAINERS
> index 76f9446bba..2cbf65433d 100644
> --- a/board/toradex/colibri_imx6/MAINTAINERS
> +++ b/board/toradex/colibri_imx6/MAINTAINERS
> @@ -1,5 +1,5 @@
>  Colibri iMX6
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  W: http://developer.toradex.com/software/linux/linux-software
>  W:  https://www.toradex.com/community
>  S: Maintained
> diff --git a/board/toradex/colibri_imx7/MAINTAINERS 
> b/board/toradex/colibri_imx7/MAINTAINERS
> index 61a504487a..3d7d010d8a 100644
> --- a/board/toradex/colibri_imx7/MAINTAINERS
> +++ b/board/toradex/colibri_imx7/MAINTAINERS
> @@ -1,5 +1,5 @@
>  Colibri iMX7
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  W: http://developer.toradex.com/software/linux/linux-software
>  W: https://www.toradex.com/community
>  S: Maintained
> diff --git a/board/toradex/colibri_t20/MAINTAINERS 
> b/board/toradex/colibri_t20/MAINTAINERS
> index 2a8e6fb74b..61fbd2c1e0 100644
> --- a/board/toradex/colibri_t20/MAINTAINERS
> +++ b/board/toradex/colibri_t20/MAINTAINERS
> @@ -1,5 +1,5 @@
>  COLIBRI_T20
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  S: Maintained
>  F: board/toradex/colibri_t20/
>  F: include/configs/colibri_t20.h
> diff --git a/board/toradex/colibri_t30/MAINTAINERS 
> b/board/toradex/colibri_t30/MAINTAINERS
> index 00c03c89b8..ded9e28295 100644
> --- a/board/toradex/colibri_t30/MAINTAINERS
> +++ b/board/toradex/colibri_t30/MAINTAINERS
> @@ -1,5 +1,5 @@
>  Colibri T30
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  S: Maintained
>  F: board/toradex/colibri_t30/
>  F: include/configs/colibri_t30.h
> diff --git a/board/toradex/colibri_vf/MAINTAINERS 
> b/board/toradex/colibri_vf/MAINTAINERS
> index f94cc0fbe2..c6627654a2 100644
> --- a/board/toradex/colibri_vf/MAINTAINERS
> +++ b/board/toradex/colibri_vf/MAINTAINERS
> @@ -1,5 +1,5 @@
>  Colibri VFxx
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  W: http://developer.toradex.com/software/linux/linux-software
>  W: https://www.toradex.com/community
>  S: Maintained
> diff --git a/board/toradex/verdin-imx8mm/MAINTAINERS 
> b/board/toradex/verdin-imx8mm/MAINTAINERS
> index 2495696e9d..08c370178c 100644
> --- a/board/toradex/verdin-imx8mm/MAINTAINERS
> +++ b/board/toradex/verdin-imx8mm/MAINTAINERS
> @@ -1,5 +1,5 @@
>  Verdin iMX8M Mini
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  W: 
> https://www.toradex.com/computer-on-modules/verdin-arm-family/nxp-imx-8m-mini
>  S: Maintained
>  F: arch/arm/dts/imx8mm-verdin.dts
> --
> 2.25.1
>


-- 
Best regards

[PATCH] efi_loader: Extra checks while opening an OPTEE session

2020-12-23 Thread Ilias Apalodimas
When opening an OP-TEE session we need to check the internal return
value of OP-TEE call arguments as well the return code of the
function itself.
The code was also ignoring to close the OP-TEE session in case the
shared memory registration failed.

Fixes: f042e47e8fb43 ("efi_loader: Implement EFI variable handling via OP-TEE")
Signed-off-by: Ilias Apalodimas 
---
 lib/efi_loader/efi_variable_tee.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/efi_loader/efi_variable_tee.c 
b/lib/efi_loader/efi_variable_tee.c
index be6f3dfad469..717d0b45e7cd 100644
--- a/lib/efi_loader/efi_variable_tee.c
+++ b/lib/efi_loader/efi_variable_tee.c
@@ -45,10 +45,11 @@ static int get_connection(struct mm_connection *conn)
memset(&arg, 0, sizeof(arg));
tee_optee_ta_uuid_to_octets(arg.uuid, &uuid);
rc = tee_open_session(tee, &arg, 0, NULL);
-   if (!rc) {
-   conn->tee = tee;
-   conn->session = arg.session;
-   }
+   if (rc || arg.ret != TEE_SUCCESS)
+   return rc == 0 ? -EIO : rc;
+
+   conn->tee = tee;
+   conn->session = arg.session;
 
return rc;
 }
@@ -88,6 +89,7 @@ static efi_status_t optee_mm_communicate(void *comm_buf, 
ulong dsize)
 
if (tee_shm_register(conn.tee, comm_buf, buf_size, 0, &shm)) {
log_err("Unable to register shared memory\n");
+   tee_close_session(conn.tee, conn.session);
return EFI_UNSUPPORTED;
}
 
-- 
2.30.0.rc1



Re: [PATCH v2 1/2] lib: uuid: use RNG device if present

2020-12-23 Thread Torsten Duwe
On Sun, 20 Dec 2020 11:17:50 -0700
Simon Glass  wrote:

> Hi Torsten,
> 
> On Sun, 20 Dec 2020 at 10:00, Torsten Duwe  wrote:
> >
> > On Fri, 18 Dec 2020 19:29:12 -0700
> > Simon Glass  wrote:
> >
> > > > -   int i;
> > > > -
> > > > -   srand(get_ticks() + rand());
> > > > +   int i, ret;
> > > > +   struct udevice *devp;
> > > > +   u8 randv = 0;
> > > > +
> > > > +#if defined(CONFIG_DM_RNG)
> > >
> > > This seems a little backwards to me. The caller should request a
> > > RNG device, getting either a hardware one or a software one, and
> > > then call the uclass method to get the uuid.
> >
> > Strictly speaking, there's no such thing as a "software RNG". The
> > term "DRBG" was coined for accurateness, "deterministic random bit
> > generator". The oxymoron "deterministic random" pretty much nails
> > it. Alternatively, it can be called "pseudo" RNG.
> > rand() and srand() exactly implement such a mechanism already, with
> > low coding overhead. U-Boot runs fine with them most of the time,
> > but there are rare cases where real entropy would be needed. This
> > is what these two patches are about. In case there's more, I
> > already speculated about a centralised entity in my response to the
> > v1 cover letter, but for now these two changes should do.
> 
> I am used to the term pseudo-random, but it doesn't much matter what
> kind of random number is used. It is still covered by the RNG class.

Well, in these 2 cases, it _does_ matter. And besides, as I wrote
above, pseudo randomness is produced by the rand() function, and RNG
devices provide _real_ entropy to a system.

So, while every other entity in U-Boot is happy with a DRBG, a UUID and
a BOOTP delay need this real entropy, hence the different code, for a
start.

> You are currently burying device access in a utility function. That
> really isn't the right way to do it. See my comment above. There is no
> way to control which RNG device is used and no visibility that this is
> happening at all, outside this function.

The code looks a bit odd to me, too, as I mentioned. I imagined
something not so full blown as in the Linux kernel, but still some
central mechanism to get entropy from, for those who really need it (in
the current situation, just these 2 cases). This alternative would
result in a real /dev/random in U-Boot, which would yield a cleaner
structure, but would require more code to be produced and more code
needing change. That given, I'd agree to these 2 hacks, especially
because there are security implications. 

What's your opinion, how would you like to create really unique UUIDs?
How should BOOTP clients wait randomly (esp. in a large group)?
Shall we create some U-Boot version of /dev/random and haveged?

I'm really open to suggestions.

Torsten



Re: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-23 Thread André Przywara
On 23/12/2020 04:25, Jaehoon Chung wrote:
> On 12/23/20 11:22 AM, Amit Tomer wrote:
>> On Wed, Dec 23, 2020 at 5:57 AM André Przywara  
>> wrote:
>>>
>>> On 19/12/2020 14:51, Amit Singh Tomar wrote:
 From: Amit Singh Tomar 

 This commit adds support for MMC controllers found on Actions OWL
 S700 SoC platform.

 Signed-off-by: Amit Singh Tomar 
 ---
 Changes since previous version
   * Corrected block count to 512.
   * Changed the command timeout value to 30ms.
   * Used readl_poll_timeout.
   * Read DMA parameters from DT instead of hardcoding it.
   * Reduced number of arguments passed to own_dma_cofig.
   * Removed debug leftover.
   * Used mmc_of_parse().
 ---
  drivers/mmc/Kconfig   |   7 +
  drivers/mmc/Makefile  |   1 +
  drivers/mmc/owl_mmc.c | 399 
 ++
  3 files changed, 407 insertions(+)
  create mode 100644 drivers/mmc/owl_mmc.c

 diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
 index 14d7913..61f9c67 100644
 --- a/drivers/mmc/Kconfig
 +++ b/drivers/mmc/Kconfig
 @@ -289,6 +289,13 @@ config MMC_MXC

 If unsure, say N.

 +config MMC_OWL
 + bool "Actions OWL Multimedia Card Interface support"
 + depends on ARCH_OWL && DM_MMC && BLK
 + help
 +   This selects the OWL SD/MMC host controller found on board
 +   based on Actions S700 SoC.
>>>
>>> And S900 as well?
>>>
 +
  config MMC_MXS
   bool "Freescale MXS Multimedia Card Interface support"
   depends on MX23 || MX28 || MX6 || MX7
 diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
 index 1c849cb..f270f6c 100644
 --- a/drivers/mmc/Makefile
 +++ b/drivers/mmc/Makefile
 @@ -38,6 +38,7 @@ obj-$(CONFIG_MMC_OMAP_HS)   += omap_hsmmc.o
  obj-$(CONFIG_MMC_MXC)+= mxcmmc.o
  obj-$(CONFIG_MMC_MXS)+= mxsmmc.o
  obj-$(CONFIG_MMC_OCTEONTX)   += octeontx_hsmmc.o
 +obj-$(CONFIG_MMC_OWL)+= owl_mmc.o
  obj-$(CONFIG_MMC_PCI)+= pci_mmc.o
  obj-$(CONFIG_PXA_MMC_GENERIC) += pxa_mmc_gen.o
  obj-$(CONFIG_$(SPL_TPL_)SUPPORT_EMMC_RPMB) += rpmb.o
 diff --git a/drivers/mmc/owl_mmc.c b/drivers/mmc/owl_mmc.c
 new file mode 100644
 index 000..5c48307
 --- /dev/null
 +++ b/drivers/mmc/owl_mmc.c
 @@ -0,0 +1,399 @@
 +// SPDX-License-Identifier: GPL-2.0+
 +/*
 + * Copyright (C) 2020 Amit Singh Tomar 
 + *
 + * Driver for SD/MMC controller present on Actions Semi S700 SoC, based
 + * on Linux Driver "drivers/mmc/host/owl-mmc.c".
 + *
 + * Though, there is a bit (BSEL, BUS or DMA Special Channel Selection) 
 that
 + * controls the data transfer from SDx_DAT register either using CPU AHB 
 Bus
 + * or DMA channel, but seems like, it only works correctly using external 
 DMA
 + * channel, and those special bits used in this driver is picked from 
 vendor
 + * source exclusively for MMC/SD.
 + */
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +
 +/*
 + * SDC registers
 + */
 +#define OWL_REG_SD_EN   0x
 +#define OWL_REG_SD_CTL  0x0004
 +#define OWL_REG_SD_STATE0x0008
 +#define OWL_REG_SD_CMD  0x000c
 +#define OWL_REG_SD_ARG  0x0010
 +#define OWL_REG_SD_RSPBUF0  0x0014
 +#define OWL_REG_SD_RSPBUF1  0x0018
 +#define OWL_REG_SD_RSPBUF2  0x001c
 +#define OWL_REG_SD_RSPBUF3  0x0020
 +#define OWL_REG_SD_RSPBUF4  0x0024
 +#define OWL_REG_SD_DAT  0x0028
 +#define OWL_REG_SD_BLK_SIZE 0x002c
 +#define OWL_REG_SD_BLK_NUM  0x0030
 +#define OWL_REG_SD_BUF_SIZE 0x0034
 +
 +/* SD_EN Bits */
 +#define OWL_SD_EN_RANE  BIT(31)
 +#define OWL_SD_EN_RESE  BIT(10)
 +#define OWL_SD_ENABLE   BIT(7)
 +#define OWL_SD_EN_BSEL  BIT(6)
 +#define OWL_SD_EN_DATAWID(x)(((x) & 0x3) << 0)
 +#define OWL_SD_EN_DATAWID_MASK   0x03
 +
 +/* SD_CTL Bits */
 +#define OWL_SD_CTL_TOUTEN   BIT(31)
 +#define OWL_SD_CTL_DELAY_MSKGENMASK(23, 16)
 +#define OWL_SD_CTL_RDELAY(x)(((x) & 0xf) << 20)
 +#define OWL_SD_CTL_WDELAY(x)(((x) & 0xf) << 16)
 +#define OWL_SD_CTL_TS   BIT(7)
 +#define OWL_SD_CTL_LBE  BIT(6)
 +#define OWL_SD_CTL_TM(x)(((x) & 0xf)

Re: [PATCH v2 1/2] lib: uuid: use RNG device if present

2020-12-23 Thread Matthias Brugger
Hi Simon,

On 19/12/2020 03:29, Simon Glass wrote:
> Hi Mattias,
> 
> On Wed, 16 Dec 2020 at 09:28,  wrote:
>>
>> From: Matthias Brugger 
>>
>> When calculating a random UUID we use a weak seed.
>> Use a RNG device if present to increase entropy.
>>
>> Signed-off-by: Matthias Brugger 
>>
>> ---
>>
>> Changes in v2:
>> - fix dm_rng_read() parameters
>> - add missing include
>>
>>  lib/uuid.c | 21 ++---
>>  1 file changed, 18 insertions(+), 3 deletions(-)
>>
>> diff --git a/lib/uuid.c b/lib/uuid.c
>> index e62d5ca264..e3487380c3 100644
>> --- a/lib/uuid.c
>> +++ b/lib/uuid.c
>> @@ -15,6 +15,8 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>> +#include 
>>
>>  /*
>>   * UUID - Universally Unique IDentifier - 128 bits unique number.
>> @@ -249,9 +251,22 @@ void gen_rand_uuid(unsigned char *uuid_bin)
>>  {
>> u32 ptr[4];
>> struct uuid *uuid = (struct uuid *)ptr;
>> -   int i;
>> -
>> -   srand(get_ticks() + rand());
>> +   int i, ret;
>> +   struct udevice *devp;
>> +   u8 randv = 0;
>> +
>> +#if defined(CONFIG_DM_RNG)
> 
> This seems a little backwards to me. The caller should request a RNG
> device, getting either a hardware one or a software one, and then call
> the uclass method to get the uuid.
> 

The problem I see here is, that in case no DM_RNG is present the seed used is
different for uuid (get_ticks() + rand()) and bootp (seed_mac() uses the mac
address)

So we would need to pass this alternatives to the generic DM code, which makes
it a bit ugly. Apart from that beware that the seed used for srand() can vary
depending on the caller and the entropy it needs.

Regards,
Matthias

>> +   ret = uclass_get_device(UCLASS_RNG, 0, &devp);
>> +   if (ret) {
>> +   ret = dm_rng_read(devp, &randv, sizeof(randv));
>> +   if (ret < 0)
>> +   randv = 0;
>> +   }
>> +   if (randv)
>> +   srand(randv);
>> +   else
>> +#endif
>> +   srand(get_ticks() + rand());
>>
>> /* Set all fields randomly */
>> for (i = 0; i < 4; i++)
>> --
>> 2.29.2
>>
> 
> Regards,
> Simon
> 



Re: [PATCH 0/2] Add SIMATIC IOT2050 board support

2020-12-23 Thread Jan Kiszka
On 23.12.20 09:18, Lokesh Vutla wrote:
> 
> 
> On 18/12/20 11:43 am, Jan Kiszka wrote:
>> On 18.12.20 07:04, Jan Kiszka wrote:
>>> On 18.12.20 05:46, Lokesh Vutla wrote:
 Hi Jan,
Sorry for the delayed response.

 On 04/12/20 1:29 pm, Jan Kiszka wrote:
> This is the baseline support for the SIMATIC IOT2050 devices.
>
> Allows to boot mainline 5.10 kernels, but not the original BSP-derived
> kernel we currently ship as reference. This is due to the TI sysfw ABI
> breakages between 2.x and 3.x. We will soon provide a transitional
> kernel that allows booting both firmware ABIs - as long as full upstream
> kernel support is work in progress.
>
> Note that this baseline support lacks Ethernet drivers. We are working
> closely with TI to ensure that the to-be-upstreamed icssg-prueth driver
> will work both with new SR2.0 AM65x silicon as well as with SR1.0 which
> is used in the currently shipped IOT2050 devices.
>
> Related but not strictly needed for baseline support is [1], i.e.
> embedding of the watchdog firmware that is required on the AM65x. I will
> soon pick up that discussion again.

 yeah, long pending one.

>
> A staging tree for complete IOT2050 support can be found at [2]. Full
> image integration is available via [3].

 patches look good to me. Any chance these dts changes are reviewed in 
 upstream
 Linux?
>>>
>>> I didn't want to push them there first before publishing a firmware that
>>> allows to boot them - chicken-egg situation. I thought this way would be
>>> better and would also be no issue as we we are only using existing
>>> bindings. Obviously, any future changes to the kernel version would also
>>> be sync'ed back to U-Boot by us.
>>
>> But good that you mentioned it: I just realized that the path we are
>> using ("siemens/iot2050-{basic,advanced}.dtb") is probably not
>> upstreamable. This may have to become
>> "ti/k3-am65-iot2050-{basic,advanced}.dtb", and that is also an interface
>> between kernel and U-Boot...
>>
> 
> Planning to repost the series?
> 

Eventually. But we will likely follow your suggestion and first get the
DTs upstream into the kernel.

Jan

-- 
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux


RE: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-23 Thread Peng Fan
Thanks for Cc.

> Subject: Re: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL
> S700
> 
> Hi Amit,
> 
> On 12/23/20 2:59 PM, Amit Tomar wrote:
> > Hi Jaehoon
> >
> > I had already mentioned about making more readable than now.
> >
> >>
> >> if (rate <= 100) {
> >> rdelay = wdelay = OWL_SD_DELAY_LOW_CLK; } else if ( ...) {
> >> rdelay = wdelay = OWL_SD_DELAY_MID_CLK; } else if () {
> >> rdelay = OWL_SD_RDELAY_HIGH;
> >> wdelay = OWL_SD_WDELAY_HIGH;
> >> }
> >>
> >> writel(reg | OWL_SD_CTRL_RDELAY(rdelay) |
> >> OWL_SD_CTL_WDELAY(wdelay)...);
> >>
> >> There are many approach to make readable..but Amit mentioned it's
> >> using same code in Linux kernel driver.
> >>
> >> To be honest, this is *not* the reason but if you see controller also
> >> supports DDR50 mode(which we may support in future)
> >
> >where we have different values for read and write delays and we may
> > need that many variables to write it cleanly.
> >
> >But if this is not the problem , I will implement the changes as
> > suggested by you.
> 
> Frankly, i don't have any objection about your patch. :) Just curious about
> other driver what using same code with kernel, not only this driver.
> 
> I will follow Peng's opinion.

I am fine if the driver follows Linux kernel driver implementation.

Thanks,
Peng.

> 
> 
> Best Regards,
> Jaehoon Chung
> 
> >
> >>
> >>> Thanks
> >>> -Amit
> >>>
> >>
> >>
> >



Re: [PATCH v1] toradex: hand over maintainership

2020-12-23 Thread Oleksandr Suvorov
On Tue, Dec 22, 2020 at 5:57 PM Igor Opaniuk  wrote:
>
> From: Igor Opaniuk 
>
> Hand over maintainership of Toradex SoMs (that I was responsible of) to
> Oleksandr because of my resignation from Toradex, as such I will
> have no immediate involvement with these modules and as a result not
> able to continue maintaining these boards.
>
> CC: Oleksandr Suvorov 
> Signed-off-by: Igor Opaniuk 

Reviewed-by: Oleksandr Suvorov 

> ---
>
>  board/toradex/apalis-imx8x/MAINTAINERS| 2 +-
>  board/toradex/apalis_imx6/MAINTAINERS | 2 +-
>  board/toradex/colibri-imx6ull/MAINTAINERS | 2 +-
>  board/toradex/colibri_imx6/MAINTAINERS| 2 +-
>  board/toradex/colibri_imx7/MAINTAINERS| 2 +-
>  board/toradex/colibri_t20/MAINTAINERS | 2 +-
>  board/toradex/colibri_t30/MAINTAINERS | 2 +-
>  board/toradex/colibri_vf/MAINTAINERS  | 2 +-
>  board/toradex/verdin-imx8mm/MAINTAINERS   | 2 +-
>  9 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/board/toradex/apalis-imx8x/MAINTAINERS 
> b/board/toradex/apalis-imx8x/MAINTAINERS
> index fbf9379931..5272154447 100644
> --- a/board/toradex/apalis-imx8x/MAINTAINERS
> +++ b/board/toradex/apalis-imx8x/MAINTAINERS
> @@ -1,5 +1,5 @@
>  Apalis iMX8X
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  W: http://developer.toradex.com/software/linux/linux-software
>  S: Maintained
>  F: arch/arm/dts/fsl-imx8x-apalis.dts
> diff --git a/board/toradex/apalis_imx6/MAINTAINERS 
> b/board/toradex/apalis_imx6/MAINTAINERS
> index 4a2707e771..fde4d92dc3 100644
> --- a/board/toradex/apalis_imx6/MAINTAINERS
> +++ b/board/toradex/apalis_imx6/MAINTAINERS
> @@ -1,5 +1,5 @@
>  Apalis iMX6
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  W: http://developer.toradex.com/software/linux/linux-software
>  W:  https://www.toradex.com/community
>  S: Maintained
> diff --git a/board/toradex/colibri-imx6ull/MAINTAINERS 
> b/board/toradex/colibri-imx6ull/MAINTAINERS
> index 4107d29876..899b1ff555 100644
> --- a/board/toradex/colibri-imx6ull/MAINTAINERS
> +++ b/board/toradex/colibri-imx6ull/MAINTAINERS
> @@ -1,5 +1,5 @@
>  Colibri iMX6ULL
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  W: http://developer.toradex.com/software/linux/linux-software
>  W: https://www.toradex.com/community
>  S: Maintained
> diff --git a/board/toradex/colibri_imx6/MAINTAINERS 
> b/board/toradex/colibri_imx6/MAINTAINERS
> index 76f9446bba..2cbf65433d 100644
> --- a/board/toradex/colibri_imx6/MAINTAINERS
> +++ b/board/toradex/colibri_imx6/MAINTAINERS
> @@ -1,5 +1,5 @@
>  Colibri iMX6
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  W: http://developer.toradex.com/software/linux/linux-software
>  W:  https://www.toradex.com/community
>  S: Maintained
> diff --git a/board/toradex/colibri_imx7/MAINTAINERS 
> b/board/toradex/colibri_imx7/MAINTAINERS
> index 61a504487a..3d7d010d8a 100644
> --- a/board/toradex/colibri_imx7/MAINTAINERS
> +++ b/board/toradex/colibri_imx7/MAINTAINERS
> @@ -1,5 +1,5 @@
>  Colibri iMX7
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  W: http://developer.toradex.com/software/linux/linux-software
>  W: https://www.toradex.com/community
>  S: Maintained
> diff --git a/board/toradex/colibri_t20/MAINTAINERS 
> b/board/toradex/colibri_t20/MAINTAINERS
> index 2a8e6fb74b..61fbd2c1e0 100644
> --- a/board/toradex/colibri_t20/MAINTAINERS
> +++ b/board/toradex/colibri_t20/MAINTAINERS
> @@ -1,5 +1,5 @@
>  COLIBRI_T20
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  S: Maintained
>  F: board/toradex/colibri_t20/
>  F: include/configs/colibri_t20.h
> diff --git a/board/toradex/colibri_t30/MAINTAINERS 
> b/board/toradex/colibri_t30/MAINTAINERS
> index 00c03c89b8..ded9e28295 100644
> --- a/board/toradex/colibri_t30/MAINTAINERS
> +++ b/board/toradex/colibri_t30/MAINTAINERS
> @@ -1,5 +1,5 @@
>  Colibri T30
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  S: Maintained
>  F: board/toradex/colibri_t30/
>  F: include/configs/colibri_t30.h
> diff --git a/board/toradex/colibri_vf/MAINTAINERS 
> b/board/toradex/colibri_vf/MAINTAINERS
> index f94cc0fbe2..c6627654a2 100644
> --- a/board/toradex/colibri_vf/MAINTAINERS
> +++ b/board/toradex/colibri_vf/MAINTAINERS
> @@ -1,5 +1,5 @@
>  Colibri VFxx
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  W: http://developer.toradex.com/software/linux/linux-software
>  W: https://www.toradex.com/community
>  S: Maintained
> diff --git a/board/toradex/verdin-imx8mm/MAINTAINERS 
> b/board/toradex/verdin-imx8mm/MAINTAINERS
> index 2495696e9d..08c370178c 100644
> --- a/board/toradex/verdin-imx8mm/MAINTAINERS
> +++ b/board/toradex/verdin-imx8mm/MAINTAINERS
> @@ -1,5 +1,5 @@
>  Verdin iMX8M Mini
> -M: Igor Opaniuk 
> +M: Oleksandr Suvorov 
>  W: 
> https://www.toradex.com/computer-on-modules/verdin-arm-family/nxp-imx-8m-mini
>  S: Maintained
>  F: arch/arm/dts/imx8mm-verdin.dts
> --
> 2.25.1
>


-- 
Best regar

Re: [PATCH v6 00/28] Add DM support for omap PWM backlight

2020-12-23 Thread Dario Binacchi
Hi Lokesh,

> Il 23/12/2020 08:57 Lokesh Vutla  ha scritto:
> 
>  
> On 23/12/20 12:00 am, Dario Binacchi wrote:
> > Hi Lokesh,
> > 
> >> Il 22/12/2020 14:52 Lokesh Vutla  ha scritto:
> >>
> >>  
> >> Hi Dario,
> >>
> >> On 22/11/20 9:41 pm, Dario Binacchi wrote:
> >>>
> >>> The series was born from the need to manage the PWM backlight of the
> >>> display connected to my beaglebone board. To hit the target, I had to
> >>> develop drivers for PWM management which in turn relied on drivers for
> >>> managing timers and clocks, all developed according to the driver model.
> >>> My intention was to use the SoC-specific API only at strictly necessary
> >>> points in the code. My previous patches for migrating the AM335x display
> >>> driver to the driver model had required the implementation of additional
> >>> functions outside the concerns of the driver, (settings for dividing the
> >>> pixel clock rate, configuring the display DPLL rate, ) not being
> >>> able to use the API of the related clock drivers. This series shouldn't
> >>> have repeated the same kind of mistake. Furthermore, I also wanted to fix
> >>> that kind of forced choice. Almost everything should have been accessible
> >>> via the driver model API. In the series there are also some patches that
> >>> could be submitted separately, but which I have however inserted to avoid
> >>> applying future patches to incorporate them.
> >>> With this last consideration, I hope I have convincingly justified the
> >>> large number of patches in the series.
> >>>
> >>> The patch enabling address translation into a CPU physical address from
> >>> device-tree even in case of crossing levels with #size-cells = <0>, is
> >>> crucial for the series. The previous implementation was unable to
> >>> perform the address translation required by the am33xx device tree.
> >>> I tried to apply in a conservative way as few changes as possible and
> >>> to verify the execution of all the tests already developed, as well as
> >>> the new ones I added for the new feature.
> >>>
> >>> The patch series can be cleanly applied to the HEAD of the master which
> >>> at the time of release points to 12e396303c commit.
> >>
> >> Are we waiting for any other reviews? TI part looks good to me.
> > 
> > Everything is reviewed. There are no pending reviews.
> > 
> >> If everything else is reviewed, Ill merge the series.
> >>
> > 
> > Do you need the series to be rebased on master? 
> > I uploaded it just a month ago
> 
> This series is causing build error for powerpc platforms. Can you take a look?
> https://gitlab.denx.de/u-boot/custodians/u-boot-ti/-/jobs/193065
> 

I think CONFIG_DM is not enabled, so dm_flags is not added in 'struct 
global_data' by
the C preprocessor. 
Moving dm_flags out of '#ifdef CONFIG_DM' in 'struct global_data', would fix 
the error
but I don't think that's the right way. I think it is more correct to consider 
dm_flags only when CONFIG_DM is enabled.

Thanks and regards,
Dario

> Thanks and regards,
> Lokesh
> 
> > 
> >> Please CC me for all the series next time else it is difficult for me to 
> >> track
> >> the comments
> >>
> > 
> > Ok, I will do it.
> > 
> > Thanks and regards,
> > Dario
> > 
> >> Thanks and regards,
> >> Lokesh
> >>
> >>>
> >>> Changes in v6:
> >>> - Remove the 'am3-prcm' driver.
> >>> - Add the 'simple-bus' compatible string to the prcm_clocks node.
> >>> - Remove the 'am3-scm' driver.
> >>> - Add the 'simple-bus' compatible string to the scm_clocks node.
> >>>
> >>> Changes in v5:
> >>> - Create drivers/clk/ti directory.
> >>> - Move the clk-ti-mux.c file to drivers/clk/ti and rename it clk-mux.c
> >>> - Move the clk-ti-am3-dpll.c file to drivers/clk/ti with the name
> >>>   clk-am3-dpll.c.
> >>> - Move the clk-ti-am3-dpll-x2.c file to drivers/clk/ti with the name
> >>>   clk-am3-dpll-x2.c.
> >>> - Move the clk-ti.c file to drivers/clk/ti with the name clk.c.
> >>> - Move the clk-ti.h file to drivers/clk/ti with the name clk.h.
> >>> - Move the clk-ti-divider.c file to drivers/clk/ti with the name
> >>>   clk-divider.c.
> >>> - Move the clk-ti-gate.c file to drivers/clk/ti with the name
> >>>   clk-gate.c.
> >>> - Move the clk-ti-ctrl.c file to drivers/clk/ti with the name
> >>>   clk-ctrl.c.
> >>>
> >>> Changes in v4:
> >>> - Include device_compat.h header for dev_xxx macros.
> >>> - Remove a blank line at end of file arch/arm/dts/am33xx-l4.dtsi.
> >>> - Update clk_round_rate description.
> >>> - Add Sean Anderson review.
> >>> - Include device_compat.h header for dev_xxx macros.
> >>> - Include device_compat.h header for dev_xxx macros.
> >>> - Fix compilation errors on the dev parameter of the dev_xx macros.
> >>> - Include device_compat.h header for dev_xxx macros.
> >>> - Fix compilation errors on the dev parameter of the dev_xx macros.
> >>> - Include device_compat.h header for dev_xxx macros.
> >>> - Include device_compat.h header for dev_xxx macros.
> >>> - Fix compilation errors on the dev parameter of the dev_xx macros

Re: [RESEND PATCH 1/2] usb: xhci-mtk: support option to disable ports

2020-12-23 Thread Marek Vasut

On 12/23/20 2:52 AM, Chunfeng Yun wrote:

Add support to disable specific ports, it's useful for some
scenarios:
1. usb3 PHY is shared whith PCIe or SATA, the corresponding
usb3 port can be disabled;
2. some usb2 or usb3 ports are not used on special platforms,
they should be disabled to save power.


Applied both, thanks.


Re: [PATCH] arm:pdu001: Use pseudo partition UUID for LINUX kernel boot paramter root

2020-12-23 Thread Lokesh Vutla



On 18/12/20 1:33 pm, Felix Brack wrote:
> As more and more LINUX drivers are modified to use asynchronous probing
> instead of synchronous probing, relying on device names being equal in
> U-Boot and LINUX is not possible anymore. This is also true for block
> device names like mmc0, mmc1 ect.
> With LINUX kernel commit a1a4891 the probing type for the sdhci-omap
> driver has been set to asynchronous mode too (probe_type is now
> PROBE_PREFER_ASYNCHRONOUS).
> In the case of the PDU001 board this results in the devices mmc0 and
> mmc1 being swapped between U-Boot and LINUX. Device mmc0 in U-Boot
> becomes mmc1 in LINUX an vice versa. Hence using device name identifiers
> with LINUX kernel parameter root does not work anymore.
> This patch changes the LINUX kernel boot parameter root to use the
> pseudo (since we use MBR not GPT) partition UUID to locate the partition
> hosting the root file system.
> 
> Signed-off-by: Felix Brack 


Applied to u-boot-ti/for-next

Thanks and regards,
Lokesh



Re: [PATCH 0/2] Add SIMATIC IOT2050 board support

2020-12-23 Thread Lokesh Vutla



On 18/12/20 11:43 am, Jan Kiszka wrote:
> On 18.12.20 07:04, Jan Kiszka wrote:
>> On 18.12.20 05:46, Lokesh Vutla wrote:
>>> Hi Jan,
>>> Sorry for the delayed response.
>>>
>>> On 04/12/20 1:29 pm, Jan Kiszka wrote:
 This is the baseline support for the SIMATIC IOT2050 devices.

 Allows to boot mainline 5.10 kernels, but not the original BSP-derived
 kernel we currently ship as reference. This is due to the TI sysfw ABI
 breakages between 2.x and 3.x. We will soon provide a transitional
 kernel that allows booting both firmware ABIs - as long as full upstream
 kernel support is work in progress.

 Note that this baseline support lacks Ethernet drivers. We are working
 closely with TI to ensure that the to-be-upstreamed icssg-prueth driver
 will work both with new SR2.0 AM65x silicon as well as with SR1.0 which
 is used in the currently shipped IOT2050 devices.

 Related but not strictly needed for baseline support is [1], i.e.
 embedding of the watchdog firmware that is required on the AM65x. I will
 soon pick up that discussion again.
>>>
>>> yeah, long pending one.
>>>

 A staging tree for complete IOT2050 support can be found at [2]. Full
 image integration is available via [3].
>>>
>>> patches look good to me. Any chance these dts changes are reviewed in 
>>> upstream
>>> Linux?
>>
>> I didn't want to push them there first before publishing a firmware that
>> allows to boot them - chicken-egg situation. I thought this way would be
>> better and would also be no issue as we we are only using existing
>> bindings. Obviously, any future changes to the kernel version would also
>> be sync'ed back to U-Boot by us.
> 
> But good that you mentioned it: I just realized that the path we are
> using ("siemens/iot2050-{basic,advanced}.dtb") is probably not
> upstreamable. This may have to become
> "ti/k3-am65-iot2050-{basic,advanced}.dtb", and that is also an interface
> between kernel and U-Boot...
> 

Planning to repost the series?

Thanks and regards,
Lokesh

> Jan
> 


Re: [PATCH] arm: dts: k3-j721e: ddr: Update to 0.5.0 version of DDR config tool

2020-12-23 Thread Lokesh Vutla



On 04/12/20 5:13 am, prane...@ti.com wrote:
> From: Praneeth Bajjuri 
> 
> Update the ddr settings to use the DDR reg config tool rev 0.5.0.
> This enables 4266MTs DDR configuration.
> 
> Signed-off-by: Praneeth Bajjuri 
> Signed-off-by: Kevin Scholz 


Applied to u-boot-ti/for-next

Thanks and regards,
Lokesh



Re: [PATCH] spi: omap3_spi: Fix speed and mode selection

2020-12-23 Thread Lokesh Vutla



On 29/11/20 12:53 pm, Vignesh Raghavendra wrote:
> McSPI IP provides per CS specific speed and mode selection. Therefore it
> is possible to apply these settings only after CS is known. But
> set_speed and set_mode can be called without bus being claimed, this
> would lead driver to set up wrong CS (or previously used CS).
> 
> Fix this by apply set_speed and set_mode only if bus is already claimed.
> 
> Signed-off-by: Vignesh Raghavendra 
> ---
>  drivers/spi/omap3_spi.c | 17 ++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 


Applied to u-boot-ti/for-next

Thanks and regards,
Lokesh



Re: [PATCH] spi: ti_qspi: Fix "spi-max-frequency" error path in ti_qspi_ofdata_to_platdata

2020-12-23 Thread Lokesh Vutla



On 28/11/20 1:41 pm, Ovidiu Panait wrote:
> struct ti_qspi_priv->max_hz is declared as unsigned int, so the following
> error path check will always be false, even when "spi-max-frequency"
> property is invalid/missing:
>   priv->max_hz = fdtdec_get_int(blob, node, "spi-max-frequency", -1);
>   if (priv->max_hz < 0) {
> ...
>   }
> 
> Replace the fdtdec call with dev_read_u32_default() and use 0 as the
> default value. Error out if max_hz is zero.
> 
> Signed-off-by: Ovidiu Panait 


Applied to u-boot-ti/for-next

Thanks and regards,
Lokesh



Re: [PATCH] gpio: tca642x: fix input subcommand for gpio banks > 0

2020-12-23 Thread Lokesh Vutla



On 25/11/20 11:12 pm, Tomas Novotny wrote:
> The value of input pin for bank > 0 is always 0 for input subcommand.
> The reason is that gpio_bank variable is computed only for invert and
> output subcommands (it depends on number of arguments). The default
> value of zero causes to shift the mask away for banks > 0.
> 
> Please note that info subcommand works as expected, because the input
> pin values are accessed differently.
> 
> Fixes: 61c1775f16ed ("gpio: tca642x: Add the tca642x gpio expander driver")
> Cc: Dan Murphy 
> Signed-off-by: Tomas Novotny 


Applied to u-boot-ti/for-next

Thanks and regards,
Lokesh


Re: [PATCH] configs: am65x_evm: Define the maximum file size for DFU

2020-12-23 Thread Lokesh Vutla



On 24/11/20 3:59 pm, Aswath Govindraju wrote:
> In include/dfu.h, if CONFIG_SYS_DFU_MAX_FILE_SIZE is not defined then it is
> defined as CONFIG_SYS_DFU_DATA_BUF_SIZE. This is 128 KiB for a53 core and
> 20 KiB for r5 core. If a larger file is transferred using dfu then it
> fails.
> 
> CONFIG_SYS_DFU_DATA_BUF_SIZE can not be increased as there is not enough
> heap memory to be allocated for the buffer in case of R5 spl.
> 
> Fix this by defining CONFIG_SYS_DFU_MAX_FILE_SIZE as the default
> CONFIG_SYS_DFU_DATA_BUF_SIZE value.
> 
> Signed-off-by: Aswath Govindraju 

Applied to u-boot-ti/for-next

Thanks and regards,
Lokesh

> ---
>  include/configs/am65x_evm.h | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/include/configs/am65x_evm.h b/include/configs/am65x_evm.h
> index 41c62785e438..9d9d0c93a206 100644
> --- a/include/configs/am65x_evm.h
> +++ b/include/configs/am65x_evm.h
> @@ -56,6 +56,12 @@
>  #define CONFIG_SKIP_LOWLEVEL_INIT
>  #endif
>  
> +/*
> + * If the maximum size is not declared then it is defined as
> + * CONFIG_SYS_DFU_DATA_BUF_SIZE.
> + */
> +#define CONFIG_SYS_DFU_MAX_FILE_SIZE (1024 * 1024 * 8)   /* 8 MiB */
> +
>  #define CONFIG_SPL_MAX_SIZE  CONFIG_SYS_K3_MAX_DOWNLODABLE_IMAGE_SIZE
>  
>  #define CONFIG_SYS_BOOTM_LEN SZ_64M
> 


Re: [PATCH 0/3] usb: am654: Add support for host mode to the USB port on overlay board

2020-12-23 Thread Lokesh Vutla



On 20/11/20 9:18 pm, Aswath Govindraju wrote:
> The following series of patches
>  - adds support for host mode to USB3SS0 controller
>  - adds aliases for USB subsystems
>  - adds a workaround to use USB0 in USB 2.0 only mode

Fixed the dts patches subject to arm: dts:  and
applied to u-boot-ti for-next branch.

Thanks and regards,
Lokesh

> 
> Aswath Govindraju (3):
>   board: ti: am65x: Set SERDES0 mux to PCIe to use USB 2.0 interface
>   dts: am654-base-board-uboot: Set USB0 dr_mode to host
>   dts: am654-base-board-uboot: Add aliases for USB subsystems
> 
>  arch/arm/dts/k3-am654-base-board-u-boot.dtsi |  4 +++-
>  board/ti/am65x/evm.c | 16 
>  2 files changed, 19 insertions(+), 1 deletion(-)
> 


Re: [PATCH] drivers: tee: i2c trampoline driver

2020-12-23 Thread Jens Wiklander
Hi Jorge,

On Mon, Dec 21, 2020 at 07:15:40PM +0100, Jorge Ramirez-Ortiz wrote:
> This commit gives the secure world access to the I2C bus so it can
> communicate with I2C slaves (tipically those would be secure elements
> like the NXP SE050).
> 
> Tested on imx8mmevk.
> 
> Signed-off-by: Jorge Ramirez-Ortiz 
> ---
>  drivers/tee/optee/Makefile   |  1 +
>  drivers/tee/optee/i2c.c  | 88 
>  drivers/tee/optee/optee_msg.h| 22 ++
>  drivers/tee/optee/optee_msg_supplicant.h |  5 ++
>  drivers/tee/optee/optee_private.h| 12 
>  drivers/tee/optee/supplicant.c   |  3 +
>  6 files changed, 131 insertions(+)
>  create mode 100644 drivers/tee/optee/i2c.c
> 
> diff --git a/drivers/tee/optee/Makefile b/drivers/tee/optee/Makefile
> index 928d3f8002..068c6e7aa1 100644
> --- a/drivers/tee/optee/Makefile
> +++ b/drivers/tee/optee/Makefile
> @@ -2,4 +2,5 @@
>  
>  obj-y += core.o
>  obj-y += supplicant.o
> +obj-$(CONFIG_DM_I2C) += i2c.o
>  obj-$(CONFIG_SUPPORT_EMMC_RPMB) += rpmb.o
> diff --git a/drivers/tee/optee/i2c.c b/drivers/tee/optee/i2c.c
> new file mode 100644
> index 00..2ebbf1ff7c
> --- /dev/null
> +++ b/drivers/tee/optee/i2c.c
> @@ -0,0 +1,88 @@
> +// SPDX-License-Identifier: BSD-2-Clause
> +/*
> + * Copyright (c) 2020 Foundries.io Ltd
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "optee_msg.h"
> +#include "optee_private.h"
> +
> +static struct {
> + struct udevice *dev;
> + int chip;
> + int bus;
> +} xfer;
> +
> +void optee_suppl_cmd_i2c_transfer(struct udevice *dev,
> +   struct optee_msg_arg *arg)
> +{
> + const uint64_t attr[] = {
A u8 instead of uint64_t would give the same result.

> + OPTEE_MSG_ATTR_TYPE_VALUE_INPUT,
> + OPTEE_MSG_ATTR_TYPE_VALUE_INPUT,
> + OPTEE_MSG_ATTR_TYPE_RMEM_INOUT,
> + OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT,
> + };
> + struct udevice *chip_dev = NULL;
> + struct tee_shm *shm = NULL;
> + uint8_t *buf = NULL;
> + size_t len = 0;
> + int chip = -1;
> + int bus = -1;
> + int ret = -1;
> +
> + if (arg->num_params != ARRAY_SIZE(attr) ||
> + arg->params[0].attr != attr[0] ||
> + arg->params[1].attr != attr[1] ||
> + arg->params[2].attr != attr[2] ||
> + arg->params[3].attr != attr[3]) {
> + arg->ret = TEE_ERROR_BAD_PARAMETERS;
> + return;
> + }
> +
> + len = arg->params[2].u.tmem.size;
> + shm = (struct tee_shm *)(unsigned long)arg->params[2].u.tmem.shm_ref;
Please replace tmem with rmem. The OPTEE_MSG_ATTR_TYPE_RMEM_INOUT above
indicates that we're dealing with a struct optee_msg_param_rmem.

> + buf = shm->addr;
> + if (!buf || !len)
> + goto bad;
> +
> + bus = (int)arg->params[0].u.value.b;
> + chip = (int)arg->params[0].u.value.c;
> +
> + if (!xfer.dev || xfer.chip != chip || xfer.bus != bus) {
> + if (i2c_get_chip_for_busnum(bus, chip, 0, &chip_dev))
> + goto bad;
> +
> + xfer.dev = chip_dev;
> + xfer.chip = chip;
> + xfer.bus = bus;
Is this caching safe? No risk of using stale data?

Thanks,
Jens

> + }
> +
> + if (arg->params[1].u.value.a & OPTEE_MSG_RPC_CMD_I2C_FLAGS_TEN_BIT)
> + if (i2c_set_chip_flags(xfer.dev, DM_I2C_CHIP_10BIT))
> + goto bad;
> +
> + switch (arg->params[0].u.value.a) {
> + case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_RD:
> + ret = dm_i2c_read(xfer.dev, 0, buf, len);
> + break;
> + case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_WR:
> + ret = dm_i2c_write(xfer.dev, 0, buf, len);
> + break;
> + default:
> + goto bad;
> + }
> +
> + if (ret) {
> + arg->ret = TEE_ERROR_COMMUNICATION;
> + } else {
> + arg->params[3].u.value.a = len;
> + arg->ret = TEE_SUCCESS;
> + }
> +
> + return;
> +bad:
> + arg->ret = TEE_ERROR_BAD_PARAMETERS;
> +}
> diff --git a/drivers/tee/optee/optee_msg.h b/drivers/tee/optee/optee_msg.h
> index 24c60960fc..7cedb59a82 100644
> --- a/drivers/tee/optee/optee_msg.h
> +++ b/drivers/tee/optee/optee_msg.h
> @@ -422,4 +422,26 @@ struct optee_msg_arg {
>   */
>  #define OPTEE_MSG_RPC_CMD_SHM_FREE   7
>  
> +/*
> + * Access a device on an i2c bus
> + *
> + * [in]  param[0].u.value.a  mode: RD(0), WR(1)
> + * [in]  param[0].u.value.b  i2c adapter
> + * [in]  param[0].u.value.c  i2c chip
> + *
> + * [in]  param[1].u.value.a  i2c control flags
> + * [in]  param[1].u.value.b  i2c retry (optional)
> + *
> + * [in/out] memref[2]buffer to exchange the transfer 
> data
> + *   with the secure world
> + *
> + * [out]  param[3].u.value.a bytes transferred by the driver
> + */
> +#define OPTEE_MSG_RPC_CMD

<    1   2