west: runners: blackmagicprobe: update reset on connect command

Recently the blackmagicprobe command for "connect under reset" has been
updated from "connect_srst" to "connect_rst". Update the flag name in
the west blackmagicprobe binding, keep the old one as well for
compatibility with out of tree boards, and send both the old and new
commands to GDB so that it works with both the old and new firmware. GDB
is going to get a "command not supported by this target" for one of the
two and proceed with the other one.

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
This commit is contained in:
Fabio Baltieri 2023-01-11 23:18:16 +00:00 committed by Carles Cufí
commit dabfffaf26
3 changed files with 25 additions and 21 deletions

View file

@ -5,7 +5,7 @@ board_runner_args(pyocd "--flash-opt=-O reset_type=hw")
board_runner_args(pyocd "--flash-opt=-O connect_mode=under-reset")
board_runner_args(jlink "--device=STM32WLE5JC" "--speed=4000" "--reset-after-load")
board_runner_args(stm32cubeprogrammer "--port=swd" "--reset-mode=hw")
board_runner_args(blackmagicprobe "--gdb-serial=/dev/ttyBmpGdb" "--connect-srst")
board_runner_args(blackmagicprobe "--gdb-serial=/dev/ttyBmpGdb" "--connect-rst")
include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)

View file

@ -13,7 +13,7 @@ from runners.core import ZephyrBinaryRunner, RunnerCaps
class BlackMagicProbeRunner(ZephyrBinaryRunner):
'''Runner front-end for Black Magic probe.'''
def __init__(self, cfg, gdb_serial, connect_srst=False):
def __init__(self, cfg, gdb_serial, connect_rst=False):
super().__init__(cfg)
self.gdb = [cfg.gdb] if cfg.gdb else None
# as_posix() because gdb doesn't recognize backslashes as path
@ -22,14 +22,18 @@ class BlackMagicProbeRunner(ZephyrBinaryRunner):
# https://github.com/zephyrproject-rtos/zephyr/issues/50789
self.elf_file = Path(cfg.elf_file).as_posix()
self.gdb_serial = gdb_serial
if connect_srst:
self.connect_srst_enable_arg = [
'-ex', "monitor connect_srst enable"]
self.connect_srst_disable_arg = [
'-ex', "monitor connect_srst disable"]
if connect_rst:
self.connect_rst_enable_arg = [
'-ex', "monitor connect_rst enable",
'-ex', "monitor connect_srst enable",
]
self.connect_rst_disable_arg = [
'-ex', "monitor connect_rst disable",
'-ex', "monitor connect_srst disable",
]
else:
self.connect_srst_enable_arg = []
self.connect_srst_disable_arg = []
self.connect_rst_enable_arg = []
self.connect_rst_disable_arg = []
@classmethod
def name(cls):
@ -41,13 +45,13 @@ class BlackMagicProbeRunner(ZephyrBinaryRunner):
@classmethod
def do_create(cls, cfg, args):
return BlackMagicProbeRunner(cfg, args.gdb_serial, args.connect_srst)
return BlackMagicProbeRunner(cfg, args.gdb_serial, args.connect_rst)
@classmethod
def do_add_parser(cls, parser):
parser.add_argument('--gdb-serial', default='/dev/ttyACM0',
help='GDB serial port')
parser.add_argument('--connect-srst', action='store_true',
parser.add_argument('--connect-rst', '--connect-srst', action='store_true',
help='Assert SRST during connect? (default: no)')
def bmp_flash(self, command, **kwargs):
@ -57,7 +61,7 @@ class BlackMagicProbeRunner(ZephyrBinaryRunner):
['-ex', "set confirm off",
'-ex', "target extended-remote {}".format(
self.gdb_serial)] +
self.connect_srst_enable_arg +
self.connect_rst_enable_arg +
['-ex', "monitor swdp_scan",
'-ex', "attach 1",
'-ex', "load {}".format(self.elf_file),
@ -79,7 +83,7 @@ class BlackMagicProbeRunner(ZephyrBinaryRunner):
['-ex', "set confirm off",
'-ex', "target extended-remote {}".format(
self.gdb_serial)] +
self.connect_srst_disable_arg +
self.connect_rst_disable_arg +
['-ex', "monitor swdp_scan",
'-ex', "attach 1"])
else:
@ -87,7 +91,7 @@ class BlackMagicProbeRunner(ZephyrBinaryRunner):
['-ex', "set confirm off",
'-ex', "target extended-remote {}".format(
self.gdb_serial)] +
self.connect_srst_disable_arg +
self.connect_rst_disable_arg +
['-ex', "monitor swdp_scan",
'-ex', "attach 1",
'-ex', "file {}".format(self.elf_file)])
@ -100,7 +104,7 @@ class BlackMagicProbeRunner(ZephyrBinaryRunner):
['-ex', "set confirm off",
'-ex', "target extended-remote {}".format(
self.gdb_serial)] +
self.connect_srst_enable_arg +
self.connect_rst_enable_arg +
['-ex', "monitor swdp_scan",
'-ex', "attach 1",
'-ex', "file {}".format(self.elf_file),

View file

@ -45,9 +45,9 @@ EXPECTED_COMMANDS = {
}
EXPECTED_CONNECT_SRST_COMMAND = {
'attach': 'monitor connect_srst disable',
'debug': 'monitor connect_srst enable',
'flash': 'monitor connect_srst enable',
'attach': 'monitor connect_rst disable',
'debug': 'monitor connect_rst enable',
'flash': 'monitor connect_rst enable',
}
def require_patch(program):
@ -78,9 +78,9 @@ def test_blackmagicprobe_create(cc, req, command, runner_config):
@pytest.mark.parametrize('command', EXPECTED_CONNECT_SRST_COMMAND)
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
@patch('runners.core.ZephyrBinaryRunner.check_call')
def test_blackmagicprobe_connect_srst(cc, req, command, runner_config):
'''Test that commands list the correct connect_srst value when enabled.'''
args = ['--gdb-serial', TEST_GDB_SERIAL, '--connect-srst']
def test_blackmagicprobe_connect_rst(cc, req, command, runner_config):
'''Test that commands list the correct connect_rst value when enabled.'''
args = ['--gdb-serial', TEST_GDB_SERIAL, '--connect-rst']
parser = argparse.ArgumentParser()
BlackMagicProbeRunner.add_parser(parser)
arg_namespace = parser.parse_args(args)