From 57313f83e83e1fac87c1a9088175f12ebd3577a0 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Tue, 22 Jun 2021 10:26:17 +0200 Subject: usbgadget: add support for USB mass storage gadget 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 Link: https://lore.barebox.org/20210622082617.18011-9-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- common/usbgadget.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'common') diff --git a/common/usbgadget.c b/common/usbgadget.c index 9bbaa4ea12..34a685234b 100644 --- a/common/usbgadget.c +++ b/common/usbgadget.c @@ -66,6 +66,14 @@ int usbgadget_register(const struct usbgadget_funcs *funcs) } } + if (flags & USBGADGET_MASS_STORAGE) { + opts->ums_opts.files = parse(funcs->ums_opts); + if (IS_ENABLED(CONFIG_USB_GADGET_MASS_STORAGE) && file_list_empty(opts->ums_opts.files)) { + file_list_free(opts->ums_opts.files); + opts->ums_opts.files = system_partitions_get(); + } + } + if (flags & USBGADGET_FASTBOOT) { opts->fastboot_opts.files = parse(funcs->fastboot_opts); if (IS_ENABLED(CONFIG_FASTBOOT_BASE) && file_list_empty(opts->fastboot_opts.files)) { @@ -122,7 +130,7 @@ static int usbgadget_autostart_set(struct param_d *param, void *ctx) if (acm) funcs.flags |= USBGADGET_ACM; - funcs.flags |= USBGADGET_DFU | USBGADGET_FASTBOOT; + funcs.flags |= USBGADGET_DFU | USBGADGET_FASTBOOT | USBGADGET_MASS_STORAGE; err = usbgadget_register(&funcs); if (!err) -- cgit v1.2.3