summaryrefslogtreecommitdiffstats
path: root/fastboot/usb_linux.c
diff options
context:
space:
mode:
authorDan Murphy <D.Murphy@motorola.com>2009-08-18 09:41:09 -0500
committerMike Lockwood <lockwood@android.com>2009-08-19 14:32:01 -0400
commitb2de4db941f5329f9f19e70feff5786b2d5acbb6 (patch)
tree3d1898a9d3e606710dff58ac2990ad5a7b35427e /fastboot/usb_linux.c
parent761aeb431e6d1482754a98bba2b683ba8111ef88 (diff)
downloadsystem_core-b2de4db941f5329f9f19e70feff5786b2d5acbb6.zip
system_core-b2de4db941f5329f9f19e70feff5786b2d5acbb6.tar.gz
system_core-b2de4db941f5329f9f19e70feff5786b2d5acbb6.tar.bz2
fastboot: Add retry to USB read call.
If the USB connection to the device is reset but is still there the code should retry to re-connect the device and continue. This is a short term fix for a bootloader issue. We should revisit and look for a better solution. Signed-off-by: Dan Murphy <D.Murphy@motorola.com> Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'fastboot/usb_linux.c')
-rw-r--r--fastboot/usb_linux.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/fastboot/usb_linux.c b/fastboot/usb_linux.c
index 06c62b8..3b40ba7 100644
--- a/fastboot/usb_linux.c
+++ b/fastboot/usb_linux.c
@@ -51,7 +51,9 @@
#include "usb.h"
-#if TRACE_USB
+#define MAX_RETRIES 5
+
+#ifdef TRACE_USB
#define DBG1(x...) fprintf(stderr, x)
#define DBG(x...) fprintf(stderr, x)
#else
@@ -303,7 +305,7 @@ int usb_read(usb_handle *h, void *_data, int len)
unsigned char *data = (unsigned char*) _data;
unsigned count = 0;
struct usbdevfs_bulktransfer bulk;
- int n;
+ int n, retry;
if(h->ep_in == 0) {
return -1;
@@ -316,16 +318,20 @@ int usb_read(usb_handle *h, void *_data, int len)
bulk.len = xfer;
bulk.data = data;
bulk.timeout = 0;
-
- DBG("[ usb read %d fd = %d], fname=%s\n", xfer, h->desc, h->fname);
- n = ioctl(h->desc, USBDEVFS_BULK, &bulk);
- DBG("[ usb read %d ] = %d, fname=%s\n", xfer, n, h->fname);
-
- if(n < 0) {
- DBG1("ERROR: n = %d, errno = %d (%s)\n",
- n, errno, strerror(errno));
- return -1;
+ retry = 0;
+
+ do{
+ DBG("[ usb read %d fd = %d], fname=%s\n", xfer, h->desc, h->fname);
+ n = ioctl(h->desc, USBDEVFS_BULK, &bulk);
+ DBG("[ usb read %d ] = %d, fname=%s, Retry %d \n", xfer, n, h->fname, retry);
+
+ if( n < 0 ) {
+ DBG1("ERROR: n = %d, errno = %d (%s)\n",n, errno, strerror(errno));
+ if ( ++retry > MAX_RETRIES ) return -1;
+ sleep( 1 );
+ }
}
+ while( n < 0 );
count += n;
len -= n;