Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

makefiles/tools/jlink.inc.mk: use ELF file for flashing #19541

Merged
merged 3 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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