[PATCH v2 1/2] cmd: bind: Try to improve the (un)bind help

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.
Signed-off-by: Miquel Raynal miquel.raynal@bootlin.com --- Changes in v2: * Moved the details in the long text section as suggested by Heinrich. * Rephrased the help text as well, not fully following Heinrich suggestion, but taking inspiration from it. --- cmd/bind.c | 4 ++++ 1 file changed, 4 insertions(+)
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" );

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 --- 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.
Changes in v2: * s/UDC/UDCs/. I kept the sentence as it was as the suggested form did not sound well at all when there is only one UDC. --- 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:
participants (1)
-
Miquel Raynal