Skip to content

Commit f6ee8fe

Browse files
15characterlimiGerrit Code Review
authored and
Gerrit Code Review
committed
Merge "Revert "Add derived UsbTransport class with USB reset method""
2 parents 1c92fa4 + ec1542f commit f6ee8fe

File tree

4 files changed

+18
-59
lines changed

4 files changed

+18
-59
lines changed

fastboot/usb.h

+1-8
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ struct usb_ifc_info {
5252
char device_path[256];
5353
};
5454

55-
class UsbTransport : public Transport {
56-
// Resets the underlying transport. Returns 0 on success.
57-
// This effectively simulates unplugging and replugging
58-
virtual int Reset() = 0;
59-
};
60-
6155
typedef int (*ifc_match_func)(usb_ifc_info *ifc);
6256

63-
// 0 is non blocking
64-
UsbTransport* usb_open(ifc_match_func callback, uint32_t timeout_ms = 0);
57+
Transport* usb_open(ifc_match_func callback);

fastboot/usb_linux.cpp

+9-21
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
using namespace std::chrono_literals;
5454

55-
#define MAX_RETRIES 2
55+
#define MAX_RETRIES 5
5656

5757
/* Timeout in seconds for usb_wait_for_disconnect.
5858
* It doesn't usually take long for a device to disconnect (almost always
@@ -91,21 +91,18 @@ struct usb_handle
9191
unsigned char ep_out;
9292
};
9393

94-
class LinuxUsbTransport : public UsbTransport {
94+
class LinuxUsbTransport : public Transport {
9595
public:
96-
explicit LinuxUsbTransport(std::unique_ptr<usb_handle> handle, uint32_t ms_timeout = 0)
97-
: handle_(std::move(handle)), ms_timeout_(ms_timeout) {}
96+
explicit LinuxUsbTransport(std::unique_ptr<usb_handle> handle) : handle_(std::move(handle)) {}
9897
~LinuxUsbTransport() override = default;
9998

10099
ssize_t Read(void* data, size_t len) override;
101100
ssize_t Write(const void* data, size_t len) override;
102101
int Close() override;
103-
int Reset() override;
104102
int WaitForDisconnect() override;
105103

106104
private:
107105
std::unique_ptr<usb_handle> handle_;
108-
const uint32_t ms_timeout_;
109106

110107
DISALLOW_COPY_AND_ASSIGN(LinuxUsbTransport);
111108
};
@@ -405,7 +402,7 @@ ssize_t LinuxUsbTransport::Write(const void* _data, size_t len)
405402
bulk.ep = handle_->ep_out;
406403
bulk.len = xfer;
407404
bulk.data = data;
408-
bulk.timeout = ms_timeout_;
405+
bulk.timeout = 0;
409406

410407
n = ioctl(handle_->desc, USBDEVFS_BULK, &bulk);
411408
if(n != xfer) {
@@ -439,7 +436,7 @@ ssize_t LinuxUsbTransport::Read(void* _data, size_t len)
439436
bulk.ep = handle_->ep_in;
440437
bulk.len = xfer;
441438
bulk.data = data;
442-
bulk.timeout = ms_timeout_;
439+
bulk.timeout = 0;
443440
retry = 0;
444441

445442
do {
@@ -450,7 +447,7 @@ ssize_t LinuxUsbTransport::Read(void* _data, size_t len)
450447
if (n < 0) {
451448
DBG1("ERROR: n = %d, errno = %d (%s)\n",n, errno, strerror(errno));
452449
if (++retry > MAX_RETRIES) return -1;
453-
std::this_thread::sleep_for(100ms);
450+
std::this_thread::sleep_for(1s);
454451
}
455452
} while (n < 0);
456453

@@ -480,19 +477,10 @@ int LinuxUsbTransport::Close()
480477
return 0;
481478
}
482479

483-
int LinuxUsbTransport::Reset() {
484-
int ret = 0;
485-
// We reset the USB connection
486-
if ((ret = ioctl(handle_->desc, USBDEVFS_RESET, 0))) {
487-
return ret;
488-
}
489-
490-
return 0;
491-
}
492-
493-
UsbTransport* usb_open(ifc_match_func callback, uint32_t timeout_ms) {
480+
Transport* usb_open(ifc_match_func callback)
481+
{
494482
std::unique_ptr<usb_handle> handle = find_usb_device("/sys/bus/usb/devices", callback);
495-
return handle ? new LinuxUsbTransport(std::move(handle), timeout_ms) : nullptr;
483+
return handle ? new LinuxUsbTransport(std::move(handle)) : nullptr;
496484
}
497485

498486
/* Wait for the system to notice the device is gone, so that a subsequent

fastboot/usb_osx.cpp

+5-21
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,17 @@ struct usb_handle
6565
unsigned int zero_mask;
6666
};
6767

68-
class OsxUsbTransport : public UsbTransport {
68+
class OsxUsbTransport : public Transport {
6969
public:
70-
OsxUsbTransport(std::unique_ptr<usb_handle> handle, uint32_t ms_timeout)
71-
: handle_(std::move(handle)), ms_timeout_(ms_timeout) {}
70+
OsxUsbTransport(std::unique_ptr<usb_handle> handle) : handle_(std::move(handle)) {}
7271
~OsxUsbTransport() override = default;
7372

7473
ssize_t Read(void* data, size_t len) override;
7574
ssize_t Write(const void* data, size_t len) override;
7675
int Close() override;
77-
int Reset() override;
7876

7977
private:
8078
std::unique_ptr<usb_handle> handle_;
81-
const uint32_t ms_timeout_;
8279

8380
DISALLOW_COPY_AND_ASSIGN(OsxUsbTransport);
8481
};
@@ -459,33 +456,22 @@ static int init_usb(ifc_match_func callback, std::unique_ptr<usb_handle>* handle
459456
* Definitions of this file's public functions.
460457
*/
461458

