Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Added make vars FLASH_BOOTLOADER_UICR and FLASH_SDK_BOOTLOADER_CONFIG #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions template/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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.
# Like this: FLASH_SDK_BOOTLOADER_CONFIG := 1
FLASH_SDK_BOOTLOADER_CONFIG_ADDRESS ?= 0x3FC00


all: $(OBJS) $(OBJS_AS) $(HEX)

rebuild: clean all
Expand Down
45 changes: 40 additions & 5 deletions template/Makefile.posix
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -21,11 +21,41 @@ 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" >$@
@printf "loadbin \"$(BIN)\" $(FLASH_START_ADDRESS)\n" >>$@
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
ifdef FLASH_SDK_BOOTLOADER_CONFIG
@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 >$@

flash.jlink:
printf "r\nloadbin $(BIN) $(FLASH_START_ADDRESS)\nr\ng\nexit\n" > flash.jlink
$(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
Expand All @@ -39,7 +69,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" >$@
@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
Expand Down