Update flash.py

This commit is contained in:
royjr
2026-08-22 00:47:46 -04:00
parent 7966631819
commit bdbaf6f074
+5 -1
View File
@@ -105,7 +105,7 @@ def open_device(path):
return os.open(f"/dev/bus/usb/{bus:03d}/{dev:03d}", os.O_RDWR)
def link_up() -> bool:
def link_up(reset: bool = False) -> bool:
# asm enumerates on USB-C alone, gpu is only usable once pcie link is up
try:
path, _, _ = find_chestnut()
@@ -115,6 +115,10 @@ def link_up() -> bool:
except (OSError, RuntimeError):
return False
try:
if reset:
# a consumer killed mid device_fini leaves the link wedged, drop power to force a retrain
fcntl.ioctl(fd, USBDEVFS_CONTROL, Ctrl(0x40, 0xF3, 0, 0, 0, 2000, None))
time.sleep(0.5)
fcntl.ioctl(fd, USBDEVFS_CONTROL, Ctrl(0x40, 0xF3, 1, 0, 0, 2000, None))
buf = (ctypes.c_ubyte * 1)()
fcntl.ioctl(fd, USBDEVFS_CONTROL, Ctrl(0xC0, 0xE4, 0xB450, 0, 1, 1000, ctypes.cast(buf, ctypes.c_void_p)))