{"record":{"id":"940cda21d8d02f5b","repo":"commaai/openpilot","slug":"could-not-disable-usb-runtime-pm-control","errorCode":null,"errorMessage":"could not disable USB runtime PM: {control}","messagePattern":"could not disable USB runtime PM: (.+?)","errorType":"console","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"openpilot/system/hardware/chestnut/flash.py","lineNumber":87,"sourceCode":"      pass\n  if len(found) > 1:\n    raise RuntimeError(f\"expected one chestnut, found {len(found)}\")\n  return found[0] if found else (None, None, None)\n\n\ndef in_rom_bootloader(vid_pid, product):\n  # the ROM bootloader reports the config page strings, or its own when the config page is lost\n  return vid_pid in ROM_VID_PIDS or product == ROM_PRODUCT or (product or \"\").startswith(\"AS2462\")\n\n\ndef disable_runtime_pm(path):\n  control = os.path.join(path, \"power/control\")\n  if not os.path.exists(control):\n    return\n  with open(control, \"w\") as f:\n    f.write(\"on\\n\")\n  if open(control).read().strip() != \"on\":\n    raise RuntimeError(f\"could not disable USB runtime PM: {control}\")\n  delay = os.path.join(path, \"power/autosuspend_delay_ms\")\n  if os.path.exists(delay):\n    with open(delay, \"w\") as f:\n      f.write(\"-1\\n\")\n\n\ndef unbind_drivers(path):\n  for interface in glob.glob(path + \":*\"):\n    driver = interface + \"/driver\"\n    if os.path.islink(driver):\n      with open(os.path.realpath(driver) + \"/unbind\", \"w\") as f:\n        f.write(os.path.basename(interface))\n\n\ndef open_device(path):\n  bus, dev = int(open(path + \"/busnum\").read()), int(open(path + \"/devnum\").read())\n  return os.open(f\"/dev/bus/usb/{bus:03d}/{dev:03d}\", os.O_RDWR)\n","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/commaai/openpilot/blob/516ec1e68203439a73f340f1d0b3b91eabc626ee/openpilot/system/hardware/chestnut/flash.py#L69-L105","documentation":"RuntimeError from disable_runtime_pm() in the chestnut flasher: it writes 'on' to the device's sysfs power/control file but a read-back returns something other than 'on', so runtime power management is still active and could suspend the device mid-flash. The flasher refuses to continue with nondeterministic USB power state.","triggerScenarios":"Running the flasher without root (sysfs power files are root-writable, so the write silently fails or is ignored), an unusual kernel/driver that ignores power/control writes, or a read-only sysfs mount.","commonSituations":"Invoking the flash tool as a normal user instead of sudo, containers without writable /sys, or a kernel where the USB driver does not honor runtime PM control for that interface.","solutions":["Run the flasher as root (sudo) so sysfs writes take effect","Check dmesg and /sys/<dev>/power/control manually: echo on, then cat to see whether it sticks","If in a container, run with /sys mounted rw or flash from the host"],"exampleFix":"# before\npython3 flash.py   # as normal user\n\n# after\nsudo python3 flash.py","handlingStrategy":"try-catch","validationCode":"import os\n\ndef runtime_pm_writable(sysfs_path: str) -> bool:\n    control = os.path.join(sysfs_path, 'power', 'control')\n    if not os.path.exists(control):\n        return True  # nothing to disable\n    return os.access(control, os.W_OK)","typeGuard":null,"tryCatchPattern":"try:\n    disable_runtime_pm(sysfs_path)\nexcept RuntimeError as e:\n    if 'runtime PM' in str(e):\n        raise RuntimeError('rerun the flasher as root so sysfs power/control writes take effect') from e\n    raise","preventionTips":["Run the flasher with sudo/root privileges","Avoid flashing from containers unless /sys is mounted read-write"],"tags":["firmware","flashing","usb","permissions","sysfs"],"backgroundTag":null,"analyzedSha":"516ec1e68203439a73f340f1d0b3b91eabc626ee","analyzedAt":"2026-08-15T00:17:37.461Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}