Skip to content

Commit acabc69

Browse files
authored
install newer OpenOCD via tl_install from github
1 parent a899cc6 commit acabc69

File tree

1 file changed

+50
-14
lines changed

1 file changed

+50
-14
lines changed

platform.py

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
# limitations under the License.
1414

1515
import os
16-
import urllib
16+
import subprocess
1717
import sys
18-
import json
19-
import re
20-
import requests
18+
import shutil
19+
from os.path import join
2120

2221
from platformio.public import PlatformBase, to_unix_path
22+
from platformio.proc import get_pythonexe_path
23+
from platformio.project.config import ProjectConfig
24+
from platformio.package.manager.tool import ToolPackageManager
2325

2426

2527
IS_WINDOWS = sys.platform.startswith("win")
@@ -29,6 +31,36 @@
2931
if IS_WINDOWS:
3032
os.environ["PLATFORMIO_SYSTEM_TYPE"] = "windows_amd64"
3133

34+
python_exe = get_pythonexe_path()
35+
pm = ToolPackageManager()
36+
37+
def install_tool(TOOL):
38+
TOOLS_PATH_DEFAULT = os.path.join(os.path.expanduser("~"), ".platformio")
39+
IDF_TOOLS = os.path.join(ProjectConfig.get_instance().get("platformio", "packages_dir"), "tl-install", "tools", "idf_tools.py")
40+
TOOLS_JSON_PATH = os.path.join(ProjectConfig.get_instance().get("platformio", "packages_dir"), TOOL, "tools.json")
41+
TOOLS_PACK_PATH = os.path.join(ProjectConfig.get_instance().get("platformio", "packages_dir"), TOOL, "package.json")
42+
IDF_TOOLS_CMD = (
43+
python_exe,
44+
IDF_TOOLS,
45+
"--quiet",
46+
"--non-interactive",
47+
"--tools-json",
48+
TOOLS_JSON_PATH,
49+
"install"
50+
)
51+
52+
tl_flag = bool(os.path.exists(IDF_TOOLS))
53+
json_flag = bool(os.path.exists(TOOLS_JSON_PATH))
54+
if tl_flag and json_flag:
55+
rc = subprocess.call(IDF_TOOLS_CMD)
56+
if rc != 0:
57+
sys.stderr.write("Error: Couldn't execute 'idf_tools.py install'\n")
58+
else:
59+
tl_path = "file://" + join(TOOLS_PATH_DEFAULT, "tools", TOOL)
60+
shutil.copyfile(TOOLS_PACK_PATH, join(TOOLS_PATH_DEFAULT, "tools", TOOL, "package.json"))
61+
pm.install(tl_path)
62+
return
63+
3264

3365
class Espressif32Platform(PlatformBase):
3466
def configure_default_packages(self, variables, targets):
@@ -43,7 +75,12 @@ def configure_default_packages(self, variables, targets):
4375
core_variant_build = (''.join(variables.get("build_flags", []))).replace("-D", " ")
4476
frameworks = variables.get("pioframework", [])
4577

46-
if "arduino" in frameworks:
78+
# Installer only needed for setup, deactivate
79+
self.packages["tl-install"]["optional"] = True
80+
# Installed not from pio registry, deactivate until needed
81+
self.packages["tool-openocd-esp32"]["optional"] = True
82+
83+
if "arduino" in frameworks and variables.get("custom_sdkconfig") is None and len(str(board_sdkconfig)) < 3:
4784
self.packages["framework-arduinoespressif32"]["optional"] = False
4885
self.packages["framework-arduinoespressif32-libs"]["optional"] = False
4986
# use matching espressif Arduino libs
@@ -93,21 +130,20 @@ def configure_default_packages(self, variables, targets):
93130
# Starting from v12, Espressif's toolchains are shipped without
94131
# bundled GDB. Instead, it's distributed as separate packages for Xtensa
95132
# and RISC-V targets.
96-
for gdb_package in ("tool-xtensa-esp-elf-gdb", "tool-riscv32-esp-elf-gdb"):
97-
self.packages[gdb_package]["optional"] = False
98-
# if IS_WINDOWS:
99-
# Note: On Windows GDB v12 is not able to
100-
# launch a GDB server in pipe mode while v11 works fine
101-
# self.packages[gdb_package]["version"] = "~11.2.0"
133+
if (variables.get("build_type") or "debug" in "".join(targets)) or variables.get("upload_protocol"):
134+
for gdb_package in ("tool-xtensa-esp-elf-gdb", "tool-riscv32-esp-elf-gdb"):
135+
self.packages[gdb_package]["optional"] = False
136+
install_tool("tool-openocd-esp32")
137+
self.packages["tool-openocd-esp32"]["optional"] = False
102138

103139
# Common packages for IDF and mixed Arduino+IDF projects
104140
if "espidf" in frameworks:
105141
self.packages["toolchain-esp32ulp"]["optional"] = False
106142
for p in self.packages:
107143
if p in (
108-
"tool-scons",
109144
"tool-cmake",
110145
"tool-ninja",
146+
"tool-scons",
111147
"tool-esp-rom-elfs",
112148
):
113149
self.packages[p]["optional"] = False
@@ -119,8 +155,8 @@ def configure_default_packages(self, variables, targets):
119155
else:
120156
self.packages.pop("toolchain-xtensa-esp-elf", None)
121157

122-
if mcu in ("esp32s2", "esp32s3", "esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4"):
123-
if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4"):
158+
if mcu in ("esp32s2", "esp32s3", "esp32c2", "esp32c3", "esp32c5", "esp32c6", "esp32h2", "esp32p4"):
159+
if mcu in ("esp32c2", "esp32c3", "esp32c5", "esp32c6", "esp32h2", "esp32p4"):
124160
self.packages.pop("toolchain-esp32ulp", None)
125161
# RISC-V based toolchain for ESP32C3, ESP32C6 ESP32S2, ESP32S3 ULP
126162
self.packages["toolchain-riscv32-esp"]["optional"] = False

0 commit comments

Comments
 (0)