From eee6ff2000128f9e8b366ceb4c337186b117b3aa Mon Sep 17 00:00:00 2001 From: Michael Patton Date: Mon, 2 Feb 2026 10:53:10 +1100 Subject: [PATCH] Fix USB timeout crashes during sensor initialization Two issues cause python3-validity to crash on startup, particularly after reboot or when the sensor flash is uninitialized: 1. get_flash_info() in flash.py calls assert_status() on the response from command 0x3e, which throws on any 0x04xx status. These statuses indicate uninitialized flash, which is a normal condition that init_flash() is designed to handle. The crash prevents init_flash() from ever reaching its formatting logic. Fix: return an empty FlashInfo when status byte is 0x04, allowing init_flash() to proceed with flash formatting as intended. 2. send_init() in usb.py calls assert_status() on the init_hardcoded command, which fails with 0x0411 when no firmware is loaded. The very next lines check the 4302 (get_fw_info) response and fall through to init_hardcoded_clean_slate for exactly this case, but the assert prevents that path from ever being reached. Fix: remove assert_status() on init_hardcoded, allowing the existing clean slate fallback logic to work as designed. Tested on Lenovo ThinkPad X1 Carbon Gen 5 with Validity VFS495 (138a:0097) sensor running Ubuntu 25.10 / kernel 6.17. --- validitysensor/flash.py | 2 ++ validitysensor/usb.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/validitysensor/flash.py b/validitysensor/flash.py index 54c5240..5874ac2 100644 --- a/validitysensor/flash.py +++ b/validitysensor/flash.py @@ -38,6 +38,8 @@ def __repr__(self): def get_flash_info(): rsp = tls.cmd(unhex('3e')) + if rsp[0] == 0x04: + return FlashInfo(None, 0, 0, 0, 0, []) assert_status(rsp) rsp = rsp[2:] hdr = rsp[:0xe] diff --git a/validitysensor/usb.py b/validitysensor/usb.py index 464b092..1bebfd8 100644 --- a/validitysensor/usb.py +++ b/validitysensor/usb.py @@ -87,7 +87,7 @@ def send_init(self): # c28c745a in response is a FwextBuildtime = 0x5A748CC2 rsp = self.cmd(unhexlify('4302')) # get_fw_info() - assert_status(self.cmd(init_hardcoded)) + self.cmd(init_hardcoded) (err, ), rsp = unpack('