Skip to content

Commit

Permalink
Tidy up DFU status and related reporting
Browse files Browse the repository at this point in the history
Report status with the text from the DFU specification.

Signed-off-by: Tormod Volden <[email protected]>
  • Loading branch information
tormodvolden committed Feb 7, 2021
1 parent c69c644 commit 4dfa0f2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/dfu_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ int dfuload_do_dnload(struct dfu_if *dif, int xfer_size, struct dfu_file *file)

if (dst.bStatus != DFU_STATUS_OK) {
printf(" failed!\n");
printf("state(%u) = %s, status(%u) = %s\n", dst.bState,
printf("DFU state(%u) = %s, status(%u) = %s\n", dst.bState,
dfu_state_to_string(dst.bState), dst.bStatus,
dfu_status_to_string(dst.bStatus));
ret = -1;
Expand Down Expand Up @@ -185,7 +185,7 @@ int dfuload_do_dnload(struct dfu_if *dif, int xfer_size, struct dfu_file *file)
libusb_error_name(ret));
goto out;
}
printf("state(%u) = %s, status(%u) = %s\n", dst.bState,
printf("DFU state(%u) = %s, status(%u) = %s\n", dst.bState,
dfu_state_to_string(dst.bState), dst.bStatus,
dfu_status_to_string(dst.bStatus));

Expand Down
6 changes: 3 additions & 3 deletions src/dfuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ static int dfuse_special_command(struct dfu_if *dif, unsigned int address,
if (firstpoll) {
firstpoll = 0;
if (dst.bState != DFU_STATE_dfuDNBUSY) {
fprintf(stderr, "state(%u) = %s, status(%u) = %s\n", dst.bState,
fprintf(stderr, "DFU state(%u) = %s, status(%u) = %s\n", dst.bState,
dfu_state_to_string(dst.bState), dst.bStatus,
dfu_status_to_string(dst.bStatus));
errx(EX_PROTOCOL, "Wrong state after command \"%s\" download",
Expand Down Expand Up @@ -313,8 +313,8 @@ static int dfuse_dnload_chunk(struct dfu_if *dif, unsigned char *data, int size,
printf("Transitioning to dfuMANIFEST state\n");

if (dst.bStatus != DFU_STATUS_OK) {
fprintf(stderr, " failed!\n");
fprintf(stderr, "state(%u) = %s, status(%u) = %s\n", dst.bState,
printf(" failed!\n");
fprintf(stderr, "DFU state(%u) = %s, status(%u) = %s\n", dst.bState,
dfu_state_to_string(dst.bState), dst.bStatus,
dfu_status_to_string(dst.bStatus));
return -1;
Expand Down
25 changes: 12 additions & 13 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ int main(int argc, char **argv)
if (ret || !dfu_root->dev_handle)
errx(EX_IOERR, "Cannot open device: %s", libusb_error_name(ret));

printf("ID %04x:%04x\n", dfu_root->vendor, dfu_root->product);
printf("Device ID %04x:%04x\n", dfu_root->vendor, dfu_root->product);

/* If first interface is DFU it is likely not proper run-time */
if (dfu_root->interface > 0)
Expand Down Expand Up @@ -488,8 +488,7 @@ int main(int argc, char **argv)
}
}

printf("Determining device status: ");

printf("Determining device status...\n");
err = dfu_get_status(dfu_root, &status);
if (err == LIBUSB_ERROR_PIPE) {
printf("Device does not implement get_status, assuming appIDLE\n");
Expand All @@ -498,10 +497,11 @@ int main(int argc, char **argv)
status.bState = DFU_STATE_appIDLE;
status.iString = 0;
} else if (err < 0) {
errx(EX_IOERR, "error get_status");
errx(EX_IOERR, "error get_status: %s", libusb_error_name(err));
} else {
printf("state = %s, status = %d\n",
dfu_state_to_string(status.bState), status.bStatus);
printf("DFU state(%u) = %s, status(%u) = %s\n", status.bState,
dfu_state_to_string(status.bState), status.bStatus,
dfu_status_to_string(status.bStatus));
}
milli_sleep(status.bwPollTimeout);

Expand Down Expand Up @@ -608,13 +608,14 @@ int main(int argc, char **argv)
}

status_again:
printf("Determining device status: ");
printf("Determining device status...\n");
ret = dfu_get_status(dfu_root, &status );
if (ret < 0) {
errx(EX_IOERR, "error get_status: %s", libusb_error_name(ret));
}
printf("state = %s, status = %d\n",
dfu_state_to_string(status.bState), status.bStatus);
printf("DFU state(%u) = %s, status(%u) = %s\n", status.bState,
dfu_state_to_string(status.bState), status.bStatus,
dfu_status_to_string(status.bStatus));

milli_sleep(status.bwPollTimeout);

Expand All @@ -624,23 +625,21 @@ int main(int argc, char **argv)
errx(EX_PROTOCOL, "Device still in Run-Time Mode!");
break;
case DFU_STATE_dfuERROR:
printf("dfuERROR, clearing status\n");
printf("Clearing status\n");
if (dfu_clear_status(dfu_root->dev_handle, dfu_root->interface) < 0) {
errx(EX_IOERR, "error clear_status");
}
goto status_again;
break;
case DFU_STATE_dfuDNLOAD_IDLE:
case DFU_STATE_dfuUPLOAD_IDLE:
printf("aborting previous incomplete transfer\n");
printf("Aborting previous incomplete transfer\n");
if (dfu_abort(dfu_root->dev_handle, dfu_root->interface) < 0) {
errx(EX_IOERR, "can't send DFU_ABORT");
}
goto status_again;
break;
case DFU_STATE_dfuIDLE:
printf("dfuIDLE, continuing\n");
break;
default:
break;
}
Expand Down

0 comments on commit 4dfa0f2

Please sign in to comment.