Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

west: runners: jlink: add support for -nogui 1 command line parameter #27617

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/west_commands/runners/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def check_call(self, cmd):
return
subprocess.check_call(cmd)

def check_output(self, cmd):
def check_output(self, cmd, **kwargs):
'''Subclass subprocess.check_output() wrapper.

Subclasses should use this method to run command in a
Expand All @@ -574,7 +574,7 @@ def check_output(self, cmd):
self._log_cmd(cmd)
if _DRY_RUN:
return b''
return subprocess.check_output(cmd)
return subprocess.check_output(cmd, **kwargs)

def popen_ignore_int(self, cmd):
'''Spawn a child command, ensuring it ignores SIGINT.
Expand Down
43 changes: 42 additions & 1 deletion scripts/west_commands/runners/jlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@

import argparse
import os
import platform
import re
import shlex
import sys
import tempfile

from packaging import version
from runners.core import ZephyrBinaryRunner, RunnerCaps, \
BuildConfiguration
from subprocess import TimeoutExpired

DEFAULT_JLINK_EXE = 'JLink.exe' if sys.platform == 'win32' else 'JLinkExe'
DEFAULT_JLINK_GDB_PORT = 2331
Expand Down Expand Up @@ -104,6 +108,38 @@ def print_gdbserver_message(self):
self.logger.info('J-Link GDB server running on port {}'.
format(self.gdb_port))

def read_version(self):
'''Read the J-Link Commander version output.

J-Link Commander does not provide neither a stand-alone version string
output nor command line parameter help output. To find the version, we
launch it using a bogus command line argument (to get it to fail) and
read the version information provided to stdout.

A timeout is used since the J-Link Commander takes up to a few seconds
to exit upon failure.'''
if platform.system() == 'Windows':
# The check below does not work on Microsoft Windows
return ''

self.require(self.commander)
# Match "Vd.dd" substring
ver_re = re.compile(r'\s+V([.0-9]+)[a-zA-Z]*\s+', re.IGNORECASE)
cmd = ([self.commander] + ['-bogus-argument-that-does-not-exist'])
try:
self.check_output(cmd, timeout=0.1)
except TimeoutExpired as e:
ver_m = ver_re.search(e.output.decode('utf-8'))
if ver_m:
return ver_m.group(1)
else:
return ''

def supports_nogui(self):
ver = self.read_version()
# -nogui was introduced in J-Link Commander v6.80
return version.parse(ver) >= version.parse("6.80")

def do_run(self, command, **kwargs):
server_cmd = ([self.gdbserver] +
['-select', 'usb', # only USB connections supported
Expand Down Expand Up @@ -179,7 +215,12 @@ def flash(self, **kwargs):
with open(fname, 'wb') as f:
f.writelines(bytes(line + '\n', 'utf-8') for line in lines)

cmd = ([self.commander] +
if self.supports_nogui():
nogui = ['-nogui', '1']
else:
nogui = []

cmd = ([self.commander] + nogui +
['-if', self.iface,
'-speed', self.speed,
'-device', self.device,
Expand Down