Skip to content

Commit 6b9f0df

Browse files
rhsskMaureenHelm
authored andcommitted
runners: pyocd: add --telnet-port parameter
With multiple debug probes attached, attempting to launch multiple debug servers resulted in "OSError: [Errno 98] Address already in use" despite explicitly setting --gdb-port to unique values. The issue was caused by the default telnet port: 4444. Adding --telnet-port parameter allows to explicitly define the address to a unique value and avoid the socket exception. Signed-off-by: Rihards Skuja <[email protected]>
1 parent 0c4f4a9 commit 6b9f0df

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

scripts/west_commands/runners/pyocd.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
BuildConfiguration
1111

1212
DEFAULT_PYOCD_GDB_PORT = 3333
13+
DEFAULT_PYOCD_TELNET_PORT = 4444
1314

1415

1516
class PyOcdBinaryRunner(ZephyrBinaryRunner):
@@ -18,7 +19,8 @@ class PyOcdBinaryRunner(ZephyrBinaryRunner):
1819
def __init__(self, cfg, target,
1920
pyocd='pyocd',
2021
flash_addr=0x0, flash_opts=None,
21-
gdb_port=DEFAULT_PYOCD_GDB_PORT, tui=False,
22+
gdb_port=DEFAULT_PYOCD_GDB_PORT,
23+
telnet_port=DEFAULT_PYOCD_TELNET_PORT, tui=False,
2224
board_id=None, daparg=None, frequency=None):
2325
super(PyOcdBinaryRunner, self).__init__(cfg)
2426

@@ -27,6 +29,7 @@ def __init__(self, cfg, target,
2729
self.flash_addr_args = ['-a', hex(flash_addr)] if flash_addr else []
2830
self.gdb_cmd = [cfg.gdb] if cfg.gdb is not None else None
2931
self.gdb_port = gdb_port
32+
self.telnet_port = telnet_port
3033
self.tui_args = ['-tui'] if tui else []
3134
self.hex_name = cfg.hex_file
3235
self.bin_name = cfg.bin_file
@@ -75,6 +78,9 @@ def do_add_parser(cls, parser):
7578
parser.add_argument('--gdb-port', default=DEFAULT_PYOCD_GDB_PORT,
7679
help='pyocd gdb port, defaults to {}'.format(
7780
DEFAULT_PYOCD_GDB_PORT))
81+
parser.add_argument('--telnet-port', default=DEFAULT_PYOCD_TELNET_PORT,
82+
help='pyocd telnet port, defaults to {}'.format(
83+
DEFAULT_PYOCD_TELNET_PORT))
7884
parser.add_argument('--tui', default=False, action='store_true',
7985
help='if given, GDB uses -tui')
8086
parser.add_argument('--board-id',
@@ -89,7 +95,7 @@ def create(cls, cfg, args):
8995
cfg, args.target,
9096
pyocd=args.pyocd,
9197
flash_addr=flash_addr, flash_opts=args.flash_opt,
92-
gdb_port=args.gdb_port, tui=args.tui,
98+
gdb_port=args.gdb_port, telnet_port=args.telnet_port, tui=args.tui,
9399
board_id=args.board_id, daparg=args.daparg,
94100
frequency=args.frequency)
95101

@@ -102,7 +108,7 @@ def create(cls, cfg, args):
102108
return ret
103109

104110
def port_args(self):
105-
return ['-p', str(self.gdb_port)]
111+
return ['-p', str(self.gdb_port), '-T', str(self.telnet_port)]
106112

107113
def do_run(self, command, **kwargs):
108114
self.require(self.pyocd)

scripts/west_commands/tests/test_pyocd.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
TEST_DAPARG = 'test-daparg'
2424
TEST_TARGET = 'test-target'
2525
TEST_FLASH_OPTS = ['--test-flash', 'args']
26-
TEST_PORT = 1
26+
TEST_GDB_PORT = 1
27+
TEST_TELNET_PORT = 2
2728

2829
TEST_ALL_KWARGS = {
2930
'pyocd': TEST_PYOCD,
3031
'flash_addr': TEST_ADDR,
3132
'flash_opts': TEST_FLASH_OPTS,
32-
'gdb_port': TEST_PORT,
33+
'gdb_port': TEST_GDB_PORT,
34+
'telnet_port': TEST_TELNET_PORT,
3335
'tui': False,
3436
'board_id': TEST_BOARD_ID,
3537
'frequency': TEST_FREQUENCY,
@@ -43,7 +45,8 @@
4345
'--pyocd', TEST_PYOCD] +
4446
['--flash-opt={}'.format(o) for o in
4547
TEST_FLASH_OPTS] +
46-
['--gdb-port', str(TEST_PORT),
48+
['--gdb-port', str(TEST_GDB_PORT),
49+
'--telnet-port', str(TEST_TELNET_PORT),
4750
'--board-id', TEST_BOARD_ID,
4851
'--frequency', str(TEST_FREQUENCY)])
4952

@@ -76,18 +79,20 @@
7679
DEBUG_ALL_EXPECTED_SERVER = [TEST_PYOCD,
7780
'gdbserver',
7881
'-da', TEST_DAPARG,
79-
'-p', str(TEST_PORT),
82+
'-p', str(TEST_GDB_PORT),
83+
'-T', str(TEST_TELNET_PORT),
8084
'-t', TEST_TARGET,
8185
'-u', TEST_BOARD_ID,
8286
'-f', TEST_FREQUENCY]
8387
DEBUG_ALL_EXPECTED_CLIENT = [RC_GDB, RC_KERNEL_ELF,
84-
'-ex', 'target remote :{}'.format(TEST_PORT),
88+
'-ex', 'target remote :{}'.format(TEST_GDB_PORT),
8589
'-ex', 'monitor halt',
8690
'-ex', 'monitor reset',
8791
'-ex', 'load']
8892
DEBUG_DEF_EXPECTED_SERVER = ['pyocd',
8993
'gdbserver',
9094
'-p', '3333',
95+
'-T', '4444',
9196
'-t', TEST_TARGET]
9297
DEBUG_DEF_EXPECTED_CLIENT = [RC_GDB, RC_KERNEL_ELF,
9398
'-ex', 'target remote :3333',
@@ -99,13 +104,15 @@
99104
DEBUGSERVER_ALL_EXPECTED_CALL = [TEST_PYOCD,
100105
'gdbserver',
101106
'-da', TEST_DAPARG,
102-
'-p', str(TEST_PORT),
107+
'-p', str(TEST_GDB_PORT),
108+
'-T', str(TEST_TELNET_PORT),
103109
'-t', TEST_TARGET,
104110
'-u', TEST_BOARD_ID,
105111
'-f', TEST_FREQUENCY]
106112
DEBUGSERVER_DEF_EXPECTED_CALL = ['pyocd',
107113
'gdbserver',
108114
'-p', '3333',
115+
'-T', '4444',
109116
'-t', TEST_TARGET]
110117

111118

0 commit comments

Comments
 (0)