Skip to content

Commit

Permalink
runners: jlink: Add support for J-Link over IP
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
marnold-b authored and carlescufi committed Jan 9, 2024
1 parent d9c0d69 commit 240bd8e
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions scripts/west_commands/runners/jlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'''Runner for debugging with J-Link.'''

import argparse
import ipaddress
import logging
import os
from pathlib import Path
Expand All @@ -25,6 +26,13 @@
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):
Expand Down Expand Up @@ -80,7 +88,8 @@ def capabilities(cls):
@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:
Expand Down Expand Up @@ -226,9 +235,9 @@ def do_run(self, command, **kwargs):
'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,
Expand Down Expand Up @@ -355,8 +364,7 @@ def flash(self, **kwargs):
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,
Expand Down

0 comments on commit 240bd8e

Please sign in to comment.