From 6f3ff5e61c3ff92356345604415dd682b817bf76 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 29 Jan 2018 20:47:26 +0100 Subject: ubiformat: Allow to ubiformat with a buffer given So far ubiformat can only handle files. Make it possible to pass a buffer into ubiformat. Signed-off-by: Sascha Hauer --- include/ubiformat.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include') diff --git a/include/ubiformat.h b/include/ubiformat.h index 8305a853c7..8a7a16ac18 100644 --- a/include/ubiformat.h +++ b/include/ubiformat.h @@ -15,7 +15,14 @@ struct ubiformat_args { int ubi_ver; uint32_t image_seq; long long ec; + + /* + * Either set image if you have a file or set image_buf / image_size + * if you have a buffer. + */ const char *image; + const void *image_buf; + loff_t image_size; }; int ubiformat(struct mtd_info *mtd, struct ubiformat_args *args); -- cgit v1.2.3 From ed1dded0898faa1f917309172f2065014756c59f Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Fri, 26 Jan 2018 09:58:56 +0100 Subject: usb: gadget: fastboot: Add external command execution support Custom projects may need vendor specific expansions to the fastboot command execution. Allow these to be implemented without messing in the fastboot code directly. We have a hook for all commands and also one for the "flash" command. Each hook can decide if the generic command parser is executed afterwards (return value FASTBOOT_CMD_FALLTHROUGH) or if the generic parser shall be skipped (return value 0 or negative error code). This allows board code to implement vendor specific "oem" commands or to handle the downloaded image in a special way (i.e. do signature checks on them) Signed-off-by: Sascha Hauer --- drivers/usb/gadget/f_fastboot.c | 21 ++++++++++++++++++++- drivers/usb/gadget/multi.c | 2 ++ include/usb/fastboot.h | 17 +++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index b851e8d1c3..787b1205ec 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -75,6 +75,9 @@ struct f_fastboot { 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 @@ static int fastboot_bind(struct usb_configuration *c, struct usb_function *f) 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 @@ static void cb_flash(struct f_fastboot *f_fb, const char *cmd) 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 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req) { 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 44969be0c9..d6edfb8cf2 100644 --- a/drivers/usb/gadget/multi.c +++ b/drivers/usb/gadget/multi.c @@ -128,6 +128,8 @@ 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->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 ced890c9ab..00c9d00df5 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 f_fastboot_opts { 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 */ -- cgit v1.2.3