462-
UsbTransport* usb_open(ifc_match_func callback, uint32_t timeout_ms) {
459+
Transport* usb_open(ifc_match_func callback) {
463460
std::unique_ptr<usb_handle> handle;
464461

465462
if (init_usb(callback, &handle) < 0) {
466463
/* Something went wrong initializing USB. */
467464
return nullptr;
468465
}
469466

470-
return new OsxUsbTransport(std::move(handle), timeout_ms);
467+
return new OsxUsbTransport(std::move(handle));
471468
}
472469

473470
int OsxUsbTransport::Close() {
474471
/* TODO: Something better here? */
475472
return 0;
476473
}
477474

478-
int OsxUsbTransport::Reset() {
479-
IOReturn result = (*handle_->interface)->ResetDevice(handle_->interface);
480-
481-
if (result == 0) {
482-
return 0;
483-
} else {
484-
ERR("usb_reset failed with status %x\n", result);
485-
return -1;
486-
}
487-
}
488-
489475
ssize_t OsxUsbTransport::Read(void* data, size_t len) {
490476
IOReturn result;
491477
UInt32 numBytes = len;
@@ -508,9 +494,7 @@ ssize_t OsxUsbTransport::Read(void* data, size_t len) {
508494
return -1;
509495
}
510496

511-
result = (*handle_->interface)
512-
->ReadPipeTO(handle_->interface, handle_->bulkIn, data, &numBytes,
513-
USB_TRANSACTION_TIMEOUT, USB_TRANSACTION_TIMEOUT);
497+
result = (*handle_->interface)->ReadPipe(handle_->interface, handle_->bulkIn, data, &numBytes);
514498

515499
if (result == 0) {
516500
return (int) numBytes;

fastboot/usb_windows.cpp

+3-9
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,14 @@ struct usb_handle {
6666
std::string interface_name;
6767
};
6868

69-
class WindowsUsbTransport : public UsbTransport {
69+
class WindowsUsbTransport : public Transport {
7070
public:
7171
WindowsUsbTransport(std::unique_ptr<usb_handle> handle) : handle_(std::move(handle)) {}
7272
~WindowsUsbTransport() override = default;
7373

7474
ssize_t Read(void* data, size_t len) override;
7575
ssize_t Write(const void* data, size_t len) override;
7676
int Close() override;
77-
int Reset() override;
7877

7978
private:
8079
std::unique_ptr<usb_handle> handle_;
@@ -262,12 +261,6 @@ int WindowsUsbTransport::Close() {
262261
return 0;
263262
}
264263

265-
int WindowsUsbTransport::Reset() {
266-
DBG("usb_reset currently unsupported\n\n");
267-
// TODO, this is a bit complicated since it is using ADB
268-
return -1;
269-
}
270-
271264
int recognized_device(usb_handle* handle, ifc_match_func callback) {
272265
struct usb_ifc_info info;
273266
USB_DEVICE_DESCRIPTOR device_desc;
@@ -373,7 +366,8 @@ static std::unique_ptr<usb_handle> find_usb_device(ifc_match_func callback) {
373366
return handle;
374367
}
375368

376-
UsbTransport* usb_open(ifc_match_func callback, uint32_t) {
369+
Transport* usb_open(ifc_match_func callback)
370+
{
377371
std::unique_ptr<usb_handle> handle = find_usb_device(callback);
378372
return handle ? new WindowsUsbTransport(std::move(handle)) : nullptr;
379373
}

0 commit comments

Comments
 (0)