@@ -71,8 +71,10 @@ def install_tool(TOOL):
71
71
sys .stderr .write ("Error: Couldn't execute 'idf_tools.py install'\n " )
72
72
else :
73
73
tl_path = "file://" + join (TOOLS_PATH_DEFAULT , "tools" , TOOL )
74
- if not os . path . exists ( join ( TOOLS_PATH_DEFAULT , "tools" , TOOL , "package.json" )) :
74
+ try :
75
75
shutil .copyfile (TOOL_PACKAGE_PATH , join (TOOLS_PATH_DEFAULT , "tools" , TOOL , "package.json" ))
76
+ except FileNotFoundError as e :
77
+ sys .stderr .write (f"Error copying tool package file: { e } \n " )
76
78
self .packages .pop (TOOL , None )
77
79
if os .path .exists (TOOL_PATH ) and os .path .isdir (TOOL_PATH ):
78
80
try :
@@ -112,6 +114,51 @@ def install_tool(TOOL):
112
114
if mcu == "esp32c2" :
113
115
self .packages ["framework-arduino-c2-skeleton-lib" ]["optional" ] = False
114
116
117
+ mcu_toolchain_mapping = {
118
+ # Xtensa based and FSM toolchain
119
+ ("esp32" , "esp32s2" , "esp32s3" ): {
120
+ "toolchains" : ["toolchain-xtensa-esp-elf" ],
121
+ "ulp_toolchain" : ["toolchain-esp32ulp" ] + (["toolchain-riscv32-esp" ] if mcu != "esp32" else []),
122
+ "debug_tools" : ["tool-xtensa-esp-elf-gdb" ]
123
+ },
124
+ # RISC-V based toolchain
125
+ ("esp32c2" , "esp32c3" , "esp32c5" , "esp32c6" , "esp32h2" , "esp32p4" ): {
126
+ "toolchains" : ["toolchain-riscv32-esp" ],
127
+ "ulp_toolchain" : None ,
128
+ "debug_tools" : ["tool-riscv32-esp-elf-gdb" ]
129
+ }
130
+ }
131
+
132
+ # Iterate through MCU mappings
133
+ for supported_mcus , toolchain_data in mcu_toolchain_mapping .items ():
134
+ if mcu in supported_mcus :
135
+ # Set mandatory toolchains
136
+ for toolchain in toolchain_data ["toolchains" ]:
137
+ self .packages [toolchain ]["optional" ] = False
138
+
139
+ # Set ULP toolchain if applicable
140
+ ulp_toolchain = toolchain_data .get ("ulp_toolchain" )
141
+ if ulp_toolchain and os .path .isdir ("ulp" ):
142
+ for toolchain in ulp_toolchain :
143
+ self .packages [toolchain ]["optional" ] = False
144
+ # Install debug tools if conditions match
145
+ if (variables .get ("build_type" ) or "debug" in "" .join (targets )) or variables .get ("upload_protocol" ):
146
+ for debug_tool in toolchain_data ["debug_tools" ]:
147
+ install_tool (debug_tool )
148
+ install_tool ("tool-openocd-esp32" )
149
+ break # Exit loop once MCU is matched
150
+
151
+ # Common packages for IDF and mixed Arduino+IDF projects
152
+ COMMON_IDF_PACKAGES = [
153
+ "tool-cmake" ,
154
+ "tool-ninja" ,
155
+ "tool-scons" ,
156
+ "tool-esp-rom-elfs"
157
+ ]
158
+ if "espidf" in frameworks :
159
+ for package in COMMON_IDF_PACKAGES :
160
+ self .packages [package ]["optional" ] = False
161
+
115
162
# Enable check tools only when "check_tool" is active
116
163
for p in self .packages :
117
164
if p in ("tool-cppcheck" , "tool-clangtidy" , "tool-pvs-studio" ):
@@ -126,9 +173,6 @@ def install_tool(TOOL):
126
173
else :
127
174
self .packages ["tool-mkspiffs" ]["optional" ] = False
128
175
129
- if os .path .isdir ("ulp" ):
130
- self .packages ["toolchain-esp32ulp" ]["optional" ] = False
131
-
132
176
if "downloadfs" in targets :
133
177
filesystem = variables .get ("board_build.filesystem" , "littlefs" )
134
178
if filesystem == "littlefs" :
@@ -141,35 +185,6 @@ def install_tool(TOOL):
141
185
else :
142
186
del self .packages ["tool-dfuutil-arduino" ]
143
187
144
- # install GDB and OpenOCD when debug mode or upload_protocol is set
145
- if (variables .get ("build_type" ) or "debug" in "" .join (targets )) or variables .get ("upload_protocol" ):
146
- for gdb_package in ("tool-xtensa-esp-elf-gdb" , "tool-riscv32-esp-elf-gdb" ):
147
- self .packages [gdb_package ]["optional" ] = False
148
- install_tool ("tool-openocd-esp32" )
149
-
150
- # Common packages for IDF and mixed Arduino+IDF projects
151
- if "espidf" in frameworks :
152
- self .packages ["toolchain-esp32ulp" ]["optional" ] = False
153
- for p in self .packages :
154
- if p in (
155
- "tool-cmake" ,
156
- "tool-ninja" ,
157
- "tool-scons" ,
158
- "tool-esp-rom-elfs" ,
159
- ):
160
- self .packages [p ]["optional" ] = False
161
-
162
- if mcu in ("esp32" , "esp32s2" , "esp32s3" ):
163
- self .packages ["toolchain-xtensa-esp-elf" ]["optional" ] = False
164
- else :
165
- self .packages .pop ("toolchain-xtensa-esp-elf" , None )
166
-
167
- if mcu in ("esp32s2" , "esp32s3" , "esp32c2" , "esp32c3" , "esp32c5" , "esp32c6" , "esp32h2" , "esp32p4" ):
168
- if mcu in ("esp32c2" , "esp32c3" , "esp32c5" , "esp32c6" , "esp32h2" , "esp32p4" ):
169
- self .packages .pop ("toolchain-esp32ulp" , None )
170
- # RISC-V based toolchain for ESP32C2, ESP32C3, ESP32C5 ESP32C6 ESP32S2, ESP32S3 ESP32P4 and ULP
171
- self .packages ["toolchain-riscv32-esp" ]["optional" ] = False
172
-
173
188
return super ().configure_default_packages (variables , targets )
174
189
175
190
def get_boards (self , id_ = None ):
0 commit comments