Skip to content

Commit

Permalink
west: openocd: Allow to specify FTDI instance by its serial number
Browse files Browse the repository at this point in the history
To be used in setups with multiple boards attached to the same one
host we need to have an ability to specify precisely which JTAG probe
to use for a particular board.

This is done by passing "ftdi_serial XXX" command to OpenOCD.
And the serial ("XXX") is supposed to be passed from higher level,
typically via west's options. And exactly for that we add another
"openocd" runner option "--serial=XXX" which sets
a Tcl's "_ZEPHYR_BOARD_SERIAL" variable that later gets passed
to OpenOCD's "ftdi_serial" command.

See more discussions on the matter here:
#22543

Signed-off-by: Alexey Brodkin <[email protected]>
  • Loading branch information
abrodkin authored and jhedberg committed Feb 13, 2020
1 parent 3b60f09 commit 5a4237e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions scripts/west_commands/runners/openocd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class OpenOcdBinaryRunner(ZephyrBinaryRunner):

def __init__(self, cfg, pre_init=None, pre_load=None,
load_cmd=None, verify_cmd=None, post_verify=None,
tui=None, config=None,
tui=None, config=None, serial=None,
tcl_port=DEFAULT_OPENOCD_TCL_PORT,
telnet_port=DEFAULT_OPENOCD_TELNET_PORT,
gdb_port=DEFAULT_OPENOCD_GDB_PORT):
Expand Down Expand Up @@ -50,6 +50,7 @@ def __init__(self, cfg, pre_init=None, pre_load=None,
self.gdb_port = gdb_port
self.gdb_cmd = [cfg.gdb] if cfg.gdb else None
self.tui_arg = ['-tui'] if tui else []
self.serial = ['-c set _ZEPHYR_BOARD_SERIAL ' + serial] if serial else []

@classmethod
def name(cls):
Expand All @@ -59,6 +60,8 @@ def name(cls):
def do_add_parser(cls, parser):
parser.add_argument('--config',
help='if given, override default config file')
parser.add_argument('--serial', default="",
help='if given, selects FTDI instance by its serial number, defaults to empty')
# Options for flashing:
parser.add_argument('--cmd-pre-init', action='append',
help='''Command to run before calling init;
Expand Down Expand Up @@ -93,7 +96,7 @@ def create(cls, cfg, args):
pre_init=args.cmd_pre_init,
pre_load=args.cmd_pre_load, load_cmd=args.cmd_load,
verify_cmd=args.cmd_verify, post_verify=args.cmd_post_verify,
tui=args.tui, config=args.config,
tui=args.tui, config=args.config, serial=args.serial,
tcl_port=args.tcl_port, telnet_port=args.telnet_port,
gdb_port=args.gdb_port)

Expand Down Expand Up @@ -138,7 +141,7 @@ def do_flash(self, **kwargs):
post_verify_cmd.append("-c")
post_verify_cmd.append(i)

cmd = (self.openocd_cmd + self.cfg_cmd +
cmd = (self.openocd_cmd + self.serial + self.cfg_cmd +
pre_init_cmd + ['-c', 'init',
'-c', 'targets'] +
pre_load_cmd + ['-c', 'reset halt',
Expand All @@ -161,7 +164,7 @@ def do_debug(self, **kwargs):
pre_init_cmd.append("-c")
pre_init_cmd.append(i)

server_cmd = (self.openocd_cmd + self.cfg_cmd +
server_cmd = (self.openocd_cmd + self.serial + self.cfg_cmd +
['-c', 'tcl_port {}'.format(self.tcl_port),
'-c', 'telnet_port {}'.format(self.telnet_port),
'-c', 'gdb_port {}'.format(self.gdb_port)] +
Expand Down

0 comments on commit 5a4237e

Please sign in to comment.