From 43e137ea1fbf0823d43497b85dd4ccf45072d04d Mon Sep 17 00:00:00 2001 From: Joe Merten Date: Wed, 9 Apr 2014 09:48:40 +0200 Subject: [PATCH 1/6] Increase readability - printf splitted in multiple calls --- template/Makefile.posix | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/template/Makefile.posix b/template/Makefile.posix index b7d896b..cf8119d 100644 --- a/template/Makefile.posix +++ b/template/Makefile.posix @@ -25,7 +25,11 @@ flash: all flash.jlink $(JLINK) flash.jlink flash.jlink: - printf "r\nloadbin $(BIN) $(FLASH_START_ADDRESS)\nr\ng\nexit\n" > flash.jlink + printf "r\n" > flash.jlink + printf "loadbin $(BIN) $(FLASH_START_ADDRESS)\n" >> flash.jlink + printf "r\n" >> flash.jlink + printf "g\n" >> flash.jlink + printf "exit\n" >> flash.jlink flash-softdevice: erase-all flash-softdevice.jlink ifndef SOFTDEVICE @@ -39,7 +43,12 @@ endif flash-softdevice.jlink: # Write to NVMC to enable write. Write mainpart, write UICR. Assumes device is erased. - printf "w4 4001e504 1\nloadbin \"$(SOFTDEVICE_OUTPUT:.hex=_mainpart.bin)\" 0\nloadbin \"$(SOFTDEVICE_OUTPUT:.hex=_uicr.bin)\" 0x10001000\nr\ng\nexit\n" > flash-softdevice.jlink + printf "w4 4001e504 1\n" > flash-softdevice.jlink + printf "loadbin \"$(SOFTDEVICE_OUTPUT:.hex=_mainpart.bin)\" 0\n" >> flash-softdevice.jlink + printf "loadbin \"$(SOFTDEVICE_OUTPUT:.hex=_uicr.bin)\" 0x10001000\n" >> flash-softdevice.jlink + printf "r\n" >> flash-softdevice.jlink + printf "g\n" >> flash-softdevice.jlink + printf "exit\n" >> flash-softdevice.jlink recover: recover.jlink erase-all.jlink pin-reset.jlink $(JLINK) recover.jlink From 722037a740fc55b99839f6c0a8ffe23612f38ad5 Mon Sep 17 00:00:00 2001 From: Joe Merten Date: Wed, 9 Apr 2014 11:57:41 +0200 Subject: [PATCH 2/6] =?UTF-8?q?Added=20a=20!=20to=20the=20JLinkExe=20call?= =?UTF-8?q?=20to=20prevent=20the=20"make:=20Error=201=20(ignored)"=20See?= =?UTF-8?q?=20also=20=E2=86=92=20http://forum.segger.com/index.php=3Fpage?= =?UTF-8?q?=3DThread&threadID=3D1545?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/Makefile.posix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/Makefile.posix b/template/Makefile.posix index cf8119d..82bea67 100644 --- a/template/Makefile.posix +++ b/template/Makefile.posix @@ -10,7 +10,7 @@ endif MAKE_BUILD_FOLDER = mkdir -p $(OUTPUT_PATH) -JLINK = -JLinkExe $(JLINK_OPTIONS) $(JLINKEXE_OPTION) +JLINK = -! JLinkExe $(JLINK_OPTIONS) $(JLINKEXE_OPTION) JLINKGDBSERVER = JLinkGDBServer $(JLINK_OPTIONS) $(JLINKGDBSERVER_OPTION) SOFTDEVICE_OUTPUT = $(OUTPUT_PATH)$(notdir $(SOFTDEVICE)) From a2c4d64615356dc90ae36cf9d8cb722c0969b18b Mon Sep 17 00:00:00 2001 From: Joe Merten Date: Wed, 9 Apr 2014 12:53:50 +0200 Subject: [PATCH 3/6] Reduced printf verbosibility --- template/Makefile.posix | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/template/Makefile.posix b/template/Makefile.posix index 82bea67..e3bd0f2 100644 --- a/template/Makefile.posix +++ b/template/Makefile.posix @@ -25,11 +25,11 @@ flash: all flash.jlink $(JLINK) flash.jlink flash.jlink: - printf "r\n" > flash.jlink - printf "loadbin $(BIN) $(FLASH_START_ADDRESS)\n" >> flash.jlink - printf "r\n" >> flash.jlink - printf "g\n" >> flash.jlink - printf "exit\n" >> flash.jlink + @printf "r\n" >$@ + @printf "loadbin $(BIN) $(FLASH_START_ADDRESS)\n" >>$@ + @printf "r\n" >>$@ + @printf "g\n" >>$@ + @printf "exit\n" >>$@ flash-softdevice: erase-all flash-softdevice.jlink ifndef SOFTDEVICE @@ -43,12 +43,12 @@ endif flash-softdevice.jlink: # Write to NVMC to enable write. Write mainpart, write UICR. Assumes device is erased. - printf "w4 4001e504 1\n" > flash-softdevice.jlink - printf "loadbin \"$(SOFTDEVICE_OUTPUT:.hex=_mainpart.bin)\" 0\n" >> flash-softdevice.jlink - printf "loadbin \"$(SOFTDEVICE_OUTPUT:.hex=_uicr.bin)\" 0x10001000\n" >> flash-softdevice.jlink - printf "r\n" >> flash-softdevice.jlink - printf "g\n" >> flash-softdevice.jlink - printf "exit\n" >> flash-softdevice.jlink + @printf "w4 4001e504 1\n" >$@ + @printf "loadbin \"$(SOFTDEVICE_OUTPUT:.hex=_mainpart.bin)\" 0\n" >>$@ + @printf "loadbin \"$(SOFTDEVICE_OUTPUT:.hex=_uicr.bin)\" 0x10001000\n" >>$@ + @printf "r\n" >>$@ + @printf "g\n" >>$@ + @printf "exit\n" >>$@ recover: recover.jlink erase-all.jlink pin-reset.jlink $(JLINK) recover.jlink From 4b0005899f66a2818d6d11f04c7fb6c80c49cba8 Mon Sep 17 00:00:00 2001 From: Joe Merten Date: Wed, 9 Apr 2014 12:57:19 +0200 Subject: [PATCH 4/6] Added make vars FLASH_BOOTLOADER_UICR and FLASH_SDK_BOOTLOADER_CONFIG - You can FLASH_BOOTLOADER_UICR set in your project specific Makefile, if your project is a bootloader. This causes the storage of the bootloader's address to UICR 10001014 so that it is called by the SoftDevice during bootup - You can FLASH_BOOTLOADER_CONFIG set in your project specific Makefile, if your project is a normal application and your target system consist of a bootloader which is based on the Nordic Sdk. This causes a write of some configuration data into the last flash block (typically 16 byte at 3FC00 for a 256k device) that notifies the bootloader that there is a valid application in the flash. --- template/Makefile | 10 ++++++++++ template/Makefile.posix | 31 +++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/template/Makefile b/template/Makefile index 16c1c4e..2768e38 100644 --- a/template/Makefile +++ b/template/Makefile @@ -85,6 +85,16 @@ OBJS_AS = $(addprefix $(OUTPUT_PATH), $(SRCS_AS:.s=.os)) JLINK_OPTIONS = -device nrf51822 -if swd -speed 1000 +# You can FLASH_BOOTLOADER_UICR set in your project specific Makefile, if your project is a bootloader. +# This causes the storage of the bootloader's address to UICR 10001014 so that it is called by the SoftDevice during bootup +FLASH_BOOTLOADER_UICR ?= false + +# You can FLASH_BOOTLOADER_CONFIG set in your project specific Makefile, if your project is a normal application and your target system consist of a bootloader which is based on the Nordic Sdk. +# This causes a write of some configuration data into the last flash block (typically 16 byte at 3FC00 for a 256k device) that notifies the bootloader that there is a valid application in the flash. +FLASH_SDK_BOOTLOADER_CONFIG ?= false +FLASH_SDK_BOOTLOADER_CONFIG_ADDRESS ?= 0x3FC00 + + all: $(OBJS) $(OBJS_AS) $(HEX) rebuild: clean all diff --git a/template/Makefile.posix b/template/Makefile.posix index e3bd0f2..22c4ae2 100644 --- a/template/Makefile.posix +++ b/template/Makefile.posix @@ -24,12 +24,31 @@ clean: flash: all flash.jlink $(JLINK) flash.jlink -flash.jlink: - @printf "r\n" >$@ - @printf "loadbin $(BIN) $(FLASH_START_ADDRESS)\n" >>$@ - @printf "r\n" >>$@ - @printf "g\n" >>$@ - @printf "exit\n" >>$@ +flash.jlink: $(OUTPUT_PATH)/bootloader-uicr.bin $(OUTPUT_PATH)/sdk-bootloader-config.bin + @printf "r\n" >$@ + @printf "loadbin \"$(BIN)\" $(FLASH_START_ADDRESS)\n" >>$@ +ifneq ($(FLASH_BOOTLOADER_UICR),false) + @# FIXME: The bootloader's address is wrote correctly to uicr, but I always get a "Error: Programming failed @ address 0x10001000 (block verification error)" + @# Even "w4 4001e504 1" won't help. Any suggestions? + @#printf "w4 4001e504 1\n" >>$@ + @printf "loadbin \"$(OUTPUT_PATH)/bootloader-uicr.bin\" 0x10001014\n" >>$@ +endif +ifneq ($(FLASH_SDK_BOOTLOADER_CONFIG),false) + @printf "loadbin \"$(OUTPUT_PATH)/sdk-bootloader-config.bin\" $(FLASH_SDK_BOOTLOADER_CONFIG_ADDRESS)\n" >>$@ +endif + @printf "r\n" >>$@ + @printf "g\n" >>$@ + @printf "exit\n" >>$@ + +$(OUTPUT_PATH)/bootloader-uicr.bin: + @# printf "\x00\xA0\x03\x00" >$@ + @# For flashing the bootloader's uicr entry, we need the flash address in 32 bit binary little endian format + @# We first convert the e.g. "0003a000" to "00 a0 03 00", so that xxd can convert that to binary + @printf "$(shell a="$(FLASH_START_ADDRESS)"; printf "$${a:6:2} $${a:4:2} $${a:2:2} $${a:0:2}")" | xxd -r -p >$@ + +$(OUTPUT_PATH)/sdk-bootloader-config.bin: + @# TODO: Set correct values for crc16 & size, see also bootloader_settings_t + @printf "\x01\x00\x00\x00\x00\x00\x00\x00" >$@ flash-softdevice: erase-all flash-softdevice.jlink ifndef SOFTDEVICE From 4e4c494fb4239c45efb18662074af52a258a2f5a Mon Sep 17 00:00:00 2001 From: Joe Merten Date: Wed, 9 Apr 2014 13:04:26 +0200 Subject: [PATCH 5/6] Changed FLASH_BOOTLOADER_UICR / FLASH_SDK_BOOTLOADER_CONFIG to ifdef --- template/Makefile | 4 ++-- template/Makefile.posix | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/template/Makefile b/template/Makefile index 2768e38..ac310d2 100644 --- a/template/Makefile +++ b/template/Makefile @@ -87,11 +87,11 @@ JLINK_OPTIONS = -device nrf51822 -if swd -speed 1000 # You can FLASH_BOOTLOADER_UICR set in your project specific Makefile, if your project is a bootloader. # This causes the storage of the bootloader's address to UICR 10001014 so that it is called by the SoftDevice during bootup -FLASH_BOOTLOADER_UICR ?= false +# Like this: FLASH_BOOTLOADER_UICR := 1 # You can FLASH_BOOTLOADER_CONFIG set in your project specific Makefile, if your project is a normal application and your target system consist of a bootloader which is based on the Nordic Sdk. # This causes a write of some configuration data into the last flash block (typically 16 byte at 3FC00 for a 256k device) that notifies the bootloader that there is a valid application in the flash. -FLASH_SDK_BOOTLOADER_CONFIG ?= false +# Like this: FLASH_SDK_BOOTLOADER_CONFIG := 1 FLASH_SDK_BOOTLOADER_CONFIG_ADDRESS ?= 0x3FC00 diff --git a/template/Makefile.posix b/template/Makefile.posix index 22c4ae2..6bba89f 100644 --- a/template/Makefile.posix +++ b/template/Makefile.posix @@ -27,13 +27,13 @@ flash: all flash.jlink flash.jlink: $(OUTPUT_PATH)/bootloader-uicr.bin $(OUTPUT_PATH)/sdk-bootloader-config.bin @printf "r\n" >$@ @printf "loadbin \"$(BIN)\" $(FLASH_START_ADDRESS)\n" >>$@ -ifneq ($(FLASH_BOOTLOADER_UICR),false) +ifdef FLASH_BOOTLOADER_UICR @# FIXME: The bootloader's address is wrote correctly to uicr, but I always get a "Error: Programming failed @ address 0x10001000 (block verification error)" @# Even "w4 4001e504 1" won't help. Any suggestions? @#printf "w4 4001e504 1\n" >>$@ @printf "loadbin \"$(OUTPUT_PATH)/bootloader-uicr.bin\" 0x10001014\n" >>$@ endif -ifneq ($(FLASH_SDK_BOOTLOADER_CONFIG),false) +ifdef FLASH_SDK_BOOTLOADER_CONFIG @printf "loadbin \"$(OUTPUT_PATH)/sdk-bootloader-config.bin\" $(FLASH_SDK_BOOTLOADER_CONFIG_ADDRESS)\n" >>$@ endif @printf "r\n" >>$@ From d3c57873d2b4cb87b2a5860b8c3a9aacab4efd34 Mon Sep 17 00:00:00 2001 From: Joe Merten Date: Wed, 9 Apr 2014 13:24:14 +0200 Subject: [PATCH 6/6] Hack to suppress the block verification error when writing the uicr --- template/Makefile.posix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/template/Makefile.posix b/template/Makefile.posix index 6bba89f..55985fe 100644 --- a/template/Makefile.posix +++ b/template/Makefile.posix @@ -21,8 +21,15 @@ clean: rm -f JLink.log rm -f .gdbinit +ifdef FLASH_BOOTLOADER_UICR + # Hack to suppress the block verification error when writing the uicr + FLASH_BOOTLOADER_UICR_ERROR_SUPPRESSION_HACK := | grep -v "Programming failed @ address 0x10001000" | grep -v "Verification failed @ address 0x10001000" || true +else + FLASH_BOOTLOADER_UICR_ERROR_SUPPRESSION_HACK := +endif + flash: all flash.jlink - $(JLINK) flash.jlink + $(JLINK) flash.jlink $(FLASH_BOOTLOADER_UICR_ERROR_SUPPRESSION_HACK) flash.jlink: $(OUTPUT_PATH)/bootloader-uicr.bin $(OUTPUT_PATH)/sdk-bootloader-config.bin @printf "r\n" >$@