From cddbdaf5e1644c6fcbbe18ef78621eb8fc4e0efd Mon Sep 17 00:00:00 2001 From: Robbe Derks Date: Sun, 14 Dec 2025 13:54:51 +0800 Subject: [PATCH] usbgpu: patch: auto-detect controller PID/VID (#13645) * auto-detect controller * fix lint? * needs '' * just try --- extra/usbgpu/patch.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/extra/usbgpu/patch.py b/extra/usbgpu/patch.py index 533d9c6532..48c167dd11 100755 --- a/extra/usbgpu/patch.py +++ b/extra/usbgpu/patch.py @@ -3,6 +3,13 @@ import sys, os, zlib, struct, hashlib from tinygrad.helpers import DEBUG, getenv, fetch from tinygrad.runtime.support.usb import USB3 +SUPPORTED_CONTROLLERS = [ + (0x174C, 0x2464), + (0x174C, 0x2463), + (0xADD1, 0x0001), +] +if getenv("USBDEV", ""): SUPPORTED_CONTROLLERS.insert(0, (int(x, 16) for x in getenv("USBDEV", "").split(":"))) + def patch(input_filepath, file_hash, patches): with open(input_filepath, 'rb') as infile: data = bytearray(infile.read()) @@ -40,10 +47,14 @@ if not os.path.exists(file_path): patches = [(0x2a0d + 1 + 4, b'\x0a', b'\x05')] patched_fw = patch(file_path, file_hash, patches) -vendor, device = [int(x, base=16) for x in getenv("USBDEV", "174C:2464").split(":")] -try: dev = USB3(vendor, device, 0x81, 0x83, 0x02, 0x04) -except RuntimeError as e: - raise RuntimeError(f'{e}. You can set USBDEV environment variable to your device\'s vendor and device ID (e.g., USBDEV="174C:2464")') from e +dev = None +for vendor, device in SUPPORTED_CONTROLLERS: + try: + dev = USB3(vendor, device, 0x81, 0x83, 0x02, 0x04) + break + except RuntimeError: pass +if dev is None: + raise RuntimeError('Could not open controller. You can set USBDEV environment variable to your device\'s vendor and device ID (e.g., USBDEV="174C:2464")') config1 = bytes([ 0xFF, 0xFF, 0xFF, 0xFF, 0x41, 0x41, 0x41, 0x41, 0x42, 0x42, 0x42, 0x42, 0x30, 0x30, 0x36, 0x30,