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 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('