Skip to content

Commit 151d2e1

Browse files
rlehsalkinium
andcommitted
[scons] Add command to run only OpenOcd
Co-authored-by: Niklas Hauser <[email protected]>
1 parent 5dcdf1d commit 151d2e1

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

tools/build_script_generator/scons/module.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,18 @@ scons program-remote profile={debug|release} [host={ip or hostname}] [firmware={
283283

284284
Writes the executable onto your target connected to a remote OpenOCD process
285285
running on your own computer (host=`localhost`) or somewhere else.
286+
(\* *only ARM Cortex-M targets*)
287+
288+
289+
#### scons openocd
290+
291+
```
292+
scons openocd
293+
```
294+
295+
Starts an OpenOCD process to attach a remote debugger to (e.g. with
296+
`scons program-remote` or `scons debug-remote`).
297+
(\* *only ARM Cortex-M targets*)
286298

287299

288300
#### scons run
@@ -342,7 +354,7 @@ Launches GDB for post-mortem debugging with the firmware identified by the
342354
See the `modm:platform:fault` module for details how to receive the coredump data.
343355

344356

345-
#### scons program-remote
357+
#### scons debug-remote
346358

347359
```
348360
scons debug-remote profile={debug|release} ui={tui|web} [host={ip or hostname}] [firmware={hash or file}]

tools/build_script_generator/scons/resources/build_target.py.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ def build_target(env, sources):
6464
env.Alias("reset-bmp", env.ResetBMP())
6565
env.Alias("reset-remote", env.ResetGdbRemote())
6666

67+
# Start only OpenOCD to attach a external (remote) debugger
68+
env.Alias("openocd", env.OpenOcd())
69+
6770
# Default to OpenOCD
6871
env.Alias("program", "program-openocd")
6972
env.Alias("reset", "reset-openocd")

tools/build_script_generator/scons/site_tools/comstr.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ def generate(env, **kw):
9999
env["ARTIFACT_COMSTR"] = "%s╭───Artifact─── %s$SOURCE\n" \
100100
"%s╰────Cache────> %s$ARTIFACT_FILEPATH%s" % install
101101

102+
env["RUN_OPENOCD_COMSTR"] = "%s╭────────────── %s\n" \
103+
"%s╰───OpenOCD───> %s$CONFIG_DEVICE_NAME%s" % install
104+
102105
env["DEBUG_OPENOCD_COMSTR"] = "%s╭─────GDB─────> %s$SOURCE\n" \
103106
"%s╰───OpenOCD───> %s$CONFIG_DEVICE_NAME%s" % install
104107

tools/build_script_generator/scons/site_tools/openocd.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,23 @@ def call_reset_openocd(target, source, env):
6262
action = Action(call_reset_openocd, cmdstr="$RESET_OPENOCD_COMSTR")
6363
return env.AlwaysBuild(env.Alias(alias, '', action))
6464

65+
# -----------------------------------------------------------------------------
66+
def run_openocd(env, alias="run_openocd"):
67+
def call_run_openocd(target, source, env):
68+
config = env.Listify(env.get("MODM_OPENOCD_CONFIGFILES", []))
69+
searchdir = env.Listify(env.get("MODM_OPENOCD_SEARCHDIRS", []))
70+
openocd.call(config=map(env.subst, config),
71+
search=map(env.subst, searchdir), verbose=True)
72+
73+
action = Action(call_run_openocd, cmdstr="$RUN_OPENOCD_COMSTR")
74+
return env.AlwaysBuild(env.Alias(alias, '', action))
75+
6576
# -----------------------------------------------------------------------------
6677
def generate(env, **kw):
6778
env.AddMethod(program_openocd, "ProgramOpenOcd")
6879
env.AddMethod(debug_openocd, "DebugOpenOcd")
6980
env.AddMethod(reset_openocd, "ResetOpenOcd")
81+
env.AddMethod(run_openocd, "OpenOcd")
7082

7183
def exists(env):
7284
return env.Detect("openocd")

tools/modm_tools/openocd.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def stop(self):
6666

6767

6868
# -----------------------------------------------------------------------------
69-
def call(commands=None, config=None, search=None, blocking=True, silent=False):
69+
def call(commands=None, config=None, search=None, blocking=True, silent=False, verbose=False):
7070
commands = utils.listify(commands)
7171
config = utils.listify(config)
7272
search = utils.listify(search)
@@ -83,7 +83,8 @@ def call(commands=None, config=None, search=None, blocking=True, silent=False):
8383
" ".join(map('-f "{}"'.format, config)),
8484
" ".join(map('-c "{}"'.format, commands))
8585
)
86-
# print(command_openocd)
86+
if verbose:
87+
print(command_openocd)
8788

8889
kwargs = {"cwd": os.getcwd(), "shell": True}
8990
if blocking:

0 commit comments

Comments
 (0)