summaryrefslogtreecommitdiffstats
path: root/common/usbgadget.c
Commit message (Collapse)AuthorAgeFilesLines
* usb: move include files to place where Linux has themSascha Hauer2023-03-201-3/+3
| | | | | | | | | For easier patch merging and comparison with Linux move the usb gadget files to where Linux has them. For now do a plain git mv include/usb include/linux/usb, eventhough there might be some files which are purely barebox specific. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct device_d to deviceSascha Hauer2023-01-101-1/+1
| | | | | | | | | | | | | The '_d' suffix was originally introduced in case we want to import Linux struct device as a separate struct into barebox. Over time it became clear that this won't happen, instead barebox struct device_d is basically the same as Linux struct device. Rename the struct name accordingly to make porting Linux code easier. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usbgadget: autostart: add usbgadget_autostart() for board codeAhmad Fatoum2022-08-171-5/+32
| | | | | | | | | | | | | | | | global.usbgadget.autostart is registered at postenvironment level initcall, so changing its value before that doesn't have the desired effect of automatically starting the usb gadget. Refactor the code so that we have a usbgadget_do_autostart() function that first checks if it should run at all and that it's the right time to run. This function can be called at any time and based on that implement usbgadget_autostart() to let board code be able to trigger the autorun functionality. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220815091733.1973736-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: gadget: don't register UMS with empty functionAhmad Fatoum2022-03-281-1/+1
| | | | | | | | | | | | | | | | system_partitions_get clones the system partitions and passes it along. DFU and Fastboot use system partitions as a fallback and pass along a NULL file list if they are empty. This enables e.g. usbgadget -A '' to work: No files are expored, but fastboot OEM commands are possible. USB mass storage though does pass along an empty system partitions file list instead of NULL, which leads to bind failure, because UMS gadget refuses to bind with no LUNs. Detect this case. Fixes: 57313f83e83e ("usbgadget: add support for USB mass storage gadget") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220319110246.2850396-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: gadget: implement and use system_partitions_get_nullAhmad Fatoum2022-03-281-3/+1
| | | | | | | | | | | | | system_partitions_get() clones the system partitions file list and returns the copy. usb multi gadget code expects disabled gadgets to have a NULL file list, not an empty one, so fastboot and DFU handle this case. Add a new system_partitions_get_null helper that can be used instead. This will be used for USB mass storage gadget as well in a follow-up commit. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220319110246.2850396-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* file_list: add file_list_parse_null()Rouven Czerwinski2021-10-051-20/+4
| | | | | | | | | | Move the usbgadget parse() function to file_list and rename it to file_list_parse_null() which will return a NULL pointer instead of an error. Also adjust the callers in the usbgadget code. Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> Link: https://lore.barebox.org/20210810052928.101783-1-r.czerwinski@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usbgadget: add support for USB mass storage gadgetAhmad Fatoum2021-06-251-1/+9
| | | | | | | | | | | | | | | | | | | This driver is based on the f_mass_storage drivers in Linux v5.11 and U-Boot v2021.01. Unlike the U-Boot version, it runs asynchronously without blocking the bootloader from doing other tasks, like exporting other USB gadgets at the same time or enabling shell access. With pollers and workqueues, enabling this would need a large rework of the code to be completely callback based, whenever the original Linux code sleeps waiting for events. With the new bthread support, we can actually sleep and handover control to other bthreads until there is actual work to do. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210622082617.18011-9-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usbgadget: refactor usbgadget_register to accept arrayAhmad Fatoum2021-06-251-11/+17
| | | | | | | | | | usbgadget_register currently takes 6 arguments. Instead of increasing them to 8 to support the new usb mass storage gadget, rewrite it to accept a pointer to a struct with all the options instead. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210622082617.18011-8-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fastboot/dfu: use system partitions as fall backAhmad Fatoum2021-05-121-29/+48
| | | | | | | | | | | | | Use the new system partitions infrastructure to have fastboot and DFU fall back to using the same partitions if the global.usbgadget.dfu_function and global.fastboot_partitions are not set, respectively. No functional change intended for configurations that have SYSTEM_PARTITIONS disabled. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210503114901.13095-13-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usbgadget: allow DFU and Fastboot functions to coexistAhmad Fatoum2021-05-121-7/+6
| | | | | | | | | | | | | | | | | According to the commit, one upon a time the fastboot client tool did not support a device that exports DFU as well. It does nowadays, and while dfu-util 0.9 doesn't, it might some day. Because these host tools are outside of barebox' control, allow both to coexist and just throw a warning that dfu-util might not work. With the new system partitions support, enabled fastboot and DFU mean that autostart would start both as part of the same multi-gadget. This would've failed, but would now just emit a warning. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210503114901.13095-11-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usbgadget: autostart: fix indeterminism around usbgadget.autostartAhmad Fatoum2021-05-121-6/+10
| | | | | | | | | | | | | | | | | | | | | | | The setter for usbgadget.autostart evaluates other device paramaters, so it must happen postenvironment, otherwise it could run too early and not see the device parameters it depends on. This was observed with usbgadget.dfu_function, which wasn't loaded from the environment early enough, but it now does. While at it, remove some more wonkyness: - usbgadget_autostart_set is only ever called when the IS_ENABLED(CONFIG_USB_GADGET_AUTOSTART), so drop the check - There is no need to make usbgadget.acm specific to autostart. It's behavior now is counter intuitive (enable Kconfig symbol, but don't set global variable and it will have an effect. Disable CONFIG_USB_GADGET_AUTOSTART, which looks completely unrelated and it no longer works. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210503114901.13095-10-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: replace license statements with SPDX-License-IdentifiersAhmad Fatoum2020-11-271-10/+1
| | | | | | | | | | | | | For all files in common/ that already have a license text: - Replace with appropriate SPDX-License-Identifier - Remove empty comment lines around replacement - remove comment completely if only thing remaining is name of file without description Reviewed-by: Roland Hieber <rhi@pengutronix.de> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usbgadget: autostart: don't print error on repeated nv.usbgadget.autostart=1Ahmad Fatoum2020-11-241-2/+8
| | | | | | | | | | | | | | | | | | | | | | nvvar_add results in two calls to dev_set_param: - once when the existing global variable is found and set - once more when setting the nv variable This results in an annoying but ultimately harmless message on startup: ERROR: USB multi gadget already registered ERROR: failed to create nv variable usbgadget.autostart: Device or resource busy Avoid this by ignoring usbgadget.autostart=1 after it succeeded once. This issue should only affect $global.usbgadget.autostart, because all other global variables are "simple" meaning that they have no setters triggered. Fixes: 5a5c5178e7dc ("usbgadget: autostart: support delayed usbgadget.autostart=1") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/reboot-mode' into masterSascha Hauer2020-10-141-3/+3
|\
| * Merge branch 'for-next/magicvar-unique-id' into for-next/reboot-modeSascha Hauer2020-10-071-9/+6
| |\
| * | usbgadget: autostart: support delayed usbgadget.autostart=1Ahmad Fatoum2020-09-291-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | So far, global.usbgadget.autostart=1 from the shell was without effect, because the variable is only evaluated once at postenvironment_initcall. Use the new globalvar_add_bool() to allow acting on the variable being true at any time. This is necessary for scripts that want to enable the usbgadget autostart functionality selectively without themselves hardcoding the particularities of what is exported. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | Merge branch 'for-next/percent_pe' into masterSascha Hauer2020-10-141-2/+1
|\ \ \ | |_|/ |/| |
| * | vsprintf: retire strerrorp in favor of %peAhmad Fatoum2020-09-291-2/+1
| |/ | | | | | | | | | | | | | | | | strerrorp() is only used along with printf. We now have a format specifier for printing error pointers directly, so use that and remove strerrorp. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / magicvar: Replace BAREBOX_MAGICVAR_NAMED with BAREBOX_MAGICVARSascha Hauer2020-10-021-9/+6
|/ | | | | | | | BAREBOX_MAGICVAR now generates a unique identifier automatically, so we can convert users of BAREBOX_MAGICVAR_NAMED to the simpler BAREBOX_MAGICVAR macro. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fastboot: rename usbgadget.fastboot_* variables to fastboot.*Daniel Glöckner2020-08-191-15/+6
| | | | | | | | | | | | | There is nothing USB-specific in the defined usbgadget.fastboot_* variables. Rename them to be usable also for the UDP fastboot transport. The usbgadget.fastboot_function variable is used to define the files and devices accessible with the erase and flash commands. Since "function" is a term from the USB specification and the Fastboot specification uses the term "partition", we rename that variable to "fastboot.partitions". Signed-off-by: Daniel Glöckner <dg@emlix.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usbgadget: autostart: add DFU supportLadislav Michl2018-10-291-0/+144
Use global variable dfu_function to autostart DFU. As similar code is used to start multifunction gadget using command, move common code to common/usbgadget.c and consolidate it. It turned out that '-s' option of usbgadget command does nothing, so remove its help text and make it function as '-a'. Signed-off-by: Ladislav Michl <ladis@linux-mips.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>