Skip to content

Commit

Permalink
[cortex-m] Communicate the flash_offset to the dfu-util tool
Browse files Browse the repository at this point in the history
  • Loading branch information
el-han committed May 14, 2024
1 parent f01fd0a commit 19bfa81
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions tools/build_script_generator/cmake/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def post_build(env):
if subs["core"].startswith("cortex-m"):
# get memory information
subs["memories"] = env.query("::memories")
subs["flash_offset"] = env.get(":platform:cortex-m:linkerscript.flash_offset", 0)
subs["flash_address"] = hex(0x08000000 + subs["flash_offset"])
else:
subs["memories"] = []
# Set these substitutions for all templates
Expand Down
2 changes: 2 additions & 0 deletions tools/build_script_generator/make/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def post_build(env):
subs["uf2mem"] = ["{:#x}:{:#x}:{}".format(m["start"], m["start"] + m["size"],
"CONTENTS" if "flash" in m["name"] else "NO_CONTENTS")
for m in subs["memories"]]
subs["flash_offset"] = env.get(":platform:cortex-m:linkerscript.flash_offset", 0)
subs["flash_address"] = hex(0x08000000 + subs["flash_offset"])
else:
subs["memories"] = []
# Add SCons specific data
Expand Down
3 changes: 2 additions & 1 deletion tools/build_script_generator/make/resources/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ program-jlink: build
@$(PYTHON3) -m modm_tools.jlink -device $(MODM_JLINK_DEVICE) $(ELF_FILE)

delay?=5
CONFIG_FLASH_ADDRESS?=0x08000000
.PHONY: program-dfu
program-dfu: bin
@dfu-util -v -E$(delay) -R -i 0 -a 0 -s 0x08000000:leave -D $(BIN_FILE)
@dfu-util -v -E$(delay) -R -i 0 -a 0 -s $(CONFIG_FLASH_ADDRESS):leave -D $(BIN_FILE)
%#
%% if platform in ["sam"]
.PHONY: program-bossac
Expand Down
2 changes: 2 additions & 0 deletions tools/build_script_generator/make/resources/config.mk.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ MODM_GDB_COMMANDS = -x $(MODM_PATH)/gdbinit -ex "dir $(GCC_BASE)" -ex "modm_setu
MODM_GDB_COMMANDS_OPENOCD = -x $(MODM_PATH)/gdbinit_openocd
MODM_GDB_COMMANDS_JLINK = -x $(MODM_PATH)/gdbinit_jlink
MODM_GDB_COMMANDS_BMP = -x $(MODM_PATH)/gdbinit_bmp
CONFIG_FLASH_OFFSET := {{ flash_offset }}
CONFIG_FLASH_ADDRESS := {{ flash_address }}
%% if platform == "sam"
%% if bossac_offset
MODM_BOSSAC_OFFSET := {{ bossac_offset }}
Expand Down
2 changes: 2 additions & 0 deletions tools/build_script_generator/scons/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ def post_build(env):
if subs["core"].startswith("cortex-m"):
# get memory information
subs["memories"] = env.query("::memories")
subs["flash_offset"] = env.get(":platform:cortex-m:linkerscript.flash_offset", 0)
subs["flash_address"] = hex(0x08000000 + subs["flash_offset"])
else:
subs["memories"] = []
# Add SCons specific data
Expand Down
6 changes: 6 additions & 0 deletions tools/build_script_generator/scons/resources/SConscript.in
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ env.Append(MODM_GDBINIT_OPENOCD = "$BASEPATH/modm/gdbinit_openocd")
env.Append(MODM_GDBINIT_JLINK = "$BASEPATH/modm/gdbinit_jlink")
env.Append(MODM_GDBINIT_BMP = "$BASEPATH/modm/gdbinit_bmp")
env.Append(MODM_GDB_COMMANDS = ["dir $GCC_PATH", "modm_setup_tui"])

%% if core.startswith("cortex-m")
env["CONFIG_FLASH_OFFSET"] = {{ flash_offset }}
env["CONFIG_FLASH_ADDRESS"] = {{ flash_address }}
%% endif

%% if platform == "sam"
%% if bossac_offset
env.Append(MODM_BOSSAC_OFFSET = {{ bossac_offset }})
Expand Down
3 changes: 2 additions & 1 deletion tools/build_script_generator/scons/site_tools/dfu.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
# -----------------------------------------------------------------------------
def program_dfu(env, source):
delay = ARGUMENTS.get("delay", "5")
actionString = 'dfu-util -v -E{} -R -i 0 -a 0 -s 0x08000000:leave -D $SOURCE'.format(delay)
flash_address = env.get("CONFIG_FLASH_ADDRESS", 0x08000000)
actionString = 'dfu-util -v -E{} -R -i 0 -a 0 -s {}:leave -D $SOURCE'.format(delay, flash_address)
return env.AlwaysBuildAction(actionString, "$PROGRAM_DFU_COMSTR", source)

# -----------------------------------------------------------------------------
Expand Down

0 comments on commit 19bfa81

Please sign in to comment.