Skip to content

Commit

Permalink
Enlarge USB bulk transfer size for faster downloads
Browse files Browse the repository at this point in the history
The default USB transfer bulk is fixed as 4096 in fastboot util code for
Windows and Linux. Enlarging the bulk size can greatly improve the image
download speed via USB.

For Windows, adjust the max bulk size to 1MB to maximize the USB transfer
speed. With this change, the USB transfer speed can be doubled to 20MB/s.

For Linux, adjust the max bulk size to 16384 to maximize the USB transfer
speed according to MAX_USBFS_BUFFER_SIZE definition in drivers/usb/core/devio.c.

For OSX, the maxLenToSend is already 1MB in code.

Change-Id: If6af8c6301f6f6c2ef345e37241706f16d8f5cda
  • Loading branch information
David Krause committed Mar 28, 2011
1 parent 7c55654 commit 913eb8b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions fastboot/usb_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
#define DBG1(x...)
#endif

/* The max bulk size for linux is 16384 which is defined
* in drivers/usb/core/devio.c.
*/
#define MAX_USBFS_BULK_SIZE (16 * 1024)

struct usb_handle
{
char fname[64];
Expand Down Expand Up @@ -289,7 +294,7 @@ int usb_write(usb_handle *h, const void *_data, int len)

while(len > 0) {
int xfer;
xfer = (len > 4096) ? 4096 : len;
xfer = (len > MAX_USBFS_BULK_SIZE) ? MAX_USBFS_BULK_SIZE : len;

bulk.ep = h->ep_out;
bulk.len = xfer;
Expand Down Expand Up @@ -323,7 +328,7 @@ int usb_read(usb_handle *h, void *_data, int len)
}

while(len > 0) {
int xfer = (len > 4096) ? 4096 : len;
int xfer = (len > MAX_USBFS_BULK_SIZE) ? MAX_USBFS_BULK_SIZE : len;

bulk.ep = h->ep_in;
bulk.len = xfer;
Expand Down
5 changes: 3 additions & 2 deletions fastboot/usb_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#define DBG(x...)
#endif

#define MAX_USBFS_BULK_SIZE (1024 * 1024)

/** Structure usb_handle describes our connection to the usb device via
AdbWinApi.dll. This structure is returned from usb_open() routine and
Expand Down Expand Up @@ -160,7 +161,7 @@ int usb_write(usb_handle* handle, const void* data, int len) {
if (NULL != handle) {
// Perform write
while(len > 0) {
int xfer = (len > 4096) ? 4096 : len;
int xfer = (len > MAX_USBFS_BULK_SIZE) ? MAX_USBFS_BULK_SIZE : len;
ret = AdbWriteEndpointSync(handle->adb_write_pipe,
(void*)data,
(unsigned long)xfer,
Expand Down Expand Up @@ -200,7 +201,7 @@ int usb_read(usb_handle *handle, void* data, int len) {
DBG("usb_read %d\n", len);
if (NULL != handle) {
while (1) {
int xfer = (len > 4096) ? 4096 : len;
int xfer = (len > MAX_USBFS_BULK_SIZE) ? MAX_USBFS_BULK_SIZE : len;

ret = AdbReadEndpointSync(handle->adb_read_pipe,
(void*)data,
Expand Down

0 comments on commit 913eb8b

Please sign in to comment.