public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH v3 0/3] Improve the experience with USB gadgets
@ 2023-10-10  9:03 Miquel Raynal
  2023-10-10  9:03 ` [PATCH v3 1/3] cmd: Change the dependencies between CMD_BIND and USB_GADGET Miquel Raynal
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Miquel Raynal @ 2023-10-10  9:03 UTC (permalink / raw)
  To: Marek Vasut, Lukasz Majewski, Mattijs Korpershoek
  Cc: u-boot, Thomas Petazzoni, Miquel Raynal

Try to ease the use of USB gadgets for people not fully aware of all the
terms and constraints. With more helpful error messages a little bit of
guidance anyone should be able to adapt to the bind/unbind game that is
now necessary with USB gadgets.

The idea is to eventually get proper USB composite gadget support, but
that is a longer term goal.

Changes in v3:
* First patch is new.
* Collected the tags received.
* Imply CMD_DM from CMD_BIND.

Miquel Raynal (3):
  cmd: Change the dependencies between CMD_BIND and USB_GADGET
  cmd: bind: Try to improve the (un)bind help
  usb: udc: Try to clarify an error message

 cmd/Kconfig                       |  2 +-
 cmd/bind.c                        |  4 ++++
 drivers/usb/gadget/Kconfig        |  1 +
 drivers/usb/gadget/udc/udc-core.c | 13 ++++++++++++-
 4 files changed, 18 insertions(+), 2 deletions(-)

-- 
2.34.1


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

* [PATCH v3 1/3] cmd: Change the dependencies between CMD_BIND and USB_GADGET
  2023-10-10  9:03 [PATCH v3 0/3] Improve the experience with USB gadgets Miquel Raynal
@ 2023-10-10  9:03 ` Miquel Raynal
  2023-10-18  7:01   ` Mattijs Korpershoek
  2023-10-10  9:03 ` [PATCH v3 2/3] cmd: bind: Try to improve the (un)bind help Miquel Raynal
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Miquel Raynal @ 2023-10-10  9:03 UTC (permalink / raw)
  To: Marek Vasut, Lukasz Majewski, Mattijs Korpershoek
  Cc: u-boot, Thomas Petazzoni, Miquel Raynal

Today CMD_BIND defaults to 'y' when USB_ETHER is enabled. In practice,
CMD_BIND should default to 'y' when any USB gadget is enabled not only
USB_ETHER. Let's invert the logic of the dependency and use the weak
'imply' keyword to enforce this.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 cmd/Kconfig                | 1 -
 drivers/usb/gadget/Kconfig | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 43ca10f69cc..6cc3bf6c2d0 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -996,7 +996,6 @@ config CMD_BCB
 config CMD_BIND
 	bool "bind/unbind - Bind or unbind a device to/from a driver"
 	depends on DM
-	default y if USB_ETHER
 	help
 	  Bind or unbind a device to/from a driver from the command line.
 	  This is useful in situations where a device may be handled by several
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 1cfe6022842..44f47a07207 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -17,6 +17,7 @@ menuconfig USB_GADGET
 	bool "USB Gadget Support"
 	depends on DM
 	select DM_USB
+	imply CMD_BIND
 	help
 	   USB is a master/slave protocol, organized with one master
 	   host (such as a PC) controlling up to 127 peripheral devices.
-- 
2.34.1


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

* [PATCH v3 2/3] cmd: bind: Try to improve the (un)bind help
  2023-10-10  9:03 [PATCH v3 0/3] Improve the experience with USB gadgets Miquel Raynal
  2023-10-10  9:03 ` [PATCH v3 1/3] cmd: Change the dependencies between CMD_BIND and USB_GADGET Miquel Raynal
@ 2023-10-10  9:03 ` Miquel Raynal
  2023-10-10  9:03 ` [PATCH v3 3/3] usb: udc: Try to clarify an error message Miquel Raynal
  2023-11-21 14:52 ` [PATCH v3 0/3] Improve the experience with USB gadgets Mattijs Korpershoek
  3 siblings, 0 replies; 6+ messages in thread
From: Miquel Raynal @ 2023-10-10  9:03 UTC (permalink / raw)
  To: Marek Vasut, Lukasz Majewski, Mattijs Korpershoek
  Cc: u-boot, Thomas Petazzoni, Miquel Raynal, Simon Glass

While it may sound totally obvious for the regular U-Boot developer to
get the parameters of the bind/unbind commands from the output of 'dm
tree', it did not felt straightforward to me until I was explicitly
told to look there. And even when I knew the command, I did not make a
direct link between the arguments of this command and the columns
returned by 'dm tree'.

