Skip to content

Commit

Permalink
Add jlink_serial_no argument to specify target
Browse files Browse the repository at this point in the history
-adds flag `--jlink-serial-no XXXX` to specify target board
  • Loading branch information
tyler-potyondy committed Nov 7, 2024
1 parent 0d22542 commit a705ba1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------------------
Expand Down
14 changes: 11 additions & 3 deletions tockloader/jlinkexe.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def __init__(self, args):
self.jlink_cmd = "JLinkExe"
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,
Expand Down Expand Up @@ -195,6 +198,10 @@ def _run_jtag_commands(self, commands, binary, write=True):
self.jlink_speed,
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))

Expand Down Expand Up @@ -456,10 +463,11 @@ 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,
)
Expand Down
5 changes: 5 additions & 0 deletions tockloader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Expand Down

0 comments on commit a705ba1

Please sign in to comment.