diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index b851e8d..787b120 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -75,6 +75,9 @@ struct usb_ep *in_ep, *out_ep; struct usb_request *in_req, *out_req; struct file_list *files; + int (*cmd_exec)(struct f_fastboot *, const char *cmd); + int (*cmd_flash)(struct f_fastboot *, struct file_list_entry *entry, + const char *filename, const void *buf, size_t len); int download_fd; void *buf; @@ -327,6 +330,8 @@ struct fb_variable *var; f_fb->files = opts->files; + f_fb->cmd_exec = opts->cmd_exec; + f_fb->cmd_flash = opts->cmd_flash; var = fb_addvar(f_fb, "version"); fb_setvar(var, "0.4"); @@ -932,6 +937,13 @@ goto out; } + if (f_fb->cmd_flash) { + ret = f_fb->cmd_flash(f_fb, fentry, sourcefile, f_fb->buf, + f_fb->download_size); + if (ret != FASTBOOT_CMD_FALLTHROUGH) + goto out; + } + filename = fentry->filename; if (filetype == filetype_android_sparse) { @@ -1197,15 +1209,22 @@ { char *cmdbuf = req->buf; struct f_fastboot *f_fb = req->context; + int ret; if (req->status != 0) return; *(cmdbuf + req->actual) = 0; + if (f_fb->cmd_exec) { + ret = f_fb->cmd_exec(f_fb, cmdbuf); + if (ret != FASTBOOT_CMD_FALLTHROUGH) + goto done; + } + fb_run_command(f_fb, cmdbuf, cmd_dispatch_info, ARRAY_SIZE(cmd_dispatch_info)); - +done: *cmdbuf = '\0'; req->actual = 0; memset(req->buf, 0, EP_BUFFER_SIZE); diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c index 44969be..d6edfb8 100644 --- a/drivers/usb/gadget/multi.c +++ b/drivers/usb/gadget/multi.c @@ -128,6 +128,8 @@ opts = container_of(fi_fastboot, struct f_fastboot_opts, func_inst); opts->files = gadget_multi_opts->fastboot_opts.files; + opts->cmd_exec = gadget_multi_opts->fastboot_opts.cmd_exec; + opts->cmd_flash = gadget_multi_opts->fastboot_opts.cmd_flash; opts->export_bbu = gadget_multi_opts->fastboot_opts.export_bbu; f_fastboot = usb_get_function(fi_fastboot); diff --git a/include/usb/fastboot.h b/include/usb/fastboot.h index ced890c..00c9d00 100644 --- a/include/usb/fastboot.h +++ b/include/usb/fastboot.h @@ -5,6 +5,8 @@ #include #include +struct f_fastboot; + /** * struct f_fastboot_opts - options to configure the fastboot gadget * @func_inst: The USB function instance to register on @@ -15,6 +17,21 @@ struct usb_function_instance func_inst; struct file_list *files; bool export_bbu; + int (*cmd_exec)(struct f_fastboot *, const char *cmd); + int (*cmd_flash)(struct f_fastboot *, struct file_list_entry *entry, + const char *filename, const void *buf, size_t len); }; +/* + * Return codes for the exec_cmd callback above: + * + * FASTBOOT_CMD_FALLTHROUGH - Not handled by the external command dispatcher, + * handle it with internal dispatcher + * Other than these negative error codes mean errors handling the command and + * zero means the command has been successfully handled. + */ +#define FASTBOOT_CMD_FALLTHROUGH 1 + +int fastboot_tx_print(struct f_fastboot *f_fb, const char *fmt, ...); + #endif /* _USB_FASTBOOT_H */