runners: jlink: Add support for J-Link over IP

Add support for J-Link over IP and J-Link remote server.
If the "--dev-id" is a valid ip, the transport over ip is selected.
Otherwise usb is selected.

Signed-off-by: Michael Arnold <marnold@baumer.com>
This commit is contained in:
Michael Arnold 2023-11-15 16:36:36 +00:00 committed by Carles Cufí
commit 240bd8e16a

View file

@ -5,6 +5,7 @@
'''Runner for debugging with J-Link.'''
import argparse
import ipaddress
import logging
import os
from pathlib import Path
@ -25,6 +26,13 @@ except ImportError:
DEFAULT_JLINK_EXE = 'JLink.exe' if sys.platform == 'win32' else 'JLinkExe'
DEFAULT_JLINK_GDB_PORT = 2331
def is_ip(ip):
try:
ipaddress.ip_address(ip)
except ValueError:
return False
return True
class ToggleAction(argparse.Action):
def __call__(self, parser, args, ignored, option):
@ -80,7 +88,8 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
@classmethod
def dev_id_help(cls) -> str:
return '''Device identifier. Use it to select the J-Link Serial Number
of the device connected over USB.'''
of the device connected over USB. If the J-Link is connected over ip,
the Device identifier is the ip.'''
@classmethod
def tool_opt_help(cls) -> str:
@ -226,9 +235,9 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
'RTOSPlugin_Zephyr')
server_cmd = ([self.gdbserver] +
# only USB connections supported
['-select', 'usb' + (f'={self.dev_id}'
if self.dev_id else ''),
['-select',
('ip' if is_ip(self.dev_id) else 'usb') +
(f'={self.dev_id}' if self.dev_id else ''),
'-port', str(self.gdb_port),
'-if', self.iface,
'-speed', self.speed,
@ -355,8 +364,7 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
loader_details = "?" + self.loader
cmd = ([self.commander] +
# only USB connections supported
(['-USB', f'{self.dev_id}'] if self.dev_id else []) +
(['-IP', f'{self.dev_id}'] if is_ip(self.dev_id) else (['-USB', f'{self.dev_id}'] if self.dev_id else [])) +
(['-nogui', '1'] if self.supports_nogui else []) +
['-if', self.iface,
'-speed', self.speed,