From 436dd5700e32d25d2ca6557bd2ef9a5ef73d4648 Mon Sep 17 00:00:00 2001 From: Haoran Wang Date: Wed, 25 Oct 2017 18:08:42 +0800 Subject: [PATCH] [iot] fastboot:Add 'get_staged' command support When host end execute "fastboot get_staged [ ]" The staged data from the last command will be output to host end. If the last command did not result in staged data or the target data larger than end point buffer size, this command will be fail. This patch also alloc new buffer that is larger than normal end point's as the this command need to transfer data by one packet. So that only the file that less than 128KB will be transfered. Change-Id: I1dbefa130df9ca348a30d7bc52cb856c052776bf Signed-off-by: Haoran Wang --- drivers/usb/gadget/f_fastboot.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index d14c4a8d40..8fb21bf5a3 100755 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -2055,6 +2055,15 @@ static int fastboot_set_alt(struct usb_function *f, ret = -EINVAL; goto err; } +#ifdef CONFIG_ANDROID_THINGS_SUPPORT + /* + * fastboot host end implement to get data in one bulk package so need + * large buffer for the "fastboot upload" and "fastboot get_staged". + */ + if (f_fb->in_req->buf) + free(f_fb->in_req->buf); + f_fb->in_req->buf = memalign(CONFIG_SYS_CACHELINE_SIZE, EP_BUFFER_SIZE * 32); +#endif f_fb->in_req->complete = fastboot_complete; for (i = 0; i < MAX_REQ_NUM; i++) { @@ -2576,6 +2585,25 @@ static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req) usb_ep_queue(ep, req, 0); } +static void cb_upload(struct usb_ep *ep, struct usb_request *req) +{ + char response[FASTBOOT_RESPONSE_LEN]; + + if (!download_bytes || download_bytes > (EP_BUFFER_SIZE * 32)) { + sprintf(response, "FAIL"); + fastboot_tx_write_str(response); + return; + } + + printf("Will upload %d bytes.\n", download_bytes); + snprintf(response, FASTBOOT_RESPONSE_LEN, "DATA%08x", download_bytes); + fastboot_tx_write_str(response); + + fastboot_tx_write((const char *)(interface.transfer_buffer), download_bytes); + + snprintf(response,FASTBOOT_RESPONSE_LEN, "OKAY"); + fastboot_tx_write_str(response); +} static void cb_download(struct usb_ep *ep, struct usb_request *req) { char *cmd = req->buf; @@ -2932,6 +2960,9 @@ static const struct cmd_dispatch_info cmd_dispatch_info[] = { }, { .cmd = "getvar:", .cb = cb_getvar, + }, { + .cmd = "upload", + .cb = cb_upload, }, { .cmd = "download:", .cb = cb_download, -- 2.17.1