From 36b51467ddb3709b5d4ee13be47d64b33d8f750e Mon Sep 17 00:00:00 2001 From: cladmi Date: Thu, 16 Aug 2018 15:17:18 +0200 Subject: [PATCH] openocd.sh: add functions to access board flash address This allows getting the ROM base address. It may not be available in the build system directly so better extract it from openocd. Also openocd is board specific and this address is cpu specific so would have definition order issue in the build system. --- dist/tools/openocd/openocd.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/dist/tools/openocd/openocd.sh b/dist/tools/openocd/openocd.sh index 7ea7d66569..94ac2695fa 100755 --- a/dist/tools/openocd/openocd.sh +++ b/dist/tools/openocd/openocd.sh @@ -159,6 +159,29 @@ _is_binfile() { [[ -z "${firmware_type}" ]] && _has_bin_extension "${firmware}"; } } +# Outputs bank info on different lines without the '{}' +_flash_list() { + # Openocd output for 'flash list' is + # .... + # {name nrf51 base 0 size 0 bus_width 1 chip_width 1} {name nrf51 base 268439552 size 0 bus_width 1 chip_width 1} + # .... + sh -c "${OPENOCD} \ + ${OPENOCD_ADAPTER_INIT} \ + -f '${OPENOCD_CONFIG}' \ + -c 'flash list' \ + -c 'shutdown'" 2>&1 | sed -n '/^{.*}$/ {s/\} /\}\n/g;s/[{}]//g;p}' +} + +# Print flash address for 'bank_num' num defaults to 1 +# _flash_address [bank_num:1] +_flash_address() { + bank_num=${1:-1} + + # extract 'base' value and print as hexadecimal + # name nrf51 base 268439552 size 0 bus_width 1 chip_width 1 + _flash_list | awk "NR==${bank_num}"'{printf "0x%08x\n", $4}' +} + # # now comes the actual actions #