From 59208ac13bd82ef6619c03eabd8007af0b92c7dd Mon Sep 17 00:00:00 2001 From: Frank Li Date: Sun, 24 Nov 2019 17:10:07 +0800 Subject: [PATCH] runners: pyocd: add --tool-opt parameter add --tool-opt to support more pyocd parameter Signed-off-by: Frank Li --- scripts/west_commands/runners/pyocd.py | 17 ++++++++++++++--- scripts/west_commands/tests/test_pyocd.py | 14 ++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/scripts/west_commands/runners/pyocd.py b/scripts/west_commands/runners/pyocd.py index 8b7512d04a3..ae15175b51a 100644 --- a/scripts/west_commands/runners/pyocd.py +++ b/scripts/west_commands/runners/pyocd.py @@ -21,7 +21,7 @@ class PyOcdBinaryRunner(ZephyrBinaryRunner): flash_addr=0x0, flash_opts=None, gdb_port=DEFAULT_PYOCD_GDB_PORT, telnet_port=DEFAULT_PYOCD_TELNET_PORT, tui=False, - board_id=None, daparg=None, frequency=None): + board_id=None, daparg=None, frequency=None, tool_opt=None): super(PyOcdBinaryRunner, self).__init__(cfg) self.target_args = ['-t', target] @@ -50,6 +50,11 @@ class PyOcdBinaryRunner(ZephyrBinaryRunner): frequency_args = ['-f', frequency] self.frequency_args = frequency_args + tool_opt_args = [] + if tool_opt is not None: + tool_opt_args = [tool_opt] + self.tool_opt_args = tool_opt_args + self.flash_extra = flash_opts if flash_opts else [] @classmethod @@ -85,6 +90,9 @@ class PyOcdBinaryRunner(ZephyrBinaryRunner): help='if given, GDB uses -tui') parser.add_argument('--board-id', help='ID of board to flash, default is to prompt') + parser.add_argument('--tool-opt', + help='''Additional options for pyocd Commander, + e.g. \'--script=user.py\' ''') @classmethod def create(cls, cfg, args): @@ -97,7 +105,8 @@ class PyOcdBinaryRunner(ZephyrBinaryRunner): flash_addr=flash_addr, flash_opts=args.flash_opt, gdb_port=args.gdb_port, telnet_port=args.telnet_port, tui=args.tui, board_id=args.board_id, daparg=args.daparg, - frequency=args.frequency) + frequency=args.frequency, + tool_opt=args.tool_opt) daparg = os.environ.get('PYOCD_DAPARG') if not ret.daparg_args and daparg: @@ -139,6 +148,7 @@ class PyOcdBinaryRunner(ZephyrBinaryRunner): self.target_args + self.board_args + self.frequency_args + + self.tool_opt_args + self.flash_extra + [fname]) @@ -156,7 +166,8 @@ class PyOcdBinaryRunner(ZephyrBinaryRunner): self.port_args() + self.target_args + self.board_args + - self.frequency_args) + self.frequency_args + + self.tool_opt_args) if command == 'debugserver': self.log_gdbserver_message() diff --git a/scripts/west_commands/tests/test_pyocd.py b/scripts/west_commands/tests/test_pyocd.py index f4a99486e3b..62cecfb6a8e 100644 --- a/scripts/west_commands/tests/test_pyocd.py +++ b/scripts/west_commands/tests/test_pyocd.py @@ -25,6 +25,7 @@ TEST_TARGET = 'test-target' TEST_FLASH_OPTS = ['--test-flash', 'args'] TEST_GDB_PORT = 1 TEST_TELNET_PORT = 2 +TEST_TOOL_OPT = 'test-opt' TEST_ALL_KWARGS = { 'pyocd': TEST_PYOCD, @@ -36,6 +37,7 @@ TEST_ALL_KWARGS = { 'board_id': TEST_BOARD_ID, 'frequency': TEST_FREQUENCY, 'daparg': TEST_DAPARG, + 'tool_opt': TEST_TOOL_OPT, } TEST_DEF_KWARGS = {} @@ -48,7 +50,8 @@ TEST_ALL_PARAMS = (['--target', TEST_TARGET, ['--gdb-port', str(TEST_GDB_PORT), '--telnet-port', str(TEST_TELNET_PORT), '--board-id', TEST_BOARD_ID, - '--frequency', str(TEST_FREQUENCY)]) + '--frequency', str(TEST_FREQUENCY), + '--tool-opt', TEST_TOOL_OPT]) TEST_DEF_PARAMS = ['--target', TEST_TARGET] @@ -69,7 +72,8 @@ FLASH_ALL_EXPECTED_CALL = ([TEST_PYOCD, '-e', 'sector', '-a', hex(TEST_ADDR), '-da', TEST_DAPARG, '-t', TEST_TARGET, '-u', TEST_BOARD_ID, - '-f', TEST_FREQUENCY] + + '-f', TEST_FREQUENCY, + TEST_TOOL_OPT] + TEST_FLASH_OPTS + [RC_KERNEL_HEX]) FLASH_DEF_EXPECTED_CALL = ['pyocd', 'flash', '-e', 'sector', @@ -83,7 +87,8 @@ DEBUG_ALL_EXPECTED_SERVER = [TEST_PYOCD, '-T', str(TEST_TELNET_PORT), '-t', TEST_TARGET, '-u', TEST_BOARD_ID, - '-f', TEST_FREQUENCY] + '-f', TEST_FREQUENCY, + TEST_TOOL_OPT] DEBUG_ALL_EXPECTED_CLIENT = [RC_GDB, RC_KERNEL_ELF, '-ex', 'target remote :{}'.format(TEST_GDB_PORT), '-ex', 'monitor halt', @@ -108,7 +113,8 @@ DEBUGSERVER_ALL_EXPECTED_CALL = [TEST_PYOCD, '-T', str(TEST_TELNET_PORT), '-t', TEST_TARGET, '-u', TEST_BOARD_ID, - '-f', TEST_FREQUENCY] + '-f', TEST_FREQUENCY, + TEST_TOOL_OPT] DEBUGSERVER_DEF_EXPECTED_CALL = ['pyocd', 'gdbserver', '-p', '3333',