From f49062330967a549d2967242c36a2fe984b16b4e Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Mon, 20 Jun 2022 20:13:54 +0900 Subject: [PATCH 1/5] dfu: add CONFIG_DFU_NAME_MAX_SIZE configuration Add CONFIG_DFU_NAME_MAX_SIZE to change the proper size. If name is longer than default size, it can do wrong behavior during updating image. So it need to change the proper maximum size. This patch is proviced the solution to change value with configuration. Signed-off-by: Jaehoon Chung Reviewed-by: Mattijs Korpershoek Reviewed-by: Lukasz Majewski Link: https://lore.kernel.org/r/20220620111354.448512-1-jh80.chung@samsung.com [mkorpershoek: fixed build errors for dfu.h includes] Signed-off-by: Mattijs Korpershoek --- drivers/dfu/Kconfig | 9 +++++++++ include/dfu.h | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig index 8771678ca5a..0360d9da142 100644 --- a/drivers/dfu/Kconfig +++ b/drivers/dfu/Kconfig @@ -112,5 +112,14 @@ config SYS_DFU_MAX_FILE_SIZE the buffer once we've been given the whole file. Define this to the maximum filesize (in bytes) for the buffer. If undefined it defaults to the CONFIG_SYS_DFU_DATA_BUF_SIZE. + +config DFU_NAME_MAX_SIZE + int "Size of the name to be added in dfu entity" + default 32 + depends on DFU + help + This value is used to maximum size. If name is longer than default size, + we need to change the proper maximum size. + endif endmenu diff --git a/include/dfu.h b/include/dfu.h index 68b5ca46ce5..2f42781888a 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -98,7 +98,12 @@ struct virt_internal_data { int dev_num; }; + +#if defined(CONFIG_DFU_NAME_MAX_SIZE) +#define DFU_NAME_SIZE CONFIG_DFU_NAME_MAX_SIZE +#else #define DFU_NAME_SIZE 32 +#endif #ifndef DFU_DEFAULT_POLL_TIMEOUT #define DFU_DEFAULT_POLL_TIMEOUT 0 #endif From 1041ee64eb18f7a3af30085765ced149cb4dc7cf Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 7 Nov 2023 01:09:59 +0100 Subject: [PATCH 2/5] usb: gadget: f_mass_storage: Stop ums on START-STOP UNIT SCSI command Exit the UMS handler loop in case START-STOP UNIT SCSI command is received. This is sent e.g. by the util-linux eject(1) command and indicates to the device that it is supposed to spin down the media and enter low power state. This effectively adds support for exitting the 'ums' command from host using 'eject /dev/sdN' that is on par with 'dfu-util -e' . Signed-off-by: Marek Vasut Reviewed-by: Mattijs Korpershoek Link: https://lore.kernel.org/r/20231107001018.55640-1-marex@denx.de Signed-off-by: Mattijs Korpershoek --- drivers/usb/gadget/f_mass_storage.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 1d17331cb03..c725aed3f62 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -327,6 +327,7 @@ struct fsg_common { unsigned int short_packet_received:1; unsigned int bad_lun_okay:1; unsigned int running:1; + unsigned int eject:1; int thread_wakeup_needed; struct completion thread_notifier; @@ -669,6 +670,10 @@ static int sleep_thread(struct fsg_common *common) } if (k == 10) { + /* Handle START-STOP UNIT */ + if (common->eject) + return -EPIPE; + /* Handle CTRL+C */ if (ctrlc()) return -EPIPE; @@ -1325,6 +1330,8 @@ static int do_start_stop(struct fsg_common *common) return -EINVAL; } + common->eject = 1; + return 0; } From 9b63fcaec664780545318d923063bedd898a629c Mon Sep 17 00:00:00 2001 From: Miquel Raynal Date: Tue, 10 Oct 2023 11:03:02 +0200 Subject: [PATCH 3/5] cmd: Change the dependencies between CMD_BIND and USB_GADGET 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 Reviewed-by: Mattijs Korpershoek Tested-by: Mattijs Korpershoek # on vim3 Link: https://lore.kernel.org/r/20231010090304.49335-2-miquel.raynal@bootlin.com Signed-off-by: Mattijs Korpershoek --- cmd/Kconfig | 1 - drivers/usb/gadget/Kconfig | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/Kconfig b/cmd/Kconfig index 6f636155e5b..859e305634b 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -977,7 +977,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 4eccc5e3370..c72a8047635 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. From 249a75d8e82b422639beedca3d7d945cd78869ba Mon Sep 17 00:00:00 2001 From: Miquel Raynal Date: Tue, 10 Oct 2023 11:03:03 +0200 Subject: [PATCH 4/5] 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. 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 Reviewed-by: Simon Glass Reviewed-by: Mattijs Korpershoek Link: https://lore.kernel.org/r/20231010090304.49335-3-miquel.raynal@bootlin.com Signed-off-by: Mattijs Korpershoek --- cmd/Kconfig | 1 + cmd/bind.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/cmd/Kconfig b/cmd/Kconfig index 859e305634b..ac1644282a9 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -977,6 +977,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", " \n" "bind \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( "\n" "unbind \n" "unbind \n" + "Use 'dm tree' to list all devices registered in the driver model,\n" + "their path, class, index and current driver.\n" ); From 8a0d07807abb5370fe879321c7f1d22fdda3255f Mon Sep 17 00:00:00 2001 From: Miquel Raynal Date: Tue, 10 Oct 2023 11:03:04 +0200 Subject: [PATCH 5/5] usb: udc: Try to clarify an error message 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 Reviewed-by: Mattijs Korpershoek Link: https://lore.kernel.org/r/20231010090304.49335-4-miquel.raynal@bootlin.com Signed-off-by: Mattijs Korpershoek --- 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 eb0b35969ce..ba658d92296 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 ' + * 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: