Skip to content

Commit

Permalink
Fallback to libusb0/kamakiri
Browse files Browse the repository at this point in the history
  • Loading branch information
chaosmaster committed Aug 11, 2021
1 parent 26bc888 commit 87a2541
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def main():
log("Disabling watchdog timer")
device.write32(config.watchdog_address, 0x22000064)

if device.libusb0:
arguments.kamakiri = True

bootrom__name = "bootrom_" + hex(hw_code)[2:] + ".bin"

if arguments.test and not arguments.kamakiri:
Expand Down
14 changes: 11 additions & 3 deletions src/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self, port=None):
self.preloader = False
self.timeout = TIMEOUT
self.usbdk = False
self.libusb0 = False

if os.name == 'nt':
try:
Expand Down Expand Up @@ -81,11 +82,18 @@ def find(self, wait=False):

try:
self.configuration = self.udev.get_active_configuration()
except usb.core.USBError as e:
if e.errno == 13:
except (usb.core.USBError, NotImplementedError) as e:
if type(e) is usb.core.USBError and e.errno == 13 or type(e) is NotImplementedError:
log("Failed to enable libusb1, is UsbDk installed?")
log("Falling back to libusb0 (kamakiri only)")
self.backend = usb.backend.libusb0.get_backend()
self.udev = usb.core.find(idVendor=int(VID, 16), backend=self.backend)
self.udev.set_configuration()
self.libusb0 = True
try:
self.udev.set_configuration()
except AttributeError:
log("Failed to enable libusb0")
exit(1)

if self.udev.idProduct != int(PID, 16):
self.preloader = True
Expand Down

0 comments on commit 87a2541

Please sign in to comment.