From fe0b829d5bff3a64b9269be34d02e05b109239cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Tue, 30 Apr 2019 11:51:35 +0200 Subject: [PATCH] boards/common/nrf52: add openocd support for 'nordic_softdevice_ble' Enable the handling of flashing `softdevice.hex` when flashing the firmware for openocd. However, for flashing, only the `hexfile` and `binfile` can currently be used. The `elffile` is generated with local pages aligned to `0x10000` which makes the program starting at `0x1f000` be flashed from `0x10000` with padding bytes even if the `.text` section is indeed at `0x1f000`: readelf --sections bin/nrf52dk/gnrc_networking.elf ... [ 1] .text PROGBITS 0001f000 00f000 00f698 00 AX 0 0 16 ... readelf --segments bin/nrf52dk/gnrc_networking.elf ... LOAD 0x000000 0x00010000 0x00010000 0x1e6a0 0x1e6a0 R E 0x10000 ... The padding bytes would go through `verify_image` in `openocd` so be expected to not be overwritten but are by `softdevice.hex` Using --nmagic at link time removes the local page alignement but would need dedicated testing. --- boards/common/nrf52/Makefile.include | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/boards/common/nrf52/Makefile.include b/boards/common/nrf52/Makefile.include index 21b20b001f..0e909fbe41 100644 --- a/boards/common/nrf52/Makefile.include +++ b/boards/common/nrf52/Makefile.include @@ -41,8 +41,24 @@ else ifeq (openocd,$(PROGRAMMER)) # for nrf52dk and nrf52840dk boards. To use OpenOCD with these a version # build from source (master > 2018, August the 13rd) is required. ifneq (,$(filter nordic_softdevice_ble,$(USEPKG))) - # openocd doesn't work (yet) with softdevice - $(error Cannot use OpenOCD with nordic_softdevice module) + LINKER_SCRIPT ?= $(RIOTCPU)/$(CPU)/ldscripts/$(CPU_MODEL)_sd.ld + + export OPENOCD_PRE_FLASH_CMDS += -c 'flash write_image erase "$(BINDIR)/softdevice.hex"' + export OPENOCD_PRE_VERIFY_CMDS += -c 'verify_image "$(BINDIR)/softdevice.hex"' + + # Cannot use the 'ELFFILE' here + # The segments are 0x10000 aligned so padding bytes are copied and verified + # + # Using 'LINKFLAGS += -Wl,--nmagic' prevents it but would require + # dedicated testing/review + FLASHFILE ?= $(HEXFILE) + + # murdock: softdevice.hex file is used for flashing + # It must be taken into account for the test input hash and + # be sent to the separated testing boards + TEST_EXTRA_FILES += $(BINDIR)/softdevice.hex + # Files in TEST_EXTRA_FILES need to have an explicit target + $(BINDIR)/softdevice.hex: | $(ELFFILE) endif DEBUG_ADAPTER ?= jlink export OPENOCD_CONFIG := $(RIOTBOARD)/common/nrf52/dist/openocd.cfg