diff --git a/esphome/__main__.py b/esphome/__main__.py index d0a1811bd4e..46a07de1cf4 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -58,6 +58,7 @@ from esphome.helpers import get_bool_env, indent, is_ip_address from esphome.log import AnsiFore, color, setup_log from esphome.types import ConfigType from esphome.util import ( + PICOTOOL_PACKAGE, detect_rp2040_bootsel, get_picotool_path, get_serial_ports, @@ -792,7 +793,8 @@ def upload_using_picotool(config: ConfigType) -> int: if picotool is None: _LOGGER.error( "picotool not found. Ensure the RP2040 PlatformIO platform " - "is installed (tool-picotool-rp2040-earlephilhower)." + "is installed (%s).", + PICOTOOL_PACKAGE, ) return 1 @@ -820,11 +822,13 @@ def upload_using_picotool(config: ConfigType) -> int: for line in stderr.splitlines(): safe_print(line) if "LIBUSB_ERROR_ACCESS" in stderr or "Permission denied" in stderr: - _LOGGER.error( - "Permission denied accessing USB device. " - "On Linux, you may need to add udev rules for RP2040 devices. " - "See: https://github.com/raspberrypi/picotool#linux-permissions" - ) + msg = "Permission denied accessing USB device." + if sys.platform.startswith("linux"): + msg += ( + " You may need to add udev rules for RP2040 devices." + " See: https://github.com/raspberrypi/picotool#linux-permissions" + ) + _LOGGER.error(msg) else: _LOGGER.error("picotool upload failed (exit code %d).", result.returncode) return 1 diff --git a/esphome/util.py b/esphome/util.py index 695c83cab35..d0fa4300a98 100644 --- a/esphome/util.py +++ b/esphome/util.py @@ -355,6 +355,9 @@ def get_serial_ports() -> list[SerialPort]: return result +PICOTOOL_PACKAGE = "tool-picotool-rp2040-earlephilhower" + + def get_picotool_path(cc_path: str) -> Path | None: """Derive the picotool binary path from the PlatformIO toolchain cc_path. @@ -367,7 +370,7 @@ def get_picotool_path(cc_path: str) -> Path | None: # Go from .../packages/toolchain-.../bin/gcc up to .../packages/ packages_dir = cc.parent.parent.parent binary_name = "picotool.exe" if sys.platform == "win32" else "picotool" - picotool = packages_dir / "tool-picotool-rp2040-earlephilhower" / binary_name + picotool = packages_dir / PICOTOOL_PACKAGE / binary_name if picotool.is_file(): return picotool return None