]> git.proxmox.com Git - grub2.git/commitdiff
Split long USB transfers into short ones.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 20 Jan 2013 21:45:53 +0000 (22:45 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 20 Jan 2013 21:45:53 +0000 (22:45 +0100)
ChangeLog
grub-core/bus/usb/usbtrans.c
include/grub/usbtrans.h

index 4d09825e58f418e0e182ebd4d455f2a3f6447ae2..c8edf734c468d2b3ef22361437207ee7ba720465 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2013-01-20  Aleš Nesrsta  <starous@volny.cz>
+
+       Split long USB transfers into short ones.
+
 2013-01-20  Andrey Borzenkov <arvidjaar@gmail.com>
 
        * docs/grub.texi (Simple configuration): Clarify GRUB_HIDDEN_TIMEOUT
index 167fae5a28b9168f1c432cadecf1571def72d3cb..154c72d55f9ac33d8cba71ca31f88afcfeb80e55 100644 (file)
@@ -351,11 +351,23 @@ grub_usb_err_t
 grub_usb_bulk_read (grub_usb_device_t dev,
                    int endpoint, grub_size_t size, char *data)
 {
-  grub_size_t actual;
+  grub_size_t actual, transferred;
   grub_usb_err_t err;
-  err = grub_usb_bulk_readwrite (dev, endpoint, size, data,
-                                GRUB_USB_TRANSFER_TYPE_IN, 1000, &actual);
-  if (!err && actual != size)
+  grub_size_t current_size, position;
+
+  for (position = 0, transferred = 0;
+       position < size; position += MAX_USB_TRANSFER_LEN)
+    {
+      current_size = size - position;
+      if (current_size >= MAX_USB_TRANSFER_LEN)
+       current_size = MAX_USB_TRANSFER_LEN;
+      err = grub_usb_bulk_readwrite (dev, endpoint, current_size,
+              &data[position], GRUB_USB_TRANSFER_TYPE_IN, 1000, &actual);
+      transferred += actual;
+      if (err || (current_size != actual) ) break;
+    }
+
+  if (!err && transferred != size)
     err = GRUB_USB_ERR_DATA;
   return err;
 }
index 5ee276d263617635ca7b2ba03b20e3d8736eb9a8..5429007d04ff10ee296e948553d91cd6ad1c68a0 100644 (file)
@@ -19,6 +19,8 @@
 #ifndef        GRUB_USBTRANS_H
 #define        GRUB_USBTRANS_H 1
 
+#define MAX_USB_TRANSFER_LEN 0x0800
+
 typedef enum
   {
     GRUB_USB_TRANSFER_TYPE_IN,