mirror of
https://github.com/esphome/esphome.git
synced 2026-09-17 18:18:43 +00:00
[rp2040] Extract picotool package const, fix platform check for udev hint
- Add PICOTOOL_PACKAGE constant for the PlatformIO package name - Only show udev rules hint on Linux, not on macOS/Windows
This commit is contained in:
+10
-6
@@ -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
|
||||
|
||||
+4
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user