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

JLink: Add serial number argument to specify flashing target #118

Merged
merged 2 commits into from
Dec 11, 2024
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: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,15 @@ knowing the device type of the MCU on the board.

tockloader [command] --board [board] --arch [arch] --page-size [page_size] \
--jlink --jlink-cmd [jlink_cmd] --jlink-device [device] \
--jlink-speed [speed] --jlink-if [if]
--jlink-speed [speed] --jlink-if [if] \
--jlink-serial-number [serial_number]

- `jlink_cmd`: The JLink executable to invoke. Defaults to `JLinkExe` on
Mac/Linux, and `JLink` on Windows.
- `device`: The JLinkExe device identifier.
- `speed`: The speed value to pass to JLink. Defaults to 1200.
- `if`: The interface to pass to JLink.
- `serial-number`: The serial number of the target board to use with JLink.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a separate paragraph?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following the formatting above for this as a code block. Should I alter this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's right / necessary for the markdown to render correctly.

Without space before 203:
image

Without space before 207:
image

As-is:
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No sorry I meant this is a jlink option (and only jlink) and should go with the --jlink example above.

Tockloader can also do JTAG using OpenOCD. OpenOCD needs to know which config
file to use.
Expand Down
21 changes: 19 additions & 2 deletions tockloader/jlinkexe.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def __init__(self, args):
if platform.system() == "Windows":
self.jlink_cmd = "JLink"

# Obtain serial number if --jlink-serial-number argument provided
self.jlink_serial_number = getattr(self.args, "jlink_serial_number")

# 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
Expand Down Expand Up @@ -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_number:
jlink_command += " -USB {}".format(self.jlink_serial_number)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, I guess this could lead to weird errors if you happen to supply a "serial number" with spaces or other weird characters in there. On the other hand, I don't think we should sanitize these inputs, so this seems good to me.


logging.debug('Running "{}".'.format(jlink_command))

def print_output(subp):
Expand Down Expand Up @@ -456,9 +463,19 @@ def run_terminal(self):
return

logging.status("Starting JLinkExe JTAG connection.")

# Include serial number specifier if `--jlink-serial-number` flag provided.
jlink_serial_number_str = ""
if self.jlink_serial_number:
jlink_serial_number_str = ("-USB {}").format(self.jlink_serial_number)

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
"{} -device {} -if {} -speed {} -autoconnect 1 {} --jtagconf -1,-1".format(
self.jlink_cmd,
self.jlink_device,
self.jlink_if,
self.jlink_speed,
jlink_serial_number_str,
).split(),
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-number",
default=None,
help="Specify a specific JLink via serial number. Useful when multiple JLinks are connected to the same machine.",
)
parent_channel.add_argument(
"--openocd-board", help="The cfg file in OpenOCD `board` folder."
)
Expand Down
Loading