Skip to content

Commit dbca7e1

Browse files
committed
openocd: get flash and debug files from cli
Get FLASH_FILE and ELFFILE from command line instead of environment variable.
1 parent bfa7a47 commit dbca7e1

3 files changed

Lines changed: 23 additions & 19 deletions

File tree

boards/seeeduino_arch-pro/Makefile.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ include $(RIOTMAKE)/tools/serial.inc.mk
1111
DEBUG_ADAPTER ?= dap
1212

1313
# this board uses openocd
14-
export IMAGE_FILE = $(HEXFILE)
14+
FFLAGS ?= flash $(HEXFILE)
1515
include $(RIOTMAKE)/tools/openocd.inc.mk
1616

1717
# generate image checksum from hex file

dist/tools/openocd/openocd.sh

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,33 @@
1717
#
1818
# The script supports the following actions:
1919
#
20-
# flash: flash a given ELF file to the target.
20+
# flash: flash <image_file>
21+
# flash given file to the target.
2122
#
2223
# options:
23-
# IMAGE_FILE: Filename of the file that will be flashed
24+
# <image_file>: Filename of the file that will be flashed
2425
# PRE_FLASH_CHECK_SCRIPT: a command to run before flashing to
25-
# verify the integrity of the image to be flashed. ELFFILE is
26+
# verify the integrity of the image to be flashed. <image_file> is
2627
# passed as a command line argument to this command.
27-
# Even though the file name variable is named ELFFILE, flashing
28-
# works with any file format recognized by OpenOCD (elf, ihex, s19, bin).
2928
#
30-
# debug: starts OpenOCD as GDB server in the background and
29+
# Flashing works with any file format recognized by OpenOCD
30+
# (elf, ihex, s19, bin).
31+
#
32+
# debug: debug <elfile>
33+
# starts OpenOCD as GDB server in the background and
3134
# connects to the server with the GDB client specified by
3235
# the board
3336
#
3437
# options:
38+
# <elffile>: path to the file to debug, must be in a format
39+
# recognized by GDB (preferably ELF, it will not
40+
# work with .bin, .hex or .s19 because they lack
41+
# symbol information)
3542
# GDB_PORT: port opened for GDB connections
3643
# TCL_PORT: port opened for TCL connections
3744
# TELNET_PORT: port opened for telnet connections
3845
# DBG: debugger client command, default: 'gdb -q'
3946
# TUI: if TUI!=null, the -tui option will be used
40-
# ELFFILE: path to the file to debug, must be in a format
41-
# recognized by GDB (preferably ELF, it will not
42-
# work with .bin, .hex or .s19 because they lack
43-
# symbol information)
4447
#
4548
# debug-server: starts OpenOCD as GDB server, but does not connect to
4649
# to it with any frontend. This might be useful when using
@@ -93,10 +96,6 @@
9396
# Default offset is 0, meaning the image will be flashed at the address that it
9497
# was linked at.
9598
: ${IMAGE_OFFSET:=0}
96-
# Image file used for flashing. Must be in a format that OpenOCD can handle (ELF,
97-
# Intel hex, S19, or raw binary)
98-
# Default is to use $ELFFILE
99-
: ${IMAGE_FILE:=${ELFFILE}}
10099
# Type of image, leave empty to let OpenOCD automatically detect the type from
101100
# the file (default).
102101
# Valid values: elf, hex, s19, bin (see OpenOCD manual for more information)
@@ -210,6 +209,7 @@ _flash_address() {
210209
# now comes the actual actions
211210
#
212211
do_flash() {
212+
IMAGE_FILE=$1
213213
test_config
214214
test_imagefile
215215
if [ -n "${PRE_FLASH_CHECK_SCRIPT}" ]; then
@@ -256,6 +256,7 @@ do_flash() {
256256
}
257257

258258
do_debug() {
259+
ELFFILE=$1
259260
test_config
260261
test_elffile
261262
# temporary file that saves OpenOCD pid
@@ -330,15 +331,16 @@ do_reset() {
330331
# parameter dispatching
331332
#
332333
ACTION="$1"
334+
shift # pop $1 from $@
333335

334336
case "${ACTION}" in
335337
flash)
336338
echo "### Flashing Target ###"
337-
do_flash
339+
do_flash "$@"
338340
;;
339341
debug)
340342
echo "### Starting Debugging ###"
341-
do_debug
343+
do_debug "$@"
342344
;;
343345
debug-server)
344346
echo "### Starting GDB Server ###"
@@ -350,6 +352,8 @@ case "${ACTION}" in
350352
;;
351353
*)
352354
echo "Usage: $0 {flash|debug|debug-server|reset}"
355+
echo " flash <flash_file>"
356+
echo " debug <elffile>"
353357
exit 2
354358
;;
355359
esac

makefiles/tools/openocd.inc.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ export DEBUGGER = $(RIOTTOOLS)/openocd/openocd.sh
33
export DEBUGSERVER = $(RIOTTOOLS)/openocd/openocd.sh
44
export RESET ?= $(RIOTTOOLS)/openocd/openocd.sh
55

6-
export FFLAGS ?= flash
7-
export DEBUGGER_FLAGS ?= debug
6+
export FFLAGS ?= flash $(ELFFILE)
7+
export DEBUGGER_FLAGS ?= debug $(ELFFILE)
88
export DEBUGSERVER_FLAGS ?= debug-server
99
export RESET_FLAGS ?= reset
1010

0 commit comments

Comments
 (0)