r1123 - trunk/src/host/dfu-util/src
laforge at sita.openmoko.org
laforge at sita.openmoko.org
Sun Feb 25 21:35:04 CET 2007
Author: laforge
Date: 2007-02-25 21:35:03 +0100 (Sun, 25 Feb 2007)
New Revision: 1123
Modified:
trunk/src/host/dfu-util/src/main.c
trunk/src/host/dfu-util/src/sam7dfu.c
Log:
* add explicit 'Reset after transfer' switch (--reset -R)
* correctly implement MANIFEST/MANIFEST_SYNC/IDLE stat transition after transfer
Modified: trunk/src/host/dfu-util/src/main.c
===================================================================
--- trunk/src/host/dfu-util/src/main.c 2007-02-25 20:34:15 UTC (rev 1122)
+++ trunk/src/host/dfu-util/src/main.c 2007-02-25 20:35:03 UTC (rev 1123)
@@ -264,6 +264,7 @@
" -t --transfer-size\t\tSpecify the number of bytes per USB Transfer\n"
" -U --upload file\t\tRead firmware from device into <file>\n"
" -D --download file\t\tWrite firmware from <file> into device\n"
+ " -R --reset\t\t\tIssue USB Reset signalling once we're finished\n"
);
}
@@ -282,6 +283,7 @@
{ "transfer-size", 1, 0, 't' },
{ "upload", 1, 0, 'U' },
{ "download", 1, 0, 'D' },
+ { "reset", 1, 0, 'R' },
};
enum mode {
@@ -301,6 +303,7 @@
struct dfu_status status;
struct usb_dfu_func_descriptor func_dfu;
char *filename = NULL;
+ int final_reset = 0;
printf("dfu-util - (C) 2007 by OpenMoko Inc.\n"
"This program is Free Software and has ABSOLUTELY NO WARRANTY\n\n");
@@ -314,7 +317,7 @@
while (1) {
int c, option_index = 0;
- c = getopt_long(argc, argv, "hVvld:c:i:a:t:U:D:", opts, &option_index);
+ c = getopt_long(argc, argv, "hVvld:c:i:a:t:U:D:R", opts, &option_index);
if (c == -1)
break;
@@ -369,6 +372,9 @@
mode = MODE_DOWNLOAD;
filename = optarg;
break;
+ case 'R':
+ final_reset = 1;
+ break;
default:
help();
exit(2);
@@ -442,7 +448,8 @@
printf("state = %s, status = %d\n", dfu_state_to_string(status.bState), status.bStatus);
switch (status.bState) {
- case STATE_APP_IDLE:
+ case DFU_STATE_appIDLE:
+ case DFU_STATE_appDETACH:
printf("Device really in Runtime Mode, send DFU detach request...\n");
if (dfu_detach(_rt_dif.dev_handle, _rt_dif.interface, 1000) < 0) {
fprintf(stderr, "error detaching: %s\n", usb_strerror());
@@ -455,7 +462,7 @@
}
sleep(2);
break;
- case STATE_DFU_ERROR:
+ case DFU_STATE_dfuERROR:
printf("dfuERROR, clearing status\n");
if (dfu_clear_status(_rt_dif.dev_handle, _rt_dif.interface) < 0) {
fprintf(stderr, "error clear_status: %s\n", usb_strerror());
@@ -463,9 +470,9 @@
break;
}
break;
- case STATE_DFU_IDLE:
- printf("Device already in dfuIDLE ?!?, continuing\n");
- goto already_idle;
+ default:
+ printf(stderr, "IMPOSSIBLE: Runtime device already in DFU state ?!?\n");
+ exit(1);
break;
}
@@ -497,7 +504,6 @@
* procedure */
}
-already_idle:
num_ifs = count_dfu_interfaces(dif->dev);
if (num_ifs < 0) {
fprintf(stderr, "No DFU Interface after RESET?!?\n");
@@ -522,7 +528,6 @@
}
#endif
printf("Claiming USB DFU Interface...\n");
- printf("%p (%d)\n", dif->dev_handle, *(int *)dif->dev_handle);
if (usb_claim_interface(dif->dev_handle, dif->interface) < 0) {
fprintf(stderr, "Cannot claim interface: %s\n", usb_strerror());
exit(1);
@@ -619,6 +624,17 @@
exit(1);
}
+ if (final_reset) {
+ if (dfu_detach(dif->dev_handle, dif->interface, 1000) < 0) {
+ fprintf("can't detach: %s\n", usb_strerror());
+ }
+ printf("Resetting USB to swithc back to runtime mode\n");
+ if (usb_reset(dif->dev_handle) < 0) {
+ fprintf(stderr, "error resetting after download: %s\n",
+ usb_strerror());
+ }
+ }
+
exit(0);
}
Modified: trunk/src/host/dfu-util/src/sam7dfu.c
===================================================================
--- trunk/src/host/dfu-util/src/sam7dfu.c 2007-02-25 20:34:15 UTC (rev 1122)
+++ trunk/src/host/dfu-util/src/sam7dfu.c 2007-02-25 20:35:03 UTC (rev 1123)
@@ -117,19 +117,33 @@
printf("] finished!\n");
+get_status:
/* Transition to MANIFEST_SYNC state */
ret = dfu_get_status(usb_handle, interface, &dst);
if (ret < 0) {
- fprintf(stderr, "unable to transition to MANIFEST state\n");
+ fprintf(stderr, "unable to read DFU status\n");
goto out_close;
}
-
+ printf("state(%u) = %s, status(%u) = %s\n", dst.bState,
+ dfu_state_to_string(dst.bState), dst.bStatus,
+ dfu_status_to_string(dst.bStatus));
+
+ /* FIXME: deal correctly with ManifestationTolerant=0 / WillDetach bits */
+ switch (dst.bState) {
+ case DFU_STATE_dfuMANIFEST_SYNC:
+ case DFU_STATE_dfuMANIFEST:
+ goto get_status;
+ break;
+ case DFU_STATE_dfuIDLE:
+ break;
+ }
+#if 0
printf("Resetting USB...\n");
- sleep(1);
if (usb_reset(usb_handle) < 0) {
fprintf(stderr, "error resetting after download: %s\n",
usb_strerror());
}
+#endif
printf("Done!\n");
out_close:
close(fd);
More information about the commitlog
mailing list