Re: [PATCH] usb: gadget: usbhs: Add Renesas USBHS device driver

2024-07-23 Thread Mattijs Korpershoek
Hi Marek,

Sorry for the review delay and thank you for the patch.

On jeu., juin 20, 2024 at 02:55, Marek Vasut  
wrote:

> From: Vitaliy Vasylskyy 
>
> Add UDC driver for Renesas USBHS controller found in R-Car Gen3 SoCs.
> This is mostly ported from the Linux kernel, with additional porting
> glue. The code has been synchronized with 1b4861e32e46 ("Linux 6.9.3")
> and cleaned up and ported to DM since the original implementation by
> Vitaliy.
>
> Signed-off-by: Vitaliy Vasylskyy 
> Signed-off-by: Marek Vasut 
> ---
> Note that the driver does have a few checkpatch warnings in it, those
> also partly come from Linux.
> ---
> Cc: Jonas Karlman 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Miquel Raynal 
> Cc: Simon Glass 
> Cc: Tom Rini 
> Cc: Vitaliy Vasylskyy 

I've reviewed this by comparing this patch to the Linux stable 6.9.3
codebase located in drivers/usb/renesas_usbhs/ and the
phy driver (drivers/usb/renesas_usbhs/)

While I notice some differences, such as:
* no USB host support (no VBUS control support)
* no dma mapping control support
* no support for the older RCar controllers (rcar2)

This looks good overall.

Reviewed-by: Mattijs Korpershoek 

[...]


> ---
> -- 
> 2.43.0


[PATCH] env: mmc: Fix env loading with CONFIG_SYS_MMC_ENV_PART

2024-07-19 Thread Mattijs Korpershoek
When CONFIG_SYS_MMC_ENV_PART=2, the environment is loaded from
the USER partition (hwpart=0) instead of from the
BOOT1 partition (hwpart=2).

IS_ENABLED() cannot be used for non-boolean KConfig options.
Its documentation states:

> * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y',
> * 0 otherwise.

So in our case, IS_ENABLED(CONFIG_SYS_MMC_ENV_PART) evaluates to 0.

Because of this, the hwpart variable is never assigned and mmc_offset()
ends up switching back to the USER hwpart (0) instead of BOOT1 (2).

Fix it by using #define instead.

Tested with:

  # have CONFIG_SYS_MMC_ENV_PART=2 in defconfig
  # 1. Erase mmc0boot1
  => mmc dev 0 2
  => mmc erase 0 400
  => mmc read ${loadaddr} 0 400
  => md ${loadaddr} 4
  8200:      

  # 2. Restore default environment and save to MMC
  => env default -a -f
  => saveenv

  # 3. Read back mmc0boot1 and confirm the env is present
  => mmc read ${loadaddr} 0 400
  => md ${loadaddr} 4
  8200: 13e0632e 72646461 7469665f 3978303d  .c..addr_fit=0x9

Fixes: 5b4acb0ff79d ("env: mmc: Apply GPT only on eMMC user HW partition")
Signed-off-by: Mattijs Korpershoek 
---
 env/mmc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/env/mmc.c b/env/mmc.c
index 776df0786be5..0338aa6c56ad 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -110,8 +110,9 @@ static inline s64 mmc_offset(struct mmc *mmc, int copy)
int hwpart = 0;
int err;
 
-   if (IS_ENABLED(CONFIG_SYS_MMC_ENV_PART))
-   hwpart = mmc_get_env_part(mmc);
+#if defined(CONFIG_SYS_MMC_ENV_PART)
+   hwpart = mmc_get_env_part(mmc);
+#endif
 
 #if defined(CONFIG_ENV_MMC_PARTITION)
str = CONFIG_ENV_MMC_PARTITION;

---
base-commit: 45956736ac7c9c8b04522789c20fb45ff95a
change-id: 20240719-fix-mmc-env-boot1-a8d4b4512a29

Best regards,
-- 
Mattijs Korpershoek 



Re: [PATCH v2 02/21] sandbox: Fix a comment in os_find_u_boot()

2024-07-18 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On sam., juil. 13, 2024 at 08:00, Simon Glass  wrote:

> Fix a missing dot in a comment, since '..' is confusing.
>
> Signed-off-by: Simon Glass 

Reviewed-by: Mattijs Korpershoek 

