diff --git a/Makefile.include b/Makefile.include index 902a30950aba1d9cd46db761f403328358e6fc56..71f4cacd069b1e76aac65b0ae6621023f78e6297 100644 --- a/Makefile.include +++ b/Makefile.include @@ -360,13 +360,16 @@ distclean: -@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTPKG)/$$i distclean ; done -@rm -rf $(BINDIRBASE) -flash: all +flash: all $(FLASHDEPS) @command -v $(FLASHER) >/dev/null 2>&1 || \ { $(COLOR_ECHO) \ '${COLOR_RED}Flash program $(FLASHER) not found. Aborting.${COLOR_RESET}'; \ exit 1; } $(FLASHER) $(FFLAGS) +preflash: all + $(PREFLASHER) $(PREFFLAGS) + term: $(filter flash, $(MAKECMDGOALS)) @command -v $(TERMPROG) >/dev/null 2>&1 || \ { $(COLOR_ECHO) \ @@ -430,6 +433,10 @@ include $(RIOTMAKE)/features.inc.mk # Export variables used throughout the whole make system: include $(RIOTMAKE)/vars.inc.mk +# Include build targets for selected tools after the default RIOT targets have +# been defined (-> so the `all` will be always the first target) +include $(RIOTMAKE)/tools/targets.inc.mk + # Warn if the selected board and drivers don't provide all needed features: ifneq (, $(filter all, $(if $(MAKECMDGOALS), $(MAKECMDGOALS), all))) EXPECT_ERRORS := diff --git a/boards/arduino-due/Makefile.include b/boards/arduino-due/Makefile.include index a943e194c3cc2eba5c6f7c9ba9e4f3ccb26ef031..ddc00645084279f13420a8a4fed0a2658549bfc6 100644 --- a/boards/arduino-due/Makefile.include +++ b/boards/arduino-due/Makefile.include @@ -6,9 +6,9 @@ export CPU_MODEL = sam3x8e PORT_LINUX ?= /dev/ttyACM0 PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbmodem*))) -# define board specific flasher options -export FLASHER = $(RIOTBOARD)/$(BOARD)/dist/flash.sh -export OFLAGS = -O binary - # setup serial terminal include $(RIOTMAKE)/tools/serial.inc.mk + +# setup flasher (using BOSSA) +export BOSSA_ARDUINO_PREFLASH = yes +include $(RIOTMAKE)/tools/bossa.inc.mk diff --git a/boards/arduino-due/dist/bossac b/boards/arduino-due/dist/bossac deleted file mode 100755 index 573e7d9e7716acf1d885f88da3f523cce67cb0da..0000000000000000000000000000000000000000 Binary files a/boards/arduino-due/dist/bossac and /dev/null differ diff --git a/boards/arduino-due/dist/bossac_osx b/boards/arduino-due/dist/bossac_osx deleted file mode 100755 index 49a20b38a92e713bcc25b15de464642bc257220b..0000000000000000000000000000000000000000 Binary files a/boards/arduino-due/dist/bossac_osx and /dev/null differ diff --git a/boards/arduino-due/dist/flash.sh b/boards/arduino-due/dist/flash.sh deleted file mode 100755 index d61326e20c572155ccb6581912343baf30f9449e..0000000000000000000000000000000000000000 --- a/boards/arduino-due/dist/flash.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -if [ `uname` = "Linux" ]; then - stty -F "${PORT}" raw ispeed 1200 ospeed 1200 cs8 -cstopb ignpar eol 255 eof 255 - "${RIOTBOARD}"/"${BOARD}"/dist/bossac -R -e -w -v -b "${HEXFILE}" -elif [ `uname` = "Darwin" ]; then - stty -f ${PORT} raw ispeed 1200 ospeed 1200 cs8 -cstopb ignpar eol 255 eof 255 - "${RIOTBOARD}"/"${BOARD}"/dist/bossac_osx -R -e -w -v -b "${HEXFILE}" -else - echo "CAUTION: No flash tool for your host system found!" -fi diff --git a/boards/arduino-mkr1000/Makefile.include b/boards/arduino-mkr1000/Makefile.include index 42923676a3997060b1d651b4785bd7f9100e2906..12635c8263a5bf238ab6815f57de4b849a0542dd 100644 --- a/boards/arduino-mkr1000/Makefile.include +++ b/boards/arduino-mkr1000/Makefile.include @@ -6,23 +6,19 @@ export CPU_MODEL = samd21g18a export PORT_LINUX ?= /dev/ttyACM0 export PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbmodem*))) +# setup serial terminal +include $(RIOTMAKE)/tools/serial.inc.mk + +# setup the flash tool used ifeq ($(PROGRAMMER),jlink) # in case J-Link is attached to SWD pins, use a plain CPU memory model export JLINK_DEVICE := atsamw25 include $(RIOTMAKE)/tools/jlink.inc.mk else - # when BOSSA is used (default), use a different flash map - # refer https://github.com/shumatech/BOSSA for this programmer - export PROGRAMMER = bossa + # on default, we use BOSSA to flash this board export LINKER_SCRIPT ?= $(RIOTCPU)/sam0_common/ldscripts/$(CPU_MODEL)_mkr1000.ld - - # define board specific flasher options - export FLASHER = $(RIOTBOARD)/$(BOARD)/dist/flash.sh - export OFLAGS = -O binary + include $(RIOTMAKE)/tools/bossa.inc.mk endif -# setup serial terminal -include $(RIOTMAKE)/tools/serial.inc.mk - # setup the boards dependencies include $(RIOTBOARD)/$(BOARD)/Makefile.dep diff --git a/boards/arduino-mkr1000/dist/bossac b/boards/arduino-mkr1000/dist/bossac deleted file mode 100755 index 2a4fb679ffd2eb847bd82e416a9dab39777d5d99..0000000000000000000000000000000000000000 Binary files a/boards/arduino-mkr1000/dist/bossac and /dev/null differ diff --git a/boards/arduino-mkr1000/dist/bossac_osx b/boards/arduino-mkr1000/dist/bossac_osx deleted file mode 100755 index 49a20b38a92e713bcc25b15de464642bc257220b..0000000000000000000000000000000000000000 Binary files a/boards/arduino-mkr1000/dist/bossac_osx and /dev/null differ diff --git a/boards/arduino-mkr1000/dist/flash.sh b/boards/arduino-mkr1000/dist/flash.sh deleted file mode 100755 index 8f928de7fd215887dc6800c5a025704ddeaad5c0..0000000000000000000000000000000000000000 --- a/boards/arduino-mkr1000/dist/flash.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -# To put the board in update mode, manually double press the reset button before -# running `make flash`. - -if [ `uname` = "Linux" ]; then - stty -F "${PORT}" raw ispeed 1200 ospeed 1200 cs8 -cstopb ignpar eol 255 eof 255 - "${RIOTBOARD}"/"${BOARD}"/dist/bossac --port=${PORT} -i -b -U true -i -e -w -v "${HEXFILE}" -R -elif [ `uname` = "Darwin" ]; then - stty -f ${PORT} raw ispeed 1200 ospeed 1200 cs8 -cstopb ignpar eol 255 eof 255 - "${RIOTBOARD}"/"${BOARD}"/dist/bossac_osx --port=${PORT} -i -b -U true -i -e -w -v "${HEXFILE}" -R -else - echo "CAUTION: No flash tool for your host system found!" -fi diff --git a/boards/udoo/Makefile.include b/boards/udoo/Makefile.include index f566c727b51805a2d88130b3f489a0163f66ac55..de164e968de38d07c16ec8db02b6b74b6d57b840 100644 --- a/boards/udoo/Makefile.include +++ b/boards/udoo/Makefile.include @@ -2,23 +2,13 @@ export CPU = sam3 export CPU_MODEL = sam3x8e -#define the flash-tool and default port depending on the host operating system -OS := $(shell uname) -ifeq ($(OS),Linux) - PORT ?= /dev/ttyUSB0 - FLASHER = $(RIOTBOARD)/$(BOARD)/dist/bossac_udoo -else ifeq ($(OS),Darwin) - PORT = /dev/tty.SLAB_USBtoUART - FLASHER = $(RIOTBOARD)/$(BOARD)/dist/bossac_udoo_osx -else - $(info CAUTION: No flash tool for your host system found!) - # TODO: add support for windows as host platform -endif -export FLASHER -export PORT - -export OFLAGS = -O binary -export FFLAGS = -R -e -w -v -b bin/$(BOARD)/$(APPLICATION).hex +# define the default port depending on host OS +PORT_LINUX ?= /dev/ttyACM0 +PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbmodem*))) # setup serial terminal include $(RIOTMAKE)/tools/serial.inc.mk + +# setup the flash tool (BOSSA) +export BOSSA_ARDUINO_PREFLASH = yes +include $(RIOTMAKE)/tools/bossa.inc.mk diff --git a/boards/udoo/dist/bossac_udoo b/boards/udoo/dist/bossac_udoo deleted file mode 100755 index 14fd8d8db212639f36190faef19b398f980ed0a6..0000000000000000000000000000000000000000 Binary files a/boards/udoo/dist/bossac_udoo and /dev/null differ diff --git a/boards/udoo/dist/bossac_udoo_osx b/boards/udoo/dist/bossac_udoo_osx deleted file mode 100755 index 9d3d9e3d11a252fde79e831c315fd5ea46a41c4b..0000000000000000000000000000000000000000 Binary files a/boards/udoo/dist/bossac_udoo_osx and /dev/null differ diff --git a/dist/tools/bossa/.gitignore b/dist/tools/bossa/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..923a11211e059efa0300a67ad73fdb3d0d82917c --- /dev/null +++ b/dist/tools/bossa/.gitignore @@ -0,0 +1,2 @@ +bossac +bin diff --git a/dist/tools/bossa/Makefile b/dist/tools/bossa/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..345ee63580e9a6e8886ab0ccf465fe0a20fd6a7d --- /dev/null +++ b/dist/tools/bossa/Makefile @@ -0,0 +1,17 @@ +PKG_NAME = bossa +PKG_URL = https://github.com/shumatech/BOSSA +PKG_VERSION = 26154375695f345491bba158d57177aa231d6765 +PKG_LICENSE = BSD-3-Clause +PKG_BUILDDIR = $(CURDIR)/bin + +.PHONY: all + +all: git-download + @echo "[INFO] compiling bossac from source now" + @env -u CXX COMMON_CXXFLAGS="-std=c++11" $(MAKE) BINDIR=$(PKG_BUILDDIR) -C $(PKG_BUILDDIR) strip-bossac + @mv $(PKG_BUILDDIR)/bossac $(CURDIR)/bossac + +distclean:: + @rm -f $(CURDIR)/bossac + +include $(RIOTBASE)/pkg/pkg.mk diff --git a/makefiles/tools/bossa.inc.mk b/makefiles/tools/bossa.inc.mk new file mode 100644 index 0000000000000000000000000000000000000000..89aed6d8e30e2f447172ef19c1d27b56a43130d0 --- /dev/null +++ b/makefiles/tools/bossa.inc.mk @@ -0,0 +1,26 @@ +export FLASHER ?= $(RIOTBASE)/dist/tools/bossa/bossac +export FFLAGS ?= -p $(PORT) -i -i -w -v -b -R $(HEXFILE) + +export OFLAGS = -O binary +export HEXFILE = $(ELFFILE:.elf=.bin) + +# some arduino boards need to toggle the serial interface a little bit to get +# them ready for flashing... +ifneq (,$(BOSSA_ARDUINO_PREFLASH)) +OS := $(shell uname) +ifeq ($(OS),Linux) + STTY_FLAG = -F +else ifeq ($(OS),Darwin) + STTY_FLAG = -f +endif + +PREFLASHER ?= stty +PREFFLAGS ?= $(STTY_FLAG) $(PORT) raw ispeed 1200 ospeed 1200 cs8 -cstopb ignpar eol 255 eof 255 +FLASHDEPS += preflash +endif + +# if we go with the default (BOSSA shipped with RIOT), we download and build +# the tool if not already done +ifeq ($(RIOTBASE)/dist/tools/bossa/bossac,$(FLASHER)) +FLASHDEPS += $(RIOTBASE)/dist/tools/bossa/bossac +endif diff --git a/makefiles/tools/targets.inc.mk b/makefiles/tools/targets.inc.mk new file mode 100644 index 0000000000000000000000000000000000000000..f1a0ed5032bd10f185de1f0ca3a257381f413a09 --- /dev/null +++ b/makefiles/tools/targets.inc.mk @@ -0,0 +1,11 @@ +# This file contains a collection of targets defined by tools shipped with RIOT. +# The reason for keeping those targets separated from their tool Makfiles is +# that these targets have to be defined after the default build targets +# (as `all`), so `all` will always be the first target defined and thereby the +# default target when `make` is called without any further argument. + +# target for building the bossac binary +$(RIOTBASE)/dist/tools/bossa/bossac: + @echo "[INFO] bossac binary not found - building it from source" + @make -C $(RIOTBASE)/dist/tools/bossa + @echo "[INFO] bossac binary successfully build!"