Skip to content

Commit 0dbb36d

Browse files
committed
Automatically configure openOCD scripts folder
1 parent cb35c87 commit 0dbb36d

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

builder/main.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _update_max_upload_size(env):
9393
if p['type'] in ("0", "app")
9494
]
9595
if sizes:
96-
env.BoardConfig().update("upload.maximum_size", max(sizes))
96+
board.update("upload.maximum_size", max(sizes))
9797

9898

9999
def _to_unix_slashes(path):
@@ -129,6 +129,7 @@ def __fetch_spiffs_size(target, source, env):
129129

130130
env = DefaultEnvironment()
131131
platform = env.PioPlatform()
132+
board = env.BoardConfig()
132133

133134
env.Replace(
134135
__get_board_f_flash=_get_board_f_flash,
@@ -177,8 +178,7 @@ def __fetch_spiffs_size(target, source, env):
177178
"elf2image",
178179
"--flash_mode", "$BOARD_FLASH_MODE",
179180
"--flash_freq", "${__get_board_f_flash(__env__)}",
180-
"--flash_size", env.BoardConfig().get(
181-
"upload.flash_size", "detect"),
181+
"--flash_size", board.get("upload.flash_size", "detect"),
182182
"-o", "$TARGET", "$SOURCES"
183183
]), "Building $TARGET"),
184184
suffix=".bin"
@@ -252,7 +252,7 @@ def __fetch_spiffs_size(target, source, env):
252252
#
253253

254254
upload_protocol = env.subst("$UPLOAD_PROTOCOL")
255-
debug_tools = env.BoardConfig().get("debug.tools", {})
255+
debug_tools = board.get("debug.tools", {})
256256
upload_actions = []
257257

258258
# Compatibility with old OTA configurations
@@ -328,27 +328,31 @@ def __fetch_spiffs_size(target, source, env):
328328
]
329329

330330
elif upload_protocol in debug_tools:
331-
openocd_dir = platform.get_package_dir("tool-openocd-esp32") or ""
332-
uploader_flags = ["-s", _to_unix_slashes(openocd_dir)]
333-
if not int(ARGUMENTS.get("PIOVERBOSE", 0)):
334-
uploader_flags.append("--debug=1")
335-
uploader_flags.extend(
331+
openocd_args = ["-d%d" % (2 if int(ARGUMENTS.get("PIOVERBOSE", 0)) else 1)]
332+
openocd_args.extend(
336333
debug_tools.get(upload_protocol).get("server").get("arguments", []))
337-
uploader_flags.extend(["-c", 'program_esp32 {{$SOURCE}} 0x10000 verify'])
334+
openocd_args.extend([
335+
"-c",
336+
"program_esp32 {{$SOURCE}} %s verify" %
337+
board.get("upload.offset_address", "0x10000")
338+
])
338339
for image in env.get("FLASH_EXTRA_IMAGES", []):
339-
uploader_flags.extend(
340-
["-c", 'program_esp32 {{%s}} %s verify' % (
341-
_to_unix_slashes(image[1]), image[0])])
342-
uploader_flags.extend(["-c", "reset run; shutdown"])
343-
for i, item in enumerate(uploader_flags):
344-
if "$PACKAGE_DIR" in item:
345-
uploader_flags[i] = item.replace(
346-
"$PACKAGE_DIR", _to_unix_slashes(openocd_dir))
347-
348-
env.Replace(
349-
UPLOADER="openocd",
350-
UPLOADERFLAGS=uploader_flags,
351-
UPLOADCMD="$UPLOADER $UPLOADERFLAGS")
340+
openocd_args.extend([
341+
"-c",
342+
'program_esp32 {{%s}} %s verify' %
343+
(_to_unix_slashes(image[1]), image[0])
344+
])
345+
openocd_args.extend(["-c", "reset run; shutdown"])
346+
openocd_args = [
347+
f.replace(
348+
"$PACKAGE_DIR",
349+
_to_unix_slashes(
350+
platform.get_package_dir("tool-openocd-esp32") or ""))
351+
for f in openocd_args
352+
]
353+
env.Replace(UPLOADER="openocd",
354+
UPLOADERFLAGS=openocd_args,
355+
UPLOADCMD="$UPLOADER $UPLOADERFLAGS")
352356
upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")]
353357

354358
# custom upload tool
@@ -366,7 +370,8 @@ def __fetch_spiffs_size(target, source, env):
366370

367371
AlwaysBuild(
368372
env.Alias("erase", None, [
369-
env.VerboseAction(env.AutodetectUploadPort, "Looking for serial port..."),
373+
env.VerboseAction(env.AutodetectUploadPort,
374+
"Looking for serial port..."),
370375
env.VerboseAction("$ERASECMD", "Erasing...")
371376
]))
372377

platform.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def _add_dynamic_options(self, board):
8484

8585
server_args = [
8686
"-s", "$PACKAGE_DIR/share/openocd/scripts",
87-
"-f", "share/openocd/scripts/interface/%s.cfg" % openocd_interface,
88-
"-f", "share/openocd/scripts/board/%s" % debug.get("openocd_board")
87+
"-f", "interface/%s.cfg" % openocd_interface,
88+
"-f", "board/%s" % debug.get("openocd_board")
8989
]
9090

9191
debug['tools'][link] = {

0 commit comments

Comments
 (0)