From 7199051aaf0ddfa2849650933119307327d8669c Mon Sep 17 00:00:00 2001 From: Chris Sarbora Date: Fri, 22 Mar 2024 09:32:02 -0500 Subject: [PATCH] Wait for disconnect when rebooting to userspace FB Wait for the device to disconnect when rebooting to userspace fastboot. This is a particular problem for USB-over-IP devices, which must tunnel the USB commands over a relatively-slow network and thus will not disconnect as quickly as local ones. Only currently effective for Linux hosts, since LinuxUsbTransport is the only transport that implements WaitForDisconnect(). Test Plan: provision with a usbip-attached device, see flash succeed Change-Id: Ia8903dfa6e40755377870fbeaef9162934f992a0 --- fastboot/fastboot.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp index 12a1ddc87..6b9e493eb 100644 --- a/fastboot/fastboot.cpp +++ b/fastboot/fastboot.cpp @@ -1547,9 +1547,14 @@ bool is_userspace_fastboot() { void reboot_to_userspace_fastboot() { fb->RebootTo("fastboot"); + if (fb->WaitForDisconnect() != fastboot::SUCCESS) { + die("Error waiting for USB disconnect."); + } fb->set_transport(nullptr); - // Give the current connection time to close. + // Not all platforms support WaitForDisconnect. There also isn't a great way to tell whether + // or not WaitForDisconnect is supported. So, just wait a bit extra for everyone, in order to + // make sure that the device has had time to initiate its reboot and disconnect itself. std::this_thread::sleep_for(std::chrono::seconds(1)); fb->set_transport(open_device());