[PATCH] dfu-util: Don't sleep unnecessarily

Bernard Blackham b-openmoko at largestprime.net
Wed Mar 9 06:49:42 CET 2011


The DFU spec says that bwPollTimeout is the amount of time that
should pass between DFU_GETSTATUS requests. If the status is already
good, we do not need to sleep as we will not poll again.

This speeds up DFU downloads directly into memory.

Signed-off-by: Bernard Blackham <b-openmoko at largestprime.net>

diff --git a/src/dfu_load.c b/src/dfu_load.c
index 3a4f382..f6dc8ce 100644
--- a/src/dfu_load.c
+++ b/src/dfu_load.c
@@ -163,14 +163,18 @@ int dfuload_do_dnload(struct usb_dev_handle *usb_handle, int interface,
 				fprintf(stderr, "Error during download get_status\n");
 				goto out_close;
 			}
+
+			if (dst.bState == DFU_STATE_dfuDNLOAD_IDLE ||
+					dst.bState == DFU_STATE_dfuERROR)
+				break;
+
 			/* Wait while device executes flashing */
 			if (quirks & QUIRK_POLLTIMEOUT)
 				usleep(DEFAULT_POLLTIMEOUT * 1000);
 			else
 				usleep(dst.bwPollTimeout * 1000);
 
-		} while (dst.bState != DFU_STATE_dfuDNLOAD_IDLE &&
-			 dst.bState != DFU_STATE_dfuERROR);
+		} while (1);
 		if (dst.bStatus != DFU_STATUS_OK) {
 			printf(" failed!\n");
 			printf("state(%u) = %s, status(%u) = %s\n", dst.bState,



More information about the devel mailing list