Skip to content

Commit d8ea3ab

Browse files
authored
Merge pull request #119 from charles37/master
Add OpenOCD Serial Number Flag
2 parents e3f7966 + ae9cc6a commit d8ea3ab

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

tockloader/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,11 @@ def main():
795795
default=None,
796796
help="Specify a specific JLink via serial number. Useful when multiple JLinks are connected to the same machine.",
797797
)
798+
parent_channel.add_argument(
799+
"--openocd-serial-number",
800+
default=None,
801+
help="Specify a specific board via serial number when using OpenOCD. Useful when multiple identical boards are connected.",
802+
)
798803
parent_channel.add_argument(
799804
"--openocd-board", help="The cfg file in OpenOCD `board` folder."
800805
)

tockloader/openocd.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def __init__(self, args):
3131
# Command can be passed in as an argument, otherwise use default.
3232
self.openocd_cmd = getattr(self.args, "openocd_cmd")
3333

34+
# Store the serial number if provided
35+
self.openocd_serial_number = getattr(self.args, "openocd_serial_number")
36+
3437
def attached_board_exists(self):
3538
# Get a list of attached devices, check if that list has at least
3639
# one entry.
@@ -132,8 +135,14 @@ def _gather_openocd_cmdline(self, commands, binary, write=True, exit=True):
132135
# Defaults.
133136
prefix = ""
134137
source = "source [find board/{board}];".format(board=self.openocd_board)
138+
135139
cmd_prefix = "init; reset init; halt;"
136140
cmd_suffix = ""
141+
serial_no_cmd = ""
142+
143+
# Add serial number specification if provided
144+
if hasattr(self, "openocd_serial_number") and self.openocd_serial_number:
145+
serial_no_cmd = "adapter serial {};".format(self.openocd_serial_number)
137146

138147
# Do the customizations
139148
if "workareazero" in self.openocd_options:
@@ -151,12 +160,15 @@ def _gather_openocd_cmdline(self, commands, binary, write=True, exit=True):
151160
if exit:
152161
cmd_suffix += "exit"
153162

154-
command_param = "{prefix} {source} {cmd_prefix} {cmd} {cmd_suffix}".format(
155-
prefix=prefix,
156-
source=source,
157-
cmd_prefix=cmd_prefix,
158-
cmd="; ".join(commands),
159-
cmd_suffix=cmd_suffix,
163+
command_param = (
164+
"{prefix} {serial_no_cmd} {source} {cmd_prefix} {cmd} {cmd_suffix}".format(
165+
prefix=prefix,
166+
serial_no_cmd=serial_no_cmd,
167+
source=source,
168+
cmd_prefix=cmd_prefix,
169+
cmd="; ".join(commands),
170+
cmd_suffix=cmd_suffix,
171+
)
160172
)
161173

162174
return (

0 commit comments

Comments
 (0)