diff --git a/src/dfuse.c b/src/dfuse.c index 2f8530e..eb321bf 100644 --- a/src/dfuse.c +++ b/src/dfuse.c @@ -322,6 +322,17 @@ static int dfuse_dnload_chunk(struct dfu_if *dif, unsigned char *data, int size, return bytes_sent; } +static void dfuse_do_leave(struct dfu_if *dif) +{ + if (dfuse_address_present) + dfuse_special_command(dif, dfuse_address, SET_ADDRESS); + if (dif->quirks & QUIRK_DFUSE_LEAVE) + /* leave without DFU_GETSTATUS */ + dfuse_download(dif, 0, NULL, 2); + else + dfuse_dnload_chunk(dif, NULL, 0, 2); +} + int dfuse_do_upload(struct dfu_if *dif, int xfer_size, int fd, const char *dfuse_options) { @@ -407,11 +418,8 @@ int dfuse_do_upload(struct dfu_if *dif, int xfer_size, int fd, dfu_progress_bar("Upload", total_bytes, total_bytes); dfu_abort_to_idle(dif); - if (dfuse_leave) { - if (dfuse_address_present) - dfuse_special_command(dif, dfuse_address, SET_ADDRESS); - dfuse_dnload_chunk(dif, NULL, 0, 2); /* Zero-size */ - } + if (dfuse_leave) + dfuse_do_leave(dif); out_free: free(buf); @@ -729,10 +737,8 @@ int dfuse_do_dnload(struct dfu_if *dif, int xfer_size, struct dfu_file *file, dfu_abort_to_idle(dif); } - if (dfuse_leave) { - if (dfuse_address_present) - dfuse_special_command(dif, dfuse_address, SET_ADDRESS); - dfuse_dnload_chunk(dif, NULL, 0, 2); /* Zero-size */ - } + if (dfuse_leave) + dfuse_do_leave(dif); + return ret; } diff --git a/src/quirks.c b/src/quirks.c index ee0964d..eec9ef9 100755 --- a/src/quirks.c +++ b/src/quirks.c @@ -63,11 +63,13 @@ uint16_t get_quirks(uint16_t vendor, uint16_t product, uint16_t bcdDevice) quirks |= QUIRK_POLLTIMEOUT; /* Some GigaDevice GD32 devices have improperly-encoded serial numbers - * and bad DfuSe descriptors which we use serial number to correct. */ + * and bad DfuSe descriptors which we use serial number to correct. + * They also "leave" without a DFU_GETSTATUS request */ if (vendor == VENDOR_GIGADEVICE && product == PRODUCT_GD32) { quirks |= QUIRK_UTF8_SERIAL; quirks |= QUIRK_DFUSE_LAYOUT; + quirks |= QUIRK_DFUSE_LEAVE; } return (quirks); diff --git a/src/quirks.h b/src/quirks.h index 0a1d612..9f0dc4f 100755 --- a/src/quirks.h +++ b/src/quirks.h @@ -27,6 +27,7 @@ #define QUIRK_FORCE_DFU11 (1<<1) #define QUIRK_UTF8_SERIAL (1<<2) #define QUIRK_DFUSE_LAYOUT (1<<3) +#define QUIRK_DFUSE_LEAVE (1<<4) /* Fallback value, works for OpenMoko */ #define DEFAULT_POLLTIMEOUT 5