From a088a79cf76a5c5c373af717cddb672271655e34 Mon Sep 17 00:00:00 2001 From: Tyler Potyondy Date: Thu, 9 May 2024 09:56:46 -0700 Subject: [PATCH] Add jlink_serial_no argument to specify target -adds flag `--jlink-serial-no XXXX` to specify target board --- README.md | 2 ++ tockloader/jlinkexe.py | 19 ++++++++++++++++--- tockloader/main.py | 5 +++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 095ff0e..f67279f 100644 --- a/README.md +++ b/README.md @@ -287,6 +287,8 @@ operation based on the requirements of a particular hardware platform. bundle using only a single flash command. This will require that anytime any app changes in any way (e.g. its header changes or the app is updated or a new app is installed) all apps are re-written. +- `--jlink-serial-no`: This selects which attached JLink device Tockloader is to + interact with using the specified JLink serial number. Credentials and Integrity Support --------------------------------- diff --git a/tockloader/jlinkexe.py b/tockloader/jlinkexe.py index 09f30f1..735312f 100644 --- a/tockloader/jlinkexe.py +++ b/tockloader/jlinkexe.py @@ -36,6 +36,9 @@ def __init__(self, args): if platform.system() == "Windows": self.jlink_cmd = "JLink" + # Obtain serial number if --jlink_serial_no argument provided + self.jlink_serial_no = getattr(self.args, "jlink_serial_no") + # By default we assume that jlinkexe can be used to read any address on # this board, so we set `address_maximum` to None. In some cases, # however, particularly with external flash chips, jlinkexe may not be @@ -196,6 +199,10 @@ def _run_jtag_commands(self, commands, binary, write=True): jlink_file.name, ) + # append target selector if serial number provided + if self.jlink_serial_no: + jlink_command += " -USB {} ".format(self.jlink_serial_no) + logging.debug('Running "{}".'.format(jlink_command)) def print_output(subp): @@ -456,10 +463,16 @@ def run_terminal(self): return logging.status("Starting JLinkExe JTAG connection.") - jtag_p = subprocess.Popen( - "{} -device {} -if {} -speed {} -autoconnect 1 -jtagconf -1,-1".format( - self.jlink_cmd, self.jlink_device, self.jlink_if, self.jlink_speed + command_str = ( + "{} -device {} -if {} -speed {} -autoconnect 1 -USB {} --jtagconf -1,-1".format( + self.jlink_cmd, + self.jlink_device, + self.jlink_if, + self.jlink_speed, + "" if self.jlink_serial_no is None else self.jlink_serial_no, ).split(), + ) + jtag_p = subprocess.Popen( stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) diff --git a/tockloader/main.py b/tockloader/main.py index 46055af..e57b652 100644 --- a/tockloader/main.py +++ b/tockloader/main.py @@ -778,6 +778,11 @@ def main(): parent_channel.add_argument( "--jlink-if", help="The interface type to pass to JLinkExe." ) + parent_channel.add_argument( + "--jlink-serial-no", + default=None, + help="Specify a specific JLink via serial number. Useful when multiple JLinks connected to same machine.", + ) parent_channel.add_argument( "--openocd-board", help="The cfg file in OpenOCD `board` folder." )