1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-14 11:39:03 +00:00

trezorctl: add USB reset command for stuck devices

This commit is contained in:
matejcik 2019-04-05 17:15:55 +02:00
parent 50fe0d96bb
commit 34052af9db
2 changed files with 18 additions and 1 deletions

View File

@ -774,6 +774,18 @@ def self_test(connect):
return debuglink.self_test(connect())
@cli.command()
def usb_reset():
"""Perform USB reset on a stuck device.
This can fix LIBUSB_ERROR_PIPE and similar errors when connecting to a device
in a messed state.
"""
from trezorlib.transport.webusb import WebUsbTransport
WebUsbTransport.enumerate(usb_reset=True)
#
# Basic coin functions
#

View File

@ -106,7 +106,7 @@ class WebUsbTransport(ProtocolBasedTransport):
return "%s:%s" % (self.PATH_PREFIX, dev_to_str(self.device))
@classmethod
def enumerate(cls) -> Iterable["WebUsbTransport"]:
def enumerate(cls, usb_reset=False) -> Iterable["WebUsbTransport"]:
if cls.context is None:
cls.context = usb1.USBContext()
cls.context.open()
@ -128,6 +128,11 @@ class WebUsbTransport(ProtocolBasedTransport):
devices.append(WebUsbTransport(dev))
except usb1.USBErrorNotSupported:
pass
except usb1.USBErrorPipe:
if usb_reset:
handle = dev.open()
handle.resetDevice()
handle.close()
return devices
def find_debug(self) -> "WebUsbTransport":