Skip to content

Commit

Permalink
Add quirk for GD32 leave request without DFU_GETSTATUS
Browse files Browse the repository at this point in the history
ST's document AN3156 is ambiguous about this, and their own
devices require a DFU_GETSTATUS request, however GD decided
to not use one and instead leave immediately.

https://sourceforge.net/p/dfu-util/tickets/104/

Signed-off-by: Tormod Volden <[email protected]>
  • Loading branch information
tormodvolden committed Feb 7, 2021
1 parent ff17547 commit c66695c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
26 changes: 16 additions & 10 deletions src/dfuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
4 changes: 3 additions & 1 deletion src/quirks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/quirks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c66695c

Please sign in to comment.