> ---
>
> (no changes since v1)
>
>  arch/sandbox/cpu/os.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
> index 6a8a5e7b89b..1491d00504d 100644
> --- a/arch/sandbox/cpu/os.c
> +++ b/arch/sandbox/cpu/os.c
> @@ -964,7 +964,7 @@ int os_find_u_boot(char *fname, int maxlen, bool use_img,
>   p = strstr(fname, subdir);
>   if (p) {
>   if (*next_prefix)
> - /* e.g. ".../tpl/u-boot-spl"  to "../spl/u-boot-spl" */
> + /* e.g. ".../tpl/u-boot-spl"  to ".../spl/u-boot-spl" */
>   memcpy(p + 1, next_prefix, strlen(next_prefix));
>   else
>   /* e.g. ".../spl/u-boot" to ".../u-boot" */
> -- 
> 2.34.1


Re: [PATCH v2 01/21] sandbox: Use const in os_jump_to_file()

2024-07-18 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On sam., juil. 13, 2024 at 08:00, Simon Glass  wrote:

> The argument array is not changed by the callee, so mark it const.
>
> Signed-off-by: Simon Glass 

Reviewed-by: Mattijs Korpershoek 

> ---
>
> (no changes since v1)
>
>  arch/sandbox/cpu/os.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
> index d7869b2e368..6a8a5e7b89b 100644
> --- a/arch/sandbox/cpu/os.c
> +++ b/arch/sandbox/cpu/os.c
> @@ -808,7 +808,7 @@ static int make_exec(char *fname, const void *data, int 
> size)
>   * @count: Number of arguments in @add_args
>   * Return: 0 if OK, -ENOMEM if out of memory
>   */
> -static int add_args(char ***argvp, char *add_args[], int count)
> +static int add_args(char ***argvp, const char *add_args[], int count)
>  {
>   char **argv, **ap;
>   int argc;
> @@ -859,7 +859,7 @@ static int os_jump_to_file(const char *fname, bool 
> delete_it)
>   struct sandbox_state *state = state_get_current();
>   char mem_fname[30];
>   int fd, err;
> - char *extra_args[5];
> + const char *extra_args[5];
>   char **argv = state->argv;
>   int argc;
>  #ifdef DEBUG
> -- 
> 2.34.1


Re: [PATCH] cmd: move CMD_DHCP6 options beneath CMD_DHCP6

2024-07-17 Thread Mattijs Korpershoek
Hi Heinrich,

Thank you for the patch.

On mer., juil. 17, 2024 at 16:54, Heinrich Schuchardt 
 wrote:

> All Kconfig options that depend on CONFIG_CMD_DHCP6 should immediately
> follow it.
>
> Signed-off-by: Heinrich Schuchardt 

Reviewed-by: Mattijs Korpershoek 

> ---
>  cmd/Kconfig | 34 +-
>  1 file changed, 17 insertions(+), 17 deletions(-)
>
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index 0cf0d8ad8ab..323e473cd64 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -1810,6 +1810,23 @@ config CMD_DHCP6
> Will perform 4-message exchange with DHCPv6 server, requesting
> the minimum required options to TFTP boot. Complies with RFC 8415.
>  
> +if CMD_DHCP6
> +
> +config DHCP6_PXE_CLIENTARCH
> + hex
> + default 0x16 if ARM64
> + default 0x15 if ARM
> + default 0xFF
> +
> +config DHCP6_PXE_DHCP_OPTION
> + bool "Request & store 'pxe_configfile' from DHCP6 server"
> +
> +config DHCP6_ENTERPRISE_ID
> + int "Enterprise ID to send in DHCPv6 Vendor Class Option"
> + default 0
> +
> +endif
> +
>  config BOOTP_MAY_FAIL
>   bool "Allow for the BOOTP/DHCP server to not be found"
>   depends on CMD_BOOTP
> @@ -1927,23 +1944,6 @@ config BOOTP_VCI_STRING
>   default "U-Boot.arm" if ARM
>   default "U-Boot"
>  
> -if CMD_DHCP6
> -
> -config DHCP6_PXE_CLIENTARCH
> - hex
> - default 0x16 if ARM64
> - default 0x15 if ARM
> - default 0xFF
> -
> -config DHCP6_PXE_DHCP_OPTION
> - bool "Request & store 'pxe_configfile' from DHCP6 server"
> -
> -config DHCP6_ENTERPRISE_ID
> - int "Enterprise ID to send in DHCPv6 Vendor Class Option"
> - default 0
> -
> -endif
> -
>  config CMD_TFTPBOOT
>   bool "tftpboot"
>   default y
> -- 
> 2.45.2


Re: [PATCH v2 14/14] doc: Describe the bootstd settings

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On mar., juil. 16, 2024 at 08:04, Simon Glass  wrote:

> The bootstd node provides some configuration properties. Add these to
> the documentation.
>
> Signed-off-by: Simon Glass 
> Reviewed-by: Quentin Schulz 

Reviewed-by: Mattijs Korpershoek 

> ---
>
> (no changes since v1)
>
>  doc/develop/bootstd/overview.rst | 13 +
>  1 file changed, 13 insertions(+)
>
> diff --git a/doc/develop/bootstd/overview.rst 
> b/doc/develop/bootstd/overview.rst
> index 4a55b7da00a..d92a649beb0 100644
> --- a/doc/develop/bootstd/overview.rst
> +++ b/doc/develop/bootstd/overview.rst
> @@ -406,6 +406,19 @@ You should probably also enable 
> `CONFIG_BOOTSTD_DEFAULTS`, which provides
>  several filesystem and network features (if `CONFIG_NET` is enabled) so that
>  a good selection of boot options is available.
>  
> +Some devicetree properties are supported in the bootstd node when
> +`CONFIG_BOOTSTD_FULL` is enabled:
> +
> +filename-prefixes
> +List of prefixes to use when searching for files on block devices. 
> This
> +defaults to {"/", "/boot/"} if not provided.
> +
> +bootdev-order
> +Lists the bootdev ordering to use. Note that the deprecated
> +`boot_targets` environment variable overrides this, if present.
> +
> +theme (subnode)
> +Sets the theme to use for menus. See :doc:`/develop/expo`.
>  
>  Available bootmeth drivers
>  --
> -- 
> 2.34.1


Re: [PATCH v2 13/14] boot: Correct indentation in efi bootmeth

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On mar., juil. 16, 2024 at 08:04, Simon Glass  wrote:

> Fix a minor indentation / whitespace problem in a comment.
>
> Signed-off-by: Simon Glass 
> Reviewed-by: Heinrich Schuchardt 
> Reviewed-by: Quentin Schulz 

Reviewed-by: Mattijs Korpershoek 

> ---
>
> (no changes since v1)
>
>  boot/bootmeth_efi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c
> index 56a6e47f5b2..39232eb2e25 100644
> --- a/boot/bootmeth_efi.c
> +++ b/boot/bootmeth_efi.c
> @@ -265,7 +265,7 @@ static int distro_efi_read_bootflow_net(struct bootflow 
> *bflow)
>   return log_msg_ret("sz", -EINVAL);
>   bflow->size = size;
>  
> -/* bootfile should be setup by dhcp*/
> + /* bootfile should be setup by dhcp */
>   bootfile_name = env_get("bootfile");
>   if (!bootfile_name)
>   return log_msg_ret("bootfile_name", ret);
> -- 
> 2.34.1


Re: [PATCH v2 12/14] doc: Add a link to VBE from the bootstd docs

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On mar., juil. 16, 2024 at 08:04, Simon Glass  wrote:

> Link to this page to make it easier to find the VBE docs.
>
> Signed-off-by: Simon Glass 
> Reviewed-by: Heinrich Schuchardt 
> Reviewed-by: Quentin Schulz 

Reviewed-by: Mattijs Korpershoek 

> ---
>
> (no changes since v1)
>
>  doc/develop/bootstd/overview.rst | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/doc/develop/bootstd/overview.rst 
> b/doc/develop/bootstd/overview.rst
> index e4924b55ae7..4a55b7da00a 100644
> --- a/doc/develop/bootstd/overview.rst
> +++ b/doc/develop/bootstd/overview.rst
> @@ -416,7 +416,7 @@ Bootmeth drivers are provided for booting from various 
> media:
> - :doc:`extlinux / syslinux ` boot from a network (PXE)
> - :doc:`U-Boot scripts 

Re: [PATCH v2 11/14] doc: Add a description for bootmeth_script

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On mar., juil. 16, 2024 at 08:04, Simon Glass  wrote:

> Add documentation for the script bootmeth.
>
> Signed-off-by: Simon Glass 
> Reviewed-by: Quentin Schulz 

Reviewed-by: Mattijs Korpershoek 

> ---
>
> Changes in v2:
> - Adjustments from Heinrich's comments
>
>  doc/develop/bootstd/index.rst|  1 +
>  doc/develop/bootstd/overview.rst |  2 +-
>  doc/develop/bootstd/script.rst   | 52 
>  3 files changed, 54 insertions(+), 1 deletion(-)
>  create mode 100644 doc/develop/bootstd/script.rst
>
> diff --git a/doc/develop/bootstd/index.rst b/doc/develop/bootstd/index.rst
> index 2c5d2d3fade..9d35b567d55 100644
> --- a/doc/develop/bootstd/index.rst
> +++ b/doc/develop/bootstd/index.rst
> @@ -11,4 +11,5 @@ Standard Boot
> pxelinux
> qfw
> cros
> +   script
> sandbox
> diff --git a/doc/develop/bootstd/overview.rst 
> b/doc/develop/bootstd/overview.rst
> index add054f3088..e4924b55ae7 100644
> --- a/doc/develop/bootstd/overview.rst
> +++ b/doc/develop/bootstd/overview.rst
> @@ -414,7 +414,7 @@ Bootmeth drivers are provided for booting from various 
> media:
>  
> - :doc:`extlinux / syslinux ` boot from a storage device
> - :doc:`extlinux / syslinux ` boot from a network (PXE)
> -   - U-Boot scripts from disk, network or SPI flash
> +   - :doc:`U-Boot scripts 

Re: [PATCH v2 10/14] bootstd: Correct handling of script from network

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On mar., juil. 16, 2024 at 08:04, Simon Glass  wrote:

> When reading a script from a network, no block device is available.
> Update the implementation to support this correctly, avoiding setting
> environment variables which relate only to block devices.
>
> Signed-off-by: Simon Glass 

Reviewed-by: Mattijs Korpershoek 

> ---
>
> (no changes since v1)
>
>  boot/bootmeth_script.c | 51 +-
>  1 file changed, 31 insertions(+), 20 deletions(-)
>
> diff --git a/boot/bootmeth_script.c b/boot/bootmeth_script.c
> index 24da47c7259..c5cbf18c2e6 100644
> --- a/boot/bootmeth_script.c
> +++ b/boot/bootmeth_script.c
> @@ -185,31 +185,42 @@ static int script_set_bootflow(struct udevice *dev, 
> struct bootflow *bflow,
>  
>  static int script_boot(struct udevice *dev, struct bootflow *bflow)
>  {
> - struct blk_desc *desc = dev_get_uclass_plat(bflow->blk);
> + struct blk_desc *desc;
>   ulong addr;
>   int ret = 0;
>  
> - if (desc->uclass_id == UCLASS_USB) {
> - ret = env_set("devtype", "usb");
> + if (bflow->blk) {
> + desc = dev_get_uclass_plat(bflow->blk);
> + if (desc->uclass_id == UCLASS_USB) {
> + ret = env_set("devtype", "usb");
> + } else {
> + /*
> +  * If the uclass is AHCI, but the driver is ATA
> +  * (not scsi), set devtype to sata
> +  */
> + if (IS_ENABLED(CONFIG_SATA) &&
> + desc->uclass_id == UCLASS_AHCI)
> + ret = env_set("devtype", "sata");
> + else
> + ret = env_set("devtype", 
> blk_get_devtype(bflow->blk));
> + }
> + if (!ret)
> + ret = env_set_hex("devnum", desc->devnum);
> + if (!ret)
> + ret = env_set_hex("distro_bootpart", bflow->part);
> + if (!ret)
> + ret = env_set("prefix", bflow->subdir);
> + if (!ret && IS_ENABLED(CONFIG_ARCH_SUNXI) &&
> + !strcmp("mmc", blk_get_devtype(bflow->blk)))
> + ret = env_set_hex("mmc_bootdev", desc->devnum);
>   } else {
> - /* If the uclass is AHCI, but the driver is ATA
> -  * (not scsi), set devtype to sata
> -  */
> - if (IS_ENABLED(CONFIG_SATA) &&
> - desc->uclass_id == UCLASS_AHCI)
> - ret = env_set("devtype", "sata");
> - else
> - ret = env_set("devtype", blk_get_devtype(bflow->blk));
> + const struct udevice *media = dev_get_parent(bflow->dev);
> +
> + ret = env_set("devtype",
> +   uclass_get_name(device_get_uclass_id(media)));
> + if (!ret)
> + ret = env_set_hex("devnum", dev_seq(media));
>   }
> - if (!ret)
> - ret = env_set_hex("devnum", desc->devnum);
> - if (!ret)
> - ret = env_set_hex("distro_bootpart", bflow->part);
> - if (!ret)
> - ret = env_set("prefix", bflow->subdir);
> - if (!ret && IS_ENABLED(CONFIG_ARCH_SUNXI) &&
> - !strcmp("mmc", blk_get_devtype(bflow->blk)))
> - ret = env_set_hex("mmc_bootdev", desc->devnum);
>   if (ret)
>   return log_msg_ret("env", ret);
>  
> -- 
> 2.34.1


Re: [PATCH v2 09/14] bootstd: Tidy up comments on the boothmeth drivers

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On mar., juil. 16, 2024 at 08:04, Simon Glass  wrote:

> Fix a typo in the comment and add one to the EFI driver too.
>
> Signed-off-by: Simon Glass 
> Reviewed-by: Heinrich Schuchardt 
> Reviewed-by: Quentin Schulz 

Reviewed-by: Mattijs Korpershoek 

> ---
>
> (no changes since v1)
>
>  boot/bootmeth_efi.c  | 1 +
>  boot/bootmeth_extlinux.c | 2 +-
>  boot/bootmeth_script.c   | 2 +-
>  3 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c
> index 5a4c125835a..56a6e47f5b2 100644
> --- a/boot/bootmeth_efi.c
> +++ b/boot/bootmeth_efi.c
> @@ -394,6 +394,7 @@ static const struct udevice_id distro_efi_bootmeth_ids[] 
> = {
>   { }
>  };
>  
> +/* Put a number before 'efi' to provide a default ordering */
>  U_BOOT_DRIVER(bootmeth_4efi) = {
>   .name   = "bootmeth_efi",
>   .id = UCLASS_BOOTMETH,
> diff --git a/boot/bootmeth_extlinux.c b/boot/bootmeth_extlinux.c
> index 9b55686948f..fbb05ef928e 100644
> --- a/boot/bootmeth_extlinux.c
> +++ b/boot/bootmeth_extlinux.c
> @@ -183,7 +183,7 @@ static const struct udevice_id extlinux_bootmeth_ids[] = {
>   { }
>  };
>  
> -/* Put an number before 'extlinux' to provide a default ordering */
> +/* Put a number before 'extlinux' to provide a default ordering */
>  U_BOOT_DRIVER(bootmeth_1extlinux) = {
>   .name   = "bootmeth_extlinux",
>   .id = UCLASS_BOOTMETH,
> diff --git a/boot/bootmeth_script.c b/boot/bootmeth_script.c
> index 0e05d28d4d9..24da47c7259 100644
> --- a/boot/bootmeth_script.c
> +++ b/boot/bootmeth_script.c
> @@ -250,7 +250,7 @@ static const struct udevice_id script_bootmeth_ids[] = {
>   { }
>  };
>  
> -/* Put an number before 'script' to provide a default ordering */
> +/* Put a number before 'script' to provide a default ordering */
>  U_BOOT_DRIVER(bootmeth_2script) = {
>   .name   = "bootmeth_script",
>   .id = UCLASS_BOOTMETH,
> -- 
> 2.34.1


Re: [PATCH v2 08/14] doc: Add a description for bootmeth_sandbox

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On mar., juil. 16, 2024 at 08:04, Simon Glass  wrote:

> Add documentation for the sandbox bootmeth.
>
> Fix up the compatible string to drop the 'extlinux' part, which is not
> relevant to this bootmeth.
>
> Signed-off-by: Simon Glass 
> Reviewed-by: Quentin Schulz 

Reviewed-by: Mattijs Korpershoek 

> ---
>
> Changes in v2:
> - Adjustments from Heinrich's comments
>
>  boot/bootmeth_sandbox.c  |  2 +-
>  doc/develop/bootstd/index.rst|  1 +
>  doc/develop/bootstd/overview.rst |  1 +
>  doc/develop/bootstd/sandbox.rst  | 17 +
>  4 files changed, 20 insertions(+), 1 deletion(-)
>  create mode 100644 doc/develop/bootstd/sandbox.rst
>
> diff --git a/boot/bootmeth_sandbox.c b/boot/bootmeth_sandbox.c
> index 0bc8f688e30..26c713bb5f3 100644
> --- a/boot/bootmeth_sandbox.c
> +++ b/boot/bootmeth_sandbox.c
> @@ -55,7 +55,7 @@ static struct bootmeth_ops sandbox_bootmeth_ops = {
>  };
>  
>  static const struct udevice_id sandbox_bootmeth_ids[] = {
> - { .compatible = "u-boot,sandbox-extlinux" },
> + { .compatible = "u-boot,sandbox-bootmeth" },
>   { }
>  };
>  
> diff --git a/doc/develop/bootstd/index.rst b/doc/develop/bootstd/index.rst
> index 69fd3c2d2eb..2c5d2d3fade 100644
> --- a/doc/develop/bootstd/index.rst
> +++ b/doc/develop/bootstd/index.rst
> @@ -11,3 +11,4 @@ Standard Boot
> pxelinux
> qfw
> cros
> +   sandbox
> diff --git a/doc/develop/bootstd/overview.rst 
> b/doc/develop/bootstd/overview.rst
> index 9b50b5593c4..add054f3088 100644
> --- a/doc/develop/bootstd/overview.rst
> +++ b/doc/develop/bootstd/overview.rst
> @@ -420,6 +420,7 @@ Bootmeth drivers are provided for booting from various 
> media:
> - :doc:`ChromiumOS ` ChromiumOS boot from a disk
> - EFI boot using boot manager
> - :doc:`QFW `: QEMU firmware interface
> +   - :doc:`sandbox ` used only for testing
>  
>  Each driver is controlled by a Kconfig option. If no bootmeth driver is
>  selected by a compatible string in the devicetree, all available bootmeth
> diff --git a/doc/develop/bootstd/sandbox.rst b/doc/develop/bootstd/sandbox.rst
> new file mode 100644
> index 000..a90c1accc84
> --- /dev/null
> +++ b/doc/develop/bootstd/sandbox.rst
> @@ -0,0 +1,17 @@
> +.. SPDX-License-Identifier: GPL-2.0+:
> +
> +Sandbox Bootmeth
> +
> +
> +The sandbox bootmeth is only used for testing. It does not provide any 
> facility
> +for booting an OS. While sandbox can do all the processing before the actual
> +boot, it is not connected in this bootmeth.
> +
> +When invoked on a bootdev, this bootmeth pretends to find a bootflow and 
> creates
> +the associated structure.
> +
> +When the bootflow is booted, the bootmeth returns -EENOTSUPP indicating that 
> it
> +is not supported.
> +
> +The compatible string "u-boot,sandbox-bootmeth" is used for the driver. It 
> is present
> +if `CONFIG_BOOTMETH_SANDBOX` is enabled.
> -- 
> 2.34.1


Re: [PATCH v2 07/14] doc: Add a description for bootmeth_cros

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On mar., juil. 16, 2024 at 08:04, Simon Glass  wrote:

> Add documentation for the cros bootmeth.
>
> Signed-off-by: Simon Glass 
> Reviewed-by: Quentin Schulz 

Reviewed-by: Mattijs Korpershoek 

> ---
>
> Changes in v2:
> - Adjustments from Heinrich's comments
>
>  doc/develop/bootstd/cros.rst | 33 
>  doc/develop/bootstd/index.rst|  1 +
>  doc/develop/bootstd/overview.rst |  1 +
>  3 files changed, 35 insertions(+)
>  create mode 100644 doc/develop/bootstd/cros.rst
>
> diff --git a/doc/develop/bootstd/cros.rst b/doc/develop/bootstd/cros.rst
> new file mode 100644
> index 000..92b83729150
> --- /dev/null
> +++ b/doc/develop/bootstd/cros.rst
> @@ -0,0 +1,33 @@
> +.. SPDX-License-Identifier: GPL-2.0+:
> +
> +ChromiumOS Bootmeth
> +===
> +
> +ChromiumOS provides a mechanism for booting its Operating System from a block
> +device, described
> +`here 
> <https://www.chromium.org/chromium-os/chromiumos-design-docs/verified-boot/>`_.
> +
> +U-Boot includes support for reading the associated data structures from the
> +device and identifying a bootable ChromiumOS image. This structure includes 
> the
> +kernel itself, boot arguments (kernel command line), as well as the x86 setup
> +block (for x86 only).
> +
> +When invoked on a bootdev, this bootmeth searches for kernel partitions with
> +the appropriate GUID (Globally Unique Identifier). When found, the 
> information
> +is loaded and a bootflow is created.
> +
> +When the bootflow is booted, the bootmeth reads the kernel and boot 
> arguments.
> +It then boots the kernel using zboot (on x86) or bootm (on ARM). The boot
> +arguments are adjusted to replace %U with the UUID of the selected kernel
> +partition. This results in the correct root disk being used, which is the 
> next
> +partition after the kernel partition.
> +
> +For ARM, a :doc:`/usage/fit/index` is used. The `CONFIG_FIT_BEST_MATCH` 
> option
> +must be enabled for U-Boot to select the correct devicetree to boot with.
> +
> +Note that a ChromiumOS image typically has two copies of the Operating 
> System,
> +each with its own kernel and root disk. There is no initial ramdisk (initrd).
> +This means that this bootmeth typically locates two separate images.
> +
> +The compatible string "u-boot,cros" is used for the driver. It is present
> +if `CONFIG_BOOTMETH_CROS` is enabled.
> diff --git a/doc/develop/bootstd/index.rst b/doc/develop/bootstd/index.rst
> index f8fce7207ce..69fd3c2d2eb 100644
> --- a/doc/develop/bootstd/index.rst
> +++ b/doc/develop/bootstd/index.rst
> @@ -10,3 +10,4 @@ Standard Boot
> extlinux
> pxelinux
> qfw
> +   cros
> diff --git a/doc/develop/bootstd/overview.rst 
> b/doc/develop/bootstd/overview.rst
> index f23e344546d..9b50b5593c4 100644
> --- a/doc/develop/bootstd/overview.rst
> +++ b/doc/develop/bootstd/overview.rst
> @@ -417,6 +417,7 @@ Bootmeth drivers are provided for booting from various 
> media:
> - U-Boot scripts from disk, network or SPI flash
> - EFI boot using bootefi from disk
> - VBE
> +   - :doc:`ChromiumOS ` ChromiumOS boot from a disk
> - EFI boot using boot manager
> - :doc:`QFW `: QEMU firmware interface
>  
> -- 
> 2.34.1


Re: [PATCH v2 06/14] doc: Add a description for bootmeth_qfw

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On mar., juil. 16, 2024 at 08:04, Simon Glass  wrote:

> Add documentation for the qfw bootmeth.
>
> Fix up the compatible string to drop the 'extlinux' part, which is not
> relevant to this bootmeth.
>
> Signed-off-by: Simon Glass 
> Reviewed-by: Quentin Schulz 
> ---
>
> Changes in v2:
> - Adjustments from Heinrich's comments
>
>  boot/bootmeth_qfw.c  |  2 +-
>  doc/develop/bootstd/index.rst|  1 +
>  doc/develop/bootstd/overview.rst |  1 +
>  doc/develop/bootstd/qfw.rst  | 20 
>  4 files changed, 23 insertions(+), 1 deletion(-)
>  create mode 100644 doc/develop/bootstd/qfw.rst
>
> diff --git a/boot/bootmeth_qfw.c b/boot/bootmeth_qfw.c
> index dfaa944594e..2f8e00cf350 100644
> --- a/boot/bootmeth_qfw.c
> +++ b/boot/bootmeth_qfw.c
> @@ -88,7 +88,7 @@ static struct bootmeth_ops qfw_bootmeth_ops = {
>  };
>  
>  static const struct udevice_id qfw_bootmeth_ids[] = {
> - { .compatible = "u-boot,qfw-extlinux" },
> + { .compatible = "u-boot,qfw-bootmeth" },
>   { }
>  };
>  
> diff --git a/doc/develop/bootstd/index.rst b/doc/develop/bootstd/index.rst
> index 5052afe448f..f8fce7207ce 100644
> --- a/doc/develop/bootstd/index.rst
> +++ b/doc/develop/bootstd/index.rst
> @@ -9,3 +9,4 @@ Standard Boot
> overview
> extlinux
> pxelinux
> +   qfw
> diff --git a/doc/develop/bootstd/overview.rst 
> b/doc/develop/bootstd/overview.rst
> index b9b45f1e7a7..f23e344546d 100644
> --- a/doc/develop/bootstd/overview.rst
> +++ b/doc/develop/bootstd/overview.rst
> @@ -418,6 +418,7 @@ Bootmeth drivers are provided for booting from various 
> media:
> - EFI boot using bootefi from disk
> - VBE
> - EFI boot using boot manager
> +   - :doc:`QFW `: QEMU firmware interface
>  
>  Each driver is controlled by a Kconfig option. If no bootmeth driver is
>  selected by a compatible string in the devicetree, all available bootmeth
> diff --git a/doc/develop/bootstd/qfw.rst b/doc/develop/bootstd/qfw.rst
> new file mode 100644
> index 000..b2ff1364fd8
> --- /dev/null
> +++ b/doc/develop/bootstd/qfw.rst
> @@ -0,0 +1,20 @@
> +.. SPDX-License-Identifier: GPL-2.0+:
> +
> +QFW Bootmeth
> +
> +
> +`QEMU https://www.qemu.org/>`_ is a system emulator which is able to boot
> +Operating Systems. QEMU provides specific support for booting an OS image
> +provided on the QEMU command line.
> +
> +When invoked on a bootdev for UCLASS_QFW, this bootmeth reads the kernel
> +provided by the QEMU `-kernel` argument, the initial ramdisk and provided by

There is a "and" which should be removed here:
ramdisk and provided by -> ramdisk provided by

With that fixed:

Reviewed-by: Mattijs Korpershoek 


> +`-initrd` and the boot arguments (command line) provided by `-append` into
> +memory ready for booting.
> +
> +When the bootflow is booted, the bootmeth tries the `booti` command first, 
> then
> +falls back to the `bootz` command. U-Boot's 'control' devicetree is passed
> +through to the kernel.
> +
> +The compatible string "u-boot,qfw-bootmeth" is used for the driver. It is
> +present if `CONFIG_QFW` is enabled.
> -- 
> 2.34.1


Re: [PATCH v2 05/14] doc: Add a description for bootmeth_pxe

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On mar., juil. 16, 2024 at 08:04, Simon Glass  wrote:

> Add documentation for the pxe bootmeth.
>
> Signed-off-by: Simon Glass 
> Reviewed-by: Quentin Schulz 

Reviewed-by: Mattijs Korpershoek 

Nitpick: now that pxelinux.rst exist, can we link to this file in
extlinux.rst ?

> ---
>
> Changes in v2:
> - Adjustments from Heinrich's comments
>
>  doc/develop/bootstd/index.rst|  1 +
>  doc/develop/bootstd/overview.rst |  2 +-
>  doc/develop/bootstd/pxelinux.rst | 27 +++
>  3 files changed, 29 insertions(+), 1 deletion(-)
>  create mode 100644 doc/develop/bootstd/pxelinux.rst
>
> diff --git a/doc/develop/bootstd/index.rst b/doc/develop/bootstd/index.rst
> index 5bbb3d633a3..5052afe448f 100644
> --- a/doc/develop/bootstd/index.rst
> +++ b/doc/develop/bootstd/index.rst
> @@ -8,3 +8,4 @@ Standard Boot
>  
> overview
> extlinux
> +   pxelinux
> diff --git a/doc/develop/bootstd/overview.rst 
> b/doc/develop/bootstd/overview.rst
> index 7af159b9ca8..b9b45f1e7a7 100644
> --- a/doc/develop/bootstd/overview.rst
> +++ b/doc/develop/bootstd/overview.rst
> @@ -413,7 +413,7 @@ Available bootmeth drivers
>  Bootmeth drivers are provided for booting from various media:
>  
> - :doc:`extlinux / syslinux ` boot from a storage device
> -   - extlinux boot from a network (PXE)
> +   - :doc:`extlinux / syslinux ` boot from a network (PXE)
> - U-Boot scripts from disk, network or SPI flash
> - EFI boot using bootefi from disk
> - VBE
> diff --git a/doc/develop/bootstd/pxelinux.rst 
> b/doc/develop/bootstd/pxelinux.rst
> new file mode 100644
> index 000..a4e559160ca
> --- /dev/null
> +++ b/doc/develop/bootstd/pxelinux.rst
> @@ -0,0 +1,27 @@
> +.. SPDX-License-Identifier: GPL-2.0+:
> +
> +PXE Bootmeth
> +
> +
> +PXE (Preboot eXecution-Environment) provides a way to boot an operating 
> system
> +over a network interface. The PXE bootmeth supports PXELINUX and allows 
> U-Boot to
> +provide a menu of possible Operating Systems from which the user can choose.
> +
> +U-Boot includes a parser for the `extlinux.conf` file described
> +`here 
> <https://uapi-group.org/specifications/specs/boot_loader_specification>`_.
> +It consists primarily of a list of named operating systems along with the
> +kernel, initial ramdisk and other settings. The file is retrieved from a 
> network
> +server using the TFTP protocol.
> +
> +When invoked on a bootdev, this bootmeth searches for the file and creates a
> +bootflow if found. See
> +`PXELINUX <https://wiki.syslinux.org/wiki/index.php?title=PXELINUX>`_ for
> +a full description of the search procedure.
> +
> +When the bootflow is booted, the bootmeth calls pxe_setup_ctx() to set up the
> +context, then pxe_process() to process the file. Depending on the contents, 
> this
> +may boot an Operating System or provide a list of options to the user, 
> perhaps
> +with a timeout.
> +
> +The compatible string "u-boot,extlinux-pxe" is used for the driver. It is
> +present if `CONFIG_BOOTMETH_EXTLINUX_PXE` is enabled.
> -- 
> 2.34.1


Re: [PATCH v2 04/14] doc: Add a description for bootmeth_extlinux

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On mar., juil. 16, 2024 at 08:04, Simon Glass  wrote:

> Add documentation for the extlinux bootmeth.
>
> Signed-off-by: Simon Glass 
> Reviewed-by: Quentin Schulz 

Reviewed-by: Mattijs Korpershoek 

Minor nitpicks below, feel free to ignore or apply.

> ---
>
> Changes in v2:
> - Adjustments from Heinrich's comments
>
>  doc/develop/bootstd/extlinux.rst | 28 
>  doc/develop/bootstd/index.rst|  1 +
>  doc/develop/bootstd/overview.rst |  4 ++--
>  3 files changed, 31 insertions(+), 2 deletions(-)
>  create mode 100644 doc/develop/bootstd/extlinux.rst
>
> diff --git a/doc/develop/bootstd/extlinux.rst 
> b/doc/develop/bootstd/extlinux.rst
> new file mode 100644
> index 000..d87730410ee
> --- /dev/null
> +++ b/doc/develop/bootstd/extlinux.rst
> @@ -0,0 +1,28 @@
> +.. SPDX-License-Identifier: GPL-2.0+:
> +
> +Extlinux Bootmeth
> +=
> +
> +`Extlinux 
> <https://uapi-group.org/specifications/specs/boot_loader_specification>`_
> +(sometimes called syslinux) allows U-Boot to provide a menu of available
> +operating systems from which the user can choose.
> +
> +U-Boot includes a parser for the `extlinux.conf` file. It consists primarily 
> of
> +a list of named operating systems along with the kernel, initial ramdisk and
> +other settings. The file is stored in the `extlinux/` subdirectory, possibly
> +under the `boot/` subdirectory. This list of prefixes ({"/", "/boot"} by

Can the prefixes also be surrounded by `` (`{"/", "boot"`} to insist
that this is "code listing" as well ?

> +default) can be selected with the `filename-prefixes` property in the bootstd
> +device.
> +
> +Note that the PXE bootmeth uses the same file format, but in a network 
> context.
> +
> +When invoked on a bootdev, this bootmeth searches for the file and creates a
> +bootflow if found.
> +
> +When the bootflow is booted, the bootmeth calls pxe_setup_ctx() to set up the
> +context, then pxe_process() to process the file. Depending on the contents, 
> this

same for pxe_setup_ctx and pxe_process

> +may boot an operating system or provide a list of options to the user, 
> perhaps
> +with a timeout.
> +
> +The compatible string "u-boot,extlinux" is used for the driver. It is present
> +if `CONFIG_BOOTMETH_EXTLINUX` is enabled.
> diff --git a/doc/develop/bootstd/index.rst b/doc/develop/bootstd/index.rst
> index f4f87c7787c..5bbb3d633a3 100644
> --- a/doc/develop/bootstd/index.rst
> +++ b/doc/develop/bootstd/index.rst
> @@ -7,3 +7,4 @@ Standard Boot
> :maxdepth: 2
>  
> overview
> +   extlinux
> diff --git a/doc/develop/bootstd/overview.rst 
> b/doc/develop/bootstd/overview.rst
> index d5051e986bb..7af159b9ca8 100644
> --- a/doc/develop/bootstd/overview.rst
> +++ b/doc/develop/bootstd/overview.rst
> @@ -410,9 +410,9 @@ a good selection of boot options is available.
>  Available bootmeth drivers
>  --
>  
> -Bootmeth drivers are provided for:
> +Bootmeth drivers are provided for booting from various media:
>  
> -   - extlinux / syslinux boot from a disk
> +   - :doc:`extlinux / syslinux ` boot from a storage device
> - extlinux boot from a network (PXE)
> - U-Boot scripts from disk, network or SPI flash
> - EFI boot using bootefi from disk
> -- 
> 2.34.1


Re: [PATCH v2 03/14] doc: Mention automatic binding of bootmeths

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On mar., juil. 16, 2024 at 08:04, Simon Glass  wrote:

> Add a note about how bootmeth drivers are instantiated.
>
> Signed-off-by: Simon Glass 
> Suggested-by: Heinrich Schuchardt 

Reviewed-by: Mattijs Korpershoek 

> ---
>
> Changes in v2:
> - Add new patch to mention automatic binding of bootmeths
>
>  doc/develop/bootstd/overview.rst | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/doc/develop/bootstd/overview.rst 
> b/doc/develop/bootstd/overview.rst
> index 761f61a573b..d5051e986bb 100644
> --- a/doc/develop/bootstd/overview.rst
> +++ b/doc/develop/bootstd/overview.rst
> @@ -419,6 +419,9 @@ Bootmeth drivers are provided for:
> - VBE
> - EFI boot using boot manager
>  
> +Each driver is controlled by a Kconfig option. If no bootmeth driver is
> +selected by a compatible string in the devicetree, all available bootmeth
> +drivers are bound automatically.
>  
>  Command interface
>  -
> -- 
> 2.34.1


Re: [PATCH v2 02/14] doc: Move bootstd into its own directory

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On mar., juil. 16, 2024 at 08:04, Simon Glass  wrote:

> Before adding more files, move the bootstd docs into a new directory,
> with an index.
>
> Signed-off-by: Simon Glass 
> Reviewed-by: Quentin Schulz 

Reviewed-by: Mattijs Korpershoek 

> ---
>
> (no changes since v1)
>
>  MAINTAINERS   |  2 +-
>  doc/board/starfive/milk-v_mars_cm.rst |  2 +-
>  doc/develop/board_best_practices.rst  |  2 +-
>  doc/develop/bootstd/index.rst |  9 +
>  doc/develop/{bootstd.rst => bootstd/overview.rst} | 14 +++---
>  doc/develop/index.rst |  2 +-
>  doc/usage/cmd/bootdev.rst |  2 +-
>  doc/usage/cmd/bootflow.rst|  2 +-
>  doc/usage/cmd/bootmeth.rst|  2 +-
>  doc/usage/environment.rst |  2 +-
>  10 files changed, 24 insertions(+), 15 deletions(-)
>  create mode 100644 doc/develop/bootstd/index.rst
>  rename doc/develop/{bootstd.rst => bootstd/overview.rst} (99%)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 9bee9284cca..86b830aa997 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -927,7 +927,7 @@ F:boot/bootmeth*.c
>  F:   boot/bootstd.c
>  F:   cmd/bootdev.c
>  F:   cmd/bootflow.c
> -F:   doc/develop/bootstd.rst
> +F:   doc/develop/bootstd/
>  F:   doc/usage/bootdev.rst
>  F:   doc/usage/bootflow.rst
>  F:   doc/usage/bootmeth.rst
> diff --git a/doc/board/starfive/milk-v_mars_cm.rst 
> b/doc/board/starfive/milk-v_mars_cm.rst
> index b31de6043bb..52d4e5e9098 100644
> --- a/doc/board/starfive/milk-v_mars_cm.rst
> +++ b/doc/board/starfive/milk-v_mars_cm.rst
> @@ -89,7 +89,7 @@ provide a default value.
>  
>  The variable *$fdtfile* is used in the boot process to automatically load
>  a device-tree provided by the operating system. For details of the boot
> -process refer to the :doc:`U-Boot Standard Boot <../../../develop/bootstd>`
> +process refer to the :doc:`/develop/bootstd/index`
>  description.
>  
>  Boot source selection
> diff --git a/doc/develop/board_best_practices.rst 
> b/doc/develop/board_best_practices.rst
> index f44401eab7d..09632c80ce7 100644
> --- a/doc/develop/board_best_practices.rst
> +++ b/doc/develop/board_best_practices.rst
> @@ -7,7 +7,7 @@ In addition to the regular best practices such as using 
> :doc:`checkpatch` and
>  following the :doc:`docstyle` and the :doc:`codingstyle` there are some 
> things
>  which are specific to creating a new board port.
>  
> -* Implement :doc:`bootstd` to ensure that most operating systems will be
> +* Implement :doc:`bootstd/index` to ensure that most operating systems will 
> be
>supported by the platform.
>  
>  * The platform defconfig file must be generated via `make savedefconfig`.
> diff --git a/doc/develop/bootstd/index.rst b/doc/develop/bootstd/index.rst
> new file mode 100644
> index 000..f4f87c7787c
> --- /dev/null
> +++ b/doc/develop/bootstd/index.rst
> @@ -0,0 +1,9 @@
> +.. SPDX-License-Identifier: GPL-2.0+:
> +
> +Standard Boot
> +=
> +
> +.. toctree::
> +   :maxdepth: 2
> +
> +   overview
> diff --git a/doc/develop/bootstd.rst b/doc/develop/bootstd/overview.rst
> similarity index 99%
> rename from doc/develop/bootstd.rst
> rename to doc/develop/bootstd/overview.rst
> index 34631089ae0..761f61a573b 100644
> --- a/doc/develop/bootstd.rst
> +++ b/doc/develop/bootstd/overview.rst
> @@ -1,7 +1,7 @@
>  .. SPDX-License-Identifier: GPL-2.0+:
>  
> -U-Boot Standard Boot
> -
> +Standard Boot Overview
> +==
>  
>  Introduction
>  
> @@ -17,7 +17,7 @@ introduces the following concepts:
>  For Linux, the distro (Linux distribution, e.g. Debian, Fedora) is 
> responsible
>  for creating a bootflow for each kernel combination that it wants to offer.
>  These bootflows are stored on media so they can be discovered by U-Boot. This
> -feature is typically called `distro boot` (see :doc:`distro`) because it is
> +feature is typically called `distro boot` (see :doc:`../distro`) because it 
> is
>  a way for distributions to boot on any hardware.
>  
>  Traditionally U-Boot has relied on scripts to implement this feature. See
> @@ -32,7 +32,7 @@ way to boot with U-Boot. The feature is extensible to 
> different Operating
>  Systems (such as Chromium OS) and devices (beyond just block and network
>  devices). It supports EFI boot and EFI bootmgr too.
>  
> -Finally, standard boot supports the operation of :doc:`vbe`.
> +Finally, standard boot supports the operati

Re: [PATCH v2 01/14] MAINTAINERS: Rename BOOTDEVICE

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On mar., juil. 16, 2024 at 08:04, Simon Glass  wrote:

> Rename this to BOOTSTD which is the normal name for the feature.
>
> Signed-off-by: Simon Glass 
> Reviewed-by: Quentin Schulz 

Reviewed-by: Mattijs Korpershoek 

> ---
>
> (no changes since v1)
>
>  MAINTAINERS | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 2c6de3a1d84..9bee9284cca 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -918,7 +918,7 @@ F:drivers/block/blkmap.c
>  F:   include/blkmap.h
>  F:   test/dm/blkmap.c
>  
> -BOOTDEVICE
> +BOOTSTD
>  M:   Simon Glass 
>  S:   Maintained
>  F:   boot/bootdev*.c
> -- 
> 2.34.1


Re: [PATCH 07/13] doc: Add a description for bootmeth_sandbox

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On lun., juil. 15, 2024 at 11:13, Simon Glass  wrote:

> Add documentation for the sandbox bootmeth.
>
> Fix up the compatible string to drop the 'extlinux' part, which is not
> relevant to this bootmeth.
>
> Signed-off-by: Simon Glass 

Reviewed-by: Mattijs Korpershoek 

> ---
>
>  boot/bootmeth_sandbox.c  |  2 +-
>  doc/develop/bootstd/index.rst|  1 +
>  doc/develop/bootstd/overview.rst |  1 +
>  doc/develop/bootstd/sandbox.rst  | 18 ++
>  4 files changed, 21 insertions(+), 1 deletion(-)
>  create mode 100644 doc/develop/bootstd/sandbox.rst
>
> diff --git a/boot/bootmeth_sandbox.c b/boot/bootmeth_sandbox.c
> index 0bc8f688e30..26c713bb5f3 100644
> --- a/boot/bootmeth_sandbox.c
> +++ b/boot/bootmeth_sandbox.c
> @@ -55,7 +55,7 @@ static struct bootmeth_ops sandbox_bootmeth_ops = {
>  };
>  
>  static const struct udevice_id sandbox_bootmeth_ids[] = {
> - { .compatible = "u-boot,sandbox-extlinux" },
> + { .compatible = "u-boot,sandbox-bootmeth" },
>   { }
>  };
>  
> diff --git a/doc/develop/bootstd/index.rst b/doc/develop/bootstd/index.rst
> index 69fd3c2d2eb..2c5d2d3fade 100644
> --- a/doc/develop/bootstd/index.rst
> +++ b/doc/develop/bootstd/index.rst
> @@ -11,3 +11,4 @@ Standard Boot
> pxelinux
> qfw
> cros
> +   sandbox
> diff --git a/doc/develop/bootstd/overview.rst 
> b/doc/develop/bootstd/overview.rst
> index f12e93236a7..58acaa4d3ce 100644
> --- a/doc/develop/bootstd/overview.rst
> +++ b/doc/develop/bootstd/overview.rst
> @@ -420,6 +420,7 @@ Bootmeth drivers are provided for:
> - :doc:`ChromiumOS ` ChromiumOS boot from a disk
> - EFI boot using boot manager
> - :doc:`QFW `: QEMU firmware interface
> +   - :doc:`sandbox ` used only for testing
>  
>  
>  Command interface
> diff --git a/doc/develop/bootstd/sandbox.rst b/doc/develop/bootstd/sandbox.rst
> new file mode 100644
> index 000..508f0fd5baa
> --- /dev/null
> +++ b/doc/develop/bootstd/sandbox.rst
> @@ -0,0 +1,18 @@
> +.. SPDX-License-Identifier: GPL-2.0+:
> +
> +Sandbox Bootmeth
> +
> +
> +The sandbox bootmeth is only used for testing. It does not provide any 
> facility
> +for booting an OS. While sandbox can do all the processing before the actual
> +boot, it is not connected in this bootmeth.
> +
> +When invoked on a bootdev, this bootmeth pretends to find a bootflow and 
> creates
> +the associated structure.
> +
> +When the bootflow is booted, the bootmeth returns -EENOTSUPP indicating that 
> it
> +is not supported.
> +
> +The compatible string "u-boot,sandbox-bootmeth" is used for the driver. The
> +driver is automatically instantiated if there are no bootmeth drivers in the
> +devicetree.
> -- 
> 2.34.1


Re: [PATCH 06/13] doc: Add a description for bootmeth_cros

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On lun., juil. 15, 2024 at 11:13, Simon Glass  wrote:

> Add documentation for the cros bootmeth.
>
> Signed-off-by: Simon Glass 

Reviewed-by: Mattijs Korpershoek 

> ---
>
>  doc/develop/bootstd/cros.rst | 33 
>  doc/develop/bootstd/index.rst|  1 +
>  doc/develop/bootstd/overview.rst |  1 +
>  3 files changed, 35 insertions(+)
>  create mode 100644 doc/develop/bootstd/cros.rst
>
> diff --git a/doc/develop/bootstd/cros.rst b/doc/develop/bootstd/cros.rst
> new file mode 100644
> index 000..96f148837ac
> --- /dev/null
> +++ b/doc/develop/bootstd/cros.rst
> @@ -0,0 +1,33 @@
> +.. SPDX-License-Identifier: GPL-2.0+:
> +
> +ChromiumOS Bootmeth
> +===
> +
> +ChromiumOS provides a mechanism for booting its Operating System from a block
> +device, described
> +`here 
> <https://www.chromium.org/chromium-os/chromiumos-design-docs/verified-boot/>`_.
> +
> +U-Boot includes support for reading the associated data structures from the
> +device and identifying a bootable ChromiumOS image. This structure includes 
> the
> +kernel itself, boot arguments (kernel command line), as well as the x86 setup
> +block (for x86 only).
> +
> +When invoked on a bootdev, this bootmeth searches for kernel partitions with
> +the appropriate GUID (Globally Unique Identifier). When found, the 
> information
> +is loaded and a bootflow is created.
> +
> +When the bootflow is booted, the bootmeth reads the kernel and boot 
> arguments.
> +It then boots the kernel using zboot (on x86) or bootm (on ARM). The boot
> +arguments are adjusted to replace %U with the UUID of the selected kernel
> +partition. This results in the correct root disk being used, which is the 
> next
> +partition after the kernel partition.
> +
> +For ARM, a :doc:`/usage/fit/index` is used. The `CONFIG_FIT_BEST_MATCH` 
> option
> +must be enabled for U-Boot to select the correct devicetree to boot with.
> +
> +Note that a ChromiumOS image typically has two copies of the OS, each with 
> its
> +own kernel and root disk. There is no initial ramdisk (initrd). This means 
> that
> +this bootmeth typically locates two separate images.
> +
> +The compatible string "u-boot,cros" is used for the driver. The driver is
> +automatically instantiated if there are no bootmeth drivers in the 
> devicetree.
> diff --git a/doc/develop/bootstd/index.rst b/doc/develop/bootstd/index.rst
> index f8fce7207ce..69fd3c2d2eb 100644
> --- a/doc/develop/bootstd/index.rst
> +++ b/doc/develop/bootstd/index.rst
> @@ -10,3 +10,4 @@ Standard Boot
> extlinux
> pxelinux
> qfw
> +   cros
> diff --git a/doc/develop/bootstd/overview.rst 
> b/doc/develop/bootstd/overview.rst
> index bcc2c00c775..f12e93236a7 100644
> --- a/doc/develop/bootstd/overview.rst
> +++ b/doc/develop/bootstd/overview.rst
> @@ -417,6 +417,7 @@ Bootmeth drivers are provided for:
> - U-Boot scripts from disk, network or SPI flash
> - EFI boot using bootefi from disk
> - VBE
> +   - :doc:`ChromiumOS ` ChromiumOS boot from a disk
> - EFI boot using boot manager
> - :doc:`QFW `: QEMU firmware interface
>  
> -- 
> 2.34.1


Re: [PATCH 05/13] doc: Add a description for bootmeth_qfw

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On lun., juil. 15, 2024 at 11:13, Simon Glass  wrote:

> Add documentation for the qfw bootmeth.
>
> Fix up the compatible string to drop the 'extlinux' part, which is not
> relevant to this bootmeth.
>
> Signed-off-by: Simon Glass 
> ---
>
>  boot/bootmeth_qfw.c  |  2 +-
>  doc/develop/bootstd/index.rst|  1 +
>  doc/develop/bootstd/overview.rst |  1 +
>  doc/develop/bootstd/qfw.rst  | 21 +
>  4 files changed, 24 insertions(+), 1 deletion(-)
>  create mode 100644 doc/develop/bootstd/qfw.rst
>
> diff --git a/boot/bootmeth_qfw.c b/boot/bootmeth_qfw.c
> index dfaa944594e..2f8e00cf350 100644
> --- a/boot/bootmeth_qfw.c
> +++ b/boot/bootmeth_qfw.c
> @@ -88,7 +88,7 @@ static struct bootmeth_ops qfw_bootmeth_ops = {
>  };
>  
>  static const struct udevice_id qfw_bootmeth_ids[] = {
> - { .compatible = "u-boot,qfw-extlinux" },
> + { .compatible = "u-boot,qfw-bootmeth" },
>   { }
>  };
>  
> diff --git a/doc/develop/bootstd/index.rst b/doc/develop/bootstd/index.rst
> index 5052afe448f..f8fce7207ce 100644
> --- a/doc/develop/bootstd/index.rst
> +++ b/doc/develop/bootstd/index.rst
> @@ -9,3 +9,4 @@ Standard Boot
> overview
> extlinux
> pxelinux
> +   qfw
> diff --git a/doc/develop/bootstd/overview.rst 
> b/doc/develop/bootstd/overview.rst
> index fd0692daf0d..bcc2c00c775 100644
> --- a/doc/develop/bootstd/overview.rst
> +++ b/doc/develop/bootstd/overview.rst
> @@ -418,6 +418,7 @@ Bootmeth drivers are provided for:
> - EFI boot using bootefi from disk
> - VBE
> - EFI boot using boot manager
> +   - :doc:`QFW `: QEMU firmware interface
>  
>  
>  Command interface
> diff --git a/doc/develop/bootstd/qfw.rst b/doc/develop/bootstd/qfw.rst
> new file mode 100644
> index 000..b0d47fd246a
> --- /dev/null
> +++ b/doc/develop/bootstd/qfw.rst
> @@ -0,0 +1,21 @@
> +.. SPDX-License-Identifier: GPL-2.0+:
> +
> +QFW Bootmeth
> +
> +
> +`QEMU https://www.qemu.org/>`_ is a system emulator which is able to boot
> +Operating Systems. QEMU provides specific support for booting an OS image
> +provided on the QEMU command line.
> +
> +When invoked on a bootdev for UCLASS_QFW, this bootmeth reads the kernel
> +provided by the QEMU `-kernel` argument, the iniital ramdisk and provided by

iniital -> initial

ramdisk and provided by -> ramdisk provided by

With that fixed:

Reviewed-by: Mattijs Korpershoek 

> +`-initrd` and the boot arguments (command line) provided by `-append` into
> +memory ready for booting.
> +
> +When the bootflow is booted, the bootmeth tries the `booti` command first, 
> then
> +falls back to the `bootz` command. U-Boot's 'control' devicetree is passed
> +through to the kernel.
> +
> +The compatible string "u-boot,qfw-bootmeth" is used for the driver. The 
> driver
> +is automatically instantiated if there are no bootmeth drivers in the
> +devicetree.
> -- 
> 2.34.1


Re: [PATCH 04/13] doc: Add a description for bootmeth_pxe

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On lun., juil. 15, 2024 at 11:13, Simon Glass  wrote:

> Add documentation for the pxe bootmeth.
>
> Signed-off-by: Simon Glass 

Reviewed-by: Mattijs Korpershoek 

Nitpick: now that pxelinux.rst exist, can we link to this file in
extlinux.rst ?

> ---
>
>  doc/develop/bootstd/index.rst|  1 +
>  doc/develop/bootstd/overview.rst |  2 +-
>  doc/develop/bootstd/pxelinux.rst | 27 +++
>  3 files changed, 29 insertions(+), 1 deletion(-)
>  create mode 100644 doc/develop/bootstd/pxelinux.rst
>
> diff --git a/doc/develop/bootstd/index.rst b/doc/develop/bootstd/index.rst
> index 5bbb3d633a3..5052afe448f 100644
> --- a/doc/develop/bootstd/index.rst
> +++ b/doc/develop/bootstd/index.rst
> @@ -8,3 +8,4 @@ Standard Boot
>  
> overview
> extlinux
> +   pxelinux
> diff --git a/doc/develop/bootstd/overview.rst 
> b/doc/develop/bootstd/overview.rst
> index 086a0b1281d..fd0692daf0d 100644
> --- a/doc/develop/bootstd/overview.rst
> +++ b/doc/develop/bootstd/overview.rst
> @@ -413,7 +413,7 @@ Available bootmeth drivers
>  Bootmeth drivers are provided for:
>  
> - :doc:`extlinux / syslinux ` boot from a disk
> -   - extlinux boot from a network (PXE)
> +   - :doc:`extlinux / syslinux ` boot from a network (PXE)
> - U-Boot scripts from disk, network or SPI flash
> - EFI boot using bootefi from disk
> - VBE
> diff --git a/doc/develop/bootstd/pxelinux.rst 
> b/doc/develop/bootstd/pxelinux.rst
> new file mode 100644
> index 000..08ba67e09c5
> --- /dev/null
> +++ b/doc/develop/bootstd/pxelinux.rst
> @@ -0,0 +1,27 @@
> +.. SPDX-License-Identifier: GPL-2.0+:
> +
> +PXE Bootmeth
> +
> +
> +PXE (Preboot eXecution-Environment) provides a way to boot an Operating 
> System
> +over a network interface. The PXE bootmeth supports PXELINUX and allows 
> U-Boot to
> +provide a menu of possible Operating Systems from which the user can choose.
> +
> +U-Boot includes a parser for the `extlinux.conf` file described
> +`here 
> <https://uapi-group.org/specifications/specs/boot_loader_specification>`_.
> +It consists primarily of a list of named OSes along with the kernel, initial
> +ramdisk and other settings. The file is retrieved from a network server using
> +tftpboot.
> +
> +When invoked on a bootdev, this bootmeth searches for the file and creates a
> +bootflow if found. See
> +`PXELINUX <https://wiki.syslinux.org/wiki/index.php?title=PXELINUX>`_ for
> +a full description of the search procedure.
> +
> +When the bootflow is booted, the bootmeth calls pxe_setup_ctx() to set up the
> +context, then pxe_process() to process the file. Depending on the contents, 
> this
> +may boot an OS or provide a list of options to the user, perhaps with a 
> timeout.
> +
> +The compatible string "u-boot,extlinux-pxe" is used for the driver. The 
> driver
> +is automatically instantiated if there are no bootmeth drivers in the
> +devicetree.
> -- 
> 2.34.1


Re: [PATCH 03/13] doc: Add a description for bootmeth_extlinux

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On lun., juil. 15, 2024 at 11:13, Simon Glass  wrote:

> Add documentation for the extlinux bootmeth.
>
> Signed-off-by: Simon Glass 

Reviewed-by: Mattijs Korpershoek 

Minor nitpicks below, feel free to ignore or apply.

> ---
>
>  doc/develop/bootstd/extlinux.rst | 27 +++
>  doc/develop/bootstd/index.rst|  1 +
>  doc/develop/bootstd/overview.rst |  2 +-
>  3 files changed, 29 insertions(+), 1 deletion(-)
>  create mode 100644 doc/develop/bootstd/extlinux.rst
>
> diff --git a/doc/develop/bootstd/extlinux.rst 
> b/doc/develop/bootstd/extlinux.rst
> new file mode 100644
> index 000..28490f38899
> --- /dev/null
> +++ b/doc/develop/bootstd/extlinux.rst
> @@ -0,0 +1,27 @@
> +.. SPDX-License-Identifier: GPL-2.0+:
> +
> +Extlinux Bootmeth
> +=
> +
> +`Extlinux 
> <https://uapi-group.org/specifications/specs/boot_loader_specification>`_
> +(sometimes called syslinux) allows U-Boot to provide a menu of possible
> +Operating Systems from which the user can choose.
> +
> +U-Boot includes a parser for the `extlinux.conf` file. It consists primarily 
> of
> +a list of named OSes along with the kernel, initial ramdisk and other 
> settings.
> +The file is stored in the `extlinux/` subdirectory, possibly under the 
> `boot/`
> +subdirectory. This list of prefixes ({"/", "/boot"} by default) can be 
> selected

Can the prefixes also be surrounded by `` (`{"/", "boot"`} to insist
that this is "code listing" as well ?

> +with the `filename-prefixes` property in the bootstd device.
> +
> +Note that PXE (Preboot eXecution-Environment) uses the same file format, but 
> in
> +a network context.
> +
> +When invoked on a bootdev, this bootmeth searches for the file and creates a
> +bootflow if found.
> +
> +When the bootflow is booted, the bootmeth calls pxe_setup_ctx() to set up the
> +context, then pxe_process() to process the file. Depending on the contents, 
> this

same for pxe_setup_ctx and pxe_process

> +may boot an OS or provide a list of options to the user, perhaps with a 
> timeout.
> +
> +The compatible string "u-boot,extlinux" is used for the driver. The driver is
> +automatically instantiated if there are no bootmeth drivers in the 
> devicetree.
> diff --git a/doc/develop/bootstd/index.rst b/doc/develop/bootstd/index.rst
> index f4f87c7787c..5bbb3d633a3 100644
> --- a/doc/develop/bootstd/index.rst
> +++ b/doc/develop/bootstd/index.rst
> @@ -7,3 +7,4 @@ Standard Boot
> :maxdepth: 2
>  
> overview
> +   extlinux
> diff --git a/doc/develop/bootstd/overview.rst 
> b/doc/develop/bootstd/overview.rst
> index 761f61a573b..086a0b1281d 100644
> --- a/doc/develop/bootstd/overview.rst
> +++ b/doc/develop/bootstd/overview.rst
> @@ -412,7 +412,7 @@ Available bootmeth drivers
>  
>  Bootmeth drivers are provided for:
>  
> -   - extlinux / syslinux boot from a disk
> +   - :doc:`extlinux / syslinux ` boot from a disk
> - extlinux boot from a network (PXE)
> - U-Boot scripts from disk, network or SPI flash
> - EFI boot using bootefi from disk
> -- 
> 2.34.1


Re: [PATCH 02/13] doc: Move bootstd into its own directory

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On lun., juil. 15, 2024 at 11:13, Simon Glass  wrote:

> Before adding more files, move the bootstd docs into a new directory,
> with an index.
>
> Signed-off-by: Simon Glass 

Reviewed-by: Mattijs Korpershoek 

> ---
>
>  MAINTAINERS   |  2 +-
>  doc/board/starfive/milk-v_mars_cm.rst |  2 +-
>  doc/develop/board_best_practices.rst  |  2 +-
>  doc/develop/bootstd/index.rst |  9 +
>  doc/develop/{bootstd.rst => bootstd/overview.rst} | 14 +++---
>  doc/develop/index.rst |  2 +-
>  doc/usage/cmd/bootdev.rst |  2 +-
>  doc/usage/cmd/bootflow.rst|  2 +-
>  doc/usage/cmd/bootmeth.rst|  2 +-
>  doc/usage/environment.rst |  2 +-
>  10 files changed, 24 insertions(+), 15 deletions(-)
>  create mode 100644 doc/develop/bootstd/index.rst
>  rename doc/develop/{bootstd.rst => bootstd/overview.rst} (99%)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 9bee9284cca..86b830aa997 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -927,7 +927,7 @@ F:boot/bootmeth*.c
>  F:   boot/bootstd.c
>  F:   cmd/bootdev.c
>  F:   cmd/bootflow.c
> -F:   doc/develop/bootstd.rst
> +F:   doc/develop/bootstd/
>  F:   doc/usage/bootdev.rst
>  F:   doc/usage/bootflow.rst
>  F:   doc/usage/bootmeth.rst
> diff --git a/doc/board/starfive/milk-v_mars_cm.rst 
> b/doc/board/starfive/milk-v_mars_cm.rst
> index b31de6043bb..52d4e5e9098 100644
> --- a/doc/board/starfive/milk-v_mars_cm.rst
> +++ b/doc/board/starfive/milk-v_mars_cm.rst
> @@ -89,7 +89,7 @@ provide a default value.
>  
>  The variable *$fdtfile* is used in the boot process to automatically load
>  a device-tree provided by the operating system. For details of the boot
> -process refer to the :doc:`U-Boot Standard Boot <../../../develop/bootstd>`
> +process refer to the :doc:`/develop/bootstd/index`
>  description.
>  
>  Boot source selection
> diff --git a/doc/develop/board_best_practices.rst 
> b/doc/develop/board_best_practices.rst
> index f44401eab7d..09632c80ce7 100644
> --- a/doc/develop/board_best_practices.rst
> +++ b/doc/develop/board_best_practices.rst
> @@ -7,7 +7,7 @@ In addition to the regular best practices such as using 
> :doc:`checkpatch` and
>  following the :doc:`docstyle` and the :doc:`codingstyle` there are some 
> things
>  which are specific to creating a new board port.
>  
> -* Implement :doc:`bootstd` to ensure that most operating systems will be
> +* Implement :doc:`bootstd/index` to ensure that most operating systems will 
> be
>supported by the platform.
>  
>  * The platform defconfig file must be generated via `make savedefconfig`.
> diff --git a/doc/develop/bootstd/index.rst b/doc/develop/bootstd/index.rst
> new file mode 100644
> index 000..f4f87c7787c
> --- /dev/null
> +++ b/doc/develop/bootstd/index.rst
> @@ -0,0 +1,9 @@
> +.. SPDX-License-Identifier: GPL-2.0+:
> +
> +Standard Boot
> +=
> +
> +.. toctree::
> +   :maxdepth: 2
> +
> +   overview
> diff --git a/doc/develop/bootstd.rst b/doc/develop/bootstd/overview.rst
> similarity index 99%
> rename from doc/develop/bootstd.rst
> rename to doc/develop/bootstd/overview.rst
> index 34631089ae0..761f61a573b 100644
> --- a/doc/develop/bootstd.rst
> +++ b/doc/develop/bootstd/overview.rst
> @@ -1,7 +1,7 @@
>  .. SPDX-License-Identifier: GPL-2.0+:
>  
> -U-Boot Standard Boot
> -
> +Standard Boot Overview
> +==
>  
>  Introduction
>  
> @@ -17,7 +17,7 @@ introduces the following concepts:
>  For Linux, the distro (Linux distribution, e.g. Debian, Fedora) is 
> responsible
>  for creating a bootflow for each kernel combination that it wants to offer.
>  These bootflows are stored on media so they can be discovered by U-Boot. This
> -feature is typically called `distro boot` (see :doc:`distro`) because it is
> +feature is typically called `distro boot` (see :doc:`../distro`) because it 
> is
>  a way for distributions to boot on any hardware.
>  
>  Traditionally U-Boot has relied on scripts to implement this feature. See
> @@ -32,7 +32,7 @@ way to boot with U-Boot. The feature is extensible to 
> different Operating
>  Systems (such as Chromium OS) and devices (beyond just block and network
>  devices). It supports EFI boot and EFI bootmgr too.
>  
> -Finally, standard boot supports the operation of :doc:`vbe`.
> +Finally, standard boot supports the operation of :doc:`../vbe`.
>  
>  Bootflow
>  
> @@ -427,1

Re: [PATCH 01/13] MAINTAINERS: Rename BOOTDEVICE

2024-07-16 Thread Mattijs Korpershoek
Hi Simon,

Thank you for the patch.

On lun., juil. 15, 2024 at 11:13, Simon Glass  wrote:

> Rename this to BOOTSTD which is the normal name for the feature.
>
> Signed-off-by: Simon Glass 

Reviewed-by: Mattijs Korpershoek 

> ---
>
>  MAINTAINERS | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 2c6de3a1d84..9bee9284cca 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -918,7 +918,7 @@ F:drivers/block/blkmap.c
>  F:   include/blkmap.h
>  F:   test/dm/blkmap.c
>  
> -BOOTDEVICE
> +BOOTSTD
>  M:   Simon Glass 
>  S:   Maintained
>  F:   boot/bootdev*.c
> -- 
> 2.34.1


[GIT PULL] Please pull u-boot-dfu-20240711

2024-07-11 Thread Mattijs Korpershoek
Hi Tom,

Please find some new developments for master:

Usb gadget:
- A welcome cleanup: epautoconf workaround is dropped to use
  .match_ep() instead
- Introduce handle_interrupts() op for USB_GADGET_GENERIC, which
  allows a per-driver interrupt handling

Fastboot:
- Fix mssing include when building with TCP only

Thi CI job is at 
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/21552

Thanks,
Mattijs

The following changes since commit 7c9c5c0562347dccb8ac89148784a34de402ea9e:

  Merge patch series "xtensa: Enable qemu-xtensa board" (2024-07-04 16:11:08 
-0600)

are available in the Git repository at:

  https://source.denx.de/u-boot/custodians/u-boot-dfu.git 
tags/u-boot-dfu-20240711

for you to fetch changes up to b091d3872833a4b8d088ee41348a2d4ff48067cc:

  include/fastboot.h: add missing types.h include (2024-07-09 09:15:37 +0200)


u-boot-dfu-20240711

Usb gadget:
- A welcome cleanup: epautoconf workaround is dropped to use
  .match_ep() instead
- Introduce handle_interrupts() op for USB_GADGET_GENERIC, which
  allows a per-driver interrupt handling

Fastboot:
- Fix mssing include when building with TCP only


Caleb Connolly (1):
  include/fastboot.h: add missing types.h include

Marek Vasut (17):
  usb: gadget: g_dnl: Drop usb_gadget_controller_number()
  usb: gadget: ether: Drop usb_gadget_controller_number()
  usb: gadget: Drop usb_gadget_controller_number()
  usb: gadget: Drop all gadget_is_*() functions
  usb: gadget: Add full ep_matches() check past .match_ep() callback
  usb: dwc3: gadget: Convert epautoconf workaround to match_ep callback
  usb: gadget: Introduce handle_interrupts ops to USB_GADGET_GENERIC uclass
  usb: gadget: cdns3: Convert interrupt handling to usb_gadget_generic_ops
  usb: gadget: dwc2: Convert interrupt handling to usb_gadget_generic_ops
  usb: gadget: dwc3: Convert interrupt handling to usb_gadget_generic_ops
  usb: gadget: max3420: Convert interrupt handling to usb_gadget_generic_ops
  usb: gadget: mtu3: Convert interrupt handling to usb_gadget_generic_ops
  usb: gadget: omap2430: Convert interrupt handling to 
usb_gadget_generic_ops
  usb: gadget: musb: Convert interrupt handling to usb_gadget_generic_ops
  usb: gadget: ux500: Convert interrupt handling to usb_gadget_generic_ops
  usb: gadget: sandbox: Drop dm_usb_gadget_handle_interrupts()
  usb: gadget: Mark dm_usb_gadget_handle_interrupts as non-weak for 
DM_USB_GADGET

 drivers/usb/cdns3/core.c|  24 +
 drivers/usb/cdns3/gadget-export.h   |   2 +
 drivers/usb/cdns3/gadget.c  |  11 +-
 drivers/usb/dwc3/dwc3-generic.c |  23 ++--
 drivers/usb/dwc3/dwc3-layerscape.c  |  21 ++--
 drivers/usb/dwc3/gadget.c   |  33 ++
 drivers/usb/gadget/dwc2_udc_otg.c   |  20 +++-
 drivers/usb/gadget/epautoconf.c |  81 +-
 drivers/usb/gadget/ether.c  |  25 ++---
 drivers/usb/gadget/g_dnl.c  |  17 +--
 drivers/usb/gadget/gadget_chips.h   | 210 
 drivers/usb/gadget/max3420_udc.c|  19 ++--
 drivers/usb/gadget/udc/udc-uclass.c |  24 +
 drivers/usb/host/usb-sandbox.c  |   7 +-
 drivers/usb/mtu3/mtu3_plat.c|  23 ++--
 drivers/usb/musb-new/omap2430.c |  26 +++--
 drivers/usb/musb-new/ti-musb.c  |  23 ++--
 drivers/usb/musb-new/ux500.c|  22 ++--
 include/fastboot.h  |   2 +
 include/linux/usb/gadget.h  |   8 ++
 20 files changed, 219 insertions(+), 402 deletions(-)
 delete mode 100644 drivers/usb/gadget/gadget_chips.h



[PATCH v3 4/5] bootstd: Add a bootmeth for Android

2024-07-10 Thread Mattijs Korpershoek
Android boot flow is a bit different than a regular Linux distro.
Android relies on multiple partitions in order to boot.

A typical boot flow would be:
1. Parse the Bootloader Control Block (BCB, misc partition)
2. If BCB requested bootonce-bootloader, start fastboot and wait.
3. If BCB requested recovery or normal android, run the following:
3.a. Get slot (A/B) from BCB
3.b. Run AVB (Android Verified Boot) on boot partitions
3.c. Load boot and vendor_boot partitions
3.d. Load device-tree, ramdisk and boot

The AOSP documentation has more details at [1], [2], [3]

This has been implemented via complex boot scripts such as [4].
However, these boot script are neither very maintainable nor generic.
Moreover, DISTRO_DEFAULTS is being deprecated [5].

Add a generic Android bootflow implementation for bootstd.
For this initial version, only boot image v4 is supported.

[1] https://source.android.com/docs/core/architecture/bootloader
[2] https://source.android.com/docs/core/architecture/partitions
[3] https://source.android.com/docs/core/architecture/partitions/generic-boot
[4] 
https://source.denx.de/u-boot/u-boot/-/blob/master/include/configs/meson64_android.h
[5] https://lore.kernel.org/r/all/20230914165615.1058529-17-...@chromium.org/

Reviewed-by: Simon Glass 
Reviewed-by: Julien Masson 
Tested-by: Guillaume La Roque 
Signed-off-by: Mattijs Korpershoek 
---
 MAINTAINERS |   7 +
 boot/Kconfig|  17 ++
 boot/Makefile   |   2 +
 boot/bootmeth_android.c | 553 
 boot/bootmeth_android.h |  29 +++
 doc/develop/bootstd.rst |   6 +
 6 files changed, 614 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 2c6de3a1d849..19ca57d200b9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -939,6 +939,13 @@ F: include/bootstd.h
 F: net/eth_bootdevice.c
 F: test/boot/
 
+BOOTMETH_ANDROID
+M: Mattijs Korpershoek 
+S: Maintained
+T: git https://source.denx.de/u-boot/custodians/u-boot-dfu.git
+F: boot/bootmeth_android.c
+F: boot/bootmeth_android.h
+
 BTRFS
 M: Marek Behún 
 R: Qu Wenruo 
diff --git a/boot/Kconfig b/boot/Kconfig
index ffcae840a506..4a17deaa3e24 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -494,6 +494,23 @@ config BOOTMETH_GLOBAL
  EFI bootmgr, since they take full control over which bootdevs are
  selected to boot.
 
+config BOOTMETH_ANDROID
+   bool "Bootdev support for Android"
+   depends on X86 || ARM || SANDBOX
+   depends on CMDLINE
+   select ANDROID_AB
+   select ANDROID_BOOT_IMAGE
+   select CMD_BCB
+   select CMD_FASTBOOT
+   select PARTITION_TYPE_GUID
+   select PARTITION_UUIDS
+   help
+ Enables support for booting Android using bootstd. Android requires
+ multiple partitions (misc, boot, vbmeta, ...) in storage for booting.
+
+ Note that only MMC bootdevs are supported at present. This is caused
+ by AVB being limited to MMC devices only.
+
 config BOOTMETH_CROS
bool "Bootdev support for Chromium OS"
depends on X86 || ARM || SANDBOX
diff --git a/boot/Makefile b/boot/Makefile
index 84ccfeaecec4..75d1cd46fabf 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -66,3 +66,5 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_REQUEST) += vbe_request.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE) += vbe_simple.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_FW) += vbe_simple_fw.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_OS) += vbe_simple_os.o
+
+obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_ANDROID) += bootmeth_android.o
diff --git a/boot/bootmeth_android.c b/boot/bootmeth_android.c
new file mode 100644
index ..6e8d3e615db0
--- /dev/null
+++ b/boot/bootmeth_android.c
@@ -0,0 +1,553 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Bootmeth for Android
+ *
+ * Copyright (C) 2024 BayLibre, SAS
+ * Written by Mattijs Korpershoek 
+ */
+#define LOG_CATEGORY UCLASS_BOOTSTD
+
+#include 
+#include 
+#if CONFIG_IS_ENABLED(AVB_VERIFY)
+#include 
+#endif
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "bootmeth_android.h"
+
+#define BCB_FIELD_COMMAND_SZ 32
+#define BCB_PART_NAME "misc"
+#define BOOT_PART_NAME "boot"
+#define VENDOR_BOOT_PART_NAME "vendor_boot"
+
+/**
+ * struct android_priv - Private data
+ *
+ * This is read from the disk and recorded for use when the full Android
+ * kernel must be loaded and booted
+ *
+ * @boot_mode: Requested boot mode (normal, recovery, bootloader)
+ * @slot: Nul-terminated partition slot suffix read from BCB ("a\0" or "b\0")
+ * @header_version: Android boot image header version
+ */
+struct android_priv {
+   enum android_boot_mode boot_mode;
+   char slot[2];
+   u32 header_version;
+};
+
+static int android_check(struct udevice *dev, struct bootflow_iter *iter)
+{
+   /* This only works on 

[PATCH v3 5/5] bootstd: Add test for bootmeth_android

2024-07-10 Thread Mattijs Korpershoek
Add a unit test for testing the Android bootmethod.

This requires another mmc image (mmc7) to contain the following partitions:
- misc: contains the Bootloader Control Block (BCB)
- boot_a: contains a fake generic kernel image
- vendor_boot_a: contains a fake vendor_boot image

Also add BOOTMETH_ANDROID as a dependency on sandbox so that we can test
this with:

$ ./test/py/test.py --bd sandbox --build -k test_ut # build the mmc7.img
$ ./test/py/test.py --bd sandbox --build -k bootflow_android

Signed-off-by: Mattijs Korpershoek 
---
 arch/sandbox/dts/test.dts |  8 +
 configs/sandbox_defconfig |  2 +-
 test/boot/bootflow.c  | 68 ++--
 test/py/tests/test_ut.py  | 79 +++
 4 files changed, 153 insertions(+), 4 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index a012f5c4c9ba..5fb5eac862ec 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -43,6 +43,7 @@
mmc4 = "/mmc4";
mmc5 = "/mmc5";
mmc6 = "/mmc6";
+   mmc7 = "/mmc7";
pci0 = 
pci1 = 
pci2 = 
@@ -1129,6 +1130,13 @@
filename = "mmc6.img";
};
 
+   /* This is used for Android tests */
+   mmc7 {
+   status = "disabled";
+   compatible = "sandbox,mmc";
+   filename = "mmc7.img";
+   };
+
pch {
compatible = "sandbox,pch";
};
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index da8c1976d7bd..36e43e0e21ab 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -15,6 +15,7 @@ CONFIG_FIT=y
 CONFIG_FIT_RSASSA_PSS=y
 CONFIG_FIT_CIPHER=y
 CONFIG_FIT_VERBOSE=y
+CONFIG_BOOTMETH_ANDROID=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_MEASURED_BOOT=y
 CONFIG_BOOTSTAGE=y
@@ -40,7 +41,6 @@ CONFIG_LOG_MAX_LEVEL=9
 CONFIG_LOG_DEFAULT_LEVEL=6
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_STACKPROTECTOR=y
-CONFIG_ANDROID_AB=y
 CONFIG_CMD_CPU=y
 CONFIG_CMD_LICENSE=y
 CONFIG_CMD_SMBIOS=y
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 4511cfa7f9bf..8b46256fa48d 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -27,6 +27,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+extern U_BOOT_DRIVER(bootmeth_android);
 extern U_BOOT_DRIVER(bootmeth_cros);
 extern U_BOOT_DRIVER(bootmeth_2script);
 
@@ -518,12 +519,12 @@ BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | 
UT_TESTF_SCAN_FDT);
  * @uts: Unit test state
  * @mmc_dev: MMC device to use, e.g. "mmc4". Note that this must remain valid
  * in the caller until
- * @bind_cros: true to bind the ChromiumOS bootmeth
+ * @bind_cros: true to bind the ChromiumOS and Android bootmeths
  * @old_orderp: Returns the original bootdev order, which must be restored
  * Returns 0 on success, -ve on failure
  */
 static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
-   bool bind_cros, const char ***old_orderp)
+   bool bind_cros_android, const char ***old_orderp)
 {
static const char *order[] = {"mmc2", "mmc1", NULL, NULL};
struct udevice *dev, *bootstd;
@@ -545,12 +546,19 @@ static int prep_mmc_bootdev(struct unit_test_state *uts, 
const char *mmc_dev,
"bootmeth_script", 0, ofnode_null(), ));
 
/* Enable the cros bootmeth if needed */
-   if (IS_ENABLED(CONFIG_BOOTMETH_CROS) && bind_cros) {
+   if (IS_ENABLED(CONFIG_BOOTMETH_CROS) && bind_cros_android) {
ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, ));
ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_cros),
"cros", 0, ofnode_null(), ));
}
 
