Skip to content

Commit

Permalink
[scons] Add command to run only OpenOcd
Browse files Browse the repository at this point in the history
Co-authored-by: Niklas Hauser <niklas.hauser@rwth-aachen.de>
  • Loading branch information
rleh and salkinium committed Oct 28, 2021
1 parent 5dcdf1d commit 151d2e1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
14 changes: 13 additions & 1 deletion tools/build_script_generator/scons/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,18 @@ scons program-remote profile={debug|release} [host={ip or hostname}] [firmware={

Writes the executable onto your target connected to a remote OpenOCD process
running on your own computer (host=`localhost`) or somewhere else.
(\* *only ARM Cortex-M targets*)


#### scons openocd

```
scons openocd
```

Starts an OpenOCD process to attach a remote debugger to (e.g. with
`scons program-remote` or `scons debug-remote`).
(\* *only ARM Cortex-M targets*)


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


#### scons program-remote
#### scons debug-remote

```
scons debug-remote profile={debug|release} ui={tui|web} [host={ip or hostname}] [firmware={hash or file}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def build_target(env, sources):
env.Alias("reset-bmp", env.ResetBMP())
env.Alias("reset-remote", env.ResetGdbRemote())

# Start only OpenOCD to attach a external (remote) debugger
env.Alias("openocd", env.OpenOcd())

# Default to OpenOCD
env.Alias("program", "program-openocd")
env.Alias("reset", "reset-openocd")
Expand Down
3 changes: 3 additions & 0 deletions tools/build_script_generator/scons/site_tools/comstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def generate(env, **kw):
env["ARTIFACT_COMSTR"] = "%s╭───Artifact─── %s$SOURCE\n" \
"%s╰────Cache────> %s$ARTIFACT_FILEPATH%s" % install

env["RUN_OPENOCD_COMSTR"] = "%s╭────────────── %s\n" \
"%s╰───OpenOCD───> %s$CONFIG_DEVICE_NAME%s" % install

env["DEBUG_OPENOCD_COMSTR"] = "%s╭─────GDB─────> %s$SOURCE\n" \
"%s╰───OpenOCD───> %s$CONFIG_DEVICE_NAME%s" % install

Expand Down
12 changes: 12 additions & 0 deletions tools/build_script_generator/scons/site_tools/openocd.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,23 @@ def call_reset_openocd(target, source, env):
action = Action(call_reset_openocd, cmdstr="$RESET_OPENOCD_COMSTR")
return env.AlwaysBuild(env.Alias(alias, '', action))

# -----------------------------------------------------------------------------
def run_openocd(env, alias="run_openocd"):
def call_run_openocd(target, source, env):
config = env.Listify(env.get("MODM_OPENOCD_CONFIGFILES", []))
searchdir = env.Listify(env.get("MODM_OPENOCD_SEARCHDIRS", []))
openocd.call(config=map(env.subst, config),
search=map(env.subst, searchdir), verbose=True)

action = Action(call_run_openocd, cmdstr="$RUN_OPENOCD_COMSTR")
return env.AlwaysBuild(env.Alias(alias, '', action))

# -----------------------------------------------------------------------------
def generate(env, **kw):
env.AddMethod(program_openocd, "ProgramOpenOcd")
env.AddMethod(debug_openocd, "DebugOpenOcd")
env.AddMethod(reset_openocd, "ResetOpenOcd")
env.AddMethod(run_openocd, "OpenOcd")

def exists(env):
return env.Detect("openocd")
5 changes: 3 additions & 2 deletions tools/modm_tools/openocd.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def stop(self):


# -----------------------------------------------------------------------------
def call(commands=None, config=None, search=None, blocking=True, silent=False):
def call(commands=None, config=None, search=None, blocking=True, silent=False, verbose=False):
commands = utils.listify(commands)
config = utils.listify(config)
search = utils.listify(search)
Expand All @@ -83,7 +83,8 @@ def call(commands=None, config=None, search=None, blocking=True, silent=False):
" ".join(map('-f "{}"'.format, config)),
" ".join(map('-c "{}"'.format, commands))
)
# print(command_openocd)
if verbose:
print(command_openocd)

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

0 comments on commit 151d2e1

Please sign in to comment.