diff --git a/main.py b/main.py index bf215af..ffafe31 100755 --- a/main.py +++ b/main.py @@ -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: diff --git a/src/device.py b/src/device.py index e005d4d..e64bf43 100644 --- a/src/device.py +++ b/src/device.py @@ -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: @@ -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