+   /* Enable the android bootmeths if needed */
+   if (IS_ENABLED(CONFIG_BOOTMETH_ANDROID) && bind_cros_android) {
+   ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, ));
+   ut_assertok(device_bind(bootstd, 
DM_DRIVER_REF(bootmeth_android),
+   "android", 0, ofnode_null(), ));
+   }
+
/* Change the order to include the device */
std = dev_get_priv(bootstd);
old_order = std->bootdev_order;
@@ -589,6 +597,37 @@ static int scan_mmc_bootdev(struct unit_test_state *uts, 
const char *mmc_dev,
return 0;
 }
 
+/**
+ * scan_mmc_android_bootdev() - Set up an mmc bootdev so we can access other
+ * distros. Android bootflow might print "ANDROID:*" while scanning
+ *
+ * @uts: Unit test state
+ * @mmc_dev: MMC device to use, e.g. "mmc4"
+ * Returns 0 on success, -ve on failure
+ */
+static int scan_mmc_android_bootdev(struct unit_test_stat

[PATCH v3 3/5] android: boot: Add set_abootimg_addr() and set_avendor_bootimg_addr()

2024-07-10 Thread Mattijs Korpershoek
The only way to configure the load addresses for both bootimg and
vendor_bootimg is by using the "abootimg" command.
If we want to use the C API, there is no equivalent.

Add set_abootimg_addr() and set_avendor_bootimg_addr() so that we can
specify the load address from C.

This can be useful for implementing an Android bootmethod.

Reviewed-by: Igor Opaniuk 
Reviewed-by: Julien Masson 
Reviewed-by: Simon Glass 
Reviewed-by: Guillaume La Roque 
Tested-by: Guillaume La Roque 
Signed-off-by: Mattijs Korpershoek 
---
 cmd/abootimg.c  | 10 ++
 include/image.h | 14 ++
 2 files changed, 24 insertions(+)

diff --git a/cmd/abootimg.c b/cmd/abootimg.c
index 327712a536c0..ae7a1a7c83b0 100644
--- a/cmd/abootimg.c
+++ b/cmd/abootimg.c
@@ -22,6 +22,11 @@ ulong get_abootimg_addr(void)
return (_abootimg_addr == -1 ? image_load_addr : _abootimg_addr);
 }
 
+void set_abootimg_addr(ulong addr)
+{
+   _abootimg_addr = addr;
+}
+
 ulong get_ainit_bootimg_addr(void)
 {
return _ainit_bootimg_addr;
@@ -32,6 +37,11 @@ ulong get_avendor_bootimg_addr(void)
return _avendor_bootimg_addr;
 }
 
