-
Notifications
You must be signed in to change notification settings - Fork 25
Add delays after finalizing dfu update + USB fix #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,12 +105,20 @@ static int libhoth_usb_reconnect(struct libhoth_device* dev) { | |
| } | ||
|
|
||
| libhoth_usb_close(dev); | ||
| libusb_handle_events_completed(usb_ctx, NULL); | ||
|
|
||
| uint64_t start_time_ms = libhoth_get_monotonic_ms(); | ||
|
|
||
| while (1) { | ||
| int ret = libhoth_usb_get_device(usb_ctx, &usb_loc, &libusb_dev); | ||
| libusb_exit(usb_ctx); | ||
| int ret = libusb_init(&usb_ctx); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to init libusb again? If there is one, would it be possible to call this in the loop instead of once after
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we need to re-init, because otherwise, from my testing, libusb cannot find the device and we get a timeout |
||
| if (ret != 0) { | ||
| fprintf( | ||
| stderr, | ||
| "libusb_init_context failed while reconnecting (error: %d (%s))\n", | ||
| ret, libusb_strerror(ret)); | ||
| } | ||
|
|
||
| ret = libhoth_usb_get_device(usb_ctx, &usb_loc, &libusb_dev); | ||
| if (ret == 0) { | ||
| // Found the device | ||
| break; | ||
|
|
@@ -123,6 +131,7 @@ static int libhoth_usb_reconnect(struct libhoth_device* dev) { | |
| stderr, | ||
| "libhoth_usb_open timed out while reconnecting (error: %d (%s))\n", | ||
| ret, libusb_strerror(ret)); | ||
| libusb_exit(usb_ctx); | ||
| return ret; // Timeout | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of waiting in a loop, could an event handler be installed to check for USB discovery events? Based on a quick look at the documentation, I see that
libusb_hotplug_register_callbackcan be used for registering callbacks when events occur. But I haven't used it as of now, so I can't say how well it would work here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using hotplug discovery could work, assuming that all of the platforms we want to support have support for hotplug, which the libusb docs have called out as not necessarily being true.
One tricky thing is that if we register for hotplug events during reconnect, the eROT might have already started rebooting and we will miss the disconnect. The eROT might also have already rebooted, meaning we will miss the reconnect event.
The current API for reconnect right now is to delay for a second to be certain that the eROT has at least gone down for reboot, then to poll for discovery since this seems to be the most straight-forward way to have support for all transports.