diff --git a/boards/nrf52840-mdk/Makefile.include b/boards/nrf52840-mdk/Makefile.include index cda1e9e7727e..c324b10a2c80 100644 --- a/boards/nrf52840-mdk/Makefile.include +++ b/boards/nrf52840-mdk/Makefile.include @@ -8,7 +8,7 @@ PROGRAMMER ?= pyocd ifeq (pyocd,$(PROGRAMMER)) # The board is not recognized automatically by pyocd, so the CPU target # option is passed explicitly - export FLASH_TARGET_TYPE ?= -t $(CPU) + export FLASH_TARGET_TYPE ?= -t nrf52840 include $(RIOTMAKE)/tools/pyocd.inc.mk else ifeq (openocd,$(PROGRAMMER)) DEBUG_ADAPTER = dap diff --git a/dist/tools/pyocd/pyocd.sh b/dist/tools/pyocd/pyocd.sh index 5998dd906992..1a935cd0a1dc 100755 --- a/dist/tools/pyocd/pyocd.sh +++ b/dist/tools/pyocd/pyocd.sh @@ -70,6 +70,12 @@ # CPU Target type. # Use `-t` followed by value. Example: -t nrf51 : ${FLASH_TARGET_TYPE:=} +# This is an optional offset to the base address that can be used to flash an +# image in a different location than it is linked at. This feature can be useful +# when flashing images for firmware swapping/remapping boot loaders. +# Default offset is 0, meaning the image will be flashed at the address that it +# was linked at. +: ${IMAGE_OFFSET:=0} # # Examples of alternative debugger configurations @@ -112,8 +118,13 @@ test_hexfile() { do_flash() { HEX_FILE=$1 test_hexfile + + if [ "${IMAGE_OFFSET}" != "0" ]; then + echo "Flashing with IMAGE_OFFSET: ${IMAGE_OFFSET}" + fi + # flash device - sh -c "${PYOCD_FLASH} ${FLASH_TARGET_TYPE} \"${HEX_FILE}\"" && + sh -c "${PYOCD_FLASH} ${FLASH_TARGET_TYPE} -a ${IMAGE_OFFSET} \"${HEX_FILE}\"" && echo 'Done flashing' }