+void set_avendor_bootimg_addr(ulong addr)
+{
+   _avendor_bootimg_addr = addr;
+}
+
 static int abootimg_get_ver(int argc, char *const argv[])
 {
const struct andr_boot_img_hdr_v0 *hdr;
diff --git a/include/image.h b/include/image.h
index 9daaee15cdbb..dd4042d1bd90 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1971,6 +1971,13 @@ bool is_android_vendor_boot_image_header(const void 
*vendor_boot_img);
  */
 ulong get_abootimg_addr(void);
 
+/**
+ * set_abootimg_addr() - Set Android boot image address
+ *
+ * Return: no returned results
+ */
+void set_abootimg_addr(ulong addr);
+
 /**
  * get_ainit_bootimg_addr() - Get Android init boot image address
  *
@@ -1985,6 +1992,13 @@ ulong get_ainit_bootimg_addr(void);
  */
 ulong get_avendor_bootimg_addr(void);
 
+/**
+ * set_abootimg_addr() - Set Android vendor boot image address
+ *
+ * Return: no returned results
+ */
+void set_avendor_bootimg_addr(ulong addr);
+
 /**
  * board_fit_config_name_match() - Check for a matching board name
  *

-- 
2.45.2



[PATCH v3 2/5] bootstd: Add bootflow_iter_check_mmc() helper

2024-07-10 Thread Mattijs Korpershoek
Some bootflows might be able to only boot from MMC devices.

Add a helper function these bootflows can use.

Reviewed-by: Igor Opaniuk 
Reviewed-by: Julien Masson 
Reviewed-by: Guillaume La Roque 
Tested-by: Guillaume La Roque 
Signed-off-by: Mattijs Korpershoek 
---
 boot/bootflow.c| 12 
 include/bootflow.h |  9 +
 2 files changed, 21 insertions(+)

diff --git a/boot/bootflow.c b/boot/bootflow.c
index 9aa3179c3881..59d77d2385f4 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -575,6 +575,18 @@ int bootflow_iter_check_blk(const struct bootflow_iter 
*iter)
return -ENOTSUPP;
 }
 
+int bootflow_iter_check_mmc(const struct bootflow_iter *iter)
+{
+   const struct udevice *media = dev_get_parent(iter->dev);
+   enum uclass_id id = device_get_uclass_id(media);
+
+   log_debug("uclass %d: %s\n", id, uclass_get_name(id));
+   if (id == UCLASS_MMC)
+   return 0;
+
+   return -ENOTSUPP;
+}
+
 int bootflow_iter_check_sf(const struct bootflow_iter *iter)
 {
const struct udevice *media = dev_get_parent(iter->dev);
diff --git a/include/bootflow.h b/include/bootflow.h
index 6affc5e1a4f3..4d2fc7b69b57 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -408,6 +408,15 @@ void bootflow_remove(struct bootflow *bflow);
  */
 int bootflow_iter_check_blk(const struct bootflow_iter *iter);
 
+/**
+ * bootflow_iter_check_mmc() - Check that a bootflow uses a MMC device
+ *
+ * This checks the bootdev in the bootflow to make sure it uses a mmc device
+ *
+ * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. ethernet)
+ */
+int bootflow_iter_check_mmc(const struct bootflow_iter *iter);
+
 /**
  * bootflow_iter_check_sf() - Check that a bootflow uses SPI FLASH
  *

-- 
2.45.2



[PATCH v3 1/5] boot: android: Provide vendor_bootimg_addr in boot_get_fdt()

2024-07-10 Thread Mattijs Korpershoek
When calling android_image_get_dtb_by_index() using boot image v3+,
we should also pass the vendor_boot ramdisk address.

Use get_avendor_bootimg_addr() to do so.

Notes: on boot image v2, this is harmless since get_avendor_bootimg_addr()
   returns -1.
   for legacy implementations that don't have CMD_ABOOTIMG, add a weak
   implementation to avoid linking errors.

Reviewed-by: Simon Glass 
Reviewed-by: Julien Masson 
Reviewed-by: Igor Opaniuk 
Reviewed-by: Guillaume La Roque 
Tested-by: Guillaume La Roque 
Signed-off-by: Mattijs Korpershoek 
---
 boot/image-android.c | 5 +
 boot/image-fdt.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/boot/image-android.c b/boot/image-android.c
index ee626972c114..09c7a44e058a 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -56,6 +56,11 @@ static ulong add_trailer(ulong bootconfig_start_addr, ulong 
bootconfig_size)
return BOOTCONFIG_TRAILER_SIZE;
 }
 
+__weak ulong get_avendor_bootimg_addr(void)
+{
+   return -1;
+}
+
 static void android_boot_image_v3_v4_parse_hdr(const struct 
andr_boot_img_hdr_v3 *hdr,
   struct andr_image_data *data)
 {
diff --git a/boot/image-fdt.c b/boot/image-fdt.c
index 56dd7687f51c..8332792b8e80 100644
--- a/boot/image-fdt.c
+++ b/boot/image-fdt.c
@@ -502,7 +502,7 @@ int boot_get_fdt(void *buf, const char *select, uint arch,
 * Firstly check if this android boot image has dtb field.
 */
dtb_idx = (u32)env_get_ulong("adtb_idx", 10, 0);
-   if (android_image_get_dtb_by_index((ulong)hdr, 0,
+   if (android_image_get_dtb_by_index((ulong)hdr, 
get_avendor_bootimg_addr(),
   dtb_idx, _addr, 
_size)) {
fdt_blob = (char *)map_sysmem(fdt_addr, 0);
if (fdt_check_header(fdt_blob))

-- 
2.45.2



[PATCH v3 0/5] bootstd: Add Android support

2024-07-10 Thread Mattijs Korpershoek
Android boot flow is a bit different than a regular Linux distro.
Android relies on multiple partitions in order to boot.

A typical boot flow would be:
1. Parse the Bootloader Control Block (BCB, misc partition)
2. If BCB requested bootonce-bootloader, start fastboot and wait.
3. If BCB requested recovery or normal android, run the following:
   a. Get slot (A/B) from BCB
   b. Run AVB (Android Verified Boot) on boot partitions
   c. Load boot and vendor_boot partitions
   d. Load device-tree, ramdisk and boot

The AOSP documentation has more details at [1], [2], [3]

This has been implemented via complex boot scripts such as [4].
However, these boot script are neither very maintainable nor generic.
Moreover, DISTRO_DEFAULTS is being deprecated [5].

Add a generic Android bootflow implementation for bootstd.

For this initial version, only boot image v4 is supported.

This has been tested on sandbox using:
$ ./test/py/test.py --bd sandbox --build -k test_ut

This has also been tested on the AM62X SK EVM using TI's Android SDK[6]
To test on TI board, the following (WIP) patch is needed as well:
https://gitlab.baylibre.com/baylibre/ti/ti-u-boot/-/commit/84cceb912bccd7cdd7f9dd69bca0e5d987a1fd04

[1] https://source.android.com/docs/core/architecture/bootloader
[2] https://source.android.com/docs/core/architecture/partitions
[3] https://source.android.com/docs/core/architecture/partitions/generic-boot
[4] 
https://source.denx.de/u-boot/u-boot/-/blob/master/include/configs/meson64_android.h
[5] https://lore.kernel.org/r/all/20230914165615.1058529-17-...@chromium.org/
[6] 
https://software-dl.ti.com/processor-sdk-android/esd/AM62X/09_02_00/docs/android/Overview.html

Signed-off-by: Mattijs Korpershoek 
---
Changes in v3:
- Fixed CI issues (Tom):
  * Generate bootv4.img and vendor_boot.img in test_ut.py
  * Mark CONFIG_BOOTMETH_ANDROID dependent on CONFIG_CMDLINE
  * Make bootflow_android() test dependent on CONFIG_BOOTMETH_ANDROID
  Because of the above changes, I've removed the reviewers on patch 5/5
- Link to v2: 
https://lore.kernel.org/r/20240613-bootmeth-android-v2-0-397f6e66e...@baylibre.com

Changes in v2:
- Dropped patch 2/6 boot: android: Add image_android_get_version() (Igor)
- Fixed multi-line comment style (Igor, Simon)
- Added dependency on CMD_FASTBOOT for BOOTMETH_ANDROID (Igor)
- Fixed various resource leaks (Igor)
- Fixed bootmeth_priv dangling pointer on error cases (Igor)
- Updated test instructions in commit message for patch 6/6
- Added __weak impl of get_avendor_bootimg_addr() in patch 1 (dropped
  Igor's review because of this change)
- Added extra info in Kconfig to detail MMC limitation (Simon)
- Fixed typo Bootmethod->Bootmeth (Simon)
- Documented android_priv structure (Simon)
- Demoted various messages from printf() to log_debug (Simon)
- Fixed some lines too long (Simon)
- Added function documentation to read_slotted_partition() (Simon)
- Added some doc about avb extra_args being modified (Simon)
- Link to v1: 
https://lore.kernel.org/r/20240606-bootmeth-android-v1-0-0c69d4457...@baylibre.com

---
Mattijs Korpershoek (5):
  boot: android: Provide vendor_bootimg_addr in boot_get_fdt()
  bootstd: Add bootflow_iter_check_mmc() helper
  android: boot: Add set_abootimg_addr() and set_avendor_bootimg_addr()
  bootstd: Add a bootmeth for Android
  bootstd: Add test for bootmeth_android

 MAINTAINERS   |   7 +
 arch/sandbox/dts/test.dts |   8 +
 boot/Kconfig  |  17 ++
 boot/Makefile |   2 +
 boot/bootflow.c   |  12 +
 boot/bootmeth_android.c   | 553 ++
 boot/bootmeth_android.h   |  29 +++
 boot/image-android.c  |   5 +
 boot/image-fdt.c  |   2 +-
 cmd/abootimg.c|  10 +
 configs/sandbox_defconfig |   2 +-
 doc/develop/bootstd.rst   |   6 +
 include/bootflow.h|   9 +
 include/image.h   |  14 ++
 test/boot/bootflow.c  |  68 +-
 test/py/tests/test_ut.py  |  79 +++
 16 files changed, 818 insertions(+), 5 deletions(-)
---
base-commit: 475aa8345a78396d39b42f96eccecd37ebe24e99
change-id: 20240605-bootmeth-android-bfc8596e9367

Best regards,
-- 
Mattijs Korpershoek 



Re: [PATCH] eth: asix88179: reset during probe

2024-07-09 Thread Mattijs Korpershoek
Hi Marek,

On mar., juil. 09, 2024 at 13:13, Marek Vasut  wrote:

> On 7/9/24 10:39 AM, Mattijs Korpershoek wrote:
>> Hi Caleb,
>
> Hi,
>
>> Thank you for the patch.
>> 
>> On mar., juin 18, 2024 at 16:57, Caleb Connolly  
>> wrote:
>> 
>>> In some cases (consistently in my case with an embedded board) the
>>> ethernet controller will time out on the first init but always succeed
>>> after reset.
>>>
>>> Let's reset the controller during probe so we always start with it in a
>>> known state, and don't have wait for the first asix_wait_link() to
>>> time out.
>>>
>>> Signed-off-by: Caleb Connolly 
>> 
>> Reviewed-by: Mattijs Korpershoek 
>> 
>>> ---
>>> I see this behaviour consistently across three Qualcomm platforms that use 
>>> this
>>> controller.
>>> ---
>>>   drivers/usb/eth/asix88179.c | 6 ++
>>>   1 file changed, 6 insertions(+)
>
> Do you want to pick it via usb-gadget tree or shall I pick it via usb tree ?

According to get_maintainer.pl, it should be you :)

./scripts/get_maintainer.pl -- drivers/usb/eth/asix88179.c
Marek Vasut  (maintainer:USB)
Tom Rini  (maintainer:THE 
REST,authored:3/3=100%,added_lines:1/1=100%,removed_lines:2/2=100%)
Mattijs Korpershoek  (commit_signer:1/3=33%)
u-boot@lists.denx.de (open list)

If you are okay with that, please pick it up.

Thanks!
Mattijs


Re: [PATCH v2 3/3] phy: test: Implement sandbox PHY .set_mode and DM test

2024-07-09 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On lun., juin 17, 2024 at 19:36, Marek Vasut  
wrote:

> Implement trivial extension to the sandbox PHY, which makes it pretend
> to support selecting USB Host mode and nothing else. Any other mode is
> rejected with -EINVAL. Any submode except for default submode 0 is
> rejected with -EOPNOTSUPP . The implementation behaves in this trivial
> way to permit easy unit testing using test which is also added in this
> commit.
>
> To run the test, use e.g. sandbox64_defconfig and run U-Boot as follows:
> $ ./u-boot -Tc 'ut dm phy_setup'
>
> Signed-off-by: Marek Vasut 

Reviewed-by: Mattijs Korpershoek 

> ---
> Cc: Caleb Connolly 
> Cc: Fabio Estevam 
> Cc: Fabrice Gasnier 
> Cc: Jonas Karlman 
> Cc: Mathieu Othacehe 
> Cc: Mattijs Korpershoek 
> Cc: Neil Armstrong 
> Cc: Nishanth Menon 
> Cc: Nobuhiro Iwamatsu 
> Cc: Sean Anderson 
> Cc: Simon Glass 
> Cc: Sumit Garg 
> Cc: Tim Harvey 
> Cc: Tom Rini 
> Cc: Xavier Drudis Ferran 
> Cc: u-boot-q...@groups.io
> Cc: u-boot@lists.denx.de
> ---
> V2: New patch
> ---
>  drivers/phy/sandbox-phy.c | 13 +
>  test/dm/phy.c |  7 +++
>  2 files changed, 20 insertions(+)
>
> diff --git a/drivers/phy/sandbox-phy.c b/drivers/phy/sandbox-phy.c
> index b159147a765..e70d20432e0 100644
> --- a/drivers/phy/sandbox-phy.c
> +++ b/drivers/phy/sandbox-phy.c
> @@ -72,6 +72,18 @@ static int sandbox_phy_exit(struct phy *phy)
>   return 0;
>  }
>  
> +static int
> +sandbox_phy_set_mode(struct phy *phy, enum phy_mode mode, int submode)
> +{
> + if (submode)
> + return -EOPNOTSUPP;
> +
> + if (mode != PHY_MODE_USB_HOST)
> + return -EINVAL;
> +
> + return 0;
> +}
> +
>  static int sandbox_phy_bind(struct udevice *dev)
>  {
>   if (dev_get_driver_data(dev) != DRIVER_DATA)
> @@ -96,6 +108,7 @@ static struct phy_ops sandbox_phy_ops = {
>   .power_off = sandbox_phy_power_off,
>   .init = sandbox_phy_init,
>   .exit = sandbox_phy_exit,
> + .set_mode = sandbox_phy_set_mode,
>  };
>  
>  static const struct udevice_id sandbox_phy_ids[] = {
> diff --git a/test/dm/phy.c b/test/dm/phy.c
> index a90881b12ab..a93aa83ab10 100644
> --- a/test/dm/phy.c
> +++ b/test/dm/phy.c
> @@ -246,6 +246,13 @@ static int dm_test_phy_setup(struct unit_test_state *uts)
>   ut_assertok(generic_setup_phy(parent, , 0, PHY_MODE_USB_HOST, 0));
>   ut_assertok(generic_shutdown_phy());
>  
> + /* set_mode as USB Host passes, anything else is not supported */
> + ut_assertok(generic_setup_phy(parent, , 0, PHY_MODE_USB_HOST, 0));
> + ut_assertok(generic_phy_set_mode(, PHY_MODE_USB_HOST, 0));
> + ut_asserteq(-EOPNOTSUPP, generic_phy_set_mode(, PHY_MODE_USB_HOST, 
> 1));
> + ut_asserteq(-EINVAL, generic_phy_set_mode(, PHY_MODE_USB_DEVICE, 
> 0));
> + ut_assertok(generic_shutdown_phy());
> +
>   /* power_off fail with -EIO */
>   ut_assertok(generic_setup_phy(parent, , 1, PHY_MODE_USB_HOST, 0));
>   ut_asserteq(-EIO, generic_shutdown_phy());
> -- 
> 2.43.0


Re: [PATCH v2 2/3] phy: rcar: Split init and set_mode operations

2024-07-09 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On lun., juin 17, 2024 at 19:36, Marek Vasut  
wrote:

> The current init operation also sets the PHY into USB host mode.
> Split the mode configuration into set_mode callback instead and
> implement support for device and OTG modes as well.
>
> The OTG mode performs auto-detection and selects either host or
> device mode. In case the OTG mode is configured, submode field
> can be used to select full PHY (re)initialization or only mode
> auto-detection. The full (re)initialization is only necessary
> once, on start up.
>
> Since the OTG mode may enable IRQ generation in the PHY, disable
> that IRQ generation in the exit callback again.
>
> Signed-off-by: Marek Vasut 

Reviewed-by: Mattijs Korpershoek 

> ---
> Cc: Caleb Connolly 
> Cc: Fabio Estevam 
> Cc: Fabrice Gasnier 
> Cc: Jonas Karlman 
> Cc: Mathieu Othacehe 
> Cc: Mattijs Korpershoek 
> Cc: Neil Armstrong 
> Cc: Nishanth Menon 
> Cc: Nobuhiro Iwamatsu 
> Cc: Sean Anderson 
> Cc: Simon Glass 
> Cc: Sumit Garg 
> Cc: Tim Harvey 
> Cc: Tom Rini 
> Cc: Xavier Drudis Ferran 
> Cc: u-boot-q...@groups.io
> Cc: u-boot@lists.denx.de
> ---
> V2: No change
> ---
>  drivers/phy/phy-rcar-gen3.c | 90 ++---
>  1 file changed, 85 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/phy/phy-rcar-gen3.c b/drivers/phy/phy-rcar-gen3.c
> index 7c292cae0e2..b278f995f37 100644
> --- a/drivers/phy/phy-rcar-gen3.c
> +++ b/drivers/phy/phy-rcar-gen3.c
> @@ -8,6 +8,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -31,8 +32,13 @@
>  #define USB2_LINECTRL1   0x610
>  #define USB2_ADPCTRL 0x630
>  
> +/* INT_ENABLE */
> +#define USB2_INT_ENABLE_UCOM_INTEN   BIT(3)
> +#define USB2_INT_ENABLE_USBH_INTB_EN BIT(2)
> +#define USB2_INT_ENABLE_USBH_INTA_EN BIT(1)
> +
>  /* USBCTR */
> -#define USB2_USBCTR_PLL_RST  BIT(1)
> +#define USB2_USBCTR_PLL_RST  BIT(1)
>  
>  /* SPD_RSM_TIMSET */
>  #define USB2_SPD_RSM_TIMSET_INIT 0x014e029b
> @@ -43,11 +49,23 @@
>  /* COMMCTRL */
>  #define USB2_COMMCTRL_OTG_PERI   BIT(31) /* 1 = Peripheral mode 
> */
>  
> +/* OBINTSTA and OBINTEN */
> +#define USB2_OBINT_SESSVLDCHGBIT(12)
> +#define USB2_OBINT_IDDIGCHG  BIT(11)
> +
> +/* VBCTRL */
> +#define USB2_VBCTRL_DRVVBUSSEL   BIT(8)
> +
>  /* LINECTRL1 */
> +#define USB2_LINECTRL1_DPRPD_EN  BIT(19)
>  #define USB2_LINECTRL1_DP_RPDBIT(18)
> +#define USB2_LINECTRL1_DMRPD_EN  BIT(17)
>  #define USB2_LINECTRL1_DM_RPDBIT(16)
>  
>  /* ADPCTRL */
> +#define USB2_ADPCTRL_OTGSESSVLD  BIT(20)
> +#define USB2_ADPCTRL_IDDIG   BIT(19)
> +#define USB2_ADPCTRL_IDPULLUPBIT(5)  /* 1 = ID sampling is 
> enabled */
>  #define USB2_ADPCTRL_DRVVBUS BIT(4)
>  
>  struct rcar_gen3_phy {
> @@ -65,12 +83,14 @@ static int rcar_gen3_phy_phy_init(struct phy *phy)
>   writel(USB2_SPD_RSM_TIMSET_INIT, priv->regs + USB2_SPD_RSM_TIMSET);
>   writel(USB2_OC_TIMSET_INIT, priv->regs + USB2_OC_TIMSET);
>  
> - setbits_le32(priv->regs + USB2_LINECTRL1,
> -  USB2_LINECTRL1_DP_RPD | USB2_LINECTRL1_DM_RPD);
> + return 0;
> +}
>  
> - clrbits_le32(priv->regs + USB2_COMMCTRL, USB2_COMMCTRL_OTG_PERI);
> +static int rcar_gen3_phy_phy_exit(struct phy *phy)
> +{
> + struct rcar_gen3_phy *priv = dev_get_priv(phy->dev);
>  
> - setbits_le32(priv->regs + USB2_ADPCTRL, USB2_ADPCTRL_DRVVBUS);
> + writel(0, priv->regs + USB2_INT_ENABLE);
>  
>   return 0;
>  }
> @@ -102,10 +122,70 @@ static int rcar_gen3_phy_phy_power_off(struct phy *phy)
>   return regulator_set_enable(priv->vbus_supply, false);
>  }
>  
> +static int rcar_gen3_phy_phy_set_mode(struct phy *phy, enum phy_mode mode,
> +   int submode)
> +{
> + const u32 adpdevmask = USB2_ADPCTRL_IDDIG | USB2_ADPCTRL_OTGSESSVLD;
> + struct rcar_gen3_phy *priv = dev_get_priv(phy->dev);
> + u32 adpctrl;
> +
> + if (mode == PHY_MODE_USB_OTG) {
> + if (submode) {
> + /* OTG submode is used as initialization indicator */
> + writel(USB2_INT_ENABLE_UCOM_INTEN |
> +USB2_INT_ENABLE_USBH_INTB_EN |
> +USB2_INT_ENABLE_USBH_INTA_EN,
> +priv->regs + USB2_INT_ENABLE);
> + setbits_le32(priv->regs + USB2_VBCTRL,
> +  

Re: [PATCH v2 1/3] phy: Extend generic_setup_phy() with PHY mode and submode

2024-07-09 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On lun., juin 17, 2024 at 19:36, Marek Vasut  
wrote:

> Extend generic_setup_phy() parameter list with PHY mode and submode and
> call generic_phy_set_mode() in generic_setup_phy(), so the generic PHY
> setup function can configure the PHY into correct mode before powering
> the PHY up.
>
> Update all call sites of generic_setup_phy() as well, all of which are
> USB host related, except for DM test which now behaves as a USB host
> test.
>
> Note that if the PHY driver does not implement the .set_mode callback,
> generic_phy_set_mode() call returns 0 and does not error out, so this
> should not break any existing systems.
>
> Signed-off-by: Marek Vasut 

Reviewed-by: Mattijs Korpershoek 

> ---
> Cc: Caleb Connolly 
> Cc: Fabio Estevam 
> Cc: Fabrice Gasnier 
> Cc: Jonas Karlman 
> Cc: Mathieu Othacehe 
> Cc: Mattijs Korpershoek 
> Cc: Neil Armstrong 
> Cc: Nishanth Menon 
> Cc: Nobuhiro Iwamatsu 
> Cc: Sean Anderson 
> Cc: Simon Glass 
> Cc: Sumit Garg 
> Cc: Tim Harvey 
> Cc: Tom Rini 
> Cc: Xavier Drudis Ferran 
> Cc: u-boot-q...@groups.io
> Cc: u-boot@lists.denx.de
> ---
> V2: Add failpath to return errno from generic_phy_set_mode()
> ---
>  drivers/phy/phy-uclass.c| 13 +++--
>  drivers/usb/host/ehci-generic.c |  2 +-
>  drivers/usb/host/ehci-msm.c |  2 +-
>  drivers/usb/host/ehci-mx6.c |  2 +-
>  drivers/usb/host/ehci-pci.c |  2 +-
>  drivers/usb/host/ohci-generic.c |  2 +-
>  include/generic-phy.h   |  5 -
>  test/dm/phy.c   |  8 
>  8 files changed, 24 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c
> index acdcda15b5b..777d952b041 100644
> --- a/drivers/phy/phy-uclass.c
> +++ b/drivers/phy/phy-uclass.c
> @@ -508,7 +508,8 @@ int generic_phy_power_off_bulk(struct phy_bulk *bulk)
>   return ret;
>  }
>  
> -int generic_setup_phy(struct udevice *dev, struct phy *phy, int index)
> +int generic_setup_phy(struct udevice *dev, struct phy *phy, int index,
> +   enum phy_mode mode, int submode)
>  {
>   int ret;
>  
> @@ -520,10 +521,18 @@ int generic_setup_phy(struct udevice *dev, struct phy 
> *phy, int index)
>   if (ret)
>   return ret;
>  
> + ret = generic_phy_set_mode(phy, mode, submode);
> + if (ret)
> + goto phys_mode_err;
> +
>   ret = generic_phy_power_on(phy);
>   if (ret)
> - generic_phy_exit(phy);
> + goto phys_mode_err;
> +
> + return 0;
>  
> +phys_mode_err:
> + generic_phy_exit(phy);
>   return ret;
>  }
>  
> diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c
> index 23c3ed25554..1ae3619ce25 100644
> --- a/drivers/usb/host/ehci-generic.c
> +++ b/drivers/usb/host/ehci-generic.c
> @@ -94,7 +94,7 @@ static int ehci_usb_probe(struct udevice *dev)
>   if (err)
>   goto reset_err;
>  
> - err = generic_setup_phy(dev, >phy, 0);
> + err = generic_setup_phy(dev, >phy, 0, PHY_MODE_USB_HOST, 0);
>   if (err)
>   goto regulator_err;
>  
> diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c
> index a081f71b187..b0c060b8173 100644
> --- a/drivers/usb/host/ehci-msm.c
> +++ b/drivers/usb/host/ehci-msm.c
> @@ -56,7 +56,7 @@ static int ehci_usb_probe(struct udevice *dev)
>   hcor = (struct ehci_hcor *)((phys_addr_t)hccr +
>   HC_LENGTH(ehci_readl(&(hccr)->cr_capbase)));
>  
> - ret = generic_setup_phy(dev, >phy, 0);
> + ret = generic_setup_phy(dev, >phy, 0, PHY_MODE_USB_HOST, 0);
>   if (ret)
>   return ret;
>  
> diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
> index 31cd8a50f4a..a93fa5d5455 100644
> --- a/drivers/usb/host/ehci-mx6.c
> +++ b/drivers/usb/host/ehci-mx6.c
> @@ -703,7 +703,7 @@ static int ehci_usb_probe(struct udevice *dev)
>   usb_phy_enable(ehci, priv->phy_addr);
>  #endif
>  #else
> - ret = generic_setup_phy(dev, >phy, 0);
> + ret = generic_setup_phy(dev, >phy, 0, PHY_MODE_USB_HOST, 0);
>   if (ret)
>   goto err_regulator;
>  #endif
> diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
> index 572686580cd..8d05b14e898 100644
> --- a/drivers/usb/host/ehci-pci.c
> +++ b/drivers/usb/host/ehci-pci.c
> @@ -30,7 +30,7 @@ static int ehci_pci_init(struct udevice *dev, struct 
> ehci_hccr **ret_hccr,
>   int ret;
>   u32 cmd;
>  
> - ret = generic_setup_phy(dev, >phy, 0);
> + ret = generic_setup_phy(dev, >phy, 

Re: [PATCH] eth: asix88179: reset during probe

2024-07-09 Thread Mattijs Korpershoek
Hi Caleb,

Thank you for the patch.

On mar., juin 18, 2024 at 16:57, Caleb Connolly  
wrote:

> In some cases (consistently in my case with an embedded board) the
> ethernet controller will time out on the first init but always succeed
> after reset.
>
> Let's reset the controller during probe so we always start with it in a
> known state, and don't have wait for the first asix_wait_link() to
> time out.
>
> Signed-off-by: Caleb Connolly 

Reviewed-by: Mattijs Korpershoek 

> ---
> I see this behaviour consistently across three Qualcomm platforms that use 
> this
> controller.
> ---
>  drivers/usb/eth/asix88179.c | 6 ++
>  1 file changed, 6 insertions(+)
>
> diff --git a/drivers/usb/eth/asix88179.c b/drivers/usb/eth/asix88179.c
> index 7bfd285b3aa4..a0aa5c25e428 100644
> --- a/drivers/usb/eth/asix88179.c
> +++ b/drivers/usb/eth/asix88179.c
> @@ -628,8 +628,14 @@ static int ax88179_eth_probe(struct udevice *dev)
>  
>   usb_dev = priv->ueth.pusb_dev;
>   priv->maxpacketsize = usb_dev->epmaxpacketout[AX_ENDPOINT_OUT];
>  
> + ret = asix_basic_reset(>ueth, priv);
> + if (ret) {
> + printf("Failed to reset ethernet device\n");
> + return ret;
> + }
> +
>   /* Get the MAC address */
>   ret = asix_read_mac(>ueth, pdata->enetaddr);
>   if (ret)
>   return ret;
> -- 
> 2.45.0


Re: [PATCH] include/fastboot.h: add missing types.h include

2024-07-09 Thread Mattijs Korpershoek
Hi,

On Fri, 21 Jun 2024 03:51:02 +0200, Caleb Connolly wrote:
> Fixes a compile error when building with only the TCP fastboot implementation.
> 
> 

Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu 
(u-boot-dfu)

[1/1] include/fastboot.h: add missing types.h include
  
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/b091d3872833a4b8d088ee41348a2d4ff48067cc

--
Mattijs


Re: [PATCH] include/fastboot.h: add missing types.h include

2024-07-05 Thread Mattijs Korpershoek
Hi Caleb,

Thank you for the patch.

On ven., juin 21, 2024 at 03:51, Caleb Connolly  
wrote:

> Fixes a compile error when building with only the TCP fastboot implementation.
>
> Signed-off-by: Caleb Connolly 

Reviewed-by: Mattijs Korpershoek 

> ---
>  include/fastboot.h | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/include/fastboot.h b/include/fastboot.h
> index 2ca1b907a54d..b106d6177493 100644
> --- a/include/fastboot.h
> +++ b/include/fastboot.h
> @@ -11,8 +11,10 @@
>   */
>  #ifndef _FASTBOOT_H_
>  #define _FASTBOOT_H_
>  
> +#include 
> +
>  #define FASTBOOT_VERSION "0.4"
>  
>  /*
>   * Signals u-boot fastboot code to send multiple responses by
> -- 
> 2.45.0


Re: [PATCH 00/11] usb: gadget: Introduce handle_interrupts ops to USB_GADGET_GENERIC uclass

2024-07-05 Thread Mattijs Korpershoek
Hi,

On Fri, 14 Jun 2024 02:51:15 +0200, Marek Vasut wrote:
> Introduce .ops for USB_GADGET_GENERIC uclass. The first new ops is
> .handle_interrupts which must be implemented by DM capable USB gadget
> controller drivers and must implement interrupt handling similar to
> dm_usb_gadget_handle_interrupts(). For DM USB gadget drivers this is
> a replacement for dm_usb_gadget_handle_interrupts(). Convert the DM
> USB gadget drivers to this new ops instead.
> 
> [...]

Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu 
(u-boot-dfu)

[01/11] usb: gadget: Introduce handle_interrupts ops to USB_GADGET_GENERIC 
uclass

https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/d36ef5cbedd08e9a11c6a719d853f1003173133e
[02/11] usb: gadget: cdns3: Convert interrupt handling to usb_gadget_generic_ops

https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/356542d6dd72f66031bc0fbe174a99c360ee318a
[03/11] usb: gadget: dwc2: Convert interrupt handling to usb_gadget_generic_ops

https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/2329109fbd7e48c559594c089238dc57d7fea166
[04/11] usb: gadget: dwc3: Convert interrupt handling to usb_gadget_generic_ops

https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/75f94ed82ff0a8c021decaa9a0eda56d48cba716
[05/11] usb: gadget: max3420: Convert interrupt handling to 
usb_gadget_generic_ops

https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/a75753327399d821ba70d8cb493d1bc12d1034cc
[06/11] usb: gadget: mtu3: Convert interrupt handling to usb_gadget_generic_ops

https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/2c2d7c2bab0ec6e4cd93db242822a57986680917
[07/11] usb: gadget: omap2430: Convert interrupt handling to 
usb_gadget_generic_ops

https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/521bc756cb5fea0ca8c159bd812da063e08bd351
[08/11] usb: gadget: musb: Convert interrupt handling to usb_gadget_generic_ops

https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/281eaf1ed83a09bfce6b82b86775e11d4269ad08
[09/11] usb: gadget: ux500: Convert interrupt handling to usb_gadget_generic_ops

https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/ac4bf5d48a9e85e79ced3b7195a8599c21c0a16d
[10/11] usb: gadget: sandbox: Drop dm_usb_gadget_handle_interrupts()

https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/ed8e638de1ef0ab2bf87c6c83882b275b66b292f
[11/11] usb: gadget: Mark dm_usb_gadget_handle_interrupts as non-weak for 
DM_USB_GADGET

https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/9e2c14804e4aaefe7cbb43d444f5dc83ba76c86d

--
Mattijs


Re: [PATCH 1/6] usb: gadget: g_dnl: Drop usb_gadget_controller_number()

2024-07-05 Thread Mattijs Korpershoek
Hi,

On Sun, 09 Jun 2024 23:32:14 +0200, Marek Vasut wrote:
> The bcdDevice field is defined as
> |Device release number in binary-coded decimal
> in the USB 2.0 specification. We use this field to distinguish the UDCs
> from each other. In theory this could be used on the host side to apply
> certain quirks if the "special" UDC in combination with this gadget is
> used. This hasn't been done as far as I am aware. In practice it would
> be better to fix the UDC driver before shipping since a later release
> might not need this quirk anymore.
> 
> [...]

Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu 
(u-boot-dfu)

[1/6] usb: gadget: g_dnl: Drop usb_gadget_controller_number()
  
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/0fca00114a805ec3c68c6156bc4ae6c4214a6e8a
[2/6] usb: gadget: ether: Drop usb_gadget_controller_number()
  
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/7f1b062ca4f23ea77541006759c1ec1108bdda74
[3/6] usb: gadget: Drop usb_gadget_controller_number()
  
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/2cee3bc6abc592c403140b8a7191879ce95be992
[4/6] usb: gadget: Drop all gadget_is_*() functions
  
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/db62b6a0a016b69cf0e26eea4004c3edbebd4394
[5/6] usb: gadget: Add full ep_matches() check past .match_ep() callback
  
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/bd7ec7b04f877b8b4a88d4367f100dc3f0af27a3
[6/6] usb: dwc3: gadget: Convert epautoconf workaround to match_ep callback
  
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/1918b8010c321c939fdedd6e461ccac87e0d3415

--
Mattijs


Re: [PATCH v2 0/5] bootstd: Add Android support

2024-07-04 Thread Mattijs Korpershoek
Hi Tom,

On jeu., juin 20, 2024 at 08:23, Tom Rini  wrote:

> On Thu, Jun 13, 2024 at 12:13:07PM +0200, Mattijs Korpershoek wrote:
>
>> Android boot flow is a bit different than a regular Linux distro.
>> Android relies on multiple partitions in order to boot.
>> 
>> A typical boot flow would be:
>> 1. Parse the Bootloader Control Block (BCB, misc partition)
>> 2. If BCB requested bootonce-bootloader, start fastboot and wait.
>> 3. If BCB requested recovery or normal android, run the following:
>>a. Get slot (A/B) from BCB
>>b. Run AVB (Android Verified Boot) on boot partitions
>>c. Load boot and vendor_boot partitions
>>d. Load device-tree, ramdisk and boot
>> 
>> The AOSP documentation has more details at [1], [2], [3]
>> 
>> This has been implemented via complex boot scripts such as [4].
>> However, these boot script are neither very maintainable nor generic.
>> Moreover, DISTRO_DEFAULTS is being deprecated [5].
>> 
>> Add a generic Android bootflow implementation for bootstd.
>> 
>> For this initial version, only boot image v4 is supported.
>> 
>> This has been tested on sandbox using:
>> $ ./test/py/test.py --bd sandbox --build -k test_ut
>> 
>> This has also been tested on the AM62X SK EVM using TI's Android SDK[6]
>> To test on TI board, the following (WIP) patch is needed as well:
>> https://gitlab.baylibre.com/baylibre/ti/ti-u-boot/-/commit/84cceb912bccd7cdd7f9dd69bca0e5d987a1fd04
>> 
>> [1] https://source.android.com/docs/core/architecture/bootloader
>> [2] https://source.android.com/docs/core/architecture/partitions
>> [3] https://source.android.com/docs/core/architecture/partitions/generic-boot
>> [4] 
>> https://source.denx.de/u-boot/u-boot/-/blob/master/include/configs/meson64_android.h
>> [5] https://lore.kernel.org/r/all/20230914165615.1058529-17-...@chromium.org/
>> [6] 
>> https://software-dl.ti.com/processor-sdk-android/esd/AM62X/09_02_00/docs/android/Overview.html
>
> This leads to failures in CI such as:
> === FAILURES 
> ===
> ___ test_ut_dm_init_bootstd 
> 
> test/py/tests/test_ut.py:555: in test_ut_dm_init_bootstd
> setup_android_image(u_boot_console)
> test/py/tests/test_ut.py:488: in setup_android_image
> with open(boot_img, 'rb') as inf:
> E   FileNotFoundError: [Errno 2] No such file or directory: 
> '/tmp/malta64el/bootv4.img'
> - Captured stdout call 
> -

Thank you for reporting, and sorry about the CI failure.
I think I need to somehow declare a dependency on the bootv4.img file.

I will send a v3 to fix this.

>
> -- 
> Tom


Re: [PATCH v2 0/5] bootstd: Add Android support

2024-06-19 Thread Mattijs Korpershoek
Hi Simon.

On mar., juin 18, 2024 at 21:03, Simon Glass  wrote:

> Hi Mattijs,
>
> On Mon, 17 Jun 2024 at 09:15, Mattijs Korpershoek
>  wrote:
>>
>> Hi Simon,
>>
>> On lun., juin 17, 2024 at 07:53, Simon Glass  wrote:
>>
>> > Hi Mattijs,
>> >
>> > On Thu, 13 Jun 2024 at 04:13, Mattijs Korpershoek
>> >  wrote:
>> >>
>> >> Android boot flow is a bit different than a regular Linux distro.
>> >> Android relies on multiple partitions in order to boot.
>> >>
>> >> A typical boot flow would be:
>> >> 1. Parse the Bootloader Control Block (BCB, misc partition)
>> >> 2. If BCB requested bootonce-bootloader, start fastboot and wait.
>> >> 3. If BCB requested recovery or normal android, run the following:
>> >>a. Get slot (A/B) from BCB
>> >>b. Run AVB (Android Verified Boot) on boot partitions
>> >>c. Load boot and vendor_boot partitions
>> >>d. Load device-tree, ramdisk and boot
>> >>
>> >> The AOSP documentation has more details at [1], [2], [3]
>> >>
>> >> This has been implemented via complex boot scripts such as [4].
>> >> However, these boot script are neither very maintainable nor generic.
>> >> Moreover, DISTRO_DEFAULTS is being deprecated [5].
>> >>
>> >> Add a generic Android bootflow implementation for bootstd.
>> >>
>> >> For this initial version, only boot image v4 is supported.
>> >>
>> >> This has been tested on sandbox using:
>> >> $ ./test/py/test.py --bd sandbox --build -k test_ut
>> >>
>> >> This has also been tested on the AM62X SK EVM using TI's Android SDK[6]
>> >> To test on TI board, the following (WIP) patch is needed as well:
>> >> https://gitlab.baylibre.com/baylibre/ti/ti-u-boot/-/commit/84cceb912bccd7cdd7f9dd69bca0e5d987a1fd04
>> >>
>> >> [1] https://source.android.com/docs/core/architecture/bootloader
>> >> [2] https://source.android.com/docs/core/architecture/partitions
>> >> [3] 
>> >> https://source.android.com/docs/core/architecture/partitions/generic-boot
>> >> [4] 
>> >> https://source.denx.de/u-boot/u-boot/-/blob/master/include/configs/meson64_android.h
>> >> [5] 
>> >> https://lore.kernel.org/r/all/20230914165615.1058529-17-...@chromium.org/
>> >> [6] 
>> >> https://software-dl.ti.com/processor-sdk-android/esd/AM62X/09_02_00/docs/android/Overview.html
>> >>
>> >> Signed-off-by: Mattijs Korpershoek 
>> >> ---
>> >> Changes in v2:
>> >> - Dropped patch 2/6 boot: android: Add image_android_get_version() (Igor)
>> >> - Fixed multi-line comment style (Igor, Simon)
>> >> - Added dependency on CMD_FASTBOOT for BOOTMETH_ANDROID (Igor)
>> >> - Fixed various resource leaks (Igor)
>> >> - Fixed bootmeth_priv dangling pointer on error cases (Igor)
>> >> - Updated test instructions in commit message for patch 6/6
>> >> - Added __weak impl of get_avendor_bootimg_addr() in patch 1 (dropped
>> >>   Igor's review because of this change)
>> >> - Added extra info in Kconfig to detail MMC limitation (Simon)
>> >> - Fixed typo Bootmethod->Bootmeth (Simon)
>> >> - Documented android_priv structure (Simon)
>> >> - Demoted various messages from printf() to log_debug (Simon)
>> >> - Fixed some lines too long (Simon)
>> >> - Added function documentation to read_slotted_partition() (Simon)
>> >> - Added some doc about avb extra_args being modified (Simon)
>> >> - Link to v1: 
>> >> https://lore.kernel.org/r/20240606-bootmeth-android-v1-0-0c69d4457...@baylibre.com
>> >>
>> >> ---
>> >> Mattijs Korpershoek (5):
>> >>   boot: android: Provide vendor_bootimg_addr in boot_get_fdt()
>> >>   bootstd: Add bootflow_iter_check_mmc() helper
>> >>   android: boot: Add set_abootimg_addr() and 
>> >> set_avendor_bootimg_addr()
>> >>   bootstd: Add a bootmeth for Android
>> >>   bootstd: Add test for bootmeth_android
>> >>
>> >>  MAINTAINERS   |   7 +
>> >>  arch/sandbox/dts/test.dts |   8 +
>> >>  boot/Kconfig  |  16 ++
>> >>  boot/Makefile |   2 +
>> >>  boot/bootflow.c   |  12 +
>> >>  boot/bootmeth_android.c   | 553 
>> >> ++

Re: [PATCH v3 1/1] usb: informative message if no controller

2024-06-18 Thread Mattijs Korpershoek
Hi Heinrich,

Thank you for the patch.

On mar., juin 18, 2024 at 11:58, Heinrich Schuchardt 
 wrote:

> The message 'No working controllers found' provides no clue that this
> refers to USB controllers.
>
> Provide a message that refers to USB. Use log_info().
>
> Signed-off-by: Heinrich Schuchardt 

Reviewed-by: Mattijs Korpershoek 

> ---
> v3:
>   plural controllers
> v2:
>   add 'found' at end of message
>   keep printf
> ---
>  drivers/usb/host/usb-uclass.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c
> index a1cd0ad2d66..e16432a1516 100644
> --- a/drivers/usb/host/usb-uclass.c
> +++ b/drivers/usb/host/usb-uclass.c
> @@ -388,7 +388,7 @@ int usb_init(void)
>  
>   /* if we were not able to find at least one working bus, bail out */
>   if (controllers_initialized == 0)
> - printf("No working controllers found\n");
> + printf("No USB controllers found\n");
>  
>   return usb_started ? 0 : -ENOENT;
>  }
> -- 
> 2.43.0


Re: [PATCH 11/11] usb: gadget: Mark dm_usb_gadget_handle_interrupts as non-weak for DM_USB_GADGET

2024-06-18 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch

On ven., juin 14, 2024 at 02:51, Marek Vasut  
wrote:

> The dm_usb_gadget_handle_interrupts() is not implemented by any USB
> gadget controller drivers which do enable DM_USB_GADGET anymore. Set
> the symbol as non-weak.
>
> Signed-off-by: Marek Vasut 

Reviewed-by: Mattijs Korpershoek 

> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
> ---
>  drivers/usb/gadget/udc/udc-uclass.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/udc/udc-uclass.c 
> b/drivers/usb/gadget/udc/udc-uclass.c
> index 2320039fe3b..fbe62bbce47 100644
> --- a/drivers/usb/gadget/udc/udc-uclass.c
> +++ b/drivers/usb/gadget/udc/udc-uclass.c
> @@ -18,7 +18,7 @@ usb_gadget_generic_dev_ops(struct udevice *dev)
>   return (const struct usb_gadget_generic_ops *)dev->driver->ops;
>  }
>  
> -__weak int dm_usb_gadget_handle_interrupts(struct udevice *dev)
> +int dm_usb_gadget_handle_interrupts(struct udevice *dev)
>  {
>   const struct usb_gadget_generic_ops *ops;
>  
> -- 
> 2.43.0


Re: [PATCH 10/11] usb: gadget: sandbox: Drop dm_usb_gadget_handle_interrupts()

2024-06-18 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On ven., juin 14, 2024 at 02:51, Marek Vasut  
wrote:

> Drop dm_usb_gadget_handle_interrupts() in favor of empty default
> implementation of the same in drivers/usb/gadget/udc/udc-uclass.c .
>
> Signed-off-by: Marek Vasut 

Reviewed-by: Mattijs Korpershoek 

> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
> ---
>  drivers/usb/host/usb-sandbox.c | 7 +--
>  1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/drivers/usb/host/usb-sandbox.c b/drivers/usb/host/usb-sandbox.c
> index e26f0b292ed..f687fe2c430 100644
> --- a/drivers/usb/host/usb-sandbox.c
> +++ b/drivers/usb/host/usb-sandbox.c
> @@ -123,12 +123,7 @@ static int sandbox_submit_int(struct udevice *bus, 
> struct usb_device *udev,
>   return ret;
>  }
>  
> -#if CONFIG_IS_ENABLED(DM_USB_GADGET)
> -int dm_usb_gadget_handle_interrupts(struct udevice *dev)
> -{
> - return 0;
> -}
> -#else
> +#if !CONFIG_IS_ENABLED(DM_USB_GADGET)
>  int usb_gadget_register_driver(struct usb_gadget_driver *driver)
>  {
>   struct sandbox_udc *dev = this_controller;
> -- 
> 2.43.0


Re: [PATCH 08/11] usb: gadget: musb: Convert interrupt handling to usb_gadget_generic_ops

2024-06-18 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On ven., juin 14, 2024 at 02:51, Marek Vasut  
wrote:

> Implement .handle_interrupts callback as a replacement for deprecated
> dm_usb_gadget_handle_interrupts() function. The new callback allows
> for each DM capable USB gadget controller driver to define its own
> IRQ handling implementation without colliding with other controller
> drivers.
>
> Signed-off-by: Marek Vasut 

Reviewed-by: Mattijs Korpershoek 

> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
> ---
>  drivers/usb/musb-new/ti-musb.c | 23 ++-
>  1 file changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/usb/musb-new/ti-musb.c b/drivers/usb/musb-new/ti-musb.c
> index 76e8b88369e..ec1baa9337d 100644
> --- a/drivers/usb/musb-new/ti-musb.c
> +++ b/drivers/usb/musb-new/ti-musb.c
> @@ -233,15 +233,6 @@ static int ti_musb_peripheral_of_to_plat(struct udevice 
> *dev)
>  }
>  #endif
>  
> -int dm_usb_gadget_handle_interrupts(struct udevice *dev)
> -{
> - struct ti_musb_peripheral *priv = dev_get_priv(dev);
> -
> - priv->periph->isr(0, priv->periph);
> -
> - return 0;
> -}
> -
>  static int ti_musb_peripheral_probe(struct udevice *dev)
>  {
>   struct ti_musb_peripheral *priv = dev_get_priv(dev);
> @@ -269,12 +260,26 @@ static int ti_musb_peripheral_remove(struct udevice 
> *dev)
>   return 0;
>  }
>  
> +static int ti_musb_gadget_handle_interrupts(struct udevice *dev)
> +{
> + struct ti_musb_peripheral *priv = dev_get_priv(dev);
> +
> + priv->periph->isr(0, priv->periph);
> +
> + return 0;
> +}
> +
> +static const struct usb_gadget_generic_ops ti_musb_gadget_ops = {
> + .handle_interrupts  = ti_musb_gadget_handle_interrupts,
> +};
> +
>  U_BOOT_DRIVER(ti_musb_peripheral) = {
>   .name   = "ti-musb-peripheral",
>   .id = UCLASS_USB_GADGET_GENERIC,
>  #if CONFIG_IS_ENABLED(OF_CONTROL)
>   .of_to_plat = ti_musb_peripheral_of_to_plat,
>  #endif
> + .ops= _musb_gadget_ops,
>   .probe = ti_musb_peripheral_probe,
>   .remove = ti_musb_peripheral_remove,
>   .ops= _usb_ops,
> -- 
> 2.43.0


Re: [PATCH 09/11] usb: gadget: ux500: Convert interrupt handling to usb_gadget_generic_ops

2024-06-18 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On ven., juin 14, 2024 at 02:51, Marek Vasut  
wrote:

> Implement .handle_interrupts callback as a replacement for deprecated
> dm_usb_gadget_handle_interrupts() function. The new callback allows
> for each DM capable USB gadget controller driver to define its own
> IRQ handling implementation without colliding with other controller
> drivers.
>
> Signed-off-by: Marek Vasut 

Reviewed-by: Mattijs Korpershoek 

nitpick below (up to you if you want to fix it)

> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
> ---
>  drivers/usb/musb-new/ux500.c | 22 ++
>  1 file changed, 14 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/usb/musb-new/ux500.c b/drivers/usb/musb-new/ux500.c
> index 6b4ef3c8578..89dd75b7d05 100644
> --- a/drivers/usb/musb-new/ux500.c
> +++ b/drivers/usb/musb-new/ux500.c
> @@ -91,14 +91,6 @@ static const struct musb_platform_ops ux500_musb_ops = {
>   .disable= ux500_musb_disable,
>  };
>  
> -int dm_usb_gadget_handle_interrupts(struct udevice *dev)
> -{
> - struct ux500_glue *glue = dev_get_priv(dev);
> -
> - glue->mdata.host->isr(0, glue->mdata.host);
> - return 0;
> -}
> -
>  static int ux500_musb_probe(struct udevice *dev)
>  {
>  #ifdef CONFIG_USB_MUSB_HOST
> @@ -155,6 +147,19 @@ static int ux500_musb_remove(struct udevice *dev)
>   return 0;
>  }
>  
> +static int ux500_gadget_handle_interrupts(struct udevice *dev)
> +{
> + struct ux500_glue *glue = dev_get_priv(dev);
> +
> + glue->mdata.host->isr(0, glue->mdata.host);
> +
> + return 0;
> +}
> +
> +static const struct usb_gadget_generic_ops ux500_gadget_ops = {
> + .handle_interrupts  = ux500_gadget_handle_interrupts,
> +};
> +
>  static const struct udevice_id ux500_musb_ids[] = {
>   { .compatible = "stericsson,db8500-musb" },
>   { }
> @@ -168,6 +173,7 @@ U_BOOT_DRIVER(ux500_musb) = {
>   .id = UCLASS_USB_GADGET_GENERIC,
>  #endif
>   .of_match   = ux500_musb_ids,
> + .ops= _gadget_ops,

In case of CONFIG_USB_MUSB_HOST=y, ops gets redefined below.
Can we move this assignment below
```
.id = UCLASS_USB_GADGET_GENERIC,
```
?

>   .probe  = ux500_musb_probe,
>   .remove = ux500_musb_remove,
>  #ifdef CONFIG_USB_MUSB_HOST
> -- 
> 2.43.0


Re: [PATCH 04/11] usb: gadget: dwc3: Convert interrupt handling to usb_gadget_generic_ops

2024-06-18 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On ven., juin 14, 2024 at 02:51, Marek Vasut  
wrote:

> Implement .handle_interrupts callback as a replacement for deprecated
> dm_usb_gadget_handle_interrupts() function. The new callback allows
> for each DM capable USB gadget controller driver to define its own
> IRQ handling implementation without colliding with other controller
> drivers.
>
> Signed-off-by: Marek Vasut 

Reviewed-by: Mattijs Korpershoek 

> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
> ---
>  drivers/usb/dwc3/dwc3-generic.c| 23 ++-
>  drivers/usb/dwc3/dwc3-layerscape.c | 21 +
>  2 files changed, 27 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c
> index 8db678eb85d..731ede2fead 100644
> --- a/drivers/usb/dwc3/dwc3-generic.c
> +++ b/drivers/usb/dwc3/dwc3-generic.c
> @@ -194,34 +194,39 @@ static int dwc3_generic_of_to_plat(struct udevice *dev)
>  }
>  
>  #if CONFIG_IS_ENABLED(DM_USB_GADGET)
> -int dm_usb_gadget_handle_interrupts(struct udevice *dev)
> +static int dwc3_generic_peripheral_probe(struct udevice *dev)
>  {
>   struct dwc3_generic_priv *priv = dev_get_priv(dev);
> - struct dwc3 *dwc3 = >dwc3;
>  
> - dwc3_gadget_uboot_handle_interrupt(dwc3);
> -
> - return 0;
> + return dwc3_generic_probe(dev, priv);
>  }
>  
> -static int dwc3_generic_peripheral_probe(struct udevice *dev)
> +static int dwc3_generic_peripheral_remove(struct udevice *dev)
>  {
>   struct dwc3_generic_priv *priv = dev_get_priv(dev);
>  
> - return dwc3_generic_probe(dev, priv);
> + return dwc3_generic_remove(dev, priv);
>  }
>  
> -static int dwc3_generic_peripheral_remove(struct udevice *dev)
> +static int dwc3_gadget_handle_interrupts(struct udevice *dev)
>  {
>   struct dwc3_generic_priv *priv = dev_get_priv(dev);
> + struct dwc3 *dwc3 = >dwc3;
>  
> - return dwc3_generic_remove(dev, priv);
> + dwc3_gadget_uboot_handle_interrupt(dwc3);
> +
> + return 0;
>  }
>  
> +static const struct usb_gadget_generic_ops dwc3_gadget_ops = {
> + .handle_interrupts  = dwc3_gadget_handle_interrupts,
> +};
> +
>  U_BOOT_DRIVER(dwc3_generic_peripheral) = {
>   .name   = "dwc3-generic-peripheral",
>   .id = UCLASS_USB_GADGET_GENERIC,
>   .of_to_plat = dwc3_generic_of_to_plat,
> + .ops= _gadget_ops,
>   .probe = dwc3_generic_peripheral_probe,
>   .remove = dwc3_generic_peripheral_remove,
>   .priv_auto  = sizeof(struct dwc3_generic_priv),
> diff --git a/drivers/usb/dwc3/dwc3-layerscape.c 
> b/drivers/usb/dwc3/dwc3-layerscape.c
> index ff83bf71e89..108b44c67eb 100644
> --- a/drivers/usb/dwc3/dwc3-layerscape.c
> +++ b/drivers/usb/dwc3/dwc3-layerscape.c
> @@ -99,33 +99,38 @@ static int dwc3_layerscape_of_to_plat(struct udevice *dev)
>  }
>  
>  #if CONFIG_IS_ENABLED(DM_USB_GADGET)
> -int dm_usb_gadget_handle_interrupts(struct udevice *dev)
> +static int dwc3_layerscape_peripheral_probe(struct udevice *dev)
>  {
>   struct dwc3_layerscape_priv *priv = dev_get_priv(dev);
>  
> - dwc3_gadget_uboot_handle_interrupt(>dwc3);
> -
> - return 0;
> + return dwc3_layerscape_probe(dev, priv);
>  }
>  
> -static int dwc3_layerscape_peripheral_probe(struct udevice *dev)
> +static int dwc3_layerscape_peripheral_remove(struct udevice *dev)
>  {
>   struct dwc3_layerscape_priv *priv = dev_get_priv(dev);
>  
> - return dwc3_layerscape_probe(dev, priv);
> + return dwc3_layerscape_remove(dev, priv);
>  }
>  
> -static int dwc3_layerscape_peripheral_remove(struct udevice *dev)
> +static int dwc3_layerscape_gadget_handle_interrupts(struct udevice *dev)
>  {
>   struct dwc3_layerscape_priv *priv = dev_get_priv(dev);
>  
> - return dwc3_layerscape_remove(dev, priv);
> + dwc3_gadget_uboot_handle_interrupt(>dwc3);
> +
> + return 0;
>  }
>  
> +static const struct usb_gadget_generic_ops dwc3_layerscape_gadget_ops = {
> + .handle_interrupts  = dwc3_layerscape_gadget_handle_interrupts,
> +};
> +
>  U_BOOT_DRIVER(dwc3_layerscape_peripheral) = {
>   .name   = "dwc3-layerscape-peripheral",
>   .id = UCLASS_USB_GADGET_GENERIC,
>   .of_to_plat = dwc3_layerscape_of_to_plat,
> + .ops= _layerscape_gadget_ops,
>   .probe = dwc3_layerscape_peripheral_probe,
>   .remove = dwc3_layerscape_peripheral_remove,
>   .priv_auto  = sizeof(struct dwc3_layerscape_priv),
> -- 
> 2.43.0


Re: [PATCH 06/11] usb: gadget: mtu3: Convert interrupt handling to usb_gadget_generic_ops

2024-06-18 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On ven., juin 14, 2024 at 02:51, Marek Vasut  
wrote:

> Implement .handle_interrupts callback as a replacement for deprecated
> dm_usb_gadget_handle_interrupts() function. The new callback allows
> for each DM capable USB gadget controller driver to define its own
> IRQ handling implementation without colliding with other controller
> drivers.
>
> Signed-off-by: Marek Vasut 

Reviewed-by: Mattijs Korpershoek 

> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
> ---
>  drivers/usb/mtu3/mtu3_plat.c | 23 ++-
>  1 file changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
> index ca86b58dfcd..f8e14eabfb2 100644
> --- a/drivers/usb/mtu3/mtu3_plat.c
> +++ b/drivers/usb/mtu3/mtu3_plat.c
> @@ -223,15 +223,6 @@ static const struct udevice_id ssusb_of_match[] = {
>  };
>  
>  #if CONFIG_IS_ENABLED(DM_USB_GADGET)
> -int dm_usb_gadget_handle_interrupts(struct udevice *dev)
> -{
> - struct mtu3 *mtu = dev_get_priv(dev);
> -
> - mtu3_irq(0, mtu);
> -
> - return 0;
> -}
> -
>  static int mtu3_gadget_probe(struct udevice *dev)
>  {
>   struct ssusb_mtk *ssusb = dev_to_ssusb(dev->parent);
> @@ -250,10 +241,24 @@ static int mtu3_gadget_remove(struct udevice *dev)
>   return 0;
>  }
>  
> +static int mtu3_gadget_handle_interrupts(struct udevice *dev)
> +{
> + struct mtu3 *mtu = dev_get_priv(dev);
> +
> + mtu3_irq(0, mtu);
> +
> + return 0;
> +}
> +
> +static const struct usb_gadget_generic_ops mtu3_gadget_ops = {
> + .handle_interrupts  = mtu3_gadget_handle_interrupts,
> +};
> +
>  U_BOOT_DRIVER(mtu3_peripheral) = {
>   .name = "mtu3-peripheral",
>   .id = UCLASS_USB_GADGET_GENERIC,
>   .of_match = ssusb_of_match,
> + .ops = _gadget_ops,
>   .probe = mtu3_gadget_probe,
>   .remove = mtu3_gadget_remove,
>   .priv_auto  = sizeof(struct mtu3),
> -- 
> 2.43.0


Re: [PATCH 05/11] usb: gadget: max3420: Convert interrupt handling to usb_gadget_generic_ops

2024-06-18 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On ven., juin 14, 2024 at 02:51, Marek Vasut  
wrote:

> Implement .handle_interrupts callback as a replacement for deprecated
> dm_usb_gadget_handle_interrupts() function. The new callback allows
> for each DM capable USB gadget controller driver to define its own
> IRQ handling implementation without colliding with other controller
> drivers.
>
> Signed-off-by: Marek Vasut 

Reviewed-by: Mattijs Korpershoek 

> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
> ---
>  drivers/usb/gadget/max3420_udc.c | 19 ---
>  1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/usb/gadget/max3420_udc.c 
> b/drivers/usb/gadget/max3420_udc.c
> index 5a227c0ffd9..557a1f0644e 100644
> --- a/drivers/usb/gadget/max3420_udc.c
> +++ b/drivers/usb/gadget/max3420_udc.c
> @@ -808,13 +808,6 @@ static void max3420_setup_spi(struct max3420_udc *udc)
>   spi_wr8(udc, MAX3420_REG_PINCTL, bFDUPSPI);
>  }
>  
> -int dm_usb_gadget_handle_interrupts(struct udevice *dev)
> -{
> - struct max3420_udc *udc = dev_get_priv(dev);
> -
> - return max3420_irq(udc);
> -}
> -
>  static int max3420_udc_probe(struct udevice *dev)
>  {
>   struct max3420_udc *udc = dev_get_priv(dev);
> @@ -859,6 +852,17 @@ static int max3420_udc_remove(struct udevice *dev)
>   return 0;
>  }
>  
> +static int max3420_gadget_handle_interrupts(struct udevice *dev)
> +{
> + struct max3420_udc *udc = dev_get_priv(dev);
> +
> + return max3420_irq(udc);
> +}
> +
> +static const struct usb_gadget_generic_ops max3420_gadget_ops = {
> + .handle_interrupts  = max3420_gadget_handle_interrupts,
> +};
> +
>  static const struct udevice_id max3420_ids[] = {
>   { .compatible = "maxim,max3421-udc" },
>   { }
> @@ -868,6 +872,7 @@ U_BOOT_DRIVER(max3420_generic_udc) = {
>   .name = "max3420-udc",
>   .id = UCLASS_USB_GADGET_GENERIC,
>   .of_match = max3420_ids,
> + .ops = _gadget_ops,
>   .probe = max3420_udc_probe,
>   .remove = max3420_udc_remove,
>   .priv_auto  = sizeof(struct max3420_udc),
> -- 
> 2.43.0


Re: [PATCH 03/11] usb: gadget: dwc2: Convert interrupt handling to usb_gadget_generic_ops

2024-06-18 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On ven., juin 14, 2024 at 02:51, Marek Vasut  
wrote:

> Implement .handle_interrupts callback as a replacement for deprecated
> dm_usb_gadget_handle_interrupts() function. The new callback allows
> for each DM capable USB gadget controller driver to define its own
> IRQ handling implementation without colliding with other controller
> drivers.
>
> Signed-off-by: Marek Vasut 

Reviewed-by: Mattijs Korpershoek 

> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
> ---
>  drivers/usb/gadget/dwc2_udc_otg.c | 20 +++-
>  1 file changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/usb/gadget/dwc2_udc_otg.c 
> b/drivers/usb/gadget/dwc2_udc_otg.c
> index 6bd395a6235..7e9dd6f4268 100644
> --- a/drivers/usb/gadget/dwc2_udc_otg.c
> +++ b/drivers/usb/gadget/dwc2_udc_otg.c
> @@ -941,11 +941,6 @@ int dwc2_udc_handle_interrupt(void)
>   return 0;
>  }
>  
> -int dm_usb_gadget_handle_interrupts(struct udevice *dev)
> -{
> - return dwc2_udc_handle_interrupt();
> -}
> -
>  #if CONFIG_IS_ENABLED(DM_USB_GADGET)
>  struct dwc2_priv_data {
>   struct clk_bulk clks;
> @@ -1173,6 +1168,15 @@ static int dwc2_udc_otg_remove(struct udevice *dev)
>   return dm_scan_fdt_dev(dev);
>  }
>  
> +static int dwc2_gadget_handle_interrupts(struct udevice *dev)
> +{
> + return dwc2_udc_handle_interrupt();
> +}
> +
> +static const struct usb_gadget_generic_ops dwc2_gadget_ops = {
> + .handle_interrupts  = dwc2_gadget_handle_interrupts,
> +};
> +
>  static const struct udevice_id dwc2_udc_otg_ids[] = {
>   { .compatible = "snps,dwc2" },
>   { .compatible = "brcm,bcm2835-usb" },
> @@ -1185,6 +1189,7 @@ U_BOOT_DRIVER(dwc2_udc_otg) = {
>   .name   = "dwc2-udc-otg",
>   .id = UCLASS_USB_GADGET_GENERIC,
>   .of_match = dwc2_udc_otg_ids,
> + .ops= _gadget_ops,
>   .of_to_plat = dwc2_udc_otg_of_to_plat,
>   .probe = dwc2_udc_otg_probe,
>   .remove = dwc2_udc_otg_remove,
> @@ -1200,4 +1205,9 @@ int dwc2_udc_B_session_valid(struct udevice *dev)
>  
>   return readl(_reg->gotgctl) & B_SESSION_VALID;
>  }
> +#else
> +int dm_usb_gadget_handle_interrupts(struct udevice *dev)
> +{
> + return dwc2_udc_handle_interrupt();
> +}
>  #endif /* CONFIG_IS_ENABLED(DM_USB_GADGET) */
> -- 
> 2.43.0


Re: [PATCH 02/11] usb: gadget: cdns3: Convert interrupt handling to usb_gadget_generic_ops

2024-06-18 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On ven., juin 14, 2024 at 02:51, Marek Vasut  
wrote:

> Implement .handle_interrupts callback as a replacement for deprecated
> dm_usb_gadget_handle_interrupts() function. The new callback allows
> for each DM capable USB gadget controller driver to define its own
> IRQ handling implementation without colliding with other controller
> drivers.
>
> Keep the dm_usb_gadget_handle_interrupts() in this driver for non-DM
> case for now, until this driver gets fully converted to DM USB gadget.
>
> Signed-off-by: Marek Vasut 

Reviewed-by: Mattijs Korpershoek 

> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
> ---
>  drivers/usb/cdns3/core.c  | 24 
>  drivers/usb/cdns3/gadget-export.h |  2 ++
>  drivers/usb/cdns3/gadget.c| 11 +--
>  3 files changed, 27 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
> index b4e931646b8..cbe06a9e7b6 100644
> --- a/drivers/usb/cdns3/core.c
> +++ b/drivers/usb/cdns3/core.c
> @@ -20,6 +20,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  
> @@ -462,15 +463,38 @@ static int cdns3_gadget_remove(struct udevice *dev)
>   return cdns3_remove(cdns);
>  }
>  
> +static int cdns3_gadget_handle_interrupts(struct udevice *dev)
> +{
> + struct cdns3 *cdns = dev_get_priv(dev);
> +
> + cdns3_gadget_uboot_handle_interrupt(cdns);
> +
> + return 0;
> +}
> +
> +static const struct usb_gadget_generic_ops cdns3_gadget_ops = {
> + .handle_interrupts  = cdns3_gadget_handle_interrupts,
> +};
> +
>  U_BOOT_DRIVER(cdns_usb3_peripheral) = {
>   .name   = "cdns-usb3-peripheral",
>   .id = UCLASS_USB_GADGET_GENERIC,
>   .of_match = cdns3_ids,
> + .ops= _gadget_ops,
>   .probe = cdns3_gadget_probe,
>   .remove = cdns3_gadget_remove,
>   .priv_auto  = sizeof(struct cdns3_gadget_priv),
>   .flags = DM_FLAG_ALLOC_PRIV_DMA,
>  };
> +#else
> +int dm_usb_gadget_handle_interrupts(struct udevice *dev)
> +{
> + struct cdns3 *cdns = dev_get_priv(dev);
> +
> + cdns3_gadget_uboot_handle_interrupt(cdns);
> +
> + return 0;
> +}
>  #endif
>  
>  #if defined(CONFIG_SPL_USB_HOST) || \
> diff --git a/drivers/usb/cdns3/gadget-export.h 
> b/drivers/usb/cdns3/gadget-export.h
> index 577469eee96..b3fd7c53039 100644
> --- a/drivers/usb/cdns3/gadget-export.h
> +++ b/drivers/usb/cdns3/gadget-export.h
> @@ -25,4 +25,6 @@ static inline void cdns3_gadget_exit(struct cdns3 *cdns) { }
>  
>  #endif
>  
> +void cdns3_gadget_uboot_handle_interrupt(struct cdns3 *cdns);
> +
>  #endif /* __LINUX_CDNS3_GADGET_EXPORT */
> diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c
> index d11175dc5b6..32b2c412068 100644
> --- a/drivers/usb/cdns3/gadget.c
> +++ b/drivers/usb/cdns3/gadget.c
> @@ -2755,19 +2755,10 @@ int cdns3_gadget_init(struct cdns3 *cdns)
>   *
>   * Handles ep0 and gadget interrupt
>   */
> -static void cdns3_gadget_uboot_handle_interrupt(struct cdns3 *cdns)
> +void cdns3_gadget_uboot_handle_interrupt(struct cdns3 *cdns)
>  {
>   int ret = cdns3_device_irq_handler(0, cdns);
>  
>   if (ret == IRQ_WAKE_THREAD)
>   cdns3_device_thread_irq_handler(0, cdns);
>  }
> -
> -int dm_usb_gadget_handle_interrupts(struct udevice *dev)
> -{
> - struct cdns3 *cdns = dev_get_priv(dev);
> -
> - cdns3_gadget_uboot_handle_interrupt(cdns);
> -
> - return 0;
> -}
> -- 
> 2.43.0


Re: [PATCH] usb: dwc3-generic: Fix build errors when USB_DWC3_GADGET is disabled

2024-06-18 Thread Mattijs Korpershoek
Hi Jonas,

On sam., mars 02, 2024 at 14:00, Jonas Karlman  wrote:

[...]

>> 
>> I will keep you posted.
>
> Thanks, much appreciated!
>
> Please also keep in mind that changing the interrupt handling probably
> only fixes the second of the two build errors reported and fixed by this
> patch.
>
> Trying to build with following will trigger the first build error, and
> should not change because use of dm_usb_gadget_handle_interrupts() is
> reworked.
>
> CONFIG_DM_USB_GADGET=y
> CONFIG_USB_DWC3=y
> # CONFIG_USB_DWC3_GADGET is not set
> CONFIG_USB_DWC3_GENERIC=y
> CONFIG_USB_GADGET=y
>
> E.g to only include host part of dwc3 and gadget from another driver,
> to i.e. save on binary size, produce following build error:
>
> aarch64-linux-gnu-ld.bfd: drivers/usb/dwc3/dwc3-generic.o: in function 
> `dm_usb_gadget_handle_interrupts':
> drivers/usb/dwc3/dwc3-generic.c:201:(.text.dm_usb_gadget_handle_interrupts+0x10):
>   undefined reference to `dwc3_gadget_uboot_handle_interrupt'
>
> I guess force select USB_DWC3_GADGET for USB_DWC3_GENERIC would make
> that build error disappear, and increase binary size as a result.
>
> For my RK3328 series [1] I will just revert to use USB_XHCI_DWC3 instead
> of using USB_DWC3_GENERIC on boards that enable peripheral use of otg
> port.
>
> [1] https://patchwork.ozlabs.org/patch/1904779/

Marek ended up doing this rework.
It's available for review here, if you want to have a look:
https://lore.kernel.org/all/20240614005309.34433-1-marek.vasut+rene...@mailbox.org/

>
> Regards,
> Jonas
>
>> 
>>>

[...]


Re: [PATCH 01/11] usb: gadget: Introduce handle_interrupts ops to USB_GADGET_GENERIC uclass

2024-06-18 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On ven., juin 14, 2024 at 02:51, Marek Vasut  
wrote:

> Introduce .ops for USB_GADGET_GENERIC uclass. The first new ops is
> .handle_interrupts which must be implemented by DM capable USB gadget
> controller drivers and must implement interrupt handling similar to
> dm_usb_gadget_handle_interrupts(). This patch currently provides weak
> dm_usb_gadget_handle_interrupts() implementation which is overriden by
> the drivers, but this will be removed once conversion to handle_interrupts
> callback is complete.
>
> Signed-off-by: Marek Vasut 

Reviewed-by: Mattijs Korpershoek 

> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
> ---
>  drivers/usb/gadget/udc/udc-uclass.c | 24 
>  include/linux/usb/gadget.h  |  8 
>  2 files changed, 32 insertions(+)
>
> diff --git a/drivers/usb/gadget/udc/udc-uclass.c 
> b/drivers/usb/gadget/udc/udc-uclass.c
> index 5dc23a55bb5..2320039fe3b 100644
> --- a/drivers/usb/gadget/udc/udc-uclass.c
> +++ b/drivers/usb/gadget/udc/udc-uclass.c
> @@ -12,6 +12,25 @@
>  #include 
>  
>  #if CONFIG_IS_ENABLED(DM_USB_GADGET)
> +static inline const struct usb_gadget_generic_ops *
> +usb_gadget_generic_dev_ops(struct udevice *dev)
> +{
> + return (const struct usb_gadget_generic_ops *)dev->driver->ops;
> +}
> +
> +__weak int dm_usb_gadget_handle_interrupts(struct udevice *dev)
> +{
> + const struct usb_gadget_generic_ops *ops;
> +
> + ops = usb_gadget_generic_dev_ops(dev);
> + if (!ops)
> + return -EFAULT;
> + if (!ops->handle_interrupts)
> + return -ENOSYS;
> +
> + return ops->handle_interrupts(dev);
> +}
> +
>  int udc_device_get_by_index(int index, struct udevice **udev)
>  {
>   struct udevice *dev = NULL;
> @@ -54,6 +73,11 @@ int udc_device_put(struct udevice *udev)
>  {
>   return board_usb_cleanup(legacy_index, USB_INIT_DEVICE);
>  }
> +
> +__weak int dm_usb_gadget_handle_interrupts(struct udevice *dev)
> +{
> + return 0;
> +}
>  #endif
>  
>  #if CONFIG_IS_ENABLED(DM)
> diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
> index 36572be89e6..cf2161603d6 100644
> --- a/include/linux/usb/gadget.h
> +++ b/include/linux/usb/gadget.h
> @@ -970,6 +970,14 @@ extern void usb_ep_autoconfig_reset(struct usb_gadget *);
>  
>  extern int dm_usb_gadget_handle_interrupts(struct udevice *);
>  
> +/**
> + * struct usb_gadget_generic_ops - The functions that a gadget driver must 
> implement.
> + * @handle_interrupts: Handle UDC interrupts.
> + */
> +struct usb_gadget_generic_ops {
> + int (*handle_interrupts)(struct udevice *udevice);
> +};
> +
>  /**
>   * udc_device_get_by_index() - Get UDC udevice by index
>   * @index: UDC device index
> -- 
> 2.43.0


Re: [PATCH 00/11] usb: gadget: Introduce handle_interrupts ops to USB_GADGET_GENERIC uclass

2024-06-18 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the series.

On ven., juin 14, 2024 at 02:51, Marek Vasut  
wrote:

> Introduce .ops for USB_GADGET_GENERIC uclass. The first new ops is
> .handle_interrupts which must be implemented by DM capable USB gadget
> controller drivers and must implement interrupt handling similar to
> dm_usb_gadget_handle_interrupts(). For DM USB gadget drivers this is
> a replacement for dm_usb_gadget_handle_interrupts(). Convert the DM
> USB gadget drivers to this new ops instead.
>
> DEPENDS: https://patchwork.ozlabs.org/project/uboot/list/?series=410150
>
> Marek Vasut (11):
>   usb: gadget: Introduce handle_interrupts ops to USB_GADGET_GENERIC
> uclass
>   usb: gadget: cdns3: Convert interrupt handling to
> usb_gadget_generic_ops
>   usb: gadget: dwc2: Convert interrupt handling to
> usb_gadget_generic_ops
>   usb: gadget: dwc3: Convert interrupt handling to
> usb_gadget_generic_ops
>   usb: gadget: max3420: Convert interrupt handling to
> usb_gadget_generic_ops
>   usb: gadget: mtu3: Convert interrupt handling to
> usb_gadget_generic_ops
>   usb: gadget: omap2430: Convert interrupt handling to
> usb_gadget_generic_ops
>   usb: gadget: musb: Convert interrupt handling to
> usb_gadget_generic_ops
>   usb: gadget: ux500: Convert interrupt handling to
> usb_gadget_generic_ops
>   usb: gadget: sandbox: Drop dm_usb_gadget_handle_interrupts()
>   usb: gadget: Mark dm_usb_gadget_handle_interrupts as non-weak for
> DM_USB_GADGET
>
>  drivers/usb/cdns3/core.c| 24 
>  drivers/usb/cdns3/gadget-export.h   |  2 ++
>  drivers/usb/cdns3/gadget.c  | 11 +--
>  drivers/usb/dwc3/dwc3-generic.c | 23 ++-
>  drivers/usb/dwc3/dwc3-layerscape.c  | 21 +
>  drivers/usb/gadget/dwc2_udc_otg.c   | 20 +++-
>  drivers/usb/gadget/max3420_udc.c| 19 ---
>  drivers/usb/gadget/udc/udc-uclass.c | 24 
>  drivers/usb/host/usb-sandbox.c  |  7 +--
>  drivers/usb/mtu3/mtu3_plat.c| 23 ++-
>  drivers/usb/musb-new/omap2430.c | 26 --
>  drivers/usb/musb-new/ti-musb.c  | 23 ++-
>  drivers/usb/musb-new/ux500.c| 22 ++
>  include/linux/usb/gadget.h  |  8 
>  14 files changed, 172 insertions(+), 81 deletions(-)

Tested on Khadas vim3 using fastboot, ums and usb storage scanning.

Tested-by: Mattijs Korpershoek  # vim3

>
> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
>
> -- 
> 2.43.0


Re: [PATCH v2 0/5] bootstd: Add Android support

2024-06-17 Thread Mattijs Korpershoek
Hi Simon,

On lun., juin 17, 2024 at 07:53, Simon Glass  wrote:

> Hi Mattijs,
>
> On Thu, 13 Jun 2024 at 04:13, Mattijs Korpershoek
>  wrote:
>>
>> Android boot flow is a bit different than a regular Linux distro.
>> Android relies on multiple partitions in order to boot.
>>
>> A typical boot flow would be:
>> 1. Parse the Bootloader Control Block (BCB, misc partition)
>> 2. If BCB requested bootonce-bootloader, start fastboot and wait.
>> 3. If BCB requested recovery or normal android, run the following:
>>a. Get slot (A/B) from BCB
>>b. Run AVB (Android Verified Boot) on boot partitions
>>c. Load boot and vendor_boot partitions
>>d. Load device-tree, ramdisk and boot
>>
>> The AOSP documentation has more details at [1], [2], [3]
>>
>> This has been implemented via complex boot scripts such as [4].
>> However, these boot script are neither very maintainable nor generic.
>> Moreover, DISTRO_DEFAULTS is being deprecated [5].
>>
>> Add a generic Android bootflow implementation for bootstd.
>>
>> For this initial version, only boot image v4 is supported.
>>
>> This has been tested on sandbox using:
>> $ ./test/py/test.py --bd sandbox --build -k test_ut
>>
>> This has also been tested on the AM62X SK EVM using TI's Android SDK[6]
>> To test on TI board, the following (WIP) patch is needed as well:
>> https://gitlab.baylibre.com/baylibre/ti/ti-u-boot/-/commit/84cceb912bccd7cdd7f9dd69bca0e5d987a1fd04
>>
>> [1] https://source.android.com/docs/core/architecture/bootloader
>> [2] https://source.android.com/docs/core/architecture/partitions
>> [3] https://source.android.com/docs/core/architecture/partitions/generic-boot
>> [4] 
>> https://source.denx.de/u-boot/u-boot/-/blob/master/include/configs/meson64_android.h
>> [5] https://lore.kernel.org/r/all/20230914165615.1058529-17-...@chromium.org/
>> [6] 
>> https://software-dl.ti.com/processor-sdk-android/esd/AM62X/09_02_00/docs/android/Overview.html
>>
>> Signed-off-by: Mattijs Korpershoek 
>> ---
>> Changes in v2:
>> - Dropped patch 2/6 boot: android: Add image_android_get_version() (Igor)
>> - Fixed multi-line comment style (Igor, Simon)
>> - Added dependency on CMD_FASTBOOT for BOOTMETH_ANDROID (Igor)
>> - Fixed various resource leaks (Igor)
>> - Fixed bootmeth_priv dangling pointer on error cases (Igor)
>> - Updated test instructions in commit message for patch 6/6
>> - Added __weak impl of get_avendor_bootimg_addr() in patch 1 (dropped
>>   Igor's review because of this change)
>> - Added extra info in Kconfig to detail MMC limitation (Simon)
>> - Fixed typo Bootmethod->Bootmeth (Simon)
>> - Documented android_priv structure (Simon)
>> - Demoted various messages from printf() to log_debug (Simon)
>> - Fixed some lines too long (Simon)
>> - Added function documentation to read_slotted_partition() (Simon)
>> - Added some doc about avb extra_args being modified (Simon)
>> - Link to v1: 
>> https://lore.kernel.org/r/20240606-bootmeth-android-v1-0-0c69d4457...@baylibre.com
>>
>> ---
>> Mattijs Korpershoek (5):
>>   boot: android: Provide vendor_bootimg_addr in boot_get_fdt()
>>   bootstd: Add bootflow_iter_check_mmc() helper
>>   android: boot: Add set_abootimg_addr() and set_avendor_bootimg_addr()
>>   bootstd: Add a bootmeth for Android
>>   bootstd: Add test for bootmeth_android
>>
>>  MAINTAINERS   |   7 +
>>  arch/sandbox/dts/test.dts |   8 +
>>  boot/Kconfig  |  16 ++
>>  boot/Makefile |   2 +
>>  boot/bootflow.c   |  12 +
>>  boot/bootmeth_android.c   | 553 
>> ++
>>  boot/bootmeth_android.h   |  29 +++
>>  boot/image-android.c  |   5 +
>>  boot/image-fdt.c  |   2 +-
>>  cmd/abootimg.c|  10 +
>>  configs/sandbox_defconfig |   2 +-
>>  doc/develop/bootstd.rst   |   6 +
>>  include/bootflow.h|   9 +
>>  include/image.h   |  14 ++
>>  test/boot/bootflow.c  |  65 +-
>>  test/py/tests/test_ut.py  |  76 +++
>>  16 files changed, 811 insertions(+), 5 deletions(-)
>> ---
>> base-commit: f9886bc60f42d5bcfcfa4e474af7dc230400b6be
>> change-id: 20240605-bootmeth-android-bfc8596e9367
>>
>> Best regards,
>> --
>> Mattijs Korpershoek 
>>
>
> Thinking about this, I believe we should start having docs about the
> individual bootmeths themselves.

Yes.

>
> Can you add a section about your new bootmeth? I will come up with a
> patch for the others that I know about. Perhaps
> doc/develop/bootstd.rst would be a suitable place for now?

Yes I can add a section. I would have preferred to have an example to
work from there, but I can start writing docs as well.

I'm leaving on vacation soon (without computer), so I'll be able to
send a v3 with docs included in at earliest a 2-3 weeks from now.

If you make a patch for the other bootmeths in the mean-time, please cc
me so that I can help review and have an example for Android.

Thanks!
Mattijs

>
> Regards,
> Simon


Re: [PATCH v2 2/2] bootstd: Replace bootmethod(s) -> bootmeth(s)

2024-06-17 Thread Mattijs Korpershoek
Hi Heinrich,

Thank you for your review.

On dim., juin 16, 2024 at 09:38, Heinrich Schuchardt  wrote:

> On 6/4/24 17:15, Mattijs Korpershoek wrote:
>> According to [1], we should use bootmeth when describing the
>> struct bootmeth:
>>
>> """
>> For version 2, a new naming scheme is used as above:
>>
>>  - bootdev is used instead of bootdevice, because 'device' is overused,
>>  is everywhere in U-Boot, can be confused with udevice
>
> Boot devices are udevices though they don't relate to hardware but to an
> abstract concept.
>
> bootdev is just an abbreviation. This does not make the meaning any clearer.

Per my understanding, the name for this concept is "bootdev", not
"boot device", see:

https://docs.u-boot.org/en/latest/develop/bootstd.html#introduction

>
>>  - bootmeth - because 'method' is too vanilla, appears 1300 times in
>>  U-Boot
>> """
>
> Avoiding abbreviations like bootdev and bootmeth improved readability.

The above paragraph is quoted from email [1].
In this email, Simon made the choice to use bootmeth and bootdev
when pushing the initial implementation.

This patch just corrects the places where the older terminology
(bootmethod, bootdevice) was still used.

So i'm a bit confused on why this patch got rejected.
Is it preferable to keep two terminologies for the same concept?

Thanks
Mattijs


[1] https://lore.kernel.org/u-boot/20211023232635.9195-1-...@chromium.org/

>
> Best regards
>
> Heinrich
>
>>
>> Replace all occurences in various comments for consistency.
>>
>> [1] https://lore.kernel.org/u-boot/20211023232635.9195-1-...@chromium.org/
>> Signed-off-by: Mattijs Korpershoek 
>> ---
>>   board/sandbox/sandbox.env |  2 +-
>>   boot/bootmeth-uclass.c|  2 +-
>>   include/bootmeth.h| 30 +++---
>>   include/extlinux.h|  2 +-
>>   test/boot/bootflow.c  |  2 +-
>>   test/boot/bootmeth.c  |  6 +++---
>>   6 files changed, 22 insertions(+), 22 deletions(-)
>>
>> diff --git a/board/sandbox/sandbox.env b/board/sandbox/sandbox.env
>> index a2c19702d64d..564dce78a898 100644
>> --- a/board/sandbox/sandbox.env
>> +++ b/board/sandbox/sandbox.env
>> @@ -10,7 +10,7 @@ eth6addr=02:00:11:22:33:47
>>   ipaddr=192.0.2.1
>>
>>   /*
>> - * These are used for distro boot which is not supported. But once 
>> bootmethod
>> + * These are used for distro boot which is not supported. But once bootmeth
>>* is provided these will be used again.
>>*/
>>   bootm_size=0x1000
>> diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c
>> index 1d157d54dbdd..e3475f46b34c 100644
>> --- a/boot/bootmeth-uclass.c
>> +++ b/boot/bootmeth-uclass.c
>> @@ -167,7 +167,7 @@ int bootmeth_setup_iter_order(struct bootflow_iter 
>> *iter, bool include_global)
>>  if (pass)
>>  iter->first_glob_method = upto;
>>  /*
>> - * Get a list of bootmethods, in seq order (i.e. using
>> + * Get a list of bootmeths, in seq order (i.e. using
>>   * aliases). There may be gaps so try to count up high
>>   * enough to find them all.
>>   */
>> diff --git a/include/bootmeth.h b/include/bootmeth.h
>> index 529c4d813d82..2570d9593d49 100644
>> --- a/include/bootmeth.h
>> +++ b/include/bootmeth.h
>> @@ -47,7 +47,7 @@ struct bootmeth_ops {
>>   * This may involve reading state from the system, e.g. some data in
>>   * the firmware area.
>>   *
>> - * @dev:Bootmethod device to check
>> + * @dev:Bootmeth device to check
>>   * @buf:Buffer to place the info in (terminator must fit)
>>   * @maxsize:Size of buffer
>>   * Returns: 0 if OK, -ENOSPC is buffer is too small, other -ve error if
>> @@ -74,7 +74,7 @@ struct bootmeth_ops {
>>   *
>>   * It may update only the flags in @iter
>>   *
>> - * @dev:Bootmethod device to check against
>> + * @dev:Bootmeth device to check against
>>   * @iter:   On entry, provides bootdev, hwpart, part
>>   * Return: 0 if OK, -ENOTSUPP if this bootdev is not supported
>>   */
>> @@ -83,7 +83,7 @@ struct bootmeth_ops {
>>  /**
>>   * read_bootflow() - read a bootflow for a device
>>   *
>> - * @dev:Bootmethod device to use
>> + * @dev:Bootmeth de

Re: [PATCH v2 0/5] bootstd: Add Android support

2024-06-14 Thread Mattijs Korpershoek
Hi Guillaume,

Thank you for testing.

On ven., juin 14, 2024 at 11:53, Guillaume LA ROQUE  
wrote:

> Hi,
>
> i apply  patch series with commit you give in cover letter and test on 
> TI AM62S-SK board.
> Android boot properly , just with a small changes in uboot eenv
>
> setenv vendor_boot_comp_addr_r 0xd000

I see.

Thank you for sharing this.

I can confirm that this is indeed needed on next since
da3447d09fa0 ("android: Fix ramdisk loading for bootimage v3+").

Will take that into account when sending board support using bootmeth_android

>
> this changes is need link to patch done by roman on ramdisk and vendor 
> boot loading.
>
> so you can add for this series:
>
> Tested-by: Guillaume La Roque 
>
>

[...]


[PATCH v2 2/5] bootstd: Add bootflow_iter_check_mmc() helper

2024-06-13 Thread Mattijs Korpershoek
Some bootflows might be able to only boot from MMC devices.

Add a helper function these bootflows can use.

Reviewed-by: Igor Opaniuk 
Signed-off-by: Mattijs Korpershoek 
---
 boot/bootflow.c| 12 
 include/bootflow.h |  9 +
 2 files changed, 21 insertions(+)

diff --git a/boot/bootflow.c b/boot/bootflow.c
index 9aa3179c3881..59d77d2385f4 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -575,6 +575,18 @@ int bootflow_iter_check_blk(const struct bootflow_iter 
*iter)
return -ENOTSUPP;
 }
 
+int bootflow_iter_check_mmc(const struct bootflow_iter *iter)
+{
+   const struct udevice *media = dev_get_parent(iter->dev);
+   enum uclass_id id = device_get_uclass_id(media);
+
+   log_debug("uclass %d: %s\n", id, uclass_get_name(id));
+   if (id == UCLASS_MMC)
+   return 0;
+
+   return -ENOTSUPP;
+}
+
 int bootflow_iter_check_sf(const struct bootflow_iter *iter)
 {
const struct udevice *media = dev_get_parent(iter->dev);
diff --git a/include/bootflow.h b/include/bootflow.h
index 080ee8501225..6058ddd89b16 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -407,6 +407,15 @@ void bootflow_remove(struct bootflow *bflow);
  */
 int bootflow_iter_check_blk(const struct bootflow_iter *iter);
 
+/**
+ * bootflow_iter_check_mmc() - Check that a bootflow uses a MMC device
+ *
+ * This checks the bootdev in the bootflow to make sure it uses a mmc device
+ *
+ * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. ethernet)
+ */
+int bootflow_iter_check_mmc(const struct bootflow_iter *iter);
+
 /**
  * bootflow_iter_check_sf() - Check that a bootflow uses SPI FLASH
  *

-- 
2.45.2



[PATCH v2 1/5] boot: android: Provide vendor_bootimg_addr in boot_get_fdt()

2024-06-13 Thread Mattijs Korpershoek
When calling android_image_get_dtb_by_index() using boot image v3+,
we should also pass the vendor_boot ramdisk address.

Use get_avendor_bootimg_addr() to do so.

Notes: on boot image v2, this is harmless since get_avendor_bootimg_addr()
   returns -1.
   for legacy implementations that don't have CMD_ABOOTIMG, add a weak
   implementation to avoid linking errors.

Signed-off-by: Mattijs Korpershoek 
---
 boot/image-android.c | 5 +
 boot/image-fdt.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/boot/image-android.c b/boot/image-android.c
index ee626972c114..09c7a44e058a 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -56,6 +56,11 @@ static ulong add_trailer(ulong bootconfig_start_addr, ulong 
bootconfig_size)
return BOOTCONFIG_TRAILER_SIZE;
 }
 
+__weak ulong get_avendor_bootimg_addr(void)
+{
+   return -1;
+}
+
 static void android_boot_image_v3_v4_parse_hdr(const struct 
andr_boot_img_hdr_v3 *hdr,
   struct andr_image_data *data)
 {
diff --git a/boot/image-fdt.c b/boot/image-fdt.c
index 56dd7687f51c..8332792b8e80 100644
--- a/boot/image-fdt.c
+++ b/boot/image-fdt.c
@@ -502,7 +502,7 @@ int boot_get_fdt(void *buf, const char *select, uint arch,
 * Firstly check if this android boot image has dtb field.
 */
dtb_idx = (u32)env_get_ulong("adtb_idx", 10, 0);
-   if (android_image_get_dtb_by_index((ulong)hdr, 0,
+   if (android_image_get_dtb_by_index((ulong)hdr, 
get_avendor_bootimg_addr(),
   dtb_idx, _addr, 
_size)) {
fdt_blob = (char *)map_sysmem(fdt_addr, 0);
if (fdt_check_header(fdt_blob))

-- 
2.45.2



[PATCH v2 0/5] bootstd: Add Android support

2024-06-13 Thread Mattijs Korpershoek
Android boot flow is a bit different than a regular Linux distro.
Android relies on multiple partitions in order to boot.

A typical boot flow would be:
1. Parse the Bootloader Control Block (BCB, misc partition)
2. If BCB requested bootonce-bootloader, start fastboot and wait.
3. If BCB requested recovery or normal android, run the following:
   a. Get slot (A/B) from BCB
   b. Run AVB (Android Verified Boot) on boot partitions
   c. Load boot and vendor_boot partitions
   d. Load device-tree, ramdisk and boot

The AOSP documentation has more details at [1], [2], [3]

This has been implemented via complex boot scripts such as [4].
However, these boot script are neither very maintainable nor generic.
Moreover, DISTRO_DEFAULTS is being deprecated [5].

Add a generic Android bootflow implementation for bootstd.

For this initial version, only boot image v4 is supported.

This has been tested on sandbox using:
$ ./test/py/test.py --bd sandbox --build -k test_ut

This has also been tested on the AM62X SK EVM using TI's Android SDK[6]
To test on TI board, the following (WIP) patch is needed as well:
https://gitlab.baylibre.com/baylibre/ti/ti-u-boot/-/commit/84cceb912bccd7cdd7f9dd69bca0e5d987a1fd04

[1] https://source.android.com/docs/core/architecture/bootloader
[2] https://source.android.com/docs/core/architecture/partitions
[3] https://source.android.com/docs/core/architecture/partitions/generic-boot
[4] 
https://source.denx.de/u-boot/u-boot/-/blob/master/include/configs/meson64_android.h
[5] https://lore.kernel.org/r/all/20230914165615.1058529-17-...@chromium.org/
[6] 
https://software-dl.ti.com/processor-sdk-android/esd/AM62X/09_02_00/docs/android/Overview.html

Signed-off-by: Mattijs Korpershoek 
---
Changes in v2:
- Dropped patch 2/6 boot: android: Add image_android_get_version() (Igor)
- Fixed multi-line comment style (Igor, Simon)
- Added dependency on CMD_FASTBOOT for BOOTMETH_ANDROID (Igor)
- Fixed various resource leaks (Igor)
- Fixed bootmeth_priv dangling pointer on error cases (Igor)
- Updated test instructions in commit message for patch 6/6
- Added __weak impl of get_avendor_bootimg_addr() in patch 1 (dropped
  Igor's review because of this change)
- Added extra info in Kconfig to detail MMC limitation (Simon)
- Fixed typo Bootmethod->Bootmeth (Simon)
- Documented android_priv structure (Simon)
- Demoted various messages from printf() to log_debug (Simon)
- Fixed some lines too long (Simon)
- Added function documentation to read_slotted_partition() (Simon)
- Added some doc about avb extra_args being modified (Simon)
- Link to v1: 
https://lore.kernel.org/r/20240606-bootmeth-android-v1-0-0c69d4457...@baylibre.com

---
Mattijs Korpershoek (5):
  boot: android: Provide vendor_bootimg_addr in boot_get_fdt()
  bootstd: Add bootflow_iter_check_mmc() helper
  android: boot: Add set_abootimg_addr() and set_avendor_bootimg_addr()
  bootstd: Add a bootmeth for Android
  bootstd: Add test for bootmeth_android

 MAINTAINERS   |   7 +
 arch/sandbox/dts/test.dts |   8 +
 boot/Kconfig  |  16 ++
 boot/Makefile |   2 +
 boot/bootflow.c   |  12 +
 boot/bootmeth_android.c   | 553 ++
 boot/bootmeth_android.h   |  29 +++
 boot/image-android.c  |   5 +
 boot/image-fdt.c  |   2 +-
 cmd/abootimg.c|  10 +
 configs/sandbox_defconfig |   2 +-
 doc/develop/bootstd.rst   |   6 +
 include/bootflow.h|   9 +
 include/image.h   |  14 ++
 test/boot/bootflow.c  |  65 +-
 test/py/tests/test_ut.py  |  76 +++
 16 files changed, 811 insertions(+), 5 deletions(-)
---
base-commit: f9886bc60f42d5bcfcfa4e474af7dc230400b6be
change-id: 20240605-bootmeth-android-bfc8596e9367

Best regards,
-- 
Mattijs Korpershoek 



[PATCH v2 3/5] android: boot: Add set_abootimg_addr() and set_avendor_bootimg_addr()

2024-06-13 Thread Mattijs Korpershoek
The only way to configure the load addresses for both bootimg and
vendor_bootimg is by using the "abootimg" command.
If we want to use the C API, there is no equivalent.

Add set_abootimg_addr() and set_avendor_bootimg_addr() so that we can
specify the load address from C.

This can be useful for implementing an Android bootmethod.

Reviewed-by: Igor Opaniuk 
Signed-off-by: Mattijs Korpershoek 
---
 cmd/abootimg.c  | 10 ++
 include/image.h | 14 ++
 2 files changed, 24 insertions(+)

diff --git a/cmd/abootimg.c b/cmd/abootimg.c
index 327712a536c0..ae7a1a7c83b0 100644
--- a/cmd/abootimg.c
+++ b/cmd/abootimg.c
@@ -22,6 +22,11 @@ ulong get_abootimg_addr(void)
return (_abootimg_addr == -1 ? image_load_addr : _abootimg_addr);
 }
 
+void set_abootimg_addr(ulong addr)
+{
+   _abootimg_addr = addr;
+}
+
 ulong get_ainit_bootimg_addr(void)
 {
return _ainit_bootimg_addr;
@@ -32,6 +37,11 @@ ulong get_avendor_bootimg_addr(void)
return _avendor_bootimg_addr;
 }
 
+void set_avendor_bootimg_addr(ulong addr)
+{
+   _avendor_bootimg_addr = addr;
+}
+
 static int abootimg_get_ver(int argc, char *const argv[])
 {
const struct andr_boot_img_hdr_v0 *hdr;
diff --git a/include/image.h b/include/image.h
index c5b288f62b44..df2decbf5c2a 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1970,6 +1970,13 @@ bool is_android_vendor_boot_image_header(const void 
*vendor_boot_img);
  */
 ulong get_abootimg_addr(void);
 
+/**
+ * set_abootimg_addr() - Set Android boot image address
+ *
+ * Return: no returned results
+ */
+void set_abootimg_addr(ulong addr);
+
 /**
  * get_ainit_bootimg_addr() - Get Android init boot image address
  *
@@ -1984,6 +1991,13 @@ ulong get_ainit_bootimg_addr(void);
  */
 ulong get_avendor_bootimg_addr(void);
 
+/**
+ * set_abootimg_addr() - Set Android vendor boot image address
+ *
+ * Return: no returned results
+ */
+void set_avendor_bootimg_addr(ulong addr);
+
 /**
  * board_fit_config_name_match() - Check for a matching board name
  *

-- 
2.45.2



[PATCH v2 5/5] bootstd: Add test for bootmeth_android

2024-06-13 Thread Mattijs Korpershoek
Add a unit test for testing the Android bootmethod.

This requires another mmc image (mmc7) to contain the following partitions:
- misc: contains the Bootloader Control Block (BCB)
- boot_a: contains a fake generic kernel image
- vendor_boot_a: contains a fake vendor_boot image

Also add BOOTMETH_ANDROID as a dependency on sandbox so that we can test
this with:

$ ./test/py/test.py --bd sandbox --build -k test_abootimg # build bootv4.img
$ ./test/py/test.py --bd sandbox --build -k test_ut # build the mmc7.img
$ ./test/py/test.py --bd sandbox --build -k bootflow_android

Reviewed-by: Simon Glass 
Signed-off-by: Mattijs Korpershoek 
---
 arch/sandbox/dts/test.dts |  8 +
 configs/sandbox_defconfig |  2 +-
 test/boot/bootflow.c  | 65 ++--
 test/py/tests/test_ut.py  | 76 +++
 4 files changed, 147 insertions(+), 4 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index a012f5c4c9ba..5fb5eac862ec 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -43,6 +43,7 @@
mmc4 = "/mmc4";
mmc5 = "/mmc5";
mmc6 = "/mmc6";
+   mmc7 = "/mmc7";
pci0 = 
pci1 = 
pci2 = 
@@ -1129,6 +1130,13 @@
filename = "mmc6.img";
};
 
+   /* This is used for Android tests */
+   mmc7 {
+   status = "disabled";
+   compatible = "sandbox,mmc";
+   filename = "mmc7.img";
+   };
+
pch {
compatible = "sandbox,pch";
};
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 93b52f2de5cf..bc4398f101a7 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -15,6 +15,7 @@ CONFIG_FIT=y
 CONFIG_FIT_RSASSA_PSS=y
 CONFIG_FIT_CIPHER=y
 CONFIG_FIT_VERBOSE=y
+CONFIG_BOOTMETH_ANDROID=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_MEASURED_BOOT=y
 CONFIG_BOOTSTAGE=y
@@ -40,7 +41,6 @@ CONFIG_LOG_MAX_LEVEL=9
 CONFIG_LOG_DEFAULT_LEVEL=6
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_STACKPROTECTOR=y
-CONFIG_ANDROID_AB=y
 CONFIG_CMD_CPU=y
 CONFIG_CMD_LICENSE=y
 CONFIG_CMD_SMBIOS=y
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 4511cfa7f9bf..934c4dcbad2b 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -27,6 +27,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+extern U_BOOT_DRIVER(bootmeth_android);
 extern U_BOOT_DRIVER(bootmeth_cros);
 extern U_BOOT_DRIVER(bootmeth_2script);
 
@@ -518,12 +519,12 @@ BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | 
UT_TESTF_SCAN_FDT);
  * @uts: Unit test state
  * @mmc_dev: MMC device to use, e.g. "mmc4". Note that this must remain valid
  * in the caller until
- * @bind_cros: true to bind the ChromiumOS bootmeth
+ * @bind_cros: true to bind the ChromiumOS and Android bootmeths
  * @old_orderp: Returns the original bootdev order, which must be restored
  * Returns 0 on success, -ve on failure
  */
 static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
-   bool bind_cros, const char ***old_orderp)
+   bool bind_cros_android, const char ***old_orderp)
 {
static const char *order[] = {"mmc2", "mmc1", NULL, NULL};
struct udevice *dev, *bootstd;
@@ -545,12 +546,19 @@ static int prep_mmc_bootdev(struct unit_test_state *uts, 
const char *mmc_dev,
"bootmeth_script", 0, ofnode_null(), ));
 
/* Enable the cros bootmeth if needed */
-   if (IS_ENABLED(CONFIG_BOOTMETH_CROS) && bind_cros) {
+   if (IS_ENABLED(CONFIG_BOOTMETH_CROS) && bind_cros_android) {
ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, ));
ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_cros),
"cros", 0, ofnode_null(), ));
}
 
+   /* Enable the android bootmeths if needed */
+   if (IS_ENABLED(CONFIG_BOOTMETH_ANDROID) && bind_cros_android) {
+   ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, ));
+   ut_assertok(device_bind(bootstd, 
DM_DRIVER_REF(bootmeth_android),
+   "android", 0, ofnode_null(), ));
+   }
+
/* Change the order to include the device */
std = dev_get_priv(bootstd);
old_order = std->bootdev_order;
@@ -589,6 +597,37 @@ static int scan_mmc_bootdev(struct unit_test_state *uts, 
const char *mmc_dev,
return 0;
 }
 
+/**
+ * scan_mmc_android_bootdev() - Set up an mmc bootdev so we can access other
+ * distros. Android bootflow might print "ANDROID:*" while scanning
+ *
+ * @uts: Unit test state
+ * @mmc_dev: MMC device to use, e.g. "mmc4"
+ * Returns 0 on suc

[PATCH v2 4/5] bootstd: Add a bootmeth for Android

2024-06-13 Thread Mattijs Korpershoek
Android boot flow is a bit different than a regular Linux distro.
Android relies on multiple partitions in order to boot.

A typical boot flow would be:
1. Parse the Bootloader Control Block (BCB, misc partition)
2. If BCB requested bootonce-bootloader, start fastboot and wait.
3. If BCB requested recovery or normal android, run the following:
3.a. Get slot (A/B) from BCB
3.b. Run AVB (Android Verified Boot) on boot partitions
3.c. Load boot and vendor_boot partitions
3.d. Load device-tree, ramdisk and boot

The AOSP documentation has more details at [1], [2], [3]

This has been implemented via complex boot scripts such as [4].
However, these boot script are neither very maintainable nor generic.
Moreover, DISTRO_DEFAULTS is being deprecated [5].

Add a generic Android bootflow implementation for bootstd.
For this initial version, only boot image v4 is supported.

[1] https://source.android.com/docs/core/architecture/bootloader
[2] https://source.android.com/docs/core/architecture/partitions
[3] https://source.android.com/docs/core/architecture/partitions/generic-boot
[4] 
https://source.denx.de/u-boot/u-boot/-/blob/master/include/configs/meson64_android.h
[5] https://lore.kernel.org/r/all/20230914165615.1058529-17-...@chromium.org/

Reviewed-by: Simon Glass 
Signed-off-by: Mattijs Korpershoek 
---
 MAINTAINERS |   7 +
 boot/Kconfig|  16 ++
 boot/Makefile   |   2 +
 boot/bootmeth_android.c | 553 
 boot/bootmeth_android.h |  29 +++
 doc/develop/bootstd.rst |   6 +
 6 files changed, 613 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 66783d636e3d..6d2b87720565 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -939,6 +939,13 @@ F: include/bootstd.h
 F: net/eth_bootdevice.c
 F: test/boot/
 
+BOOTMETH_ANDROID
+M: Mattijs Korpershoek 
+S: Maintained
+T: git https://source.denx.de/u-boot/custodians/u-boot-dfu.git
+F: boot/bootmeth_android.c
+F: boot/bootmeth_android.h
+
 BTRFS
 M: Marek Behún 
 R: Qu Wenruo 
diff --git a/boot/Kconfig b/boot/Kconfig
index 6f3096c15a6f..88266c8d2ed3 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -494,6 +494,22 @@ config BOOTMETH_GLOBAL
  EFI bootmgr, since they take full control over which bootdevs are
  selected to boot.
 
+config BOOTMETH_ANDROID
+   bool "Bootdev support for Android"
+   depends on X86 || ARM || SANDBOX
+   select ANDROID_AB
+   select ANDROID_BOOT_IMAGE
+   select CMD_BCB
+   select CMD_FASTBOOT
+   select PARTITION_TYPE_GUID
+   select PARTITION_UUIDS
+   help
+ Enables support for booting Android using bootstd. Android requires
+ multiple partitions (misc, boot, vbmeta, ...) in storage for booting.
+
+ Note that only MMC bootdevs are supported at present. This is caused
+ by AVB being limited to MMC devices only.
+
 config BOOTMETH_CROS
bool "Bootdev support for Chromium OS"
depends on X86 || ARM || SANDBOX
diff --git a/boot/Makefile b/boot/Makefile
index 84ccfeaecec4..75d1cd46fabf 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -66,3 +66,5 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_REQUEST) += vbe_request.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE) += vbe_simple.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_FW) += vbe_simple_fw.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_OS) += vbe_simple_os.o
+
+obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_ANDROID) += bootmeth_android.o
diff --git a/boot/bootmeth_android.c b/boot/bootmeth_android.c
new file mode 100644
index ..6e8d3e615db0
--- /dev/null
+++ b/boot/bootmeth_android.c
@@ -0,0 +1,553 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Bootmeth for Android
+ *
+ * Copyright (C) 2024 BayLibre, SAS
+ * Written by Mattijs Korpershoek 
+ */
+#define LOG_CATEGORY UCLASS_BOOTSTD
+
+#include 
+#include 
+#if CONFIG_IS_ENABLED(AVB_VERIFY)
+#include 
+#endif
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "bootmeth_android.h"
+
+#define BCB_FIELD_COMMAND_SZ 32
+#define BCB_PART_NAME "misc"
+#define BOOT_PART_NAME "boot"
+#define VENDOR_BOOT_PART_NAME "vendor_boot"
+
+/**
+ * struct android_priv - Private data
+ *
+ * This is read from the disk and recorded for use when the full Android
+ * kernel must be loaded and booted
+ *
+ * @boot_mode: Requested boot mode (normal, recovery, bootloader)
+ * @slot: Nul-terminated partition slot suffix read from BCB ("a\0" or "b\0")
+ * @header_version: Android boot image header version
+ */
+struct android_priv {
+   enum android_boot_mode boot_mode;
+   char slot[2];
+   u32 header_version;
+};
+
+static int android_check(struct udevice *dev, struct bootflow_iter *iter)
+{
+   /* This only works on mmc devices */
+   if (bootflow_iter_check_mmc(iter))
+   return log_msg

Re: [PATCH 5/6] bootstd: Add a bootmeth for Android

2024-06-12 Thread Mattijs Korpershoek
Hi Simon,

Thank you for your review.

On mar., juin 11, 2024 at 12:52, Simon Glass  wrote:

> Hi Mattijs,
>
> On Thu, 6 Jun 2024 at 06:24, Mattijs Korpershoek
>  wrote:
>>
>> Android boot flow is a bit different than a regular Linux distro.
>> Android relies on multiple partitions in order to boot.
>>
>> A typical boot flow would be:
>> 1. Parse the Bootloader Control Block (BCB, misc partition)
>> 2. If BCB requested bootonce-bootloader, start fastboot and wait.
>> 3. If BCB requested recovery or normal android, run the following:
>> 3.a. Get slot (A/B) from BCB
>> 3.b. Run AVB (Android Verified Boot) on boot partitions
>> 3.c. Load boot and vendor_boot partitions
>> 3.d. Load device-tree, ramdisk and boot
>>
>> The AOSP documentation has more details at [1], [2], [3]
>>
>> This has been implemented via complex boot scripts such as [4].
>> However, these boot script are neither very maintainable nor generic.
>> Moreover, DISTRO_DEFAULTS is being deprecated [5].
>>
>> Add a generic Android bootflow implementation for bootstd.
>> For this initial version, only boot image v4 is supported.
>>
>> [1] https://source.android.com/docs/core/architecture/bootloader
>> [2] https://source.android.com/docs/core/architecture/partitions
>> [3] https://source.android.com/docs/core/architecture/partitions/generic-boot
>> [4] 
>> https://source.denx.de/u-boot/u-boot/-/blob/master/include/configs/meson64_android.h
>> [5] https://lore.kernel.org/r/all/20230914165615.1058529-17-...@chromium.org/
>>
>> Signed-off-by: Mattijs Korpershoek 
>> ---
>>  MAINTAINERS |   7 +
>>  boot/Kconfig|  14 ++
>>  boot/Makefile   |   2 +
>>  boot/bootmeth_android.c | 522 
>> 
>>  boot/bootmeth_android.h |  27 +++
>>  doc/develop/bootstd.rst |   6 +
>>  6 files changed, 578 insertions(+)
>
> Reviewed-by: Simon Glass 
>
> nits below
>
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 66783d636e3d..6d2b87720565 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -939,6 +939,13 @@ F: include/bootstd.h
>>  F: net/eth_bootdevice.c
>>  F: test/boot/
>>
>> +BOOTMETH_ANDROID
>> +M: Mattijs Korpershoek 
>> +S: Maintained
>> +T: git https://source.denx.de/u-boot/custodians/u-boot-dfu.git
>> +F: boot/bootmeth_android.c
>> +F: boot/bootmeth_android.h
>> +
>>  BTRFS
>>  M: Marek Behún 
>>  R: Qu Wenruo 
>> diff --git a/boot/Kconfig b/boot/Kconfig
>> index 6f3096c15a6f..5fa6f3b8315d 100644
>> --- a/boot/Kconfig
>> +++ b/boot/Kconfig
>> @@ -494,6 +494,20 @@ config BOOTMETH_GLOBAL
>>   EFI bootmgr, since they take full control over which bootdevs are
>>   selected to boot.
>>
>> +config BOOTMETH_ANDROID
>> +   bool "Bootdev support for Android"
>> +   depends on X86 || ARM || SANDBOX
>> +   select ANDROID_AB
>> +   select ANDROID_BOOT_IMAGE
>> +   select CMD_BCB
>> +   select PARTITION_TYPE_GUID
>> +   select PARTITION_UUIDS
>> +   help
>> + Enables support for booting Android using bootdevs. Android 
>> requires
>
> using standard boot (or using bootstd).

Will do for v2.

>
>> + multiple partitions (misc, boot, vbmeta, ...) in storage for 
>> booting.
>> +
>> + Note that only MMC bootdevs are supported at present.
>
> Why is that limitation present? Can you please mention what is needed
> to remove it?

Mainly because we use AVB and AVB is hard-coded for MMC. Alistair
submitted changes to convert to generic block devices here:

https://lore.kernel.org/all/20220926220211.868968-1-ade...@google.com/

There were some review comments but I did not see any v2 on the list.

I will add a comment in the KConfig description.

>
>> +
>>  config BOOTMETH_CROS
>> bool "Bootdev support for Chromium OS"
>> depends on X86 || ARM || SANDBOX
>> diff --git a/boot/Makefile b/boot/Makefile
>> index 84ccfeaecec4..75d1cd46fabf 100644
>> --- a/boot/Makefile
>> +++ b/boot/Makefile
>> @@ -66,3 +66,5 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_REQUEST) += 
>> vbe_request.o
>>  obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE) += vbe_simple.o
>>  obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_FW) += vbe_simple_fw.o
>>  obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_OS) += vbe_simple_os.o
>> +
>> +obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_ANDROID) += bootmeth_and

Re: [PATCH 5/6] bootstd: Add a bootmeth for Android

2024-06-11 Thread Mattijs Korpershoek
Hi Igor,

Thank you for your quick review.

On lun., juin 10, 2024 at 17:15, Igor Opaniuk  wrote:

> Hi Mattijs,
>
> On Thu, Jun 6, 2024 at 2:24 PM Mattijs Korpershoek
>  wrote:
>>
>> Android boot flow is a bit different than a regular Linux distro.
>> Android relies on multiple partitions in order to boot.
>>
>> A typical boot flow would be:
>> 1. Parse the Bootloader Control Block (BCB, misc partition)
>> 2. If BCB requested bootonce-bootloader, start fastboot and wait.
>> 3. If BCB requested recovery or normal android, run the following:
>> 3.a. Get slot (A/B) from BCB
>> 3.b. Run AVB (Android Verified Boot) on boot partitions
>> 3.c. Load boot and vendor_boot partitions
>> 3.d. Load device-tree, ramdisk and boot
>>
>> The AOSP documentation has more details at [1], [2], [3]
>>
>> This has been implemented via complex boot scripts such as [4].
>> However, these boot script are neither very maintainable nor generic.
>> Moreover, DISTRO_DEFAULTS is being deprecated [5].
>>
>> Add a generic Android bootflow implementation for bootstd.
>> For this initial version, only boot image v4 is supported.
>>
>> [1] https://source.android.com/docs/core/architecture/bootloader
>> [2] https://source.android.com/docs/core/architecture/partitions
>> [3] https://source.android.com/docs/core/architecture/partitions/generic-boot
>> [4] 
>> https://source.denx.de/u-boot/u-boot/-/blob/master/include/configs/meson64_android.h
>> [5] https://lore.kernel.org/r/all/20230914165615.1058529-17-...@chromium.org/
>>
>> Signed-off-by: Mattijs Korpershoek 
>> ---
>>  MAINTAINERS |   7 +
>>  boot/Kconfig|  14 ++
>>  boot/Makefile   |   2 +
>>  boot/bootmeth_android.c | 522 
>> 
>>  boot/bootmeth_android.h |  27 +++
>>  doc/develop/bootstd.rst |   6 +
>>  6 files changed, 578 insertions(+)
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 66783d636e3d..6d2b87720565 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -939,6 +939,13 @@ F: include/bootstd.h
>>  F: net/eth_bootdevice.c
>>  F: test/boot/
>>
>> +BOOTMETH_ANDROID
>> +M: Mattijs Korpershoek 
>> +S: Maintained
>> +T: git https://source.denx.de/u-boot/custodians/u-boot-dfu.git
>> +F: boot/bootmeth_android.c
>> +F: boot/bootmeth_android.h
>> +
>>  BTRFS
>>  M: Marek Behún 
>>  R: Qu Wenruo 
>> diff --git a/boot/Kconfig b/boot/Kconfig
>> index 6f3096c15a6f..5fa6f3b8315d 100644
>> --- a/boot/Kconfig
>> +++ b/boot/Kconfig
>> @@ -494,6 +494,20 @@ config BOOTMETH_GLOBAL
>>   EFI bootmgr, since they take full control over which bootdevs are
>>   selected to boot.
>>
>> +config BOOTMETH_ANDROID
>> +   bool "Bootdev support for Android"
>> +   depends on X86 || ARM || SANDBOX
>> +   select ANDROID_AB
>> +   select ANDROID_BOOT_IMAGE
>> +   select CMD_BCB
>> +   select PARTITION_TYPE_GUID
>> +   select PARTITION_UUIDS
>> +   help
>> + Enables support for booting Android using bootdevs. Android 
>> requires
>> + multiple partitions (misc, boot, vbmeta, ...) in storage for 
>> booting.
>> +
>> + Note that only MMC bootdevs are supported at present.
>> +
>>  config BOOTMETH_CROS
>> bool "Bootdev support for Chromium OS"
>> depends on X86 || ARM || SANDBOX
>> diff --git a/boot/Makefile b/boot/Makefile
>> index 84ccfeaecec4..75d1cd46fabf 100644
>> --- a/boot/Makefile
>> +++ b/boot/Makefile
>> @@ -66,3 +66,5 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_REQUEST) += 
>> vbe_request.o
>>  obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE) += vbe_simple.o
>>  obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_FW) += vbe_simple_fw.o
>>  obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_OS) += vbe_simple_os.o
>> +
>> +obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_ANDROID) += bootmeth_android.o
>> diff --git a/boot/bootmeth_android.c b/boot/bootmeth_android.c
>> new file mode 100644
>> index ..26d548d2fd6e
>> --- /dev/null
>> +++ b/boot/bootmeth_android.c
>> @@ -0,0 +1,522 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/*
>> + * Bootmethod for Android
>> + *
>> + * Copyright (C) 2024 BayLibre, SAS
>> + * Written by Mattijs Korpershoek 
>> + */
>> +#define LOG_CATEGORY UCLASS_BOOTSTD
>> +
>> +#include 
>> +#include 
>

Re: [PATCH 3/6] usb: gadget: Drop usb_gadget_controller_number()

2024-06-11 Thread Mattijs Korpershoek
Hi Lukasz,

On mar., juin 11, 2024 at 10:51, Lukasz Majewski  wrote:

> On Tue, 11 Jun 2024 09:20:33 +0200
> Mattijs Korpershoek  wrote:

[...]

>
>> > -- 
>> > 2.43.0  
>
> FInally. :-)
>
> Thanks Mattijs for this cleanup.

You should thank Marek, i've just reviewed his work :)

>
> Reviewed-by: Lukasz Majewski 
>
>
> Best regards,
>
> Lukasz Majewski
>
> --
>
> DENX Software Engineering GmbH,  Managing Director: Erika Unter
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


Re: [PATCH 3/6] bootstd: Add bootflow_iter_check_mmc() helper

2024-06-11 Thread Mattijs Korpershoek
Hi Igor,

Thank you for the review.

On lun., juin 10, 2024 at 11:31, Igor Opaniuk  wrote:

> Hi Mattijs,
>
> On Thu, Jun 6, 2024 at 2:24 PM Mattijs Korpershoek
>  wrote:
>>
>> Some bootflows might be able to only boot from MMC devices.
>>
>> Add a helper function these bootflows can use.
>>
>> Signed-off-by: Mattijs Korpershoek 
>> ---
>>  boot/bootflow.c| 12 
>>  include/bootflow.h |  9 +
>>  2 files changed, 21 insertions(+)
>>
>> diff --git a/boot/bootflow.c b/boot/bootflow.c
>> index 9aa3179c3881..59d77d2385f4 100644
>> --- a/boot/bootflow.c
>> +++ b/boot/bootflow.c
>> @@ -575,6 +575,18 @@ int bootflow_iter_check_blk(const struct bootflow_iter 
>> *iter)
>> return -ENOTSUPP;
>>  }
>>
>> +int bootflow_iter_check_mmc(const struct bootflow_iter *iter)
>> +{
>> +   const struct udevice *media = dev_get_parent(iter->dev);
>> +   enum uclass_id id = device_get_uclass_id(media);
>> +
>> +   log_debug("uclass %d: %s\n", id, uclass_get_name(id));
>> +   if (id == UCLASS_MMC)
>> +   return 0;
>> +
>> +   return -ENOTSUPP;
>> +}
>> +
>>  int bootflow_iter_check_sf(const struct bootflow_iter *iter)
>>  {
>> const struct udevice *media = dev_get_parent(iter->dev);
>> diff --git a/include/bootflow.h b/include/bootflow.h
>> index 080ee8501225..6058ddd89b16 100644
>> --- a/include/bootflow.h
>> +++ b/include/bootflow.h
>> @@ -407,6 +407,15 @@ void bootflow_remove(struct bootflow *bflow);
>>   */
>>  int bootflow_iter_check_blk(const struct bootflow_iter *iter);
>>
>> +/**
>> + * bootflow_iter_check_mmc() - Check that a bootflow uses a MMC device
>> + *
>> + * This checks the bootdev in the bootflow to make sure it uses a mmc device
>> + *
>> + * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. ethernet)
>> + */
>> +int bootflow_iter_check_mmc(const struct bootflow_iter *iter);
>> +
>>  /**
>>   * bootflow_iter_check_sf() - Check that a bootflow uses SPI FLASH
>>   *
>>
>> --
>> 2.45.0
>>
>
> Reviewed-by: Igor Opaniuk 
>
> A bit offtopic (just an idea for future refactoring), but I think all these
> bootflow_iter_check_* helpers should be replaced by just one
> int bootflow_iter_check_id(const struct bootflow_iter *iter, enum uclass_id 
> id)
> to avoid code duplication or at least keep all these
> bootmedia-specific functions as
> wrappers with one-line call to bootflow_iter_check_id(iter,
> UCLASS_SPI_*) inside.

I like this idea as well, I'll consider to implement this as a future 
refactoring.

>
> -- 
> Best regards - Atentamente - Meilleures salutations
>
> Igor Opaniuk
>
> mailto: igor.opan...@gmail.com
> skype: igor.opanyuk
> https://www.linkedin.com/in/iopaniuk


Re: [PATCH 2/6] boot: android: Add image_android_get_version()

2024-06-11 Thread Mattijs Korpershoek
Hi Igor,

Thank you for the review.

On lun., juin 10, 2024 at 11:20, Igor Opaniuk  wrote:

> Hi Mattijs,
>
> On Thu, Jun 6, 2024 at 2:24 PM Mattijs Korpershoek
>  wrote:
>>
>> When reading a boot image header, we may need to retrieve the header
>> version.
>>
>> Add a helper function for it.
>>
>> Signed-off-by: Mattijs Korpershoek 
>> ---
>>  boot/image-android.c | 7 ++-
>>  include/image.h  | 7 +++
>>  2 files changed, 13 insertions(+), 1 deletion(-)
>>
>> diff --git a/boot/image-android.c b/boot/image-android.c
>> index ddd8ffd5e540..4f8fb51585eb 100644
>> --- a/boot/image-android.c
>> +++ b/boot/image-android.c
>> @@ -185,7 +185,7 @@ bool android_image_get_data(const void *boot_hdr, const 
>> void *vendor_boot_hdr,
>> return false;
>> }
>>
>> -   if (((struct andr_boot_img_hdr_v0 *)boot_hdr)->header_version > 2) {
>> +   if (android_image_get_version(boot_hdr) > 2) {
>> if (!vendor_boot_hdr) {
>> printf("For boot header v3+ vendor boot image has to 
>> be provided\n");
>> return false;
>> @@ -203,6 +203,11 @@ bool android_image_get_data(const void *boot_hdr, const 
>> void *vendor_boot_hdr,
>> return true;
>>  }
>>
>> +u32 android_image_get_version(const void *hdr)
>> +{
>> +   return ((struct andr_boot_img_hdr_v0 *)hdr)->header_version;
>> +}
>> +
>>  static ulong android_image_get_kernel_addr(struct andr_image_data *img_data)
>>  {
>> /*
>> diff --git a/include/image.h b/include/image.h
>> index acffd17e0dfd..18e5ced5ab42 100644
>> --- a/include/image.h
>> +++ b/include/image.h
>> @@ -1963,6 +1963,13 @@ bool is_android_boot_image_header(const void *hdr);
>>   */
>>  bool is_android_vendor_boot_image_header(const void *vendor_boot_img);
>>
>> +/**
>> + * android_image_get_version() - Retrieve the boot.img version
>> + *
>> + * Return: Android boot image header version.
>> + */
>> +u32 android_image_get_version(const void *hdr);
>> +
>>  /**
>>   * get_abootimg_addr() - Get Android boot image address
>>   *
>>
>> --
>> 2.45.0
>>
> why introduce a helper function if there is only one user of it?

I added a second user of the helper function in patch 5/6.

>
> android_image_get_data() expects andr_boot_img_hdr_v0 anyway,
> as it has an explicit check for it in the very beginning
> (is_android_boot_image_header()).

Right.

>
> Have you considered adjusting android_image_get_data() declaration, and just 
> use
> andr_boot_img_hdr_v0 *boot_hdr as first param instead (like it's done
> for example in
> android_boot_image_v0_v1_v2_parse_hdr()) and then rely on implicit
> cast when this
> function is used.
>
> this is of course all a matter of preference, just thinking out loud

I've given this some more thought, and since I'm already using
struct andr_boot_img_hdr_v0 in bootmeth_android/scan_boot_part(), I will
drop this patch for v2.

The helper seems indeed a bit useless given that we can use the struct's
member for this.

Thanks!

>
> -- 
> Best regards - Atentamente - Meilleures salutations
>
> Igor Opaniuk
>
> mailto: igor.opan...@gmail.com
> skype: igor.opanyuk
> https://www.linkedin.com/in/iopaniuk


Re: [PATCH 6/6] usb: dwc3: gadget: Convert epautoconf workaround to match_ep callback

2024-06-11 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On dim., juin 09, 2024 at 23:32, Marek Vasut  
wrote:

> Use the .match_ep() callback instead of workaround in core code.
> Replace descriptor parsing with ch9 macros with the same effect.
> Drop the SPL specific behavior, it is unclear why SPL should even
> be special.

Li, Peng,

Is this good for you as well?

You seem to be the author/committer of:
c93edbf5385e ("usb: gadget: don't change ep name for dwc3 while ep autoconfig")

I'd like to make sure this patch does not break your use-case.
Please let me know within 2 weeks or so, otherwise I'll apply the changes.

>
> Signed-off-by: Marek Vasut 

To me, this looks good.

Reviewed-by: Mattijs Korpershoek 
Tested-by: Mattijs Korpershoek  # on vim3

> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
> ---
>  drivers/usb/dwc3/gadget.c   | 33 +++
>  drivers/usb/gadget/epautoconf.c | 46 +
>  2 files changed, 34 insertions(+), 45 deletions(-)
>
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index fab32575647..3ef2f016a60 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -1606,6 +1606,38 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
>   return 0;
>  }
>  
> +static struct usb_ep *dwc3_find_ep(struct usb_gadget *gadget, const char 
> *name)
> +{
> + struct usb_ep *ep;
> +
> + list_for_each_entry(ep, >ep_list, ep_list)
> + if (!strcmp(ep->name, name))
> + return ep;
> +
> + return NULL;
> +}
> +
> +static struct
> +usb_ep *dwc3_gadget_match_ep(struct usb_gadget *gadget,
> +  struct usb_endpoint_descriptor *desc,
> +  struct usb_ss_ep_comp_descriptor *comp_desc)
> +{
> + /*
> +  * First try standard, common configuration: ep1in-bulk,
> +  * ep2out-bulk, ep3in-int to match other udc drivers to avoid
> +  * confusion in already deployed software (endpoint numbers
> +  * hardcoded in userspace software/drivers)
> +  */
> + if (usb_endpoint_is_bulk_in(desc))
> + return dwc3_find_ep(gadget, "ep1in");
> + if (usb_endpoint_is_bulk_out(desc))
> + return dwc3_find_ep(gadget, "ep2out");
> + if (usb_endpoint_is_int_in(desc))
> + return dwc3_find_ep(gadget, "ep3in");
> +
> + return NULL;
> +}
> +
>  static const struct usb_gadget_ops dwc3_gadget_ops = {
>   .get_frame  = dwc3_gadget_get_frame,
>   .wakeup = dwc3_gadget_wakeup,
> @@ -1613,6 +1645,7 @@ static const struct usb_gadget_ops dwc3_gadget_ops = {
>   .pullup = dwc3_gadget_pullup,
>   .udc_start  = dwc3_gadget_start,
>   .udc_stop   = dwc3_gadget_stop,
> + .match_ep   = dwc3_gadget_match_ep,
>  };
>  
>  /* 
> -- */
> diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
> index 66599ce8efa..a4da4f72de9 100644
> --- a/drivers/usb/gadget/epautoconf.c
> +++ b/drivers/usb/gadget/epautoconf.c
> @@ -166,18 +166,6 @@ static int ep_matches(
>   return 1;
>  }
>  
> -static struct usb_ep *
> -find_ep(struct usb_gadget *gadget, const char *name)
> -{
> - struct usb_ep   *ep;
> -
> - list_for_each_entry(ep, >ep_list, ep_list) {
> - if (0 == strcmp(ep->name, name))
> - return ep;
> - }
> - return NULL;
> -}
> -
>  /**
>   * usb_ep_autoconfig - choose an endpoint matching the descriptor
>   * @gadget: The device to which the endpoint must belong.
> @@ -213,39 +201,7 @@ struct usb_ep *usb_ep_autoconfig(
>   struct usb_endpoint_descriptor  *desc
>  )
>  {
> - struct usb_ep   *ep = NULL;
> - u8  type;
> -
> - type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
> -
> - /* First, apply chip-specific "best usage" knowledge.
> -  * This might make a good usb_gadget_ops hook ...
> -  */
> - if (!IS_ENABLED(CONFIG_SPL_BUILD) &&
> - IS_ENABLED(CONFIG_USB_DWC3_GADGET) &&
> - !strcmp("dwc3-gadget", gadget->name)) {
> - const char *name = NULL;
> - /*
> -  * First try standard, common configuration: ep1in-bulk,
> -  * ep2out-bulk, ep3in-int to match other udc driver

Re: [PATCH 5/6] usb: gadget: Add full ep_matches() check past .match_ep() callback

2024-06-11 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On dim., juin 09, 2024 at 23:32, Marek Vasut  
wrote:

> If .match_ep() callback returns non-NULL endpoint, immediately check
> its usability and if the returned endpoint is usable, stop search and
> return the endpoint. Otherwise, continue with best effort search for
> usable endpoint.
>
> Currently the code would attempt the best effort search in any case,
> which may find another unexpected endpoint. It is likely that the
> intention of the original code was to stop the search early.
>
> Fixes: 77dcbdf3c1ce ("usb: gadget: Add match_ep() op to usb_gadget_ops")
> Signed-off-by: Marek Vasut 

I've added Vignesh to the CC list since he is the author of
77dcbdf3c1ce. He might be able to comment if this was indeed a mistake.

It looks like a good fix to me as well. With this change we match more closely
the linux implementation (usb_ep_autoconfig_ss()).

Reviewed-by: Mattijs Korpershoek 
Tested-by: Mattijs Korpershoek  # on vim3

> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
> ---
>  drivers/usb/gadget/epautoconf.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
> index 09950ceeaed..66599ce8efa 100644
> --- a/drivers/usb/gadget/epautoconf.c
> +++ b/drivers/usb/gadget/epautoconf.c
> @@ -247,8 +247,11 @@ struct usb_ep *usb_ep_autoconfig(
>   return ep;
>   }
>  
> - if (gadget->ops->match_ep)
> + if (gadget->ops->match_ep) {
>   ep = gadget->ops->match_ep(gadget, desc, NULL);
> + if (ep && ep_matches(gadget, ep, desc))
> + return ep;
> + }
>  
>   /* Second, look at endpoints until an unclaimed one looks usable */
>   list_for_each_entry(ep, >ep_list, ep_list) {
> -- 
> 2.43.0


Re: [PATCH 4/6] usb: gadget: Drop all gadget_is_*() functions

2024-06-11 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On dim., juin 09, 2024 at 23:32, Marek Vasut  
wrote:

> The only actually used gadget_is_*() functions are the one for DWC3
> used in epautoconf.c usb_ep_autoconfig() and one for MUSB in ether.c.
> The DWC3 one should be fixed in some separate patch.
>
> Inline the gadget_is_dwc3() and stop using ifdefs in favor of
> IS_ENABLED() macro.
>
> The rest of gadget_is_*() calls in usb_ep_autoconfig() can never
> be anything but 0, since those gadgets are not supported in U-Boot,
> so remove all that unused code. Remove gadget_chips.h as well.
>
> Signed-off-by: Marek Vasut 

Reviewed-by: Mattijs Korpershoek 
Tested-by: Mattijs Korpershoek  # on vim3

> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
> ---
>  drivers/usb/gadget/epautoconf.c   |  40 +---
>  drivers/usb/gadget/ether.c|   8 +-
>  drivers/usb/gadget/gadget_chips.h | 148 --
>  3 files changed, 6 insertions(+), 190 deletions(-)
>  delete mode 100644 drivers/usb/gadget/gadget_chips.h
>
> diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
> index 0a70035ce04..09950ceeaed 100644
> --- a/drivers/usb/gadget/epautoconf.c
> +++ b/drivers/usb/gadget/epautoconf.c
> @@ -12,7 +12,6 @@
>  #include 
>  #include 
>  #include 
> -#include "gadget_chips.h"
>  
>  #define isdigit(c)  ('0' <= (c) && (c) <= '9')
>  
> @@ -222,41 +221,9 @@ struct usb_ep *usb_ep_autoconfig(
>   /* First, apply chip-specific "best usage" knowledge.
>* This might make a good usb_gadget_ops hook ...
>*/
> - if (gadget_is_net2280(gadget) && type == USB_ENDPOINT_XFER_INT) {
> - /* ep-e, ep-f are PIO with only 64 byte fifos */
> - ep = find_ep(gadget, "ep-e");
> - if (ep && ep_matches(gadget, ep, desc))
> - return ep;
> - ep = find_ep(gadget, "ep-f");
> - if (ep && ep_matches(gadget, ep, desc))
> - return ep;
> -
> - } else if (gadget_is_goku(gadget)) {
> - if (USB_ENDPOINT_XFER_INT == type) {
> - /* single buffering is enough */
> - ep = find_ep(gadget, "ep3-bulk");
> - if (ep && ep_matches(gadget, ep, desc))
> - return ep;
> - } else if (USB_ENDPOINT_XFER_BULK == type
> - && (USB_DIR_IN & desc->bEndpointAddress)) {
> - /* DMA may be available */
> - ep = find_ep(gadget, "ep2-bulk");
> - if (ep && ep_matches(gadget, ep, desc))
> - return ep;
> - }
> -
> - } else if (gadget_is_sh(gadget) && USB_ENDPOINT_XFER_INT == type) {
> - /* single buffering is enough; maybe 8 byte fifo is too */
> - ep = find_ep(gadget, "ep3in-bulk");
> - if (ep && ep_matches(gadget, ep, desc))
> - return ep;
> -
> - } else if (gadget_is_mq11xx(gadget) && USB_ENDPOINT_XFER_INT == type) {
> - ep = find_ep(gadget, "ep1-bulk");
> - if (ep && ep_matches(gadget, ep, desc))
> - return ep;
> -#ifndef CONFIG_SPL_BUILD
> - } else if (gadget_is_dwc3(gadget)) {
> + if (!IS_ENABLED(CONFIG_SPL_BUILD) &&
> + IS_ENABLED(CONFIG_USB_DWC3_GADGET) &&
> + !strcmp("dwc3-gadget", gadget->name)) {
>   const char *name = NULL;
>   /*
>* First try standard, common configuration: ep1in-bulk,
> @@ -278,7 +245,6 @@ struct usb_ep *usb_ep_autoconfig(
>   ep = find_ep(gadget, name);
>   if (ep && ep_matches(gadget, ep, desc))
>   return ep;
> -#endif
>   }
>  
>   if (gadget->ops->match_ep)
> diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
> index e76464e121b..b7b7bacb00d 100644
> --- a/drivers/usb/gadget/ether.c
> +++ b/drivers/usb/gadget/ether.c
> @@ -1989,13 +1989,11 @@ static int eth_bind(struct usb_gadget *gadget)
>* standard protocol is _strongly_ preferred for interop purposes.
>* (By everyone except Microsoft.)
>*/
> - if (gadget_is_musbhdrc(gadget)) {
> +
> + if (IS_ENABLED(CONFIG_USB_MUSB_GADGET) &&am

Re: [PATCH 3/6] usb: gadget: Drop usb_gadget_controller_number()

2024-06-11 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On dim., juin 09, 2024 at 23:32, Marek Vasut  
wrote:

> The bcdDevice field is defined as
> |Device release number in binary-coded decimal
> in the USB 2.0 specification. We use this field to distinguish the UDCs
> from each other. In theory this could be used on the host side to apply
> certain quirks if the "special" UDC in combination with this gadget is
> used. This hasn't been done as far as I am aware. In practice it would
> be better to fix the UDC driver before shipping since a later release
> might not need this quirk anymore.
>
> This patch removes the newly unused function. Linux stopped using this
> functionality in 2012, remove it from U-Boot as well.
>
> Matching Linux kernel commit:
> ed9cbda63d45 ("usb: gadget: remove usb_gadget_controller_number()")
>
> Signed-off-by: Marek Vasut 

Reviewed-by: Mattijs Korpershoek 
Tested-by: Mattijs Korpershoek  # on vim3

> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
> ---
>  drivers/usb/gadget/gadget_chips.h | 62 ---
>  1 file changed, 62 deletions(-)
>
> diff --git a/drivers/usb/gadget/gadget_chips.h 
> b/drivers/usb/gadget/gadget_chips.h
> index 98156c312d2..316051686c4 100644
> --- a/drivers/usb/gadget/gadget_chips.h
> +++ b/drivers/usb/gadget/gadget_chips.h
> @@ -146,65 +146,3 @@
>  #else
>  #define gadget_is_dwc2(g)0
>  #endif
> -
> -/**
> - * usb_gadget_controller_number - support bcdDevice id convention
> - * @gadget: the controller being driven
> - *
> - * Return a 2-digit BCD value associated with the peripheral controller,
> - * suitable for use as part of a bcdDevice value, or a negative error code.
> - *
> - * NOTE:  this convention is purely optional, and has no meaning in terms of
> - * any USB specification.  If you want to use a different convention in your
> - * gadget driver firmware -- maybe a more formal revision ID -- feel free.
> - *
> - * Hosts see these bcdDevice numbers, and are allowed (but not encouraged!)
> - * to change their behavior accordingly.  For example it might help avoiding
> - * some chip bug.
> - */
> -static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
> -{
> - if (gadget_is_net2280(gadget))
> - return 0x01;
> - else if (gadget_is_dummy(gadget))
> - return 0x02;
> - else if (gadget_is_sh(gadget))
> - return 0x04;
> - else if (gadget_is_goku(gadget))
> - return 0x06;
> - else if (gadget_is_mq11xx(gadget))
> - return 0x07;
> - else if (gadget_is_omap(gadget))
> - return 0x08;
> - else if (gadget_is_n9604(gadget))
> - return 0x09;
> - else if (gadget_is_at91(gadget))
> - return 0x12;
> - else if (gadget_is_imx(gadget))
> - return 0x13;
> - else if (gadget_is_musbhsfc(gadget))
> - return 0x14;
> - else if (gadget_is_musbhdrc(gadget))
> - return 0x15;
> - else if (gadget_is_atmel_usba(gadget))
> - return 0x17;
> - else if (gadget_is_fsl_usb2(gadget))
> - return 0x18;
> - else if (gadget_is_amd5536udc(gadget))
> - return 0x19;
> - else if (gadget_is_m66592(gadget))
> - return 0x20;
> - else if (gadget_is_ci(gadget))
> - return 0x21;
> - else if (gadget_is_dwc3(gadget))
> - return 0x23;
> - else if (gadget_is_cdns3(gadget))
> - return 0x24;
> - else if (gadget_is_max3420(gadget))
> - return 0x25;
> - else if (gadget_is_mtu3(gadget))
> - return 0x26;
> - else if (gadget_is_dwc2(gadget))
> - return 0x27;
> - return -ENOENT;
> -}
> -- 
> 2.43.0


Re: [PATCH 2/6] usb: gadget: ether: Drop usb_gadget_controller_number()

2024-06-11 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On dim., juin 09, 2024 at 23:32, Marek Vasut  
wrote:

> The bcdDevice field is defined as
> |Device release number in binary-coded decimal
> in the USB 2.0 specification. We use this field to distinguish the UDCs
> from each other. In theory this could be used on the host side to apply
> certain quirks if the "special" UDC in combination with this gadget is
> used. This hasn't been done as far as I am aware. In practice it would
> be better to fix the UDC driver before shipping since a later release
> might not need this quirk anymore.
>
> This patch converts this gadget to use the U-Boot version instead of a
> random 2 or 3 plus the UDC number. Linux stopped using this functionality
> in 2012, remove it from U-Boot as well.
>
> Matching Linux kernel commit:
> ed9cbda63d45 ("usb: gadget: remove usb_gadget_controller_number()")
>
> Signed-off-by: Marek Vasut 

Reviewed-by: Mattijs Korpershoek 
Tested-by: Mattijs Korpershoek  # on vim3

> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
> ---
>  drivers/usb/gadget/ether.c | 17 +++--
>  1 file changed, 3 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
> index b8b29d399b1..e76464e121b 100644
> --- a/drivers/usb/gadget/ether.c
> +++ b/drivers/usb/gadget/ether.c
> @@ -22,8 +22,8 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
> -#include "gadget_chips.h"
>  #include "rndis.h"
>  
>  #include 
> @@ -1998,19 +1998,8 @@ static int eth_bind(struct usb_gadget *gadget)
>   rndis = 0;
>   }
>  
> - gcnum = usb_gadget_controller_number(gadget);
> - if (gcnum >= 0)
> - device_desc.bcdDevice = cpu_to_le16(0x0300 + gcnum);
> - else {
> - /*
> -  * can't assume CDC works.  don't want to default to
> -  * anything less functional on CDC-capable hardware,
> -  * so we fail in this case.
> -  */
> - pr_err("controller '%s' not recognized",
> - gadget->name);
> - return -ENODEV;
> - }
> + gcnum = (U_BOOT_VERSION_NUM << 4) | U_BOOT_VERSION_NUM_PATCH;
> + device_desc.bcdDevice = cpu_to_le16(gcnum);
>  
>   /*
>* If there's an RNDIS configuration, that's what Windows wants to
> -- 
> 2.43.0


Re: [PATCH 1/6] usb: gadget: g_dnl: Drop usb_gadget_controller_number()

2024-06-11 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the patch.

On dim., juin 09, 2024 at 23:32, Marek Vasut  
wrote:

> The bcdDevice field is defined as
> |Device release number in binary-coded decimal
> in the USB 2.0 specification. We use this field to distinguish the UDCs
> from each other. In theory this could be used on the host side to apply
> certain quirks if the "special" UDC in combination with this gadget is
> used. This hasn't been done as far as I am aware. In practice it would
> be better to fix the UDC driver before shipping since a later release
> might not need this quirk anymore.
>
> This patch converts this gadget to use the U-Boot version instead of a
> random 2 or 3 plus the UDC number. Linux stopped using this functionality
> in 2012, remove it from U-Boot as well.
>
> Matching Linux kernel commit:
> ed9cbda63d45 ("usb: gadget: remove usb_gadget_controller_number()")
>
> Signed-off-by: Marek Vasut 

Compared with linux commit, and looks good to me.

Reviewed-by: Mattijs Korpershoek 

Tested that I could use fastboot, ums and scan for storage devices on
khadas vim3

Tested-by: Mattijs Korpershoek  # vim3

> ---
> Cc: Alexander Sverdlin 
> Cc: Felipe Balbi 
> Cc: Lukasz Majewski 
> Cc: Mattijs Korpershoek 
> Cc: Nishanth Menon 
> Cc: Simon Glass 
> Cc: Thinh Nguyen 
> Cc: Tom Rini 
> Cc: u-boot@lists.denx.de
> ---
>  drivers/usb/gadget/g_dnl.c | 17 +++--
>  1 file changed, 3 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c
> index b5b5f5d8c11..631969b3405 100644
> --- a/drivers/usb/gadget/g_dnl.c
> +++ b/drivers/usb/gadget/g_dnl.c
> @@ -17,10 +17,10 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #include 
>  
> -#include "gadget_chips.h"
>  #include "composite.c"
>  
>  /*
> @@ -199,18 +199,6 @@ void g_dnl_clear_detach(void)
>   g_dnl_detach_request = false;
>  }
>  
> -static int g_dnl_get_bcd_device_number(struct usb_composite_dev *cdev)
> -{
> - struct usb_gadget *gadget = cdev->gadget;
> - int gcnum;
> -
> - gcnum = usb_gadget_controller_number(gadget);
> - if (gcnum > 0)
> - gcnum += 0x200;
> -
> - return g_dnl_get_board_bcd_device_number(gcnum);
> -}
> -
>  /**
>   * Update internal serial number variable when the "serial#" env var changes.
>   *
> @@ -261,7 +249,8 @@ static int g_dnl_bind(struct usb_composite_dev *cdev)
>   if (ret)
>   goto error;
>  
> - gcnum = g_dnl_get_bcd_device_number(cdev);
> + gcnum = g_dnl_get_board_bcd_device_number((U_BOOT_VERSION_NUM << 4) |
> +   U_BOOT_VERSION_NUM_PATCH);
>   if (gcnum >= 0)
>   device_desc.bcdDevice = cpu_to_le16(gcnum);
>   else {
> -- 
> 2.43.0


Re: [PATCH 2/3] arm: dts: am625_sk: Switch to OF_UPSTREAM

2024-06-07 Thread Mattijs Korpershoek
Hi Nishanth,

Thank you for the patch.

On mer., juin 05, 2024 at 10:27, Nishanth Menon  wrote:

> Enable OF_UPSTREAM for am625-sk board. Remove DT files that
> are now available in dts/upstream. Update the appended files based on
> version of latest OF_UPSTREAM sync point (v6.10-rc1).
>
> Signed-off-by: Nishanth Menon 

Reviewed-by: Mattijs Korpershoek 

Boot tested to main U-Boot via DFU on AM62X SK EVM.

Tested-by: Mattijs Korpershoek 

> ---
>  arch/arm/dts/Makefile|3 +-
>  arch/arm/dts/k3-am62-main.dtsi   | 1058 --
>  arch/arm/dts/k3-am62-mcu.dtsi|  176 -
>  arch/arm/dts/k3-am62-thermal.dtsi|   36 -
>  arch/arm/dts/k3-am62-wakeup.dtsi |   96 ---
>  arch/arm/dts/k3-am62.dtsi|  122 ---
>  arch/arm/dts/k3-am625-sk-binman.dtsi |2 +-
>  arch/arm/dts/k3-am625-sk.dts |  299 
>  arch/arm/dts/k3-am625.dtsi   |  155 
>  arch/arm/dts/k3-am62x-sk-common.dtsi |  535 -
>  configs/am62x_evm_a53_defconfig  |3 +-
>  11 files changed, 4 insertions(+), 2481 deletions(-)
>  delete mode 100644 arch/arm/dts/k3-am62-main.dtsi
>  delete mode 100644 arch/arm/dts/k3-am62-mcu.dtsi
>  delete mode 100644 arch/arm/dts/k3-am62-thermal.dtsi
>  delete mode 100644 arch/arm/dts/k3-am62-wakeup.dtsi
>  delete mode 100644 arch/arm/dts/k3-am62.dtsi
>  delete mode 100644 arch/arm/dts/k3-am625-sk.dts
>  delete mode 100644 arch/arm/dts/k3-am625.dtsi
>  delete mode 100644 arch/arm/dts/k3-am62x-sk-common.dtsi
>
> diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> index 813426a3e519..5b0bcf336924 100644
> --- a/arch/arm/dts/Makefile
> +++ b/arch/arm/dts/Makefile
> @@ -1198,8 +1198,7 @@ dtb-$(CONFIG_SOC_K3_AM642) += k3-am642-r5-evm.dtb \
> k3-am642-r5-sk.dtb \
> k3-am642-r5-phycore-som-2gb.dtb
>  
> -dtb-$(CONFIG_SOC_K3_AM625) += k3-am625-sk.dtb \
> -   k3-am625-r5-sk.dtb \
> +dtb-$(CONFIG_SOC_K3_AM625) += k3-am625-r5-sk.dtb \
> k3-am625-r5-beagleplay.dtb \
> k3-am625-verdin-r5.dtb \
> k3-am625-r5-phycore-som-2gb.dtb
> diff --git a/arch/arm/dts/k3-am62-main.dtsi b/arch/arm/dts/k3-am62-main.dtsi
> deleted file mode 100644
> index e9cffca073ef..
> --- a/arch/arm/dts/k3-am62-main.dtsi
> +++ /dev/null
> @@ -1,1058 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0-only OR MIT
> -/*
> - * Device Tree Source for AM625 SoC Family Main Domain peripherals
> - *
> - * Copyright (C) 2020-2024 Texas Instruments Incorporated - 
> https://www.ti.com/
> - */
> -
> -_main {
> - oc_sram: sram@7000 {
> - compatible = "mmio-sram";
> - reg = <0x00 0x7000 0x00 0x1>;
> - #address-cells = <1>;
> - #size-cells = <1>;
> - ranges = <0x0 0x00 0x7000 0x1>;
> - };
> -
> - gic500: interrupt-controller@180 {
> - compatible = "arm,gic-v3";
> - #address-cells = <2>;
> - #size-cells = <2>;
> - ranges;
> - #interrupt-cells = <3>;
> - interrupt-controller;
> - reg = <0x00 0x0180 0x00 0x1>,   /* GICD */
> -   <0x00 0x0188 0x00 0xc>,   /* GICR */
> -   <0x00 0x0188 0x00 0xc>,   /* GICR */
> -   <0x01 0x 0x00 0x2000>,/* GICC */
> -   <0x01 0x0001 0x00 0x1000>,/* GICH */
> -   <0x01 0x0002 0x00 0x2000>;/* GICV */
> - /*
> -  * vcpumntirq:
> -  * virtual CPU interface maintenance interrupt
> -  */
> - interrupts = ;
> -
> - gic_its: msi-controller@182 {
> - compatible = "arm,gic-v3-its";
> - reg = <0x00 0x0182 0x00 0x1>;
> - socionext,synquacer-pre-its = <0x100 0x40>;
> - msi-controller;
> - #msi-cells = <1>;
> - };
> - };
> -
> - main_conf: bus@10 {
> - compatible = "simple-bus";
> - #address-cells = <1>;
> - #size-cells = <1>;
> - ranges = <0x0 0x00 0x0010 0x2>;
> -
> - phy_gmii_sel: phy@4044 {
> - compatible = "ti,am654-phy-gmii-sel";
> - reg = <0x4044 0x8>;
> - 

[PATCH 5/6] bootstd: Add a bootmeth for Android

2024-06-06 Thread Mattijs Korpershoek
Android boot flow is a bit different than a regular Linux distro.
Android relies on multiple partitions in order to boot.

A typical boot flow would be:
1. Parse the Bootloader Control Block (BCB, misc partition)
2. If BCB requested bootonce-bootloader, start fastboot and wait.
3. If BCB requested recovery or normal android, run the following:
3.a. Get slot (A/B) from BCB
3.b. Run AVB (Android Verified Boot) on boot partitions
3.c. Load boot and vendor_boot partitions
3.d. Load device-tree, ramdisk and boot

The AOSP documentation has more details at [1], [2], [3]

This has been implemented via complex boot scripts such as [4].
However, these boot script are neither very maintainable nor generic.
Moreover, DISTRO_DEFAULTS is being deprecated [5].

Add a generic Android bootflow implementation for bootstd.
For this initial version, only boot image v4 is supported.

[1] https://source.android.com/docs/core/architecture/bootloader
[2] https://source.android.com/docs/core/architecture/partitions
[3] https://source.android.com/docs/core/architecture/partitions/generic-boot
[4] 
https://source.denx.de/u-boot/u-boot/-/blob/master/include/configs/meson64_android.h
[5] https://lore.kernel.org/r/all/20230914165615.1058529-17-...@chromium.org/

Signed-off-by: Mattijs Korpershoek 
---
 MAINTAINERS |   7 +
 boot/Kconfig|  14 ++
 boot/Makefile   |   2 +
 boot/bootmeth_android.c | 522 
 boot/bootmeth_android.h |  27 +++
 doc/develop/bootstd.rst |   6 +
 6 files changed, 578 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 66783d636e3d..6d2b87720565 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -939,6 +939,13 @@ F: include/bootstd.h
 F: net/eth_bootdevice.c
 F: test/boot/
 
+BOOTMETH_ANDROID
+M: Mattijs Korpershoek 
+S: Maintained
+T: git https://source.denx.de/u-boot/custodians/u-boot-dfu.git
+F: boot/bootmeth_android.c
+F: boot/bootmeth_android.h
+
 BTRFS
 M: Marek Behún 
 R: Qu Wenruo 
diff --git a/boot/Kconfig b/boot/Kconfig
index 6f3096c15a6f..5fa6f3b8315d 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -494,6 +494,20 @@ config BOOTMETH_GLOBAL
  EFI bootmgr, since they take full control over which bootdevs are
  selected to boot.
 
+config BOOTMETH_ANDROID
+   bool "Bootdev support for Android"
+   depends on X86 || ARM || SANDBOX
+   select ANDROID_AB
+   select ANDROID_BOOT_IMAGE
+   select CMD_BCB
+   select PARTITION_TYPE_GUID
+   select PARTITION_UUIDS
+   help
+ Enables support for booting Android using bootdevs. Android requires
+ multiple partitions (misc, boot, vbmeta, ...) in storage for booting.
+
+ Note that only MMC bootdevs are supported at present.
+
 config BOOTMETH_CROS
bool "Bootdev support for Chromium OS"
depends on X86 || ARM || SANDBOX
diff --git a/boot/Makefile b/boot/Makefile
index 84ccfeaecec4..75d1cd46fabf 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -66,3 +66,5 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_REQUEST) += vbe_request.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE) += vbe_simple.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_FW) += vbe_simple_fw.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_OS) += vbe_simple_os.o
+
+obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_ANDROID) += bootmeth_android.o
diff --git a/boot/bootmeth_android.c b/boot/bootmeth_android.c
new file mode 100644
index ..26d548d2fd6e
--- /dev/null
+++ b/boot/bootmeth_android.c
@@ -0,0 +1,522 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Bootmethod for Android
+ *
+ * Copyright (C) 2024 BayLibre, SAS
+ * Written by Mattijs Korpershoek 
+ */
+#define LOG_CATEGORY UCLASS_BOOTSTD
+
+#include 
+#include 
+#if CONFIG_IS_ENABLED(AVB_VERIFY)
+#include 
+#endif
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "bootmeth_android.h"
+
+#define BCB_FIELD_COMMAND_SZ 32
+#define BCB_PART_NAME "misc"
+#define BOOT_PART_NAME "boot"
+#define VENDOR_BOOT_PART_NAME "vendor_boot"
+
+/**
+ * struct android_priv - Private data
+ *
+ * This is read from the disk and recorded for use when the full Android
+ * kernel must be loaded and booted
+ */
+struct android_priv {
+   int boot_mode;
+   char slot[2];
+   u32 header_version;
+};
+
+static int android_check(struct udevice *dev, struct bootflow_iter *iter)
+{
+   /* This only works on mmc devices */
+   if (bootflow_iter_check_mmc(iter))
+   return log_msg_ret("mmc", -ENOTSUPP);
+
+   /* This only works on whole devices, as multiple
+* partitions are needed to boot Android
+*/
+   if (iter->part != 0)
+   return log_msg_ret("mmc part", -ENOTSUPP);
+
+   return 0;
+}
+
+static int scan_boot_part(struct udevice *blk, struct android_priv *priv)
+{
+   

[PATCH 6/6] bootstd: Add test for bootmeth_android

2024-06-06 Thread Mattijs Korpershoek
Add a unit test for testing the Android bootmethod.

This requires another mmc image (mmc7) to contain the following partitions:
- misc: contains the Bootloader Control Block (BCB)
- boot_a: contains a fake generic kernel image
- vendor_boot_a: contains a fake vendor_boot image

Also add BOOTMETH_ANDROID as a dependency on sandbox so that we can test
this with:

$ ./test/py/test.py --bd sandbox --build -k test_ut # to build the mmc7.img
$ ./test/py/test.py --bd sandbox --build -k bootflow_android

Signed-off-by: Mattijs Korpershoek 
---
 arch/sandbox/dts/test.dts |  8 +
 configs/sandbox_defconfig |  2 +-
 test/boot/bootflow.c  | 65 ++--
 test/py/tests/test_ut.py  | 76 +++
 4 files changed, 147 insertions(+), 4 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index a012f5c4c9ba..5fb5eac862ec 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -43,6 +43,7 @@
mmc4 = "/mmc4";
mmc5 = "/mmc5";
mmc6 = "/mmc6";
+   mmc7 = "/mmc7";
pci0 = 
pci1 = 
pci2 = 
@@ -1129,6 +1130,13 @@
filename = "mmc6.img";
};
 
+   /* This is used for Android tests */
+   mmc7 {
+   status = "disabled";
+   compatible = "sandbox,mmc";
+   filename = "mmc7.img";
+   };
+
pch {
compatible = "sandbox,pch";
};
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 93b52f2de5cf..bc4398f101a7 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -15,6 +15,7 @@ CONFIG_FIT=y
 CONFIG_FIT_RSASSA_PSS=y
 CONFIG_FIT_CIPHER=y
 CONFIG_FIT_VERBOSE=y
+CONFIG_BOOTMETH_ANDROID=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_MEASURED_BOOT=y
 CONFIG_BOOTSTAGE=y
@@ -40,7 +41,6 @@ CONFIG_LOG_MAX_LEVEL=9
 CONFIG_LOG_DEFAULT_LEVEL=6
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_STACKPROTECTOR=y
-CONFIG_ANDROID_AB=y
 CONFIG_CMD_CPU=y
 CONFIG_CMD_LICENSE=y
 CONFIG_CMD_SMBIOS=y
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 4511cfa7f9bf..934c4dcbad2b 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -27,6 +27,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+extern U_BOOT_DRIVER(bootmeth_android);
 extern U_BOOT_DRIVER(bootmeth_cros);
 extern U_BOOT_DRIVER(bootmeth_2script);
 
@@ -518,12 +519,12 @@ BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | 
UT_TESTF_SCAN_FDT);
  * @uts: Unit test state
  * @mmc_dev: MMC device to use, e.g. "mmc4". Note that this must remain valid
  * in the caller until
- * @bind_cros: true to bind the ChromiumOS bootmeth
+ * @bind_cros: true to bind the ChromiumOS and Android bootmeths
  * @old_orderp: Returns the original bootdev order, which must be restored
  * Returns 0 on success, -ve on failure
  */
 static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
-   bool bind_cros, const char ***old_orderp)
+   bool bind_cros_android, const char ***old_orderp)
 {
static const char *order[] = {"mmc2", "mmc1", NULL, NULL};
struct udevice *dev, *bootstd;
@@ -545,12 +546,19 @@ static int prep_mmc_bootdev(struct unit_test_state *uts, 
const char *mmc_dev,
"bootmeth_script", 0, ofnode_null(), ));
 
/* Enable the cros bootmeth if needed */
-   if (IS_ENABLED(CONFIG_BOOTMETH_CROS) && bind_cros) {
+   if (IS_ENABLED(CONFIG_BOOTMETH_CROS) && bind_cros_android) {
ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, ));
ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_cros),
"cros", 0, ofnode_null(), ));
}
 
