2023-05-03 05:48:49 +00:00
|
|
|
import SCons
|
2022-06-26 12:00:03 +00:00
|
|
|
from SCons.Action import Action
|
2023-05-03 05:48:49 +00:00
|
|
|
from SCons.Builder import Builder
|
2022-06-26 12:00:03 +00:00
|
|
|
from SCons.Defaults import Touch
|
|
|
|
|
|
|
|
__OPENOCD_BIN = "openocd"
|
|
|
|
|
2023-11-15 16:27:35 +00:00
|
|
|
# TODO: FL-3663: rework argument passing to lists
|
2022-06-26 12:00:03 +00:00
|
|
|
_oocd_action = Action(
|
|
|
|
"${OPENOCD} ${OPENOCD_OPTS} ${OPENOCD_COMMAND}",
|
2022-06-30 16:06:12 +00:00
|
|
|
"${OPENOCDCOMSTR}",
|
2022-06-26 12:00:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def generate(env):
|
|
|
|
env.SetDefault(
|
|
|
|
OPENOCD=__OPENOCD_BIN,
|
|
|
|
OPENOCD_OPTS="",
|
|
|
|
OPENOCD_COMMAND="",
|
2022-06-30 16:06:12 +00:00
|
|
|
OPENOCDCOM="${OPENOCD} ${OPENOCD_OPTS} ${OPENOCD_COMMAND}",
|
|
|
|
OPENOCDCOMSTR="",
|
2022-06-26 12:00:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
env.Append(
|
|
|
|
BUILDERS={
|
2022-06-30 16:06:12 +00:00
|
|
|
"OpenOCDFlash": Builder(
|
2022-06-26 12:00:03 +00:00
|
|
|
action=[
|
|
|
|
_oocd_action,
|
|
|
|
Touch("${TARGET}"),
|
|
|
|
],
|
|
|
|
suffix=".flash",
|
|
|
|
src_suffix=".bin",
|
|
|
|
),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def exists(env):
|
|
|
|
try:
|
|
|
|
return env["OPENOCD"]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if openocd := env.WhereIs(__OPENOCD_BIN):
|
|
|
|
return openocd
|
|
|
|
|
|
|
|
raise SCons.Errors.StopError("Could not detect openocd")
|