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

scripts: west_commands: runners: fix support for JLink RTT #83832

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
17 changes: 11 additions & 6 deletions scripts/west_commands/runners/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,22 +920,27 @@ def ensure_output(self, output_type: str) -> None:
# RuntimeError avoids a stack trace saved in run_common.
raise RuntimeError(err)

def run_telnet_client(self, host: str, port: int) -> None:
def run_telnet_client(self, host: str, port: int, active_sock=None) -> None:
'''
Run a telnet client for user interaction.
'''
# If a `nc` command is available, run it, as it will provide the best support for
# CONFIG_SHELL_VT100_COMMANDS etc.
if shutil.which('nc') is not None:
# If the caller passed in an active socket, use that
if active_sock is not None:
sock = active_sock
elif shutil.which('nc') is not None:
# If a `nc` command is available, run it, as it will provide the
# best support for CONFIG_SHELL_VT100_COMMANDS etc.
client_cmd = ['nc', host, str(port)]
# Note: netcat (nc) does not handle sigint, so cannot use run_client()
self.check_call(client_cmd)
return
else:
# Start a new socket connection
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))

# Otherwise, use a pure python implementation. This will work well for logging,
# but input is line based only.
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
sel = selectors.DefaultSelector()
sel.register(sys.stdin, selectors.EVENT_READ)
sel.register(sock, selectors.EVENT_READ)
Expand Down
4 changes: 1 addition & 3 deletions scripts/west_commands/runners/jlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,7 @@ def do_run(self, command, **kwargs):
break
except ConnectionRefusedError:
time.sleep(0.1)
sock.shutdown(socket.SHUT_RDWR)
time.sleep(0.1)
self.run_telnet_client('localhost', self.rtt_port)
self.run_telnet_client('localhost', self.rtt_port, sock)
except Exception as e:
self.logger.error(e)
finally:
Expand Down
Loading