+   /* Enable the android bootmeths if needed */
+   if (IS_ENABLED(CONFIG_BOOTMETH_ANDROID) && bind_cros_android) {
+   ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, ));
+   ut_assertok(device_bind(bootstd, 
DM_DRIVER_REF(bootmeth_android),
+   "android", 0, ofnode_null(), ));
+   }
+
/* Change the order to include the device */
std = dev_get_priv(bootstd);
old_order = std->bootdev_order;
@@ -589,6 +597,37 @@ static int scan_mmc_bootdev(struct unit_test_state *uts, 
const char *mmc_dev,
return 0;
 }
 
+/**
+ * scan_mmc_android_bootdev() - Set up an mmc bootdev so we can access other
+ * distros. Android bootflow might print "ANDROID:*" while scanning
+ *
+ * @uts: Unit test state
+ * @mmc_dev: MMC device to use, e.g. "mmc4"
+ * Returns 0 on success, -ve on failure
+ */
+static int scan_mmc_android_bootdev(struct unit_test_stat

[PATCH 4/6] android: boot: Add set_abootimg_addr() and set_avendor_bootimg_addr()

2024-06-06 Thread Mattijs Korpershoek
The only way to configure the load addresses for both bootimg and
vendor_bootimg is by using the "abootimg" command.
If we want to use the C API, there is no equivalent.

Add set_abootimg_addr() and set_avendor_bootimg_addr() so that we can
specify the load address from C.

This can be useful for implementing an Android bootmethod.

Signed-off-by: Mattijs Korpershoek 
---
 cmd/abootimg.c  | 10 ++
 include/image.h | 14 ++
 2 files changed, 24 insertions(+)

diff --git a/cmd/abootimg.c b/cmd/abootimg.c
index 88c77d999290..33381e22dec2 100644
--- a/cmd/abootimg.c
+++ b/cmd/abootimg.c
@@ -21,11 +21,21 @@ ulong get_abootimg_addr(void)
return (_abootimg_addr == -1 ? image_load_addr : _abootimg_addr);
 }
 
