From 1ec4ea2d7c3e4bda2a727301901b5c57f17c430b Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Thu, 18 Feb 2021 11:19:48 +0100 Subject: [PATCH 1/2] tools/edbg: add wrapper bash script --- dist/tools/edbg/edbg.sh | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 dist/tools/edbg/edbg.sh diff --git a/dist/tools/edbg/edbg.sh b/dist/tools/edbg/edbg.sh new file mode 100755 index 0000000000..e1ee99874f --- /dev/null +++ b/dist/tools/edbg/edbg.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +# Default edbg command +: "${EDBG:=edbg}" +# Edbg command base arguments +: "${EDBG_ARGS:=}" + +test_imagefile() { + if [ ! -f "${IMAGE_FILE}" ]; then + echo "Error: Unable to locate IMAGE_FILE" + echo " (${IMAGE_FILE})" + exit 1 + fi +} + +do_flash() { + IMAGE_FILE=$1 + test_imagefile + + # Configure edbg flash flags + local _fflags="${EDBG_ARGS} --verbose --file ${IMAGE_FILE} --verify" + + # flash device + sh -c "${EDBG} ${_fflags} || ${EDBG} ${_fflags} --program" && echo 'Done flashing' +} + +do_reset() { + sh -c "${EDBG} ${EDBG_ARGS}" +} + +# +# parameter dispatching +# +ACTION="$1" +shift # pop $1 from $@ + +case "${ACTION}" in + flash) + echo "### Flashing Target ###" + do_flash "$@" + ;; + reset) + echo "### Resetting Target ###" + do_reset + ;; + *) + echo "Usage: $0 {flash|reset}" + echo " flash " + exit 2 + ;; +esac From 9153e39dab2ee8349e3e5772c5194d081f90e460 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Thu, 18 Feb 2021 11:20:13 +0100 Subject: [PATCH 2/2] makefiles/edbg: refactor to use wrapper script --- makefiles/tools/edbg.inc.mk | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/makefiles/tools/edbg.inc.mk b/makefiles/tools/edbg.inc.mk index 2fe20b1084..75137f9c14 100644 --- a/makefiles/tools/edbg.inc.mk +++ b/makefiles/tools/edbg.inc.mk @@ -1,9 +1,11 @@ include $(RIOTMAKE)/tools/edbg-devices.inc.mk -RIOT_EDBG = $(RIOTTOOLS)/edbg/edbg -EDBG ?= $(RIOT_EDBG) -FLASHER ?= $(EDBG) +# Edbg use a bin file for flashing FLASHFILE ?= $(BINFILE) + +EDBG ?= $(RIOTTOOLS)/edbg/edbg +FLASHDEPS += $(EDBG) + # Use USB serial number to select device when more than one is connected # Use /dist/tools/usb-serial/list-ttys.sh to find out serial number. # Usage: @@ -15,22 +17,21 @@ endif # Set offset according to IMAGE_OFFSET if it's defined EDBG_ARGS += $(if $(IMAGE_OFFSET),--offset $(IMAGE_OFFSET)) +EDBG_ARGS += --target $(EDBG_DEVICE_TYPE) -FFLAGS ?= $(EDBG_ARGS) --target $(EDBG_DEVICE_TYPE) --verbose \ - --file $(FLASHFILE) +EDBG_TARGETS = flash flash-only reset +# Export EDBG to required targets +$(call target-export-variables,$(EDBG_TARGETS),EDBG) -ifeq ($(RIOT_EDBG),$(FLASHER)) - FLASHDEPS += $(RIOT_EDBG) -endif -RESET ?= $(EDBG) -RESET_FLAGS ?= $(EDBG_ARGS) --target $(EDBG_DEVICE_TYPE) +# Export EDBG_ARGS to required targets +$(call target-export-variables,$(EDBG_TARGETS),EDBG_ARGS) -define edbg-flash-recipe - $(call check_cmd,$(FLASHER),Flash program) - $(FLASHER) $(FFLAGS) --verify || $(FLASHER) $(FFLAGS) --verify --program -endef +# Set flasher and reset for the RIOT build system +FLASHER ?= $(RIOTTOOLS)/edbg/edbg.sh +FFLAGS ?= flash $(FLASHFILE) -flash-recipe = $(edbg-flash-recipe) +RESET ?= $(RIOTTOOLS)/edbg/edbg.sh +RESET_FLAGS ?= reset # use openocd for debugging, must be included at the end so FLASHER/RESET # variables are already set for edbg.