From: Tormod Volden <debian.tor...@gmail.com>

If the device has the bitWillDetach set it will detach and reattach
itself to the USB bus after receiving the DETACH request, and the
host computer should not issue a USB reset.

Also make sure the descriptor structures containing these
flags are initialized to zero, for the case where the
descriptor can not be retrieved from the device.

---

This should theoretically be as simple as that. I do not know of any
devices that have the bitWillDetach set and can not test it. But
we should get this in and see if someone can test it. On success,
we can update the documentation to say we support DFU 1.1 as well.

Tormod

 src/main.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/main.c b/src/main.c
index b9e11c0..debbce8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -594,7 +594,7 @@ int main(int argc, char **argv)
        unsigned int host_page_size;
        enum mode mode = MODE_NONE;
        struct dfu_status status;
-       struct usb_dfu_func_descriptor func_dfu, func_dfu_rt;
+       struct usb_dfu_func_descriptor func_dfu = {0}, func_dfu_rt = {0};
        libusb_context *ctx;
        struct dfu_file file;
        char *alt_name = NULL; /* query alt name if non-NULL */
@@ -821,10 +821,15 @@ int main(int argc, char **argv)
                        }
                        libusb_release_interface(_rt_dif.dev_handle,
                                                 _rt_dif.interface);
-                       printf("Resetting USB...\n");
-                       ret = libusb_reset_device(_rt_dif.dev_handle);
-                       if (ret < 0 && ret != LIBUSB_ERROR_NOT_FOUND)
-                               fprintf(stderr, "error resetting after 
detach\n");
+                       if (func_dfu_rt.bmAttributes & USB_DFU_WILL_DETACH) {
+                               printf("Device will detach and reattach...\n");
+                       } else {
+                               printf("Resetting USB...\n");
+                               ret = libusb_reset_device(_rt_dif.dev_handle);
+                               if (ret < 0 && ret != LIBUSB_ERROR_NOT_FOUND)
+                                       fprintf(stderr, "error resetting "
+                                               "after detach\n");
+                       }
                        sleep(2);
                        break;
                case DFU_STATE_dfuERROR:
-- 
1.7.5.4


_______________________________________________
devel mailing list
devel@lists.openmoko.org
https://lists.openmoko.org/mailman/listinfo/devel

Reply via email to