+void set_abootimg_addr(ulong addr)
+{
+   _abootimg_addr = addr;
+}
+
 ulong get_avendor_bootimg_addr(void)
 {
return _avendor_bootimg_addr;
 }
 
+void set_avendor_bootimg_addr(ulong addr)
+{
+   _avendor_bootimg_addr = addr;
+}
+
 static int abootimg_get_ver(int argc, char *const argv[])
 {
const struct andr_boot_img_hdr_v0 *hdr;
diff --git a/include/image.h b/include/image.h
index 18e5ced5ab42..6deaf406605e 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1977,6 +1977,13 @@ u32 android_image_get_version(const void *hdr);
  */
 ulong get_abootimg_addr(void);
 
+/**
+ * set_abootimg_addr() - Set Android boot image address
+ *
+ * Return: no returned results
+ */
+void set_abootimg_addr(ulong addr);
+
 /**
  * get_avendor_bootimg_addr() - Get Android vendor boot image address
  *
@@ -1984,6 +1991,13 @@ ulong get_abootimg_addr(void);
  */
 ulong get_avendor_bootimg_addr(void);
 
+/**
+ * set_abootimg_addr() - Set Android vendor boot image address
+ *
+ * Return: no returned results
+ */
+void set_avendor_bootimg_addr(ulong addr);
+
 /**
  * board_fit_config_name_match() - Check for a matching board name
  *

-- 
2.45.0



[PATCH 3/6] bootstd: Add bootflow_iter_check_mmc() helper

2024-06-06 Thread Mattijs Korpershoek
Some bootflows might be able to only boot from MMC devices.

Add a helper function these bootflows can use.

Signed-off-by: Mattijs Korpershoek 
---
 boot/bootflow.c| 12 
 include/bootflow.h |  9 +
 2 files changed, 21 insertions(+)

diff --git a/boot/bootflow.c b/boot/bootflow.c
index 9aa3179c3881..59d77d2385f4 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -575,6 +575,18 @@ int bootflow_iter_check_blk(const struct bootflow_iter 
*iter)
return -ENOTSUPP;
 }
 
+int bootflow_iter_check_mmc(const struct bootflow_iter *iter)
+{
+   const struct udevice *media = dev_get_parent(iter->dev);
+   enum uclass_id id = device_get_uclass_id(media);
+
+   log_debug("uclass %d: %s\n", id, uclass_get_name(id));
+   if (id == UCLASS_MMC)
+   return 0;
+
+   return -ENOTSUPP;
+}
+
 int bootflow_iter_check_sf(const struct bootflow_iter *iter)
 {
const struct udevice *media = dev_get_parent(iter->dev);
diff --git a/include/bootflow.h b/include/bootflow.h
index 080ee8501225..6058ddd89b16 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -407,6 +407,15 @@ void bootflow_remove(struct bootflow *bflow);
  */
 int bootflow_iter_check_blk(const struct bootflow_iter *iter);
 
+/**
+ * bootflow_iter_check_mmc() - Check that a bootflow uses a MMC device
+ *
+ * This checks the bootdev in the bootflow to make sure it uses a mmc device
+ *
+ * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. ethernet)
+ */
+int bootflow_iter_check_mmc(const struct bootflow_iter *iter);
+
 /**
  * bootflow_iter_check_sf() - Check that a bootflow uses SPI FLASH
  *

-- 
2.45.0



[PATCH 2/6] boot: android: Add image_android_get_version()

2024-06-06 Thread Mattijs Korpershoek
When reading a boot image header, we may need to retrieve the header
version.

Add a helper function for it.

Signed-off-by: Mattijs Korpershoek 
---
 boot/image-android.c | 7 ++-
 include/image.h  | 7 +++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/boot/image-android.c b/boot/image-android.c
index ddd8ffd5e540..4f8fb51585eb 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -185,7 +185,7 @@ bool android_image_get_data(const void *boot_hdr, const 
void *vendor_boot_hdr,
return false;
}
 
-   if (((struct andr_boot_img_hdr_v0 *)boot_hdr)->header_version > 2) {
+   if (android_image_get_version(boot_hdr) > 2) {
if (!vendor_boot_hdr) {
printf("For boot header v3+ vendor boot image has to be 
provided\n");
return false;
@@ -203,6 +203,11 @@ bool android_image_get_data(const void *boot_hdr, const 
void *vendor_boot_hdr,
return true;
 }
 
+u32 android_image_get_version(const void *hdr)
+{
+   return ((struct andr_boot_img_hdr_v0 *)hdr)->header_version;
+}
+
 static ulong android_image_get_kernel_addr(struct andr_image_data *img_data)
 {
/*
diff --git a/include/image.h b/include/image.h
index acffd17e0dfd..18e5ced5ab42 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1963,6 +1963,13 @@ bool is_android_boot_image_header(const void *hdr);
  */
 bool is_android_vendor_boot_image_header(const void *vendor_boot_img);
 
+/**
+ * android_image_get_version() - Retrieve the boot.img version
+ *
+ * Return: Android boot image header version.
+ */
+u32 android_image_get_version(const void *hdr);
+
 /**
  * get_abootimg_addr() - Get Android boot image address
  *

-- 
2.45.0



[PATCH 1/6] boot: android: Provide vendor_bootimg_addr in boot_get_fdt()

2024-06-06 Thread Mattijs Korpershoek
When calling android_image_get_dtb_by_index() using boot image v3+,
we should also pass the vendor_boot ramdisk address.

Use get_avendor_bootimg_addr() to do so.

Note: on boot image v2, this is harmless since get_avendor_bootimg_addr()
returns -1.

Signed-off-by: Mattijs Korpershoek 
---
 boot/image-fdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/boot/image-fdt.c b/boot/image-fdt.c
index 56dd7687f51c..8332792b8e80 100644
--- a/boot/image-fdt.c
+++ b/boot/image-fdt.c
@@ -502,7 +502,7 @@ int boot_get_fdt(void *buf, const char *select, uint arch,
 * Firstly check if this android boot image has dtb field.
 */
dtb_idx = (u32)env_get_ulong("adtb_idx", 10, 0);
-   if (android_image_get_dtb_by_index((ulong)hdr, 0,
+   if (android_image_get_dtb_by_index((ulong)hdr, 
get_avendor_bootimg_addr(),
   dtb_idx, _addr, 
_size)) {
fdt_blob = (char *)map_sysmem(fdt_addr, 0);
if (fdt_check_header(fdt_blob))

-- 
2.45.0



[PATCH 0/6] bootstd: Add Android support

2024-06-06 Thread Mattijs Korpershoek
Android boot flow is a bit different than a regular Linux distro.
Android relies on multiple partitions in order to boot.

A typical boot flow would be:
1. Parse the Bootloader Control Block (BCB, misc partition)
2. If BCB requested bootonce-bootloader, start fastboot and wait.
3. If BCB requested recovery or normal android, run the following:
   a. Get slot (A/B) from BCB
   b. Run AVB (Android Verified Boot) on boot partitions
   c. Load boot and vendor_boot partitions
   d. Load device-tree, ramdisk and boot

The AOSP documentation has more details at [1], [2], [3]

This has been implemented via complex boot scripts such as [4].
However, these boot script are neither very maintainable nor generic.
Moreover, DISTRO_DEFAULTS is being deprecated [5].

Add a generic Android bootflow implementation for bootstd.

For this initial version, only boot image v4 is supported.

This has been tested on sandbox using:
$ ./test/py/test.py --bd sandbox --build -k test_ut

This has also been tested on the AM62X SK EVM using TI's Android SDK[6]
To test on TI board, the following (WIP) patch is needed as well:
https://gitlab.baylibre.com/baylibre/ti/ti-u-boot/-/commit/84cceb912bccd7cdd7f9dd69bca0e5d987a1fd04

[1] https://source.android.com/docs/core/architecture/bootloader
[2] https://source.android.com/docs/core/architecture/partitions
[3] https://source.android.com/docs/core/architecture/partitions/generic-boot
[4] 
https://source.denx.de/u-boot/u-boot/-/blob/master/include/configs/meson64_android.h
[5] https://lore.kernel.org/r/all/20230914165615.1058529-17-...@chromium.org/
[6] 
https://software-dl.ti.com/processor-sdk-android/esd/AM62X/09_02_00/docs/android/Overview.html

Signed-off-by: Mattijs Korpershoek 
---
Mattijs Korpershoek (6):
  boot: android: Provide vendor_bootimg_addr in boot_get_fdt()
  boot: android: Add image_android_get_version()
  bootstd: Add bootflow_iter_check_mmc() helper
  android: boot: Add set_abootimg_addr() and set_avendor_bootimg_addr()
  bootstd: Add a bootmeth for Android
  bootstd: Add test for bootmeth_android

 MAINTAINERS   |   7 +
 arch/sandbox/dts/test.dts |   8 +
 boot/Kconfig  |  14 ++
 boot/Makefile |   2 +
 boot/bootflow.c   |  12 ++
 boot/bootmeth_android.c   | 522 ++
 boot/bootmeth_android.h   |  27 +++
 boot/image-android.c  |   7 +-
 boot/image-fdt.c  |   2 +-
 cmd/abootimg.c|  10 +
 configs/sandbox_defconfig |   2 +-
 doc/develop/bootstd.rst   |   6 +
 include/bootflow.h|   9 +
 include/image.h   |  21 ++
 test/boot/bootflow.c  |  65 +-
 test/py/tests/test_ut.py  |  76 +++
 16 files changed, 784 insertions(+), 6 deletions(-)
---
base-commit: 227be29df37545f74243a98c12a4a33c4160e3cd
change-id: 20240605-bootmeth-android-bfc8596e9367

Best regards,
-- 
Mattijs Korpershoek 



Re: [GIT PULL] Please pull u-boot-dfu-20240606

2024-06-06 Thread Mattijs Korpershoek
Hi everyone,

On jeu., mai 16, 2024 at 17:12, Mattijs Korpershoek  
wrote:

> Hi Tom,
>
> Please find some fixes for master:
>
> - dwc3 fix crash when ep0 stalls or gadget is stopped
> - Kconfig build fix for DFU_SF (SPI flash DFU driver)
>
> The CI job is at 
> https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/20990

Please ignore this one, my mail client screwed up the send date.

Sorry about that :(

Mattijs

>
> Thanks,
> Mattijs
>
> The following changes since commit c0ea27bccfb7d2d37fd36806ac2a2f7389099420:
>
>   Prepare v2024.07-rc4 (2024-06-03 18:34:59 -0600)
>
> are available in the Git repository at:
>
>   https://source.denx.de/u-boot/custodians/u-boot-dfu.git 
> tags/u-boot-dfu-20240606
>
> for you to fetch changes up to 4339138a2086f8449b9356130cb6e97a81aa8679:
>
>   dfu: add missing dependency for SPI flash DFU driver (2024-06-06 09:11:21 
> +0200)
>
> 
> u-boot-dfu-20240606
>
> - dwc3 fix crash when ep0 stalls or gadget is stopped
> - Kconfig build fix for DFU_SF (SPI flash DFU driver)
>
> 
> Heinrich Schuchardt (1):
>   dfu: add missing dependency for SPI flash DFU driver
>
> Neil Armstrong (1):
>   usb: dwc3: gadget: fix crash in dwc3_gadget_giveback()
>
>  drivers/dfu/Kconfig   | 1 +
>  drivers/usb/dwc3/gadget.c | 4 ++--
>  2 files changed, 3 insertions(+), 2 deletions(-)


[GIT PULL] Please pull u-boot-dfu-20240606

2024-06-06 Thread Mattijs Korpershoek
Hi Tom,

Please find some fixes for master:

- dwc3 fix crash when ep0 stalls or gadget is stopped
- Kconfig build fix for DFU_SF (SPI flash DFU driver)

The CI job is at 
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/20990

Thanks,
Mattijs

The following changes since commit c0ea27bccfb7d2d37fd36806ac2a2f7389099420:

  Prepare v2024.07-rc4 (2024-06-03 18:34:59 -0600)

are available in the Git repository at:

  https://source.denx.de/u-boot/custodians/u-boot-dfu.git 
tags/u-boot-dfu-20240606

for you to fetch changes up to 4339138a2086f8449b9356130cb6e97a81aa8679:

  dfu: add missing dependency for SPI flash DFU driver (2024-06-06 09:11:21 
+0200)


u-boot-dfu-20240606

- dwc3 fix crash when ep0 stalls or gadget is stopped
- Kconfig build fix for DFU_SF (SPI flash DFU driver)


Heinrich Schuchardt (1):
  dfu: add missing dependency for SPI flash DFU driver

Neil Armstrong (1):
  usb: dwc3: gadget: fix crash in dwc3_gadget_giveback()

 drivers/dfu/Kconfig   | 1 +
 drivers/usb/dwc3/gadget.c | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)


[GIT PULL] Please pull u-boot-dfu-20240606

2024-06-06 Thread Mattijs Korpershoek
Hi Tom,

Please find some fixes for master:

- dwc3 fix crash when ep0 stalls or gadget is stopped
- Kconfig build fix for DFU_SF (SPI flash DFU driver)

The CI job is at 
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/20990

Thanks,
Mattijs

The following changes since commit c0ea27bccfb7d2d37fd36806ac2a2f7389099420:

  Prepare v2024.07-rc4 (2024-06-03 18:34:59 -0600)

are available in the Git repository at:

  https://source.denx.de/u-boot/custodians/u-boot-dfu.git 
tags/u-boot-dfu-20240606

for you to fetch changes up to 4339138a2086f8449b9356130cb6e97a81aa8679:

  dfu: add missing dependency for SPI flash DFU driver (2024-06-06 09:11:21 
+0200)


u-boot-dfu-20240606

- dwc3 fix crash when ep0 stalls or gadget is stopped
- Kconfig build fix for DFU_SF (SPI flash DFU driver)


Heinrich Schuchardt (1):
  dfu: add missing dependency for SPI flash DFU driver

Neil Armstrong (1):
  usb: dwc3: gadget: fix crash in dwc3_gadget_giveback()

 drivers/dfu/Kconfig   | 1 +
 drivers/usb/dwc3/gadget.c | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)



Re: [PATCH 1/3] arm: dts: am625_beagleplay: Switch to OF_UPSTREAM

2024-06-06 Thread Mattijs Korpershoek
Hi Nishanth,

Thank you for the patch.

On mer., juin 05, 2024 at 10:27, Nishanth Menon  wrote:

> Enable OF_UPSTREAM for AM625-beagleplay board. Remove DT files that
> are now available in dts/upstream. Update the appended files based on
> version of latest OF_UPSTREAM sync point (v6.10-rc1).
>
> Signed-off-by: Nishanth Menon 

Reviewed-by: Mattijs Korpershoek 

> ---
>  arch/arm/dts/Makefile|   1 -
>  arch/arm/dts/k3-am625-beagleplay-u-boot.dtsi |   4 +-
>  arch/arm/dts/k3-am625-beagleplay.dts | 932 ---
>  configs/am62x_beagleplay_a53_defconfig   |   3 +-
>  4 files changed, 4 insertions(+), 936 deletions(-)
>  delete mode 100644 arch/arm/dts/k3-am625-beagleplay.dts
>
> diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> index 624dadf8ece2..813426a3e519 100644
> --- a/arch/arm/dts/Makefile
> +++ b/arch/arm/dts/Makefile
> @@ -1200,7 +1200,6 @@ dtb-$(CONFIG_SOC_K3_AM642) += k3-am642-r5-evm.dtb \
>  
>  dtb-$(CONFIG_SOC_K3_AM625) += k3-am625-sk.dtb \
> k3-am625-r5-sk.dtb \
> -   k3-am625-beagleplay.dtb \
> k3-am625-r5-beagleplay.dtb \
> k3-am625-verdin-r5.dtb \
> k3-am625-r5-phycore-som-2gb.dtb
> diff --git a/arch/arm/dts/k3-am625-beagleplay-u-boot.dtsi 
> b/arch/arm/dts/k3-am625-beagleplay-u-boot.dtsi
> index 9ac4a825f841..dd5b335ed2ee 100644
> --- a/arch/arm/dts/k3-am625-beagleplay-u-boot.dtsi
> +++ b/arch/arm/dts/k3-am625-beagleplay-u-boot.dtsi
> @@ -66,9 +66,9 @@
>  #ifdef CONFIG_TARGET_AM625_A53_BEAGLEPLAY
>  
>  #define SPL_NODTB "spl/u-boot-spl-nodtb.bin"
> -#define SPL_AM625_BEAGLEPLAY_DTB "spl/dts/k3-am625-beagleplay.dtb"
> +#define SPL_AM625_BEAGLEPLAY_DTB "spl/dts/ti/k3-am625-beagleplay.dtb"
>  #define UBOOT_NODTB "u-boot-nodtb.bin"
> -#define AM625_BEAGLEPLAY_DTB "arch/arm/dts/k3-am625-beagleplay.dtb"
> +#define AM625_BEAGLEPLAY_DTB 
> "dts/upstream/src/arm64/ti/k3-am625-beagleplay.dtb"
>  
>   {
>   ti-dm {
> diff --git a/arch/arm/dts/k3-am625-beagleplay.dts 
> b/arch/arm/dts/k3-am625-beagleplay.dts
> deleted file mode 100644
> index 8ab838f1697c..
> --- a/arch/arm/dts/k3-am625-beagleplay.dts
> +++ /dev/null
> @@ -1,932 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0-only OR MIT
> -/*
> - * https://beagleplay.org/
> - *
> - * Copyright (C) 2022-2024 Texas Instruments Incorporated - 
> https://www.ti.com/
> - * Copyright (C) 2022-2024 Robert Nelson, BeagleBoard.org Foundation
> - */
> -
> -/dts-v1/;
> -
> -#include 
> -#include 
> -#include 
> -#include "k3-am625.dtsi"
> -
> -/ {
> - compatible = "beagle,am625-beagleplay", "ti,am625";
> - model = "BeagleBoard.org BeaglePlay";
> -
> - aliases {
> - ethernet0 = _port1;
> - ethernet1 = _port2;
> - gpio0 = _gpio0;
> - gpio1 = _gpio1;
> - gpio2 = _gpio0;
> - i2c0 = _i2c0;
> - i2c1 = _i2c1;
> - i2c2 = _i2c2;
> - i2c3 = _i2c3;
> - i2c4 = _i2c0;
> - i2c5 = _i2c0;
> - mmc0 = 
> - mmc1 = 
> - mmc2 = 
> - rtc0 = 
> - serial0 = _uart5;
> - serial1 = _uart6;
> - serial2 = _uart0;
> - usb0 = 
> - usb1 = 
> - };
> -
> - chosen {
> - stdout-path = "serial2:115200n8";
> - };
> -
> - memory@8000 {
> - bootph-pre-ram;
> - device_type = "memory";
> - /* 2G RAM */
> - reg = <0x 0x8000 0x 0x8000>;
> - };
> -
> - reserved-memory {
> - #address-cells = <2>;
> - #size-cells = <2>;
> - ranges;
> -
> - ramoops: ramoops@9ca0 {
> - compatible = "ramoops";
> - reg = <0x00 0x9ca0 0x00 0x0010>;
> - record-size = <0x8000>;
> - console-size = <0x8000>;
> - ftrace-size = <0x00>;
> - pmsg-size = <0x8000>;
> - };
> -
> - secure_tfa_ddr: tfa@9e78 {
> - reg = <0x00 0x9e78 0x00 0x8>;
> - no-map;
> - };
> -
> - secure_ddr: optee@9e80 {
> - reg = <0x00 0x9e80 0x00 0

Re: [PATCH 1/1] dfu: add missing dependency for SPI flash DFU driver

2024-06-06 Thread Mattijs Korpershoek
Hi,

On Tue, 04 Jun 2024 07:44:25 +0200, Heinrich Schuchardt wrote:
> Building the SPI flash DFU driver fails if SPI flash support is missing.
> 
> drivers/dfu/dfu_sf.c:123:29: error:
> ‘CONFIG_SF_DEFAULT_MODE’ undeclared (first use in this function);
> 
> Add the missing dependency.
> 
> [...]

Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu 
(u-boot-dfu)

[1/1] dfu: add missing dependency for SPI flash DFU driver
  
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/4339138a2086f8449b9356130cb6e97a81aa8679

--
Mattijs


Re: [PATCH 3/3] regulator: rk8xx: clarify operator precedence

2024-06-05 Thread Mattijs Korpershoek
Hi Quentin,

Thank you for the patch.

On mer., juin 05, 2024 at 11:33, Quentin Schulz  wrote:

> From: Quentin Schulz 
>
> My linter complains that the order isn't clear enough so let's put
> parentheses around the ternary condition to make it happy.
>
> Signed-off-by: Quentin Schulz 

Reviewed-by: Mattijs Korpershoek 

> ---
>  drivers/power/regulator/rk8xx.c | 26 +-
>  1 file changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/power/regulator/rk8xx.c b/drivers/power/regulator/rk8xx.c
> index bd5a37e718f..3125835bc07 100644
> --- a/drivers/power/regulator/rk8xx.c
> +++ b/drivers/power/regulator/rk8xx.c
> @@ -520,7 +520,7 @@ static int _buck_get_enable(struct udevice *pmic, int 
> buck)
>   if (ret < 0)
>   return ret;
>  
> - return ret & mask ? true : false;
> + return (ret & mask) ? true : false;
>  }
>  
>  static int _buck_set_suspend_enable(struct udevice *pmic, int buck, bool 
> enable)
> @@ -585,7 +585,7 @@ static int _buck_get_suspend_enable(struct udevice *pmic, 
> int buck)
>   val = pmic_reg_read(pmic, RK816_REG_DCDC_SLP_EN);
>   if (val < 0)
>   return val;
> - ret = val & mask ? 1 : 0;
> + ret = (val & mask) ? 1 : 0;
>   break;
>   case RK806_ID:
>   {
> @@ -608,7 +608,7 @@ static int _buck_get_suspend_enable(struct udevice *pmic, 
> int buck)
>   val = pmic_reg_read(pmic, REG_SLEEP_SET_OFF1);
>   if (val < 0)
>   return val;
> - ret = val & mask ? 0 : 1;
> + ret = (val & mask) ? 0 : 1;
>   break;
>   case RK809_ID:
>   case RK817_ID:
> @@ -620,7 +620,7 @@ static int _buck_get_suspend_enable(struct udevice *pmic, 
> int buck)
>   val = pmic_reg_read(pmic, RK817_POWER_SLP_EN(0));
>   if (val < 0)
>   return val;
> - ret = val & mask ? 1 : 0;
> + ret = (val & mask) ? 1 : 0;
>   break;
>   default:
>   ret = -EINVAL;
> @@ -723,7 +723,7 @@ static int _ldo_get_enable(struct udevice *pmic, int ldo)
>   if (ret < 0)
>   return ret;
>  
> - return ret & mask ? true : false;
> + return (ret & mask) ? true : false;
>  }
>  
>  static int _nldo_get_enable(struct udevice *pmic, int nldo)
> @@ -980,7 +980,7 @@ static int _ldo_get_suspend_enable(struct udevice *pmic, 
> int ldo)
>   val = pmic_reg_read(pmic, RK816_REG_LDO_SLP_EN);
>   if (val < 0)
>   return val;
> - ret = val & mask ? 1 : 0;
> + ret = (val & mask) ? 1 : 0;
>   break;
>   case RK808_ID:
>   case RK818_ID:
> @@ -988,7 +988,7 @@ static int _ldo_get_suspend_enable(struct udevice *pmic, 
> int ldo)
>   val = pmic_reg_read(pmic, REG_SLEEP_SET_OFF2);
>   if (val < 0)
>   return val;
> - ret = val & mask ? 0 : 1;
> + ret = (val & mask) ? 0 : 1;
>   break;
>   case RK809_ID:
>   case RK817_ID:
> @@ -997,13 +997,13 @@ static int _ldo_get_suspend_enable(struct udevice 
> *pmic, int ldo)
>   val = pmic_reg_read(pmic, RK817_POWER_SLP_EN(0));
>   if (val < 0)
>   return val;
> - ret = val & mask ? 1 : 0;
> + ret = (val & mask) ? 1 : 0;
>   } else {
>   mask = 1 << ldo;
>   val = pmic_reg_read(pmic, RK817_POWER_SLP_EN(1));
>   if (val < 0)
>   return val;
> - ret = val & mask ? 1 : 0;
> + ret = (val & mask) ? 1 : 0;
>   }
>   break;
>   }
> @@ -1438,7 +1438,7 @@ static int switch_get_enable(struct udevice *dev)
>   if (ret < 0)
>   return ret;
>  
> - return ret & mask ? true : false;
> + return (ret & mask) ? true : false;
>  }
>  
>  static int switch_set_suspend_value(struct udevice *dev, int uvolt)
> @@ -1493,21 +1493,21 @@ static int switch_get_suspend_enable(struct udevice 
> *dev)
>   val = pmic_reg_read(dev->parent, REG_SLEEP_SET_OFF1);
>   if (val < 0)
>   return val;
> - ret = val & mask ? 0 : 1;
> + ret = (val & mask) ? 0 : 1;
>   break;
>   

Re: [PATCH v2 2/2] bootstd: Replace bootmethod(s) -> bootmeth(s)

2024-06-05 Thread Mattijs Korpershoek
Hi Quentin,

Thank you for the review.

On mar., juin 04, 2024 at 17:25, Quentin Schulz  
wrote:

> Hi Mattijs,
>
> On 6/4/24 5:15 PM, Mattijs Korpershoek wrote:
>> According to [1], we should use bootmeth when describing the
>> struct bootmeth:
>> 
>> """
>> For version 2, a new naming scheme is used as above:
>> 
>>  - bootdev is used instead of bootdevice, because 'device' is overused,
>>  is everywhere in U-Boot, can be confused with udevice
>>  - bootmeth - because 'method' is too vanilla, appears 1300 times in
>>  U-Boot
>> """
>> 
>> Replace all occurences in various comments for consistency.
>> 
>
> s/occurences/occurrences/

Urgh, I guess I spot typos from others but not my own ones :/

>
> Sorry, was too tempting to highlight a typo in a commit that fixes typos :)
>
> (Don't send a v3 for this please :) )

I won't. I hope the person applying this patch can do a fixup.

>
>> [1] https://lore.kernel.org/u-boot/20211023232635.9195-1-...@chromium.org/
>
> Reviewed-by: Quentin Schulz 
>
> Thanks!
> Quentin


Re: [PATCH] bootstd: Fix a handful of doc typos in bootmeth

2024-06-04 Thread Mattijs Korpershoek
Hi Quentin,

Thanks for the review!

On mar., juin 04, 2024 at 14:22, Quentin Schulz  
wrote:

> Hi Mattijs,
>
> On 6/4/24 2:04 PM, Mattijs Korpershoek wrote:

[...]

>> 
>> There seems indeed to be some inconsistencies around bootmeths versus
>> bootmethods.
>> 
>> To me, we should use 'bootmeth' everywhere.
>> 
>> Simon, as the maintainer of bootflow, do you agree ?
>> 
>> I can spin up another patch to fix this.
>> 
>
> c.f. https://lore.kernel.org/u-boot/20211023232635.9195-1-...@chromium.org/
>
> """
> For version 2, a new naming scheme is used as above:
>
> - bootdev is used instead of bootdevice, because 'device' is overused,
> is everywhere in U-Boot, can be confused with udevice
> - bootmeth - because 'method' is too vanilla, appears 1300 times in
> U-Boot
> """
>
> SO I think we should change it to bootmeth(s) indeed.

Ah, thank you for the link, that is helpful.

I've done the global rename, made this into a series here:

https://lore.kernel.org/all/20240604-bootmeth-typos-v2-0-821683a95...@baylibre.com

>
> Reviewed-by: Quentin Schulz 
>
> Thanks,
> Quentin


[PATCH v2 2/2] bootstd: Replace bootmethod(s) -> bootmeth(s)

2024-06-04 Thread Mattijs Korpershoek
According to [1], we should use bootmeth when describing the
struct bootmeth:

"""
For version 2, a new naming scheme is used as above:

- bootdev is used instead of bootdevice, because 'device' is overused,
is everywhere in U-Boot, can be confused with udevice
- bootmeth - because 'method' is too vanilla, appears 1300 times in
U-Boot
"""

Replace all occurences in various comments for consistency.

[1] https://lore.kernel.org/u-boot/20211023232635.9195-1-...@chromium.org/
Signed-off-by: Mattijs Korpershoek 
---
 board/sandbox/sandbox.env |  2 +-
 boot/bootmeth-uclass.c|  2 +-
 include/bootmeth.h| 30 +++---
 include/extlinux.h|  2 +-
 test/boot/bootflow.c  |  2 +-
 test/boot/bootmeth.c  |  6 +++---
 6 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/board/sandbox/sandbox.env b/board/sandbox/sandbox.env
index a2c19702d64d..564dce78a898 100644
--- a/board/sandbox/sandbox.env
+++ b/board/sandbox/sandbox.env
@@ -10,7 +10,7 @@ eth6addr=02:00:11:22:33:47
 ipaddr=192.0.2.1
 
 /*
- * These are used for distro boot which is not supported. But once bootmethod
+ * These are used for distro boot which is not supported. But once bootmeth
  * is provided these will be used again.
  */
 bootm_size=0x1000
diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c
index 1d157d54dbdd..e3475f46b34c 100644
--- a/boot/bootmeth-uclass.c
+++ b/boot/bootmeth-uclass.c
@@ -167,7 +167,7 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, 
bool include_global)
if (pass)
iter->first_glob_method = upto;
/*
-* Get a list of bootmethods, in seq order (i.e. using
+* Get a list of bootmeths, in seq order (i.e. using
 * aliases). There may be gaps so try to count up high
 * enough to find them all.
 */
diff --git a/include/bootmeth.h b/include/bootmeth.h
index 529c4d813d82..2570d9593d49 100644
--- a/include/bootmeth.h
+++ b/include/bootmeth.h
@@ -47,7 +47,7 @@ struct bootmeth_ops {
 * This may involve reading state from the system, e.g. some data in
 * the firmware area.
 *
-* @dev:Bootmethod device to check
+* @dev:Bootmeth device to check
 * @buf:Buffer to place the info in (terminator must fit)
 * @maxsize:Size of buffer
 * Returns: 0 if OK, -ENOSPC is buffer is too small, other -ve error if
@@ -74,7 +74,7 @@ struct bootmeth_ops {
 *
 * It may update only the flags in @iter
 *
-* @dev:Bootmethod device to check against
+* @dev:Bootmeth device to check against
 * @iter:   On entry, provides bootdev, hwpart, part
 * Return: 0 if OK, -ENOTSUPP if this bootdev is not supported
 */
@@ -83,7 +83,7 @@ struct bootmeth_ops {
/**
 * read_bootflow() - read a bootflow for a device
 *
-* @dev:Bootmethod device to use
+* @dev:Bootmeth device to use
 * @bflow:  On entry, provides dev, hwpart, part and method.
 *  Returns updated bootflow if found
 * Return: 0 if OK, -ve on error
@@ -96,7 +96,7 @@ struct bootmeth_ops {
 * This provides a bootflow file to the bootmeth, to see if it is valid.
 * If it is, the bootflow is set up accordingly.
 *
-* @dev:Bootmethod device to use
+* @dev:Bootmeth device to use
 * @bflow:  On entry, provides bootdev.
 *  Returns updated bootflow if found
 * @buf:Buffer containing the possible bootflow file
@@ -111,7 +111,7 @@ struct bootmeth_ops {
 *
 * Read a file from the same place as the bootflow came from
 *
-* @dev:Bootmethod device to use
+* @dev:Bootmeth device to use
 * @bflow:  Bootflow providing info on where to read from
 * @file_path:  Path to file (may be absolute or relative)
 * @addr:   Address to load file
@@ -126,7 +126,7 @@ struct bootmeth_ops {
/**
 * readall() - read all files for a bootflow
 *
-* @dev:Bootmethod device to boot
+* @dev:Bootmeth device to boot
 * @bflow:  Bootflow to read
 * Return: 0 if OK, -EIO on I/O error, other -ve on other error
 */
@@ -135,7 +135,7 @@ struct bootmeth_ops {
/**
 * boot() - boot a bootflow
 *
-* @dev:Bootmethod device to boot
+* @dev:Bootmeth device to boot
 * @bflow:  Bootflow to boot
 * Return: does not return on success, since it should boot the
 *  Operating System. Returns -EFAULT if that fails, -ENOTSUPP if
@@ -15

[PATCH v2 1/2] bootstd: Fix a handful of doc typos in bootmeth

2024-06-04 Thread Mattijs Korpershoek
Fix some trivial typos found by browsing the code.
Done with flyspell.

Reviewed-by: Quentin Schulz 
Signed-off-by: Mattijs Korpershoek 
---
 include/bootmeth.h | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/bootmeth.h b/include/bootmeth.h
index 0fc36104ece0..529c4d813d82 100644
--- a/include/bootmeth.h
+++ b/include/bootmeth.h
@@ -40,7 +40,7 @@ struct bootmeth_ops {
/**
 * get_state_desc() - get detailed state information
 *
-* Prodecues a textual description of the state of the bootmeth. This
+* Produces a textual description of the state of the bootmeth. This
 * can include newline characters if it extends to multiple lines. It
 * must be a nul-terminated string.
 *
@@ -138,7 +138,7 @@ struct bootmeth_ops {
 * @dev:Bootmethod device to boot
 * @bflow:  Bootflow to boot
 * Return: does not return on success, since it should boot the
-*  Operating Systemn. Returns -EFAULT if that fails, -ENOTSUPP if
+*  Operating System. Returns -EFAULT if that fails, -ENOTSUPP if
 *  trying method resulted in finding out that is not actually
 *  supported for this boot and should not be tried again unless
 *  something changes, other -ve on other error
@@ -151,7 +151,7 @@ struct bootmeth_ops {
 /**
  * bootmeth_get_state_desc() - get detailed state information
  *
- * Prodecues a textual description of the state of the bootmeth. This
+ * Produces a textual description of the state of the bootmeth. This
  * can include newline characters if it extends to multiple lines. It
  * must be a nul-terminated string.
  *
@@ -244,7 +244,7 @@ int bootmeth_read_file(struct udevice *dev, struct bootflow 
*bflow,
  * @dev:   Bootmethod device to use
  * @bflow: Bootflow to read
  * Return: does not return on success, since it should boot the
- * Operating Systemn. Returns -EFAULT if that fails, other -ve on
+ * Operating System. Returns -EFAULT if that fails, other -ve on
  * other error
  */
 int bootmeth_read_all(struct udevice *dev, struct bootflow *bflow);
@@ -255,7 +255,7 @@ int bootmeth_read_all(struct udevice *dev, struct bootflow 
*bflow);
  * @dev:   Bootmethod device to boot
  * @bflow: Bootflow to boot
  * Return: does not return on success, since it should boot the
- * Operating Systemn. Returns -EFAULT if that fails, other -ve on
+ * Operating System. Returns -EFAULT if that fails, other -ve on
  * other error
  */
 int bootmeth_boot(struct udevice *dev, struct bootflow *bflow);
@@ -264,7 +264,7 @@ int bootmeth_boot(struct udevice *dev, struct bootflow 
*bflow);
  * bootmeth_setup_iter_order() - Set up the ordering of bootmeths to scan
  *
  * This sets up the ordering information in @iter, based on the selected
- * ordering of the bootmethds in bootstd_priv->bootmeth_order. If there is no
+ * ordering of the bootmeths in bootstd_priv->bootmeth_order. If there is no
  * ordering there, then all bootmethods are added
  *
  * @iter: Iterator to update with the order

-- 
2.45.0



[PATCH v2 0/2] bootstd: Fix a handful of doc typos in bootmeth

2024-06-04 Thread Mattijs Korpershoek
While working on bootflow, we noticed some wording inconsistencies with
bootmeth versus bootmethod.

According to [1], we should use bootmeth(s), not bootmethod(s):

"""
For version 2, a new naming scheme is used as above:

- bootdev is used instead of bootdevice, because 'device' is overused,
is everywhere in U-Boot, can be confused with udevice
- bootmeth - because 'method' is too vanilla, appears 1300 times in
U-Boot
"""

[1] c.f. https://lore.kernel.org/u-boot/20211023232635.9195-1-...@chromium.org/

First patch fixes some trivial typos, second patch replaces all
occurences of bootmethod(s) -> bootmeth(s).

Signed-off-by: Mattijs Korpershoek 
---
Changes in v2:
- Made into a series
- New patch replaces all bootmethod(s) -> bootmeth(s)
- Link to v1: 
https://lore.kernel.org/r/20240603-bootmeth-typos-v1-1-6edbdb469...@baylibre.com

---
Mattijs Korpershoek (2):
  bootstd: Fix a handful of doc typos in bootmeth
  bootstd: Replace bootmethod(s) -> bootmeth(s)

 board/sandbox/sandbox.env |  2 +-
 boot/bootmeth-uclass.c|  2 +-
 include/bootmeth.h| 42 +-
 include/extlinux.h|  2 +-
 test/boot/bootflow.c  |  2 +-
 test/boot/bootmeth.c  |  6 +++---
 6 files changed, 28 insertions(+), 28 deletions(-)
---
base-commit: ea722aa5eb33740ae77e8816aeb72b385e621cd0
change-id: 20240603-bootmeth-typos-47c865e70ccf

Best regards,
-- 
Mattijs Korpershoek 



Re: [PATCH] bootstd: Fix a handful of doc typos in bootmeth

2024-06-04 Thread Mattijs Korpershoek
Hi Quentin,

On mar., juin 04, 2024 at 11:47, Quentin Schulz  
wrote:

> Hi Mattijs,
>
> On 6/3/24 11:11 AM, Mattijs Korpershoek wrote:
>> Fix some trivial typos found by browsing the code.
>> Done with flyspell.
>> 
>> Signed-off-by: Mattijs Korpershoek  > ---
>>   include/bootmeth.h | 12 ++--
>>   1 file changed, 6 insertions(+), 6 deletions(-)
>> 
>> diff --git a/include/bootmeth.h b/include/bootmeth.h
>> index 0fc36104ece0..529c4d813d82 100644
>> --- a/include/bootmeth.h
>> +++ b/include/bootmeth.h
>> @@ -40,7 +40,7 @@ struct bootmeth_ops {
>>  /**
>>   * get_state_desc() - get detailed state information
>>   *
>> - * Prodecues a textual description of the state of the bootmeth. This
>> + * Produces a textual description of the state of the bootmeth. This
>>   * can include newline characters if it extends to multiple lines. It
>>   * must be a nul-terminated string.
>>   *
>> @@ -138,7 +138,7 @@ struct bootmeth_ops {
>>   * @dev:Bootmethod device to boot
>>   * @bflow:  Bootflow to boot
>>   * Return: does not return on success, since it should boot the
>> - *  Operating Systemn. Returns -EFAULT if that fails, -ENOTSUPP if
>> + *  Operating System. Returns -EFAULT if that fails, -ENOTSUPP if
>>   *  trying method resulted in finding out that is not actually
>>   *  supported for this boot and should not be tried again unless
>>   *  something changes, other -ve on other error
>> @@ -151,7 +151,7 @@ struct bootmeth_ops {
>>   /**
>>* bootmeth_get_state_desc() - get detailed state information
>>*
>> - * Prodecues a textual description of the state of the bootmeth. This
>> + * Produces a textual description of the state of the bootmeth. This
>>* can include newline characters if it extends to multiple lines. It
>>* must be a nul-terminated string.
>
> I see we have a mix of null-terminated and nul-terminated in the tree,
> is the latter correct?

Thank you for your review.

I believe nul-terminated is correct: nul is the character, and null is the 
pointer.

See:
- https://news.ycombinator.com/item?id=22283217
- https://internals.rust-lang.org/t/null-consistency/16767

I'll check the tree and submit another patch to fix this.

>
>>*
>> @@ -244,7 +244,7 @@ int bootmeth_read_file(struct udevice *dev, struct 
>> bootflow *bflow,
>>* @dev:   Bootmethod device to use
>>* @bflow: Bootflow to read
>>* Return: does not return on success, since it should boot the
>> - *  Operating Systemn. Returns -EFAULT if that fails, other -ve on
>> + *  Operating System. Returns -EFAULT if that fails, other -ve on
>>* other error
>>*/
>>   int bootmeth_read_all(struct udevice *dev, struct bootflow *bflow);
>> @@ -255,7 +255,7 @@ int bootmeth_read_all(struct udevice *dev, struct 
>> bootflow *bflow);
>>* @dev:   Bootmethod device to boot
>>* @bflow: Bootflow to boot
>>* Return: does not return on success, since it should boot the
>> - *  Operating Systemn. Returns -EFAULT if that fails, other -ve on
>> + *  Operating System. Returns -EFAULT if that fails, other -ve on
>>* other error
>>*/
>>   int bootmeth_boot(struct udevice *dev, struct bootflow *bflow);
>> @@ -264,7 +264,7 @@ int bootmeth_boot(struct udevice *dev, struct bootflow 
>> *bflow);
>>* bootmeth_setup_iter_order() - Set up the ordering of bootmeths to scan
>>*
>>* This sets up the ordering information in @iter, based on the selected
>> - * ordering of the bootmethds in bootstd_priv->bootmeth_order. If there is 
>> no
>> + * ordering of the bootmeths in bootstd_priv->bootmeth_order. If there is no
>>* ordering there, then all bootmethods are added
>>*
>
> Shouldn't this be bootmeths here as well?
>
> (And there's another occurrence in boot/bootmeth-uclass.c

There seems indeed to be some inconsistencies around bootmeths versus
bootmethods.

To me, we should use 'bootmeth' everywhere.

Simon, as the maintainer of bootflow, do you agree ?

I can spin up another patch to fix this.

>
> Cheers,
> Quentin


Re: [PATCH v3 1/8] dfu: add scsi backend

2024-06-04 Thread Mattijs Korpershoek
Hi Caleb,

Thank you for the patch.

On lun., juin 03, 2024 at 14:49, Caleb Connolly  
wrote:

> This is extremely similar to the MMC backend, but there are some notable
> differences.
>
> Works with a DFU string like
>
> scsi 4=u-boot-bin part 11
>
> Where "4" is the SCSI dev number (sequential LUN across all SCSI devices)
> and "11" is the partition number.
>
> Signed-off-by: Caleb Connolly 
> ---
>  doc/usage/dfu.rst  |  32 
>  drivers/dfu/Kconfig|   7 +
>  drivers/dfu/Makefile   |   1 +
>  drivers/dfu/dfu.c  |   5 +-
>  drivers/dfu/dfu_scsi.c | 435 
> +
>  include/dfu.h  |  26 +++
>  6 files changed, 505 insertions(+), 1 deletion(-)
>
> diff --git a/doc/usage/dfu.rst b/doc/usage/dfu.rst
> index 8cc09c308d82..f497dcf137a4 100644
> --- a/doc/usage/dfu.rst
> +++ b/doc/usage/dfu.rst
> @@ -21,8 +21,9 @@ U-Boot implements this DFU capability (CONFIG_DFU) with the 
> command dfu
>  
>  Today the supported DFU backends are:
>  
>  - MMC (RAW or FAT / EXT2 / EXT3 / EXT4 file system / SKIP / SCRIPT)
> +- SCSI (UFS, RAW partition, FAT / EXT2 / EXT3 / EXT4 file system / SKIP / 
> SCRIPT)
>  - NAND
>  - RAM
>  - SF (serial flash)
>  - MTD (all MTD device: NAND, SPI-NOR, SPI-NAND,...)
> @@ -166,8 +167,38 @@ mmc
>  
>  Please note that this means the user will be able to execute any
>  arbitrary commands just like in the u-boot's shell.

Can we please add CONFIG_DFU_SCSI in "Configuration Options" section at
the beginning of this document?

See:
https://docs.u-boot.org/en/latest/usage/dfu.html#configuration-options

Note: I requested that here:
https://lore.kernel.org/all/87o7a94pe1@baylibre.com/

With above addressed, feel free to add:
Reviewed-by: Mattijs Korpershoek 

And please take this through your tree:
Acked-by: Mattijs Korpershoek 

>  
> +scsi

[...]


Re: [PATCH 1/1] dfu: add missing dependency for SPI flash DFU driver

2024-06-04 Thread Mattijs Korpershoek
Hi Heinrich,

Thank you for the patch.

On mar., juin 04, 2024 at 07:44, Heinrich Schuchardt 
 wrote:

> Building the SPI flash DFU driver fails if SPI flash support is missing.
>
> drivers/dfu/dfu_sf.c:123:29: error:
> ‘CONFIG_SF_DEFAULT_MODE’ undeclared (first use in this function);
>
> Add the missing dependency.
>
> Signed-off-by: Heinrich Schuchardt 

Reviewed-by: Mattijs Korpershoek 

> ---
>  drivers/dfu/Kconfig | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig
> index 0360d9da142..971204758aa 100644
> --- a/drivers/dfu/Kconfig
> +++ b/drivers/dfu/Kconfig
> @@ -68,6 +68,7 @@ config DFU_RAM
>  
>  config DFU_SF
>   bool "SPI flash back end for DFU"
> + depends on SPI_FLASH || DM_SPI_FLASH
>   help
> This option enables using DFU to read and write to SPI flash based
> storage.
> -- 
> 2.43.0


Re: [PATCH] usb: dwc3: gadget: fix crash in dwc3_gadget_giveback()

2024-06-04 Thread Mattijs Korpershoek
Hi,

On Tue, 28 May 2024 10:35:03 +0200, Neil Armstrong wrote:
> If the ep0 stalls or request are dequeued when gagdet is stopped,
> the request dma may not be mapped yet and dwc3_flush_cache() may be
> called with a NULL pointer.
> 
> Check req->request.dma before calling dwc3_flush_cache() and later
> the usb_gadget_unmap_request() functions since it means that
> usb_gadget_map_request() hasn't been called yet.
> 
> [...]

Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu 
(u-boot-dfu)

[1/1] usb: dwc3: gadget: fix crash in dwc3_gadget_giveback()
  
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/85ced6f4745f529098cae38a5bd3144035a1318c

--
Mattijs


  1   2   3   4   5   6   >