remote: usb: print "access denied" error
authorSean Cross <sean@xobs.io>
Tue, 21 May 2019 01:35:09 +0000 (02:35 +0100)
committerSean Cross <sean@xobs.io>
Tue, 21 May 2019 01:36:18 +0000 (09:36 +0800)
When we get an error with errno 13, it means that the user doesn't
have access to the USB device.  Rather than silently eating this
error and returning -1, print out a message to aid in debugging.

Signed-off-by: Sean Cross <sean@xobs.io>
litex/tools/remote/comm_usb.py

index 53ee4c8182193ddfb0fb807cc7c566fb8cae5e04..302a4e4e4c6197d8bc4a14f111f69bc74ed7cb05 100644 (file)
@@ -111,7 +111,14 @@ class CommUSB:
             if value is None:
                 raise TypeError
             return int.from_bytes(value, byteorder="little")
-        except (usb.core.USBError, TypeError):
+        except usb.core.USBError as e:
+            if e.errno == 13:
+                print("Access Denied. Maybe try using sudo?")
+            self.close()
+            self.open()
+            if depth < self.MAX_RECURSION_COUNT:
+                return self.usb_read(addr, depth+1)
+        except TypeError:
             self.close()
             self.open()
             if depth < self.MAX_RECURSION_COUNT:
@@ -127,7 +134,7 @@ class CommUSB:
 
     def usb_write(self, addr, value, depth=0):
         try:
-            self.dev.ctrl_transfer(bmRequestType=0x43, bRequest=0x00,
+            value = self.dev.ctrl_transfer(bmRequestType=0x43, bRequest=0x00,
                     wValue=addr & 0xffff,
                     wIndex=(addr >> 16) & 0xffff,
                     data_or_wLength=bytes([(value >> 0) & 0xff,
@@ -135,7 +142,9 @@ class CommUSB:
                                            (value >> 16) & 0xff,
                                            (value >> 24) & 0xff]
                                           ), timeout=None)
-        except usb.core.USBError:
+        except usb.core.USBError as e:
+            if e.errno == 13:
+                print("Access Denied. Maybe try using sudo?")
             self.close()
             self.open()
             if depth < self.MAX_RECURSION_COUNT: