Re: [PATCH v1] stm32mp1: read auth stats and boot_partition from tamp

2023-11-08 Thread Patrice CHOTARD



On 11/6/23 11:41, Igor Opaniuk wrote:
> Obtain from TAMP backup register information about image authorization
> status and partition id used for booting. Store this info in
> environmental variables ("boot_auth" and "boot_part" correspondingly).
> 
> Image authorization supported values:
> 0x0 - No authentication done
> 0x1 - Authentication done and failed
> 0x2 - Authentication done and succeeded
> 
> These values are stored to TAMP backup register by Trusted Firmware-A [1].
> 
> Testing:
> STM32MP> print boot_part
> boot_part=1
> STM32MP> print boot_auth
> boot_auth=2
> 
> [1] 
> https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/commit/?h=refs/heads/integration=ab2b325c1ab895e626d4e11a9f26b9e7c968f8d8
> 
> Signed-off-by: Igor Opaniuk 
> Co-developed-by: Oleksandr Suvorov 
> Signed-off-by: Oleksandr Suvorov 
> 
> ---
> 
>  arch/arm/mach-stm32mp/cpu.c   | 23 +++
>  arch/arm/mach-stm32mp/include/mach/stm32.h|  4 
>  .../arm/mach-stm32mp/include/mach/sys_proto.h |  3 +++
>  3 files changed, 30 insertions(+)
> 
> diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c
> index e07abbe21c1..ba5942848bd 100644
> --- a/arch/arm/mach-stm32mp/cpu.c
> +++ b/arch/arm/mach-stm32mp/cpu.c
> @@ -40,6 +40,13 @@ u32 get_bootmode(void)
>   TAMP_BOOT_MODE_SHIFT;
>  }
>  
> +u32 get_bootauth(void)
> +{
> + /* read boot auth status and partition from TAMP backup register */
> + return (readl(TAMP_BOOT_CONTEXT) & TAMP_BOOT_AUTH_MASK) >>
> + TAMP_BOOT_AUTH_SHIFT;
> +}
> +
>  /*
>   * weak function overidde: set the DDR/SYSRAM executable before to enable the
>   * MMU and configure DACR, for early early_enable_caches (SPL or pre-reloc)
> @@ -371,8 +378,24 @@ __weak void stm32mp_misc_init(void)
>  {
>  }
>  
> +static int setup_boot_auth_info(void)
> +{
> + char buf[10];
> + u32 bootauth = get_bootauth();
> +
> + snprintf(buf, sizeof(buf), "%d", bootauth >> 4);
> + env_set("boot_auth", buf);
> +
> + snprintf(buf, sizeof(buf), "%d", bootauth &
> +  (u32)TAMP_BOOT_PARTITION_MASK);
> + env_set("boot_part", buf);
> +
> + return 0;
> +}
> +
>  int arch_misc_init(void)
>  {
> + setup_boot_auth_info();
>   setup_boot_mode();
>   setup_mac_address();
>   setup_serial_number();
> diff --git a/arch/arm/mach-stm32mp/include/mach/stm32.h 
> b/arch/arm/mach-stm32mp/include/mach/stm32.h
> index 1cdc5e3b186..ac0deced67e 100644
> --- a/arch/arm/mach-stm32mp/include/mach/stm32.h
> +++ b/arch/arm/mach-stm32mp/include/mach/stm32.h
> @@ -139,8 +139,12 @@ enum boot_device {
>  
>  #define TAMP_BOOT_MODE_MASK  GENMASK(15, 8)
>  #define TAMP_BOOT_MODE_SHIFT 8
> +#define TAMP_BOOT_AUTH_MASK  GENMASK(23, 16)
> +#define TAMP_BOOT_AUTH_SHIFT 16
>  #define TAMP_BOOT_DEVICE_MASKGENMASK(7, 4)
>  #define TAMP_BOOT_INSTANCE_MASK  GENMASK(3, 0)
> +#define TAMP_BOOT_AUTH_ST_MASK   GENMASK(7, 4)
> +#define TAMP_BOOT_PARTITION_MASK GENMASK(3, 0)
>  #define TAMP_BOOT_FORCED_MASKGENMASK(7, 0)
>  
>  enum forced_boot_mode {
> diff --git a/arch/arm/mach-stm32mp/include/mach/sys_proto.h 
> b/arch/arm/mach-stm32mp/include/mach/sys_proto.h
> index 83fb32a45fc..52aca1e23e1 100644
> --- a/arch/arm/mach-stm32mp/include/mach/sys_proto.h
> +++ b/arch/arm/mach-stm32mp/include/mach/sys_proto.h
> @@ -66,6 +66,9 @@ void get_soc_name(char name[SOC_NAME_SIZE]);
>  /* return boot mode */
>  u32 get_bootmode(void);
>  
> +/* return auth status and partition */
> +u32 get_bootauth(void);
> +
>  int get_eth_nb(void);
>  int setup_mac_address(void);
>  

Reviewed-by: Patrice Chotard 

Thanks
Patrice


Re: [PATCH 2/2] arm: stm32: Limit u-boot.itb size to 0x160000 bytes on DH STM32MP15 DHSOM

2023-11-08 Thread Patrice CHOTARD



On 11/4/23 17:31, Marek Vasut wrote:
> The maximum size of u-boot.itb in SPI NOR on DH STM32MP15 DHSOM is
> 0x16 . Define this size in U-Boot config to prevent misconfigured
> builds from emitting larger u-boot.itb than the one which fits the
> SPI NOR area reserved for the blob.
> 
> The SPI NOR layout is as follows:
> 0x00_..0x03_ ... SPL 1
> 0x04_..0x07_ ... SPL 2
> 0x08_..0x1d_ ... U-Boot
> 0x1e_..0x1e_ ... Environment 1
> 0x1f_..0x1f_ ... Environment 2
> 
> Signed-off-by: Marek Vasut 
> ---
> Cc: Andreas Geisreiter 
> Cc: Christoph Niedermaier 
> Cc: Patrice Chotard 
> Cc: Patrick Delaunay 
> Cc: u-b...@dh-electronics.com
> Cc: uboot-st...@st-md-mailman.stormreply.com
> ---
>  configs/stm32mp15_dhcom_basic_defconfig | 2 ++
>  configs/stm32mp15_dhcor_basic_defconfig | 2 ++
>  2 files changed, 4 insertions(+)
> 
> diff --git a/configs/stm32mp15_dhcom_basic_defconfig 
> b/configs/stm32mp15_dhcom_basic_defconfig
> index 08aac878f8e..1d241529be7 100644
> --- a/configs/stm32mp15_dhcom_basic_defconfig
> +++ b/configs/stm32mp15_dhcom_basic_defconfig
> @@ -25,6 +25,8 @@ CONFIG_SPL_SPI=y
>  CONFIG_SYS_LOAD_ADDR=0xc200
>  CONFIG_SYS_MEMTEST_START=0xc000
>  CONFIG_SYS_MEMTEST_END=0xc400
> +CONFIG_HAS_BOARD_SIZE_LIMIT=y
> +CONFIG_BOARD_SIZE_LIMIT=1441792
>  CONFIG_FIT=y
>  CONFIG_SPL_LOAD_FIT=y
>  CONFIG_SPL_LOAD_FIT_ADDRESS=0xc100
> diff --git a/configs/stm32mp15_dhcor_basic_defconfig 
> b/configs/stm32mp15_dhcor_basic_defconfig
> index 8cd6924b580..6e0c4a8cf9f 100644
> --- a/configs/stm32mp15_dhcor_basic_defconfig
> +++ b/configs/stm32mp15_dhcor_basic_defconfig
> @@ -23,6 +23,8 @@ CONFIG_SPL_SPI_FLASH_SUPPORT=y
>  CONFIG_SPL_SPI=y
>  # CONFIG_ARMV7_VIRT is not set
>  CONFIG_SYS_LOAD_ADDR=0xc200
> +CONFIG_HAS_BOARD_SIZE_LIMIT=y
> +CONFIG_BOARD_SIZE_LIMIT=1441792
>  CONFIG_FIT=y
>  CONFIG_SPL_LOAD_FIT=y
>  CONFIG_SPL_LOAD_FIT_ADDRESS=0xc100
Reviewed-by: Patrice Chotard 

Thanks
Patrice


Re: [PATCH 1/2] arm: stm32: Enable TCP, IPv6, wget on DH STM32MP15 DHSOM

2023-11-08 Thread Patrice CHOTARD



On 11/4/23 17:31, Marek Vasut wrote:
> Enable support for TCP protocol, wget, and IPv6 on this platform.
> The former two allow users download payload into the U-Boot from
> a web server, which may be more convenient or easier to set up
> than TFTP server. The later is enabled to future proof the IP
> stack on this platform.
> 
> Signed-off-by: Marek Vasut 
> ---
> Cc: Andreas Geisreiter 
> Cc: Christoph Niedermaier 
> Cc: Patrice Chotard 
> Cc: Patrick Delaunay 
> Cc: u-b...@dh-electronics.com
> Cc: uboot-st...@st-md-mailman.stormreply.com
> ---
>  configs/stm32mp15_dhcom_basic_defconfig | 5 +
>  configs/stm32mp15_dhcor_basic_defconfig | 5 +
>  2 files changed, 10 insertions(+)
> 
> diff --git a/configs/stm32mp15_dhcom_basic_defconfig 
> b/configs/stm32mp15_dhcom_basic_defconfig
> index b6cd0a47fa7..08aac878f8e 100644
> --- a/configs/stm32mp15_dhcom_basic_defconfig
> +++ b/configs/stm32mp15_dhcom_basic_defconfig
> @@ -76,7 +76,10 @@ CONFIG_CMD_REMOTEPROC=y
>  CONFIG_CMD_SPI=y
>  CONFIG_CMD_USB=y
>  CONFIG_CMD_USB_MASS_STORAGE=y
> +CONFIG_CMD_DHCP6=y
> +CONFIG_CMD_TFTPPUT=y
>  CONFIG_SYS_DISABLE_AUTOLOAD=y
> +CONFIG_CMD_WGET=y
>  CONFIG_CMD_BOOTCOUNT=y
>  CONFIG_CMD_CACHE=y
>  CONFIG_CMD_TIME=y
> @@ -101,6 +104,8 @@ CONFIG_IP_DEFRAG=y
>  CONFIG_TFTP_TSIZE=y
>  CONFIG_USE_SERVERIP=y
>  CONFIG_SERVERIP="192.168.1.1"
> +CONFIG_PROT_TCP_SACK=y
> +CONFIG_IPV6=y
>  CONFIG_STM32_ADC=y
>  CONFIG_SPL_BLOCK_CACHE=y
>  CONFIG_BOOTCOUNT_LIMIT=y
> diff --git a/configs/stm32mp15_dhcor_basic_defconfig 
> b/configs/stm32mp15_dhcor_basic_defconfig
> index d1acf9c657e..8cd6924b580 100644
> --- a/configs/stm32mp15_dhcor_basic_defconfig
> +++ b/configs/stm32mp15_dhcor_basic_defconfig
> @@ -74,7 +74,10 @@ CONFIG_CMD_REMOTEPROC=y
>  CONFIG_CMD_SPI=y
>  CONFIG_CMD_USB=y
>  CONFIG_CMD_USB_MASS_STORAGE=y
> +CONFIG_CMD_DHCP6=y
> +CONFIG_CMD_TFTPPUT=y
>  CONFIG_SYS_DISABLE_AUTOLOAD=y
> +CONFIG_CMD_WGET=y
>  CONFIG_CMD_BOOTCOUNT=y
>  CONFIG_CMD_CACHE=y
>  CONFIG_CMD_TIME=y
> @@ -99,6 +102,8 @@ CONFIG_IP_DEFRAG=y
>  CONFIG_TFTP_TSIZE=y
>  CONFIG_USE_SERVERIP=y
>  CONFIG_SERVERIP="192.168.1.1"
> +CONFIG_PROT_TCP_SACK=y
> +CONFIG_IPV6=y
>  CONFIG_STM32_ADC=y
>  CONFIG_SPL_BLOCK_CACHE=y
>  CONFIG_BOOTCOUNT_LIMIT=y

Reviewed-by: Patrice Chotard 

Thanks
Patrice


[PATCH 1/2] drivers: watchdog: add andes atcwdt200 support

2023-11-08 Thread Randolph
This patch adds an implementation of the Andes watchdog ATCWDT200 driver.

Signed-off-by: CL Wang 
Signed-off-by: Randolph 
---
 drivers/watchdog/Kconfig |   6 +
 drivers/watchdog/Makefile|   1 +
 drivers/watchdog/atcwdt200_wdt.c | 219 +++
 3 files changed, 226 insertions(+)
 create mode 100644 drivers/watchdog/atcwdt200_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 07fc4940e9..6b0f77dd3f 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -130,6 +130,12 @@ config WDT_AT91
  Select this to enable Microchip watchdog timer, which can be found on
  some AT91 devices.
 
+config WDT_ATCWDT200
+   bool "Andes watchdog timer support"
+   depends on WDT
+   help
+ Select this to enable Andes ATCWDT200 watchdog timer
+
 config WDT_BCM6345
bool "BCM6345 watchdog timer support"
depends on WDT && (ARCH_BMIPS || BCM6856 || \
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index eef786f5e7..1750ebbb1f 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_WDT_ARM_SMC) += arm_smc_wdt.o
 obj-$(CONFIG_WDT_ARMADA_37XX) += armada-37xx-wdt.o
 obj-$(CONFIG_WDT_ASPEED) += ast_wdt.o
 obj-$(CONFIG_WDT_AST2600) += ast2600_wdt.o
+obj-$(CONFIG_WDT_ATCWDT200) += atcwdt200_wdt.o
 obj-$(CONFIG_WDT_BCM2835) += bcm2835_wdt.o
 obj-$(CONFIG_WDT_BCM6345) += bcm6345_wdt.o
 obj-$(CONFIG_WDT_BOOKE) += booke_wdt.o
diff --git a/drivers/watchdog/atcwdt200_wdt.c b/drivers/watchdog/atcwdt200_wdt.c
new file mode 100644
index 00..dc34013473
--- /dev/null
+++ b/drivers/watchdog/atcwdt200_wdt.c
@@ -0,0 +1,219 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C)  2023 Andes Technology Corporation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define NODE_NOT_FOUND 0x
+
+#define WDT_WP_MAGIC   0x5aa5
+#define WDT_RESTART_MAGIC  0xcafe
+
+/* Control Register */
+#define REG_WDT_ID 0x00
+#define REG_WDT_CFG0x10
+#define REG_WDT_RS 0x14
+#define REG_WDT_WE 0x18
+#define REG_WDT_STA0x1C
+
+#define RST_TIME_OFF   8
+#define RST_TIME_MSK   (0x7 << RST_TIME_OFF)
+#define RST_CLK_128(0 << RST_TIME_OFF)
+#define RST_CLK_256(1 << RST_TIME_OFF)
+#define RST_CLK_512(2 << RST_TIME_OFF)
+#define RST_CLK_1024   (3 << RST_TIME_OFF)
+#define INT_TIME_OFF   4
+#define INT_TIME_MSK   (0xf << INT_TIME_OFF)
+#define INT_CLK_2_6(0 << INT_TIME_OFF)  /* clk period*2^6  */
+#define INT_CLK_2_8(1 << INT_TIME_OFF)  /* clk period*2^8  */
+#define INT_CLK_2_10   (2 << INT_TIME_OFF)  /* clk period*2^10 */
+#define INT_CLK_2_11   (3 << INT_TIME_OFF)  /* clk period*2^11 */
+#define INT_CLK_2_12   (4 << INT_TIME_OFF)  /* clk period*2^12 */
+#define INT_CLK_2_13   (5 << INT_TIME_OFF)  /* clk period*2^13 */
+#define INT_CLK_2_14   (6 << INT_TIME_OFF)  /* clk period*2^14 */
+#define INT_CLK_2_15   (7 << INT_TIME_OFF)  /* clk period*2^15 */
+#define INT_CLK_2_17   (8 << INT_TIME_OFF)  /* clk period*2^17 */
+#define INT_CLK_2_19   (9 << INT_TIME_OFF)  /* clk period*2^19 */
+#define INT_CLK_2_21   (10 << INT_TIME_OFF) /* clk period*2^21 */
+#define INT_CLK_2_23   (11 << INT_TIME_OFF) /* clk period*2^23 */
+#define INT_CLK_2_25   (12 << INT_TIME_OFF) /* clk period*2^25 */
+#define INT_CLK_2_27   (13 << INT_TIME_OFF) /* clk period*2^27 */
+#define INT_CLK_2_29   (14 << INT_TIME_OFF) /* clk period*2^29 */
+#define INT_CLK_2_31   (15 << INT_TIME_OFF) /* clk period*2^31 */
+#define INT_CLK_MIN0x0
+#define INT_CLK_MAX_16B0x7
+#define INT_CLK_MAX_32B0xF
+#define RST_EN BIT(3)
+#define INT_EN BIT(2)
+#define CLK_PCLK   BIT(1)
+#define WDT_EN BIT(0)
+#define INT_EXPIREDBIT(0)
+
+#define INT_TIME_ARRAY 16
+#define RST_TIME_ARRAY 8
+
+struct wdt_priv {
+   void __iomem *base;
+   u32 wdt_clk_src;
+   u32 clk_freq;
+   u8  max_clk;
+};
+
+static inline u8 atcwdt_get_2_power_of_n(u8 index, u8 type)
+{
+   u8 div_int[INT_TIME_ARRAY] = {6, 8, 10, 11, 12, 13, 14, 15, 17, 19, 21, 
23, 25, 27, 29, 31};
+   u8 div_rst[RST_TIME_ARRAY] = {7, 8, 9, 10, 11, 12, 13, 14};
+   u8 *pdiv;
+
+   if (type == RST_TIME_ARRAY)
+   pdiv = div_rst;
+   else
+   pdiv = div_int;
+
+   if (index >= type)
+   index = type - 1;
+
+   return pdiv[index];
+}
+
+static u8 atwdt_search_msb(u64 freq_ms, u8 type)
+{
+   u64 result;
+   u64 freq_sec;
+   u8 index;
+
+   freq_sec = freq_ms / 1000;
+   for (index = 0; index < type; index++) {
+   result = freq_sec >> atcwdt_get_2_power_of_n(index, type);
+
+   if (result <= 1)
+   break;
+   }
+
+   return index;
+}
+
+static int 

[PATCH 2/2] configs: andes: add watchdog support fot andes ae350

2023-11-08 Thread Randolph
It adds the ATCWDT200 support for Andes AE350 platform.
It also enables wdt command support.

Signed-off-by: CL Wang 
Signed-off-by: Randolph 
---
 configs/ae350_rv32_defconfig | 4 
 configs/ae350_rv32_spl_defconfig | 4 
 configs/ae350_rv32_spl_xip_defconfig | 4 
 configs/ae350_rv32_xip_defconfig | 4 
 configs/ae350_rv64_defconfig | 4 
 configs/ae350_rv64_spl_defconfig | 4 
 configs/ae350_rv64_spl_xip_defconfig | 4 
 configs/ae350_rv64_xip_defconfig | 4 
 8 files changed, 32 insertions(+)

diff --git a/configs/ae350_rv32_defconfig b/configs/ae350_rv32_defconfig
index 06cd972a0d..a32672f8ed 100644
--- a/configs/ae350_rv32_defconfig
+++ b/configs/ae350_rv32_defconfig
@@ -22,6 +22,7 @@ CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_IMLS=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_SF_TEST=y
+CONFIG_CMD_WDT=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_BOOTP_PREFER_SERVERIP=y
 CONFIG_CMD_CACHE=y
@@ -48,3 +49,6 @@ CONFIG_BAUDRATE=38400
 CONFIG_SYS_NS16550=y
 CONFIG_SPI=y
 CONFIG_ATCSPI200_SPI=y
+# CONFIG_WATCHDOG_AUTOSTART is not set
+CONFIG_WDT=y
+CONFIG_WDT_ATCWDT200=y
\ No newline at end of file
diff --git a/configs/ae350_rv32_spl_defconfig b/configs/ae350_rv32_spl_defconfig
index f469d5bb2b..e09f878329 100644
--- a/configs/ae350_rv32_spl_defconfig
+++ b/configs/ae350_rv32_spl_defconfig
@@ -32,6 +32,7 @@ CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_IMLS=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_SF_TEST=y
+CONFIG_CMD_WDT=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_BOOTP_PREFER_SERVERIP=y
 CONFIG_CMD_CACHE=y
@@ -57,3 +58,6 @@ CONFIG_SYS_NS16550=y
 CONFIG_SPI=y
 CONFIG_ATCSPI200_SPI=y
 # CONFIG_BINMAN_FDT is not set
+# CONFIG_WATCHDOG_AUTOSTART is not set
+CONFIG_WDT=y
+CONFIG_WDT_ATCWDT200=y
diff --git a/configs/ae350_rv32_spl_xip_defconfig 
b/configs/ae350_rv32_spl_xip_defconfig
index 9672a19c23..850e67a0d9 100644
--- a/configs/ae350_rv32_spl_xip_defconfig
+++ b/configs/ae350_rv32_spl_xip_defconfig
@@ -33,6 +33,7 @@ CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_IMLS=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_SF_TEST=y
+CONFIG_CMD_WDT=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_BOOTP_PREFER_SERVERIP=y
 CONFIG_CMD_CACHE=y
@@ -58,3 +59,6 @@ CONFIG_SYS_NS16550=y
 CONFIG_SPI=y
 CONFIG_ATCSPI200_SPI=y
 # CONFIG_BINMAN_FDT is not set
+# CONFIG_WATCHDOG_AUTOSTART is not set
+CONFIG_WDT=y
+CONFIG_WDT_ATCWDT200=y
diff --git a/configs/ae350_rv32_xip_defconfig b/configs/ae350_rv32_xip_defconfig
index b90200a97e..8745ac4c07 100644
--- a/configs/ae350_rv32_xip_defconfig
+++ b/configs/ae350_rv32_xip_defconfig
@@ -23,6 +23,7 @@ CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_IMLS=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_SF_TEST=y
+CONFIG_CMD_WDT=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_BOOTP_PREFER_SERVERIP=y
 CONFIG_CMD_CACHE=y
@@ -49,3 +50,6 @@ CONFIG_BAUDRATE=38400
 CONFIG_SYS_NS16550=y
 CONFIG_SPI=y
 CONFIG_ATCSPI200_SPI=y
+# CONFIG_WATCHDOG_AUTOSTART is not set
+CONFIG_WDT=y
+CONFIG_WDT_ATCWDT200=y
\ No newline at end of file
diff --git a/configs/ae350_rv64_defconfig b/configs/ae350_rv64_defconfig
index a4b9ad6162..4aa0b1a29d 100644
--- a/configs/ae350_rv64_defconfig
+++ b/configs/ae350_rv64_defconfig
@@ -22,6 +22,7 @@ CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_IMLS=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_SF_TEST=y
+CONFIG_CMD_WDT=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_BOOTP_PREFER_SERVERIP=y
 CONFIG_CMD_CACHE=y
@@ -48,3 +49,6 @@ CONFIG_BAUDRATE=38400
 CONFIG_SYS_NS16550=y
 CONFIG_SPI=y
 CONFIG_ATCSPI200_SPI=y
+# CONFIG_WATCHDOG_AUTOSTART is not set
+CONFIG_WDT=y
+CONFIG_WDT_ATCWDT200=y
\ No newline at end of file
diff --git a/configs/ae350_rv64_spl_defconfig b/configs/ae350_rv64_spl_defconfig
index 834a0fbbdd..1a3c294b16 100644
--- a/configs/ae350_rv64_spl_defconfig
+++ b/configs/ae350_rv64_spl_defconfig
@@ -32,6 +32,7 @@ CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_IMLS=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_SF_TEST=y
+CONFIG_CMD_WDT=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_BOOTP_PREFER_SERVERIP=y
 CONFIG_CMD_CACHE=y
@@ -57,3 +58,6 @@ CONFIG_SYS_NS16550=y
 CONFIG_SPI=y
 CONFIG_ATCSPI200_SPI=y
 # CONFIG_BINMAN_FDT is not set
+# CONFIG_WATCHDOG_AUTOSTART is not set
+CONFIG_WDT=y
+CONFIG_WDT_ATCWDT200=y
diff --git a/configs/ae350_rv64_spl_xip_defconfig 
b/configs/ae350_rv64_spl_xip_defconfig
index b52b8d78d7..f8db0a1a85 100644
--- a/configs/ae350_rv64_spl_xip_defconfig
+++ b/configs/ae350_rv64_spl_xip_defconfig
@@ -33,6 +33,7 @@ CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_IMLS=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_SF_TEST=y
+CONFIG_CMD_WDT=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_BOOTP_PREFER_SERVERIP=y
 CONFIG_CMD_CACHE=y
@@ -58,3 +59,6 @@ CONFIG_SYS_NS16550=y
 CONFIG_SPI=y
 CONFIG_ATCSPI200_SPI=y
 # CONFIG_BINMAN_FDT is not set
+# CONFIG_WATCHDOG_AUTOSTART is not set
+CONFIG_WDT=y
+CONFIG_WDT_ATCWDT200=y
diff --git a/configs/ae350_rv64_xip_defconfig b/configs/ae350_rv64_xip_defconfig
index cc5e751c9b..70119f154a 100644
--- a/configs/ae350_rv64_xip_defconfig
+++ b/configs/ae350_rv64_xip_defconfig
@@ -23,6 +23,7 @@ 

Re: [PATCH v6 08/25] spl: Refactor spl_load_info->read to use units of bytes

2023-11-08 Thread Xavier Drudis Ferran
El Wed, Nov 08, 2023 at 10:59:13AM -0500, Sean Anderson deia:
> 
> OK, what about
> 
> @offset: Offset to read from in bytes. This must be a multiple of 
> @load->bl_len.
> 
> --Sean

Great. Thank you.


[PATCH v3] arm64: zynqmp: Introduce kria SOM defconfig

2023-11-08 Thread Venkatesh Yadav Abbarapu
Enable the initial kria SOM specific configurations like pinctrl,
pinconf etc. Also add the environment file.

Signed-off-by: Venkatesh Yadav Abbarapu 
---
Changes in v2:
- Updated the CONFIG_ENV_OFFSET_REDUND
- Updated the CONFIG_SF_DEFAULT_SPEED to 3000
- Enabled the CONFIG_VIDEO_ZYNQMP_DPSUB
- Fixed minor changes in zynqmp_kria.env
Changes in v3:
- Updated the CONFIG_ENV_OFFSET
- Updated the CONFIG_SYS_SPI_U_BOOT_OFFS to 0x28
- Removed the CONFIG_ENV_SPI_MAX_HZ
---
 board/xilinx/zynqmp/zynqmp_kria.env  |  67 
 configs/xilinx_zynqmp_kria_defconfig | 227 +++
 2 files changed, 294 insertions(+)
 create mode 100644 board/xilinx/zynqmp/zynqmp_kria.env
 create mode 100644 configs/xilinx_zynqmp_kria_defconfig

diff --git a/board/xilinx/zynqmp/zynqmp_kria.env 
b/board/xilinx/zynqmp/zynqmp_kria.env
new file mode 100644
index 00..9140694d41
--- /dev/null
+++ b/board/xilinx/zynqmp/zynqmp_kria.env
@@ -0,0 +1,67 @@
+autoload=no
+baudrate=115200
+boot_a_script=load ${devtype} ${devnum}:${distro_bootpart} ${scriptaddr} 
${prefix}${script}; source ${scriptaddr}
+boot_efi_binary=if fdt addr ${fdt_addr_r}; then bootefi bootmgr 
${fdt_addr_r};else bootefi bootmgr ${fdtcontroladdr};fi;load ${devtype} 
${devnum}:${distro_bootpart} ${kernel_addr_r} efi/boot/bootaa64.efi; if fdt 
addr ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${fdt_addr_r};else bootefi 
${kernel_addr_r} ${fdtcontroladdr};fi
+boot_extlinux=sysboot ${devtype} ${devnum}:${distro_bootpart} any 
${scriptaddr} ${prefix}${boot_syslinux_conf}
+boot_net_usb_start=usb start
+boot_prefixes=/ /boot/
+boot_script_dhcp=boot.scr.uimg
+boot_scripts=boot.scr.uimg boot.scr
+boot_syslinux_conf=extlinux/extlinux.conf
+bootcmd_dhcp=run boot_net_usb_start; if dhcp ${scriptaddr} 
${boot_script_dhcp}; then source ${scriptaddr}; fi;setenv efi_fdtfile 
${fdtfile}; setenv efi_old_vci ${bootp_vci};setenv efi_old_arch 
${bootp_arch};setenv bootp_vci PXEClient:Arch:00011:UNDI:003000;setenv 
bootp_arch 0xb;if dhcp ${kernel_addr_r}; then tftpboot ${fdt_addr_r} 
dtb/${efi_fdtfile};if fdt addr ${fdt_addr_r}; then bootefi ${kernel_addr_r} 
${fdt_addr_r}; else bootefi ${kernel_addr_r} ${fdtcontroladdr};fi;fi;setenv 
bootp_vci ${efi_old_vci};setenv bootp_arch ${efi_old_arch};setenv 
efi_fdtfile;setenv efi_old_arch;setenv efi_old_vci;
+bootcmd_jtag=echo JTAG: Trying to boot script at ${scriptaddr} && source 
${scriptaddr}; echo JTAG: SCRIPT FAILED: continuing...;
+bootcmd_mmc0=devnum=0; run mmc_boot
+bootcmd_mmc1=devnum=1; run mmc_boot
+bootcmd_pxe=run boot_net_usb_start; dhcp; if pxe get; then pxe boot; fi
+bootcmd_usb0=devnum=0; run usb_boot
+bootcmd_usb1=devnum=1; run usb_boot
+bootcmd_usb2=devnum=2; run usb_boot
+bootcmd_usb3=devnum=3; run usb_boot
+bootdelay=2
+bootfstype=fat
+bootm_low=0
+bootm_size=0x8000
+distro_bootcmd=scsi_need_init=; for target in ${boot_targets}; do run 
bootcmd_${target}; done
+efi_dtb_prefixes=/ /dtb/ /dtb/current/
+fdt_addr_r=0x4000
+fdt_high=0x1000
+fileaddr=0x1800
+initrd_high=0x7900
+kernel_addr_r=0x1800
+load_efi_dtb=load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} 
${prefix}${efi_fdtfile}
+mmc_boot=if mmc dev ${devnum}; then devtype=mmc; run scan_dev_for_boot_part; fi
+pxefile_addr_r=0x1000
+ramdisk_addr_r=0x0210
+scan_dev_for_boot=echo Scanning ${devtype} ${devnum}:${distro_bootpart}...; 
for prefix in ${boot_prefixes}; do run scan_dev_for_extlinux; run 
scan_dev_for_scripts; done;run scan_dev_for_efi;
+scan_dev_for_boot_part=part list ${devtype} ${devnum} -bootable devplist; env 
exists devplist || setenv devplist 1; for distro_bootpart in ${devplist}; do if 
fstype ${devtype} ${devnum}:${distro_bootpart} bootfstype; then run 
scan_dev_for_boot; fi; done; setenv devplist
+scan_dev_for_efi=setenv efi_fdtfile ${fdtfile}; for prefix in 
${efi_dtb_prefixes}; do if test -e ${devtype} ${devnum}:${distro_bootpart} 
${prefix}${efi_fdtfile}; then run load_efi_dtb; fi;done;if test -e ${devtype} 
${devnum}:${distro_bootpart} efi/boot/bootaa64.efi; then echo Found EFI 
removable media binary efi/boot/bootaa64.efi; run boot_efi_binary; echo EFI 
LOAD FAILED: continuing...; fi; setenv efi_fdtfile
+scan_dev_for_extlinux=if test -e ${devtype} ${devnum}:${distro_bootpart} 
${prefix}${boot_syslinux_conf}; then echo Found ${prefix}${boot_syslinux_conf}; 
run boot_extlinux; echo SCRIPT FAILED: continuing...; fi
+scan_dev_for_scripts=for script in ${boot_scripts}; do if test -e ${devtype} 
${devnum}:${distro_bootpart} ${prefix}${script}; then echo Found U-Boot script 
${prefix}${script}; run boot_a_script; echo SCRIPT FAILED: continuing...; fi; 
done
+script_offset_f=0x3e8
+script_size_f=0x8
+scriptaddr=0x2000
+usb_boot=usb start; if usb dev ${devnum}; then devtype=usb; run 
scan_dev_for_boot_part; fi
+preboot=setenv boot_targets; setenv modeboot; run board_setup
+
+# SOM specific boot methods
+som_cc_boot=if test ${card1_name} = SCK-KV-G; then setenv boot_targets mmc1 
usb0 

Re: [PATCH 6/6] rockchip: ringneck-px30: fix modified boot_targets detection

2023-11-08 Thread Kever Yang



On 2023/11/8 22:20, Quentin Schulz wrote:

From: Quentin Schulz 

U-Boot proper automatically modifies boot_targets to swap the order in
which MMC storage media are used for standard boot based on which MMC
storage medium was used to load U-Boot proper. This is however only done
if the user has not changed it manually, therefore a check between the
default and current value is done.

This used to work fine until the migration to standard boot where
boot_targets value size in the default environment went above the 32
characters that env_get_default function can return, thus resulting in a
truncated variable.

Therefore the check between default and current value would always fail.

By using the newly added env_get_default_into function, a buffer of
the appropriate size can be allocated on the stack to get the whole
value of boot_targets in the default environment and thus fixing the
check.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 

Reviewed-by: Kever Yang 

Thanks,
- Kever

---
  board/theobroma-systems/ringneck_px30/ringneck-px30.c | 9 +++--
  1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/board/theobroma-systems/ringneck_px30/ringneck-px30.c 
b/board/theobroma-systems/ringneck_px30/ringneck-px30.c
index dd711cd05de..2bce8147eeb 100644
--- a/board/theobroma-systems/ringneck_px30/ringneck-px30.c
+++ b/board/theobroma-systems/ringneck_px30/ringneck-px30.c
@@ -39,7 +39,9 @@ static int setup_boottargets(void)
  {
const char *boot_device =
ofnode_read_chosen_string("u-boot,spl-boot-device");
-   char *env_default, *env;
+   char env_default[sizeof(BOOT_TARGETS)];
+   char *env;
+   int ret;
  
  	if (!boot_device) {

debug("%s: /chosen/u-boot,spl-boot-device not set\n",
@@ -48,7 +50,10 @@ static int setup_boottargets(void)
}
debug("%s: booted from %s\n", __func__, boot_device);
  
-	env_default = env_get_default("boot_targets");

+   ret = env_get_default_into("boot_targets", env_default,
+  sizeof(env_default));
+   if (ret < 0)
+   env_default[0] = '\0';
env = env_get("boot_targets");
if (!env) {
debug("%s: boot_targets does not exist\n", __func__);



Re: [PATCH 5/6] rockchip: puma-rk3399: fix modified boot_targets detection

2023-11-08 Thread Kever Yang



On 2023/11/8 22:20, Quentin Schulz wrote:

From: Quentin Schulz 

U-Boot proper automatically modifies boot_targets to swap the order in
which MMC storage media are used for standard boot based on which MMC
storage medium was used to load U-Boot proper. This is however only done
if the user has not changed it manually, therefore a check between the
default and current value is done.

This used to work fine until the migration to standard boot where
boot_targets value size in the default environment went above the 32
characters that env_get_default function can return, thus resulting in a
truncated variable.

Therefore the check between default and current value would always fail.

By using the newly added env_get_default_into function, a buffer of
the appropriate size can be allocated on the stack to get the whole
value of boot_targets in the default environment and thus fixing the
check.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 

Reviewed-by: Kever Yang 

Thanks,
- Kever

---
  board/theobroma-systems/puma_rk3399/puma-rk3399.c | 9 +++--
  1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/board/theobroma-systems/puma_rk3399/puma-rk3399.c 
b/board/theobroma-systems/puma_rk3399/puma-rk3399.c
index 1b7a39b0474..df667fae5fc 100644
--- a/board/theobroma-systems/puma_rk3399/puma-rk3399.c
+++ b/board/theobroma-systems/puma_rk3399/puma-rk3399.c
@@ -54,7 +54,9 @@ static int setup_boottargets(void)
  {
const char *boot_device =
ofnode_read_chosen_string("u-boot,spl-boot-device");
-   char *env_default, *env;
+   char env_default[sizeof(BOOT_TARGETS)];
+   char *env;
+   int ret;
  
  	if (!boot_device) {

debug("%s: /chosen/u-boot,spl-boot-device not set\n",
@@ -63,7 +65,10 @@ static int setup_boottargets(void)
}
debug("%s: booted from %s\n", __func__, boot_device);
  
-	env_default = env_get_default("boot_targets");

+   ret = env_get_default_into("boot_targets", env_default,
+  sizeof(env_default));
+   if (ret < 0)
+   env_default[0] = '\0';
env = env_get("boot_targets");
if (!env) {
debug("%s: boot_targets does not exist\n", __func__);



Re: [PATCH 4/6] rockchip: ringneck-px30: only declare functions in U-Boot proper

2023-11-08 Thread Kever Yang



On 2023/11/8 22:20, Quentin Schulz wrote:

From: Quentin Schulz 

Those functions are useless in anything but U-Boot proper for now, so
let's compile them out explicitly.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 

Reviewed-by: Kever Yang 

Thanks,
- Kever

---
  board/theobroma-systems/ringneck_px30/ringneck-px30.c | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/board/theobroma-systems/ringneck_px30/ringneck-px30.c 
b/board/theobroma-systems/ringneck_px30/ringneck-px30.c
index bb1bb4acf5c..dd711cd05de 100644
--- a/board/theobroma-systems/ringneck_px30/ringneck-px30.c
+++ b/board/theobroma-systems/ringneck_px30/ringneck-px30.c
@@ -25,6 +25,7 @@
  #include 
  #include 
  
+#ifndef CONFIG_SPL_BUILD

  /*
   * Swap mmc0 and mmc1 in boot_targets if booted from SD-Card.
   *
@@ -169,3 +170,4 @@ int misc_init_r(void)
  
  	return 0;

  }
+#endif



Re: [PATCH 3/6] rockchip: puma-rk3399: only declare functions in U-Boot proper

2023-11-08 Thread Kever Yang



On 2023/11/8 22:20, Quentin Schulz wrote:

From: Quentin Schulz 

Those functions are useless in anything but U-Boot proper for now, so
let's compile them out explicitly.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 

Reviewed-by: Kever Yang 

Thanks,
- Kever

---
  board/theobroma-systems/puma_rk3399/puma-rk3399.c | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/board/theobroma-systems/puma_rk3399/puma-rk3399.c 
b/board/theobroma-systems/puma_rk3399/puma-rk3399.c
index 614a60ee8f9..1b7a39b0474 100644
--- a/board/theobroma-systems/puma_rk3399/puma-rk3399.c
+++ b/board/theobroma-systems/puma_rk3399/puma-rk3399.c
@@ -26,6 +26,7 @@
  #include 
  #include 
  
+#ifndef CONFIG_SPL_BUILD

  static void setup_iodomain(void)
  {
const u32 GRF_IO_VSEL_GPIO4CD_SHIFT = 3;
@@ -192,3 +193,4 @@ int misc_init_r(void)
  
  	return 0;

  }
+#endif



Re: [PATCH 2/6] env: migrate env_get_default to call env_get_default_into

2023-11-08 Thread Kever Yang



On 2023/11/8 22:20, Quentin Schulz wrote:

From: Quentin Schulz 

Since both functions share a similar goal and env_get_default_into can
do what env_get_default wants to do with specific arguments, let's make
env_get_default call env_get_default_into so as to avoid code
duplication.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 

Reviewed-by: Kever Yang 

Thanks,
- Kever

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

diff --git a/env/common.c b/env/common.c
index 307003099dd..930bdef2f58 100644
--- a/env/common.c
+++ b/env/common.c
@@ -246,9 +246,11 @@ bool env_get_autostart(void)
   */
  char *env_get_default(const char *name)
  {
-   if (env_get_from_linear(default_environment, name,
-   (char *)(gd->env_buf),
-   sizeof(gd->env_buf)) >= 0)
+   int ret;
+
+   ret = env_get_default_into(name, (char *)(gd->env_buf),
+  sizeof(gd->env_buf));
+   if (ret >= 0)
return (char *)(gd->env_buf);
  
  	return NULL;




Re: [PATCH 1/6] env: allow to copy value from default environment into a buffer

2023-11-08 Thread Kever Yang



On 2023/11/8 22:20, Quentin Schulz wrote:

From: Quentin Schulz 

env_get_default suffers from a particular issue int that it can only
return a value truncated to gd->env_buf (32) characters. This may be
enough for most variables but it isn't for others, so let's allow users
to provide a preallocated buffer to copy the value into instead,
allowing for more control, though it'll still be truncated if the value
size is bigger than the preallocated buffer.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 

Reviewed-by: Kever Yang 

Thanks,
- Kever

---
  env/common.c  |  8 
  include/env.h | 10 ++
  2 files changed, 18 insertions(+)

diff --git a/env/common.c b/env/common.c
index eb1a9137953..307003099dd 100644
--- a/env/common.c
+++ b/env/common.c
@@ -254,6 +254,14 @@ char *env_get_default(const char *name)
return NULL;
  }
  
+/*

+ * Look up the variable from the default environment and store its value in buf
+ */
+int env_get_default_into(const char *name, char *buf, unsigned int len)
+{
+   return env_get_from_linear(default_environment, name, buf, len);
+}
+
  void env_set_default(const char *s, int flags)
  {
if (s) {
diff --git a/include/env.h b/include/env.h
index 430c4fa94a4..9a406de3781 100644
--- a/include/env.h
+++ b/include/env.h
@@ -348,6 +348,16 @@ int env_import_redund(const char *buf1, int buf1_read_fail,
   */
  char *env_get_default(const char *name);
  
+/**

+ * env_get_default_into() - Look up a variable from the default environment and
+ * copy its value in buf.
+ *
+ * @name: Variable to look up
+ * Return: actual length of the variable value excluding the terminating
+ * NULL-byte, or -1 if the variable is not found
+ */
+int env_get_default_into(const char *name, char *buf, unsigned int len);
+
  /* [re]set to the default environment */
  void env_set_default(const char *s, int flags);
  



Re: [PATCH 1/2] configs: rockchip: Use dwc3-generic driver on RK3328 and RK3399

2023-11-08 Thread Kever Yang

Hi Jonas, Marek,

On 2023/10/20 12:23, Marek Vasut wrote:

On 10/19/23 22:39, Jonas Karlman wrote:

On 2023-10-19 01:44, Marek Vasut wrote:

On 10/19/23 00:30, Jonas Karlman wrote:

[..]


+++ b/configs/rock960-rk3399_defconfig
@@ -50,6 +50,7 @@ CONFIG_SYS_RELOC_GD_ENV_ADDR=y
   CONFIG_SYS_MMC_ENV_DEV=1
   CONFIG_ROCKCHIP_GPIO=y
   CONFIG_SYS_I2C_ROCKCHIP=y
+CONFIG_MISC=y
   CONFIG_MMC_DW=y
   CONFIG_MMC_DW_ROCKCHIP=y
   CONFIG_MMC_SDHCI=y
@@ -70,12 +71,12 @@ CONFIG_SYS_NS16550_MEM32=y
   CONFIG_SYSRESET=y
   CONFIG_USB=y
   CONFIG_USB_XHCI_HCD=y
-CONFIG_USB_XHCI_DWC3=y
   CONFIG_USB_EHCI_HCD=y
   CONFIG_USB_EHCI_GENERIC=y
   CONFIG_USB_OHCI_HCD=y
   CONFIG_USB_OHCI_GENERIC=y
   CONFIG_USB_DWC3=y
+CONFIG_USB_DWC3_GENERIC=y


Why not add 'default y if ROCKCHIP' into the Kconfig instead ? This 
will

have the same effect, without requiring such massive modification of
config files.


Not fully sure what you mean by this and how that would reduce number of
affected defconfig-files. The USB_XHCI_DWC3 should still be removed from
these defconfig-files or wrong driver could be used by these boards.

Touching the defconfig-files help notify board maintainers that changes
are happening to their boards.


This patch including remove old Kconfig option and add new option, just 
move to


enable generic driver option in Kconfig file instead of defconfig file.



There will also be a separate patch that remove the rockchip,rk3399-dwc3
compatible from the dwc3-of-simple driver to finalize this transition to
use dwc3-generic driver for affected rockchip boards.


It wasn't clear to me you're switching one driver to another, thanks 
for clarification.


"
Also enable DM_USB_GADGET for any board that enable
USB_DWC3_GADGET.
"

This you can do in Kconfig file, something like:
select DM_USB_GADGET if USB_DWC3_GADGET && 


Not all the rockchip socs have usb dwc3 controller, so make this change 
in SoC level will be better.



Thanks,

- Kever



[PATCH] riscv: binman: fix the load field format

2023-11-08 Thread Randolph
The #address-cells is now equal to 2. The format of the load field for
the Linux kernel doesn't match.

Signed-off-by: Randolph 
---
 arch/riscv/dts/binman.dtsi | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/dts/binman.dtsi b/arch/riscv/dts/binman.dtsi
index 6b4eb8dc7b..5117d7c8c9 100644
--- a/arch/riscv/dts/binman.dtsi
+++ b/arch/riscv/dts/binman.dtsi
@@ -50,7 +50,8 @@
os = "Linux";
arch = "riscv";
compression = "none";
-   load = ;
+   load = ;
 
linux_blob: blob-ext {
filename = "Image";
-- 
2.34.1



Re: [PATCH] rockchip: rk3588-rock-5b: Enable CONFIG_PCI_INIT_R to support EFI networking

2023-11-08 Thread Kever Yang

Hi Martin and jonas,

On 2023/11/4 21:04, Martin Roukala (né Peres) wrote:

When u-boot chainloads an EFI bootloader such as iPXE, we want to have
already initialized the PCI subsystem so that network driver is loaded
and ready to use by the bootloader.

Fixes: 191ece249a96 ("rockchip: rk3588-rock-5b: Enable support for PCIe SATA 
cards")
Signed-off-by: Martin Roukala (né Peres) 


Scan different storage media for boot firmware always cost some time, 
the pci cost a little bit


more time then SPI/eMMC, but since this board already support PCI 
storage, it's reasonable to


enable boot from PCI.


Reviewed-by: Kever Yang 

Thanks,
- Kever


---
  configs/rock5b-rk3588_defconfig | 1 +
  1 file changed, 1 insertion(+)

diff --git a/configs/rock5b-rk3588_defconfig b/configs/rock5b-rk3588_defconfig
index 0595325e81..938137c851 100644
--- a/configs/rock5b-rk3588_defconfig
+++ b/configs/rock5b-rk3588_defconfig
@@ -36,6 +36,7 @@ CONFIG_OF_BOARD_SETUP=y
  CONFIG_DEFAULT_FDT_FILE="rockchip/rk3588-rock-5b.dtb"
  # CONFIG_DISPLAY_CPUINFO is not set
  CONFIG_DISPLAY_BOARDINFO_LATE=y
+CONFIG_PCI_INIT_R=y
  CONFIG_SPL_MAX_SIZE=0x4
  CONFIG_SPL_PAD_TO=0x7f8000
  CONFIG_SPL_HAS_BSS_LINKER_SECTION=y


Re: [PATCH] rockchip: ringneck-px30: enable i2c command

2023-11-08 Thread Kever Yang



On 2023/10/25 19:17, Quentin Schulz wrote:

From: Quentin Schulz 

This is a useful tool to check the presence of a device on a specific
i2c bus, so let's enable it.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 


Reviewed-by: Kever Yang 

Thanks,
- Kever

---
  configs/ringneck-px30_defconfig | 1 +
  1 file changed, 1 insertion(+)

diff --git a/configs/ringneck-px30_defconfig b/configs/ringneck-px30_defconfig
index b4666d0e90f..f47dfa58782 100644
--- a/configs/ringneck-px30_defconfig
+++ b/configs/ringneck-px30_defconfig
@@ -53,6 +53,7 @@ CONFIG_SPL_ATF=y
  # CONFIG_CMD_LZMADEC is not set
  # CONFIG_CMD_UNZIP is not set
  CONFIG_CMD_GPT=y
+CONFIG_CMD_I2C=y
  # CONFIG_CMD_LOADB is not set
  # CONFIG_CMD_LOADS is not set
  CONFIG_CMD_MMC=y

---
base-commit: 351da15f71e3d70dbc63e90781b403415452d864
change-id: 20231025-ringneck-i2c-cmd-6417b86bc9a8

Best regards,


Re: [PATCH v11 00/24] Modernize U-Boot shell

2023-11-08 Thread Tom Rini
On Wed, Nov 08, 2023 at 12:14:28PM +, Peter Robinson wrote:
> On Wed, Nov 8, 2023 at 12:49 AM Francis Laniel
>  wrote:
> >
> > Hi.
> >
> >
> > During 2021 summer, Sean Anderson wrote a contribution to add a new shell, 
> > based
> > on LIL, to U-Boot [1, 2].
> > While one of the goals of this contribution was to address the fact actual
> > U-Boot shell, which is based on Busybox hush, is old there was a discussion
> > about adding a new shell versus updating the actual one [3, 4].
> >
> > So, in this series, with Harald Seiler, we updated the actual U-Boot shell 
> > to
> > reflect what is currently in Busybox source code.
> > Basically, this contribution is about taking a snapshot of Busybox 
> > shell/hush.c
> > file (as it exists in commit 37460f5da) and adapt it to suit U-Boot needs.
> >
> > This contribution was written to be as backward-compatible as possible to 
> > avoid
> > breaking the existing.
> > So, the 2021 hush flavor offers the same as the actual, that is to say:
> > 1. Variable expansion.
> > 2. Instruction lists (;, && and ||).
> > 3. If, then and else.
> > 4. Loops (for, while and until).
> > No new features offered by Busybox hush were implemented (e.g. functions).
> >
> > It is possible to change the parser at runtime using the "cli" command:
> > => cli print
> > old
> > => cli set 2021
> > => cli print
> > 2021
> > => cli set old
> > The default parser is the old one.
> > Note that to use both parser, you would need to set both 
> > CONFIG_HUSH_2021_PARSER
> > and CONFIG_HUSH_OLD_PARSER.
> >
> > In terms of testing, new unit tests were added to ut to ensure the new 
> > behavior
> > is the same as the old one and it does not add regression.
> > Nonetheless, if old behavior was buggy and fixed upstream, the fix is then 
> > added
> > to U-Boot [5].
> > In sandbox, all of these tests pass smoothly:
> > => printenv board
> > board=sandbox
> > => ut hush
> > Running 20 hush tests
> > ...
> > Failures: 0
> > => parser set 2021
> > => ut hush
> > Running 20 hush tests
> > ...
> > Failures: 0
> >
> > Thanks to the effort of Harald Seiler, I was successful booting a board:
> > => printenv fdtfile
> > fdtfile=amlogic/meson-gxl-s905x-libretech-cc.dtb
> > => cli get
> > old
> > => boot
> > ...
> > root@lepotato:~#
> > root@lepotato:~# reboot
> > ...
> > => cli set 2021
> > => cli get
> > 2021
> > => printenv fdtfile
> > fdtfile=amlogic/meson-gxl-s905x-libretech-cc.dtb
> > => boot
> > ...
> > root@lepotato:~#
> >
> > I had to not use CONFIG_HUSH_2021_PARSER for the keymile board.
> > Indeed, the keymile board family is the only set of boards to call
> > get_local_var(), set_local_var() and unset_local_var().
> > Sadly, these functions are static in this contribution.
> > I could have change all of them to introduce code like this:
> > *_local_var(/*...*/)
> > {
> > if (gd->flags & GD_FLG_HUSH_OLD_PARSER)
> > return *_local_var_old(/*...*/);
> > if (gd->flags & GD_FLG_HUSH_2021_PARSER)
> > return *_local_var_2021(/*...*/);
> > }
> > But this would have mean renaming all old hush functions calls and I did not
> > want to change the old hush particularly to avoid breaking things.
> > Instead, I change the keymile board to use environment variable instead of 
> > local
> > ones.
> > I think this particularities can be addressed in future works.
> >
> > I also had to enable CONFIG_LTO for kirkwoord sheevaplug and phytec bk4r1, 
> > so
> > they do not hit their limits.
> 
> With nearly 15K lines of code added and the above limits being reached
> how much does this increase the size of a binary if it's selected?
> Those sorts of details are useful in these cover letters. Also of the
> 13k lines in cli_hush_upstream.c how much of that functionality is
> actually used in U-Boot? You mention functions are not, while I
> understand adding it straight from busybox has it's advantages for
> easier rebasing, if it's also pulling in a lot of code that is never
> used there's also detractions to adding 13k lines of code.

I've put the world build on current next, before/after this series over
at: https://gist.github.com/trini/53d9a3d59c797ecdbb3aec8edbbb9a12 and
I'll have more commentary (aside from dropping common.h) tomorrow.

-- 
Tom


signature.asc
Description: PGP signature


Re: inconsistent wget behavior

2023-11-08 Thread Fabio Estevam
Hi Tom,

On Wed, Nov 8, 2023 at 9:17 PM Tom Rini  wrote:

> Interesting.  What if you take wget out of the equation and use "tftp"
> to grab a large file with a known checksum, repeatedly (note that "rhash
> -C" will give a crc32 in Linux so you can confirm the correct value and
> loop a get, crc32, compare, repeat loop with a little work) ? I ask
> because I was reminded today that for me at least, the RPi ethernet
> isn't reliable in U-Boot for me if you stress it too hard. So I'd like
> to try see if this is "wget bug" or "network driver/related bug".

I was not able to see a failure when using "tftp" to transfer the same
420MB file.

The number of bytes transferred and md5sum always match, so this is a wget bug.


Re: [PATCH v11 00/24] Modernize U-Boot shell

2023-11-08 Thread Simon Glass
Hi Peter,

On Wed, 8 Nov 2023 at 05:14, Peter Robinson  wrote:
>
> On Wed, Nov 8, 2023 at 12:49 AM Francis Laniel
>  wrote:
> >
> > Hi.
> >
> >
> > During 2021 summer, Sean Anderson wrote a contribution to add a new shell, 
> > based
> > on LIL, to U-Boot [1, 2].
> > While one of the goals of this contribution was to address the fact actual
> > U-Boot shell, which is based on Busybox hush, is old there was a discussion
> > about adding a new shell versus updating the actual one [3, 4].
> >
> > So, in this series, with Harald Seiler, we updated the actual U-Boot shell 
> > to
> > reflect what is currently in Busybox source code.
> > Basically, this contribution is about taking a snapshot of Busybox 
> > shell/hush.c
> > file (as it exists in commit 37460f5da) and adapt it to suit U-Boot needs.
> >
> > This contribution was written to be as backward-compatible as possible to 
> > avoid
> > breaking the existing.
> > So, the 2021 hush flavor offers the same as the actual, that is to say:
> > 1. Variable expansion.
> > 2. Instruction lists (;, && and ||).
> > 3. If, then and else.
> > 4. Loops (for, while and until).
> > No new features offered by Busybox hush were implemented (e.g. functions).
> >
> > It is possible to change the parser at runtime using the "cli" command:
> > => cli print
> > old
> > => cli set 2021
> > => cli print
> > 2021
> > => cli set old
> > The default parser is the old one.
> > Note that to use both parser, you would need to set both 
> > CONFIG_HUSH_2021_PARSER
> > and CONFIG_HUSH_OLD_PARSER.
> >
> > In terms of testing, new unit tests were added to ut to ensure the new 
> > behavior
> > is the same as the old one and it does not add regression.
> > Nonetheless, if old behavior was buggy and fixed upstream, the fix is then 
> > added
> > to U-Boot [5].
> > In sandbox, all of these tests pass smoothly:
> > => printenv board
> > board=sandbox
> > => ut hush
> > Running 20 hush tests
> > ...
> > Failures: 0
> > => parser set 2021
> > => ut hush
> > Running 20 hush tests
> > ...
> > Failures: 0
> >
> > Thanks to the effort of Harald Seiler, I was successful booting a board:
> > => printenv fdtfile
> > fdtfile=amlogic/meson-gxl-s905x-libretech-cc.dtb
> > => cli get
> > old
> > => boot
> > ...
> > root@lepotato:~#
> > root@lepotato:~# reboot
> > ...
> > => cli set 2021
> > => cli get
> > 2021
> > => printenv fdtfile
> > fdtfile=amlogic/meson-gxl-s905x-libretech-cc.dtb
> > => boot
> > ...
> > root@lepotato:~#
> >
> > I had to not use CONFIG_HUSH_2021_PARSER for the keymile board.
> > Indeed, the keymile board family is the only set of boards to call
> > get_local_var(), set_local_var() and unset_local_var().
> > Sadly, these functions are static in this contribution.
> > I could have change all of them to introduce code like this:
> > *_local_var(/*...*/)
> > {
> > if (gd->flags & GD_FLG_HUSH_OLD_PARSER)
> > return *_local_var_old(/*...*/);
> > if (gd->flags & GD_FLG_HUSH_2021_PARSER)
> > return *_local_var_2021(/*...*/);
> > }
> > But this would have mean renaming all old hush functions calls and I did not
> > want to change the old hush particularly to avoid breaking things.
> > Instead, I change the keymile board to use environment variable instead of 
> > local
> > ones.
> > I think this particularities can be addressed in future works.
> >
> > I also had to enable CONFIG_LTO for kirkwoord sheevaplug and phytec bk4r1, 
> > so
> > they do not hit their limits.
>
> With nearly 15K lines of code added and the above limits being reached
> how much does this increase the size of a binary if it's selected?
> Those sorts of details are useful in these cover letters. Also of the
> 13k lines in cli_hush_upstream.c how much of that functionality is
> actually used in U-Boot? You mention functions are not, while I
> understand adding it straight from busybox has it's advantages for
> easier rebasing, if it's also pulling in a lot of code that is never
> used there's also detractions to adding 13k lines of code.

Yes it would be good to have this in the cover letter. I did some
analysis of 10 and it seemed to be about 3KB[1] which is great!

It is helpful to have the code be similar to busybox, since then we
can apply patches from upstream easily. Of course there are
trade-offs, but the decisions in this series make sense to me. It may
be possible to upstream some of the feature control, but I wouldn't
bank on it.

>
> > For all these reasons, I marked this contribution as RFC to indeed collect 
> > your
> > opinions.
> > My goal is not to change suddenly actual shell to this one, we clearly need 
> > a
> > transition period to think about it.
> > I think it is better to see this contribution as a proof of concept which 
> > shows
> > it is possible to update the actual shell.
> >
> > If you want to review it - your review will really be appreciated - here are
> > some information regarding the commits:
> > * commits marked as "test:" deal with unit 

Re: [PATCH v11 8/9] cmd: efidebug: add uri device path

2023-11-08 Thread Simon Glass
Hi Masahisa,

On Wed, 8 Nov 2023 at 04:08, Masahisa Kojima  wrote:
>
> This adds the URI device path option for 'boot add' subcommand.
> User can add the URI load option for downloading ISO image file
> or EFI application through network. Currently HTTP is only supported.
>
> Signed-off-by: Masahisa Kojima 
> Acked-by: Ilias Apalodimas 
> ---
>  cmd/efidebug.c | 51 
>  include/net.h  |  8 ++
>  net/wget.c | 71 ++
>  3 files changed, 130 insertions(+)

Reviewed-by: Simon Glass 

>
> diff --git a/cmd/efidebug.c b/cmd/efidebug.c
> index 201531ac19..42b306e708 100644
> --- a/cmd/efidebug.c
> +++ b/cmd/efidebug.c
> @@ -19,6 +19,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -829,6 +830,53 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int 
> flag,
> argc -= 1;
> argv += 1;
> break;
> +#if (IS_ENABLED(CONFIG_EFI_HTTP_BOOT))

(my very late comment could be looked at after this is applied, since
it is already at v11)

Can this be move to 'if'? You can put it inside the case and really
this code should be in a function, as do_efi_boot_add() is already
long.

> +   case 'u':
> +   {
> +   char *pos;
> +   int uridp_len;
> +   struct efi_device_path_uri *uridp;
> +
> +   if (argc <  3 || lo.label) {
> +   r = CMD_RET_USAGE;
> +   goto out;
> +   }
> +
> +   id = (int)hextoul(argv[1], );
> +   if (*endp != '\0' || id > 0x)
> +   return CMD_RET_USAGE;
> +
> +   label = efi_convert_string(argv[2]);
> +   if (!label)
> +   return CMD_RET_FAILURE;
> +
> +   if (!wget_validate_uri(argv[3])) {
> +   printf("ERROR: invalid URI\n");
> +   r = CMD_RET_FAILURE;
> +   goto out;
> +   }
> +
> +   efi_create_indexed_name(var_name16, 
> sizeof(var_name16),
> +   "Boot", id);
> +   lo.label = label;
> +
> +   uridp_len = sizeof(struct efi_device_path) + 
> strlen(argv[3]) + 1;
> +   fp_size += uridp_len + sizeof(END);
> +   fp_free = efi_alloc(fp_size);
> +   uridp = (struct efi_device_path_uri *)fp_free;
> +   uridp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
> +   uridp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_URI;
> +   uridp->dp.length = uridp_len;
> +   strcpy(uridp->uri, argv[3]);
> +   pos = (char *)uridp + uridp_len;
> +   memcpy(pos, , sizeof(END));
> +   file_path = (struct efi_device_path *)uridp;
> +   argc -= 3;
> +   argv += 3;
> +   break;
> +   }
> +#endif
> +
> default:
> r = CMD_RET_USAGE;
> goto out;
> @@ -1491,6 +1539,9 @@ U_BOOT_LONGHELP(efidebug,
> "  -b|-B[:] \n"
> "  -i|-I  [:] \n"
> "  (-b, -i for short form device path)\n"
> +#if (IS_ENABLED(CONFIG_EFI_HTTP_BOOT))
> +   "  -u   \n"
> +#endif
> "  -s ''\n"
> "efidebug boot rm  [ [ [...]]]\n"
> "  - delete UEFI Boot variables\n"
> diff --git a/include/net.h b/include/net.h
> index 57889d8b7a..c748974573 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -935,4 +935,12 @@ static inline void eth_set_enable_bootdevs(bool enable) 
> {}
>   */
>  int wget_with_dns(ulong dst_addr, char *uri);
>
> +/**
> + * wget_validate_uri() - varidate the uri
> + *
> + * @uri:   uri string of target file of wget
> + * Return: true if uri is valid, false if uri is invalid
> + */
> +bool wget_validate_uri(char *uri);
> +
>  #endif /* __NET_H__ */
> diff --git a/net/wget.c b/net/wget.c
> index 2087146b37..6ae2237a0a 100644
> --- a/net/wget.c
> +++ b/net/wget.c
> @@ -566,3 +566,74 @@ out:
> return ret;
>  }
>  #endif
> +
> +/**
> + * wget_validate_uri() - validate the uri for wget
> + *
> + * @uri:   uri string
> + *
> + * This function follows the current U-Boot wget implementation.
> + * scheme: only "http:" is supported
> + * authority:
> + *   - user information: not supported
> + *   - host: supported
> + *   - port: not supported(always use the default port)
> + *
> + * Uri is expected to be correctly percent encoded.
> + * This is the minimum check, control codes(0x1-0x19, 0x7F, except '\0')
> + * and 

Re: [PATCH] scsi: Have scsi_init_dev_desc_priv() use memset

2023-11-08 Thread Simon Glass
On Wed, 8 Nov 2023 at 12:28, Tom Rini  wrote:
>
> When we do not have CONFIG_BOUNCE_BUFFER enabled, inside of
> scsi_init_dev_desc_priv we never set the 'bb' field to false, we only
> initialize it to true when CONFIG_BOUNCE_BUFFER is set. Given that we
> have a number of other fields here we had been explicitly setting to
> zero, change to first calling memset to clear the struct and then
> initialize only the fields that need non-zero default values.
>
> Addresses-Coverity-ID: 467407 ("Uninitialized variables (UNINIT)")
> Fixes: 81bd22e935dc ("rockchip: block: blk-uclass: add bounce buffer flag to 
> blk_desc")
> Signed-off-by: Tom Rini 
> ---
> Cc: Johan Jonker 
> ---
>  drivers/scsi/scsi.c | 5 +
>  1 file changed, 1 insertion(+), 4 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH v7 08/26] spl: Refactor spl_load_info->read to use units of bytes

2023-11-08 Thread Simon Glass
On Wed, 8 Nov 2023 at 09:49, Sean Anderson  wrote:
>
> Simplify things a bit for callers of spl_load_info->read by refactoring it
> to use units of bytes instead of bl_len. This generally simplifies the
> logic, as MMC is the only loader which actually works in sectors. It will
> also allow further refactoring to remove the special-case handling of
> filename.  spl_load_legacy_img already works in units of bytes (oops) so it
> doesn't need to be changed.
>
> Signed-off-by: Sean Anderson 
> ---
>
> Changes in v7:
> - Reword documentation for spl_load_info
>
> Changes in v6:
> - New
>
>  arch/arm/mach-imx/spl_imx_romapi.c | 16 +++---
>  common/spl/spl_fit.c   | 51 +++---
>  common/spl/spl_imx_container.c | 45 +++---
>  common/spl/spl_mmc.c   | 24 --
>  common/spl/spl_nand.c  |  8 ++---
>  include/spl.h  | 18 +++
>  test/image/spl_load_os.c   | 13 
>  7 files changed, 82 insertions(+), 93 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH] sysreset: Fix unsupported request return values

2023-11-08 Thread Simon Glass
On Wed, 8 Nov 2023 at 01:51, Paul Barker  wrote:
>
> The description of the sysreset request method in  says that
> the return value should be -EPROTONOSUPPORT if the requested reset type
> is not supported by this device.
>
> Signed-off-by: Paul Barker 
> ---
>  drivers/sysreset/poweroff_gpio.c | 2 +-
>  drivers/sysreset/sysreset_psci.c | 2 +-
>  drivers/sysreset/sysreset_sandbox.c  | 4 ++--
>  drivers/sysreset/sysreset_watchdog.c | 2 +-
>  drivers/sysreset/sysreset_x86.c  | 2 +-
>  test/dm/sysreset.c   | 6 +++---
>  6 files changed, 9 insertions(+), 9 deletions(-)

Reviewed-by: Simon Glass 


>
> diff --git a/drivers/sysreset/poweroff_gpio.c 
> b/drivers/sysreset/poweroff_gpio.c
> index a5c24fd85bca..ad04e4b1a85e 100644
> --- a/drivers/sysreset/poweroff_gpio.c
> +++ b/drivers/sysreset/poweroff_gpio.c
> @@ -33,7 +33,7 @@ static int poweroff_gpio_request(struct udevice *dev, enum 
> sysreset_t type)
> int r;
>
> if (type != SYSRESET_POWER_OFF)
> -   return -ENOSYS;
> +   return -EPROTONOSUPPORT;
>
> debug("GPIO poweroff\n");
>
> diff --git a/drivers/sysreset/sysreset_psci.c 
> b/drivers/sysreset/sysreset_psci.c
> index a8a41528a849..aa09d0b88271 100644
> --- a/drivers/sysreset/sysreset_psci.c
> +++ b/drivers/sysreset/sysreset_psci.c
> @@ -25,7 +25,7 @@ static int psci_sysreset_request(struct udevice *dev, enum 
> sysreset_t type)
> psci_sys_poweroff();
> break;
> default:
> -   return -ENOSYS;
> +   return -EPROTONOSUPPORT;
> }
>
> return -EINPROGRESS;
> diff --git a/drivers/sysreset/sysreset_sandbox.c 
> b/drivers/sysreset/sysreset_sandbox.c
> index f485a1352993..c12eda81d03e 100644
> --- a/drivers/sysreset/sysreset_sandbox.c
> +++ b/drivers/sysreset/sysreset_sandbox.c
> @@ -21,7 +21,7 @@ static int sandbox_warm_sysreset_request(struct udevice 
> *dev,
> state->last_sysreset = type;
> break;
> default:
> -   return -ENOSYS;
> +   return -EPROTONOSUPPORT;
> }
> if (!state->sysreset_allowed[type])
> return -EACCES;
> @@ -70,7 +70,7 @@ static int sandbox_sysreset_request(struct udevice *dev, 
> enum sysreset_t type)
> return -EACCES;
> sandbox_exit();
> default:
> -   return -ENOSYS;
> +   return -EPROTONOSUPPORT;
> }
> if (!state->sysreset_allowed[type])
> return -EACCES;
> diff --git a/drivers/sysreset/sysreset_watchdog.c 
> b/drivers/sysreset/sysreset_watchdog.c
> index ceada2e47b54..6db5aa75b541 100644
> --- a/drivers/sysreset/sysreset_watchdog.c
> +++ b/drivers/sysreset/sysreset_watchdog.c
> @@ -29,7 +29,7 @@ static int wdt_reboot_request(struct udevice *dev, enum 
> sysreset_t type)
> return ret;
> break;
> default:
> -   return -ENOSYS;
> +   return -EPROTONOSUPPORT;
> }
>
> return -EINPROGRESS;
> diff --git a/drivers/sysreset/sysreset_x86.c b/drivers/sysreset/sysreset_x86.c
> index 4936fdb76c72..dc772b5ff9e3 100644
> --- a/drivers/sysreset/sysreset_x86.c
> +++ b/drivers/sysreset/sysreset_x86.c
> @@ -87,7 +87,7 @@ static int x86_sysreset_request(struct udevice *dev, enum 
> sysreset_t type)
> return ret;
> return -EINPROGRESS;
> default:
> -   return -ENOSYS;
> +   return -EPROTONOSUPPORT;
> }
>
> outb(value, IO_PORT_RESET);
> diff --git a/test/dm/sysreset.c b/test/dm/sysreset.c
> index 691683c56740..5aa69e046186 100644
> --- a/test/dm/sysreset.c
> +++ b/test/dm/sysreset.c
> @@ -27,8 +27,8 @@ static int dm_test_sysreset_base(struct unit_test_state 
> *uts)
> /* Device 1 is the warm sysreset device */
> ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, ));
> ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_WARM));
> -   ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_COLD));
> -   ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_POWER));
> +   ut_asserteq(-EPROTONOSUPPORT, sysreset_request(dev, SYSRESET_COLD));
> +   ut_asserteq(-EPROTONOSUPPORT, sysreset_request(dev, SYSRESET_POWER));
>
> state->sysreset_allowed[SYSRESET_WARM] = true;
> ut_asserteq(-EINPROGRESS, sysreset_request(dev, SYSRESET_WARM));
> @@ -36,7 +36,7 @@ static int dm_test_sysreset_base(struct unit_test_state 
> *uts)
>
> /* Device 2 is the cold sysreset device */
> ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, ));
> -   ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_WARM));
> +   ut_asserteq(-EPROTONOSUPPORT, sysreset_request(dev, SYSRESET_WARM));
> state->sysreset_allowed[SYSRESET_COLD] = false;
> ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_COLD));
> 

Re: [PATCH v7 02/26] arm: Disable SPL_FS_FAT when it isn't used

2023-11-08 Thread Simon Glass
On Wed, 8 Nov 2023 at 09:49, Sean Anderson  wrote:
>
> Several boards enable SPL_FS_FAT and SPL_LIBDISK_SUPPORT when they can't be
> used (as there is no block device support enabled). Disable these configs.
> The list of boards was generated with the following command:
>
> $ tools/qconfig.py -f SPL SPL_FS_FAT ~SPL_MMC ~SPL_BLK_FS ~SPL_SATA \
>   ~SPL_USB_STORAGE ~ENV_IS_IN_FAT ~EFI
>
> LIBDISK was left enabled for the am* boards, since it seems to result in
> actual size reduction, indicating that partitions are being used for
> something.
>
> Signed-off-by: Sean Anderson 
> ---
>
> Changes in v7:
> - Disable FS_FAT for the zynq(mp) boards as well, as suggested by Michal
>
> Changes in v6:
> - New
>
>  configs/am335x_evm_spiboot_defconfig  | 2 +-
>  configs/am65x_evm_r5_usbdfu_defconfig | 1 -
>  configs/xilinx_zynqmp_mini_qspi_defconfig | 3 ++-
>  configs/zynq_cse_nand_defconfig   | 2 ++
>  configs/zynq_cse_nor_defconfig| 2 ++
>  configs/zynq_cse_qspi_defconfig   | 2 ++
>  6 files changed, 9 insertions(+), 3 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH v7 10/26] spl: Remove filename from spl_load_info

2023-11-08 Thread Simon Glass
On Wed, 8 Nov 2023 at 09:49, Sean Anderson  wrote:
>
> For filesystems, filename serves the same purpose as priv. However,
> spl_load_fit_image also uses it to determine whether to use a DMA-aligned
> buffer. This is beneficial for FAT, which uses a bounce-buffer if the
> destination is not DMA-aligned. However, this is unnecessary now that
> filesystems set bl_len to ARCH_DMA_MINALIGN instead. With this done, we can
> remove filename entirely.
>
> Signed-off-by: Sean Anderson 
> ---
>
> Changes in v7:
> - Split off setting bl_len to ARCH_DMA_MINALIGN from filename removal
>
> Changes in v6:
> - New
>
>  arch/arm/mach-sunxi/spl_spi_sunxi.c | 1 -
>  common/spl/spl_blk_fs.c | 7 ---
>  common/spl/spl_fat.c| 4 ++--
>  common/spl/spl_mmc.c| 2 --
>  common/spl/spl_nand.c   | 3 ---
>  common/spl/spl_semihosting.c| 1 -
>  common/spl/spl_spi.c| 2 --
>  common/spl/spl_ymodem.c | 1 -
>  include/spl.h   | 2 --
>  test/image/spl_load_os.c| 1 -
>  10 files changed, 6 insertions(+), 18 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH v7 09/26] spl: Set FAT bl_len to ARCH_DMA_MINALIGN

2023-11-08 Thread Simon Glass
On Wed, 8 Nov 2023 at 09:49, Sean Anderson  wrote:
>
> Instead of relying on the presence of filename to determine whether we are
> dealing with a FAT filesystem (and should DMA-align the buffer), have FAT set
> bl_len to ARCH_DMA_MINALIGN instead. With this done, we can remove the
> special-case logic checking for the presence of filename.
>
> Because filesystems are not block-based, we may read less than the size passed
> to spl_load_info.read. This can happen if the file size is not DMA-aligned. 
> This
> is fine as long as we read the amount we originally wanted to. Modify the
> conditions for callers of spl_load_info.read to check against the original,
> unaligned size to avoid failing spuriously.
>
> Signed-off-by: Sean Anderson 
> ---
>
> Changes in v7:
> - Split off from the removal of filename
>
>  common/spl/spl_blk_fs.c|  3 ++-
>  common/spl/spl_fat.c   |  2 +-
>  common/spl/spl_fit.c   | 23 +--
>  common/spl/spl_imx_container.c |  8 +---
>  4 files changed, 9 insertions(+), 27 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH v11 2/9] net: wget: add wget with dns utility function

2023-11-08 Thread Simon Glass
On Wed, 8 Nov 2023 at 04:07, Masahisa Kojima  wrote:
>
> Current wget takes the target uri in this format:
>  ":"  e.g.) 192.168.1.1:/bar
> The http server ip address must be resolved before
> calling wget.
>
> This commit adds the utility function runs wget with dhs.
> User can call wget with the uri like "http://foo/bar;.
>
> Signed-off-by: Masahisa Kojima 
> Reviewed-by: Ilias Apalodimas 
> Reviewed-by: Ramon Fried 
> ---
>  include/net.h |  9 +
>  net/wget.c| 54 +++
>  2 files changed, 63 insertions(+)

Reviewed-by: Simon Glass 


Re: [PATCH] net: Make NET imply NETDEVICES

2023-11-08 Thread Simon Glass
On Wed, 8 Nov 2023 at 17:12, Tom Rini  wrote:
>
> Normally, when NET is enabled, CMD_NET will then be enabled and in turn
> NETDEVICES will (likely) be enabled via imply. However, if we disable
> CMDLINE in a defconfig we now no longer get CMD_NET enabling NETDEVICES
> for us. This suggestion (as an imply is) really isn't about the network
> commands but network itself and is a legacy of how intertwined
> NET/CMD_NET were historically. Move this over to the NET entry instead
> where it is a more logical fit.
>
> Reported-by: Simon Glass 
> Signed-off-by: Tom Rini 
> ---
> This could also be dropping the imply from cmd/Kconfig and instead
> making drivers/net/Kconfig::NETDEVICES be default y, which is what it
> practically is today. This would require a more lengthy check however to
> be sure there's no functional change and I'm not sure it's any better or
> worse than this approach.
> ---
>  cmd/Kconfig | 1 -
>  net/Kconfig | 1 +
>  2 files changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 
Tested-by: Simon Glass 

Thanks!


[PATCH 2/2] cmd: bcb: extend BCB C API to allow read/write the fields

2023-11-08 Thread Dmitrii Merkurev
Currently BCB C API only allows to modify 'command' BCB field.
Extend it so that we can also read and modify all the available
BCB fields (command, status, recovery, stage).

Co-developed-by: Cody Schuffelen 
Signed-off-by: Cody Schuffelen 
Signed-off-by: Dmitrii Merkurev 
Cc: Eugeniu Rosca 
Cc: Ying-Chun Liu (PaulLiu) 
Cc: Simon Glass 
Cc: Mattijs Korpershoek 
Cc: Sean Anderson 
Cc: Cody Schuffelen 
---
 cmd/bcb.c| 162 +++
 drivers/fastboot/fb_common.c |  14 ++-
 include/bcb.h|  60 -
 3 files changed, 179 insertions(+), 57 deletions(-)

diff --git a/cmd/bcb.c b/cmd/bcb.c
index 5d8c232663..7a77b7f7b0 100644
--- a/cmd/bcb.c
+++ b/cmd/bcb.c
@@ -25,10 +25,18 @@ enum bcb_cmd {
BCB_CMD_STORE,
 };
 
-static enum uclass_id bcb_uclass_id = UCLASS_INVALID;
-static int bcb_dev = -1;
-static int bcb_part = -1;
+static const char * const fields[] = {
+   "command",
+   "status",
+   "recovery",
+   "stage"
+};
+
 static struct bootloader_message bcb __aligned(ARCH_DMA_MINALIGN) = { { 0 } };
+static struct disk_partition partition_data;
+
+static struct blk_desc *block;
+static struct disk_partition *partition = _data;
 
 static int bcb_cmd_get(char *cmd)
 {
@@ -82,7 +90,7 @@ static int bcb_is_misused(int argc, char *const argv[])
return -1;
}
 
-   if (cmd != BCB_CMD_LOAD && (bcb_dev < 0 || bcb_part < 0)) {
+   if (cmd != BCB_CMD_LOAD && !block) {
printf("Error: Please, load BCB first!\n");
return -1;
}
@@ -94,7 +102,7 @@ err:
return -1;
 }
 
-static int bcb_field_get(char *name, char **fieldp, int *sizep)
+static int bcb_field_get(const char *name, char **fieldp, int *sizep)
 {
if (!strcmp(name, "command")) {
*fieldp = bcb.command;
@@ -119,16 +127,21 @@ static int bcb_field_get(char *name, char **fieldp, int 
*sizep)
return 0;
 }
 
-static int __bcb_load(const char *iface, int devnum, const char *partp)
+static void __bcb_reset(void)
+{
+   block = NULL;
+   partition = _data;
+   memset(_data, 0, sizeof(struct disk_partition));
+   memset(, 0, sizeof(struct bootloader_message));
+}
+
+static int __bcb_initialize(const char *iface, int devnum, const char *partp)
 {
-   struct blk_desc *desc;
-   struct disk_partition info;
-   u64 cnt;
char *endp;
int part, ret;
 
-   desc = blk_get_dev(iface, devnum);
-   if (!desc) {
+   block = blk_get_dev(iface, devnum);
+   if (!block) {
ret = -ENODEV;
goto err_read_fail;
}
@@ -137,7 +150,7 @@ static int __bcb_load(const char *iface, int devnum, const 
char *partp)
 * always select the first hwpart in case another
 * blk operation selected a different hwpart
 */
-   ret = blk_dselect_hwpart(desc, 0);
+   ret = blk_dselect_hwpart(block, 0);
if (IS_ERR_VALUE(ret)) {
ret = -ENODEV;
goto err_read_fail;
@@ -145,49 +158,63 @@ static int __bcb_load(const char *iface, int devnum, 
const char *partp)
 
part = simple_strtoul(partp, , 0);
if (*endp == '\0') {
-   ret = part_get_info(desc, part, );
+   ret = part_get_info(block, part, partition);
if (ret)
goto err_read_fail;
} else {
-   part = part_get_info_by_name(desc, partp, );
+   part = part_get_info_by_name(block, partp, partition);
if (part < 0) {
ret = part;
goto err_read_fail;
}
}
 
-   cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), info.blksz);
-   if (cnt > info.size)
+   return CMD_RET_SUCCESS;
+
+err_read_fail:
+   printf("Error: %d %d:%s read failed (%d)\n", block->uclass_id,
+  block->devnum, partition->name, ret);
+   goto err;
+err:
+   __bcb_reset();
+   return CMD_RET_FAILURE;
+}
+
+static int __bcb_load(void)
+{
+   u64 cnt;
+   int ret;
+
+   cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), partition->blksz);
+   if (cnt > partition->size)
goto err_too_small;
 
-   if (blk_dread(desc, info.start, cnt, ) != cnt) {
+   if (blk_dread(block, partition->start, cnt, ) != cnt) {
ret = -EIO;
goto err_read_fail;
}
 
-   bcb_uclass_id = desc->uclass_id;
-   bcb_dev = desc->devnum;
-   bcb_part = part;
-   debug("%s: Loaded from %s %d:%d\n", __func__, iface, bcb_dev, bcb_part);
+   debug("%s: Loaded from %d %d:%s\n", __func__, block->uclass_id,
+ block->devnum, partition->name);
 
return CMD_RET_SUCCESS;
 err_read_fail:
-   printf("Error: %s %d:%s read failed (%d)\n", iface, devnum, partp, ret);
+   printf("Error: %d %d:%s read failed (%d)\n", block->uclass_id,
+  

[PATCH 1/2] cmd: bcb: support various block device interfaces for BCB command

2023-11-08 Thread Dmitrii Merkurev
Currently BCB command-line, C APIs and implementation only
support MMC interface. Extend it to allow various block
device interfaces.

Signed-off-by: Dmitrii Merkurev 
Cc: Eugeniu Rosca 
Cc: Ying-Chun Liu (PaulLiu) 
Cc: Simon Glass 
Cc: Mattijs Korpershoek 
Cc: Sean Anderson 
Cc: Cody Schuffelen 
---
 cmd/Kconfig  |  1 -
 cmd/bcb.c| 70 ++--
 doc/android/bcb.rst  | 34 +-
 drivers/fastboot/fb_common.c |  2 +-
 include/bcb.h|  5 +--
 5 files changed, 65 insertions(+), 47 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index df6d71c103..ce2435bbb8 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -981,7 +981,6 @@ config CMD_ADC
 
 config CMD_BCB
bool "bcb"
-   depends on MMC
depends on PARTITIONS
help
  Read/modify/write the fields of Bootloader Control Block, usually
diff --git a/cmd/bcb.c b/cmd/bcb.c
index 02d0c70d87..5d8c232663 100644
--- a/cmd/bcb.c
+++ b/cmd/bcb.c
@@ -25,6 +25,7 @@ enum bcb_cmd {
BCB_CMD_STORE,
 };
 
+static enum uclass_id bcb_uclass_id = UCLASS_INVALID;
 static int bcb_dev = -1;
 static int bcb_part = -1;
 static struct bootloader_message bcb __aligned(ARCH_DMA_MINALIGN) = { { 0 } };
@@ -53,6 +54,9 @@ static int bcb_is_misused(int argc, char *const argv[])
 
switch (cmd) {
case BCB_CMD_LOAD:
+   if (argc != 3 && argc != 4)
+   goto err;
+   break;
case BCB_CMD_FIELD_SET:
if (argc != 3)
goto err;
@@ -115,7 +119,7 @@ static int bcb_field_get(char *name, char **fieldp, int 
*sizep)
return 0;
 }
 
-static int __bcb_load(int devnum, const char *partp)
+static int __bcb_load(const char *iface, int devnum, const char *partp)
 {
struct blk_desc *desc;
struct disk_partition info;
@@ -123,14 +127,14 @@ static int __bcb_load(int devnum, const char *partp)
char *endp;
int part, ret;
 
-   desc = blk_get_devnum_by_uclass_id(UCLASS_MMC, devnum);
+   desc = blk_get_dev(iface, devnum);
if (!desc) {
ret = -ENODEV;
goto err_read_fail;
}
 
/*
-* always select the USER mmc hwpart in case another
+* always select the first hwpart in case another
 * blk operation selected a different hwpart
 */
ret = blk_dselect_hwpart(desc, 0);
@@ -161,18 +165,20 @@ static int __bcb_load(int devnum, const char *partp)
goto err_read_fail;
}
 
+   bcb_uclass_id = desc->uclass_id;
bcb_dev = desc->devnum;
bcb_part = part;
-   debug("%s: Loaded from mmc %d:%d\n", __func__, bcb_dev, bcb_part);
+   debug("%s: Loaded from %s %d:%d\n", __func__, iface, bcb_dev, bcb_part);
 
return CMD_RET_SUCCESS;
 err_read_fail:
-   printf("Error: mmc %d:%s read failed (%d)\n", devnum, partp, ret);
+   printf("Error: %s %d:%s read failed (%d)\n", iface, devnum, partp, ret);
goto err;
 err_too_small:
-   printf("Error: mmc %d:%s too small!", devnum, partp);
+   printf("Error: %s %d:%s too small!", iface, devnum, partp);
goto err;
 err:
+   bcb_uclass_id = UCLASS_INVALID;
bcb_dev = -1;
bcb_part = -1;
 
@@ -182,15 +188,23 @@ err:
 static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
   char * const argv[])
 {
+   int devnum;
char *endp;
-   int devnum = simple_strtoul(argv[1], , 0);
+   char *iface = "mcc";
+
+   if (argc == 4) {
+   iface = argv[1];
+   argc--;
+   argv++;
+   }
 
+   devnum = simple_strtoul(argv[1], , 0);
if (*endp != '\0') {
printf("Error: Device id '%s' not a number\n", argv[1]);
return CMD_RET_FAILURE;
}
 
-   return __bcb_load(devnum, argv[2]);
+   return __bcb_load(iface, devnum, argv[2]);
 }
 
 static int __bcb_set(char *fieldp, const char *valp)
@@ -298,7 +312,7 @@ static int __bcb_store(void)
u64 cnt;
int ret;
 
-   desc = blk_get_devnum_by_uclass_id(UCLASS_MMC, bcb_dev);
+   desc = blk_get_devnum_by_uclass_id(bcb_uclass_id, bcb_dev);
if (!desc) {
ret = -ENODEV;
goto err;
@@ -317,7 +331,7 @@ static int __bcb_store(void)
 
return CMD_RET_SUCCESS;
 err:
-   printf("Error: mmc %d:%d write failed (%d)\n", bcb_dev, bcb_part, ret);
+   printf("Error: %d %d:%d write failed (%d)\n", bcb_uclass_id, bcb_dev, 
bcb_part, ret);
 
return CMD_RET_FAILURE;
 }
@@ -328,11 +342,11 @@ static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, 
int argc,
return __bcb_store();
 }
 
-int bcb_write_reboot_reason(int devnum, char *partp, const char *reasonp)
+int bcb_write_reboot_reason(const char *iface, int devnum, char *partp, const 
char *reasonp)
 {
int ret;
 
-   ret = 

[PATCH 0/2] cmd: bcb: extend BCB APIs to support Android boot flow

2023-11-08 Thread Dmitrii Merkurev
Following patches introduce various block interfaces support
and extend API of BCB (bootloader control block) to reuse it
for Android boot flow of Cuttlefish virtual device.

Signed-off-by: Dmitrii Merkurev 
Cc: Eugeniu Rosca 
Cc: Ying-Chun Liu (PaulLiu) 
Cc: Simon Glass 
Cc: Mattijs Korpershoek 
Cc: Sean Anderson 
Cc: Cody Schuffelen 

Dmitrii Merkurev (2):
  cmd: bcb: support various block device interfaces for BCB command
  cmd: bcb: extend BCB C API to allow read/write the fields

 cmd/Kconfig  |   1 -
 cmd/bcb.c| 206 +++
 doc/android/bcb.rst  |  34 +++---
 drivers/fastboot/fb_common.c |  14 ++-
 include/bcb.h|  59 +-
 5 files changed, 227 insertions(+), 87 deletions(-)

-- 
2.42.0.869.gea05f2083d-goog



Re: inconsistent wget behavior

2023-11-08 Thread Tom Rini
On Wed, Nov 08, 2023 at 09:00:23PM -0300, Fabio Estevam wrote:

> [Adding Tom and Marek]
> 
> On Wed, Nov 8, 2023 at 7:22 PM Tim Harvey  wrote:
> >
> > Greetings,
> >
> > I've recently given wget/tcp a try and find the results inconsistent.
> >
> > Transferring the same file 15 times in a row will eventually give me
> > an incomplete transfer with packet/byte count wrong but showing
> > 'Transfer Successful'.
> >
> > Here is current master on an imx8mp-venice-gw74xx board using IMX8MP
> > EQOS enet dev:
> >
> 
> > u-boot=> time wget $loadaddr
> > /tftpboot/venice/core-image-minimal.ext4.gz && md5sum $loadaddr
> > $filesize
> > HTTP/1.0 200 OK| | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | | |
> >  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | | |
> >  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | | |
> >  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | | |
> >  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | |
> > Packets received 64368, Transfer Successful
> > Bytes transferred = 93198937 (58e1a59 hex)
> >
> > time: 3.103 seconds
> > md5 for 4820 ... 4dae1a58 ==> 69bedfe899148c43c09a98ac950dd0ed
> 
> 
> > u-boot=> time wget $loadaddr
> > /tftpboot/venice/core-image-minimal.ext4.gz && md5sum $loadaddr
> > $filesize
> > HTTP/1.0 200 OK| | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | | |
> >  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | | |
> >  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | | |
> >  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | | | | | | | | | | | | | | | | | | | |
> >  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > | | | | | |
> > Packets received 64368, Transfer Successful
> > Bytes transferred = 26984682 (19bc0ea hex)
> >
> > time: 3.011 seconds
> > md5 for 4820 ... 49bbc0e9 ==> c9978ff116605a7729a1cb14ef51fc20
> >
> > Anyone else seeing this?
> 
> Yes, I am seeing the same behavior on an imx8mn board using the FEC driver.
> 
> I am transferring a 412MB file. Doing the wget transfers several times
> in a row, I also see the incorrect number of bytes transferred:

Interesting.  What if you take wget out of the equation and use "tftp"
to grab a large file with a known checksum, repeatedly (note that "rhash
-C" will give a crc32 in Linux so you can confirm the correct value and
loop a get, crc32, compare, repeat loop with a little work) ? I ask
because I was reminded today that for me at least, the RPi ethernet
isn't reliable in U-Boot for me if you stress it too hard. So I'd like
to try see if this is "wget bug" or "network driver/related bug".

-- 
Tom


signature.asc
Description: PGP signature


[PATCH] net: Make NET imply NETDEVICES

2023-11-08 Thread Tom Rini
Normally, when NET is enabled, CMD_NET will then be enabled and in turn
NETDEVICES will (likely) be enabled via imply. However, if we disable
CMDLINE in a defconfig we now no longer get CMD_NET enabling NETDEVICES
for us. This suggestion (as an imply is) really isn't about the network
commands but network itself and is a legacy of how intertwined
NET/CMD_NET were historically. Move this over to the NET entry instead
where it is a more logical fit.

Reported-by: Simon Glass 
Signed-off-by: Tom Rini 
---
This could also be dropping the imply from cmd/Kconfig and instead
making drivers/net/Kconfig::NETDEVICES be default y, which is what it
practically is today. This would require a more lengthy check however to
be sure there's no functional change and I'm not sure it's any better or
worse than this approach.
---
 cmd/Kconfig | 1 -
 net/Kconfig | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 629a90afb7b5..1b4aad5c930b 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1682,7 +1682,6 @@ if NET
 menuconfig CMD_NET
bool "Network commands"
default y
-   imply NETDEVICES
 
 if CMD_NET
 
diff --git a/net/Kconfig b/net/Kconfig
index 4215889127c9..8c80b3a6c671 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -5,6 +5,7 @@
 menuconfig NET
bool "Networking support"
default y
+   imply NETDEVICES
 
 if NET
 
-- 
2.34.1



Re: inconsistent wget behavior

2023-11-08 Thread Fabio Estevam
[Adding Tom and Marek]

On Wed, Nov 8, 2023 at 7:22 PM Tim Harvey  wrote:
>
> Greetings,
>
> I've recently given wget/tcp a try and find the results inconsistent.
>
> Transferring the same file 15 times in a row will eventually give me
> an incomplete transfer with packet/byte count wrong but showing
> 'Transfer Successful'.
>
> Here is current master on an imx8mp-venice-gw74xx board using IMX8MP
> EQOS enet dev:
>

> u-boot=> time wget $loadaddr
> /tftpboot/venice/core-image-minimal.ext4.gz && md5sum $loadaddr
> $filesize
> HTTP/1.0 200 OK| | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | | |
>  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | | |
>  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | | |
>  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | | |
>  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | |
> Packets received 64368, Transfer Successful
> Bytes transferred = 93198937 (58e1a59 hex)
>
> time: 3.103 seconds
> md5 for 4820 ... 4dae1a58 ==> 69bedfe899148c43c09a98ac950dd0ed


> u-boot=> time wget $loadaddr
> /tftpboot/venice/core-image-minimal.ext4.gz && md5sum $loadaddr
> $filesize
> HTTP/1.0 200 OK| | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | | |
>  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | | |
>  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | | |
>  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | | | | | | | | | | | | | | | | | | | |
>  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
> | | | | | |
> Packets received 64368, Transfer Successful
> Bytes transferred = 26984682 (19bc0ea hex)
>
> time: 3.011 seconds
> md5 for 4820 ... 49bbc0e9 ==> c9978ff116605a7729a1cb14ef51fc20
>
> Anyone else seeing this?

Yes, I am seeing the same behavior on an imx8mn board using the FEC driver.

I am transferring a 412MB file. Doing the wget transfers several times
in a row, I also see the incorrect number of bytes transferred:

u-boot=> wget test
HTTP/1.0 200 OK| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 

Re: [PATCH v11 24/24] DO NOT MERGE: ci: Build the world in any case.

2023-11-08 Thread Tom Rini
On Tue, Nov 07, 2023 at 11:41:21PM +0200, Francis Laniel wrote:

> The CI can fails previously for reasons which are not tied to hush 2021.
> Let's build the world in any case to check everything is OK there too.
> 
> Signed-off-by: Francis Laniel 
> ---
>  .azure-pipelines.yml | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
> index d6f3fa423c..4eaf0e9062 100644
> --- a/.azure-pipelines.yml
> +++ b/.azure-pipelines.yml
> @@ -469,6 +469,7 @@ stages:
>  retryCountOnTaskFailure: 2 # QEMU may be too slow, etc.
>  
>  - stage: world_build
> +  condition: always()
>jobs:
>- job: build_the_world
>  timeoutInMinutes: 0 # Use the maximum allowed

I _think_ this patch can just be dropped from your series as well at
this point. Azure now has some automatic retry logic that catches most
of the cases of when the job fails but it's not our codebase that caused
the problem and it's something transient to the CI hosts/etc.

-- 
Tom


signature.asc
Description: PGP signature


inconsistent wget behavior

2023-11-08 Thread Tim Harvey
Greetings,

I've recently given wget/tcp a try and find the results inconsistent.

Transferring the same file 15 times in a row will eventually give me
an incomplete transfer with packet/byte count wrong but showing
'Transfer Successful'.

Here is current master on an imx8mp-venice-gw74xx board using IMX8MP
EQOS enet dev:

u-boot=> time wget $loadaddr
/tftpboot/venice/core-image-minimal.ext4.gz && md5sum $loadaddr
$filesize
HTTP/1.0 200 OK| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |
 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |
 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |
 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |
 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | |
Packets received 64368, Transfer Successful
Bytes transferred = 93198937 (58e1a59 hex)

time: 3.099 seconds
md5 for 4820 ... 4dae1a58 ==> 69bedfe899148c43c09a98ac950dd0ed
u-boot=> time wget $loadaddr
/tftpboot/venice/core-image-minimal.ext4.gz && md5sum $loadaddr
$filesize
HTTP/1.0 200 OK| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |
 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |
 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |
 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |
 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | |
Packets received 64368, Transfer Successful
Bytes transferred = 93198937 (58e1a59 hex)

time: 3.103 seconds
md5 for 4820 ... 4dae1a58 ==> 69bedfe899148c43c09a98ac950dd0ed
u-boot=> time wget $loadaddr
/tftpboot/venice/core-image-minimal.ext4.gz && md5sum $loadaddr
$filesize
HTTP/1.0 200 OK| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |
 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |
 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |
 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |
 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | |
Packets received 64368, Transfer Successful
Bytes transferred = 93198937 (58e1a59 hex)

time: 3.091 seconds
md5 for 4820 ... 4dae1a58 ==> 69bedfe899148c43c09a98ac950dd0ed
u-boot=> time wget $loadaddr
/tftpboot/venice/core-image-minimal.ext4.gz && md5sum $loadaddr
$filesize
HTTP/1.0 200 OK| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |
 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |
 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | 

[PATCH] scsi: Have scsi_init_dev_desc_priv() use memset

2023-11-08 Thread Tom Rini
When we do not have CONFIG_BOUNCE_BUFFER enabled, inside of
scsi_init_dev_desc_priv we never set the 'bb' field to false, we only
initialize it to true when CONFIG_BOUNCE_BUFFER is set. Given that we
have a number of other fields here we had been explicitly setting to
zero, change to first calling memset to clear the struct and then
initialize only the fields that need non-zero default values.

Addresses-Coverity-ID: 467407 ("Uninitialized variables (UNINIT)")
Fixes: 81bd22e935dc ("rockchip: block: blk-uclass: add bounce buffer flag to 
blk_desc")
Signed-off-by: Tom Rini 
---
Cc: Johan Jonker 
---
 drivers/scsi/scsi.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 363047d0f72c..7dfe0c5e0562 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -368,15 +368,12 @@ static void scsi_setup_test_unit_ready(struct scsi_cmd 
*pccb)
  */
 static void scsi_init_dev_desc_priv(struct blk_desc *dev_desc)
 {
+   memset(dev_desc, 0, sizeof(struct blk_desc));
dev_desc->target = 0xff;
dev_desc->lun = 0xff;
dev_desc->log2blksz =
LOG2_INVALID(typeof(dev_desc->log2blksz));
dev_desc->type = DEV_TYPE_UNKNOWN;
-   dev_desc->vendor[0] = 0;
-   dev_desc->product[0] = 0;
-   dev_desc->revision[0] = 0;
-   dev_desc->removable = false;
 #if IS_ENABLED(CONFIG_BOUNCE_BUFFER)
dev_desc->bb = true;
 #endif /* CONFIG_BOUNCE_BUFFER */
-- 
2.34.1



Re: [PATCH v3 1/6] net: split IP_TCP header into separate IP/IP6 and TCP headers

2023-11-08 Thread Dmitrii Merkurev
Hey Tom, huge thanks for sharing that. I agree lwip is the proper way to
handle this, will try out this patch set and eventually migrate fastboot
apps into a new stack.

On Wed, Nov 8, 2023 at 6:45 AM Tom Rini  wrote:

> On Tue, Jul 25, 2023 at 10:56:52PM +0100, Dmitrii Merkurev wrote:
>
> > This allows us to reuse TCP logic between IP and IP6 stack.
> >
> > Signed-off-by: Dmitrii Merkurev 
> > Cc: Ying-Chun Liu (PaulLiu) 
> > Cc: Simon Glass 
> > Сс: Joe Hershberger 
> > Сс: Ramon Fried 
> > Reviewed-by: Ying-Chun Liu (PaulLiu) 
> > Reviewed-by: Simon Glass 
> > ---
> >  include/net/tcp.h | 54 
> >  net/tcp.c | 70 +++
> >  test/cmd/wget.c   | 48 ++--
> >  3 files changed, 85 insertions(+), 87 deletions(-)
>
> I do want to thank you for your contribution. However, the long term
> goal with the project right now is to move to integrate lwip as the
> networking stack (and in turn have more robust IPv6 and wget and
> similar features). So, I don't want to pickup this series (unless you
> think it's still important here-and-now, given the above). I would ask
> you to please keep an eye on that effort and either try out v10:
> https://patchwork.ozlabs.org/project/uboot/list/?series=374882=*
> or keep an eye out for v11. Thanks again!
>
> --
> Tom
>


Re: [PATCH v1 2/2] fs: fat: calculate FAT type based on cluster count

2023-11-08 Thread Sean Anderson

On 11/8/23 13:57, Sean Anderson wrote:

On 11/8/23 07:12, christian.taedcke-...@weidmueller.com wrote:

From: Christian Taedcke 

This fixes an issue where the FAT type (FAT12, FAT16) is not
correctly detected, e.g. when the BPB field BS_FilSysType contains the
valid value "FAT ".

According to the FAT spec the field BS_FilSysType has only
informational character and does not determine the FAT type.

The logic of this code is based on the linux kernel implementation
from the file fs/fat/inode.c function fat_fill_super().

For details about FAT see http://elm-chan.org/docs/fat_e.html

Signed-off-by: Christian Taedcke 


Have you run bloat-o-meter on this? FAT is used in SPL a lot.

Would it be possible to write a test for this, especially for a FAT12 
filesystem with
4084 data sectors and a FAT16 filesystem with 4085?


---

  fs/fat/fat.c | 58 +++-
  include/fat.h    |  6 -
  test/image/spl_load_fs.c |  2 +-
  3 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 8a0f4e4e6c..9179257ff2 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -27,6 +27,9 @@
  #define FATU8ARRAY2CPU16(x) (((x)[1] << 8) + (x)[0])
+/* maximum number of clusters for FAT12 */
+#define MAX_FAT12    0xFF4
+
  /*
   * Convert a string to lowercase.  Converts at most 'len' characters,
   * 'len' may be larger than the length of 'str' if 'str' is NULL
@@ -485,6 +488,32 @@ static __u8 mkcksum(struct nameext *nameext)
  return ret;
  }
+/*
+ * Determine the FAT type
+ *
+ * Based on fat_fill_super() from the Linux kernel's fs/fat/inode.c
+ */
+static int
+determine_fat_bits(const boot_sector *bs)
+{
+    if (!bs->fat_length && bs->fat32_length) {
+    return 32;
+    } else {
+    u16 fat_start = bs->reserved;
+    u32 dir_start = fat_start + bs->fats * bs->fat_length;
+    u32 rootdir_sectors = FATU8ARRAY2CPU16(bs->dir_entries) *
+  sizeof(dir_entry) /
+  FATU8ARRAY2CPU16(bs->sector_size);


Note that technically we are supposed to round up.


+    u32 data_start = dir_start + rootdir_sectors;
+    u16 sectors = FATU8ARRAY2CPU16(bs->sectors);
+    u32 total_sectors = sectors ? sectors : bs->total_sect;
+    u32 total_clusters = (total_sectors - data_start) /
+ bs->cluster_size;
+
+    return (total_clusters > MAX_FAT12) ? 16 : 12;
+    }
+}
+


This should be merged with...


  /*
   * Read boot sector and volume info from a FAT filesystem
   */
@@ -493,7 +522,6 @@ read_bootsectandvi(boot_sector *bs, volume_info *volinfo, 
int *fatsize)
  {
  __u8 *block;
  volume_info *vistart;
-    int ret = 0;
  if (cur_dev == NULL) {
  debug("Error: no device selected\n");
@@ -508,7 +536,8 @@ read_bootsectandvi(boot_sector *bs, volume_info *volinfo, 
int *fatsize)
  if (disk_read(0, 1, block) < 0) {
  debug("Error: reading block\n");
-    goto fail;
+    free(block);
+    return -1;
  }
  memcpy(bs, block, sizeof(boot_sector));
@@ -527,33 +556,15 @@ read_bootsectandvi(boot_sector *bs, volume_info *volinfo, 
int *fatsize)
  bs->info_sector = FAT2CPU16(bs->info_sector);
  bs->backup_boot = FAT2CPU16(bs->backup_boot);
  vistart = (volume_info *)(block + sizeof(boot_sector));
-    *fatsize = 32;
  } else {
  vistart = (volume_info *)&(bs->fat32_length);
-    *fatsize = 0;
  }


... these if statements (above)


  memcpy(volinfo, vistart, sizeof(volume_info));
-    if (*fatsize == 32) {
-    if (strncmp(FAT32_SIGN, vistart->fs_type, SIGNLEN) == 0)
-    goto exit;
-    } else {
-    if (strncmp(FAT12_SIGN, vistart->fs_type, SIGNLEN) == 0) {
-    *fatsize = 12;
-    goto exit;
-    }
-    if (strncmp(FAT16_SIGN, vistart->fs_type, SIGNLEN) == 0) {
-    *fatsize = 16;
-    goto exit;
-    }
-    }


I think we should still verify these as long as vistart->ext_boot_sign is 0x29.


To add to this, if we don't want to verify these we should at least check the 
heuristics from [1].

--Sean

[1] https://www.win.tue.nl/~aeb/linux/fs/fat/fat-2.html


+    *fatsize = determine_fat_bits(bs);
-    debug("Error: broken fs_type sign\n");
-fail:
-    ret = -1;
-exit:
  free(block);
-    return ret;
+    return 0;
  }
  static int get_fs_info(fsdata *mydata)
@@ -1158,9 +1169,8 @@ int file_fat_detectfs(void)
  memcpy(vol_label, volinfo.volume_label, 11);
  vol_label[11] = '\0';
-    volinfo.fs_type[5] = '\0';
-    printf("Filesystem: %s \"%s\"\n", volinfo.fs_type, vol_label);
+    printf("Filesystem: FAT%d \"%s\"\n", fatsize, vol_label);
  return 0;
  }
diff --git a/include/fat.h b/include/fat.h
index a9756fb4cd..3dce99a23c 100644
--- a/include/fat.h
+++ b/include/fat.h
@@ -34,12 +34,6 @@ struct disk_partition;
  /* Maximum number of entry for long file name according to spec */
  #define 

Re: [PATCH v1 2/2] fs: fat: calculate FAT type based on cluster count

2023-11-08 Thread Sean Anderson

On 11/8/23 07:12, christian.taedcke-...@weidmueller.com wrote:

From: Christian Taedcke 

This fixes an issue where the FAT type (FAT12, FAT16) is not
correctly detected, e.g. when the BPB field BS_FilSysType contains the
valid value "FAT ".

According to the FAT spec the field BS_FilSysType has only
informational character and does not determine the FAT type.

The logic of this code is based on the linux kernel implementation
from the file fs/fat/inode.c function fat_fill_super().

For details about FAT see http://elm-chan.org/docs/fat_e.html

Signed-off-by: Christian Taedcke 


Have you run bloat-o-meter on this? FAT is used in SPL a lot.

Would it be possible to write a test for this, especially for a FAT12 
filesystem with
4084 data sectors and a FAT16 filesystem with 4085?


---

  fs/fat/fat.c | 58 +++-
  include/fat.h|  6 -
  test/image/spl_load_fs.c |  2 +-
  3 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 8a0f4e4e6c..9179257ff2 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -27,6 +27,9 @@
  
  #define FATU8ARRAY2CPU16(x) (((x)[1] << 8) + (x)[0])
  
+/* maximum number of clusters for FAT12 */

+#define MAX_FAT12  0xFF4
+
  /*
   * Convert a string to lowercase.  Converts at most 'len' characters,
   * 'len' may be larger than the length of 'str' if 'str' is NULL
@@ -485,6 +488,32 @@ static __u8 mkcksum(struct nameext *nameext)
return ret;
  }
  
+/*

+ * Determine the FAT type
+ *
+ * Based on fat_fill_super() from the Linux kernel's fs/fat/inode.c
+ */
+static int
+determine_fat_bits(const boot_sector *bs)
+{
+   if (!bs->fat_length && bs->fat32_length) {
+   return 32;
+   } else {
+   u16 fat_start = bs->reserved;
+   u32 dir_start = fat_start + bs->fats * bs->fat_length;
+   u32 rootdir_sectors = FATU8ARRAY2CPU16(bs->dir_entries) *
+ sizeof(dir_entry) /
+ FATU8ARRAY2CPU16(bs->sector_size);


Note that technically we are supposed to round up.


+   u32 data_start = dir_start + rootdir_sectors;
+   u16 sectors = FATU8ARRAY2CPU16(bs->sectors);
+   u32 total_sectors = sectors ? sectors : bs->total_sect;
+   u32 total_clusters = (total_sectors - data_start) /
+bs->cluster_size;
+
+   return (total_clusters > MAX_FAT12) ? 16 : 12;
+   }
+}
+


This should be merged with...


  /*
   * Read boot sector and volume info from a FAT filesystem
   */
@@ -493,7 +522,6 @@ read_bootsectandvi(boot_sector *bs, volume_info *volinfo, 
int *fatsize)
  {
__u8 *block;
volume_info *vistart;
-   int ret = 0;
  
  	if (cur_dev == NULL) {

debug("Error: no device selected\n");
@@ -508,7 +536,8 @@ read_bootsectandvi(boot_sector *bs, volume_info *volinfo, 
int *fatsize)
  
  	if (disk_read(0, 1, block) < 0) {

debug("Error: reading block\n");
-   goto fail;
+   free(block);
+   return -1;
}
  
  	memcpy(bs, block, sizeof(boot_sector));

@@ -527,33 +556,15 @@ read_bootsectandvi(boot_sector *bs, volume_info *volinfo, 
int *fatsize)
bs->info_sector = FAT2CPU16(bs->info_sector);
bs->backup_boot = FAT2CPU16(bs->backup_boot);
vistart = (volume_info *)(block + sizeof(boot_sector));
-   *fatsize = 32;
} else {
vistart = (volume_info *)&(bs->fat32_length);
-   *fatsize = 0;
}


... these if statements (above)


memcpy(volinfo, vistart, sizeof(volume_info));
  
-	if (*fatsize == 32) {

-   if (strncmp(FAT32_SIGN, vistart->fs_type, SIGNLEN) == 0)
-   goto exit;
-   } else {
-   if (strncmp(FAT12_SIGN, vistart->fs_type, SIGNLEN) == 0) {
-   *fatsize = 12;
-   goto exit;
-   }
-   if (strncmp(FAT16_SIGN, vistart->fs_type, SIGNLEN) == 0) {
-   *fatsize = 16;
-   goto exit;
-   }
-   }


I think we should still verify these as long as vistart->ext_boot_sign is 0x29.

--Sean


+   *fatsize = determine_fat_bits(bs);
  
-	debug("Error: broken fs_type sign\n");

-fail:
-   ret = -1;
-exit:
free(block);
-   return ret;
+   return 0;
  }
  
  static int get_fs_info(fsdata *mydata)

@@ -1158,9 +1169,8 @@ int file_fat_detectfs(void)
  
  	memcpy(vol_label, volinfo.volume_label, 11);

vol_label[11] = '\0';
-   volinfo.fs_type[5] = '\0';
  
-	printf("Filesystem: %s \"%s\"\n", volinfo.fs_type, vol_label);

+   printf("Filesystem: FAT%d \"%s\"\n", fatsize, vol_label);
  
  	return 0;

  }
diff --git a/include/fat.h b/include/fat.h
index a9756fb4cd..3dce99a23c 100644
--- a/include/fat.h

Re: [PATCH v2] clk: nuvoton: add read only feature for clk driver

2023-11-08 Thread Sean Anderson

On 11/7/23 04:01, Jim Liu wrote:

Add a flag to set ahb/apb/fiu clock divider as read-only
It just protects the clock source and can't modify it in uboot.


Thanks for adding this


Signed-off-by: Jim Liu 
---
Changes for v2:
- add commit message
---
  drivers/clk/nuvoton/clk_npcm.c| 15 ---
  drivers/clk/nuvoton/clk_npcm.h|  1 +
  drivers/clk/nuvoton/clk_npcm8xx.c | 12 ++--
  3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/drivers/clk/nuvoton/clk_npcm.c b/drivers/clk/nuvoton/clk_npcm.c
index 8d71f2a24b..18cb9cddbf 100644
--- a/drivers/clk/nuvoton/clk_npcm.c
+++ b/drivers/clk/nuvoton/clk_npcm.c
@@ -135,7 +135,7 @@ static u32 npcm_clk_get_div(struct clk *clk)
return div;
  }
  
-static u32 npcm_clk_set_div(struct clk *clk, u32 div)

+static int npcm_clk_set_div(struct clk *clk, u32 div)
  {
struct npcm_clk_priv *priv = dev_get_priv(clk->dev);
struct npcm_clk_div *divider;
@@ -145,6 +145,9 @@ static u32 npcm_clk_set_div(struct clk *clk, u32 div)
if (!divider)
return -EINVAL;
  
+	if (divider->flags & DIV_RO)

+   return 0;
+
if (divider->flags & PRE_DIV2)
div = div >> 1;
  
@@ -153,6 +156,12 @@ static u32 npcm_clk_set_div(struct clk *clk, u32 div)

else
clkdiv = ilog2(div);
  
+	if (clkdiv > (divider->mask >> (ffs(divider->mask) - 1))) {

+   printf("clkdiv(%d) for clk(%ld) is over limit\n",
+  clkdiv, clk->id);
+   return -EINVAL;
+   }
+
val = readl(priv->base + divider->reg);
val &= ~divider->mask;
val |= (clkdiv << (ffs(divider->mask) - 1)) & divider->mask;
@@ -253,8 +262,8 @@ static ulong npcm_clk_set_rate(struct clk *clk, ulong rate)
if (ret)
return ret;
  
-	debug("%s: rate %lu, new rate (%lu / %u)\n", __func__, rate, parent_rate, div);

-   return (parent_rate / div);
+   debug("%s: rate %lu, new rate %lu\n", __func__, rate, 
npcm_clk_get_rate(clk));
+   return npcm_clk_get_rate(clk);
  }
  
  static int npcm_clk_set_parent(struct clk *clk, struct clk *parent)

diff --git a/drivers/clk/nuvoton/clk_npcm.h b/drivers/clk/nuvoton/clk_npcm.h
index 06b60dc8b8..b4726d8381 100644
--- a/drivers/clk/nuvoton/clk_npcm.h
+++ b/drivers/clk/nuvoton/clk_npcm.h
@@ -50,6 +50,7 @@
  #define PRE_DIV2  BIT(2)  /* Pre divisor = 2 */
  #define POST_DIV2 BIT(3)  /* Post divisor = 2 */
  #define FIXED_PARENT  BIT(4)  /* clock source is fixed */
+#define DIV_RO BIT(5)  /* divider is read-only */
  
  /* Parameters of PLL configuration */

  struct npcm_clk_pll {
diff --git a/drivers/clk/nuvoton/clk_npcm8xx.c 
b/drivers/clk/nuvoton/clk_npcm8xx.c
index 27e3cfcf55..d1b32e3237 100644
--- a/drivers/clk/nuvoton/clk_npcm8xx.c
+++ b/drivers/clk/nuvoton/clk_npcm8xx.c
@@ -45,12 +45,12 @@ static struct npcm_clk_select npcm8xx_clk_selectors[] = {
  };
  
  static struct npcm_clk_div npcm8xx_clk_dividers[] = {

-   {NPCM8XX_CLK_AHB, CLKDIV1, CLK4DIV, DIV_TYPE1 | PRE_DIV2},
-   {NPCM8XX_CLK_APB2, CLKDIV2, APB2CKDIV, DIV_TYPE2},
-   {NPCM8XX_CLK_APB5, CLKDIV2, APB5CKDIV, DIV_TYPE2},
-   {NPCM8XX_CLK_SPI0, CLKDIV3, SPI0CKDIV, DIV_TYPE1},
-   {NPCM8XX_CLK_SPI1, CLKDIV3, SPI1CKDIV, DIV_TYPE1},
-   {NPCM8XX_CLK_SPI3, CLKDIV1, SPI3CKDIV, DIV_TYPE1},
+   {NPCM8XX_CLK_AHB, CLKDIV1, CLK4DIV, DIV_TYPE1 | PRE_DIV2 | DIV_RO},
+   {NPCM8XX_CLK_APB2, CLKDIV2, APB2CKDIV, DIV_TYPE2 | DIV_RO},
+   {NPCM8XX_CLK_APB5, CLKDIV2, APB5CKDIV, DIV_TYPE2 | DIV_RO},


And this makes sense for bus clocks


+   {NPCM8XX_CLK_SPI0, CLKDIV3, SPI0CKDIV, DIV_TYPE1 | DIV_RO},
+   {NPCM8XX_CLK_SPI1, CLKDIV3, SPI1CKDIV, DIV_TYPE1 | DIV_RO},
+   {NPCM8XX_CLK_SPI3, CLKDIV1, SPI3CKDIV, DIV_TYPE1 | DIV_RO},


But it's a little unclear to me why this is enabled for SPI. Are you e.g.
doing XIP from SPI?

--Sean


{NPCM8XX_CLK_SPIX, CLKDIV3, SPIXCKDIV, DIV_TYPE1},
{NPCM8XX_CLK_UART, CLKDIV1, UARTDIV1, DIV_TYPE1},
{NPCM8XX_CLK_UART2, CLKDIV3, UARTDIV2, DIV_TYPE1},




Re: [PATCH v7 2/2] schemas: Add some common reserved-memory usages

2023-11-08 Thread Lean Sheng Tan
Hi Rob,
Sure, I will ask if the edk2 developers who work together for UPL spec
could help to respond here.

Hi Ard,
Regarding this part:
*However, there is no scoping in DT schema as far as I am aware, which
means that the OS may be forced/expected to interpret these regions beyond
simply disregarding them and treating them as reserved memory, and *that*
is something I strongly object to.*

I think that is one of good perspective to look into this, however please
also consider this situation: that everyone is just starting to develop
their own DT schemas (e.g. RISC-V), and there is no way to stop OS to also
pick up those DT nodes. in that case, if we do not maintain a more unified
DT schema, then OS might end up with more conflicting and
possibly contracting DT nodes/ properties (e.g. RISC-V with own DT schemas
using U-Boot (another DT schema) + edk2 payload (another DT schema, like
UPL) to boot to OS. So personally I still prefer a unified DT schema, even
if the OS never uses them, but that would be very beneficial and in control
in the long term if more people are using DT.

For now, the DT does serve as the purpose of communication vehicle in
between platform init and payload, which is still within Firmware stack.
However from edk2 stand point, there is more people want to roll out DT for
more internal usage within edk2 itself, for example:
https://uefi.org/sites/default/files/resources/Embracing%20Modularity%20and%20Boot-Time%20Configuration%20Faster%20TTM%20with%20Tiano-based%20Solutions_Warkentin.pdf

For sure, it is much easier for us (and time saving as well) to just
maintain DT schema/ format within our own UPL spec, but as mentioned, for
better long term maintenance and community collaborations, we decided to
upstream our implementation back to the main DT schema :)

Thanks!

Best Regards,
*Lean Sheng Tan*



9elements GmbH, Kortumstraße 19-21, 44787 Bochum, Germany
Email: sheng@9elements.com
Phone: *+49 234 68 94 188 <+492346894188>*
Mobile: *+49 176 76 113842 <+4917676113842>*

Registered office: Bochum
Commercial register: Amtsgericht Bochum, HRB 17519
Management: Sebastian German, Eray Bazaar

Data protection information according to Art. 13 GDPR



On Wed, 8 Nov 2023 at 15:20, Ard Biesheuvel  wrote:

> On Wed, 8 Nov 2023 at 14:57, Rob Herring  wrote:
> >
> > On Wed, Nov 8, 2023 at 5:38 AM Ard Biesheuvel  wrote:
> > >
> > > On Tue, 7 Nov 2023 at 19:07, Rob Herring  wrote:
> > > >
> > > >
> > > > All of this:
> > > >
> > >
> > > > > On Mon, 16 Oct 2023 at 15:54, Simon Glass 
> wrote:
> > > > > >
> > > > > > It is not specific to EDK2. Imagine this boot sequence:
> > > > > >
> > > > > > - Platform Init (U-Boot) starts up
> > > > > > - U-Boot uses its platform knowledge to sets some ACPI tables
> and put
> > > > > > various things in memory
> > > > > > - U-Boot sets up some runtime code and data for the OS
> > > > > > - U-Boot jumps to the Tianocore payload **
> > > > > > - Payload (Tianocore) wants to know where the ACPI tables are,
> for example
> > > > > > - Tianocore needs to provide boot services to the OS, so needs
> to know
> > > > > > the memory map, etc.
> > > > > >
> > > > > > ** At this point we want to use DT to pass the required
> information.
> > > > > >
> > > > > > Of course, Platform Init could be coreboot or Tianocore or some
> > > > > > strange private binary. Payload could be U-Boot or something
> else.
> > > > > > That is the point of this effort, to build interoperability.
> > > >
> > > > [...]
> > > >
> > > > > > Perhaps the problem here is that Linux has tied itself up in
> knots
> > > > > > with its EFI stuff and DT fixups and what-not. But this is not
> that.
> > > > > > It is a simple handoff between two pieces of firmware, Platform
> Init
> > > > > > and Payload. It has nothing to do with the OS. With Tianocore
> they are
> > > > > > typically combined, but with this usage they are split, and we
> can
> > > > > > swap out one project for another on either side of the DT
> interface.
> > > >
> > > > Is perhaps the clearest description of the problem you want to solve.
> > > > It's clearly related to EFI though not the interface to the OS. IIRC,
> > > > "platform init" and "payload" are terms in the UEFI spec, right?
> > >
> > > No they are not. This is from the universal payload specification that
> > > is being drafted here
> > >
> > > https://universalpayload.github.io/spec/index.html
> > >
> > > but the UEFI specification does not use this terminology.
> >
> > Then I'm confused as to what this is:
> >
> > https://uefi.org/specs/PI/1.8/index.html
> >
>
> The PI and UEFI specifications are both maintained by the UEFI forum.
>
> The UEFI specification covers external APIs for firmware
> implementations, i.e., the OS visible interface and the public API for
> UEFI device drivers that are not tightly integrated with system
> firmware (for example, the GPU boot time driver in the ROM of an
> add-in card)
>
> The UEFI forum's PI spec 

[PATCH] fs: ext4: Remove unused parameter from ext4_mount

2023-11-08 Thread Sean Anderson
The part_length parameter is not used. Remove it.

Signed-off-by: Sean Anderson 
---

 common/spl/spl_ext.c  | 4 ++--
 env/ext4.c| 4 ++--
 fs/ext4/ext4_common.c | 2 +-
 fs/ext4/ext4fs.c  | 2 +-
 include/ext4fs.h  | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c
index af836ca15b8..2f960956c44 100644
--- a/common/spl/spl_ext.c
+++ b/common/spl/spl_ext.c
@@ -29,7 +29,7 @@ int spl_load_image_ext(struct spl_image_info *spl_image,
 
ext4fs_set_blk_dev(block_dev, _info);
 
-   err = ext4fs_mount(part_info.size);
+   err = ext4fs_mount();
if (!err) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
printf("%s: ext4fs mount err - %d\n", __func__, err);
@@ -84,7 +84,7 @@ int spl_load_image_ext_os(struct spl_image_info *spl_image,
 
ext4fs_set_blk_dev(block_dev, _info);
 
-   err = ext4fs_mount(part_info.size);
+   err = ext4fs_mount();
if (!err) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
printf("%s: ext4fs mount err - %d\n", __func__, err);
diff --git a/env/ext4.c b/env/ext4.c
index 47e05a48919..da26705b8da 100644
--- a/env/ext4.c
+++ b/env/ext4.c
@@ -77,7 +77,7 @@ static int env_ext4_save_buffer(env_t *env_new)
dev = dev_desc->devnum;
ext4fs_set_blk_dev(dev_desc, );
 
-   if (!ext4fs_mount(info.size)) {
+   if (!ext4fs_mount()) {
printf("\n** Unable to use %s %s for saveenv **\n",
   ifname, dev_and_part);
return 1;
@@ -160,7 +160,7 @@ static int env_ext4_load(void)
dev = dev_desc->devnum;
ext4fs_set_blk_dev(dev_desc, );
 
-   if (!ext4fs_mount(info.size)) {
+   if (!ext4fs_mount()) {
printf("\n** Unable to use %s %s for loading the env **\n",
   ifname, dev_and_part);
goto err_env_relocate;
diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index f50de7c089e..ea9b92298ba 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -2368,7 +2368,7 @@ fail:
return -1;
 }
 
-int ext4fs_mount(unsigned part_length)
+int ext4fs_mount(void)
 {
struct ext2_data *data;
int status;
diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index 4c89152ce4a..3b12ec54fa2 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -233,7 +233,7 @@ int ext4fs_probe(struct blk_desc *fs_dev_desc,
 {
ext4fs_set_blk_dev(fs_dev_desc, fs_partition);
 
-   if (!ext4fs_mount(fs_partition->size)) {
+   if (!ext4fs_mount()) {
ext4fs_close();
return -1;
}
diff --git a/include/ext4fs.h b/include/ext4fs.h
index dd66d27f776..d96edfd0576 100644
--- a/include/ext4fs.h
+++ b/include/ext4fs.h
@@ -147,7 +147,7 @@ int ext4fs_create_link(const char *target, const char 
*fname);
 struct ext_filesystem *get_fs(void);
 int ext4fs_open(const char *filename, loff_t *len);
 int ext4fs_read(char *buf, loff_t offset, loff_t len, loff_t *actread);
-int ext4fs_mount(unsigned part_length);
+int ext4fs_mount(void);
 void ext4fs_close(void);
 void ext4fs_reinit_global(void);
 int ext4fs_ls(const char *dirname);
-- 
2.37.1



Re: [PATCH v3 0/2] rng: Provide a RNG based on the RISC-V Zkr ISA extension

2023-11-08 Thread Palmer Dabbelt

On Tue, 07 Nov 2023 15:12:16 PST (-0800), Conor Dooley wrote:

+CC Palmer

On Tue, Nov 07, 2023 at 05:38:37PM -0500, Tom Rini wrote:

On Tue, Nov 07, 2023 at 10:27:50PM +, Conor Dooley wrote:
> On Tue, Nov 07, 2023 at 05:10:23PM -0500, Tom Rini wrote:
> 
> 
> > further clarify or not

> > the RISC-V ISA thing that's elsewhere in this thread (and part of the
> > kernel, not a U-Boot thing).
> 
> TBH, this a bit fragmented across threads, and as someone that hasn't

> been following it it's a bit difficult to tell exactly what is being


Also just kind of jumping in: I don't usually follow u-boot stuff, but a 
few of us ended up talking abot this.



> asked for. Would someone be able to ask it as a direct question?

Sorry for being unclear, and thanks for asking. What I think the U-Boot
community would like to know is, what is the device-tree based way to
know if a RISC-V platform has the Zbb extensions


For this one, it's pretty straightforward IMO - if riscv,isa-extensions
contains "zbb", then you are safe to use those instructions. My
understanding is that relying on getting illegal instruction traps is
not a sufficient test for usability of standard extensions, as a vendor
extension could be using the same opcodes as a standard extension.


Not just could, but we've got systems that actually overlay 
vendor-specific behavior onto the standard encoding space.  There's a 
lot of small offenders for things like errata, but there's also stuff 
like T-Head where huge chunks of space reserved by the ISA for standard 
stuff gets reused.



so the RNG opcodes,
similar (in concept at least?) to the ARMv8.5 RNG feature.


The ordinary extensions that are instructions - like Zbkb that provides
bit manipulation instructions for cryptography you will be able to rely
on riscv,isa-extensions also. Zkr is actually a CSR acting as an entropy
source and is a bit more complicated. RISC-V Cryptography Extensions
Volume I, Chapter Four [0] is the relevant thing for use of the CSR
provided by Zkr, and it says "The seed CSR is also access controlled by
execution mode, and attempted read or write access will raise an illegal
instruction exception outside M mode unless access is explicitly granted."
My take is that either the SBI implementation needs to provide S-Mode
U-Boot with an accurate devicetree (including what extensions are valid
for use in S-mode) or if the devicetree is provided as part of the U-Boot
binary then it needs to match what is available at that privilege level
on the platform. In this case, you would also be able to rely on
riscv,isa-extensions for that detection. There is an existing dt-binding
patch

that adds Zkr, and my proposal would be to document that the presence of Zkr
explicitly in riscv,isa-extensions means that the bit in mseccfg.[s,u]seed
has been set so it can be used at the current privilege level.


FWIW, that seems generally viable to me.


If that's not acceptable, and people think that having Zkr in the
devicetree means that the hardware has the extension, regardless of
usability at the present privilege level, then IMO we need an SBI ecall
defined to request entablement of the CSR & report as to whether or not
that was possible.


I think we can start without the SBI interface, but I'm not 100% sure.  
I was worried about writes to "seed" somehow resulting in an information 
leak, but the spec says "The write value (in rs1 or uimm) must be 
ignored by implementations." so I think we're safe.



I'm not sure how any of the above lines up with the ARMv8.5 RNG feature
unfortunately.


All I know is what's in this patch set 
.  
It looks generalyl to me like the RNDR bits in 
"cpu-features-registers.rst" would coorespond to "Zkr" being set in 
"riscv,isa-extensions" -- we don't have ISA-defined feature registers, 
hence why all this ends up shimed in via DT.




Cheers,
Conor.

0 - https://github.com/riscv/riscv-crypto/releases/tag/v1.0.1-scalar


Re: [PATCH v2 7/8] board: ti: j721e: During resume spl restores TF-A and DM-Firmware

2023-11-08 Thread Andrew Davis

On 11/7/23 10:18 AM, Thomas Richard wrote:

During the boot a copy of DM-Firmware is done in a reserved memory
area before it starts.
When resuming, R5 SPL uses this copy of DM-Firmware instead of the fit
image.
TF-A which saved itself in this same memory area, is restored in
SRAM by R5 SPL.

Based on the work of Gregory CLEMENT 

Signed-off-by: Thomas Richard 
Signed-off-by: Gregory CLEMENT 

---

Changes in v2:
- Check if TF-A is running in DRAM, if yes no need to restore it
- Remove BL31_START macro, and get TF-A start address from the fit image

  arch/arm/mach-k3/common.c | 48 ++-
  arch/arm/mach-k3/include/mach/j721e_spl.h | 28 +
  arch/arm/mach-k3/sysfw-loader.c   |  9 +++--
  3 files changed, 81 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index a35110429b..737a1a28c6 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -26,6 +26,7 @@
  #include 
  #include 
  #include 
+#include 
  
  #if IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)

  enum {
@@ -221,6 +222,11 @@ void release_resources_for_core_shutdown(void)
}
  }
  
+__weak int board_is_resuming(void)

+{
+   return 0;
+}
+
  void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  {
typedef void __noreturn (*image_entry_noargs_t)(void);
@@ -235,6 +241,32 @@ void __noreturn jump_to_image_no_args(struct 
spl_image_info *spl_image)
if (ret)
panic("rproc failed to be initialized (%d)\n", ret);
  
+	if (board_is_resuming()) {

+#if IS_ENABLED(CONFIG_SOC_K3_J721E)
+   if (!valid_elf_image(LPM_DM_SAVE))
+   panic("%s: DM-Firmware image is not valid, it cannot be 
loaded\n",
+ __func__);
+
+   loadaddr = load_elf_image_phdr(LPM_DM_SAVE);
+
+   /*
+* Check if the start address of TF-A is in DRAM.
+* If not it means TF-A was running in SRAM, so it shall be
+* restored.
+*/
+   if (*(ulong *)(LPM_BL31_START_SAVE) < CFG_SYS_SDRAM_BASE)
+   memcpy((void *)*(uintptr_t *)(LPM_BL31_START_SAVE),
+  (void *)LPM_BL31_SAVE, BL31_SIZE);


This will not work. The memory where TF-A is running will be firewalled and
SPL absolutely cannot be securely trusted to load TF-A. Especially from an
unencrypted location in DDR. TF-A must be loaded as it is today using signed
certificate images. You should know this, I explained it all when you tried
the same in TF-A:

https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/23992

NAK

Andrew


+
+   ret = rproc_load(1, *(ulong *)(LPM_BL31_RESUME_SAVE), 
BL31_SIZE);
+   if (ret)
+   panic("%s: ATF failed to load on rproc (%d)\n", 
__func__, ret);
+
+   debug("%s: jumping to address %x\n", __func__, loadaddr);
+   goto start_arm64;
+#endif
+   }
+
init_env();
  
  	if (!fit_image_info[IMAGE_ID_DM_FW].image_start) {

@@ -250,6 +282,10 @@ void __noreturn jump_to_image_no_args(struct 
spl_image_info *spl_image)
fit_image_info[IMAGE_ID_ATF].image_start =
spl_image->entry_point;
  
+#if IS_ENABLED(CONFIG_SOC_K3_J721E)

+   *(uintptr_t *)(LPM_BL31_START_SAVE) = 
fit_image_info[IMAGE_ID_ATF].image_start;
+#endif
+
ret = rproc_load(1, fit_image_info[IMAGE_ID_ATF].image_start, 0x200);
if (ret)
panic("%s: ATF failed to load on rproc (%d)\n", __func__, ret);
@@ -289,8 +325,18 @@ void __noreturn jump_to_image_no_args(struct 
spl_image_info *spl_image)
loadaddr = load_elf_image_phdr(loadaddr);
} else {
loadaddr = fit_image_info[IMAGE_ID_DM_FW].image_start;
-   if (valid_elf_image(loadaddr))
+   if (valid_elf_image(loadaddr)) {
loadaddr = load_elf_image_phdr(loadaddr);
+#if IS_ENABLED(CONFIG_SOC_K3_J721E)
+   if (fit_image_info[IMAGE_ID_DM_FW].image_len > 
(BUFFER_ADDR - LPM_DM_SAVE))
+   log_warning("%s\n: Not enough space to save 
DM-Firmware",
+   __func__);
+   else
+   memcpy((void *)LPM_DM_SAVE,
+  (void 
*)fit_image_info[IMAGE_ID_DM_FW].image_start,
+  
fit_image_info[IMAGE_ID_DM_FW].image_len);
+#endif
+   }
}
  
  	debug("%s: jumping to address %x\n", __func__, loadaddr);

diff --git a/arch/arm/mach-k3/include/mach/j721e_spl.h 
b/arch/arm/mach-k3/include/mach/j721e_spl.h
index e8947917a6..8e0f141ed6 100644
--- a/arch/arm/mach-k3/include/mach/j721e_spl.h
+++ b/arch/arm/mach-k3/include/mach/j721e_spl.h
@@ -42,4 +42,32 @@
  #define K3_PRIMARY_BOOTMODE   0x0
  #define 

[PATCH next v2 6/6] rockchip: rk3128: remove noop file

2023-11-08 Thread Quentin Schulz
From: Quentin Schulz 

arch_cpu_init is already returning 0 in its weak definition in
common/board_f.c so let's just remove the file entirely since nothing
else is done in it.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---
 arch/arm/mach-rockchip/rk3128/Makefile |  1 -
 arch/arm/mach-rockchip/rk3128/rk3128.c | 13 -
 2 files changed, 14 deletions(-)

diff --git a/arch/arm/mach-rockchip/rk3128/Makefile 
b/arch/arm/mach-rockchip/rk3128/Makefile
index 50e11175423..8df1a60a348 100644
--- a/arch/arm/mach-rockchip/rk3128/Makefile
+++ b/arch/arm/mach-rockchip/rk3128/Makefile
@@ -4,6 +4,5 @@
 # SPDX-License-Identifier: GPL-2.0+
 #
 
-obj-y += rk3128.o
 obj-y += syscon_rk3128.o
 obj-y += clk_rk3128.o
diff --git a/arch/arm/mach-rockchip/rk3128/rk3128.c 
b/arch/arm/mach-rockchip/rk3128/rk3128.c
deleted file mode 100644
index 8f8f4951bae..000
--- a/arch/arm/mach-rockchip/rk3128/rk3128.c
+++ /dev/null
@@ -1,13 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright (c) 2017 Rockchip Electronics Co., Ltd
- */
-#include 
-#include 
-
-int arch_cpu_init(void)
-{
-   /* We do some SoC one time setting here. */
-
-   return 0;
-}

-- 
2.41.0



[PATCH next v2 5/6] rockchip: remove unused global data ptr

2023-11-08 Thread Quentin Schulz
From: Quentin Schulz 

Remove leftover import and global data ptr from files since they aren't
used anymore.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---
 arch/arm/mach-rockchip/board.c | 3 ---
 arch/arm/mach-rockchip/rk3128/rk3128.c | 3 ---
 arch/arm/mach-rockchip/rk3308/rk3308.c | 3 ---
 arch/arm/mach-rockchip/rk3328/rk3328.c | 3 ---
 arch/arm/mach-rockchip/rk3368/rk3368.c | 3 ---
 arch/arm/mach-rockchip/rk3399/rk3399.c | 3 ---
 arch/arm/mach-rockchip/rk3588/rk3588.c | 2 --
 7 files changed, 20 deletions(-)

diff --git a/arch/arm/mach-rockchip/board.c b/arch/arm/mach-rockchip/board.c
index 57f08e0be0e..6a9d297e6ff 100644
--- a/arch/arm/mach-rockchip/board.c
+++ b/arch/arm/mach-rockchip/board.c
@@ -16,7 +16,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -24,8 +23,6 @@
 #include 
 #include 
 
-DECLARE_GLOBAL_DATA_PTR;
-
 #if defined(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) && defined(CONFIG_EFI_PARTITION)
 
 #define DFU_ALT_BUF_LENSZ_1K
diff --git a/arch/arm/mach-rockchip/rk3128/rk3128.c 
b/arch/arm/mach-rockchip/rk3128/rk3128.c
index 01dbfa75cb2..8f8f4951bae 100644
--- a/arch/arm/mach-rockchip/rk3128/rk3128.c
+++ b/arch/arm/mach-rockchip/rk3128/rk3128.c
@@ -4,9 +4,6 @@
  */
 #include 
 #include 
-#include 
-
-DECLARE_GLOBAL_DATA_PTR;
 
 int arch_cpu_init(void)
 {
diff --git a/arch/arm/mach-rockchip/rk3308/rk3308.c 
b/arch/arm/mach-rockchip/rk3308/rk3308.c
index 5763604dc3e..6f121bf1304 100644
--- a/arch/arm/mach-rockchip/rk3308/rk3308.c
+++ b/arch/arm/mach-rockchip/rk3308/rk3308.c
@@ -5,7 +5,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -14,8 +13,6 @@
 #include 
 #include 
 
-DECLARE_GLOBAL_DATA_PTR;
-
 #include 
 static struct mm_region rk3308_mem_map[] = {
{
diff --git a/arch/arm/mach-rockchip/rk3328/rk3328.c 
b/arch/arm/mach-rockchip/rk3328/rk3328.c
index de17b886827..02821c9e51d 100644
--- a/arch/arm/mach-rockchip/rk3328/rk3328.c
+++ b/arch/arm/mach-rockchip/rk3328/rk3328.c
@@ -10,11 +10,8 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
-DECLARE_GLOBAL_DATA_PTR;
-
 #define CRU_BASE   0xFF44
 #define GRF_BASE   0xFF10
 #define UART2_BASE 0xFF13
diff --git a/arch/arm/mach-rockchip/rk3368/rk3368.c 
b/arch/arm/mach-rockchip/rk3368/rk3368.c
index d0a6107e5e0..d009b8758e5 100644
--- a/arch/arm/mach-rockchip/rk3368/rk3368.c
+++ b/arch/arm/mach-rockchip/rk3368/rk3368.c
@@ -8,7 +8,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -18,8 +17,6 @@
 #include 
 #include 
 
-DECLARE_GLOBAL_DATA_PTR;
-
 #define IMEM_BASE  0xFF8C
 
 /* Max MCU's SRAM value is 8K, begin at (IMEM_BASE + 4K) */
diff --git a/arch/arm/mach-rockchip/rk3399/rk3399.c 
b/arch/arm/mach-rockchip/rk3399/rk3399.c
index 6929de5603c..a13855f5ee2 100644
--- a/arch/arm/mach-rockchip/rk3399/rk3399.c
+++ b/arch/arm/mach-rockchip/rk3399/rk3399.c
@@ -11,7 +11,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -23,8 +22,6 @@
 #include 
 #include 
 
-DECLARE_GLOBAL_DATA_PTR;
-
 #define GRF_EMMCCORE_CON11 0xff77f02c
 #define GRF_BASE   0xff77
 
diff --git a/arch/arm/mach-rockchip/rk3588/rk3588.c 
b/arch/arm/mach-rockchip/rk3588/rk3588.c
index fde5f281b0a..093b2d1ba88 100644
--- a/arch/arm/mach-rockchip/rk3588/rk3588.c
+++ b/arch/arm/mach-rockchip/rk3588/rk3588.c
@@ -12,8 +12,6 @@
 #include 
 #include 
 
-DECLARE_GLOBAL_DATA_PTR;
-
 #define FIREWALL_DDR_BASE  0xfe03
 #define FW_DDR_MST5_REG0x54
 #define FW_DDR_MST13_REG   0x74

-- 
2.41.0



[PATCH next v2 4/6] rockchip: rk3588: insert u-boot, spl-boot-device into U-Boot device tree

2023-11-08 Thread Quentin Schulz
From: Quentin Schulz 

It is possible to boot U-Boot proper from a different storage medium
than the one used by the BOOTROM to load the SPL. This information is
stored in the u-boot,spl-boot-device Device Tree property and is
accessible from U-Boot proper so that it has knowledge at runtime where
it was loaded from.

Let's add support for this feature for rk3588 the same way it was done
for px30 and rk3399.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---
 arch/arm/mach-rockchip/rk3588/rk3588.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/arch/arm/mach-rockchip/rk3588/rk3588.c 
b/arch/arm/mach-rockchip/rk3588/rk3588.c
index b1f535fad50..fde5f281b0a 100644
--- a/arch/arm/mach-rockchip/rk3588/rk3588.c
+++ b/arch/arm/mach-rockchip/rk3588/rk3588.c
@@ -163,3 +163,11 @@ int arch_cpu_init(void)
return 0;
 }
 #endif
+
+#if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD)
+const char * const spl_boot_devices[BOOT_DEVICE_NONE + 1] = {
+   [BOOT_DEVICE_MMC2] = "/mmc@fe2e",
+   [BOOT_DEVICE_MMC1] = "/mmc@fe2c",
+   [BOOT_DEVICE_SPI] = "/spi@fe2b/flash@0",
+};
+#endif

-- 
2.41.0



[PATCH next v2 3/6] rockchip: factor out spl_perform_fixups into common spl-boot-order

2023-11-08 Thread Quentin Schulz
From: Quentin Schulz 

All SoCs are susceptible to wanting to know which storage medium was
used to load U-Boot SPL. So instead of reimplementing the same functions
in SoCs over and over again (here just rk3399 and px30 but rk3588 is
coming), let's just put all this in common into spl-boot-order.c
allowing to support a new SoC just by defining the spl_boot_devices
array in the appropriate SoC file.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---
 arch/arm/mach-rockchip/px30/px30.c  | 46 ---
 arch/arm/mach-rockchip/rk3399/rk3399.c  | 46 ---
 arch/arm/mach-rockchip/spl-boot-order.c | 49 +
 3 files changed, 49 insertions(+), 92 deletions(-)

diff --git a/arch/arm/mach-rockchip/px30/px30.c 
b/arch/arm/mach-rockchip/px30/px30.c
index 8937677d79e..7676adcb044 100644
--- a/arch/arm/mach-rockchip/px30/px30.c
+++ b/arch/arm/mach-rockchip/px30/px30.c
@@ -449,50 +449,4 @@ const char * const spl_boot_devices[BOOT_DEVICE_NONE + 1] 
= {
[BOOT_DEVICE_MMC2] = "/mmc@ff37",
[BOOT_DEVICE_MMC1] = "/mmc@ff39",
 };
-
-const char *spl_decode_boot_device(u32 boot_device)
-{
-   const char *spl_bootdevice_ofpath = NULL;
-
-   if (boot_device < ARRAY_SIZE(spl_boot_devices))
-   spl_bootdevice_ofpath = spl_boot_devices[boot_device];
-
-   if (spl_bootdevice_ofpath)
-   debug("%s: spl_bootdevice_id %x maps to '%s'\n",
- __func__, boot_device, spl_bootdevice_ofpath);
-   else
-   debug("%s: failed to resolve spl_bootdevice_id %x\n",
- __func__, boot_device);
-
-   return spl_bootdevice_ofpath;
-}
-
-void spl_perform_fixups(struct spl_image_info *spl_image)
-{
-   void *blob = spl_image->fdt_addr;
-   const char *boot_ofpath;
-   int chosen;
-
-   /*
-* Inject the ofpath of the device the full U-Boot (or Linux in
-* Falcon-mode) was booted from into the FDT, if a FDT has been
-* loaded at the same time.
-*/
-   if (!blob)
-   return;
-
-   boot_ofpath = spl_decode_boot_device(spl_image->boot_device);
-   if (!boot_ofpath) {
-   pr_err("%s: could not map boot_device to ofpath\n", __func__);
-   return;
-   }
-
-   chosen = fdt_find_or_add_subnode(blob, 0, "chosen");
-   if (chosen < 0) {
-   pr_err("%s: could not find/create '/chosen'\n", __func__);
-   return;
-   }
-   fdt_setprop_string(blob, chosen,
-  "u-boot,spl-boot-device", boot_ofpath);
-}
 #endif
diff --git a/arch/arm/mach-rockchip/rk3399/rk3399.c 
b/arch/arm/mach-rockchip/rk3399/rk3399.c
index 60d95c81cd2..6929de5603c 100644
--- a/arch/arm/mach-rockchip/rk3399/rk3399.c
+++ b/arch/arm/mach-rockchip/rk3399/rk3399.c
@@ -181,52 +181,6 @@ const char * const spl_boot_devices[BOOT_DEVICE_NONE + 1] 
= {
[BOOT_DEVICE_SPI] = "/spi@ff1d/flash@0",
 };
 
-const char *spl_decode_boot_device(u32 boot_device)
-{
-   const char *spl_bootdevice_ofpath = NULL;
-
-   if (boot_device < ARRAY_SIZE(spl_boot_devices))
-   spl_bootdevice_ofpath = spl_boot_devices[boot_device];
-
-   if (spl_bootdevice_ofpath)
-   debug("%s: spl_bootdevice_id %x maps to '%s'\n",
- __func__, boot_device, spl_bootdevice_ofpath);
-   else
-   debug("%s: failed to resolve spl_bootdevice_id %x\n",
- __func__, boot_device);
-
-   return spl_bootdevice_ofpath;
-}
-
-void spl_perform_fixups(struct spl_image_info *spl_image)
-{
-   void *blob = spl_image->fdt_addr;
-   const char *boot_ofpath;
-   int chosen;
-
-   /*
-* Inject the ofpath of the device the full U-Boot (or Linux in
-* Falcon-mode) was booted from into the FDT, if a FDT has been
-* loaded at the same time.
-*/
-   if (!blob)
-   return;
-
-   boot_ofpath = spl_decode_boot_device(spl_image->boot_device);
-   if (!boot_ofpath) {
-   pr_err("%s: could not map boot_device to ofpath\n", __func__);
-   return;
-   }
-
-   chosen = fdt_find_or_add_subnode(blob, 0, "chosen");
-   if (chosen < 0) {
-   pr_err("%s: could not find/create '/chosen'\n", __func__);
-   return;
-   }
-   fdt_setprop_string(blob, chosen,
-  "u-boot,spl-boot-device", boot_ofpath);
-}
-
 static void rk3399_force_power_on_reset(void)
 {
ofnode node;
diff --git a/arch/arm/mach-rockchip/spl-boot-order.c 
b/arch/arm/mach-rockchip/spl-boot-order.c
index 93b8e7de4d0..55d0976fb0a 100644
--- a/arch/arm/mach-rockchip/spl-boot-order.c
+++ b/arch/arm/mach-rockchip/spl-boot-order.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -161,4 +162,52 @@ void board_boot_order(u32 *spl_boot_list)
if (idx == 0)
 

[PATCH next v2 2/6] rockchip: px30: simplify logic for getting SPL boot medium DT node

2023-11-08 Thread Quentin Schulz
From: Quentin Schulz 

In preparation of moving spl_perform_fixups to spl-boot-order.c, let's
simplify the logic around mapping the BOOT_DEVICE_x enum index to a DT
node by using an instantiated array of chars instead of creating a new
data structure on the fly.

This will make it easier to only define the spl_boot_devices array in
the appropriate SoC file in an upcoming commit.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---
 arch/arm/mach-rockchip/px30/px30.c | 28 
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/arch/arm/mach-rockchip/px30/px30.c 
b/arch/arm/mach-rockchip/px30/px30.c
index 3bca25c609f..8937677d79e 100644
--- a/arch/arm/mach-rockchip/px30/px30.c
+++ b/arch/arm/mach-rockchip/px30/px30.c
@@ -445,22 +445,26 @@ void board_debug_uart_init(void)
 #endif /* CONFIG_DEBUG_UART_BOARD_INIT */
 
 #if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD)
+const char * const spl_boot_devices[BOOT_DEVICE_NONE + 1] = {
+   [BOOT_DEVICE_MMC2] = "/mmc@ff37",
+   [BOOT_DEVICE_MMC1] = "/mmc@ff39",
+};
+
 const char *spl_decode_boot_device(u32 boot_device)
 {
-   int i;
-   static const struct {
-   u32 boot_device;
-   const char *ofpath;
-   } spl_boot_devices_tbl[] = {
-   { BOOT_DEVICE_MMC2, "/mmc@ff37" },
-   { BOOT_DEVICE_MMC1, "/mmc@ff39" },
-   };
+   const char *spl_bootdevice_ofpath = NULL;
+
+   if (boot_device < ARRAY_SIZE(spl_boot_devices))
+   spl_bootdevice_ofpath = spl_boot_devices[boot_device];
 
-   for (i = 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i)
-   if (spl_boot_devices_tbl[i].boot_device == boot_device)
-   return spl_boot_devices_tbl[i].ofpath;
+   if (spl_bootdevice_ofpath)
+   debug("%s: spl_bootdevice_id %x maps to '%s'\n",
+ __func__, boot_device, spl_bootdevice_ofpath);
+   else
+   debug("%s: failed to resolve spl_bootdevice_id %x\n",
+ __func__, boot_device);
 
-   return NULL;
+   return spl_bootdevice_ofpath;
 }
 
 void spl_perform_fixups(struct spl_image_info *spl_image)

-- 
2.41.0



[PATCH next v2 1/6] rockchip: rk3399: simplify logic for getting SPL boot medium DT node

2023-11-08 Thread Quentin Schulz
From: Quentin Schulz 

In preparation of moving spl_perform_fixups to spl-boot-order.c, let's
simplify the logic around mapping the BOOT_DEVICE_x enum index to a DT
node by using an instantiated array of chars instead of creating a new
data structure on the fly.

This will make it easier to only define the spl_boot_devices array in
the appropriate SoC file in an upcoming commit.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---
 arch/arm/mach-rockchip/rk3399/rk3399.c | 34 +++---
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/arch/arm/mach-rockchip/rk3399/rk3399.c 
b/arch/arm/mach-rockchip/rk3399/rk3399.c
index 14565d2ed9f..60d95c81cd2 100644
--- a/arch/arm/mach-rockchip/rk3399/rk3399.c
+++ b/arch/arm/mach-rockchip/rk3399/rk3399.c
@@ -175,23 +175,27 @@ void board_debug_uart_init(void)
 #endif
 
 #if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD)
+const char * const spl_boot_devices[BOOT_DEVICE_NONE + 1] = {
+   [BOOT_DEVICE_MMC2] = "/mmc@fe32",
+   [BOOT_DEVICE_MMC1] = "/mmc@fe33",
+   [BOOT_DEVICE_SPI] = "/spi@ff1d/flash@0",
+};
+
 const char *spl_decode_boot_device(u32 boot_device)
 {
-   int i;
-   static const struct {
-   u32 boot_device;
-   const char *ofpath;
-   } spl_boot_devices_tbl[] = {
-   { BOOT_DEVICE_MMC2, "/mmc@fe32" },
-   { BOOT_DEVICE_MMC1, "/mmc@fe33" },
-   { BOOT_DEVICE_SPI, "/spi@ff1d/flash@0" },
-   };
-
-   for (i = 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i)
-   if (spl_boot_devices_tbl[i].boot_device == boot_device)
-   return spl_boot_devices_tbl[i].ofpath;
-
-   return NULL;
+   const char *spl_bootdevice_ofpath = NULL;
+
+   if (boot_device < ARRAY_SIZE(spl_boot_devices))
+   spl_bootdevice_ofpath = spl_boot_devices[boot_device];
+
+   if (spl_bootdevice_ofpath)
+   debug("%s: spl_bootdevice_id %x maps to '%s'\n",
+ __func__, boot_device, spl_bootdevice_ofpath);
+   else
+   debug("%s: failed to resolve spl_bootdevice_id %x\n",
+ __func__, boot_device);
+
+   return spl_bootdevice_ofpath;
 }
 
 void spl_perform_fixups(struct spl_image_info *spl_image)

-- 
2.41.0



[PATCH next v2 0/6] rockchip: rk3588: add support for detecting U-Boot proper boot medium

2023-11-08 Thread Quentin Schulz
It is possible to boot U-Boot proper from a different storage medium
than the one used by the BOOTROM to load the SPL. This information is
stored in the u-boot,spl-boot-device Device Tree property and is
accessible from U-Boot proper so that it has knowledge at runtime where
it was loaded from.

This is already supported on rk3399 and px30 but with duplicated code,
so this patch series also factor out all of this into spl-boot-order of
Rockchip platforms, which makes it drastically easier to add support to
other SoCs, just a simple array needing to be added to the appropriate
SoC file.

Let's add support for this feature for rk3588 the same way it was done
for px30 and rk3399.

While at it, let's do some cleanups for Rockchip platforms.

Signed-off-by: Quentin Schulz 
---
Changes in v2:
- add factoring into spl-boot-order
- rework rk3588 support to use the factored out function
- add global data ptr cleanup
- remove rk3128 main SoC file (useless content)
- Link to v1: 
https://lore.kernel.org/r/20230502-rk3588-spl-boot-dev-v1-1-071722a85...@theobroma-systems.com

---
Quentin Schulz (6):
  rockchip: rk3399: simplify logic for getting SPL boot medium DT node
  rockchip: px30: simplify logic for getting SPL boot medium DT node
  rockchip: factor out spl_perform_fixups into common spl-boot-order
  rockchip: rk3588: insert u-boot,spl-boot-device into U-Boot device tree
  rockchip: remove unused global data ptr
  rockchip: rk3128: remove noop file

 arch/arm/mach-rockchip/board.c  |  3 --
 arch/arm/mach-rockchip/px30/px30.c  | 50 +++---
 arch/arm/mach-rockchip/rk3128/Makefile  |  1 -
 arch/arm/mach-rockchip/rk3128/rk3128.c  | 16 --
 arch/arm/mach-rockchip/rk3308/rk3308.c  |  3 --
 arch/arm/mach-rockchip/rk3328/rk3328.c  |  3 --
 arch/arm/mach-rockchip/rk3368/rk3368.c  |  3 --
 arch/arm/mach-rockchip/rk3399/rk3399.c  | 55 +++--
 arch/arm/mach-rockchip/rk3588/rk3588.c  | 10 --
 arch/arm/mach-rockchip/spl-boot-order.c | 49 +
 10 files changed, 66 insertions(+), 127 deletions(-)
---
base-commit: e17d174773e9ba9447596708e702b7382e47a6cf
change-id: 20230502-rk3588-spl-boot-dev-efa2777cc21b

Best regards,
-- 
Quentin Schulz 



Re: [PATCH v3 0/2] rng: Provide a RNG based on the RISC-V Zkr ISA extension

2023-11-08 Thread Heinrich Schuchardt

On 11/8/23 08:44, Tom Rini wrote:

On Wed, Nov 08, 2023 at 07:25:22AM -0800, Heinrich Schuchardt wrote:

On 11/8/23 06:37, Tom Rini wrote:

On Wed, Nov 08, 2023 at 06:23:37AM -0800, Heinrich Schuchardt wrote:

On 11/7/23 16:34, Tom Rini wrote:

On Wed, Nov 08, 2023 at 12:29:03AM +, Conor Dooley wrote:

On Tue, Nov 07, 2023 at 06:23:05PM -0500, Tom Rini wrote:

[snip]

Thanks. Setting aside Simon's follow-up, this is what I was looking for.
We might have to wait for Heinrich to return from the conference to have
time to look at how to utilize the above and see what we can do from
there.


I did read that, but I don't think most of it is relevant to the binding
itself. His five things were:
| - U-Boot models hardware (and other things) as devices in driver model [1]

This I think should be satisfied. The Zkr CSR is a property of the CPU,
and shouldn't have its own DT node IMO. Is it problematic for U-Boot to
populate multiple devices for its driver model based on one DT node?


Devices in U-Boot are bound on the basis of a compatible string. All RISC-V
CPU nodes have a compatible string 'riscv' but that does not provide any
information about the existence of the Zkr extension. That information is in
the 'riscv,isa-extensions' property of the cpu nodes (see
Documentation/devicetree/bindings/riscv/cpus.yaml).


I know in Linux that I can create devices using something like
platform_device_register(), does U-Boot have a similar facility?


This is what the U_BOOT_DRVINFO() macro in my driver does and which Simon
discourages.


My current thoughts are that in this case we could use U_BOOT_DRVINFO()
like today and then have riscv_zkr_probe() be what checks the
riscv,isa-extensions property for an appropriate match? This would mean
we don't need any new nodes/compatibles/etc, and possibly not need any
bootph- properties added either? I assume we don't need the RNG so early
as for that to be an issue.



The presence of the Zkr extension in the device-tree 'riscv,isa-extensions'
property does not indicate if the machine mode firmware has enabled access
in supervisor mode via the mseccfg.sseed flag. This is why my driver tries
to read the seed register and checks if an exception occurs.


This I think is a question for Cody or someone else in the RISC-V
community? If just checking the property isn't sufficient, what is? Or,
what's the best / most reliable way? I don't know and I'll let the
RISC-V community sort that out instead of making incorrect assumptions
myself.


Additionally checking the device-tree would increase code size. Is it really
needed?


I mean, it depends? My biggest issue right now is that in-tree I don't
see any RISC-V targets that select any of the RISCV_ISA options so I
can't evaluate what platforms grow by how much where. We shouldn't be
talking about kilobytes of change, so no, I don't think somehow checking
the device tree for this is out of bounds. But it comes back to what I
just asked above, first. We need the correct and expected way to check
for this feature to be known, then we decide how to handle that.


Hardware with the Zkr extension is yet to hit the market. Please, run 
upstream QEMU (commit 2f32dcabc2f0 or later) with -cpu rv64,zkr=on to 
see the device-tree entry. A patch for OpenSBI to enable mseccfg.sseed 
is pending.





We may have multiple RNG drivers enabled on the same device, e.g. TPM, Zkr,
virtio-rng. In several code locations we try to use the first RNG device
(not the first successfully probed RNG device). This is why

[PATCH 1/1] rng: detect RISC-V Zkr RNG device in bind method
https://lore.kernel.org/u-boot/20231104065107.23623-1-heinrich.schucha...@canonical.com/

moves the detection from probe() to bind(). The patch further corrects the
return code if the RNG device is not available.


Sounds like we have some other general issues to sort out too then.
Filing an issue on
https://source.denx.de/u-boot/custodians/u-boot-dm/-/issues/ would be
good so it doesn't get forgotten.



Here is the issue:

Missing function to find first successfully probed device for a uclass
https://source.denx.de/u-boot/custodians/u-boot-dm/-/issues/8

Best regards

Heinrich


Re: [PATCH v6 7/8] clk: treewide: switch to clock dump from clk_ops

2023-11-08 Thread Sean Anderson

On 11/5/23 03:38, Igor Prusov wrote:

Switch to using new dump operation in clock provider drivers instead of
overriding soc_clk_dump.

Signed-off-by: Igor Prusov 
Tested-by: Patrice Chotard 
Reviewed-by: Sean Anderson 
---
  arch/mips/mach-pic32/cpu.c | 23 
  drivers/clk/aspeed/clk_ast2600.c   | 13 +
  drivers/clk/clk_k210.c | 12 +++--
  drivers/clk/clk_pic32.c| 37 ++
  drivers/clk/clk_versal.c   |  9 ---
  drivers/clk/clk_zynq.c | 28 ---
  drivers/clk/clk_zynqmp.c   | 22 +++
  drivers/clk/imx/clk-imx8.c | 13 +++--
  drivers/clk/meson/a1.c | 28 ++-
  drivers/clk/mvebu/armada-37xx-periph.c | 20 +-
  drivers/clk/stm32/clk-stm32mp1.c   | 31 ++---
  11 files changed, 108 insertions(+), 128 deletions(-)

diff --git a/arch/mips/mach-pic32/cpu.c b/arch/mips/mach-pic32/cpu.c
index dbf8c9cd22..3181a946a2 100644
--- a/arch/mips/mach-pic32/cpu.c
+++ b/arch/mips/mach-pic32/cpu.c
@@ -143,26 +143,3 @@ const char *get_core_name(void)
return str;
  }
  #endif
-#ifdef CONFIG_CMD_CLK
-
-int soc_clk_dump(void)
-{
-   int i;
-
-   printf("PLL Speed: %lu MHz\n",
-  CLK_MHZ(rate(PLLCLK)));
-
-   printf("CPU Speed: %lu MHz\n", CLK_MHZ(rate(PB7CLK)));
-
-   printf("MPLL Speed: %lu MHz\n", CLK_MHZ(rate(MPLL)));
-
-   for (i = PB1CLK; i <= PB7CLK; i++)
-   printf("PB%d Clock Speed: %lu MHz\n", i - PB1CLK + 1,
-  CLK_MHZ(rate(i)));
-
-   for (i = REF1CLK; i <= REF5CLK; i++)
-   printf("REFO%d Clock Speed: %lu MHz\n", i - REF1CLK + 1,
-  CLK_MHZ(rate(i)));
-   return 0;
-}
-#endif
diff --git a/drivers/clk/aspeed/clk_ast2600.c b/drivers/clk/aspeed/clk_ast2600.c
index b3cc8392fa..eecfacd7fc 100644
--- a/drivers/clk/aspeed/clk_ast2600.c
+++ b/drivers/clk/aspeed/clk_ast2600.c
@@ -1109,6 +1109,7 @@ struct aspeed_clks {
const char *name;
  };
  
+#if IS_ENABLED(CONFIG_CMD_CLK)

  static struct aspeed_clks aspeed_clk_names[] = {
{ ASPEED_CLK_HPLL, "hpll" },
{ ASPEED_CLK_MPLL, "mpll" },
@@ -1123,18 +1124,12 @@ static struct aspeed_clks aspeed_clk_names[] = {
{ ASPEED_CLK_HUARTX, "huxclk" },
  };
  
-int soc_clk_dump(void)

+static void ast2600_clk_dump(struct udevice *dev)
  {
-   struct udevice *dev;
struct clk clk;
unsigned long rate;
int i, ret;
  
-	ret = uclass_get_device_by_driver(UCLASS_CLK, DM_DRIVER_GET(aspeed_scu),

- );
-   if (ret)
-   return ret;
-
printf("Clk\t\tHz\n");
  
  	for (i = 0; i < ARRAY_SIZE(aspeed_clk_names); i++) {

@@ -1167,11 +1162,15 @@ int soc_clk_dump(void)
  
  	return 0;

  }
+#endif
  
  struct clk_ops ast2600_clk_ops = {

.get_rate = ast2600_clk_get_rate,
.set_rate = ast2600_clk_set_rate,
.enable = ast2600_clk_enable,
+#if IS_ENABLED(CONFIG_CMD_CLK)
+   .dump = ast2600_clk_dump,
+#endif
  };
  
  static int ast2600_clk_probe(struct udevice *dev)

diff --git a/drivers/clk/clk_k210.c b/drivers/clk/clk_k210.c
index 2f17152021..b8d666e805 100644
--- a/drivers/clk/clk_k210.c
+++ b/drivers/clk/clk_k210.c
@@ -1276,16 +1276,10 @@ static void show_clks(struct k210_clk_priv *priv, int 
id, int depth)
}
  }
  
-int soc_clk_dump(void)

+static int k210_clk_dump(struct udevice *dev)


void?


  {
-   int ret;
-   struct udevice *dev;
struct k210_clk_priv *priv;
  
-	ret = uclass_get_device_by_driver(UCLASS_CLK, DM_DRIVER_GET(k210_clk),

- );
-   if (ret)
-   return ret;
priv = dev_get_priv(dev);
  
  	puts(" Rate  Enabled Name\n");

@@ -1293,7 +1287,6 @@ int soc_clk_dump(void)
printf(" %-9lu %-7c %*s%s\n", clk_get_rate(>in0), 'y', 0, "",
   priv->in0.dev->name);
show_clks(priv, K210_CLK_IN0, 1);
-   return 0;
  }
  #endif
  
@@ -1304,6 +1297,9 @@ static const struct clk_ops k210_clk_ops = {

.set_parent = k210_clk_set_parent,
.enable = k210_clk_enable,
.disable = k210_clk_disable,
+#if IS_ENABLED(CONFIG_CMD_CLK)
+   .dump = k210_clk_dump,
+#endif
  };
  
  static int k210_clk_probe(struct udevice *dev)

diff --git a/drivers/clk/clk_pic32.c b/drivers/clk/clk_pic32.c
index ef06a7fb9f..a77d0e7419 100644
--- a/drivers/clk/clk_pic32.c
+++ b/drivers/clk/clk_pic32.c
@@ -20,6 +20,8 @@
  
  DECLARE_GLOBAL_DATA_PTR;
  
+#define CLK_MHZ(x)	((x) / 100)

+
  /* Primary oscillator */
  #define SYS_POSC_CLK_HZ   2400
  
@@ -385,9 +387,44 @@ static ulong pic32_set_rate(struct clk *clk, ulong rate)

return rate;
  }
  
+#if IS_ENABLED(CONFIG_CMD_CLK)

+static void pic32_dump(struct udevice *dev)
+{
+   int i;
+   struct clk clk;
+
+   clk.dev = 

Re: [PATCH v6 6/8] cmd: clk: Use dump function from clk_ops

2023-11-08 Thread Sean Anderson

On 11/5/23 03:38, Igor Prusov wrote:

Add another loop to dump additional info from clock providers that
implement dump operation.

Signed-off-by: Igor Prusov 
Reviewed-by: Patrice Chotard 
Tested-by: Patrice Chotard 
---
  cmd/clk.c | 9 +
  1 file changed, 9 insertions(+)

diff --git a/cmd/clk.c b/cmd/clk.c
index c7c379d7a6..4b9709d3ff 100644
--- a/cmd/clk.c
+++ b/cmd/clk.c
@@ -62,6 +62,7 @@ static void show_clks(struct udevice *dev, int depth, int 
last_flag)
  int __weak soc_clk_dump(void)
  {
struct udevice *dev;
+   const struct clk_ops *ops;
  
  	printf(" Rate   Usecnt  Name\n");

printf("--\n");
@@ -69,6 +70,14 @@ int __weak soc_clk_dump(void)
uclass_foreach_dev_probe(UCLASS_CLK, dev)
show_clks(dev, -1, 0);
  
+	uclass_foreach_dev_probe(UCLASS_CLK, dev) {

+   ops = dev_get_driver_ops(dev);
+   if (ops && ops->dump) {
+   printf("\n%s %s:\n", dev->driver->name, dev->name);
+   ops->dump(dev);
+   }
+   }
+
return 0;
  }
  #else


Reviewed-by: Sean Anderson 


Re: [PATCH v6 5/8] clk: Add dump operation to clk_ops

2023-11-08 Thread Sean Anderson

On 11/5/23 03:38, Igor Prusov wrote:

This adds dump function to struct clk_ops which should replace
soc_clk_dump. It allows clock drivers to provide custom dump
implementation without overriding generic CCF dump function.

Signed-off-by: Igor Prusov 
Reviewed-by: Patrice Chotard 
Tested-by: Patrice Chotard 
---
  include/clk-uclass.h | 15 +++
  1 file changed, 15 insertions(+)

diff --git a/include/clk-uclass.h b/include/clk-uclass.h
index a22f1a5d84..3419daab34 100644
--- a/include/clk-uclass.h
+++ b/include/clk-uclass.h
@@ -25,6 +25,7 @@ struct ofnode_phandle_args;
   * @set_parent: Set current clock parent
   * @enable: Enable a clock.
   * @disable: Disable a clock.
+ * @dump: Print clock information.
   *
   * The individual methods are described more fully below.
   */
@@ -39,6 +40,9 @@ struct clk_ops {
int (*set_parent)(struct clk *clk, struct clk *parent);
int (*enable)(struct clk *clk);
int (*disable)(struct clk *clk);
+#if IS_ENABLED(CONFIG_CMD_CLK)
+   void (*dump)(struct udevice *dev);
+#endif
  };
  
  #if 0 /* For documentation only */

@@ -135,6 +139,17 @@ int enable(struct clk *clk);
   * Return: zero on success, or -ve error code.
   */
  int disable(struct clk *clk);
+
+/**
+ * dump() - Print clock information.
+ * @clk:   The clock device to dump.
+ *
+ * If present, this function is called by "clk dump" command for each
+ * bound device.
+ *
+ * Return: zero on success, or -ve error code.


This is no longer correct, but I can remove it when applying.


+ */
+void dump(struct udevice *dev);
  #endif
  
  #endif


Reviewed-by: Sean Anderson 


Re: [UBOOT PATCH v3] test/py: net: Add a TFTP put test

2023-11-08 Thread Tom Rini
On Wed, Nov 08, 2023 at 12:40:31PM +0530, Love Kumar wrote:

> Execute tftpput command for uploading files to a server and validate its
> size & CRC32.
> 
> Signed-off-by: Love Kumar 

Thanks for reworking this. After changing tftp server so I could upload
files, this is working as I was hoping it would.

Reviewed-by: Tom Rini 

-- 
Tom


signature.asc
Description: PGP signature


[PATCH v7 24/26] spl: Convert spi to spl_load

2023-11-08 Thread Sean Anderson
This converts the spi load method to use spl_load. The address used for
LOAD_FIT_FULL may be different, but there are no in-tree users of that
config. Since payload_offs is only used without OS_BOOT, we defer its
initialization.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v6)

Changes in v6:
- Fix soft reset after loading from SPI

Changes in v5:
- Rework to load header in spl_load

 common/spl/spl_spi.c  | 80 +++
 include/spl_load.h|  1 +
 test/image/spl_load_spi.c |  1 +
 3 files changed, 15 insertions(+), 67 deletions(-)

diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index 3e08ac7c1a2..f49e534b749 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -12,11 +12,11 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -95,9 +95,9 @@ static int spl_spi_load_image(struct spl_image_info 
*spl_image,
int err = 0;
unsigned int payload_offs;
struct spi_flash *flash;
-   struct legacy_img_hdr *header;
unsigned int sf_bus = spl_spi_boot_bus();
unsigned int sf_cs = spl_spi_boot_cs();
+   struct spl_load_info load;
 
/*
 * Load U-Boot image from SPI flash into RAM
@@ -112,77 +112,23 @@ static int spl_spi_load_image(struct spl_image_info 
*spl_image,
return -ENODEV;
}
 
+#if CONFIG_IS_ENABLED(OS_BOOT)
+   if (!spl_start_uboot() && !spi_load_image_os(spl_image, bootdev, flash, 
header))
+   return 0;
+#endif
+
payload_offs = spl_spi_get_uboot_offs(flash);
-
-   header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
-
if (CONFIG_IS_ENABLED(OF_REAL)) {
payload_offs = ofnode_conf_read_int("u-boot,spl-payload-offset",
payload_offs);
}
 
-#if CONFIG_IS_ENABLED(OS_BOOT)
-   if (spl_start_uboot() || spi_load_image_os(spl_image, bootdev, flash, 
header))
-#endif
-   {
-   /* Load u-boot, mkimage header is 64 bytes. */
-   err = spi_flash_read(flash, payload_offs, sizeof(*header),
-(void *)header);
-   if (err) {
-   debug("%s: Failed to read from SPI flash (err=%d)\n",
- __func__, err);
-   return err;
-   }
-
-   if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) &&
-   image_get_magic(header) == FDT_MAGIC) {
-   u32 size = roundup(fdt_totalsize(header), 4);
-
-   err = spi_flash_read(flash, payload_offs,
-size,
-map_sysmem(CONFIG_SYS_LOAD_ADDR,
-   size));
-   if (err)
-   return err;
-   err = spl_parse_image_header(spl_image, bootdev,
-   phys_to_virt(CONFIG_SYS_LOAD_ADDR));
-   } else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
-  image_get_magic(header) == FDT_MAGIC) {
-   struct spl_load_info load;
-
-   debug("Found FIT\n");
-   load.priv = flash;
-   spl_set_bl_len(, 1);
-   load.read = spl_spi_fit_read;
-   err = spl_load_simple_fit(spl_image, ,
- payload_offs,
- header);
-   } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
-  valid_container_hdr((void *)header)) {
-   struct spl_load_info load;
-
-   load.priv = flash;
-   spl_set_bl_len(, 1);
-   load.read = spl_spi_fit_read;
-
-   err = spl_load_imx_container(spl_image, ,
-payload_offs);
-   } else {
-   err = spl_parse_image_header(spl_image, bootdev, 
header);
-   if (err)
-   return err;
-   err = spi_flash_read(flash, payload_offs + 
spl_image->offset,
-spl_image->size,
-map_sysmem(spl_image->load_addr,
-   spl_image->size));
-   }
-   if (IS_ENABLED(CONFIG_SPI_FLASH_SOFT_RESET)) {
-   err = spi_nor_remove(flash);
-   if (err)
-   return err;
-   }
-   }
-
+   load.priv = flash;
+   spl_set_bl_len(, 1);
+   load.read = 

[PATCH v7 26/26] spl: fat: Add option to disable DMA alignment

2023-11-08 Thread Sean Anderson
If we don't DMA-align buffers we pass to FAT, it will align them itself.
This behaviour likely should be deprecated in favor of
CONFIG_BOUNCE_BUFFER, but that's a task for another series. For the
meantime, don't bother aligning the buffer unless we had been doing so in
the past.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v6)

Changes in v6:
- New

 common/spl/Kconfig  | 18 --
 common/spl/spl_blk_fs.c |  5 -
 common/spl/spl_fat.c|  5 -
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index b93526904eb..fc284a5bffc 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -694,13 +694,28 @@ config SPL_FS_SQUASHFS
 config SPL_FS_FAT
bool "Support FAT filesystems"
select FS_FAT
-   select SPL_LOAD_BLOCK
help
  Enable support for FAT and VFAT filesystems with SPL. This
  permits U-Boot (or Linux in Falcon mode) to be loaded from a FAT
  filesystem from within SPL. Support for the underlying block
  device (e.g. MMC or USB) must be enabled separately.
 
+config SPL_FS_FAT_DMA_ALIGN
+   bool "Use DMA-aligned buffers with FAT"
+   depends on SPL_FS_FAT
+   select SPL_LOAD_BLOCK
+   default y if SPL_LOAD_FIT
+   help
+ The FAT filesystem driver tries to ensure that the reads it issues to
+ the block subsystem use DMA-aligned buffers. If the supplied buffer is
+ not DMA-aligned, the FAT driver will use a bounce-buffer and read
+ block-by-block. This is separate from the bounce-buffer used by the
+ block subsystem (CONFIG_BOUNCE_BUFFER).
+
+ Enable this config to align buffers passed to the FAT filesystem
+ driver. This will speed up reads, but will increase the size of U-Boot
+ by around 60 bytes.
+
 config SPL_FS_LOAD_PAYLOAD_NAME
string "File to load for U-Boot from the filesystem"
depends on SPL_FS_EXT4 || SPL_FS_FAT || SPL_FS_SQUASHFS || 
SPL_SEMIHOSTING
@@ -1282,7 +1297,6 @@ config SPL_NVME
depends on BLK
select FS_LOADER
select SPL_BLK_FS
-   select SPL_LOAD_BLOCK
help
  This option enables support for NVM Express devices.
  It supports basic functions of NVMe (read/write).
diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c
index ac267ab979b..04eac6f306b 100644
--- a/common/spl/spl_blk_fs.c
+++ b/common/spl/spl_blk_fs.c
@@ -82,7 +82,10 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
}
 
load.read = spl_fit_read;
-   spl_set_bl_len(, ARCH_DMA_MINALIGN);
+   if (IS_ENABLED(CONFIG_SPL_FS_FAT_DMA_ALIGN))
+   spl_set_bl_len(, ARCH_DMA_MINALIGN);
+   else
+   spl_set_bl_len(, 1);
load.priv = 
return spl_load(spl_image, bootdev, , filesize, 0);
 }
diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index 569f2b32928..a52f9e178e6 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -86,7 +86,10 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
}
 
load.read = spl_fit_read;
-   spl_set_bl_len(, ARCH_DMA_MINALIGN);
+   if (IS_ENABLED(CONFIG_SPL_FS_FAT_DMA_ALIGN))
+   spl_set_bl_len(, ARCH_DMA_MINALIGN);
+   else
+   spl_set_bl_len(, 1);
load.priv = (void *)filename;
err = spl_load(spl_image, bootdev, , size, 0);
 
-- 
2.37.1



[PATCH v7 25/26] spl: spi: Consolidate spi_load_image_os into spl_spi_load_image

2023-11-08 Thread Sean Anderson
spi_load_image_os performs almost the same steps as the non-falcon-boot
path of spl_spi_load_image. The load address is different, and it also
loads a device tree, but that's it. Refactor the boot process so that
they can both use the same load function.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v5)

Changes in v5:
- Rework to load header in spl_load

Changes in v2:
- New

 common/spl/spl_spi.c | 54 
 1 file changed, 14 insertions(+), 40 deletions(-)

diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index f49e534b749..89de73c726c 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -21,41 +21,6 @@
 #include 
 #include 
 
-#if CONFIG_IS_ENABLED(OS_BOOT)
-/*
- * Load the kernel, check for a valid header we can parse, and if found load
- * the kernel and then device tree.
- */
-static int spi_load_image_os(struct spl_image_info *spl_image,
-struct spl_boot_device *bootdev,
-struct spi_flash *flash,
-struct legacy_img_hdr *header)
-{
-   int err;
-
-   /* Read for a header, parse or error out. */
-   spi_flash_read(flash, CFG_SYS_SPI_KERNEL_OFFS, sizeof(*header),
-  (void *)header);
-
-   if (image_get_magic(header) != IH_MAGIC)
-   return -1;
-
-   err = spl_parse_image_header(spl_image, bootdev, header);
-   if (err)
-   return err;
-
-   spi_flash_read(flash, CFG_SYS_SPI_KERNEL_OFFS,
-  spl_image->size, (void *)spl_image->load_addr);
-
-   /* Read device tree. */
-   spi_flash_read(flash, CFG_SYS_SPI_ARGS_OFFS,
-  CFG_SYS_SPI_ARGS_SIZE,
-  (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR);
-
-   return 0;
-}
-#endif
-
 static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector,
  ulong count, void *buf)
 {
@@ -112,9 +77,21 @@ static int spl_spi_load_image(struct spl_image_info 
*spl_image,
return -ENODEV;
}
 
+   load.priv = flash;
+   spl_set_bl_len(, 1);
+   load.read = spl_spi_fit_read;
+
 #if CONFIG_IS_ENABLED(OS_BOOT)
-   if (!spl_start_uboot() && !spi_load_image_os(spl_image, bootdev, flash, 
header))
-   return 0;
+   if (spl_start_uboot()) {
+   int err = spl_load(spl_image, bootdev, , 0,
+  CFG_SYS_SPI_KERNEL_OFFS);
+
+   if (!err)
+   /* Read device tree. */
+   return spi_flash_read(flash, CFG_SYS_SPI_ARGS_OFFS,
+ CFG_SYS_SPI_ARGS_SIZE,
+ (void 
*)CONFIG_SPL_PAYLOAD_ARGS_ADDR);
+   }
 #endif
 
payload_offs = spl_spi_get_uboot_offs(flash);
@@ -123,9 +100,6 @@ static int spl_spi_load_image(struct spl_image_info 
*spl_image,
payload_offs);
}
 
-   load.priv = flash;
-   spl_set_bl_len(, 1);
-   load.read = spl_spi_fit_read;
err = spl_load(spl_image, bootdev, , 0, payload_offs);
if (IS_ENABLED(CONFIG_SPI_FLASH_SOFT_RESET))
err = spi_nor_remove(flash);
-- 
2.37.1



[PATCH v7 23/26] spl: Convert semihosting to spl_load

2023-11-08 Thread Sean Anderson
This converts the semihosting load method to use spl_load. As a result, it
also adds support for LOAD_FIT_FULL and IMX images.

Signed-off-by: Sean Anderson 
---

(no changes since v6)

Changes in v6:
- Explicitly initialize load_info members

Changes in v5:
- Rework to load header in spl_load

Changes in v2:
- New

 common/spl/spl_semihosting.c | 52 +---
 include/spl_load.h   |  1 +
 2 files changed, 7 insertions(+), 46 deletions(-)

diff --git a/common/spl/spl_semihosting.c b/common/spl/spl_semihosting.c
index 9b0610b8fc8..941fa911040 100644
--- a/common/spl/spl_semihosting.c
+++ b/common/spl/spl_semihosting.c
@@ -8,18 +8,7 @@
 #include 
 #include 
 #include 
-
-static int smh_read_full(long fd, void *memp, size_t len)
-{
-   long read;
-
-   read = smh_read(fd, memp, len);
-   if (read < 0)
-   return read;
-   if (read != len)
-   return -EIO;
-   return 0;
-}
+#include 
 
 static ulong smh_fit_read(struct spl_load_info *load, ulong file_offset,
  ulong size, void *buf)
@@ -40,8 +29,7 @@ static int spl_smh_load_image(struct spl_image_info 
*spl_image,
const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME;
int ret;
long fd, len;
-   struct legacy_img_hdr *header =
-   spl_get_load_buffer(-sizeof(*header), sizeof(*header));
+   struct spl_load_info load;
 
fd = smh_open(filename, MODE_READ | MODE_BINARY);
if (fd < 0) {
@@ -56,38 +44,10 @@ static int spl_smh_load_image(struct spl_image_info 
*spl_image,
}
len = ret;
 
-   ret = smh_read_full(fd, header, sizeof(struct legacy_img_hdr));
-   if (ret) {
-   log_debug("could not read image header: %d\n", ret);
-   goto out;
-   }
-
-   if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
-   image_get_magic(header) == FDT_MAGIC) {
-   struct spl_load_info load;
-
-   debug("Found FIT\n");
-   load.read = smh_fit_read;
-   spl_set_bl_len(, 1);
-   load.priv = 
-
-   ret = spl_load_simple_fit(spl_image, , 0, header);
-   goto out;
-   }
-
-   ret = spl_parse_image_header(spl_image, bootdev, header);
-   if (ret) {
-   log_debug("failed to parse image header: %d\n", ret);
-   goto out;
-   }
-
-   ret = smh_seek(fd, 0);
-   if (ret) {
-   log_debug("could not seek to start of image: %d\n", ret);
-   goto out;
-   }
-
-   ret = smh_read_full(fd, (void *)spl_image->load_addr, len);
+   load.read = smh_fit_read;
+   spl_set_bl_len(, 1);
+   load.priv = 
+   ret = spl_load(spl_image, bootdev, , len, 0);
if (ret)
log_debug("could not read %s: %d\n", filename, ret);
 out:
diff --git a/include/spl_load.h b/include/spl_load.h
index 2618109cee0..2a20e866cd8 100644
--- a/include/spl_load.h
+++ b/include/spl_load.h
@@ -102,6 +102,7 @@ static inline int _spl_load(struct spl_image_info 
*spl_image,
(IS_ENABLED(CONFIG_SPL_NAND_SUPPORT) && !IS_ENABLED(CONFIG_SPL_UBI)) + \
IS_ENABLED(CONFIG_SPL_NET) + \
IS_ENABLED(CONFIG_SPL_NOR_SUPPORT) + \
+   IS_ENABLED(CONFIG_SPL_SEMIHOSTING) + \
0
 
 #if SPL_LOAD_USERS > 1
-- 
2.37.1



[PATCH v7 21/26] spl: Convert nor to spl_load

2023-11-08 Thread Sean Anderson
This converts the nor load method to use spl_load. As a result it also
adds support for LOAD_FIT_FULL. Since this is the last caller of
spl_load_legacy_img, it has been removed.

We can't load FITs with external data with SPL_LOAD_FIT_FULL, so disable the
test in that case. No boards enable SPL_NOR_SUPPORT and SPL_LOAD_FIT_FULL, so
this is not a regression.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v6)

Changes in v6:
- Fix LZMA support
- Fix load address
- Explicitly initialize load_info members

Changes in v5:
- Rework to load header in spl_load

 common/spl/spl_legacy.c   | 61 ---
 common/spl/spl_nor.c  | 40 +
 include/spl_load.h|  1 +
 test/image/spl_load_nor.c |  2 ++
 4 files changed, 10 insertions(+), 94 deletions(-)

diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c
index a561939b4f0..08687ca8f6c 100644
--- a/common/spl/spl_legacy.c
+++ b/common/spl/spl_legacy.c
@@ -118,64 +118,3 @@ int spl_load_legacy_lzma(struct spl_image_info *spl_image,
spl_image->size = lzma_len;
return 0;
 }
-
-/*
- * This function is added explicitly to avoid code size increase, when
- * no compression method is enabled. The compiler will optimize the
- * following switch/case statement in spl_load_legacy_img() away due to
- * Dead Code Elimination.
- */
-static inline int spl_image_get_comp(const struct legacy_img_hdr *hdr)
-{
-   if (IS_ENABLED(CONFIG_SPL_LZMA))
-   return image_get_comp(hdr);
-
-   return IH_COMP_NONE;
-}
-
-int spl_load_legacy_img(struct spl_image_info *spl_image,
-   struct spl_boot_device *bootdev,
-   struct spl_load_info *load, ulong offset,
-   struct legacy_img_hdr *hdr)
-{
-   ulong dataptr;
-   int ret;
-
-   /*
-* If the payload is compressed, the decompressed data should be
-* directly write to its load address.
-*/
-   if (spl_image_get_comp(hdr) != IH_COMP_NONE)
-   spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
-
-   ret = spl_parse_image_header(spl_image, bootdev, hdr);
-   if (ret)
-   return ret;
-
-   /* Read image */
-   switch (spl_image_get_comp(hdr)) {
-   case IH_COMP_NONE:
-   dataptr = offset;
-
-   /*
-* Image header will be skipped only if SPL_COPY_PAYLOAD_ONLY
-* is set
-*/
-   if (spl_image->flags & SPL_COPY_PAYLOAD_ONLY)
-   dataptr += sizeof(*hdr);
-
-   load->read(load, dataptr, spl_image->size,
-  map_sysmem(spl_image->load_addr, spl_image->size));
-   break;
-
-   case IH_COMP_LZMA:
-   return spl_load_legacy_lzma(spl_image, load, offset);
-
-   default:
-   debug("Compression method %s is not supported\n",
- genimg_get_comp_short_name(image_get_comp(hdr)));
-   return -EINVAL;
-   }
-
-   return 0;
-}
diff --git a/common/spl/spl_nor.c b/common/spl/spl_nor.c
index aad230db4d3..70745114efe 100644
--- a/common/spl/spl_nor.c
+++ b/common/spl/spl_nor.c
@@ -7,8 +7,8 @@
 #include 
 #include 
 #include 
-#include 
 #include 
+#include 
 
 static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
   ulong count, void *buf)
@@ -28,8 +28,7 @@ unsigned long __weak spl_nor_get_uboot_base(void)
 static int spl_nor_load_image(struct spl_image_info *spl_image,
  struct spl_boot_device *bootdev)
 {
-   struct legacy_img_hdr *header;
-   __maybe_unused struct spl_load_info load;
+   struct spl_load_info load;
 
/*
 * Loading of the payload to SDRAM is done with skipping of
@@ -43,7 +42,8 @@ static int spl_nor_load_image(struct spl_image_info 
*spl_image,
 * Load Linux from its location in NOR flash to its defined
 * location in SDRAM
 */
-   header = (void *)CONFIG_SYS_OS_BASE;
+   const struct legacy_img_hdr *header =
+   (const struct legacy_img_hdr *)CONFIG_SYS_OS_BASE;
 #ifdef CONFIG_SPL_LOAD_FIT
if (image_get_magic(header) == FDT_MAGIC) {
int ret;
@@ -93,34 +93,8 @@ static int spl_nor_load_image(struct spl_image_info 
*spl_image,
 * Load real U-Boot from its location in NOR flash to its
 * defined location in SDRAM
 */
-   header = map_sysmem(spl_nor_get_uboot_base(), sizeof(*header));
-#ifdef CONFIG_SPL_LOAD_FIT
-   if (image_get_magic(header) == FDT_MAGIC) {
-   debug("Found FIT format U-Boot\n");
-   spl_set_bl_len(, 1);
-   load.read = spl_nor_load_read;
-   return spl_load_simple_fit(spl_image, ,
-  

[PATCH v7 20/26] spl: Convert net to spl_load

2023-11-08 Thread Sean Anderson
This converts the net load method to use spl_load. As a result, it also
adds support for LOAD_FIT_FULL and IMX images.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v6)

Changes in v6:
- Explicitly initialize load_info members

Changes in v5:
- Rework to load header in spl_load

 common/spl/spl_net.c  | 29 +
 include/spl_load.h|  1 +
 test/image/spl_load_net.c |  2 ++
 3 files changed, 8 insertions(+), 24 deletions(-)

diff --git a/common/spl/spl_net.c b/common/spl/spl_net.c
index 47994e28165..898f9df705a 100644
--- a/common/spl/spl_net.c
+++ b/common/spl/spl_net.c
@@ -11,8 +11,8 @@
 #include 
 #include 
 #include 
-#include 
 #include 
+#include 
 #include 
 #include 
 
@@ -29,8 +29,7 @@ static ulong spl_net_load_read(struct spl_load_info *load, 
ulong sector,
 static int spl_net_load_image(struct spl_image_info *spl_image,
  struct spl_boot_device *bootdev)
 {
-   struct legacy_img_hdr *header = map_sysmem(image_load_addr,
-  sizeof(*header));
+   struct spl_load_info load;
int rv;
 
env_init();
@@ -49,27 +48,9 @@ static int spl_net_load_image(struct spl_image_info 
*spl_image,
return rv;
}
 
-   if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
-   image_get_magic(header) == FDT_MAGIC) {
-   struct spl_load_info load;
-
-   debug("Found FIT\n");
-   spl_set_bl_len(, 1);
-   load.read = spl_net_load_read;
-   rv = spl_load_simple_fit(spl_image, , 0, header);
-   } else {
-   debug("Legacy image\n");
-
-   rv = spl_parse_image_header(spl_image, bootdev, header);
-   if (rv)
-   return rv;
-
-   memcpy(map_sysmem(spl_image->load_addr, spl_image->size),
-  map_sysmem(image_load_addr, spl_image->size),
-  spl_image->size);
-   }
-
-   return rv;
+   spl_set_bl_len(, 1);
+   load.read = spl_net_load_read;
+   return spl_load(spl_image, bootdev, , 0, 0);
 }
 #endif
 
diff --git a/include/spl_load.h b/include/spl_load.h
index 38294a21ad0..4777f84ac6b 100644
--- a/include/spl_load.h
+++ b/include/spl_load.h
@@ -99,6 +99,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
IS_ENABLED(CONFIG_SPL_FS_FAT) + \
IS_ENABLED(CONFIG_SPL_SYS_MMCSD_RAW_MODE) + \
(IS_ENABLED(CONFIG_SPL_NAND_SUPPORT) && !IS_ENABLED(CONFIG_SPL_UBI)) + \
+   IS_ENABLED(CONFIG_SPL_NET) + \
0
 
 #if SPL_LOAD_USERS > 1
diff --git a/test/image/spl_load_net.c b/test/image/spl_load_net.c
index f570cef163f..9d067a7a592 100644
--- a/test/image/spl_load_net.c
+++ b/test/image/spl_load_net.c
@@ -248,5 +248,7 @@ static int spl_test_net(struct unit_test_state *uts, const 
char *test_name,
return ret;
 }
 SPL_IMG_TEST(spl_test_net, LEGACY, DM_FLAGS);
+SPL_IMG_TEST(spl_test_net, LEGACY_LZMA, DM_FLAGS);
+SPL_IMG_TEST(spl_test_net, IMX8, DM_FLAGS);
 SPL_IMG_TEST(spl_test_net, FIT_INTERNAL, DM_FLAGS);
 SPL_IMG_TEST(spl_test_net, FIT_EXTERNAL, DM_FLAGS);
-- 
2.37.1



[PATCH v7 22/26] spl: Convert NVMe to spl_load

2023-11-08 Thread Sean Anderson
This converts the blk load method (used exclusively by NVMe) to use
spl_load. As a consequence, it also adds support for LOAD_FIT_FULL and
IMX images.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v6)

Changes in v6:
- Fix invalid return from spl_blk_load_image
- Explicitly initialize load_info members

Changes in v5:
- New

 common/spl/spl_blk_fs.c  | 66 +++-
 include/spl_load.h   |  1 +
 test/image/spl_load_fs.c |  2 ++
 3 files changed, 14 insertions(+), 55 deletions(-)

diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c
index 53b8e1b11b4..ac267ab979b 100644
--- a/common/spl/spl_blk_fs.c
+++ b/common/spl/spl_blk_fs.c
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -48,11 +49,11 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
   enum uclass_id uclass_id, int devnum, int partnum)
 {
const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME;
-   struct legacy_img_hdr *header;
struct blk_desc *blk_desc;
-   loff_t actlen, filesize;
+   loff_t filesize;
struct blk_dev dev;
-   int ret = -ENODEV;
+   struct spl_load_info load;
+   int ret;
 
blk_desc = blk_get_devnum_by_uclass_id(uclass_id, devnum);
if (!blk_desc) {
@@ -61,8 +62,8 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
}
 
blk_show_device(uclass_id, devnum);
-   header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
 
+   dev.filename = filename;
dev.ifname = blk_get_uclass_name(uclass_id);
snprintf(dev.dev_part_str, sizeof(dev.dev_part_str) - 1, "%x:%x",
 devnum, partnum);
@@ -70,63 +71,18 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
if (ret) {
printf("spl: unable to set blk_dev %s %s. Err - %d\n",
   dev.ifname, dev.dev_part_str, ret);
-   goto out;
-   }
-
-   ret = fs_read(filename, virt_to_phys(header), 0,
- sizeof(struct legacy_img_hdr), );
-   if (ret) {
-   printf("spl: unable to read file %s. Err - %d\n", filename,
-  ret);
-   goto out;
-   }
-
-   if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
-   image_get_magic(header) == FDT_MAGIC) {
-   struct spl_load_info load;
-
-   debug("Found FIT\n");
-   load.read = spl_fit_read;
-   spl_set_bl_len(, ARCH_DMA_MINALIGN);
-   load.priv = 
-   dev.filename = filename;
-
-   return spl_load_simple_fit(spl_image, , 0, header);
-   }
-
-   ret = spl_parse_image_header(spl_image, bootdev, header);
-   if (ret) {
-   printf("spl: unable to parse image header. Err - %d\n",
-  ret);
-   goto out;
-   }
-
-   ret = fs_set_blk_dev(dev.ifname, dev.dev_part_str, FS_TYPE_ANY);
-   if (ret) {
-   printf("spl: unable to set blk_dev %s %s. Err - %d\n",
-  dev.ifname, dev.dev_part_str, ret);
-   goto out;
+   return ret;
}
 
ret = fs_size(filename, );
if (ret) {
printf("spl: unable to get file size: %s. Err - %d\n",
   filename, ret);
-   goto out;
+   return ret;
}
 
-   ret = fs_set_blk_dev(dev.ifname, dev.dev_part_str, FS_TYPE_ANY);
-   if (ret) {
-   printf("spl: unable to set blk_dev %s %s. Err - %d\n",
-  dev.ifname, dev.dev_part_str, ret);
-   goto out;
-   }
-
-   ret = fs_read(filename, (ulong)spl_image->load_addr, 0, filesize,
- );
-   if (ret)
-   printf("spl: unable to read file %s. Err - %d\n",
-  filename, ret);
-out:
-   return ret;
+   load.read = spl_fit_read;
+   spl_set_bl_len(, ARCH_DMA_MINALIGN);
+   load.priv = 
+   return spl_load(spl_image, bootdev, , filesize, 0);
 }
diff --git a/include/spl_load.h b/include/spl_load.h
index b48f80324bb..2618109cee0 100644
--- a/include/spl_load.h
+++ b/include/spl_load.h
@@ -95,6 +95,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
  * inline if there is one caller, and extern otherwise.
  */
 #define SPL_LOAD_USERS \
+   IS_ENABLED(CONFIG_SPL_BLK_FS) + \
IS_ENABLED(CONFIG_SPL_FS_EXT4) + \
IS_ENABLED(CONFIG_SPL_FS_FAT) + \
IS_ENABLED(CONFIG_SPL_SYS_MMCSD_RAW_MODE) + \
diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c
index 67c19da95e7..5f1de5486f4 100644
--- a/test/image/spl_load_fs.c
+++ b/test/image/spl_load_fs.c
@@ -395,6 +395,8 @@ static int spl_test_blk(struct unit_test_state *uts, const 
char *test_name,
return spl_test_mmc_fs(uts, test_name, type, create_ext2, true);
 }
 SPL_IMG_TEST(spl_test_blk, LEGACY, 

[PATCH v7 19/26] spl: Convert nand to spl_load

2023-11-08 Thread Sean Anderson
This converts the nand load method to use spl_load. nand_page_size may not
be valid until after nand_spl_load_image is called (see e.g. fsl_ifc_spl),
so we set bl_len in spl_nand_read. Since spl_load reads the header for us,
we can remove that argument from spl_nand_load_element.

There are two possible regressions which could result from this commit.
First, we ask for a negative address from spl_get_load_buffer. That is,
instead of

header = spl_get_load_buffer(0, sizeof(*header));

we do

header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));

this could cause a problem if spl_get_load_buffer does not return valid
memory for negative offsets. Second, we now set bl_len for legacy images.
This can cause memory up to a bl_len - 1 before the image load address to
be written, which might not have been the case before. If this turns out to
be a problem, we can add an option for a bounce buffer.

We can't load FITs with external data with SPL_LOAD_FIT_FULL, so disable the
test in that case. No boards enable SPL_NAND_SUPPORT and SPL_LOAD_FIT_FULL, so
this is not a regression.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v6)

Changes in v6:
- New

 common/spl/spl_nand.c  | 70 +-
 include/spl_load.h |  1 +
 test/image/spl_load_nand.c |  2 ++
 3 files changed, 19 insertions(+), 54 deletions(-)

diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index 91fa7674f17..3b0a1524238 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -59,6 +60,7 @@ static ulong spl_nand_read(struct spl_load_info *load, ulong 
offs, ulong size,
sector = *(int *)load->priv;
offs = sector + nand_spl_adjust_offset(sector, offs - sector);
err = nand_spl_load_image(offs, size, dst);
+   spl_set_bl_len(load, nand_page_size());
if (err)
return 0;
 
@@ -66,60 +68,20 @@ static ulong spl_nand_read(struct spl_load_info *load, 
ulong offs, ulong size,
 }
 
 static int spl_nand_load_element(struct spl_image_info *spl_image,
-struct spl_boot_device *bootdev,
-int offset, struct legacy_img_hdr *header)
+struct spl_boot_device *bootdev, int offset)
 {
-   int bl_len;
-   int err;
+   struct spl_load_info load;
 
-   err = nand_spl_load_image(offset, sizeof(*header), (void *)header);
-   if (err)
-   return err;
-
-   bl_len = nand_page_size();
-   if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
-   image_get_magic(header) == FDT_MAGIC) {
-   struct spl_load_info load;
-
-   debug("Found FIT\n");
-   load.priv = 
-   spl_set_bl_len(, bl_len);
-   load.read = spl_nand_read;
-   return spl_load_simple_fit(spl_image, , offset, header);
-   } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
-  valid_container_hdr((void *)header)) {
-   struct spl_load_info load;
-
-   load.priv = 
-   spl_set_bl_len(, bl_len);
-   load.read = spl_nand_read;
-   return spl_load_imx_container(spl_image, , offset);
-   } else if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT) &&
-  image_get_magic(header) == IH_MAGIC) {
-   struct spl_load_info load;
-
-   debug("Found legacy image\n");
-   load.priv = 
-   spl_set_bl_len(, IS_ENABLED(CONFIG_SPL_LZMA) ? bl_len : 1);
-   load.read = spl_nand_read;
-   return spl_load_legacy_img(spl_image, bootdev, , offset, 
header);
-   } else {
-   err = spl_parse_image_header(spl_image, bootdev, header);
-   if (err)
-   return err;
-   return nand_spl_load_image(offset, spl_image->size,
-  map_sysmem(spl_image->load_addr,
- spl_image->size));
-   }
+   load.priv = 
+   spl_set_bl_len(, 1);
+   load.read = spl_nand_read;
+   return spl_load(spl_image, bootdev, , 0, offset);
 }
 
 static int spl_nand_load_image(struct spl_image_info *spl_image,
   struct spl_boot_device *bootdev)
 {
int err;
-   struct legacy_img_hdr *header;
-   int *src __attribute__((unused));
-   int *dst __attribute__((unused));
 
 #ifdef CONFIG_SPL_NAND_SOFTECC
debug("spl: nand - using sw ecc\n");
@@ -128,10 +90,12 @@ static int spl_nand_load_image(struct spl_image_info 
*spl_image,
 #endif
nand_init();
 
-   header = spl_get_load_buffer(0, sizeof(*header));
-
 #if CONFIG_IS_ENABLED(OS_BOOT)
if (!spl_start_uboot()) {
+   int *src, *dst;
+   struct 

[PATCH v7 18/26] spl: Convert mmc to spl_load

2023-11-08 Thread Sean Anderson
This converts the mmc loader to spl_load. Legacy images are handled by
spl_load (via spl_parse_image_header), so mmc_load_legacy can be
omitted. To accurately determine whether mmc_load_image_raw_sector is used
(which might not be the case if SYS_MMCSD_FS_BOOT is enabled), we introduce
a helper config SYS_MMCSD_RAW_MODE. This ensures we can inline spl_load
correctly when a board only boots from filesystems. We still need to check
for SPL_MMC, since some boards enable configure raw mode even without MMC
support.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v6)

Changes in v6:
- Add SYS_MMCSD_RAW_MODE to help determine whether SPL_MMC loads
  anything directly.
- Explicitly initialize load_info members

Changes in v5:
- Rework to load header in spl_load

 common/spl/Kconfig   |  8 
 common/spl/spl_mmc.c | 89 
 include/spl_load.h   |  1 +
 test/image/spl_load_fs.c |  3 --
 4 files changed, 16 insertions(+), 85 deletions(-)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 0bc57d5fedb..b93526904eb 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -481,6 +481,11 @@ config SPL_DISPLAY_PRINT
  banner ("U-Boot SPL ..."). This function should be provided by
  the board.
 
+config SPL_SYS_MMCSD_RAW_MODE
+   bool
+   help
+ Support booting from an MMC without a filesystem.
+
 config SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
bool "MMC raw mode: by sector"
default y if ARCH_SUNXI || ARCH_DAVINCI || ARCH_UNIPHIER || \
@@ -490,6 +495,7 @@ config SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
 OMAP44XX || OMAP54XX || AM33XX || AM43XX || \
 TARGET_SIFIVE_UNLEASHED || TARGET_SIFIVE_UNMATCHED
select SPL_LOAD_BLOCK if SPL_MMC
+   select SPL_SYS_MMCSD_RAW_MODE if SPL_MMC
help
  Use sector number for specifying U-Boot location on MMC/SD in
  raw mode.
@@ -527,6 +533,7 @@ config SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET
 config SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
bool "MMC Raw mode: by partition"
select SPL_LOAD_BLOCK if SPL_MMC
+   select SPL_SYS_MMCSD_RAW_MODE if SPL_MMC
help
  Use a partition for loading U-Boot when using MMC/SD in raw mode.
 
@@ -1114,6 +1121,7 @@ config SPL_FALCON_BOOT_MMCSD
bool "Enable Falcon boot from MMC or SD media"
depends on SPL_OS_BOOT && SPL_MMC
select SPL_LOAD_BLOCK
+   select SPL_SYS_MMCSD_RAW_MODE
help
  Select this if the Falcon mode OS image mode is on MMC or SD media.
 
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 91272c03d3f..3d032bb27ce 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -8,9 +8,9 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -19,49 +19,6 @@
 #include 
 #include 
 
-static int mmc_load_legacy(struct spl_image_info *spl_image,
-  struct spl_boot_device *bootdev,
-  struct mmc *mmc,
-  ulong sector, struct legacy_img_hdr *header)
-{
-   u32 image_offset_sectors;
-   u32 image_size_sectors;
-   unsigned long count;
-   u32 image_offset;
-   int ret;
-
-   ret = spl_parse_image_header(spl_image, bootdev, header);
-   if (ret)
-   return ret;
-
-   /* convert offset to sectors - round down */
-   image_offset_sectors = spl_image->offset / mmc->read_bl_len;
-   /* calculate remaining offset */
-   image_offset = spl_image->offset % mmc->read_bl_len;
-
-   /* convert size to sectors - round up */
-   image_size_sectors = (spl_image->size + mmc->read_bl_len - 1) /
-mmc->read_bl_len;
-
-   /* Read the header too to avoid extra memcpy */
-   count = blk_dread(mmc_get_blk_desc(mmc),
- sector + image_offset_sectors,
- image_size_sectors,
- map_sysmem(spl_image->load_addr,
-image_size_sectors * mmc->read_bl_len));
-   debug("read %x sectors to %lx\n", image_size_sectors,
- spl_image->load_addr);
-   if (count != image_size_sectors)
-   return -EIO;
-
-   if (image_offset)
-   memmove((void *)(ulong)spl_image->load_addr,
-   (void *)(ulong)spl_image->load_addr + image_offset,
-   spl_image->size);
-
-   return 0;
-}
-
 static ulong h_spl_load_read(struct spl_load_info *load, ulong off,
 ulong size, void *buf)
 {
@@ -87,46 +44,14 @@ int mmc_load_image_raw_sector(struct spl_image_info 
*spl_image,
  struct spl_boot_device *bootdev,
  struct mmc *mmc, unsigned long sector)
 {
-   unsigned long count;
-   struct legacy_img_hdr *header;
+  

Re: [PATCH 1/3] board: ti: common: add rtc setup to common folder

2023-11-08 Thread Tom Rini
On Wed, Nov 08, 2023 at 09:46:34AM -0600, Bryan Brattlof wrote:
> On November  7, 2023 thus sayeth Tom Rini:
> > On Tue, Nov 07, 2023 at 05:21:41PM -0600, Bryan Brattlof wrote:
> > 
> > > All of the starter kit boards for the am62xxx extended family utilize
> > > the same 32k crystal oscillator for a more accurate clock for the RTC
> > > instance. Add the setup the clock mux and debounce configuration to the
> > > common board directory so the entire am62xxx extended family can utilize
> > > it.
> > > 
> > > Signed-off-by: Bryan Brattlof 
> > [snip]
> > > diff --git a/board/ti/common/Kconfig b/board/ti/common/Kconfig
> > > index 49edd98014ab7..56a65c0a402bb 100644
> > > --- a/board/ti/common/Kconfig
> > > +++ b/board/ti/common/Kconfig
> > > @@ -1,3 +1,11 @@
> > > +config BOARD_HAS_32K_RTC_CRYSTAL
> > > + bool "Enable the 32k crystial for RTC"
> > > + help
> > > +Some of Texas Instrument's Starter-Kit boards have
> > > +an onboard 32k crystal. Select this option if you wish Uboot
> > > +to enable this crystal for Linux
> > > + default n
> > 
> > No "default n" as that is the default. And we (a) need some depends on
> > for what families this is found on and then (b) how, if at all, does
> > this match up with the 32k crystal used on other TI reference platforms
> > over the years? If this is specific to the K3 families of reference
> > platforms, the help needs re-phrasing and the filename is too generic.
> > It's also not a "RTC" in terms of something we can talk to via
> > drivers/rtc/rtc-uclass.c and drivers/rtc/davinci.c, or in this case
> > porting the kernel's drivers/rtc/rtc-ti-k3.c over, yes?
> > 
> > Oh, and "U-Boot" not "Uboot". Should see if the checkpatch typo list
> > can be easily expanded by us, one of these days.
> 
> Yeah I'll work on the wording.
> 
> We just need to toggle a few bits for Linux to get the crystal muxed 
> properly for the RTC driver in Linux.

This sounds a whole lot like what AM33XX_ENABLE_RTC32K_OSC symbol (which
could be badly named, too!) is about, and hence some of my other
questions. So please keep in mind the am33xx case here, and also how
likely or not every custom K3 platform is also going to be doing this,
or not. On am33xx, it does look like a few do disable it, but it's in
common code since most custom platforms want it.

> We also toggle a few bits for the debouce settings that apparently I 
> didn't separate out from this series.

Please keep in mind if these too are essentially generic changes for the
SoC family as well (or just how board specific they might be and how
wrong they could be before a problem is seen, ie technical vs
practical considerations).

-- 
Tom


signature.asc
Description: PGP signature


[PATCH v7 17/26] spl: Convert fat to spl_load

2023-11-08 Thread Sean Anderson
This converts the fat loader to use spl_load. Some platforms are very
tight on space, so we take care to only include the code we really need.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v5)

Changes in v5:
- Rework to load header in spl_load

Changes in v3:
- Fix failing on success

 common/spl/spl_fat.c | 56 +---
 include/spl_load.h   |  1 +
 test/image/spl_load_fs.c |  3 +--
 3 files changed, 20 insertions(+), 40 deletions(-)

diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index a0c34eba48f..569f2b32928 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -11,8 +11,8 @@
 #include 
 #include 
 #include 
-#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -66,58 +66,38 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
   const char *filename)
 {
int err;
-   struct legacy_img_hdr *header;
+   loff_t size;
+   struct spl_load_info load;
 
err = spl_register_fat_device(block_dev, partition);
if (err)
goto end;
 
-   header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
-
-   err = file_fat_read(filename, header, sizeof(struct legacy_img_hdr));
-   if (err <= 0)
-   goto end;
-
-   if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) &&
-   image_get_magic(header) == FDT_MAGIC) {
-   err = file_fat_read(filename,
-   map_sysmem(CONFIG_SYS_LOAD_ADDR, 0), 0);
-   if (err <= 0)
-   goto end;
-   err = spl_parse_image_header(spl_image, bootdev,
-map_sysmem(CONFIG_SYS_LOAD_ADDR,
-   err));
-   if (err == -EAGAIN)
-   return err;
-   if (err == 0)
-   err = 1;
-   } else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
-   image_get_magic(header) == FDT_MAGIC) {
-   struct spl_load_info load;
-
-   debug("Found FIT\n");
-   load.read = spl_fit_read;
-   spl_set_bl_len(, ARCH_DMA_MINALIGN);
-   load.priv = (void *)filename;
-
-   return spl_load_simple_fit(spl_image, , 0, header);
-   } else {
-   err = spl_parse_image_header(spl_image, bootdev, header);
+   /*
+* Avoid pulling in this function for other image types since we are
+* very short on space on some boards.
+*/
+   if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL)) {
+   err = fat_size(filename, );
if (err)
goto end;
-
-   err = file_fat_read(filename, map_sysmem(spl_image->load_addr,
-spl_image->size), 0);
+   } else {
+   size = 0;
}
 
+   load.read = spl_fit_read;
+   spl_set_bl_len(, ARCH_DMA_MINALIGN);
+   load.priv = (void *)filename;
+   err = spl_load(spl_image, bootdev, , size, 0);
+
 end:
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
-   if (err <= 0)
+   if (err < 0)
printf("%s: error reading image %s, err - %d\n",
   __func__, filename, err);
 #endif
 
-   return (err <= 0);
+   return err;
 }
 
 #if CONFIG_IS_ENABLED(OS_BOOT)
diff --git a/include/spl_load.h b/include/spl_load.h
index 65aa6bb4493..5e0460d956d 100644
--- a/include/spl_load.h
+++ b/include/spl_load.h
@@ -96,6 +96,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
  */
 #define SPL_LOAD_USERS \
IS_ENABLED(CONFIG_SPL_FS_EXT4) + \
+   IS_ENABLED(CONFIG_SPL_FS_FAT) + \
0
 
 #if SPL_LOAD_USERS > 1
diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c
index 01559e98c4f..333df2dfb53 100644
--- a/test/image/spl_load_fs.c
+++ b/test/image/spl_load_fs.c
@@ -425,8 +425,7 @@ static int spl_test_mmc(struct unit_test_state *uts, const 
char *test_name,
if (spl_test_mmc_fs(uts, test_name, type, create_ext2, false))
return CMD_RET_FAILURE;
 
-   if (type != IMX8 && type != LEGACY_LZMA &&
-   spl_test_mmc_fs(uts, test_name, type, create_fat, false))
+   if (spl_test_mmc_fs(uts, test_name, type, create_fat, false))
return CMD_RET_FAILURE;
 
if (type == LEGACY_LZMA)
-- 
2.37.1



[PATCH v7 15/26] spl: Add generic spl_load function

2023-11-08 Thread Sean Anderson
Implementers of SPL_LOAD_IMAGE_METHOD have to correctly determine what
type of image is being loaded and then call the appropriate image load
function correctly. This is tricky, because some image load functions
expect the whole image to already be loaded (CONFIG_SPL_LOAD_FIT_FULL),
some will load the image automatically using spl_load_info.read()
(CONFIG_SPL_LOAD_FIT/CONFIG_SPL_LOAD_IMX_CONTAINER), and some just parse
the header and expect the caller to do the actual loading afterwards
(legacy/raw images). Load methods often only support a subset of the
above methods, meaning that not all image types can be used with all
load methods. Further, the code to invoke these functions is
duplicated between different load functions.

To address this problem, this commit introduces a "spl_load" function.
It aims to handle image detection and correct invocation of each of the
parse/load functions.

Although this function generally results in a size reduction with
several users, it tends to bloat boards with only a single user.
This is generally because programmers open-coding the contents of this
function can make optimizations based on the specific loader. For
example, NOR flash is memory-mapped, so it never bothers calling
load->read. The compiler can't really make these optimizations across
translation units. LTO solves this, but it is only available on some
arches. To address this, perform "pseudo-LTO" by inlining spl_load when
there are one or fewer users. At the moment, there are no users, so
define SPL_LOAD_USERS to be 0.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v6)

Changes in v6:
- Use pseudo-LTO for spl_load
- Align reads to bl_len

Changes in v5:
- Load the header in spl_load as well
- Don't bother trying to DMA-align the buffer, since we can't really fix
  it.

Changes in v4:
- Fix format specifiers in debug prints
- Reword/fix some of the doc comments for spl_load

Changes in v3:
- Fix using ffs instead of fls
- Fix using not initializing bl_len when info->filename was NULL

Changes in v2:
- Use reverse-xmas-tree style for locals in spl_simple_read. This is not
  complete, since overhead depends on bl_mask.

 common/spl/spl.c   |  10 
 include/spl_load.h | 135 +
 2 files changed, 145 insertions(+)
 create mode 100644 include/spl_load.h

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 7ce38ce46d4..3ce5bfeec8b 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -352,6 +353,15 @@ int spl_parse_image_header(struct spl_image_info 
*spl_image,
return 0;
 }
 
+#if SPL_LOAD_USERS > 1
+int spl_load(struct spl_image_info *spl_image,
+const struct spl_boot_device *bootdev, struct spl_load_info *info,
+size_t size, size_t offset)
+{
+   return _spl_load(spl_image, bootdev, info, size, offset);
+}
+#endif
+
 __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
 {
typedef void __noreturn (*image_entry_noargs_t)(void);
diff --git a/include/spl_load.h b/include/spl_load.h
new file mode 100644
index 000..406f8b577b2
--- /dev/null
+++ b/include/spl_load.h
@@ -0,0 +1,135 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) Sean Anderson 
+ */
+#ifndef_SPL_LOAD_H_
+#define_SPL_LOAD_H_
+
+#include 
+#include 
+#include 
+#include 
+
+static inline int _spl_load(struct spl_image_info *spl_image,
+   const struct spl_boot_device *bootdev,
+   struct spl_load_info *info, size_t size,
+   size_t offset)
+{
+   struct legacy_img_hdr *header =
+   spl_get_load_buffer(-sizeof(*header), sizeof(*header));
+   ulong base_offset, image_offset, overhead;
+   int read, ret;
+
+   read = info->read(info, offset, ALIGN(sizeof(*header),
+ spl_get_bl_len(info)), header);
+   if (read < sizeof(*header))
+   return -EIO;
+
+   if (image_get_magic(header) == FDT_MAGIC) {
+   if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL)) {
+   void *buf;
+
+   /*
+* In order to support verifying images in the FIT, we
+* need to load the whole FIT into memory. Try and
+* guess how much we need to load by using the total
+* size. This will fail for FITs with external data,
+* but there's not much we can do about that.
+*/
+   if (!size)
+   size = round_up(fdt_totalsize(header), 4);
+   buf = map_sysmem(CONFIG_SYS_LOAD_ADDR, size);
+   read = info->read(info, offset,
+ ALIGN(size, 

[PATCH v7 16/26] spl: Convert ext to use spl_load

2023-11-08 Thread Sean Anderson
This converts the ext load method to use spl_load. As a consequence, it
also adds support for FIT and IMX images.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v6)

Changes in v6:
- Explicitly initialize load_info members

Changes in v5:
- Rework to load header in spl_load

 common/spl/spl_ext.c | 36 ++--
 include/spl_load.h   |  1 +
 test/image/spl_load_fs.c |  9 ++---
 3 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c
index af836ca15b8..d280b69c387 100644
--- a/common/spl/spl_ext.c
+++ b/common/spl/spl_ext.c
@@ -2,25 +2,35 @@
 
 #include 
 #include 
-#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 
+static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
+ ulong size, void *buf)
+{
+   int ret;
+   loff_t actlen;
+
+   ret = ext4fs_read(buf, file_offset, size, );
+   if (ret)
+   return ret;
+   return actlen;
+}
+
 int spl_load_image_ext(struct spl_image_info *spl_image,
   struct spl_boot_device *bootdev,
   struct blk_desc *block_dev, int partition,
   const char *filename)
 {
s32 err;
-   struct legacy_img_hdr *header;
-   loff_t filelen, actlen;
+   loff_t filelen;
struct disk_partition part_info = {};
-
-   header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
+   struct spl_load_info load;
 
if (part_get_info(block_dev, partition, _info)) {
printf("spl: no partition table found\n");
@@ -42,20 +52,10 @@ int spl_load_image_ext(struct spl_image_info *spl_image,
puts("spl: ext4fs_open failed\n");
goto end;
}
-   err = ext4fs_read((char *)header, 0, sizeof(struct legacy_img_hdr), 
);
-   if (err < 0) {
-   puts("spl: ext4fs_read failed\n");
-   goto end;
-   }
 
-   err = spl_parse_image_header(spl_image, bootdev, header);
-   if (err < 0) {
-   puts("spl: ext: failed to parse image header\n");
-   goto end;
-   }
-
-   err = ext4fs_read(map_sysmem(spl_image->load_addr, filelen), 0, filelen,
- );
+   spl_set_bl_len(, 1);
+   load.read = spl_fit_read;
+   err = spl_load(spl_image, bootdev, , filelen, 0);
 
 end:
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
diff --git a/include/spl_load.h b/include/spl_load.h
index 406f8b577b2..65aa6bb4493 100644
--- a/include/spl_load.h
+++ b/include/spl_load.h
@@ -95,6 +95,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
  * inline if there is one caller, and extern otherwise.
  */
 #define SPL_LOAD_USERS \
+   IS_ENABLED(CONFIG_SPL_FS_EXT4) + \
0
 
 #if SPL_LOAD_USERS > 1
diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c
index 59d0244d44b..01559e98c4f 100644
--- a/test/image/spl_load_fs.c
+++ b/test/image/spl_load_fs.c
@@ -422,20 +422,23 @@ static int spl_test_mmc(struct unit_test_state *uts, 
const char *test_name,
spl_mmc_clear_cache();
spl_fat_force_reregister();
 
-   if (type == LEGACY &&
-   spl_test_mmc_fs(uts, test_name, type, create_ext2, false))
+   if (spl_test_mmc_fs(uts, test_name, type, create_ext2, false))
return CMD_RET_FAILURE;
 
-   if (type != IMX8 &&
+   if (type != IMX8 && type != LEGACY_LZMA &&
spl_test_mmc_fs(uts, test_name, type, create_fat, false))
return CMD_RET_FAILURE;
 
+   if (type == LEGACY_LZMA)
+   return 0;
+
return do_spl_test_load(uts, test_name, type,
SPL_LOAD_IMAGE_GET(0, BOOT_DEVICE_MMC1,
   spl_mmc_load_image),
spl_test_mmc_write_image);
 }
 SPL_IMG_TEST(spl_test_mmc, LEGACY, DM_FLAGS);
+SPL_IMG_TEST(spl_test_mmc, LEGACY_LZMA, DM_FLAGS);
 SPL_IMG_TEST(spl_test_mmc, IMX8, DM_FLAGS);
 SPL_IMG_TEST(spl_test_mmc, FIT_EXTERNAL, DM_FLAGS);
 SPL_IMG_TEST(spl_test_mmc, FIT_INTERNAL, DM_FLAGS);
-- 
2.37.1



[PATCH v7 14/26] test: spl: Support testing LEGACY_LZMA filesystem images

2023-11-08 Thread Sean Anderson
These will soon be supported, so we need to be able to test it. Export the
lzma data and generally use the same process in spl_test_mmc_fs as
do_spl_test_load.  If we end up needing this in third place in the future,
it would probably be good to refactor things out.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v6)

Changes in v6:
- New

 include/test/spl.h   |  4 
 test/image/spl_load.c|  4 +++-
 test/image/spl_load_fs.c | 23 ++-
 3 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/include/test/spl.h b/include/test/spl.h
index c1f64658502..a2a5f33e328 100644
--- a/include/test/spl.h
+++ b/include/test/spl.h
@@ -81,6 +81,10 @@ size_t create_image(void *dst, enum spl_test_image type,
 int check_image_info(struct unit_test_state *uts, struct spl_image_info *info1,
 struct spl_image_info *info2);
 
+/* Some compressed data and it size */
+extern const char lzma_compressed[];
+extern const size_t lzma_compressed_size;
+
 /**
  * typedef write_image_t - Callback for writing an image
  * @uts: Current unit test state
diff --git a/test/image/spl_load.c b/test/image/spl_load.c
index 35ceed67756..e1036eff28c 100644
--- a/test/image/spl_load.c
+++ b/test/image/spl_load.c
@@ -374,7 +374,7 @@ SPL_IMG_TEST(spl_test_image, FIT_EXTERNAL, 0);
  * LZMA is too complex to generate on the fly, so let's use some data I put in
  * the oven^H^H^H^H compressed earlier
  */
-static const char lzma_compressed[] = {
+const char lzma_compressed[] = {
0x5d, 0x00, 0x00, 0x80, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x00, 0x02, 0x05, 0x55, 0x4e, 0x82, 0xbc, 0xc2, 0x42, 0xf6, 0x88,
0x6c, 0x99, 0xd6, 0x82, 0x48, 0xa6, 0x06, 0x67, 0xf8, 0x46, 0x7c, 0xe9,
@@ -610,6 +610,8 @@ static const char lzma_compressed[] = {
0x1e, 0xff, 0xff, 0x80, 0x8e, 0x00, 0x00
 };
 
+const size_t lzma_compressed_size = sizeof(lzma_compressed);
+
 int do_spl_test_load(struct unit_test_state *uts, const char *test_name,
 enum spl_test_image type, struct spl_image_loader *loader,
 int (*write_image)(struct unit_test_state *, void *, 
size_t))
diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c
index 297ab08a820..59d0244d44b 100644
--- a/test/image/spl_load_fs.c
+++ b/test/image/spl_load_fs.c
@@ -320,10 +320,11 @@ static int spl_test_mmc_fs(struct unit_test_state *uts, 
const char *test_name,
const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME;
struct blk_desc *dev_desc;
size_t fs_size, fs_data, img_size, img_data,
-  data_size = SPL_TEST_DATA_SIZE;
+  plain_size = SPL_TEST_DATA_SIZE;
struct spl_image_info info_write = {
.name = test_name,
-   .size = data_size,
+   .size = type == LEGACY_LZMA ? lzma_compressed_size :
+ plain_size,
}, info_read = { };
struct disk_partition part = {
.start = 1,
@@ -335,7 +336,7 @@ static int spl_test_mmc_fs(struct unit_test_state *uts, 
const char *test_name,
.boot_device = loader->boot_device,
};
void *fs;
-   char *data;
+   char *data, *plain;
 
img_size = create_image(NULL, type, _write, _data);
ut_assert(img_size);
@@ -345,7 +346,15 @@ static int spl_test_mmc_fs(struct unit_test_state *uts, 
const char *test_name,
ut_assertnonnull(fs);
 
data = fs + fs_data + img_data;
-   generate_data(data, data_size, test_name);
+   if (type == LEGACY_LZMA) {
+   plain = malloc(plain_size);
+   ut_assertnonnull(plain);
+   generate_data(plain, plain_size, "lzma");
+   memcpy(data, lzma_compressed, lzma_compressed_size);
+   } else {
+   plain = data;
+   generate_data(plain, plain_size, test_name);
+   }
ut_asserteq(img_size, create_image(fs + fs_data, type, _write,
   NULL));
ut_asserteq(fs_size, create_fs(fs, img_size, filename, NULL));
@@ -366,8 +375,12 @@ static int spl_test_mmc_fs(struct unit_test_state *uts, 
const char *test_name,
ut_assertok(loader->load_image(_read, ));
if (check_image_info(uts, _write, _read))
return CMD_RET_FAILURE;
-   ut_asserteq_mem(data, phys_to_virt(info_write.load_addr), data_size);
+   if (type == LEGACY_LZMA)
+   ut_asserteq(plain_size, info_read.size);
+   ut_asserteq_mem(plain, phys_to_virt(info_write.load_addr), plain_size);
 
+   if (type == LEGACY_LZMA)
+   free(plain);
free(fs);
return 0;
 }
-- 
2.37.1



[PATCH v7 10/26] spl: Remove filename from spl_load_info

2023-11-08 Thread Sean Anderson
For filesystems, filename serves the same purpose as priv. However,
spl_load_fit_image also uses it to determine whether to use a DMA-aligned
buffer. This is beneficial for FAT, which uses a bounce-buffer if the
destination is not DMA-aligned. However, this is unnecessary now that
filesystems set bl_len to ARCH_DMA_MINALIGN instead. With this done, we can
remove filename entirely.

Signed-off-by: Sean Anderson 
---

Changes in v7:
- Split off setting bl_len to ARCH_DMA_MINALIGN from filename removal

Changes in v6:
- New

 arch/arm/mach-sunxi/spl_spi_sunxi.c | 1 -
 common/spl/spl_blk_fs.c | 7 ---
 common/spl/spl_fat.c| 4 ++--
 common/spl/spl_mmc.c| 2 --
 common/spl/spl_nand.c   | 3 ---
 common/spl/spl_semihosting.c| 1 -
 common/spl/spl_spi.c| 2 --
 common/spl/spl_ymodem.c | 1 -
 include/spl.h   | 2 --
 test/image/spl_load_os.c| 1 -
 10 files changed, 6 insertions(+), 18 deletions(-)

diff --git a/arch/arm/mach-sunxi/spl_spi_sunxi.c 
b/arch/arm/mach-sunxi/spl_spi_sunxi.c
index 896aba69c32..5e7fba0c8e4 100644
--- a/arch/arm/mach-sunxi/spl_spi_sunxi.c
+++ b/arch/arm/mach-sunxi/spl_spi_sunxi.c
@@ -354,7 +354,6 @@ static int spl_spi_load_image(struct spl_image_info 
*spl_image,
struct spl_load_info load;
 
debug("Found FIT image\n");
-   load.filename = NULL;
load.bl_len = 1;
load.read = spi_load_read;
ret = spl_load_simple_fit(spl_image, ,
diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c
index c105c55877a..4975ce4d6ec 100644
--- a/common/spl/spl_blk_fs.c
+++ b/common/spl/spl_blk_fs.c
@@ -14,6 +14,7 @@
 
 struct blk_dev {
const char *ifname;
+   const char *filename;
char dev_part_str[8];
 };
 
@@ -31,11 +32,11 @@ static ulong spl_fit_read(struct spl_load_info *load, ulong 
file_offset,
return ret;
}
 
-   ret = fs_read(load->filename, virt_to_phys(buf), file_offset, size,
+   ret = fs_read(dev->filename, virt_to_phys(buf), file_offset, size,
  );
if (ret < 0) {
printf("spl: error reading image %s. Err - %d\n",
-  load->filename, ret);
+  dev->filename, ret);
return ret;
}
 
@@ -87,8 +88,8 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
debug("Found FIT\n");
load.read = spl_fit_read;
load.bl_len = ARCH_DMA_MINALIGN;
-   load.filename = (void *)filename;
load.priv = 
+   dev.filename = filename;
 
return spl_load_simple_fit(spl_image, , 0, header);
}
diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index 5b723456478..8a2c4e3af49 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -51,7 +51,7 @@ static ulong spl_fit_read(struct spl_load_info *load, ulong 
file_offset,
 {
loff_t actread;
int ret;
-   char *filename = (char *)load->filename;
+   char *filename = load->priv;
 
ret = fat_read_file(filename, buf, file_offset, size, );
if (ret)
@@ -98,7 +98,7 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
debug("Found FIT\n");
load.read = spl_fit_read;
load.bl_len = ARCH_DMA_MINALIGN;
-   load.filename = (void *)filename;
+   load.priv = (void *)filename;
 
return spl_load_simple_fit(spl_image, , 0, header);
} else {
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 9f41ea648ce..8c4ffe743d5 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -108,7 +108,6 @@ int mmc_load_image_raw_sector(struct spl_image_info 
*spl_image,
 
debug("Found FIT\n");
load.priv = bd;
-   load.filename = NULL;
load.bl_len = bd->blksz;
load.read = h_spl_load_read;
ret = spl_load_simple_fit(spl_image, ,
@@ -118,7 +117,6 @@ int mmc_load_image_raw_sector(struct spl_image_info 
*spl_image,
struct spl_load_info load;
 
load.priv = bd;
-   load.filename = NULL;
load.bl_len = bd->blksz;
load.read = h_spl_load_read;
 
diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index 1fcc89fa660..45d7c5f6cfb 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -90,7 +90,6 @@ static int spl_nand_load_element(struct spl_image_info 
*spl_image,
 
debug("Found FIT\n");
load.priv = 
-   load.filename = NULL;
load.bl_len = bl_len;
load.read = spl_nand_fit_read;
return spl_load_simple_fit(spl_image, , offset, header);
@@ -99,7 +98,6 @@ static int spl_nand_load_element(struct spl_image_info 

[PATCH v7 13/26] spl: legacy: Split off LZMA decompression into its own function

2023-11-08 Thread Sean Anderson
To allow for easier reuse of this functionality, split it off into its
own function.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v6)

Changes in v6:
- New

 common/spl/spl_legacy.c | 73 ++---
 include/spl.h   | 13 
 2 files changed, 52 insertions(+), 34 deletions(-)

diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c
index 75d9d822337..a561939b4f0 100644
--- a/common/spl/spl_legacy.c
+++ b/common/spl/spl_legacy.c
@@ -82,6 +82,43 @@ int spl_parse_legacy_header(struct spl_image_info *spl_image,
return 0;
 }
 
+int spl_load_legacy_lzma(struct spl_image_info *spl_image,
+struct spl_load_info *load, ulong offset)
+{
+   SizeT lzma_len = LZMA_LEN;
+   void *src;
+   ulong dataptr, overhead, size;
+   int ret;
+
+   /* dataptr points to compressed payload  */
+   dataptr = ALIGN_DOWN(sizeof(struct legacy_img_hdr),
+spl_get_bl_len(load));
+   overhead = sizeof(struct legacy_img_hdr) - dataptr;
+   size = ALIGN(spl_image->size + overhead, spl_get_bl_len(load));
+   dataptr += offset;
+
+   debug("LZMA: Decompressing %08lx to %08lx\n",
+ dataptr, spl_image->load_addr);
+   src = malloc(size);
+   if (!src) {
+   printf("Unable to allocate %d bytes for LZMA\n",
+  spl_image->size);
+   return -ENOMEM;
+   }
+
+   load->read(load, dataptr, size, src);
+   ret = lzmaBuffToBuffDecompress(map_sysmem(spl_image->load_addr,
+ spl_image->size), _len,
+  src + overhead, spl_image->size);
+   if (ret) {
+   printf("LZMA decompression error: %d\n", ret);
+   return ret;
+   }
+
+   spl_image->size = lzma_len;
+   return 0;
+}
+
 /*
  * This function is added explicitly to avoid code size increase, when
  * no compression method is enabled. The compiler will optimize the
@@ -101,8 +138,6 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
struct spl_load_info *load, ulong offset,
struct legacy_img_hdr *hdr)
 {
-   __maybe_unused SizeT lzma_len;
-   __maybe_unused void *src;
ulong dataptr;
int ret;
 
@@ -133,39 +168,9 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
   map_sysmem(spl_image->load_addr, spl_image->size));
break;
 
-   case IH_COMP_LZMA: {
-   ulong overhead, size;
+   case IH_COMP_LZMA:
+   return spl_load_legacy_lzma(spl_image, load, offset);
 
-   lzma_len = LZMA_LEN;
-
-   /* dataptr points to compressed payload  */
-   dataptr = ALIGN_DOWN(sizeof(*hdr), spl_get_bl_len(load));
-   overhead = sizeof(*hdr) - dataptr;
-   size = ALIGN(spl_image->size + overhead, spl_get_bl_len(load));
-   dataptr += offset;
-
-   debug("LZMA: Decompressing %08lx to %08lx\n",
- dataptr, spl_image->load_addr);
-   src = malloc(size);
-   if (!src) {
-   printf("Unable to allocate %d bytes for LZMA\n",
-  spl_image->size);
-   return -ENOMEM;
-   }
-
-   load->read(load, dataptr, size, src);
-   ret = lzmaBuffToBuffDecompress(map_sysmem(spl_image->load_addr,
- spl_image->size),
-  _len, src + overhead,
-  spl_image->size);
-   if (ret) {
-   printf("LZMA decompression error: %d\n", ret);
-   return ret;
-   }
-
-   spl_image->size = lzma_len;
-   break;
-   }
default:
debug("Compression method %s is not supported\n",
  genimg_get_comp_short_name(image_get_comp(hdr)));
diff --git a/include/spl.h b/include/spl.h
index 03c5c5c66b4..09521889014 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -407,6 +407,19 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 #define SPL_COPY_PAYLOAD_ONLY  1
 #define SPL_FIT_FOUND  2
 
+/**
+ * spl_load_legacy_lzma() - Load an LZMA-compressed legacy image
+ * @spl_image: Image description (already set up)
+ * @load:  Structure containing the information required to load data.
+ * @offset:Pointer to image
+ *
+ * Load/decompress an LZMA-compressed legacy image from the device.
+ *
+ * Return: 0 on success, or a negative error on failure
+ */
+int spl_load_legacy_lzma(struct spl_image_info *spl_image,
+struct spl_load_info *load, ulong offset);
+
 /**
  * spl_load_legacy_img() - Loads a legacy image 

[PATCH v7 11/26] spl: Only support bl_len when we have to

2023-11-08 Thread Sean Anderson
Aligning addresses and sizes causes overhead which is unnecessary when we
are not loading from block devices. Remove bl_len when it is not needed.

For example, on iot2050 we save 144 bytes with this patch (once the rest of
this series is applied):

add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-144 (-144)
Function old new   delta
spl_load_simple_fit  920 904 -16
load_simple_fit  496 444 -52
spl_spi_load_image   384 308 -76
Total: Before=87431, After=87287, chg -0.16%

We use panic() instead of BUILD_BUG_ON in spl_set_bl_len because we still
need to be able to compile it for things like mmc_load_image_raw_sector,
even if that function will not be used.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v6)

Changes in v6:
- New

 arch/arm/mach-imx/spl_imx_romapi.c  |  8 
 arch/arm/mach-sunxi/spl_spi_sunxi.c |  2 +-
 common/spl/Kconfig  | 14 +-
 common/spl/spl_blk_fs.c |  2 +-
 common/spl/spl_fat.c|  2 +-
 common/spl/spl_fit.c|  6 +++---
 common/spl/spl_imx_container.c  | 10 +-
 common/spl/spl_legacy.c |  4 ++--
 common/spl/spl_mmc.c|  4 ++--
 common/spl/spl_nand.c   |  6 +++---
 common/spl/spl_net.c|  2 +-
 common/spl/spl_nor.c|  8 
 common/spl/spl_ram.c|  2 +-
 common/spl/spl_semihosting.c|  2 +-
 common/spl/spl_spi.c|  4 ++--
 common/spl/spl_ymodem.c |  2 +-
 drivers/usb/gadget/f_sdp.c  |  4 ++--
 include/spl.h   | 25 +
 test/image/Kconfig  |  1 +
 test/image/spl_load.c   |  9 -
 test/image/spl_load_os.c|  2 +-
 21 files changed, 78 insertions(+), 41 deletions(-)

diff --git a/arch/arm/mach-imx/spl_imx_romapi.c 
b/arch/arm/mach-imx/spl_imx_romapi.c
index d7f6cb4b5ba..9f0968cdf71 100644
--- a/arch/arm/mach-imx/spl_imx_romapi.c
+++ b/arch/arm/mach-imx/spl_imx_romapi.c
@@ -101,7 +101,7 @@ static int spl_romapi_load_image_seekable(struct 
spl_image_info *spl_image,
struct spl_load_info load;
 
memset(, 0, sizeof(load));
-   load.bl_len = pagesize;
+   spl_set_bl_len(, pagesize);
load.read = spl_romapi_read_seekable;
return spl_load_simple_fit(spl_image, , offset, header);
} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
@@ -109,7 +109,7 @@ static int spl_romapi_load_image_seekable(struct 
spl_image_info *spl_image,
struct spl_load_info load;
 
memset(, 0, sizeof(load));
-   load.bl_len = pagesize;
+   spl_set_bl_len(, pagesize);
load.read = spl_romapi_read_seekable;
 
ret = spl_load_imx_container(spl_image, , offset);
@@ -334,7 +334,7 @@ static int spl_romapi_load_image_stream(struct 
spl_image_info *spl_image,
ss.pagesize = pagesize;
 
memset(, 0, sizeof(load));
-   load.bl_len = 1;
+   spl_set_bl_len(, 1);
load.read = spl_romapi_read_stream;
load.priv = 
 
@@ -358,7 +358,7 @@ static int spl_romapi_load_image_stream(struct 
spl_image_info *spl_image,
printf("ROM download failure %d\n", imagesize);
 
memset(, 0, sizeof(load));
-   load.bl_len = 1;
+   spl_set_bl_len(, 1);
load.read = spl_ram_load_read;
 
if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER))
diff --git a/arch/arm/mach-sunxi/spl_spi_sunxi.c 
b/arch/arm/mach-sunxi/spl_spi_sunxi.c
index 5e7fba0c8e4..267cb0b1aba 100644
--- a/arch/arm/mach-sunxi/spl_spi_sunxi.c
+++ b/arch/arm/mach-sunxi/spl_spi_sunxi.c
@@ -354,7 +354,7 @@ static int spl_spi_load_image(struct spl_image_info 
*spl_image,
struct spl_load_info load;
 
debug("Found FIT image\n");
-   load.bl_len = 1;
+   spl_set_bl_len(, 1);
load.read = spi_load_read;
ret = spl_load_simple_fit(spl_image, ,
  load_offset, header);
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index e929f1bbae1..0bc57d5fedb 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -280,8 +280,15 @@ config SPL_BOARD_INIT
  spl_board_init() from board_init_r(). This function should be
  provided by the board.
 
+config SPL_LOAD_BLOCK
+   bool
+   help
+ Support loading images from block devices. This adds a bl_len member
+ to struct spl_load_info.
+
 config SPL_BOOTROM_SUPPORT
bool "Support returning to the BOOTROM"
+   select SPL_LOAD_BLOCK if MACH_IMX
help
  Some platforms (e.g. the Rockchip RK3368) provide support in their

[PATCH v7 12/26] spl: nand: Remove spl_nand_legacy_read

2023-11-08 Thread Sean Anderson
Now that spl_nand_fit_read works in units of bytes, it can be combined with
spl_nand_legacy_read. Rename the resulting function spl_nand_read, since it
is no longer FIT-specific.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v6)

Changes in v6:
- New

 common/spl/spl_nand.c | 33 +
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index 281211b7f24..91fa7674f17 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -42,29 +42,22 @@ static int spl_nand_load_image(struct spl_image_info 
*spl_image,
 }
 #else
 
-static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs,
-  ulong size, void *dst)
+__weak u32 nand_spl_adjust_offset(u32 sector, u32 offs)
+{
+   return offs;
+}
+
+static ulong spl_nand_read(struct spl_load_info *load, ulong offs, ulong size,
+  void *dst)
 {
int err;
ulong sector;
 
-   sector = *(int *)load->priv;
-   offs = sector + nand_spl_adjust_offset(sector, offs - sector);
-   err = nand_spl_load_image(offs, size, dst);
-   if (err)
-   return 0;
-
-   return size;
-}
-
-static ulong spl_nand_legacy_read(struct spl_load_info *load, ulong offs,
- ulong size, void *dst)
-{
-   int err;
-
debug("%s: offs %lx, size %lx, dst %p\n",
  __func__, offs, size, dst);
 
+   sector = *(int *)load->priv;
+   offs = sector + nand_spl_adjust_offset(sector, offs - sector);
err = nand_spl_load_image(offs, size, dst);
if (err)
return 0;
@@ -91,7 +84,7 @@ static int spl_nand_load_element(struct spl_image_info 
*spl_image,
debug("Found FIT\n");
load.priv = 
spl_set_bl_len(, bl_len);
-   load.read = spl_nand_fit_read;
+   load.read = spl_nand_read;
return spl_load_simple_fit(spl_image, , offset, header);
} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
   valid_container_hdr((void *)header)) {
@@ -99,16 +92,16 @@ static int spl_nand_load_element(struct spl_image_info 
*spl_image,
 
load.priv = 
spl_set_bl_len(, bl_len);
-   load.read = spl_nand_fit_read;
+   load.read = spl_nand_read;
return spl_load_imx_container(spl_image, , offset);
} else if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT) &&
   image_get_magic(header) == IH_MAGIC) {
struct spl_load_info load;
 
debug("Found legacy image\n");
+   load.priv = 
spl_set_bl_len(, IS_ENABLED(CONFIG_SPL_LZMA) ? bl_len : 1);
-   load.read = spl_nand_legacy_read;
-
+   load.read = spl_nand_read;
return spl_load_legacy_img(spl_image, bootdev, , offset, 
header);
} else {
err = spl_parse_image_header(spl_image, bootdev, header);
-- 
2.37.1



[PATCH v7 08/26] spl: Refactor spl_load_info->read to use units of bytes

2023-11-08 Thread Sean Anderson
Simplify things a bit for callers of spl_load_info->read by refactoring it
to use units of bytes instead of bl_len. This generally simplifies the
logic, as MMC is the only loader which actually works in sectors. It will
also allow further refactoring to remove the special-case handling of
filename.  spl_load_legacy_img already works in units of bytes (oops) so it
doesn't need to be changed.

Signed-off-by: Sean Anderson 
---

Changes in v7:
- Reword documentation for spl_load_info

Changes in v6:
- New

 arch/arm/mach-imx/spl_imx_romapi.c | 16 +++---
 common/spl/spl_fit.c   | 51 +++---
 common/spl/spl_imx_container.c | 45 +++---
 common/spl/spl_mmc.c   | 24 --
 common/spl/spl_nand.c  |  8 ++---
 include/spl.h  | 18 +++
 test/image/spl_load_os.c   | 13 
 7 files changed, 82 insertions(+), 93 deletions(-)

diff --git a/arch/arm/mach-imx/spl_imx_romapi.c 
b/arch/arm/mach-imx/spl_imx_romapi.c
index 93d48e56aca..d7f6cb4b5ba 100644
--- a/arch/arm/mach-imx/spl_imx_romapi.c
+++ b/arch/arm/mach-imx/spl_imx_romapi.c
@@ -53,16 +53,10 @@ static int is_boot_from_stream_device(u32 boot)
 }
 
 static ulong spl_romapi_read_seekable(struct spl_load_info *load,
- ulong sector, ulong count,
+ ulong offset, ulong byte,
  void *buf)
 {
-   u32 pagesize = *(u32 *)load->priv;
-   ulong byte = count * pagesize;
-   u32 offset;
-
-   offset = sector * pagesize;
-
-   return spl_romapi_raw_seekable_read(offset, byte, buf) / pagesize;
+   return spl_romapi_raw_seekable_read(offset, byte, buf);
 }
 
 static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image,
@@ -109,8 +103,7 @@ static int spl_romapi_load_image_seekable(struct 
spl_image_info *spl_image,
memset(, 0, sizeof(load));
load.bl_len = pagesize;
load.read = spl_romapi_read_seekable;
-   load.priv = 
-   return spl_load_simple_fit(spl_image, , offset / pagesize, 
header);
+   return spl_load_simple_fit(spl_image, , offset, header);
} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
   valid_container_hdr((void *)header)) {
struct spl_load_info load;
@@ -118,9 +111,8 @@ static int spl_romapi_load_image_seekable(struct 
spl_image_info *spl_image,
memset(, 0, sizeof(load));
load.bl_len = pagesize;
load.read = spl_romapi_read_seekable;
-   load.priv = 
 
-   ret = spl_load_imx_container(spl_image, , offset / 
pagesize);
+   ret = spl_load_imx_container(spl_image, , offset);
} else {
/* TODO */
puts("Can't support legacy image\n");
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 6084ead0919..ce7ef0efd0d 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -180,7 +180,7 @@ static int get_aligned_image_offset(struct spl_load_info 
*info, int offset)
if (info->filename)
return offset & ~(ARCH_DMA_MINALIGN - 1);
 
-   return offset / info->bl_len;
+   return ALIGN_DOWN(offset, info->bl_len);
 }
 
 static int get_aligned_image_overhead(struct spl_load_info *info, int offset)
@@ -205,7 +205,7 @@ static int get_aligned_image_size(struct spl_load_info 
*info, int data_size,
if (info->filename)
return data_size;
 
-   return (data_size + info->bl_len - 1) / info->bl_len;
+   return ALIGN(data_size, info->bl_len);
 }
 
 /**
@@ -222,7 +222,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 load_simple_fit(struct spl_load_info *info, ulong sector,
+static int load_simple_fit(struct spl_load_info *info, ulong fit_offset,
   const struct spl_fit_info *ctx, int node,
   struct spl_image_info *image_info)
 {
@@ -234,7 +234,6 @@ static int load_simple_fit(struct spl_load_info *info, 
ulong sector,
void *load_ptr;
void *src;
ulong overhead;
-   int nr_sectors;
uint8_t image_comp = -1, type = -1;
const void *data;
const void *fit = ctx->fit;
@@ -291,11 +290,12 @@ static int load_simple_fit(struct spl_load_info *info, 
ulong sector,
length = len;
 
overhead = get_aligned_image_overhead(info, offset);
-   nr_sectors = get_aligned_image_size(info, length, offset);
+   size = get_aligned_image_size(info, length, offset);
 
if (info->read(info,
-  sector + get_aligned_image_offset(info, offset),
-  nr_sectors, src_ptr) != nr_sectors)
+   

[PATCH v7 09/26] spl: Set FAT bl_len to ARCH_DMA_MINALIGN

2023-11-08 Thread Sean Anderson
Instead of relying on the presence of filename to determine whether we are
dealing with a FAT filesystem (and should DMA-align the buffer), have FAT set
bl_len to ARCH_DMA_MINALIGN instead. With this done, we can remove the
special-case logic checking for the presence of filename.

Because filesystems are not block-based, we may read less than the size passed
to spl_load_info.read. This can happen if the file size is not DMA-aligned. This
is fine as long as we read the amount we originally wanted to. Modify the
conditions for callers of spl_load_info.read to check against the original,
unaligned size to avoid failing spuriously.

Signed-off-by: Sean Anderson 
---

Changes in v7:
- Split off from the removal of filename

 common/spl/spl_blk_fs.c|  3 ++-
 common/spl/spl_fat.c   |  2 +-
 common/spl/spl_fit.c   | 23 +--
 common/spl/spl_imx_container.c |  8 +---
 4 files changed, 9 insertions(+), 27 deletions(-)

diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c
index 144c8a65b5d..c105c55877a 100644
--- a/common/spl/spl_blk_fs.c
+++ b/common/spl/spl_blk_fs.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 struct blk_dev {
@@ -85,7 +86,7 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
 
debug("Found FIT\n");
load.read = spl_fit_read;
-   load.bl_len = 1;
+   load.bl_len = ARCH_DMA_MINALIGN;
load.filename = (void *)filename;
load.priv = 
 
diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index 6172e7bcd48..5b723456478 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -97,7 +97,7 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
 
debug("Found FIT\n");
load.read = spl_fit_read;
-   load.bl_len = 1;
+   load.bl_len = ARCH_DMA_MINALIGN;
load.filename = (void *)filename;
 
return spl_load_simple_fit(spl_image, , 0, header);
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index ce7ef0efd0d..0df4e6d1484 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -14,7 +14,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -172,28 +171,11 @@ static int spl_fit_get_image_node(const struct 
spl_fit_info *ctx,
 
 static int get_aligned_image_offset(struct spl_load_info *info, int offset)
 {
-   /*
-* If it is a FS read, get the first address before offset which is
-* aligned to ARCH_DMA_MINALIGN. If it is raw read return the
-* block number to which offset belongs.
-*/
-   if (info->filename)
-   return offset & ~(ARCH_DMA_MINALIGN - 1);
-
return ALIGN_DOWN(offset, info->bl_len);
 }
 
 static int get_aligned_image_overhead(struct spl_load_info *info, int offset)
 {
-   /*
-* If it is a FS read, get the difference between the offset and
-* the first address before offset which is aligned to
-* ARCH_DMA_MINALIGN. If it is raw read return the offset within the
-* block.
-*/
-   if (info->filename)
-   return offset & (ARCH_DMA_MINALIGN - 1);
-
return offset & (info->bl_len - 1);
 }
 
@@ -202,9 +184,6 @@ static int get_aligned_image_size(struct spl_load_info 
*info, int data_size,
 {
data_size = data_size + get_aligned_image_overhead(info, offset);
 
-   if (info->filename)
-   return data_size;
-
return ALIGN(data_size, info->bl_len);
 }
 
@@ -295,7 +274,7 @@ static int load_simple_fit(struct spl_load_info *info, 
ulong fit_offset,
if (info->read(info,
   fit_offset +
   get_aligned_image_offset(info, offset), size,
-  src_ptr) != size)
+  src_ptr) < length)
return -EIO;
 
debug("External data: dst=%p, offset=%x, size=%lx\n",
diff --git a/common/spl/spl_imx_container.c b/common/spl/spl_imx_container.c
index ad89a99fb23..7cd674f835f 100644
--- a/common/spl/spl_imx_container.c
+++ b/common/spl/spl_imx_container.c
@@ -45,7 +45,8 @@ static struct boot_img_t *read_auth_image(struct 
spl_image_info *spl_image,
  container, offset, size);
if (info->read(info, offset, size,
   map_sysmem(images[image_index].dst - overhead,
- images[image_index].size)) != size) {
+ images[image_index].size)) <
+   images[image_index].size) {
printf("%s wrong\n", __func__);
return NULL;
}
@@ -77,7 +78,8 @@ static int read_auth_container(struct spl_image_info 
*spl_image,
 
debug("%s: container: %p offset: %lu size: %u\n", __func__,
  container, offset, size);
-   if (info->read(info, offset, size, container) 

[PATCH v7 07/26] spl: Take advantage of bl_len's power-of-twoness

2023-11-08 Thread Sean Anderson
bl_len must be a power of two, so we can use ALIGN instead of roundup and
similar tricks to avoid divisions.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v6)

Changes in v6:
- New

 common/spl/spl_fit.c   | 2 +-
 common/spl/spl_imx_container.c | 8 
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 70d8d5942d9..6084ead0919 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -194,7 +194,7 @@ static int get_aligned_image_overhead(struct spl_load_info 
*info, int offset)
if (info->filename)
return offset & (ARCH_DMA_MINALIGN - 1);
 
-   return offset % info->bl_len;
+   return offset & (info->bl_len - 1);
 }
 
 static int get_aligned_image_size(struct spl_load_info *info, int data_size,
diff --git a/common/spl/spl_imx_container.c b/common/spl/spl_imx_container.c
index 127802f5cb7..1cc51782766 100644
--- a/common/spl/spl_imx_container.c
+++ b/common/spl/spl_imx_container.c
@@ -33,13 +33,13 @@ static struct boot_img_t *read_auth_image(struct 
spl_image_info *spl_image,
images = (struct boot_img_t *)((u8 *)container +
   sizeof(struct container_hdr));
 
-   if (images[image_index].offset % info->bl_len) {
+   if (!IS_ALIGNED(images[image_index].offset, info->bl_len)) {
printf("%s: image%d offset not aligned to %u\n",
   __func__, image_index, info->bl_len);
return NULL;
}
 
-   sectors = roundup(images[image_index].size, info->bl_len) /
+   sectors = ALIGN(images[image_index].size, info->bl_len) /
info->bl_len;
sector = images[image_index].offset / info->bl_len +
container_sector;
@@ -69,7 +69,7 @@ static int read_auth_container(struct spl_image_info 
*spl_image,
u32 sectors;
int i, size, ret = 0;
 
-   size = roundup(CONTAINER_HDR_ALIGNMENT, info->bl_len);
+   size = ALIGN(CONTAINER_HDR_ALIGNMENT, info->bl_len);
sectors = size / info->bl_len;
 
/*
@@ -103,7 +103,7 @@ static int read_auth_container(struct spl_image_info 
*spl_image,
debug("Container length %u\n", length);
 
if (length > CONTAINER_HDR_ALIGNMENT) {
-   size = roundup(length, info->bl_len);
+   size = ALIGN(length, info->bl_len);
sectors = size / info->bl_len;
 
free(container);
-- 
2.37.1



[PATCH v7 06/26] spl: Remove dev from spl_load_info

2023-11-08 Thread Sean Anderson
dev and priv serve the same purpose, and are never set at the same time.
Remove dev and convert all users to priv. While we're at it, reorder bl_len
to be last for better alignment.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

Changes in v7:
- Fix typo in commit message

Changes in v6:
- New

 common/spl/spl_mmc.c   | 6 +++---
 common/spl/spl_spi.c   | 6 +++---
 drivers/usb/gadget/f_sdp.c | 6 +++---
 include/spl.h  | 4 +---
 4 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 6d9137c32e0..3d7551a7dae 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -65,7 +65,7 @@ static int mmc_load_legacy(struct spl_image_info *spl_image,
 static ulong h_spl_load_read(struct spl_load_info *load, ulong sector,
 ulong count, void *buf)
 {
-   struct mmc *mmc = load->dev;
+   struct mmc *mmc = load->priv;
 
return blk_dread(mmc_get_blk_desc(mmc), sector, count, buf);
 }
@@ -105,7 +105,7 @@ int mmc_load_image_raw_sector(struct spl_image_info 
*spl_image,
struct spl_load_info load;
 
debug("Found FIT\n");
-   load.dev = mmc;
+   load.priv = mmc;
load.filename = NULL;
load.bl_len = mmc->read_bl_len;
load.read = h_spl_load_read;
@@ -114,7 +114,7 @@ int mmc_load_image_raw_sector(struct spl_image_info 
*spl_image,
   valid_container_hdr((void *)header)) {
struct spl_load_info load;
 
-   load.dev = mmc;
+   load.priv = mmc;
load.filename = NULL;
load.bl_len = mmc->read_bl_len;
load.read = h_spl_load_read;
diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index d83d70f2f33..af7a28e7c25 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -59,7 +59,7 @@ static int spi_load_image_os(struct spl_image_info *spl_image,
 static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector,
  ulong count, void *buf)
 {
-   struct spi_flash *flash = load->dev;
+   struct spi_flash *flash = load->priv;
ulong ret;
 
ret = spi_flash_read(flash, sector, count, buf);
@@ -151,7 +151,7 @@ static int spl_spi_load_image(struct spl_image_info 
*spl_image,
struct spl_load_info load;
 
debug("Found FIT\n");
-   load.dev = flash;
+   load.priv = flash;
load.filename = NULL;
load.bl_len = 1;
load.read = spl_spi_fit_read;
@@ -162,7 +162,7 @@ static int spl_spi_load_image(struct spl_image_info 
*spl_image,
   valid_container_hdr((void *)header)) {
struct spl_load_info load;
 
-   load.dev = flash;
+   load.priv = flash;
load.filename = NULL;
load.bl_len = 1;
load.read = spl_spi_fit_read;
diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
index ee9384fb37e..1b16b7eb452 100644
--- a/drivers/usb/gadget/f_sdp.c
+++ b/drivers/usb/gadget/f_sdp.c
@@ -744,7 +744,7 @@ static ulong sdp_load_read(struct spl_load_info *load, 
ulong sector,
 {
debug("%s: sector %lx, count %lx, buf %lx\n",
  __func__, sector, count, (ulong)buf);
-   memcpy(buf, (void *)(load->dev + sector), count);
+   memcpy(buf, (void *)(load->priv + sector), count);
return count;
 }
 
@@ -844,7 +844,7 @@ static int sdp_handle_in_ep(struct spl_image_info 
*spl_image,
struct spl_load_info load;
 
debug("Found FIT\n");
-   load.dev = header;
+   load.priv = header;
load.bl_len = 1;
load.read = sdp_load_read;
spl_load_simple_fit(spl_image, , 0,
@@ -857,7 +857,7 @@ static int sdp_handle_in_ep(struct spl_image_info 
*spl_image,
valid_container_hdr((void *)header)) {
struct spl_load_info load;
 
-   load.dev = header;
+   load.priv = header;
load.bl_len = 1;
load.read = sdp_load_read;
spl_load_imx_container(spl_image, , 0);
diff --git a/include/spl.h b/include/spl.h
index 8ff20adc28e..951e136b9ea 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -285,16 +285,13 @@ static inline void *spl_image_fdt_addr(struct 
spl_image_info *info)
 /**
  * Information required to load data from a device
  *
- * @dev: Pointer to the device, e.g. struct mmc *
  * @priv: Private data for the device
  * 

[PATCH v7 05/26] spl: Remove NULL assignments in spl_load_info

2023-11-08 Thread Sean Anderson
Remove NULL assignments to fields in spl_load_info when .load doesn't
reference these fields. This can result in more efficient code. filename
must stay even if it is unused, since load_simple_fit uses it.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v6)

Changes in v6:
- New

 arch/arm/mach-sunxi/spl_spi_sunxi.c | 2 --
 common/spl/spl_fat.c| 1 -
 common/spl/spl_mmc.c| 2 --
 common/spl/spl_nand.c   | 4 
 common/spl/spl_spi.c| 2 --
 common/spl/spl_ymodem.c | 1 -
 6 files changed, 12 deletions(-)

diff --git a/arch/arm/mach-sunxi/spl_spi_sunxi.c 
b/arch/arm/mach-sunxi/spl_spi_sunxi.c
index c2410dd7bb1..896aba69c32 100644
--- a/arch/arm/mach-sunxi/spl_spi_sunxi.c
+++ b/arch/arm/mach-sunxi/spl_spi_sunxi.c
@@ -354,8 +354,6 @@ static int spl_spi_load_image(struct spl_image_info 
*spl_image,
struct spl_load_info load;
 
debug("Found FIT image\n");
-   load.dev = NULL;
-   load.priv = NULL;
load.filename = NULL;
load.bl_len = 1;
load.read = spi_load_read;
diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index 014074f85be..6172e7bcd48 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -99,7 +99,6 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
load.read = spl_fit_read;
load.bl_len = 1;
load.filename = (void *)filename;
-   load.priv = NULL;
 
return spl_load_simple_fit(spl_image, , 0, header);
} else {
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 82689da1401..6d9137c32e0 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -106,7 +106,6 @@ int mmc_load_image_raw_sector(struct spl_image_info 
*spl_image,
 
debug("Found FIT\n");
load.dev = mmc;
-   load.priv = NULL;
load.filename = NULL;
load.bl_len = mmc->read_bl_len;
load.read = h_spl_load_read;
@@ -116,7 +115,6 @@ int mmc_load_image_raw_sector(struct spl_image_info 
*spl_image,
struct spl_load_info load;
 
load.dev = mmc;
-   load.priv = NULL;
load.filename = NULL;
load.bl_len = mmc->read_bl_len;
load.read = h_spl_load_read;
diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index b8cd6403ba4..9a5a5ffa04a 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -91,7 +91,6 @@ static int spl_nand_load_element(struct spl_image_info 
*spl_image,
struct spl_load_info load;
 
debug("Found FIT\n");
-   load.dev = NULL;
load.priv = 
load.filename = NULL;
load.bl_len = bl_len;
@@ -101,7 +100,6 @@ static int spl_nand_load_element(struct spl_image_info 
*spl_image,
   valid_container_hdr((void *)header)) {
struct spl_load_info load;
 
-   load.dev = NULL;
load.priv = 
load.filename = NULL;
load.bl_len = bl_len;
@@ -112,8 +110,6 @@ static int spl_nand_load_element(struct spl_image_info 
*spl_image,
struct spl_load_info load;
 
debug("Found legacy image\n");
-   load.dev = NULL;
-   load.priv = NULL;
load.filename = NULL;
load.bl_len = IS_ENABLED(CONFIG_SPL_LZMA) ? bl_len : 1;
load.read = spl_nand_legacy_read;
diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index 3ac4b1b5091..d83d70f2f33 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -152,7 +152,6 @@ static int spl_spi_load_image(struct spl_image_info 
*spl_image,
 
debug("Found FIT\n");
load.dev = flash;
-   load.priv = NULL;
load.filename = NULL;
load.bl_len = 1;
load.read = spl_spi_fit_read;
@@ -164,7 +163,6 @@ static int spl_spi_load_image(struct spl_image_info 
*spl_image,
struct spl_load_info load;
 
load.dev = flash;
-   load.priv = NULL;
load.filename = NULL;
load.bl_len = 1;
load.read = spl_spi_fit_read;
diff --git a/common/spl/spl_ymodem.c b/common/spl/spl_ymodem.c
index 038b4438457..8616cb3e915 100644
--- a/common/spl/spl_ymodem.c
+++ b/common/spl/spl_ymodem.c
@@ -134,7 +134,6 @@ int spl_ymodem_load_image(struct spl_image_info *spl_image,
struct ymodem_fit_info info;
 
debug("Found FIT\n");
-   load.dev = NULL;
load.priv = (void *)
load.filename = NULL;
load.bl_len = 1;
-- 
2.37.1



[PATCH v7 04/26] spl: semihosting: Don't close fd before spl_load_simple_fit

2023-11-08 Thread Sean Anderson
On real hardware, semihosting calls tend to have a large constant
overhead (on the order of tens of milliseconds). Reduce the number of
calls by one by reusing the existing fd in smh_fit_read, and closing it
at the end of spl_smh_load_image.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

Changes in v7:
- Fix typo in commit message

Changes in v6:
- New

 common/spl/spl_semihosting.c | 20 
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/common/spl/spl_semihosting.c b/common/spl/spl_semihosting.c
index f7dd289286d..8f11c29913f 100644
--- a/common/spl/spl_semihosting.c
+++ b/common/spl/spl_semihosting.c
@@ -24,18 +24,14 @@ static int smh_read_full(long fd, void *memp, size_t len)
 static ulong smh_fit_read(struct spl_load_info *load, ulong file_offset,
  ulong size, void *buf)
 {
-   long fd;
+   long fd = *(long *)load->priv;
ulong ret;
 
-   fd = smh_open(load->filename, MODE_READ | MODE_BINARY);
-   if (fd < 0) {
-   log_debug("could not open %s: %ld\n", load->filename, fd);
+   if (smh_seek(fd, file_offset))
return 0;
-   }
+
ret = smh_read(fd, buf, size);
-   smh_close(fd);
-
-   return ret;
+   return ret < 0 ? 0 : ret;
 }
 
 static int spl_smh_load_image(struct spl_image_info *spl_image,
@@ -73,11 +69,11 @@ static int spl_smh_load_image(struct spl_image_info 
*spl_image,
debug("Found FIT\n");
load.read = smh_fit_read;
load.bl_len = 1;
-   load.filename = filename;
-   load.priv = NULL;
-   smh_close(fd);
+   load.filename = NULL;
+   load.priv = 
 
-   return spl_load_simple_fit(spl_image, , 0, header);
+   ret = spl_load_simple_fit(spl_image, , 0, header);
+   goto out;
}
 
ret = spl_parse_image_header(spl_image, bootdev, header);
-- 
2.37.1



[PATCH v7 03/26] spl: Make SHOW_ERRORS depend on LIBCOMMON

2023-11-08 Thread Sean Anderson
The purpose of SHOW_ERRORS is to print extra information. Make it depend
on LIBCOMMON to avoid having to check for two configs.

Signed-off-by: Sean Anderson 
Reviewed-by: Tom Rini 
Reviewed-by: Simon Glass 
---

(no changes since v5)

Changes in v5:
- New

 common/spl/Kconfig | 1 +
 common/spl/spl.c   | 3 +--
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 00332cf243a..e929f1bbae1 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -183,6 +183,7 @@ config SPL_SYS_REPORT_STACK_F_USAGE
 
 config SPL_SHOW_ERRORS
bool "Show more information when something goes wrong"
+   depends on SPL_LIBCOMMON_SUPPORT
help
  This enabled more verbose error messages and checking when something
  goes wrong in SPL. For example, it shows the error code when U-Boot
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 732d90d39e6..7ce38ce46d4 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -718,8 +718,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
ret = boot_from_devices(_image, spl_boot_list,
ARRAY_SIZE(spl_boot_list));
if (ret) {
-   if (CONFIG_IS_ENABLED(SHOW_ERRORS) &&
-   CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT))
+   if (CONFIG_IS_ENABLED(SHOW_ERRORS))
printf(SPL_TPL_PROMPT "failed to boot from all boot 
devices (err=%d)\n",
   ret);
else
-- 
2.37.1



[PATCH v7 02/26] arm: Disable SPL_FS_FAT when it isn't used

2023-11-08 Thread Sean Anderson
Several boards enable SPL_FS_FAT and SPL_LIBDISK_SUPPORT when they can't be
used (as there is no block device support enabled). Disable these configs.
The list of boards was generated with the following command:

$ tools/qconfig.py -f SPL SPL_FS_FAT ~SPL_MMC ~SPL_BLK_FS ~SPL_SATA \
  ~SPL_USB_STORAGE ~ENV_IS_IN_FAT ~EFI

LIBDISK was left enabled for the am* boards, since it seems to result in
actual size reduction, indicating that partitions are being used for
something.

Signed-off-by: Sean Anderson 
---

Changes in v7:
- Disable FS_FAT for the zynq(mp) boards as well, as suggested by Michal

Changes in v6:
- New

 configs/am335x_evm_spiboot_defconfig  | 2 +-
 configs/am65x_evm_r5_usbdfu_defconfig | 1 -
 configs/xilinx_zynqmp_mini_qspi_defconfig | 3 ++-
 configs/zynq_cse_nand_defconfig   | 2 ++
 configs/zynq_cse_nor_defconfig| 2 ++
 configs/zynq_cse_qspi_defconfig   | 2 ++
 6 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/configs/am335x_evm_spiboot_defconfig 
b/configs/am335x_evm_spiboot_defconfig
index b5b11fb62c8..fff5265e56a 100644
--- a/configs/am335x_evm_spiboot_defconfig
+++ b/configs/am335x_evm_spiboot_defconfig
@@ -13,6 +13,7 @@ CONFIG_CLOCK_SYNTHESIZER=y
 # CONFIG_OF_LIBFDT_OVERLAY is not set
 # CONFIG_SPL_MMC is not set
 CONFIG_SPL=y
+# CONFIG_SPL_FS_FAT is not set
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_TIMESTAMP=y
@@ -27,7 +28,6 @@ CONFIG_SPL_SYS_MALLOC=y
 CONFIG_SPL_SYS_MALLOC_SIZE=0x80
 CONFIG_SPL_FIT_IMAGE_TINY=y
 # CONFIG_SPL_FS_EXT4 is not set
-CONFIG_SPL_FS_LOAD_PAYLOAD_NAME="u-boot.img"
 CONFIG_SPL_MTD=y
 # CONFIG_SPL_NAND_SUPPORT is not set
 CONFIG_SPL_DM_SPI_FLASH=y
diff --git a/configs/am65x_evm_r5_usbdfu_defconfig 
b/configs/am65x_evm_r5_usbdfu_defconfig
index f610b2dd94e..6b0bb120d10 100644
--- a/configs/am65x_evm_r5_usbdfu_defconfig
+++ b/configs/am65x_evm_r5_usbdfu_defconfig
@@ -21,7 +21,6 @@ CONFIG_SPL_DRIVERS_MISC=y
 CONFIG_SPL_STACK_R_ADDR=0x8200
 CONFIG_SPL_SIZE_LIMIT=0x7ec00
 CONFIG_SPL_SIZE_LIMIT_PROVIDE_STACK=0x2000
-CONFIG_SPL_FS_FAT=y
 CONFIG_SPL_LIBDISK_SUPPORT=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SPL_LOAD_FIT=y
diff --git a/configs/xilinx_zynqmp_mini_qspi_defconfig 
b/configs/xilinx_zynqmp_mini_qspi_defconfig
index a1adfb9e5d1..b044743474d 100644
--- a/configs/xilinx_zynqmp_mini_qspi_defconfig
+++ b/configs/xilinx_zynqmp_mini_qspi_defconfig
@@ -11,6 +11,8 @@ CONFIG_ENV_SIZE=0x80
 CONFIG_DEFAULT_DEVICE_TREE="zynqmp-mini-qspi"
 CONFIG_SPL_STACK=0xfffc
 CONFIG_SPL=y
+# CONFIG_SPL_FS_FAT is not set
+# CONFIG_SPL_LIBDISK_SUPPORT is not set
 CONFIG_SYS_MEM_RSVD_FOR_MMU=y
 CONFIG_ZYNQMP_NO_DDR=y
 # CONFIG_PSCI_RESET is not set
@@ -89,7 +91,6 @@ CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_ARM_DCC=y
 CONFIG_SPI=y
 CONFIG_ZYNQMP_GQSPI=y
-# CONFIG_FAT_WRITE is not set
 CONFIG_PANIC_HANG=y
 # CONFIG_GZIP is not set
 # CONFIG_LMB is not set
diff --git a/configs/zynq_cse_nand_defconfig b/configs/zynq_cse_nand_defconfig
index 19f653f40d0..2eb45e1242e 100644
--- a/configs/zynq_cse_nand_defconfig
+++ b/configs/zynq_cse_nand_defconfig
@@ -13,6 +13,8 @@ CONFIG_DEFAULT_DEVICE_TREE="zynq-cse-nand"
 CONFIG_SPL_STACK_R_ADDR=0x20
 CONFIG_SPL_STACK=0xfe00
 CONFIG_SPL=y
+# CONFIG_SPL_FS_FAT is not set
+# CONFIG_SPL_LIBDISK_SUPPORT is not set
 CONFIG_SYS_LOAD_ADDR=0x0
 CONFIG_REMAKE_ELF=y
 CONFIG_SYS_CUSTOM_LDSCRIPT=y
diff --git a/configs/zynq_cse_nor_defconfig b/configs/zynq_cse_nor_defconfig
index 64df1f0b83e..c5a28f28b9d 100644
--- a/configs/zynq_cse_nor_defconfig
+++ b/configs/zynq_cse_nor_defconfig
@@ -13,6 +13,8 @@ CONFIG_DEFAULT_DEVICE_TREE="zynq-cse-nor"
 CONFIG_SPL_STACK_R_ADDR=0x20
 CONFIG_SPL_STACK=0xfe00
 CONFIG_SPL=y
+# CONFIG_SPL_FS_FAT is not set
+# CONFIG_SPL_LIBDISK_SUPPORT is not set
 CONFIG_SYS_LOAD_ADDR=0x0
 CONFIG_REMAKE_ELF=y
 CONFIG_SYS_CUSTOM_LDSCRIPT=y
diff --git a/configs/zynq_cse_qspi_defconfig b/configs/zynq_cse_qspi_defconfig
index 9368fb4ffbc..9a2770af20e 100644
--- a/configs/zynq_cse_qspi_defconfig
+++ b/configs/zynq_cse_qspi_defconfig
@@ -16,6 +16,8 @@ CONFIG_SPL_STACK=0xfe00
 CONFIG_SPL=y
 CONFIG_DEBUG_UART_BASE=0x0
 CONFIG_DEBUG_UART_CLOCK=0
+# CONFIG_SPL_FS_FAT is not set
+# CONFIG_SPL_LIBDISK_SUPPORT is not set
 # CONFIG_ZYNQ_DDRC_INIT is not set
 # CONFIG_CMD_ZYNQ is not set
 CONFIG_SYS_LOAD_ADDR=0x0
-- 
2.37.1



[PATCH v7 01/26] spl: blk_fs: Fix uninitialized return value when we can't get a blk_desc

2023-11-08 Thread Sean Anderson
Initialize ret to avoid returning garbage if blk_get_devnum_by_uclass_id
fails.

Fixes: 8ce6a2e1757 ("spl: blk: Support loading images from fs")
Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v6)

Changes in v6:
- New

 common/spl/spl_blk_fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c
index 63825d620d1..144c8a65b5d 100644
--- a/common/spl/spl_blk_fs.c
+++ b/common/spl/spl_blk_fs.c
@@ -50,7 +50,7 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
struct blk_desc *blk_desc;
loff_t actlen, filesize;
struct blk_dev dev;
-   int ret;
+   int ret = -ENODEV;
 
blk_desc = blk_get_devnum_by_uclass_id(uclass_id, devnum);
if (!blk_desc) {
-- 
2.37.1



[PATCH v7 00/26] spl: Use common function for loading/parsing images

2023-11-08 Thread Sean Anderson
This series adds support for loading all image types (Legacy (with and without
LZMA), FIT (with and without LOAD_FIT_FULL), and i.MX) to the MMC, SPI, NOR,
NET, FAT, EXT, NVMe, and semihosting load methods. It does this by introducing a
helper function which handles the minutiae of invoking the proper parsing
function, and reading the rest of the image.

Hopefully, this will make it easier for load methods to support all image types
that U-Boot supports, without having undocumented unsupported image types. I
applied this to several loaders which were invoking spl_load_simple_fit and/or
spl_parse_image_header, but I did not use it with others (e.g. DFU/RAM) which
had complications in the mix.

This series is organized roughly into two parts. Patches up to "spl: Add generic
spl_load function" are all setup or size-reduction oriented. Later patches
generally convert various load functions to spl_load.

bloat-o-meter results (for CONFIG_SPL only) at [1]. Size growth has been the
bigegst challenge to preparing this series. I have used every trick I can think
of to reduce bloat. Some SAMA boards no longer fit, but I have a plan to fix
them [2].

This is bar far the largest and most-difficult revision of this series to-date.
There are probably still things which can reduce the size, but I have been
working on this series for the better part of two months and I think it is a
good idea to get some feedback. Because of the SAMA bloat, this series will not
pass CI, so I expect to do a v7 before this is ready to apply. Feel free,
however, to apply patches in the first half (especially the fixes).

This version of the series is better-tested than ever before, thanks to some new
unit tests. However, things like the i.MX ROMAPI are untested. NAND should also
be tested more-widely, for reasons listed in the commit message. I encourage you
try this series out on your favorite board.

This series depends on [3]. (Almost passing) CI at [4].

[1] https://gist.github.com/Forty-Bot/5bfe88676dd3c2aec6ebc23abb08e06f
This includes some changes to am335x_evm_spiboot and am65x_evm_r5_usbdfu
which have since been undone. This was ran for v6.
[2] https://lore.kernel.org/u-boot/20231105022742.632175-1-sean...@gmail.com/
[3] https://lore.kernel.org/u-boot/20231104203753.1579217-1-sean...@gmail.com/
[4] https://source.denx.de/u-boot/custodians/u-boot-clk/-/pipelines/18447
For v6.

Changes in v7:
- Disable FS_FAT for the zynq(mp) boards as well, as suggested by Michal
- Reword documentation for spl_load_info
- Split off setting bl_len to ARCH_DMA_MINALIGN from filename removal
- Remove Pali from CC

Changes in v6:
- Fix uninitialized return value when we can't get a blk_desc
- Disable SPL_FS_FAT when it isn't used
- Don't close fd before spl_load_simple_fit
- Remove NULL assignments in spl_load_info
- Remove dev from spl_load_info
- Take advantage of bl_len's power-of-twoness
- Refactor spl_load_info->read to use units of bytes
- Remove filename from spl_load_info
- Only support bl_len when we have to
- Remove spl_nand_legacy_read
- Split off LZMA decompression into its own function
- Support testing LEGACY_LZMA filesystem images
- Use pseudo-LTO for spl_load
- Align reads to bl_len
- Add SYS_MMCSD_RAW_MODE to help determine whether SPL_MMC loads
  anything directly.
- Convert nand to spl_load
- Fix LZMA support
- Fix load address
- Fix invalid return from spl_blk_load_image
- Fix soft reset after loading from SPI
- Explicitly initialize load_info members to reduce text size
- Rebase on u-boot/next
- Add option to disable DMA alignment for FAT

Changes in v5:
- Make SHOW_ERRORS depend on LIBCOMMON
- Load the header in spl_load as well
- Don't bother trying to DMA-align the buffer, since we can't really fix
  it.
- Convert NVMe to spl_load

Changes in v4:
- Fix format specifiers in debug prints
- Reword/fix some of the doc comments for spl_load
- Rebase on u-boot/master

Changes in v3:
- Fix using ffs instead of fls
- Fix using not initializing bl_len when info->filename was NULL
- Fix failing on success

Changes in v2:
- Use reverse-xmas-tree style for locals in spl_simple_read. This is not
  complete, since overhead depends on bl_mask.
- Convert semihosting as well
- Consolidate spi_load_image_os into spl_spi_load_image

Sean Anderson (26):
  spl: blk_fs: Fix uninitialized return value when we can't get a
blk_desc
  arm: Disable SPL_FS_FAT when it isn't used
  spl: Make SHOW_ERRORS depend on LIBCOMMON
  spl: semihosting: Don't close fd before spl_load_simple_fit
  spl: Remove NULL assignments in spl_load_info
  spl: Remove dev from spl_load_info
  spl: Take advantage of bl_len's power-of-twoness
  spl: Refactor spl_load_info->read to use units of bytes
  spl: Set FAT bl_len to ARCH_DMA_MINALIGN
  spl: Remove filename from spl_load_info
  spl: Only support bl_len when we have to
  spl: nand: Remove spl_nand_legacy_read
  spl: legacy: Split off LZMA decompression into its own function
  test: spl: Support testing 

Re: [PATCH v3 0/2] rng: Provide a RNG based on the RISC-V Zkr ISA extension

2023-11-08 Thread Tom Rini
On Wed, Nov 08, 2023 at 07:25:22AM -0800, Heinrich Schuchardt wrote:
> On 11/8/23 06:37, Tom Rini wrote:
> > On Wed, Nov 08, 2023 at 06:23:37AM -0800, Heinrich Schuchardt wrote:
> > > On 11/7/23 16:34, Tom Rini wrote:
> > > > On Wed, Nov 08, 2023 at 12:29:03AM +, Conor Dooley wrote:
> > > > > On Tue, Nov 07, 2023 at 06:23:05PM -0500, Tom Rini wrote:
> > > > [snip]
> > > > > > Thanks. Setting aside Simon's follow-up, this is what I was looking 
> > > > > > for.
> > > > > > We might have to wait for Heinrich to return from the conference to 
> > > > > > have
> > > > > > time to look at how to utilize the above and see what we can do from
> > > > > > there.
> > > > > 
> > > > > I did read that, but I don't think most of it is relevant to the 
> > > > > binding
> > > > > itself. His five things were:
> > > > > | - U-Boot models hardware (and other things) as devices in driver 
> > > > > model [1]
> > > > > 
> > > > > This I think should be satisfied. The Zkr CSR is a property of the 
> > > > > CPU,
> > > > > and shouldn't have its own DT node IMO. Is it problematic for U-Boot 
> > > > > to
> > > > > populate multiple devices for its driver model based on one DT node?
> > > 
> > > Devices in U-Boot are bound on the basis of a compatible string. All 
> > > RISC-V
> > > CPU nodes have a compatible string 'riscv' but that does not provide any
> > > information about the existence of the Zkr extension. That information is 
> > > in
> > > the 'riscv,isa-extensions' property of the cpu nodes (see
> > > Documentation/devicetree/bindings/riscv/cpus.yaml).
> > > 
> > > > > I know in Linux that I can create devices using something like
> > > > > platform_device_register(), does U-Boot have a similar facility?
> > > 
> > > This is what the U_BOOT_DRVINFO() macro in my driver does and which Simon
> > > discourages.
> > 
> > My current thoughts are that in this case we could use U_BOOT_DRVINFO()
> > like today and then have riscv_zkr_probe() be what checks the
> > riscv,isa-extensions property for an appropriate match? This would mean
> > we don't need any new nodes/compatibles/etc, and possibly not need any
> > bootph- properties added either? I assume we don't need the RNG so early
> > as for that to be an issue.
> > 
> 
> The presence of the Zkr extension in the device-tree 'riscv,isa-extensions'
> property does not indicate if the machine mode firmware has enabled access
> in supervisor mode via the mseccfg.sseed flag. This is why my driver tries
> to read the seed register and checks if an exception occurs.

This I think is a question for Cody or someone else in the RISC-V
community? If just checking the property isn't sufficient, what is? Or,
what's the best / most reliable way? I don't know and I'll let the
RISC-V community sort that out instead of making incorrect assumptions
myself.

> Additionally checking the device-tree would increase code size. Is it really
> needed?

I mean, it depends? My biggest issue right now is that in-tree I don't
see any RISC-V targets that select any of the RISCV_ISA options so I
can't evaluate what platforms grow by how much where. We shouldn't be
talking about kilobytes of change, so no, I don't think somehow checking
the device tree for this is out of bounds. But it comes back to what I
just asked above, first. We need the correct and expected way to check
for this feature to be known, then we decide how to handle that.

> We may have multiple RNG drivers enabled on the same device, e.g. TPM, Zkr,
> virtio-rng. In several code locations we try to use the first RNG device
> (not the first successfully probed RNG device). This is why
> 
> [PATCH 1/1] rng: detect RISC-V Zkr RNG device in bind method
> https://lore.kernel.org/u-boot/20231104065107.23623-1-heinrich.schucha...@canonical.com/
> 
> moves the detection from probe() to bind(). The patch further corrects the
> return code if the RNG device is not available.

Sounds like we have some other general issues to sort out too then.
Filing an issue on
https://source.denx.de/u-boot/custodians/u-boot-dm/-/issues/ would be
good so it doesn't get forgotten.

-- 
Tom


signature.asc
Description: PGP signature


[PATCH v2 5/5] pmic: qcom: dont use dev_read_addr to get USID

2023-11-08 Thread Caleb Connolly
Linux DTs stuff a value indicating if the USID is a USID or a GSID in the
reg property, the Linux SPMI driver then reads the two address cells
separately. U-boot's dev_read_addr() doesn't know how to handle this, so
use ofnode_read_u32_index() to get just the USID.

The Qcom pmic driver doesn't have support for GSID handling, so just
ignore the second value for now.

Signed-off-by: Caleb Connolly 
---
 drivers/power/pmic/pmic_qcom.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/power/pmic/pmic_qcom.c b/drivers/power/pmic/pmic_qcom.c
index ad8daf43f06f..f2ac6494811d 100644
--- a/drivers/power/pmic/pmic_qcom.c
+++ b/drivers/power/pmic/pmic_qcom.c
@@ -66,12 +66,19 @@ static const struct udevice_id pmic_qcom_ids[] = {
 static int pmic_qcom_probe(struct udevice *dev)
 {
struct pmic_qcom_priv *priv = dev_get_priv(dev);
+   int ret;
 
-   priv->usid = dev_read_addr(dev);
-
-   if (priv->usid == FDT_ADDR_T_NONE)
+   /*
+* dev_read_addr() can't be used here because the reg property actually
+* contains two discrete values, not a single 64-bit address.
+* The address is the first value.
+*/
+   ret = ofnode_read_u32_index(dev_ofnode(dev), "reg", 0, >usid);
+   if (ret < 0)
return -EINVAL;
 
+   debug("usid: %d\n", priv->usid);
+
return 0;
 }
 

-- 
2.42.0



[PATCH v2 4/5] spmi: msm: fix register range names

2023-11-08 Thread Caleb Connolly
The core and chnl register ranges were swapped on SDM845. Fix it, and
fetch the register ranges by name instead of by index.

Drop the cosmetic "version" variable and clean up the debug logging.

Signed-off-by: Caleb Connolly 
---
 arch/arm/dts/sdm845.dtsi |  2 +-
 drivers/spmi/spmi-msm.c  | 46 ++
 2 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/arch/arm/dts/sdm845.dtsi b/arch/arm/dts/sdm845.dtsi
index cd5d890e9a45..9aa3b99d8660 100644
--- a/arch/arm/dts/sdm845.dtsi
+++ b/arch/arm/dts/sdm845.dtsi
@@ -63,7 +63,7 @@
reg = <0xc44 0x1100>,
  <0xc60 0x200>,
  <0xe60 0x10>;
-   reg-names = "cnfg", "core", "obsrvr";
+   reg-names = "core", "chnls", "obsrvr";
#address-cells = <0x1>;
#size-cells = <0x1>;
 
diff --git a/drivers/spmi/spmi-msm.c b/drivers/spmi/spmi-msm.c
index 27a035c0a595..f8834e60c266 100644
--- a/drivers/spmi/spmi-msm.c
+++ b/drivers/spmi/spmi-msm.c
@@ -70,7 +70,7 @@ enum pmic_arb_channel {
 
 struct msm_spmi_priv {
phys_addr_t arb_chnl;  /* ARB channel mapping base */
-   phys_addr_t spmi_core; /* SPMI core */
+   phys_addr_t spmi_chnls; /* SPMI core */
phys_addr_t spmi_obs;  /* SPMI observer */
/* SPMI channel map */
uint8_t channel_map[SPMI_MAX_SLAVES][SPMI_MAX_PERIPH];
@@ -95,10 +95,10 @@ static int msm_spmi_write(struct udevice *dev, int usid, 
int pid, int off,
 
/* Disable IRQ mode for the current channel*/
writel(0x0,
-  priv->spmi_core + SPMI_CH_OFFSET(channel) + SPMI_REG_CONFIG);
+  priv->spmi_chnls + SPMI_CH_OFFSET(channel) + SPMI_REG_CONFIG);
 
/* Write single byte */
-   writel(val, priv->spmi_core + SPMI_CH_OFFSET(channel) + SPMI_REG_WDATA);
+   writel(val, priv->spmi_chnls + SPMI_CH_OFFSET(channel) + 
SPMI_REG_WDATA);
 
/* Prepare write command */
reg |= SPMI_CMD_EXT_REG_WRITE_LONG << SPMI_CMD_OPCODE_SHIFT;
@@ -113,12 +113,12 @@ static int msm_spmi_write(struct udevice *dev, int usid, 
int pid, int off,
ch_offset = SPMI_CH_OFFSET(channel);
 
/* Send write command */
-   writel(reg, priv->spmi_core + SPMI_CH_OFFSET(channel) + SPMI_REG_CMD0);
+   writel(reg, priv->spmi_chnls + SPMI_CH_OFFSET(channel) + SPMI_REG_CMD0);
 
/* Wait till CMD DONE status */
reg = 0;
while (!reg) {
-   reg = readl(priv->spmi_core + SPMI_CH_OFFSET(channel) +
+   reg = readl(priv->spmi_chnls + SPMI_CH_OFFSET(channel) +
SPMI_REG_STATUS);
}
 
@@ -186,47 +186,37 @@ static struct dm_spmi_ops msm_spmi_ops = {
 static int msm_spmi_probe(struct udevice *dev)
 {
struct msm_spmi_priv *priv = dev_get_priv(dev);
-   phys_addr_t config_addr;
+   phys_addr_t core_addr;
u32 hw_ver;
-   u32 version;
int i;
-   int err;
 
-   config_addr = dev_read_addr_index(dev, 0);
-   priv->spmi_core = dev_read_addr_index(dev, 1);
-   priv->spmi_obs = dev_read_addr_index(dev, 2);
+   core_addr = dev_read_addr_name(dev, "core");
+   priv->spmi_chnls = dev_read_addr_name(dev, "chnls");
+   priv->spmi_obs = dev_read_addr_name(dev, "obsrvr");
 
-   hw_ver = readl(config_addr + PMIC_ARB_VERSION);
+   hw_ver = readl(core_addr + PMIC_ARB_VERSION);
 
if (hw_ver < PMIC_ARB_VERSION_V3_MIN) {
priv->arb_ver = V2;
-   version = 2;
-   priv->arb_chnl = config_addr + APID_MAP_OFFSET_V1_V2_V3;
+   priv->arb_chnl = core_addr + APID_MAP_OFFSET_V1_V2_V3;
} else if (hw_ver < PMIC_ARB_VERSION_V5_MIN) {
priv->arb_ver = V3;
-   version = 3;
-   priv->arb_chnl = config_addr + APID_MAP_OFFSET_V1_V2_V3;
+   priv->arb_chnl = core_addr + APID_MAP_OFFSET_V1_V2_V3;
} else {
priv->arb_ver = V5;
-   version = 5;
-   priv->arb_chnl = config_addr + APID_MAP_OFFSET_V5;
-
-   if (err) {
-   dev_err(dev, "could not read APID->PPID mapping table, 
rc= %d\n", err);
-   return -1;
-   }
+   priv->arb_chnl = core_addr + APID_MAP_OFFSET_V5;
}
 
-   dev_dbg(dev, "PMIC Arb Version-%d (0x%x)\n", version, hw_ver);
+   dev_dbg(dev, "PMIC Arb Version-%d (%#x)\n", hw_ver >> 28, hw_ver);
 
if (priv->arb_chnl == FDT_ADDR_T_NONE ||
-   priv->spmi_core == FDT_ADDR_T_NONE ||
+   priv->spmi_chnls == FDT_ADDR_T_NONE ||
priv->spmi_obs == FDT_ADDR_T_NONE)
return -EINVAL;
 
-   dev_dbg(dev, "priv->arb_chnl address (%llu)\n", priv->arb_chnl);
-   dev_dbg(dev, "priv->spmi_core address (%llu)\n", priv->spmi_core);
-   dev_dbg(dev, 

[PATCH v2 2/5] gpio: qcom_pmic: rework pwrkey driver into a button driver

2023-11-08 Thread Caleb Connolly
The power and resin keys were implemented as GPIOs here, but their only
use would be as buttons. Avoid the additional layer of introspection and
rework this driver into a button driver.

While we're here, replace the "qcom,pm8998-pwrkey" compatible with
"qcom,pm8941-pwrkey" to match upstream (Linux).

The dragonboard410c and 820c boards are adjusted to benefit from this
change too, simplify their custom board init code.

Signed-off-by: Caleb Connolly 
---
 MAINTAINERS  |   1 +
 arch/arm/dts/dragonboard410c-uboot.dtsi  |  14 +-
 arch/arm/dts/dragonboard410c.dts |  22 ++-
 arch/arm/dts/dragonboard820c-uboot.dtsi  |  15 +--
 arch/arm/dts/dragonboard820c.dts |  23 +++-
 arch/arm/dts/dragonboard845c-uboot.dtsi  |  11 --
 arch/arm/dts/dragonboard845c.dts |   4 +
 arch/arm/dts/sdm845.dtsi |  23 +++-
 arch/arm/dts/starqltechn.dts |  20 +--
 arch/arm/mach-snapdragon/Kconfig |   3 +
 arch/arm/mach-snapdragon/init_sdm845.c   |  45 ++-
 board/qualcomm/dragonboard410c/dragonboard410c.c |  31 ++---
 board/qualcomm/dragonboard820c/dragonboard820c.c |  29 ++--
 drivers/button/Kconfig   |   9 ++
 drivers/button/Makefile  |   1 +
 drivers/button/button-qcom-pmic.c| 165 +++
 drivers/gpio/Kconfig |   3 +-
 drivers/gpio/qcom_pmic_gpio.c| 104 --
 18 files changed, 275 insertions(+), 248 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index f6d63c8ab563..8cd102eaa070 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -572,6 +572,7 @@ M:  Neil Armstrong 
 R: Sumit Garg 
 S: Maintained
 F: arch/arm/mach-snapdragon/
+F: drivers/button/button-qcom-pmic.c
 F: drivers/clk/qcom/
 F: drivers/gpio/msm_gpio.c
 F: drivers/mmc/msm_sdhci.c
diff --git a/arch/arm/dts/dragonboard410c-uboot.dtsi 
b/arch/arm/dts/dragonboard410c-uboot.dtsi
index 3b0bd0ed0a1b..39b03a30702c 100644
--- a/arch/arm/dts/dragonboard410c-uboot.dtsi
+++ b/arch/arm/dts/dragonboard410c-uboot.dtsi
@@ -5,6 +5,9 @@
  * (C) Copyright 2015 Mateusz Kulikowski 
  */
 
+#include 
+#include 
+
 / {
 
smem {
@@ -42,14 +45,3 @@
gpios = <_gpios 3 0>;
};
 };
-
-
-_pon {
-   key_vol_down {
-   gpios = <_pon 1 0>;
-   };
-
-   key_power {
-   gpios = <_pon 0 0>;
-   };
-};
diff --git a/arch/arm/dts/dragonboard410c.dts b/arch/arm/dts/dragonboard410c.dts
index 9230dd3fd96c..c41fee977813 100644
--- a/arch/arm/dts/dragonboard410c.dts
+++ b/arch/arm/dts/dragonboard410c.dts
@@ -147,11 +147,23 @@
#address-cells = <0x1>;
#size-cells = <0x1>;
 
-   pm8916_pon: pm8916_pon@800 {
-   compatible = "qcom,pm8916-pwrkey";
-   reg = <0x800 0x96>;
-   #gpio-cells = <2>;
-   gpio-controller;
+   pon@800 {
+   compatible = "qcom,pm8916-pon";
+   reg = <0x800 0x100>;
+   mode-bootloader = <0x2>;
+   mode-recovery = <0x1>;
+
+   pwrkey {
+   compatible = 
"qcom,pm8941-pwrkey";
+   debounce = <15625>;
+   bias-pull-up;
+   };
+
+   pm8916_resin: resin {
+   compatible = 
"qcom,pm8941-resin";
+   debounce = <15625>;
+   bias-pull-up;
+   };
};
 
pm8916_gpios: pm8916_gpios@c000 {
diff --git a/arch/arm/dts/dragonboard820c-uboot.dtsi 
b/arch/arm/dts/dragonboard820c-uboot.dtsi
index 457728a43ecb..693c0e5efcc4 100644
--- a/arch/arm/dts/dragonboard820c-uboot.dtsi
+++ b/arch/arm/dts/dragonboard820c-uboot.dtsi
@@ -5,6 +5,9 @@
  * (C) Copyright 2017 Jorge Ramirez-Ortiz 
  */
 
+#include 
+#include 
+
 / {
smem {
bootph-all;
@@ -30,15 +33,3 @@
};
};
 };
-
-_pon {
-   key_vol_down {
-   gpios = <_pon 1 0>;
-   label = "key_vol_down";
-   };
-
-   key_power {
-   gpios = <_pon 0 0>;
-   label = "key_power";
-   };
-};
diff --git a/arch/arm/dts/dragonboard820c.dts b/arch/arm/dts/dragonboard820c.dts
index ad201d48749c..0d9c9f7a4922 

[PATCH v2 3/5] gpio: qcom_pmic: fix support for upstream DT

2023-11-08 Thread Caleb Connolly
Linux devicetrees use the "gpio-ranges" property, add support for
parsing it instead of "gpio-count" so that upstream DTs can be used with
U-Boot.

Signed-off-by: Caleb Connolly 
---
 drivers/gpio/qcom_pmic_gpio.c | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/drivers/gpio/qcom_pmic_gpio.c b/drivers/gpio/qcom_pmic_gpio.c
index 7b83c67fa464..647d4143ce14 100644
--- a/drivers/gpio/qcom_pmic_gpio.c
+++ b/drivers/gpio/qcom_pmic_gpio.c
@@ -245,11 +245,37 @@ static int qcom_gpio_probe(struct udevice *dev)
return 0;
 }
 
+/*
+ * Parse basic GPIO count specified via the gpio-ranges property
+ * as specified in Linux devicetrees
+ * Returns < 0 on error, otherwise gpio count
+ */
+static int qcom_gpio_of_parse_ranges(struct udevice *dev)
+{
+   int ret;
+   struct ofnode_phandle_args args;
+
+   ret = ofnode_parse_phandle_with_args(dev_ofnode(dev), "gpio-ranges",
+NULL, 3, 0, );
+   if (ret)
+   return log_msg_ret("gpio-ranges", ret);
+
+   return args.args[2];
+}
+
 static int qcom_gpio_of_to_plat(struct udevice *dev)
 {
struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+   int ret;
 
uc_priv->gpio_count = dev_read_u32_default(dev, "gpio-count", 0);
+   if (!uc_priv->gpio_count) {
+   ret = qcom_gpio_of_parse_ranges(dev);
+   if (ret > 0)
+   uc_priv->gpio_count = ret;
+   else
+   printf("gpio-ranges error: %d\n", ret);
+   }
uc_priv->bank_name = dev_read_string(dev, "gpio-bank-name");
if (uc_priv->bank_name == NULL)
uc_priv->bank_name = "qcom_pmic";

-- 
2.42.0



[PATCH v2 1/5] gpio: qcom_pmic: fix silent dev_read_addr downcast

2023-11-08 Thread Caleb Connolly
priv->pid is uint32_t, but dev_read_addr() returns a uint64_t on arm64,
with the upper bits being used for error codes. Do error checking before
downcasting to u32 to prevent errors being silently ignored.

Signed-off-by: Caleb Connolly 
---
 drivers/gpio/qcom_pmic_gpio.c | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/qcom_pmic_gpio.c b/drivers/gpio/qcom_pmic_gpio.c
index 65feb453ebc3..e5841f502953 100644
--- a/drivers/gpio/qcom_pmic_gpio.c
+++ b/drivers/gpio/qcom_pmic_gpio.c
@@ -221,11 +221,14 @@ static int qcom_gpio_probe(struct udevice *dev)
 {
struct qcom_gpio_bank *priv = dev_get_priv(dev);
int reg;
+   u64 pid;
 
-   priv->pid = dev_read_addr(dev);
-   if (priv->pid == FDT_ADDR_T_NONE)
+   pid = dev_read_addr(dev);
+   if (pid == FDT_ADDR_T_NONE)
return log_msg_ret("bad address", -EINVAL);
 
+   priv->pid = pid;
+
/* Do a sanity check */
reg = pmic_reg_read(dev->parent, priv->pid + REG_TYPE);
if (reg != REG_TYPE_VAL)
@@ -328,11 +331,14 @@ static int qcom_pwrkey_probe(struct udevice *dev)
 {
struct qcom_gpio_bank *priv = dev_get_priv(dev);
int reg;
+   u64 pid;
 
-   priv->pid = dev_read_addr(dev);
-   if (priv->pid == FDT_ADDR_T_NONE)
+   pid = dev_read_addr(dev);
+   if (pid == FDT_ADDR_T_NONE)
return log_msg_ret("bad address", -EINVAL);
 
+   priv->pid = pid;
+
/* Do a sanity check */
reg = pmic_reg_read(dev->parent, priv->pid + REG_TYPE);
if (reg != 0x1)

-- 
2.42.0



[PATCH v2 0/5] Qualcomm PMIC fixes

2023-11-08 Thread Caleb Connolly
This series addresses some long-standing issues with the SPMI arb
driver, the PMIC, and the PMIC GPIO. It fixes compatibility with
upstream Linux devicetrees, and simplifies pwrkey/resin support by
rewriting the pon driver to be a button driver rather than a GPIO
driver.

Existing users are adjusted to use the new button driver in their
oard init code.

This series is based on the pinctrl [1] and clock [2] cleanup series.
There may be some DTS conflicts applying it standalone.

[1]: 
https://lore.kernel.org/u-boot/20231106-b4-qcom-pinctrl-v2-0-406e8d868...@linaro.org/
[2]: 
https://lore.kernel.org/u-boot/20231103-b4-qcom-clk-v3-0-8d2d460ec...@linaro.org/

---
Changes in v2:
* Avoid using non-standard "label" and "linux,code" properties for
  buttons
* Add missing sdm845 DTS parts
* Put button driver in drivers/button
* Link to v1: 
https://lore.kernel.org/r/20231106-b4-qcom-dt-compat-v1-0-0ccbb7841...@linaro.org

---
Caleb Connolly (5):
  gpio: qcom_pmic: fix silent dev_read_addr downcast
  gpio: qcom_pmic: rework pwrkey driver into a button driver
  gpio: qcom_pmic: fix support for upstream DT
  spmi: msm: fix register range names
  pmic: qcom: dont use dev_read_addr to get USID

 MAINTAINERS  |   1 +
 arch/arm/dts/dragonboard410c-uboot.dtsi  |  14 +-
 arch/arm/dts/dragonboard410c.dts |  22 ++-
 arch/arm/dts/dragonboard820c-uboot.dtsi  |  15 +--
 arch/arm/dts/dragonboard820c.dts |  23 +++-
 arch/arm/dts/dragonboard845c-uboot.dtsi  |  11 --
 arch/arm/dts/dragonboard845c.dts |   4 +
 arch/arm/dts/sdm845.dtsi |  25 +++-
 arch/arm/dts/starqltechn.dts |  20 +--
 arch/arm/mach-snapdragon/Kconfig |   3 +
 arch/arm/mach-snapdragon/init_sdm845.c   |  45 ++-
 board/qualcomm/dragonboard410c/dragonboard410c.c |  31 ++---
 board/qualcomm/dragonboard820c/dragonboard820c.c |  29 ++--
 drivers/button/Kconfig   |   9 ++
 drivers/button/Makefile  |   1 +
 drivers/button/button-qcom-pmic.c| 165 +++
 drivers/gpio/Kconfig |   3 +-
 drivers/gpio/qcom_pmic_gpio.c| 134 +-
 drivers/power/pmic/pmic_qcom.c   |  13 +-
 drivers/spmi/spmi-msm.c  |  46 +++
 20 files changed, 335 insertions(+), 279 deletions(-)
---
base-commit: d1efa48e205960b15656eb0c13227110895f1cc9

// Caleb (they/them)



Re: [PATCH v6 06/25] spl: Remove dev from spl_load_info

2023-11-08 Thread Sean Anderson

On 11/7/23 23:23, Simon Glass wrote:

Hi Sean,

On Sun, 5 Nov 2023 at 19:26, Sean Anderson  wrote:


dev and priv server the same purpose, and are never set at the same time.


serve


Remove dev and convert all users to priv. While we're at it, reorder bl_len
to be last for better alignment.


It's a bit unfortunate to drop the device, isn't it? But then, as
before, this is self-contained so Is suppose it doesn't matter what we
store.


The original goal was to have something like

struct spl_load load = SPL_LOAD_INFO(my_load_function, my_private_data);

but I had to cut it because it was resulting in too many unnecessary 
assignments.

--Sean


Reviewed-by: Simon Glass 

Regards,
Simon





Signed-off-by: Sean Anderson 
---

Changes in v6:
- New

  common/spl/spl_mmc.c   | 6 +++---
  common/spl/spl_spi.c   | 6 +++---
  drivers/usb/gadget/f_sdp.c | 6 +++---
  include/spl.h  | 4 +---
  4 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 6d9137c32e0..3d7551a7dae 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -65,7 +65,7 @@ static int mmc_load_legacy(struct spl_image_info *spl_image,
  static ulong h_spl_load_read(struct spl_load_info *load, ulong sector,
  ulong count, void *buf)
  {
-   struct mmc *mmc = load->dev;
+   struct mmc *mmc = load->priv;

 return blk_dread(mmc_get_blk_desc(mmc), sector, count, buf);
  }
@@ -105,7 +105,7 @@ int mmc_load_image_raw_sector(struct spl_image_info 
*spl_image,
 struct spl_load_info load;

 debug("Found FIT\n");
-   load.dev = mmc;
+   load.priv = mmc;
 load.filename = NULL;
 load.bl_len = mmc->read_bl_len;
 load.read = h_spl_load_read;
@@ -114,7 +114,7 @@ int mmc_load_image_raw_sector(struct spl_image_info 
*spl_image,
valid_container_hdr((void *)header)) {
 struct spl_load_info load;

-   load.dev = mmc;
+   load.priv = mmc;
 load.filename = NULL;
 load.bl_len = mmc->read_bl_len;
 load.read = h_spl_load_read;
diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index d83d70f2f33..af7a28e7c25 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -59,7 +59,7 @@ static int spi_load_image_os(struct spl_image_info *spl_image,
  static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector,
   ulong count, void *buf)
  {
-   struct spi_flash *flash = load->dev;
+   struct spi_flash *flash = load->priv;
 ulong ret;

 ret = spi_flash_read(flash, sector, count, buf);
@@ -151,7 +151,7 @@ static int spl_spi_load_image(struct spl_image_info 
*spl_image,
 struct spl_load_info load;

 debug("Found FIT\n");
-   load.dev = flash;
+   load.priv = flash;
 load.filename = NULL;
 load.bl_len = 1;
 load.read = spl_spi_fit_read;
@@ -162,7 +162,7 @@ static int spl_spi_load_image(struct spl_image_info 
*spl_image,
valid_container_hdr((void *)header)) {
 struct spl_load_info load;

-   load.dev = flash;
+   load.priv = flash;
 load.filename = NULL;
 load.bl_len = 1;
 load.read = spl_spi_fit_read;
diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
index ee9384fb37e..1b16b7eb452 100644
--- a/drivers/usb/gadget/f_sdp.c
+++ b/drivers/usb/gadget/f_sdp.c
@@ -744,7 +744,7 @@ static ulong sdp_load_read(struct spl_load_info *load, 
ulong sector,
  {
 debug("%s: sector %lx, count %lx, buf %lx\n",
   __func__, sector, count, (ulong)buf);
-   memcpy(buf, (void *)(load->dev + sector), count);
+   memcpy(buf, (void *)(load->priv + sector), count);
 return count;
  }

@@ -844,7 +844,7 @@ static int sdp_handle_in_ep(struct spl_image_info 
*spl_image,
 struct spl_load_info load;

 debug("Found FIT\n");
-   load.dev = header;
+   load.priv = header;
 load.bl_len = 1;
 load.read = sdp_load_read;
 spl_load_simple_fit(spl_image, , 0,
@@ -857,7 +857,7 @@ static int sdp_handle_in_ep(struct spl_image_info 
*spl_image,
 valid_container_hdr((void *)header)) {
 struct spl_load_info load;

-   load.dev = header;
+   load.priv = header;
 load.bl_len = 1;
   

Re: [PATCH] clk: exynos: Add header guard for clk-pll.h

2023-11-08 Thread Sean Anderson

On 11/7/23 16:22, Sam Protsenko wrote:

The clk-pll.h is going to be included in multiple files soon. Add
missing header guard to prevent possible build errors in future.

Signed-off-by: Sam Protsenko 
Fixes: 166097e87753 ("clk: exynos: add clock driver for Exynos7420 Soc")
---
  drivers/clk/exynos/clk-pll.h | 5 +
  1 file changed, 5 insertions(+)

diff --git a/drivers/clk/exynos/clk-pll.h b/drivers/clk/exynos/clk-pll.h
index c79aac44258b..7b7af5e67612 100644
--- a/drivers/clk/exynos/clk-pll.h
+++ b/drivers/clk/exynos/clk-pll.h
@@ -5,4 +5,9 @@
   * Thomas Abraham 
   */
  
+#ifndef __EXYNOS_CLK_PLL_H

+#define __EXYNOS_CLK_PLL_H
+
  unsigned long pll145x_get_rate(unsigned int *con1, unsigned long fin_freq);
+
+#endif /* __EXYNOS_CLK_PLL_H */


Reviewed-by: Sean Anderson 


Re: rockpro64 rk3399 dwc3 issue

2023-11-08 Thread Shantur Rathore
On Wed, Nov 8, 2023 at 2:50 PM Peter Robinson  wrote:
>
> Hi,
>
> > I am trying to boot OS via USB3.0 ports on RK3399 base RockPro64.
> > U-boot is failing to detect the drive in the USB3.0 port.
> >
> > If I boot linux through other mediums the drive is detected and works fine.
> > Can anyone please help me figure out the issue?
>
> Can you share the version of U-Boot you're using?

I have tried 2023.1, 2023.10 , 2024.01-rc2

An interesting finding, if I connect the same disk via a bus-powered
(no external power) USB3.0 hub the disk gets detected 100% of the
time.
Directly connecting the same disk to the same USB3.0 port and U-boot
fails to find it.
Connecting on a USB2.0 port works too.

Regards,


Re: [PATCH 0/6] siemens,am335x: clean up the draco board family

2023-11-08 Thread Tom Rini
On Wed, Nov 08, 2023 at 03:53:16PM +0100, Enrico Leto wrote:

> The boards were not maintained upstream since the development phase.
> 
> Restore SPL and remove unused settings. We need i2c to read the DDR
> settings from EEPROM, get u-boot from NAND, the console output and the
> watchdog.
> 
> Restore u-boot up to the user prompt. The complete functionality will
> be restored in future patches.
> 
> Signed-off-by: Enrico Leto 

I'm glad to see this series and in general it looks fine and is a good
start. As some parts of the future cleanup work I'd love to see a file
under doc/board/siemens for the family and moving to plain text
environment, both of which iot2050 do so there's some in-house
experience I am hopeful you can leverage as well if needed. It would
also be good to reduce the include/configs/ files to as little as
possible, I believe there's a number of dead-comments there, and other
defines that are only needed in a local context and can move to a
specific file or other header.  Thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v6 08/25] spl: Refactor spl_load_info->read to use units of bytes

2023-11-08 Thread Sean Anderson

On 11/7/23 03:49, Xavier Drudis Ferran wrote:

El Mon, Nov 06, 2023 at 08:54:03AM -0500, Sean Anderson deia:

On 11/6/23 07:35, Xavier Drudis Ferran wrote:

Thanks for your work. I'm still reading... but...


El Sun, Nov 05, 2023 at 09:25:46PM -0500, Sean Anderson deia:

diff --git a/include/spl.h b/include/spl.h
index 951e136b9ea..ecfc50e0095 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -297,10 +297,10 @@ struct spl_load_info {
 * read() - Read from device
 *
 * @load: Information about the load state
-* @sector: Sector number to read from (each @load->bl_len bytes)
-* @count: Number of sectors to read
+* @offset: Offset to read from in bytes, in multiples of @load->bl_len
+* @count: Number of bytes to read, in multiples of @load->bl_len


I'm no native English speaker, but would it be easier to understand? :

+* @offset: Offset to read from in bytes, a multiple of @load->bl_len
+* @count: Number of bytes to read, a multiple of @load->bl_len





I think it would have to be worded

@offset: Offset to read from in bytes, as a multiple of @load->bl_len

but to me these both mean the same thing.

--Sean


Ah, OK. I doubted on whether it should be a comma or "as". Apparently
it was both.

They may mean the same, but I got confused by having "in bytes", and
"in multiples" so close.

"in bytes" means the value should be the correct answer to the
question "how many bytes" (not a number of bits, not a number of
sectors)

but "in multiples of..." doesn't mean the value should be the correct
answer to "how many of multiples". Should the value be a number of
sectors (first multiple of bl_len) a number of dozens of sectors
(another multiple of bl_len) or ...?

In the first part "in" introduces a unit of measure, but in the second
the same word introduces a constraint on a value. That was confusing
to me.

Not saying it doesn't mean the same or even that you should change it,
just elaborating why I said it.



OK, what about

@offset: Offset to read from in bytes. This must be a multiple of @load->bl_len.

--Sean


Re: [PATCH v2 1/2] driver: power: add support for TPS65224

2023-11-08 Thread Bhargav Raviprakash
Hello Jaehoon,

> > Hi Bhargav,
> > 
> > On Mon, 6 Nov 2023 at 10:11, Bhargav Raviprakash  wrote:
> > >
> > > Added support for PMIC TPS65224. Includes driver for pmic,
> > > and disabling Watchdog.
> > >
> > > Signed-off-by: Bhargav Raviprakash 
> > > ---
> > >  drivers/power/pmic/Kconfig|   6 ++
> > >  drivers/power/pmic/Makefile   |   1 +
> > >  drivers/power/pmic/tps65224.c | 141 ++
> > >  include/power/tps65224.h  |  57 ++
> > >  4 files changed, 205 insertions(+)
> > >  create mode 100644 drivers/power/pmic/tps65224.c
> > >  create mode 100644 include/power/tps65224.h
> > >
> > > diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
> > > index 4a6f0ce093..b06bd31823 100644
> > > --- a/drivers/power/pmic/Kconfig
> > > +++ b/drivers/power/pmic/Kconfig
> > > @@ -378,6 +378,12 @@ config PMIC_TPS65941
> > > The TPS65941 is a PMIC containing a bunch of SMPS & LDOs.
> > > This driver binds the pmic children.
> > >
> > > +config PMIC_TPS65224
> > > +   bool "Enable driver for Texas Instruments TPS65224 PMIC"
> > > +   help
> > > +   The TPS65224 is a PMIC containing a bunch of SMPS & LDOs.
> > > +   This driver binds the pmic children.
> > > +
> > >  config PMIC_TPS65219
> > > bool "Enable driver for Texas Instruments TPS65219 PMIC"
> > > depends on DM_PMIC
> > > diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
> > > index 0b3b3d62d0..cec16e57d3 100644
> > > --- a/drivers/power/pmic/Makefile
> > > +++ b/drivers/power/pmic/Makefile
> > > @@ -33,6 +33,7 @@ obj-$(CONFIG_PMIC_STPMIC1) += stpmic1.o
> > >  obj-$(CONFIG_PMIC_TPS65217) += pmic_tps65217.o
> > >  obj-$(CONFIG_PMIC_TPS65219) += tps65219.o
> > >  obj-$(CONFIG_PMIC_TPS65941) += tps65941.o
> > > +obj-$(CONFIG_PMIC_TPS65224) += tps65224.o
> > >  obj-$(CONFIG_POWER_TPS65218) += pmic_tps65218.o
> > >
> > >  ifeq ($(CONFIG_$(SPL_)POWER_LEGACY),y)
> > > diff --git a/drivers/power/pmic/tps65224.c b/drivers/power/pmic/tps65224.c
> > > new file mode 100644
> > > index 00..33395f6edf
> > > --- /dev/null
> > > +++ b/drivers/power/pmic/tps65224.c
> > > @@ -0,0 +1,141 @@
> > > +// SPDX-License-Identifier: GPL-2.0+
> > > +/*
> > > + * (C) Copyright 2023 Texas Instruments Incorporated, 
> > > + */
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +
> > > +static const struct pmic_child_info pmic_children_info[] = {
> > > +   { .prefix = "ldo", .driver = TPS65224_LDO_DRIVER },
> > > +   { .prefix = "buck", .driver = TPS65224_BUCK_DRIVER },
> > > +   { },
> > > +};
> > > +
> > > +static int tps65224_write(struct udevice *dev, uint reg, const uint8_t 
> > > *buff,
> > > + int len)
> > > +{
> > > +   if (dm_i2c_write(dev, reg, buff, len)) {
> > > +   pr_err("write error to device: %p register: %#x!\n", dev, 
> > > reg);
> > > +   return -EIO;
> > > +   }
> > > +
> > > +   return 0;
> > > +}
> > > +
> > > +static int tps65224_read(struct udevice *dev, uint reg, uint8_t *buff, 
> > > int len)
> > > +{
> > > +   if (dm_i2c_read(dev, reg, buff, len)) {
> > > +   pr_err("read error from device: %p register: %#x!\n", 
> > > dev, reg);
> > > +   return -EIO;
> > > +   }
> > > +
> > > +   return 0;
> > > +}
> > > +
> > > +static int tps65224_bind(struct udevice *dev)
> > > +{
> > > +   ofnode regulators_node;
> > > +   int children;
> > > +
> > > +   if (dev->driver_data == TPS65224_WD)
> > > +   return 0;
> > > +
> > > +   regulators_node = dev_read_subnode(dev, "regulators");
> > > +   if (!ofnode_valid(regulators_node)) {
> > > +   debug("%s: %s regulators subnode not found!\n", __func__,
> > > + dev->name);
> > > +   return -ENXIO;
> > > +   }
> > > +
> > > +   debug("%s: '%s' - found regulators subnode\n", __func__, 
> > > dev->name);
> > > +
> > > +   children = pmic_bind_children(dev, regulators_node, 
> > > pmic_children_info);
> > > +   if (!children)
> > > +   printf("%s: %s - no child found\n", __func__, dev->name);
> > > +
> > > +   /* Probe all the child devices */
> > 
> > bind, not probe
> > 
> > > +   return dm_scan_fdt_dev(dev);
> > > +}
> > > +
> > > +static int stop_watchdog(struct udevice *wd_i2c_dev)
> > > +{
> > > +   int ret;
> > > +
> > > +   /* Maintain WD long window */
> > > +   ret = dm_i2c_reg_read(wd_i2c_dev, TPS65224_WD_MODE_REG);
> > > +   if (ret < 0) {
> > > +   debug("failed to read i2c reg (%d)\n", ret);
> > > +   return ret;
> > > +   }
> > > +
> > > +   ret &= ~TPS65224_WD_PWRHOLD_MASK;
> > > +   ret |= TPS65224_WD_PWRHOLD_MASK;
> > > +   ret = dm_i2c_reg_write(wd_i2c_dev, TPS65224_WD_MODE_REG, ret);
> > > +   if 

Re: [PATCH v6 16/25] spl: Convert fat to spl_load

2023-11-08 Thread Sean Anderson

On 11/7/23 23:24, Simon Glass wrote:

Hi Sean,

On Sun, 5 Nov 2023 at 19:26, Sean Anderson  wrote:


This converts the fat loader to use spl_load. Some platforms are very
tight on space, so we take care to only include the code we really need.

Signed-off-by: Sean Anderson 
---

(no changes since v5)

Changes in v5:
- Rework to load header in spl_load

Changes in v3:
- Fix failing on success

  common/spl/spl_fat.c | 56 +---
  include/spl_load.h   |  1 +
  test/image/spl_load_fs.c |  3 +--
  3 files changed, 20 insertions(+), 40 deletions(-)


Reviewed-by: Simon Glass 

nits below



diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index a0c34eba48f..569f2b32928 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -11,8 +11,8 @@
  #include 
  #include 
  #include 
-#include 
  #include 
+#include 
  #include 
  #include 
  #include 
@@ -66,58 +66,38 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
const char *filename)
  {
 int err;
-   struct legacy_img_hdr *header;
+   loff_t size;
+   struct spl_load_info load;

 err = spl_register_fat_device(block_dev, partition);
 if (err)
 goto end;

-   header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
-
-   err = file_fat_read(filename, header, sizeof(struct legacy_img_hdr));
-   if (err <= 0)
-   goto end;
-
-   if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) &&
-   image_get_magic(header) == FDT_MAGIC) {
-   err = file_fat_read(filename,
-   map_sysmem(CONFIG_SYS_LOAD_ADDR, 0), 0);
-   if (err <= 0)
-   goto end;
-   err = spl_parse_image_header(spl_image, bootdev,
-map_sysmem(CONFIG_SYS_LOAD_ADDR,
-   err));
-   if (err == -EAGAIN)
-   return err;
-   if (err == 0)
-   err = 1;
-   } else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
-   image_get_magic(header) == FDT_MAGIC) {
-   struct spl_load_info load;
-
-   debug("Found FIT\n");
-   load.read = spl_fit_read;
-   spl_set_bl_len(, ARCH_DMA_MINALIGN);
-   load.priv = (void *)filename;
-
-   return spl_load_simple_fit(spl_image, , 0, header);
-   } else {
-   err = spl_parse_image_header(spl_image, bootdev, header);
+   /*
+* Avoid pulling in this function for other image types since we are
+* very short on space on some boards.
+*/
+   if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL)) {
+   err = fat_size(filename, );
 if (err)
 goto end;
-
-   err = file_fat_read(filename, map_sysmem(spl_image->load_addr,
-spl_image->size), 0);
+   } else {
+   size = 0;
 }

+   load.read = spl_fit_read;
+   spl_set_bl_len(, ARCH_DMA_MINALIGN);
+   load.priv = (void *)filename;
+   err = spl_load(spl_image, bootdev, , size, 0);
+
  end:
  #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
-   if (err <= 0)
+   if (err < 0)
 printf("%s: error reading image %s, err - %d\n",
__func__, filename, err);


Do we still need this sort of #ifdef? I thought printf() would melt
away without SPL_LIBCOMMON_SUPPORT? I haven't looked though. Also it
isn't related to your patch.


From what I can tell, printf implementation is orthogonal to LIBCOMMON_SUPPORT.

--Sean


  #endif

-   return (err <= 0);
+   return err;
  }

  #if CONFIG_IS_ENABLED(OS_BOOT)
diff --git a/include/spl_load.h b/include/spl_load.h
index 65aa6bb4493..5e0460d956d 100644
--- a/include/spl_load.h
+++ b/include/spl_load.h
@@ -96,6 +96,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
   */
  #define SPL_LOAD_USERS \
 IS_ENABLED(CONFIG_SPL_FS_EXT4) + \
+   IS_ENABLED(CONFIG_SPL_FS_FAT) + \
 0

  #if SPL_LOAD_USERS > 1
diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c
index 01559e98c4f..333df2dfb53 100644
--- a/test/image/spl_load_fs.c
+++ b/test/image/spl_load_fs.c
@@ -425,8 +425,7 @@ static int spl_test_mmc(struct unit_test_state *uts, const 
char *test_name,
 if (spl_test_mmc_fs(uts, test_name, type, create_ext2, false))
 return CMD_RET_FAILURE;

-   if (type != IMX8 && type != LEGACY_LZMA &&
-   spl_test_mmc_fs(uts, test_name, type, create_fat, false))
+   if (spl_test_mmc_fs(uts, test_name, type, create_fat, false))
 return CMD_RET_FAILURE;

 if (type == LEGACY_LZMA)
--
2.37.1



Regards,
Simon




  1   2   >