[riot-notifications] [RIOT-OS/RIOT] boards: include common dfu logic where applicable (#11192)

Francisco Acosta notifications at github.com
Sat Mar 23 17:10:03 CET 2019


I'd like to propose to change a little bit more the options to maximize the flexibility of `dfu-util` and eventually be able to flash in other regions of the flash.

```diff
--- a/boards/common/stm32f103c8/Makefile.include
+++ b/boards/common/stm32f103c8/Makefile.include
@@ -24,7 +24,11 @@ include $(RIOTMAKE)/tools/serial.inc.mk
 ifeq ($(PROGRAMMER),dfu-util)
   export ROM_OFFSET ?= 0x2000 # Skip the space needed by the embedded bootloader
   # flash the board using DFU
-  DFU_ARGS += -d 1eaf:0003 -a 2
+  DFU_ID = 1eaf:0003
+
+  # Set ALT to 0
+  DFU_ALT = 2
+
   # for older bootloader versions use this:
   #DFU_ARGS += -d 1d50:6017 -s 0x08002000:leave
   include $(RIOTMAKE)/tools/dfu.inc.mk
diff --git a/boards/nz32-sc151/Makefile.include b/boards/nz32-sc151/Makefile.include
index edb3bcdb42..ca45ebc043 100644
--- a/boards/nz32-sc151/Makefile.include
+++ b/boards/nz32-sc151/Makefile.include
@@ -9,8 +9,9 @@ PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*)))
 # set the default id
 DFU_ID ?= 0483:df11
 
-# this board is flashed using DFU
-DFU_ARGS += -d $(DFU_ID) -a 0 -s 0x08000000:leave
+# Set ALT to 0
+DFU_ALT = 0
+
 include $(RIOTMAKE)/tools/dfu.inc.mk
 
 # setup serial terminal
diff --git a/boards/pyboard/Makefile.include b/boards/pyboard/Makefile.include
index 5b2742f43e..5e0385c95b 100644
--- a/boards/pyboard/Makefile.include
+++ b/boards/pyboard/Makefile.include
@@ -6,9 +6,13 @@ export CPU_MODEL = stm32f405rg
 PORT_LINUX ?= /dev/ttyUSB0
 PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*)))
 
+# this board is flashed using DFU
+DFU_ID = 1d50:607f
+
+# Set ALT to 0
+DFU_ALT = 0
+
 # setup serial terminal
 include $(RIOTMAKE)/tools/serial.inc.mk
 
-# this board is flashed using DFU
-DFU_ARGS += --alt 0 -s 0x8000000
 include $(RIOTMAKE)/tools/dfu.inc.mk
diff --git a/boards/spark-core/Makefile.include b/boards/spark-core/Makefile.include
index d2f7b21f7c..51f1a06b0e 100644
--- a/boards/spark-core/Makefile.include
+++ b/boards/spark-core/Makefile.include
@@ -8,11 +8,16 @@ PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*)))
 include $(RIOTMAKE)/tools/serial.inc.mk
 
 # this board is flashed using DFU
-DFU_ARGS += -d 1d50:607f -a 0 -s 0x08005000:leave
-include $(RIOTMAKE)/tools/dfu.inc.mk
+DFU_ID = 1d50:607f
+
+# Set ALT to 0
+DFU_ALT = 0
 
-# Skip the space needed by the embedded bootloader
+# A bootloader is included to hanlde the DFU, so we need to
+# set an offset to avoid overwritting it.
 export ROM_OFFSET ?= 0x5000
 
+include $(RIOTMAKE)/tools/dfu.inc.mk
+
 # this board uses openocd
 include $(RIOTMAKE)/tools/openocd.inc.mk
diff --git a/makefiles/tools/dfu.inc.mk b/makefiles/tools/dfu.inc.mk
index dc2bf2580c..d21b7e898a 100644
--- a/makefiles/tools/dfu.inc.mk
+++ b/makefiles/tools/dfu.inc.mk
@@ -2,7 +2,13 @@ DFU ?= dfu-util
 FLASHER ?= $(DFU)
 HEXFILE = $(BINFILE)
 
-FFLAGS ?= -D $(HEXFILE) --reset $(DFU_ARGS)
+ifdef ROM_OFFSET
+  FLASH_ADDR = $(shell printf "0x%x" $$(($(ROM_START_ADDR) + $(ROM_OFFSET))))
+else
+  FLASH_ADDR = $(ROM_START_ADDR)
+endif
+
+FFLAGS ?= --device $(DFU_ID) --alt $(DFU_ALT) --dfuse-address $(FLASH_ADDR):leave --download $(HEXFILE) --reset
 
 RESET ?= $(DFU)
 RESET_FLAGS ?= $(DFU_ARGS) -t $(DFU_DEVICE_TYPE)
```

What do you think @aabadie ?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/11192#issuecomment-475882159
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190323/1332feb0/attachment-0001.html>


More information about the notifications mailing list