mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2025-07-27 00:45:46 -04:00
Print warning if the programmer device permissions are incorrect
This commit is contained in:
parent
fe1e2254d2
commit
f83f919f9e
2 changed files with 21 additions and 12 deletions
|
@ -40,6 +40,8 @@ class IceFlasher:
|
||||||
|
|
||||||
SPI_MAX_TRANSFER_SIZE = 2048 - 8
|
SPI_MAX_TRANSFER_SIZE = 2048 - 8
|
||||||
|
|
||||||
|
handle = None
|
||||||
|
|
||||||
def _check_for_old_firmware(self) -> bool:
|
def _check_for_old_firmware(self) -> bool:
|
||||||
for device in self.context.getDeviceList():
|
for device in self.context.getDeviceList():
|
||||||
if device.getVendorID() == 0xcafe and device.getProductID() == 0x4004:
|
if device.getVendorID() == 0xcafe and device.getProductID() == 0x4004:
|
||||||
|
@ -54,25 +56,29 @@ class IceFlasher:
|
||||||
|
|
||||||
# See: https://github.com/vpelletier/python-libusb1#usage
|
# See: https://github.com/vpelletier/python-libusb1#usage
|
||||||
self.context = usb1.USBContext()
|
self.context = usb1.USBContext()
|
||||||
|
|
||||||
|
try:
|
||||||
self.handle = self.context.openByVendorIDAndProductID(
|
self.handle = self.context.openByVendorIDAndProductID(
|
||||||
0x1209,
|
0x1209,
|
||||||
0x8886,
|
0x8886,
|
||||||
skip_on_error=True,
|
skip_on_error=False
|
||||||
)
|
)
|
||||||
|
except usb1.USBErrorAccess as exp:
|
||||||
|
raise OSError('Programmer found, but unable to open- check device permissions!') from exp
|
||||||
|
|
||||||
if self.handle is None:
|
if self.handle is None:
|
||||||
# Device not present, or user is not allowed to access
|
# Device not present, or user is not allowed to access
|
||||||
# device.
|
# device.
|
||||||
if self._check_for_old_firmware():
|
if self._check_for_old_firmware():
|
||||||
raise ValueError(
|
raise OSError(
|
||||||
'Programmer with outdated firmware found- please update!')
|
'Programmer with outdated firmware found- please update!')
|
||||||
else:
|
else:
|
||||||
raise ValueError('Programmer not found')
|
raise OSError('Programmer not found- check USB cable')
|
||||||
|
|
||||||
# Check the device firmware version
|
# Check the device firmware version
|
||||||
bcd_device = self.handle.getDevice().getbcdDevice()
|
bcd_device = self.handle.getDevice().getbcdDevice()
|
||||||
if bcd_device != 0x0200:
|
if bcd_device != 0x0200:
|
||||||
raise ValueError(
|
raise OSError(
|
||||||
'Pico firmware version out of date- please upgrade')
|
'Pico firmware version out of date- please upgrade')
|
||||||
|
|
||||||
self.handle.claimInterface(0)
|
self.handle.claimInterface(0)
|
||||||
|
@ -84,9 +90,9 @@ class IceFlasher:
|
||||||
|
|
||||||
def close(self) -> None:
|
def close(self) -> None:
|
||||||
""" Release the USB device handle """
|
""" Release the USB device handle """
|
||||||
|
if self.handle is not None:
|
||||||
self._wait_async()
|
self._wait_async()
|
||||||
|
|
||||||
if self.handle is not None:
|
|
||||||
self.handle.close()
|
self.handle.close()
|
||||||
self.handle = None
|
self.handle = None
|
||||||
self.context.close()
|
self.context.close()
|
||||||
|
|
|
@ -67,10 +67,13 @@ def run_tests(test_list: list[Any]) -> bool:
|
||||||
'Failure at test step "{:}"'.format(
|
'Failure at test step "{:}"'.format(
|
||||||
test.__name__))
|
test.__name__))
|
||||||
return False
|
return False
|
||||||
except Exception as e:
|
except OSError as exp:
|
||||||
|
print(exp)
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as exp:
|
||||||
print(
|
print(
|
||||||
'Error while running test step "{:}", exception:{:}'.format(
|
'Error while running test step "{:}", exception:{:}'.format(
|
||||||
test.__name__, str(e)))
|
test.__name__, str(exp)))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue