[iot] fastboot:Add 'get_staged' command support
authorHaoran Wang <elven.wang@nxp.com>
Wed, 25 Oct 2017 10:08:42 +0000 (18:08 +0800)
committerLuo Ji <ji.luo@nxp.com>
Thu, 25 Jan 2018 11:38:53 +0000 (19:38 +0800)
When host end execute "fastboot get_staged [ <outfile> ]"
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 <elven.wang@nxp.com>
drivers/usb/gadget/f_fastboot.c

index d14c4a8..8fb21bf 100755 (executable)
@@ -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,