]> git.sur5r.net Git - u-boot/blobdiff - drivers/usb/gadget/f_fastboot.c
Merge branch 'master' of git://git.denx.de/u-boot-mpc85xx
[u-boot] / drivers / usb / gadget / f_fastboot.c
index 38c09658cc6aa54e9c41d434849aa31d842cdfa1..71b62e5005a12915a164acb74335b4cad6828e4b 100644 (file)
@@ -351,10 +351,11 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req)
                strncat(response, FASTBOOT_VERSION, chars_left);
        } else if (!strcmp_l1("bootloader-version", cmd)) {
                strncat(response, U_BOOT_VERSION, chars_left);
-       } else if (!strcmp_l1("downloadsize", cmd)) {
+       } else if (!strcmp_l1("downloadsize", cmd) ||
+               !strcmp_l1("max-download-size", cmd)) {
                char str_num[12];
 
-               sprintf(str_num, "%08x", CONFIG_USB_FASTBOOT_BUF_SIZE);
+               sprintf(str_num, "0x%08x", CONFIG_USB_FASTBOOT_BUF_SIZE);
                strncat(response, str_num, chars_left);
        } else if (!strcmp_l1("serialno", cmd)) {
                s = getenv("serial#");
@@ -386,6 +387,7 @@ static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req)
        unsigned int transfer_size = download_size - download_bytes;
        const unsigned char *buffer = req->buf;
        unsigned int buffer_size = req->actual;
+       unsigned int pre_dot_num, now_dot_num;
 
        if (req->status != 0) {
                printf("Bad status: %d\n", req->status);
@@ -398,7 +400,15 @@ static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req)
        memcpy((void *)CONFIG_USB_FASTBOOT_BUF_ADDR + download_bytes,
               buffer, transfer_size);
 
+       pre_dot_num = download_bytes / BYTES_PER_DOT;
        download_bytes += transfer_size;
+       now_dot_num = download_bytes / BYTES_PER_DOT;
+
+       if (pre_dot_num != now_dot_num) {
+               putc('.');
+               if (!(now_dot_num % 74))
+                       putc('\n');
+       }
 
        /* Check if transfer is done */
        if (download_bytes >= download_size) {
@@ -420,11 +430,6 @@ static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req)
                        req->length = ep->maxpacket;
        }
 
-       if (download_bytes && !(download_bytes % BYTES_PER_DOT)) {
-               putc('.');
-               if (!(download_bytes % (74 * BYTES_PER_DOT)))
-                       putc('\n');
-       }
        req->actual = 0;
        usb_ep_queue(ep, req, 0);
 }
@@ -541,7 +546,14 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
                error("unknown command: %s\n", cmdbuf);
                fastboot_tx_write_str("FAILunknown command");
        } else {
-               func_cb(ep, req);
+               if (req->actual < req->length) {
+                       u8 *buf = (u8 *)req->buf;
+                       buf[req->actual] = 0;
+                       func_cb(ep, req);
+               } else {
+                       error("buffer overflow\n");
+                       fastboot_tx_write_str("FAILbuffer overflow");
+               }
        }
 
        if (req->status == 0) {