Several of us lost a lot of time because of that, I would like to kindly
help other users by slightly improving this textual line. Unfortunately,
because of how this string is used (like within the 'help' command) I
cannot detail much more, but at least the pointer is there.

While we add this message, we can also imply CMD_DM when we enable
CMD_BIND so the debug message does not lead to an unknown command. This
way the 'dm' command will likely be there unless explicitly disabled.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
---
 cmd/Kconfig | 1 +
 cmd/bind.c  | 4 ++++
 2 files changed, 5 insertions(+)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 6cc3bf6c2d0..668411fd87c 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -996,6 +996,7 @@ config CMD_BCB
 config CMD_BIND
 	bool "bind/unbind - Bind or unbind a device to/from a driver"
 	depends on DM
+	imply CMD_DM
 	help
 	  Bind or unbind a device to/from a driver from the command line.
 	  This is useful in situations where a device may be handled by several
diff --git a/cmd/bind.c b/cmd/bind.c
index 4d1b7885e60..be0d4d2a711 100644
--- a/cmd/bind.c
+++ b/cmd/bind.c
@@ -246,6 +246,8 @@ U_BOOT_CMD(
 	"Bind a device to a driver",
 	"<node path> <driver>\n"
 	"bind <class> <index> <driver>\n"
+	"Use 'dm tree' to list all devices registered in the driver model,\n"
+	"their path, class, index and current driver.\n"
 );
 
 U_BOOT_CMD(
@@ -254,4 +256,6 @@ U_BOOT_CMD(
 	"<node path>\n"
 	"unbind <class> <index>\n"
 	"unbind <class> <index> <driver>\n"
+	"Use 'dm tree' to list all devices registered in the driver model,\n"
+	"their path, class, index and current driver.\n"
 );
-- 
2.34.1


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

* [PATCH v3 3/3] usb: udc: Try to clarify an error message
  2023-10-10  9:03 [PATCH v3 0/3] Improve the experience with USB gadgets Miquel Raynal
  2023-10-10  9:03 ` [PATCH v3 1/3] cmd: Change the dependencies between CMD_BIND and USB_GADGET Miquel Raynal
  2023-10-10  9:03 ` [PATCH v3 2/3] cmd: bind: Try to improve the (un)bind help Miquel Raynal
@ 2023-10-10  9:03 ` Miquel Raynal
  2023-11-21 14:52 ` [PATCH v3 0/3] Improve the experience with USB gadgets Mattijs Korpershoek
  3 siblings, 0 replies; 6+ messages in thread
From: Miquel Raynal @ 2023-10-10  9:03 UTC (permalink / raw)
  To: Marek Vasut, Lukasz Majewski, Mattijs Korpershoek
  Cc: u-boot, Thomas Petazzoni, Miquel Raynal

At some point when trying to use USB gadgets, two situations may arise
and lead to a failure. Either the UDC (USB Device Controller) is not
available at all (not described or not probed) or the UDC is already in
use. For instance, as the USB Ethernet gadget remains bound to the UDC,
the use of any other USB gadget (fastboot, dfu, etc) *after* will always
fail with the "couldn't find an available UDC" error.

Let's give a more helpful message by making a difference between the two
cases. Let's also hint people who would get this error and grep it into
the sources a better explanation of what's wrong with their workflow.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
---

While doing this I really wanted to add "much more" error comments but I
faced another reality: often the messages are there but use
pr_err/log_err which is actually silenced by default with LOGLEVEL=3, so
I consider this unnecessary, as decreasing the loglevel will make these
messages appear. I would have expected errors to be displayed, but I
understand it makes the binaries even bigger.
---
 drivers/usb/gadget/udc/udc-core.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c
index 7f73926cb3e..8405b03462e 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -323,6 +323,7 @@ err1:
 int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
 {
 	struct usb_udc		*udc = NULL;
+	unsigned int		udc_count = 0;
 	int			ret;
 
 	if (!driver || !driver->bind || !driver->setup)
@@ -330,12 +331,22 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
 
 	mutex_lock(&udc_lock);
 	list_for_each_entry(udc, &udc_list, list) {
+		udc_count++;
+
 		/* For now we take the first one */
 		if (!udc->driver)
 			goto found;
 	}
 
-	printf("couldn't find an available UDC\n");
+	if (!udc_count)
+		printf("No UDC available in the system\n");
+	else
+		/* When this happens, users should 'unbind <class> <index>'
+		 * using the output of 'dm tree' and looking at the line right
+		 * after the USB peripheral/device controller.
+		 */
+		printf("All UDCs in use (%d available), use the unbind command\n",
+		       udc_count);
 	mutex_unlock(&udc_lock);
 	return -ENODEV;
 found:
-- 
2.34.1


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

* Re: [PATCH v3 1/3] cmd: Change the dependencies between CMD_BIND and USB_GADGET
  2023-10-10  9:03 ` [PATCH v3 1/3] cmd: Change the dependencies between CMD_BIND and USB_GADGET Miquel Raynal
@ 2023-10-18  7:01   ` Mattijs Korpershoek
  0 siblings, 0 replies; 6+ messages in thread
From: Mattijs Korpershoek @ 2023-10-18  7:01 UTC (permalink / raw)
  To: Miquel Raynal, Marek Vasut, Lukasz Majewski
  Cc: u-boot, Thomas Petazzoni, Miquel Raynal

On mar., oct. 10, 2023 at 11:03, Miquel Raynal <miquel.raynal@bootlin.com> wrote:

> Today CMD_BIND defaults to 'y' when USB_ETHER is enabled. In practice,
> CMD_BIND should default to 'y' when any USB gadget is enabled not only
> USB_ETHER. Let's invert the logic of the dependency and use the weak
> 'imply' keyword to enforce this.
>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

Tested that the bind command exists when building with:
configs/khadas-vim3_android_defconfig

Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> # on vim3

> ---
>  cmd/Kconfig                | 1 -
>  drivers/usb/gadget/Kconfig | 1 +
>  2 files changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index 43ca10f69cc..6cc3bf6c2d0 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -996,7 +996,6 @@ config CMD_BCB
>  config CMD_BIND
>  	bool "bind/unbind - Bind or unbind a device to/from a driver"
>  	depends on DM
> -	default y if USB_ETHER
>  	help
>  	  Bind or unbind a device to/from a driver from the command line.
>  	  This is useful in situations where a device may be handled by several
> diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
> index 1cfe6022842..44f47a07207 100644
> --- a/drivers/usb/gadget/Kconfig
> +++ b/drivers/usb/gadget/Kconfig
> @@ -17,6 +17,7 @@ menuconfig USB_GADGET
>  	bool "USB Gadget Support"
>  	depends on DM
>  	select DM_USB
> +	imply CMD_BIND
>  	help
>  	   USB is a master/slave protocol, organized with one master
>  	   host (such as a PC) controlling up to 127 peripheral devices.
> -- 
> 2.34.1

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

* Re: [PATCH v3 0/3] Improve the experience with USB gadgets
  2023-10-10  9:03 [PATCH v3 0/3] Improve the experience with USB gadgets Miquel Raynal
                   ` (2 preceding siblings ...)
  2023-10-10  9:03 ` [PATCH v3 3/3] usb: udc: Try to clarify an error message Miquel Raynal
@ 2023-11-21 14:52 ` Mattijs Korpershoek
  3 siblings, 0 replies; 6+ messages in thread
From: Mattijs Korpershoek @ 2023-11-21 14:52 UTC (permalink / raw)
  To: Lukasz Majewski, Marek Vasut, Miquel Raynal; +Cc: u-boot, Thomas Petazzoni

Hi,

On Tue, 10 Oct 2023 11:03:01 +0200, Miquel Raynal wrote:
> Try to ease the use of USB gadgets for people not fully aware of all the
> terms and constraints. With more helpful error messages a little bit of
> guidance anyone should be able to adapt to the bind/unbind game that is
> now necessary with USB gadgets.
> 
> The idea is to eventually get proper USB composite gadget support, but
> that is a longer term goal.
> 
> [...]

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

[1/3] cmd: Change the dependencies between CMD_BIND and USB_GADGET
      https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/9b63fcaec664780545318d923063bedd898a629c
[2/3] cmd: bind: Try to improve the (un)bind help
      https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/249a75d8e82b422639beedca3d7d945cd78869ba
[3/3] usb: udc: Try to clarify an error message
      https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/8a0d07807abb5370fe879321c7f1d22fdda3255f

--
Mattijs

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

end of thread, other threads:[~2023-11-21 14:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-10  9:03 [PATCH v3 0/3] Improve the experience with USB gadgets Miquel Raynal
2023-10-10  9:03 ` [PATCH v3 1/3] cmd: Change the dependencies between CMD_BIND and USB_GADGET Miquel Raynal
2023-10-18  7:01   ` Mattijs Korpershoek
2023-10-10  9:03 ` [PATCH v3 2/3] cmd: bind: Try to improve the (un)bind help Miquel Raynal
2023-10-10  9:03 ` [PATCH v3 3/3] usb: udc: Try to clarify an error message Miquel Raynal
2023-11-21 14:52 ` [PATCH v3 0/3] Improve the experience with USB gadgets Mattijs Korpershoek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox