summaryrefslogtreecommitdiff
path: root/util/flash_jlink.py
diff options
context:
space:
mode:
authorCraig Hesling <hesling@chromium.org>2021-07-26 21:29:40 -0400
committerCommit Bot <commit-bot@chromium.org>2021-07-28 04:30:36 +0000
commit4aaa2f7ab2ab63004d4ed49c348f9aa7349e19bc (patch)
treee3b29ac68a4a4933799bde64181679337518e115 /util/flash_jlink.py
parent74e34f6bafc551dcb96cab22c558226f55b5b4d0 (diff)
downloadchrome-ec-4aaa2f7ab2ab63004d4ed49c348f9aa7349e19bc.tar.gz
util/flash_jlink: Change to USB as default
This change does the following: * allows for J-Link over USB to be the default connection * allows for passing in hostnames as the remote target, despite the segger tool only accepting IP addresses * changes the --ip arg to --remote, since this better describes the host + port description being provided BRANCH=none BUG=none TEST=# Check over USB ./util/flash_jlink.py TEST=JLinkRemoteServerCLExe ./util/flash_jlink.py --remote 127.0.0.1 ./util/flash_jlink.py --remote 127.0.0.1:19020 ./util/flash_jlink.py --remote localhost ./util/flash_jlink.py --remote localhost:19020 ./util/flash_jlink.py --remote localtoast # Should fail ./util/flash_jlink.py --remote localhost:port # Should fail Signed-off-by: Craig Hesling <hesling@chromium.org> Change-Id: I63c5a250f25bcae9828dc88b6282ac301b9a519f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3054818 Reviewed-by: Josie Nordrum <josienordrum@google.com>
Diffstat (limited to 'util/flash_jlink.py')
-rwxr-xr-xutil/flash_jlink.py54
1 files changed, 35 insertions, 19 deletions
diff --git a/util/flash_jlink.py b/util/flash_jlink.py
index e30badd059..d2fd4dec15 100755
--- a/util/flash_jlink.py
+++ b/util/flash_jlink.py
@@ -23,6 +23,9 @@ import sys
import tempfile
import time
+
+DEFAULT_SEGGER_REMOTE_PORT = 19020
+
# Commands are documented here: https://wiki.segger.com/J-Link_Commander
JLINK_COMMANDS = '''
exitonerror 1
@@ -94,29 +97,44 @@ def create_jlink_command_file(firmware_file, config):
return tmp
-def flash(jlink_exe, ip, device, interface, cmd_file):
+def flash(jlink_exe, remote, device, interface, cmd_file):
cmd = [
jlink_exe,
]
- if ip:
- ip_components = ip.split(':')
- if len(ip_components) != 2:
- logging.error(f'Given ip arg "{ip}" is malformed.')
+ if remote:
+ logging.debug(f'Connecting to J-Link over TCP/IP {remote}.')
+ remote_components = remote.split(':')
+ if len(remote_components) not in [1, 2]:
+ logging.debug(f'Given remote "{remote}" is malformed.')
return 1
- ip_host = ip_components[0]
+
+ host = remote_components[0]
try:
- ip_port = int(ip_components[1])
- except ValueError:
- logging.error(
- f'Given ip arg port "{ip_components[1]}" is malformed.')
+ ip = socket.gethostbyname(host)
+ except socket.gaierror as e:
+ logging.error(f'Failed to resolve host "{host}": {e}.')
return 1
- if not is_tcp_port_open(ip_host, ip_port):
+ logging.debug(f'Resolved {host} as {ip}.')
+ port = DEFAULT_SEGGER_REMOTE_PORT
+
+ if len(remote_components) == 2:
+ try:
+ port = int(remote_components[1])
+ except ValueError:
+ logging.error(
+ f'Given remote port "{remote_components[1]}" is malformed.')
+ return 1
+
+ remote = f'{ip}:{port}'
+
+ logging.debug(f'Checking connection to {remote}.')
+ if not is_tcp_port_open(ip, port):
logging.error(
- f'JLink server doesn\'t seem to be listening on {ip}.')
+ f'JLink server doesn\'t seem to be listening on {remote}.')
logging.error('Ensure that JLinkRemoteServerCLExe is running.')
return 1
- cmd.extend(['-ip', ip])
+ cmd.extend(['-ip', remote])
cmd.extend([
'-device', device,
@@ -143,12 +161,10 @@ def main(argv: list):
help='JLinkExe path (default: ' + default_jlink + ')',
default=default_jlink)
- default_ip = '127.0.0.1:19020'
parser.add_argument(
- '--ip', '-n',
- help='IP address of J-Link or machine running JLinkRemoteServerCLExe '
- '(default: ' + default_ip + ')',
- default=default_ip)
+ '--remote', '-n',
+ help='Use TCP/IP host[:port] to connect to a J-Link or '
+ 'JLinkRemoteServerCLExe. If unspecified, connect over USB.')
default_board = 'bloonchipper'
parser.add_argument(
@@ -182,7 +198,7 @@ def main(argv: list):
args.jlink = args.jlink
cmd_file = create_jlink_command_file(args.image, config)
- ret_code = flash(args.jlink, args.ip, config.device, config.interface,
+ ret_code = flash(args.jlink, args.remote, config.device, config.interface,
cmd_file.name)
cmd_file.close()
return ret_code