scripts: runners: new openocd fixes and features

Let the user specify these arguments as many times as they want:

--cmd-pre-init
--cmd-pre-load
--cmd-post-verify

This makes it a bit easier to handle scripts that need to do a few
things in a row depending on conditions.

Handle --cmd-pre-init and the port arguments properly in the debug
related targets.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2019-11-01 15:43:35 +01:00 committed by Kumar Gala
commit 0df4a53107

View file

@ -16,9 +16,8 @@ DEFAULT_OPENOCD_GDB_PORT = 3333
class OpenOcdBinaryRunner(ZephyrBinaryRunner): class OpenOcdBinaryRunner(ZephyrBinaryRunner):
'''Runner front-end for openocd.''' '''Runner front-end for openocd.'''
def __init__(self, cfg, def __init__(self, cfg, pre_init=None, pre_load=None,
pre_init_cmd=None, pre_cmd=None, load_cmd=None, load_cmd=None, verify_cmd=None, post_verify=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,
@ -37,11 +36,11 @@ class OpenOcdBinaryRunner(ZephyrBinaryRunner):
self.openocd_cmd = [cfg.openocd] + search_args self.openocd_cmd = [cfg.openocd] + search_args
self.hex_name = cfg.hex_file self.hex_name = cfg.hex_file
self.elf_name = cfg.elf_file self.elf_name = cfg.elf_file
self.pre_init = pre_init or []
self.pre_load = pre_load or []
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.post_verify = post_verify or []
self.pre_cmd = pre_cmd
self.post_cmd = post_cmd
self.tcl_port = tcl_port self.tcl_port = tcl_port
self.telnet_port = telnet_port self.telnet_port = telnet_port
self.gdb_port = gdb_port self.gdb_port = gdb_port
@ -57,17 +56,20 @@ 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', parser.add_argument('--cmd-pre-init', action='append',
help='Command to run before calling init') help='''Command to run before calling init;
parser.add_argument('--cmd-pre-load', may be given multiple times''')
help='Command to run before flashing') parser.add_argument('--cmd-pre-load', action='append',
help='''Command to run before flashing;
may be given multiple times''')
parser.add_argument('--cmd-load', parser.add_argument('--cmd-load',
help='''Command to load/flash binary help='''Command to load/flash binary
(required when flashing)''') (required when flashing)''')
parser.add_argument('--cmd-verify', parser.add_argument('--cmd-verify',
help='''Command to verify flashed binary''') help='''Command to verify flashed binary''')
parser.add_argument('--cmd-post-verify', parser.add_argument('--cmd-post-verify', action='append',
help='Command to run after verification') help='''Command to run after verification;
may be given multiple times''')
# Options for debugging: # Options for debugging:
parser.add_argument('--tui', default=False, action='store_true', parser.add_argument('--tui', default=False, action='store_true',
@ -84,9 +86,9 @@ 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_init=args.cmd_pre_init,
pre_cmd=args.cmd_pre_load, load_cmd=args.cmd_load, pre_load=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_verify=args.cmd_post_verify,
tui=args.tui, config=args.config, tui=args.tui, config=args.config,
tcl_port=args.tcl_port, telnet_port=args.telnet_port, tcl_port=args.tcl_port, telnet_port=args.telnet_port,
gdb_port=args.gdb_port) gdb_port=args.gdb_port)
@ -115,30 +117,15 @@ class OpenOcdBinaryRunner(ZephyrBinaryRunner):
if self.verify_cmd is None: if self.verify_cmd is None:
raise ValueError('Cannot flash; verify command is missing') raise ValueError('Cannot flash; verify command is missing')
pre_cmd = []
if self.pre_cmd is not None:
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 = []
if self.post_cmd is not None:
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 + self.cfg_cmd +
self.cfg_cmd + self.pre_init + ['-c', 'init',
pre_init_cmd + '-c', 'targets'] +
['-c', 'init', self.pre_load + ['-c', 'reset halt',
'-c', 'targets'] + '-c', self.load_cmd + ' ' + self.hex_name,
pre_cmd + '-c', 'reset halt'] +
['-c', 'reset halt', ['-c', self.verify_cmd + ' ' + self.hex_name] +
'-c', self.load_cmd + ' ' + self.hex_name, self.post_verify +
'-c', 'reset halt',
'-c', self.verify_cmd + ' ' + self.hex_name] +
post_cmd +
['-c', 'reset run', ['-c', 'reset run',
'-c', 'shutdown']) '-c', 'shutdown'])
self.check_call(cmd) self.check_call(cmd)
@ -149,14 +136,13 @@ class OpenOcdBinaryRunner(ZephyrBinaryRunner):
if self.elf_name is None: if self.elf_name is None:
raise ValueError('Cannot debug; no .elf specified') raise ValueError('Cannot debug; no .elf specified')
server_cmd = (self.openocd_cmd + server_cmd = (self.openocd_cmd + self.cfg_cmd +
self.cfg_cmd +
['-c', 'tcl_port {}'.format(self.tcl_port), ['-c', 'tcl_port {}'.format(self.tcl_port),
'-c', 'telnet_port {}'.format(self.telnet_port), '-c', 'telnet_port {}'.format(self.telnet_port),
'-c', 'gdb_port {}'.format(self.gdb_port), '-c', 'gdb_port {}'.format(self.gdb_port)] +
'-c', 'init', self.pre_init + ['-c', 'init',
'-c', 'targets', '-c', 'targets',
'-c', 'halt']) '-c', 'halt'])
gdb_cmd = (self.gdb_cmd + self.tui_arg + gdb_cmd = (self.gdb_cmd + self.tui_arg +
['-ex', 'target remote :{}'.format(self.gdb_port), ['-ex', 'target remote :{}'.format(self.gdb_port),
self.elf_name]) self.elf_name])
@ -164,9 +150,11 @@ class OpenOcdBinaryRunner(ZephyrBinaryRunner):
self.run_server_and_client(server_cmd, gdb_cmd) self.run_server_and_client(server_cmd, gdb_cmd)
def do_debugserver(self, **kwargs): def do_debugserver(self, **kwargs):
cmd = (self.openocd_cmd + cmd = (self.openocd_cmd + self.cfg_cmd +
self.cfg_cmd + ['-c', 'tcl_port {}'.format(self.tcl_port),
['-c', 'init', '-c', 'telnet_port {}'.format(self.telnet_port),
'-c', 'targets', '-c', 'gdb_port {}'.format(self.gdb_port)] +
'-c', 'reset halt']) self.pre_init + ['-c', 'init',
'-c', 'targets',
'-c', 'reset halt'])
self.check_call(cmd) self.check_call(cmd)