west: openocd: support pre init command option

With ST boards it is possible to specify the board ID when flashing using
openocd. This is very useful when having multiple devices connected.

This change allows us to address a device directly:

west flash -- --cmd-pre-init  "hla_serial 066BFF535254887767174558"

This needs to be called before init, hence the new option.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2019-09-30 11:42:08 -04:00
commit b61f86d2c0

View file

@ -17,7 +17,8 @@ class OpenOcdBinaryRunner(ZephyrBinaryRunner):
'''Runner front-end for openocd.''' '''Runner front-end for openocd.'''
def __init__(self, cfg, def __init__(self, cfg,
pre_cmd=None, load_cmd=None, verify_cmd=None, post_cmd=None, pre_init_cmd=None, pre_cmd=None, load_cmd=None, verify_cmd=None,
post_cmd=None,
tui=None, config=None, tui=None, config=None,
tcl_port=DEFAULT_OPENOCD_TCL_PORT, tcl_port=DEFAULT_OPENOCD_TCL_PORT,
telnet_port=DEFAULT_OPENOCD_TELNET_PORT, telnet_port=DEFAULT_OPENOCD_TELNET_PORT,
@ -38,6 +39,7 @@ class OpenOcdBinaryRunner(ZephyrBinaryRunner):
self.elf_name = cfg.elf_file self.elf_name = cfg.elf_file
self.load_cmd = load_cmd self.load_cmd = load_cmd
self.verify_cmd = verify_cmd self.verify_cmd = verify_cmd
self.pre_init_cmd = pre_init_cmd
self.pre_cmd = pre_cmd self.pre_cmd = pre_cmd
self.post_cmd = post_cmd self.post_cmd = post_cmd
self.tcl_port = tcl_port self.tcl_port = tcl_port
@ -55,6 +57,8 @@ class OpenOcdBinaryRunner(ZephyrBinaryRunner):
parser.add_argument('--config', parser.add_argument('--config',
help='if given, override default config file') help='if given, override default config file')
# Options for flashing: # Options for flashing:
parser.add_argument('--cmd-pre-init',
help='Command to run before calling init')
parser.add_argument('--cmd-pre-load', parser.add_argument('--cmd-pre-load',
help='Command to run before flashing') help='Command to run before flashing')
parser.add_argument('--cmd-load', parser.add_argument('--cmd-load',
@ -80,6 +84,7 @@ class OpenOcdBinaryRunner(ZephyrBinaryRunner):
def create(cls, cfg, args): def create(cls, cfg, args):
return OpenOcdBinaryRunner( return OpenOcdBinaryRunner(
cfg, cfg,
pre_init_cmd=args.cmd_pre_init,
pre_cmd=args.cmd_pre_load, load_cmd=args.cmd_load, pre_cmd=args.cmd_pre_load, load_cmd=args.cmd_load,
verify_cmd=args.cmd_verify, post_cmd=args.cmd_post_verify, verify_cmd=args.cmd_verify, post_cmd=args.cmd_post_verify,
tui=args.tui, config=args.config, tui=args.tui, config=args.config,
@ -109,14 +114,19 @@ class OpenOcdBinaryRunner(ZephyrBinaryRunner):
if self.pre_cmd is not None: if self.pre_cmd is not None:
pre_cmd = ['-c', self.pre_cmd] pre_cmd = ['-c', self.pre_cmd]
pre_init_cmd = []
if self.pre_init_cmd is not None:
pre_init_cmd = ['-c', self.pre_init_cmd]
post_cmd = [] post_cmd = []
if self.post_cmd is not None: if self.post_cmd is not None:
post_cmd = ['-c', self.post_cmd] post_cmd = ['-c', self.post_cmd]
self.logger.info('Flashing file: {}'.format(self.hex_name)) self.logger.info('Flashing file: {}'.format(self.hex_name))
cmd = (self.openocd_cmd + cmd = (self.openocd_cmd +
['-f', self.openocd_config, ['-f', self.openocd_config] +
'-c', 'init', pre_init_cmd +
['-c', 'init',
'-c', 'targets'] + '-c', 'targets'] +
pre_cmd + pre_cmd +
['-c', 'reset halt', ['-c', 'reset halt',