@@ -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