1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * Copyright (C) 2007-2010 Øyvind Harboe *
6 * oyvind.harboe@zylin.com *
8 * Copyright (C) 2009 SoftPLC Corporation *
12 * Copyright (C) 2009 Zachary T Welch *
13 * zw@superlucidity.net *
15 * This program is free software; you can redistribute it and/or modify *
16 * it under the terms of the GNU General Public License as published by *
17 * the Free Software Foundation; either version 2 of the License, or *
18 * (at your option) any later version. *
20 * This program is distributed in the hope that it will be useful, *
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
23 * GNU General Public License for more details. *
25 * You should have received a copy of the GNU General Public License *
26 * along with this program; if not, write to the *
27 * Free Software Foundation, Inc., *
28 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
29 ***************************************************************************/
35 #include "minidriver.h"
36 #include "interface.h"
37 #include "interfaces.h"
38 #include "transport.h"
46 * Holds support for configuring debug adapters from TCl scripts.
49 extern struct jtag_interface
*jtag_interface
;
54 jim_adapter_name(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
57 Jim_GetOpt_Setup(&goi
, interp
, argc
-1, argv
+ 1);
59 /* return the name of the interface */
60 /* TCL code might need to know the exact type... */
61 /* FUTURE: we allow this as a means to "set" the interface. */
63 Jim_WrongNumArgs(goi
.interp
, 1, goi
.argv
-1, "(no params)");
66 const char *name
= jtag_interface
? jtag_interface
->name
: NULL
;
67 Jim_SetResultString(goi
.interp
, name
? : "undefined", -1);
72 static int default_khz(int khz
, int *jtag_speed
)
74 LOG_ERROR("Translation from khz to jtag_speed not implemented");
78 static int default_speed_div(int speed
, int *khz
)
80 LOG_ERROR("Translation from jtag_speed to khz not implemented");
84 static int default_power_dropout(int *dropout
)
86 *dropout
= 0; /* by default we can't detect power dropout */
90 static int default_srst_asserted(int *srst_asserted
)
92 *srst_asserted
= 0; /* by default we can't detect srst asserted */
96 COMMAND_HANDLER(interface_transport_command
)
101 retval
= CALL_COMMAND_HANDLER(transport_list_parse
, &transports
);
102 if (retval
!= ERROR_OK
) {
105 retval
= allow_transports(CMD_CTX
, (const char **)transports
);
106 if (retval
!= ERROR_OK
) {
107 for (unsigned i
= 0; transports
[i
]; i
++)
115 COMMAND_HANDLER(handle_interface_list_command
)
117 if (strcmp(CMD_NAME
, "interface_list") == 0 && CMD_ARGC
> 0)
118 return ERROR_COMMAND_SYNTAX_ERROR
;
120 command_print(CMD_CTX
, "The following debug interfaces are available:");
121 for (unsigned i
= 0; NULL
!= jtag_interfaces
[i
]; i
++)
123 const char *name
= jtag_interfaces
[i
]->name
;
124 command_print(CMD_CTX
, "%u: %s", i
+ 1, name
);
130 COMMAND_HANDLER(handle_interface_command
)
132 /* check whether the interface is already configured */
135 LOG_WARNING("Interface already configured, ignoring");
139 /* interface name is a mandatory argument */
140 if (CMD_ARGC
!= 1 || CMD_ARGV
[0][0] == '\0')
141 return ERROR_COMMAND_SYNTAX_ERROR
;
143 for (unsigned i
= 0; NULL
!= jtag_interfaces
[i
]; i
++)
145 if (strcmp(CMD_ARGV
[0], jtag_interfaces
[i
]->name
) != 0)
148 if (NULL
!= jtag_interfaces
[i
]->commands
)
150 int retval
= register_commands(CMD_CTX
, NULL
,
151 jtag_interfaces
[i
]->commands
);
152 if (ERROR_OK
!= retval
)
156 jtag_interface
= jtag_interfaces
[i
];
158 if (jtag_interface
->khz
== NULL
)
159 jtag_interface
->khz
= default_khz
;
160 if (jtag_interface
->speed_div
== NULL
)
161 jtag_interface
->speed_div
= default_speed_div
;
162 if (jtag_interface
->power_dropout
== NULL
)
163 jtag_interface
->power_dropout
= default_power_dropout
;
164 if (jtag_interface
->srst_asserted
== NULL
)
165 jtag_interface
->srst_asserted
= default_srst_asserted
;
170 /* no valid interface was found (i.e. the configuration option,
171 * didn't match one of the compiled-in interfaces
173 LOG_ERROR("The specified debug interface was not found (%s)", CMD_ARGV
[0]);
174 CALL_COMMAND_HANDLER(handle_interface_list_command
);
175 return ERROR_JTAG_INVALID_INTERFACE
;
178 COMMAND_HANDLER(handle_reset_config_command
)
183 /* Original versions cared about the order of these tokens:
184 * reset_config signals [combination [trst_type [srst_type]]]
185 * They also clobbered the previous configuration even on error.
187 * Here we don't care about the order, and only change values
188 * which have been explicitly specified.
190 for (; CMD_ARGC
; CMD_ARGC
--, CMD_ARGV
++) {
195 m
= RESET_SRST_NO_GATING
;
196 if (strcmp(*CMD_ARGV
, "srst_gates_jtag") == 0)
197 /* default: don't use JTAG while SRST asserted */;
198 else if (strcmp(*CMD_ARGV
, "srst_nogate") == 0)
199 tmp
= RESET_SRST_NO_GATING
;
203 LOG_ERROR("extra reset_config %s spec (%s)",
204 "gating", *CMD_ARGV
);
205 return ERROR_INVALID_ARGUMENTS
;
211 m
= RESET_HAS_TRST
| RESET_HAS_SRST
;
212 if (strcmp(*CMD_ARGV
, "none") == 0)
214 else if (strcmp(*CMD_ARGV
, "trst_only") == 0)
215 tmp
= RESET_HAS_TRST
;
216 else if (strcmp(*CMD_ARGV
, "srst_only") == 0)
217 tmp
= RESET_HAS_SRST
;
218 else if (strcmp(*CMD_ARGV
, "trst_and_srst") == 0)
219 tmp
= RESET_HAS_TRST
| RESET_HAS_SRST
;
223 LOG_ERROR("extra reset_config %s spec (%s)",
224 "signal", *CMD_ARGV
);
225 return ERROR_INVALID_ARGUMENTS
;
230 /* combination (options for broken wiring) */
231 m
= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
232 if (strcmp(*CMD_ARGV
, "separate") == 0)
233 /* separate reset lines - default */;
234 else if (strcmp(*CMD_ARGV
, "srst_pulls_trst") == 0)
235 tmp
|= RESET_SRST_PULLS_TRST
;
236 else if (strcmp(*CMD_ARGV
, "trst_pulls_srst") == 0)
237 tmp
|= RESET_TRST_PULLS_SRST
;
238 else if (strcmp(*CMD_ARGV
, "combined") == 0)
239 tmp
|= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
243 LOG_ERROR("extra reset_config %s spec (%s)",
244 "combination", *CMD_ARGV
);
245 return ERROR_INVALID_ARGUMENTS
;
250 /* trst_type (NOP without HAS_TRST) */
251 m
= RESET_TRST_OPEN_DRAIN
;
252 if (strcmp(*CMD_ARGV
, "trst_open_drain") == 0)
253 tmp
|= RESET_TRST_OPEN_DRAIN
;
254 else if (strcmp(*CMD_ARGV
, "trst_push_pull") == 0)
255 /* push/pull from adapter - default */;
259 LOG_ERROR("extra reset_config %s spec (%s)",
260 "trst_type", *CMD_ARGV
);
261 return ERROR_INVALID_ARGUMENTS
;
266 /* srst_type (NOP without HAS_SRST) */
267 m
|= RESET_SRST_PUSH_PULL
;
268 if (strcmp(*CMD_ARGV
, "srst_push_pull") == 0)
269 tmp
|= RESET_SRST_PUSH_PULL
;
270 else if (strcmp(*CMD_ARGV
, "srst_open_drain") == 0)
271 /* open drain from adapter - default */;
275 LOG_ERROR("extra reset_config %s spec (%s)",
276 "srst_type", *CMD_ARGV
);
277 return ERROR_INVALID_ARGUMENTS
;
282 /* caller provided nonsense; fail */
283 LOG_ERROR("unknown reset_config flag (%s)", *CMD_ARGV
);
284 return ERROR_INVALID_ARGUMENTS
;
287 /* Remember the bits which were specified (mask)
288 * and their new values (new_cfg).
294 /* clear previous values of those bits, save new values */
296 int old_cfg
= jtag_get_reset_config();
300 jtag_set_reset_config(new_cfg
);
302 new_cfg
= jtag_get_reset_config();
306 * Display the (now-)current reset mode
310 /* minimal JTAG has neither SRST nor TRST (so that's the default) */
311 switch (new_cfg
& (RESET_HAS_TRST
| RESET_HAS_SRST
)) {
313 modes
[0] = "srst_only";
316 modes
[0] = "trst_only";
318 case RESET_TRST_AND_SRST
:
319 modes
[0] = "trst_and_srst";
326 /* normally SRST and TRST are decoupled; but bugs happen ... */
327 switch (new_cfg
& (RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
)) {
328 case RESET_SRST_PULLS_TRST
:
329 modes
[1] = "srst_pulls_trst";
331 case RESET_TRST_PULLS_SRST
:
332 modes
[1] = "trst_pulls_srst";
334 case RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
:
335 modes
[1] = "combined";
338 modes
[1] = "separate";
342 /* TRST-less connectors include Altera, Xilinx, and minimal JTAG */
343 if (new_cfg
& RESET_HAS_TRST
) {
344 if (new_cfg
& RESET_TRST_OPEN_DRAIN
)
345 modes
[3] = " trst_open_drain";
347 modes
[3] = " trst_push_pull";
351 /* SRST-less connectors include TI-14, Xilinx, and minimal JTAG */
352 if (new_cfg
& RESET_HAS_SRST
) {
353 if (new_cfg
& RESET_SRST_NO_GATING
)
354 modes
[2] = " srst_nogate";
356 modes
[2] = " srst_gates_jtag";
358 if (new_cfg
& RESET_SRST_PUSH_PULL
)
359 modes
[4] = " srst_push_pull";
361 modes
[4] = " srst_open_drain";
367 command_print(CMD_CTX
, "%s %s%s%s%s",
369 modes
[2], modes
[3], modes
[4]);
374 COMMAND_HANDLER(handle_adapter_nsrst_delay_command
)
377 return ERROR_COMMAND_SYNTAX_ERROR
;
381 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], delay
);
383 jtag_set_nsrst_delay(delay
);
385 command_print(CMD_CTX
, "adapter_nsrst_delay: %u", jtag_get_nsrst_delay());
389 COMMAND_HANDLER(handle_adapter_nsrst_assert_width_command
)
392 return ERROR_COMMAND_SYNTAX_ERROR
;
396 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], width
);
398 jtag_set_nsrst_assert_width(width
);
400 command_print(CMD_CTX
, "adapter_nsrst_assert_width: %u", jtag_get_nsrst_assert_width());
406 COMMAND_HANDLER(handle_adapter_khz_command
)
409 return ERROR_COMMAND_SYNTAX_ERROR
;
411 int retval
= ERROR_OK
;
415 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], khz
);
417 retval
= jtag_config_khz(khz
);
418 if (ERROR_OK
!= retval
)
422 int cur_speed
= jtag_get_speed_khz();
423 retval
= jtag_get_speed_readable(&cur_speed
);
424 if (ERROR_OK
!= retval
)
428 command_print(CMD_CTX
, "%d kHz", cur_speed
);
430 command_print(CMD_CTX
, "RCLK - adaptive");
435 static const struct command_registration interface_command_handlers
[] = {
437 .name
= "adapter_khz",
438 .handler
= handle_adapter_khz_command
,
440 .help
= "With an argument, change to the specified maximum "
441 "jtag speed. For JTAG, 0 KHz signifies adaptive "
443 "With or without argument, display current setting.",
447 .name
= "adapter_name",
449 .jim_handler
= jim_adapter_name
,
450 .help
= "Returns the name of the currently "
451 "selected adapter (driver)",
454 .name
= "adapter_nsrst_delay",
455 .handler
= handle_adapter_nsrst_delay_command
,
457 .help
= "delay after deasserting SRST in ms",
458 .usage
= "[milliseconds]",
461 .name
= "adapter_nsrst_assert_width",
462 .handler
= handle_adapter_nsrst_assert_width_command
,
464 .help
= "delay after asserting SRST in ms",
465 .usage
= "[milliseconds]",
469 .handler
= handle_interface_command
,
470 .mode
= COMMAND_CONFIG
,
471 .help
= "Select a debug adapter interface (driver)",
472 .usage
= "driver_name",
475 .name
= "interface_transports",
476 .handler
= interface_transport_command
,
477 .mode
= COMMAND_CONFIG
,
478 .help
= "Declare transports the interface supports.",
479 .usage
= "transport ... ",
482 .name
= "interface_list",
483 .handler
= handle_interface_list_command
,
485 .help
= "List all built-in debug adapter interfaces (drivers)",
488 .name
= "reset_config",
489 .handler
= handle_reset_config_command
,
491 .help
= "configure adapter reset behavior",
492 .usage
= "[none|trst_only|srst_only|trst_and_srst] "
493 "[srst_pulls_trst|trst_pulls_srst|combined|separate] "
494 "[srst_gates_jtag|srst_nogate] "
495 "[trst_push_pull|trst_open_drain] "
496 "[srst_push_pull|srst_open_drain]",
498 COMMAND_REGISTRATION_DONE
502 * Register the commands which deal with arbitrary debug adapter drivers.
504 * @todo Remove internal assumptions that all debug adapters use JTAG for
505 * transport. Various types and data structures are not named generically.
507 int interface_register_commands(struct command_context
*ctx
)
509 return register_commands(ctx
, NULL
, interface_command_handlers
);
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)