@@ -195,42 +195,7 @@ _is_binfile() {
195195 [[ -z " ${firmware_type} " ]] && _has_bin_extension " ${firmware} " ; }
196196}
197197
198- # Split bank info on different lines without the '{}'
199- _split_banks () {
200- # Input:
201- # ...
202- # {name nrf51 base 0 size 0 bus_width 1 chip_width 1} {name nrf51 base 268439552 size 0 bus_width 1 chip_width 1}
203- # ...
204- # or for newer openocd versions (v0.12.0 or higher)
205- # ...
206- # {name nrf51.flash driver nrf51 base 0 size 0 bus_width 1 chip_width 1 target nrf51.cpu} {name nrf51.uicr ...}
207- # ...
208- #
209- # Output:
210- # ...
211- # name nrf51 base 0 size 0 bus_width 1 chip_width 1
212- # name nrf51 base 268439552 size 0 bus_width 1 chip_width 1
213- # ...
214- # or for newer openocd versions (v0.12.0 or higher)
215- # ...
216- # name nrf51.flash driver nrf51 base 0 size 0 bus_width 1 chip_width 1 target nrf51.cpu
217- # name nrf51.uicr driver nrf51 base 268439552 size 0 bus_width 1 chip_width 1 target nrf51.cpu
218- # ...
219- #
220- # The following command needs specific osx handling (non gnu):
221- # * Same commands for a pattern should be on different lines
222- # * Cannot use '\n' in the replacement string
223- local sed_escaped_newline=\\ $' \n '
224-
225- sed -n '
226- /^{.*}$/ {
227- s/\} /\}' " ${sed_escaped_newline} " ' /g
228- s/[{}]//g
229- p
230- }'
231- }
232-
233- _flash_list_raw () {
198+ _flash_list () {
234199 # Openocd output for 'flash list' is either
235200 # ....
236201 # {name nrf51 base 0 size 0 bus_width 1 chip_width 1} {name nrf51 base 268439552 size 0 bus_width 1 chip_width 1}
@@ -272,32 +237,10 @@ _flash_list_raw() {
272237 -c 'shutdown'" 2>&1
273238}
274239
275- # Outputs bank info on different lines without the '{}'
276- _flash_list () {
277- # ....
278- # name nrf51 base 0 size 0 bus_width 1 chip_width 1
279- # name nrf51 base 268439552 size 0 bus_width 1 chip_width 1
280- # ....
281- # or for newer openocd versions (v0.12.0 or higher)
282- # ....
283- # name nrf51.flash driver nrf51 base 0 size 0 bus_width 1 chip_width 1 target nrf51.cpu
284- # name nrf51.uicr driver nrf51 base 268439552 size 0 bus_width 1 chip_width 1 target nrf51.cpu
285- # ....
286- _flash_list_raw | _split_banks
287- }
288-
289- # Print flash address for 'bank_num' num defaults to 1
290- # _flash_address [bank_num:1]
240+ # Print flash address for 'bank_num' num defaults to 0
241+ # _flash_address [bank_num:0]
291242_flash_address () {
292- # extract the line from '_flash_list' output for bank with number 'bank_num'
293- bank=$( _flash_list | awk " NR==${1:- 1} " )
294- # determine the column of base address, a line can have following formats
295- # name nrf51 base 268439552 size 0 bus_width 1 chip_width 1
296- # or for newer openocd versions (v0.12.0 or higher)
297- # name nrf51.flash driver nrf51 base 0 size 0 bus_width 1 chip_width 1 target nrf51.cpu
298- base_addr_idx=$( echo ${bank} | awk ' { for (i=1; i <= NF; i++) if ($i == "base") print i + 1 }' )
299- # extract the base address in hexadecimal format
300- printf 0x" %08x" $( echo ${bank} | cut -d " " -f${base_addr_idx} )
243+ _flash_list | " ${RIOTTOOLS} /openocd/openocd_flashinfo.py" --idx " ${1:- 0} "
301244}
302245
303246do_flashr () {
@@ -317,7 +260,7 @@ do_flashr() {
317260 # This allows flashing normal binary files without env configuration
318261 if _is_binfile " ${IMAGE_FILE} " " ${IMAGE_TYPE} " ; then
319262 # hardwritten to use the first bank
320- FLASH_ADDR=$( _flash_address 1 )
263+ FLASH_ADDR=$( _flash_address 0 )
321264 echo " Binfile detected, adding ROM base address: ${FLASH_ADDR} "
322265 IMAGE_TYPE=bin
323266 IMAGE_OFFSET=$( printf " 0x%08x\n" " $(( ${IMAGE_OFFSET} + ${FLASH_ADDR} )) " )
@@ -366,7 +309,7 @@ do_flash() {
366309 # This allows flashing normal binary files without env configuration
367310 if _is_binfile " ${IMAGE_FILE} " " ${IMAGE_TYPE} " ; then
368311 # hardwritten to use the first bank
369- FLASH_ADDR=$( _flash_address 1 )
312+ FLASH_ADDR=$( _flash_address 0 )
370313 echo " Binfile detected, adding ROM base address: ${FLASH_ADDR} "
371314 IMAGE_TYPE=bin
372315 IMAGE_OFFSET=$( printf " 0x%08x\n" " $(( ${IMAGE_OFFSET} + ${FLASH_ADDR} )) " )
0 commit comments