]> git.sur5r.net Git - u-boot/blobdiff - drivers/usb/gadget/f_fastboot.c
usb: spear: Add support for both SPEAr600 EHCI controllers
[u-boot] / drivers / usb / gadget / f_fastboot.c
index 751ec9e010795079a0d8c601026b0c7071f7a2fa..ca01a018b5d13578a3fa36d1681f6818a30bb2b8 100644 (file)
@@ -123,6 +123,7 @@ static struct usb_gadget_strings *fastboot_strings[] = {
 };
 
 static void rx_handler_command(struct usb_ep *ep, struct usb_request *req);
+static int strcmp_l1(const char *s1, const char *s2);
 
 static void fastboot_complete(struct usb_ep *ep, struct usb_request *req)
 {
@@ -310,6 +311,9 @@ static int fastboot_tx_write(const char *buffer, unsigned int buffer_size)
 
        memcpy(in_req->buf, buffer, buffer_size);
        in_req->length = buffer_size;
+
+       usb_ep_dequeue(fastboot_func->in_ep, in_req);
+
        ret = usb_ep_queue(fastboot_func->in_ep, in_req, 0);
        if (ret)
                printf("Error %d on queue\n", ret);
@@ -326,8 +330,20 @@ static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
        do_reset(NULL, 0, 0, NULL);
 }
 
+int __weak fb_set_reboot_flag(void)
+{
+       return -ENOSYS;
+}
+
 static void cb_reboot(struct usb_ep *ep, struct usb_request *req)
 {
+       char *cmd = req->buf;
+       if (!strcmp_l1("reboot-bootloader", cmd)) {
+               if (fb_set_reboot_flag()) {
+                       fastboot_tx_write_str("FAILCannot set reboot flag");
+                       return;
+               }
+       }
        fastboot_func->in_req->complete = compl_do_reset;
        fastboot_tx_write_str("OKAY");
 }
@@ -364,7 +380,7 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req)
                !strcmp_l1("max-download-size", cmd)) {
                char str_num[12];
 
-               sprintf(str_num, "0x%08x", CONFIG_USB_FASTBOOT_BUF_SIZE);
+               sprintf(str_num, "0x%08x", CONFIG_FASTBOOT_BUF_SIZE);
                strncat(response, str_num, chars_left);
        } else if (!strcmp_l1("serialno", cmd)) {
                s = getenv("serial#");
@@ -414,7 +430,7 @@ static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req)
        if (buffer_size < transfer_size)
                transfer_size = buffer_size;
 
-       memcpy((void *)CONFIG_USB_FASTBOOT_BUF_ADDR + download_bytes,
+       memcpy((void *)CONFIG_FASTBOOT_BUF_ADDR + download_bytes,
               buffer, transfer_size);
 
        pre_dot_num = download_bytes / BYTES_PER_DOT;
@@ -467,7 +483,7 @@ static void cb_download(struct usb_ep *ep, struct usb_request *req)
 
        if (0 == download_size) {
                sprintf(response, "FAILdata invalid size");
-       } else if (download_size > CONFIG_USB_FASTBOOT_BUF_SIZE) {
+       } else if (download_size > CONFIG_FASTBOOT_BUF_SIZE) {
                download_size = 0;
                sprintf(response, "FAILdata too large");
        } else {
@@ -528,7 +544,7 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req)
 
        strcpy(response, "FAILno flash device defined");
 #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
-       fb_mmc_flash_write(cmd, (void *)CONFIG_USB_FASTBOOT_BUF_ADDR,
+       fb_mmc_flash_write(cmd, (void *)CONFIG_FASTBOOT_BUF_ADDR,
                           download_bytes, response);
 #endif
        fastboot_tx_write_str(response);
@@ -622,6 +638,9 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
        void (*func_cb)(struct usb_ep *ep, struct usb_request *req) = NULL;
        int i;
 
+       if (req->status != 0 || req->length == 0)
+               return;
+
        for (i = 0; i < ARRAY_SIZE(cmd_dispatch_info); i++) {
                if (!strcmp_l1(cmd_dispatch_info[i].cmd, cmdbuf)) {
                        func_cb = cmd_dispatch_info[i].cb;
@@ -643,9 +662,7 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
                }
        }
 
-       if (req->status == 0) {
-               *cmdbuf = '\0';
-               req->actual = 0;
-               usb_ep_queue(ep, req, 0);
-       }
+       *cmdbuf = '\0';
+       req->actual = 0;
+       usb_ep_queue(ep, req, 0);
 }