From 9d6eadf14697f64c4b0f249cd3ef24099fa76ef5 Mon Sep 17 00:00:00 2001 From: labwebdev <32825727+labwebdev@users.noreply.github.com> Date: Wed, 8 Jul 2026 15:44:15 -0600 Subject: [PATCH 1/2] Enhance flash info handling and USB command retries - Added logging for short flash info responses to handle uninitialized flash cases. - Updated FlashInfo initialization to accept optional FlashIcInfo. - Refactored USB command execution to retry on busy status for improved reliability. --- validitysensor/flash.py | 13 ++++++++++++- validitysensor/init.py | 2 +- validitysensor/usb.py | 31 +++++++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/validitysensor/flash.py b/validitysensor/flash.py index 54c5240..bd71171 100644 --- a/validitysensor/flash.py +++ b/validitysensor/flash.py @@ -1,3 +1,4 @@ +import logging import typing from struct import pack, unpack @@ -21,7 +22,8 @@ def __repr__(self): class FlashInfo: - def __init__(self, ic: FlashIcInfo, blocks: int, unknown0: int, blocksize: int, unknown1: int, + def __init__(self, ic: typing.Optional[FlashIcInfo], blocks: int, unknown0: int, + blocksize: int, unknown1: int, partitions: typing.Sequence[PartitionInfo]): self.ic = ic self.blocks = blocks @@ -40,6 +42,15 @@ def get_flash_info(): rsp = tls.cmd(unhex('3e')) assert_status(rsp) rsp = rsp[2:] + + # Some sensors (e.g. 06cb:009a with an uninitialized/empty flash) reply + # with only the status word (0000) and no header/partition data. + # Treat a short response as an uninitialized flash so init_flash() can + # format it instead of crashing on unpack(). + if len(rsp) < 0xe: + logging.info('Flash info response too short (%d bytes); assuming uninitialized flash' % len(rsp)) + return FlashInfo(None, 0, 0, 0, 0, []) + hdr = rsp[:0xe] rsp = rsp[0xe:] jid0, jid1, blocks, unknown0, blocksize, unknown1, pcnt = unpack(' Date: Wed, 8 Jul 2026 15:44:21 -0600 Subject: [PATCH 2/2] Enhance flash info handling and USB command retries - Added logging for short flash info responses to handle uninitialized flash cases. - Updated FlashInfo initialization to accept optional FlashIcInfo. - Refactored USB command execution to retry on busy status for improved reliability. --- python3-validity.local.service | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 python3-validity.local.service diff --git a/python3-validity.local.service b/python3-validity.local.service new file mode 100644 index 0000000..25ad586 --- /dev/null +++ b/python3-validity.local.service @@ -0,0 +1,13 @@ +[Unit] +Description=python-validity driver dbus service (local checkout) +After=open-fprintd.service + +[Service] +Type=simple +Environment=PYTHONPATH=/home/liam/src/python-validity +ExecStart=/usr/bin/python3 /home/liam/src/python-validity/dbus_service/dbus-service --debug --configpath /home/liam/src/python-validity/etc/python-validity +Restart=on-success +RestartSec=3 + +[Install] +WantedBy=multi-user.target