diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2017-10-19 15:07:40 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-10-19 15:07:40 +0200 |
commit | a10a8e5e502fb5d5a6f945e208bd00a9bdeca5e2 (patch) | |
tree | cd4f007c081b7693424411cea71cb6c9e98ff379 /drivers/usb/gadget | |
parent | 7f04124c149fa4d8e8f657907c581f10987003e2 (diff) | |
parent | 05761813eff43493ee0519f0699a396de3f007a5 (diff) | |
download | barebox-a10a8e5e502fb5d5a6f945e208bd00a9bdeca5e2.tar.gz barebox-a10a8e5e502fb5d5a6f945e208bd00a9bdeca5e2.tar.xz |
Merge branch 'for-next/usbgadget'
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r-- | drivers/usb/gadget/autostart.c | 25 | ||||
-rw-r--r-- | drivers/usb/gadget/f_fastboot.c | 29 | ||||
-rw-r--r-- | drivers/usb/gadget/multi.c | 11 |
3 files changed, 54 insertions, 11 deletions
diff --git a/drivers/usb/gadget/autostart.c b/drivers/usb/gadget/autostart.c index 465d8fd380..f640a9667d 100644 --- a/drivers/usb/gadget/autostart.c +++ b/drivers/usb/gadget/autostart.c @@ -11,6 +11,8 @@ * GNU General Public License for more details. * */ +#define pr_fmt(fmt) "usbgadget autostart: " fmt + #include <common.h> #include <command.h> #include <errno.h> @@ -28,6 +30,7 @@ static int autostart; static int acm; static char *fastboot_function; +static int fastboot_bbu; static int usbgadget_autostart(void) { @@ -37,16 +40,28 @@ static int usbgadget_autostart(void) if (!autostart) return 0; - setenv("otg.mode", "peripheral"); - opts = xzalloc(sizeof(*opts)); opts->release = usb_multi_opts_release; - if (fastboot_function) + if (fastboot_function) { opts->fastboot_opts.files = file_list_parse(fastboot_function); + if (IS_ERR(opts->fastboot_opts.files)) { + pr_err("Parsing file list \"%s\" failed: %s\n", fastboot_function, + strerrorp(opts->fastboot_opts.files)); + opts->fastboot_opts.files = NULL; + } + + opts->fastboot_opts.export_bbu = fastboot_bbu; + } opts->create_acm = acm; + if (!opts->fastboot_opts.files && !opts->create_acm) { + pr_warn("No functions to register\n"); + return 0; + } + + setenv("otg.mode", "peripheral"); ret = usb_multi_register(opts); if (ret) @@ -63,6 +78,7 @@ static int usbgadget_globalvars_init(void) globalvar_add_simple_bool("usbgadget.acm", &acm); globalvar_add_simple_string("usbgadget.fastboot_function", &fastboot_function); + globalvar_add_simple_bool("usbgadget.fastboot_bbu", &fastboot_bbu); return 0; } @@ -77,3 +93,6 @@ BAREBOX_MAGICVAR_NAMED(global_usbgadget_acm, BAREBOX_MAGICVAR_NAMED(global_usbgadget_fastboot_function, global.usbgadget.fastboot_function, "usbgadget: Create Android Fastboot function"); +BAREBOX_MAGICVAR_NAMED(global_usbgadget_fastboot_bbu, + global.usbgadget.fastboot_bbu, + "usbgadget: export barebox update handlers via fastboot"); diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 598637619d..85c64c05c8 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -283,6 +283,21 @@ out: return ret; } +static int fastboot_add_bbu_variables(struct bbu_handler *handler, void *ctx) +{ + struct f_fastboot *f_fb = ctx; + char *name; + int ret; + + name = basprintf("bbu-%s", handler->name); + + ret = file_list_add_entry(f_fb->files, name, handler->devicefile, 0); + + free(name); + + return ret; +} + static int fastboot_bind(struct usb_configuration *c, struct usb_function *f) { struct usb_composite_dev *cdev = c->cdev; @@ -302,6 +317,9 @@ static int fastboot_bind(struct usb_configuration *c, struct usb_function *f) var = fb_addvar(f_fb, "bootloader-version"); fb_setvar(var, release_string); + if (IS_ENABLED(CONFIG_BAREBOX_UPDATE) && opts->export_bbu) + bbu_handlers_iterate(fastboot_add_bbu_variables, f_fb); + file_list_for_each_entry(f_fb->files, fentry) { ret = fastboot_add_partition_variables(f_fb, fentry); if (ret) @@ -679,18 +697,15 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req, const char *cmd fastboot_tx_print(f_fb, "INFOCopying file to %s...", cmd); - file_list_for_each_entry(f_fb->files, fentry) { - if (!strcmp(cmd, fentry->name)) { - filename = fentry->filename; - break; - } - } + fentry = file_list_entry_by_name(f_fb->files, cmd); - if (!filename) { + if (!fentry) { fastboot_tx_print(f_fb, "FAILNo such partition: %s", cmd); return; } + filename = fentry->filename; + if (filetype == filetype_ubi) { int fd; struct mtd_info_user meminfo; diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c index 6385c16186..44969be0c9 100644 --- a/drivers/usb/gadget/multi.c +++ b/drivers/usb/gadget/multi.c @@ -128,6 +128,7 @@ static int multi_bind_fastboot(struct usb_composite_dev *cdev) opts = container_of(fi_fastboot, struct f_fastboot_opts, func_inst); opts->files = gadget_multi_opts->fastboot_opts.files; + opts->export_bbu = gadget_multi_opts->fastboot_opts.export_bbu; f_fastboot = usb_get_function(fi_fastboot); if (IS_ERR(f_fastboot)) { @@ -234,6 +235,8 @@ static struct usb_composite_driver multi_driver = { int usb_multi_register(struct f_multi_opts *opts) { + int ret; + if (gadget_multi_opts) { pr_err("USB multi gadget already registered\n"); return -EBUSY; @@ -241,7 +244,13 @@ int usb_multi_register(struct f_multi_opts *opts) gadget_multi_opts = opts; - return usb_composite_probe(&multi_driver); + ret = usb_composite_probe(&multi_driver); + if (ret) { + usb_composite_unregister(&multi_driver); + gadget_multi_opts = NULL; + } + + return ret; } void usb_multi_unregister(void) |