From d3e860b07577a198e6b4f17e9cb9a1330d635ea3 Mon Sep 17 00:00:00 2001 From: Bernhard Nortmann Date: Fri, 11 Nov 2016 21:39:10 +0100 Subject: [PATCH] fel: Lower timeout to a more practical value The previous timeout of 60 seconds was mostly based on scenarios where large ("write") transfers take place. But it could easily become annoying if users are awaiting completion of simpler commands like "read" or "hexdump", and for some reason FEL fails to respond. Therefore I've decided to lower the timeout value to 10 seconds, adjust the maximum chunk size accordingly and - while at it - improve the source comments documenting their relationship. Signed-off-by: Bernhard Nortmann --- fel.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/fel.c b/fel.c index 46d079a..9b47d3d 100644 --- a/fel.c +++ b/fel.c @@ -77,7 +77,8 @@ static const int AW_USB_WRITE = 0x12; static int AW_USB_FEL_BULK_EP_OUT; static int AW_USB_FEL_BULK_EP_IN; -static int timeout = 60000; +static int timeout = 10000; /* 10 seconds */ + static bool verbose = false; /* If set, makes the 'fel' tool more talkative */ static uint32_t uboot_entry = 0; /* entry point (address) of U-Boot */ static uint32_t uboot_size = 0; /* size of U-Boot binary */ @@ -92,7 +93,16 @@ static void pr_info(const char *fmt, ...) } } -static const int AW_USB_MAX_BULK_SEND = 4 * 1024 * 1024; /* 4 MiB per bulk request */ +/* + * AW_USB_MAX_BULK_SEND and the timeout constant are related. + * Both need to be selected in a way that transferring the maximum chunk size + * with (SoC-specific) slow transfer speed won't time out. + * + * The 512 KiB here are chosen based on the assumption that we want a 10 seconds + * timeout, and "slow" transfers take place at approx. 64 KiB/sec - so we can + * expect the maximum chunk being transmitted within 8 seconds or less. + */ +static const int AW_USB_MAX_BULK_SEND = 512 * 1024; /* 512 KiB per bulk request */ void usb_bulk_send(libusb_device_handle *usb, int ep, const void *data, size_t length, bool progress) @@ -101,6 +111,7 @@ void usb_bulk_send(libusb_device_handle *usb, int ep, const void *data, * With no progress notifications, we'll use the maximum chunk size. * Otherwise, it's useful to lower the size (have more chunks) to get * more frequent status updates. 128 KiB per request seem suitable. + * (Worst case of "slow" transfers -> one update every two seconds.) */ size_t max_chunk = progress ? 128 * 1024 : AW_USB_MAX_BULK_SEND;