Skip to content

Commit

Permalink
Merge #19541
Browse files Browse the repository at this point in the history
19541: makefiles/tools/jlink.inc.mk: use ELF file for flashing r=maribu a=maribu

### Contribution description

There seems to be a consensus to go for a more ELF centric approach whenever possible. J-Link seems to work fine with ELF files, so let's avoid the extra step to create a bin file from the ELF file prior to flashing.


Co-authored-by: Marian Buschsieweke <[email protected]>
  • Loading branch information
bors[bot] and maribu authored May 4, 2023
2 parents 2c8fc24 + 93561c7 commit ae51cbc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 25 deletions.
1 change: 0 additions & 1 deletion boards/rpi-pico/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ PORT_LINUX ?= /dev/ttyUSB0

ifeq ($(PROGRAMMER),jlink)
JLINK_DEVICE = RP2040_M0_0
FLASHFILE = $(ELFFILE)
endif
73 changes: 50 additions & 23 deletions dist/tools/jlink/jlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
#
# The script supports the following actions:
#
# flash: flash <binfile>
# flash: flash <binfile/elffile>
#
# flash given binary format file to the target.
# flash given file to the target.
#
# options:
# <binfile>: path to the binary file that is flashed
# <binfile>: path to the file in bin format that is flashed
# <elffile>: path to the file in ELF format that is flashed
# NOTE: The file needs to be suffixed `.elf` when
# in ELF format.
#
# debug: debug <elffile>
#
Expand Down Expand Up @@ -176,28 +179,14 @@ test_version() {
fi
}

#
# now comes the actual actions
#
do_flash() {
BINFILE=$1
flash_common() {
test_config
test_serial
test_version
test_binfile
# clear any existing contents in burn file
/bin/echo -n "" > ${BINDIR}/burn.seg
# create temporary burn file
if [ ! -z "${JLINK_PRE_FLASH}" ]; then
printf "${JLINK_PRE_FLASH}\n" >> ${BINDIR}/burn.seg
if [ -n "${JLINK_POST_FLASH}" ]; then
printf "%s\n" "${JLINK_POST_FLASH}" >> "${BINDIR}/burn.seg"
fi
# address to flash is hex formatted, as required by JLink
ADDR_TO_FLASH=$(printf "0x%08x\n" "$((${FLASH_ADDR} + ${IMAGE_OFFSET}))")
echo "loadbin ${BINFILE} ${ADDR_TO_FLASH}" >> ${BINDIR}/burn.seg
if [ ! -z "${JLINK_POST_FLASH}" ]; then
printf "${JLINK_POST_FLASH}\n" >> ${BINDIR}/burn.seg
fi
cat ${JLINK_RESET_FILE} >> ${BINDIR}/burn.seg
cat "${JLINK_RESET_FILE}" >> "${BINDIR}/burn.seg"
# flash device
sh -c "${JLINK} ${JLINK_SERIAL} \
-nogui 1 \
Expand All @@ -209,6 +198,37 @@ do_flash() {
-commandfile '${BINDIR}/burn.seg'"
}

#
# now comes the actual actions
#
do_flash_bin() {
BINFILE="$1"
test_binfile
# clear any existing contents in burn file
truncate -s 0 "${BINDIR}/burn.seg"
# create temporary burn file
if [ -n "${JLINK_PRE_FLASH}" ]; then
printf "%s\n" "${JLINK_PRE_FLASH}" >> "${BINDIR}/burn.seg"
fi
# address to flash is hex formatted, as required by JLink
ADDR_TO_FLASH="$(printf "0x%08x\n" "$((FLASH_ADDR + IMAGE_OFFSET))")"
echo "loadbin ${BINFILE} ${ADDR_TO_FLASH}" >> "${BINDIR}/burn.seg"
flash_common
}

do_flash_elf() {
ELFFILE="$1"
test_elffile
# clear any existing contents in burn file
truncate -s 0 "${BINDIR}/burn.seg"
# create temporary burn file
if [ -n "${JLINK_PRE_FLASH}" ]; then
printf "%s\n" "${JLINK_PRE_FLASH}" >> "${BINDIR}/burn.seg"
fi
echo "loadfile ${ELFFILE}" >> "${BINDIR}/burn.seg"
flash_common
}

do_debug() {
ELFFILE=$1
test_config
Expand Down Expand Up @@ -309,8 +329,15 @@ shift # pop $1 from $@
case "${ACTION}" in
flash)
echo "### Flashing Target ###"
echo "### Flashing at base address ${FLASH_ADDR} with offset ${IMAGE_OFFSET} ###"
do_flash "$@"
case "$1" in
*.elf)
echo "### Flashing elf file ###"
do_flash_elf "$@"
;;
*)
echo "### Flashing bin file at base address ${FLASH_ADDR} with offset ${IMAGE_OFFSET} ###"
do_flash_bin "$@"
esac
;;
debug)
echo "### Starting Debugging ###"
Expand Down
2 changes: 1 addition & 1 deletion makefiles/tools/jlink.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ DEBUGGER ?= $(RIOTTOOLS)/jlink/jlink.sh
DEBUGSERVER ?= $(RIOTTOOLS)/jlink/jlink.sh
RESET ?= $(RIOTTOOLS)/jlink/jlink.sh

FLASHFILE ?= $(BINFILE)
FLASHFILE ?= $(ELFFILE)

FFLAGS ?= flash $(FLASHFILE)
DEBUGGER_FLAGS ?= debug $(DEBUG_ELFFILE)
Expand Down

0 comments on commit ae51cbc

Please sign in to comment.