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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
29 ***************************************************************************/
36 #include "minidriver.h"
37 #include "interface.h"
38 #include "interfaces.h"
39 #include <transport/transport.h>
47 * Holds support for configuring debug adapters from TCl scripts.
50 extern struct jtag_interface
*jtag_interface
;
51 const char * const jtag_only
[] = { "jtag", NULL
};
53 static int jim_adapter_name(Jim_Interp
*interp
, int argc
, Jim_Obj
* const *argv
)
56 Jim_GetOpt_Setup(&goi
, interp
, argc
-1, argv
+ 1);
58 /* return the name of the interface */
59 /* TCL code might need to know the exact type... */
60 /* FUTURE: we allow this as a means to "set" the interface. */
62 Jim_WrongNumArgs(goi
.interp
, 1, goi
.argv
-1, "(no params)");
65 const char *name
= jtag_interface
? jtag_interface
->name
: NULL
;
66 Jim_SetResultString(goi
.interp
, name
? : "undefined", -1);
70 static int default_khz(int khz
, int *jtag_speed
)
72 LOG_ERROR("Translation from khz to jtag_speed not implemented");
76 static int default_speed_div(int speed
, int *khz
)
78 LOG_ERROR("Translation from jtag_speed to khz not implemented");
82 static int default_power_dropout(int *dropout
)
84 *dropout
= 0; /* by default we can't detect power dropout */
88 static int default_srst_asserted(int *srst_asserted
)
90 *srst_asserted
= 0; /* by default we can't detect srst asserted */
94 COMMAND_HANDLER(interface_transport_command
)
99 retval
= CALL_COMMAND_HANDLER(transport_list_parse
, &transports
);
100 if (retval
!= ERROR_OK
)
103 retval
= allow_transports(CMD_CTX
, (const char **)transports
);
105 if (retval
!= ERROR_OK
) {
106 for (unsigned i
= 0; transports
[i
]; i
++)
113 COMMAND_HANDLER(handle_interface_list_command
)
115 if (strcmp(CMD_NAME
, "interface_list") == 0 && CMD_ARGC
> 0)
116 return ERROR_COMMAND_SYNTAX_ERROR
;
118 command_print(CMD_CTX
, "The following debug interfaces are available:");
119 for (unsigned i
= 0; NULL
!= jtag_interfaces
[i
]; i
++) {
120 const char *name
= jtag_interfaces
[i
]->name
;
121 command_print(CMD_CTX
, "%u: %s", i
+ 1, name
);
127 COMMAND_HANDLER(handle_interface_command
)
131 /* check whether the interface is already configured */
132 if (jtag_interface
) {
133 LOG_WARNING("Interface already configured, ignoring");
137 /* interface name is a mandatory argument */
138 if (CMD_ARGC
!= 1 || CMD_ARGV
[0][0] == '\0')
139 return ERROR_COMMAND_SYNTAX_ERROR
;
141 for (unsigned i
= 0; NULL
!= jtag_interfaces
[i
]; i
++) {
142 if (strcmp(CMD_ARGV
[0], jtag_interfaces
[i
]->name
) != 0)
145 if (NULL
!= jtag_interfaces
[i
]->commands
) {
146 retval
= register_commands(CMD_CTX
, NULL
,
147 jtag_interfaces
[i
]->commands
);
148 if (ERROR_OK
!= retval
)
152 jtag_interface
= jtag_interfaces
[i
];
154 /* LEGACY SUPPORT ... adapter drivers must declare what
155 * transports they allow. Until they all do so, assume
156 * the legacy drivers are JTAG-only
158 if (!jtag_interface
->transports
)
159 LOG_WARNING("Adapter driver '%s' did not declare "
160 "which transports it allows; assuming "
161 "legacy JTAG-only", jtag_interface
->name
);
162 retval
= allow_transports(CMD_CTX
, jtag_interface
->transports
163 ? jtag_interface
->transports
: jtag_only
);
164 if (ERROR_OK
!= retval
)
167 if (jtag_interface
->khz
== NULL
)
168 jtag_interface
->khz
= default_khz
;
169 if (jtag_interface
->speed_div
== NULL
)
170 jtag_interface
->speed_div
= default_speed_div
;
171 if (jtag_interface
->power_dropout
== NULL
)
172 jtag_interface
->power_dropout
= default_power_dropout
;
173 if (jtag_interface
->srst_asserted
== NULL
)
174 jtag_interface
->srst_asserted
= default_srst_asserted
;
179 /* no valid interface was found (i.e. the configuration option,
180 * didn't match one of the compiled-in interfaces
182 LOG_ERROR("The specified debug interface was not found (%s)",
184 CALL_COMMAND_HANDLER(handle_interface_list_command
);
185 return ERROR_JTAG_INVALID_INTERFACE
;
188 COMMAND_HANDLER(handle_reset_config_command
)
193 /* Original versions cared about the order of these tokens:
194 * reset_config signals [combination [trst_type [srst_type]]]
195 * They also clobbered the previous configuration even on error.
197 * Here we don't care about the order, and only change values
198 * which have been explicitly specified.
200 for (; CMD_ARGC
; CMD_ARGC
--, CMD_ARGV
++) {
205 m
= RESET_SRST_NO_GATING
;
206 if (strcmp(*CMD_ARGV
, "srst_gates_jtag") == 0)
207 /* default: don't use JTAG while SRST asserted */;
208 else if (strcmp(*CMD_ARGV
, "srst_nogate") == 0)
209 tmp
= RESET_SRST_NO_GATING
;
213 LOG_ERROR("extra reset_config %s spec (%s)",
214 "gating", *CMD_ARGV
);
215 return ERROR_COMMAND_SYNTAX_ERROR
;
221 m
= RESET_HAS_TRST
| RESET_HAS_SRST
;
222 if (strcmp(*CMD_ARGV
, "none") == 0)
224 else if (strcmp(*CMD_ARGV
, "trst_only") == 0)
225 tmp
= RESET_HAS_TRST
;
226 else if (strcmp(*CMD_ARGV
, "srst_only") == 0)
227 tmp
= RESET_HAS_SRST
;
228 else if (strcmp(*CMD_ARGV
, "trst_and_srst") == 0)
229 tmp
= RESET_HAS_TRST
| RESET_HAS_SRST
;
233 LOG_ERROR("extra reset_config %s spec (%s)",
234 "signal", *CMD_ARGV
);
235 return ERROR_COMMAND_SYNTAX_ERROR
;
240 /* combination (options for broken wiring) */
241 m
= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
242 if (strcmp(*CMD_ARGV
, "separate") == 0)
243 /* separate reset lines - default */;
244 else if (strcmp(*CMD_ARGV
, "srst_pulls_trst") == 0)
245 tmp
|= RESET_SRST_PULLS_TRST
;
246 else if (strcmp(*CMD_ARGV
, "trst_pulls_srst") == 0)
247 tmp
|= RESET_TRST_PULLS_SRST
;
248 else if (strcmp(*CMD_ARGV
, "combined") == 0)
249 tmp
|= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
253 LOG_ERROR("extra reset_config %s spec (%s)",
254 "combination", *CMD_ARGV
);
255 return ERROR_COMMAND_SYNTAX_ERROR
;
260 /* trst_type (NOP without HAS_TRST) */
261 m
= RESET_TRST_OPEN_DRAIN
;
262 if (strcmp(*CMD_ARGV
, "trst_open_drain") == 0)
263 tmp
|= RESET_TRST_OPEN_DRAIN
;
264 else if (strcmp(*CMD_ARGV
, "trst_push_pull") == 0)
265 /* push/pull from adapter - default */;
269 LOG_ERROR("extra reset_config %s spec (%s)",
270 "trst_type", *CMD_ARGV
);
271 return ERROR_COMMAND_SYNTAX_ERROR
;
276 /* srst_type (NOP without HAS_SRST) */
277 m
= RESET_SRST_PUSH_PULL
;
278 if (strcmp(*CMD_ARGV
, "srst_push_pull") == 0)
279 tmp
|= RESET_SRST_PUSH_PULL
;
280 else if (strcmp(*CMD_ARGV
, "srst_open_drain") == 0)
281 /* open drain from adapter - default */;
285 LOG_ERROR("extra reset_config %s spec (%s)",
286 "srst_type", *CMD_ARGV
);
287 return ERROR_COMMAND_SYNTAX_ERROR
;
292 /* connect_type - only valid when srst_nogate */
293 m
= RESET_CNCT_UNDER_SRST
;
294 if (strcmp(*CMD_ARGV
, "connect_assert_srst") == 0)
295 tmp
|= RESET_CNCT_UNDER_SRST
;
296 else if (strcmp(*CMD_ARGV
, "connect_deassert_srst") == 0)
297 /* connect normally - default */;
301 LOG_ERROR("extra reset_config %s spec (%s)",
302 "connect_type", *CMD_ARGV
);
303 return ERROR_COMMAND_SYNTAX_ERROR
;
308 /* caller provided nonsense; fail */
309 LOG_ERROR("unknown reset_config flag (%s)", *CMD_ARGV
);
310 return ERROR_COMMAND_SYNTAX_ERROR
;
313 /* Remember the bits which were specified (mask)
314 * and their new values (new_cfg).
320 /* clear previous values of those bits, save new values */
322 int old_cfg
= jtag_get_reset_config();
326 jtag_set_reset_config(new_cfg
);
328 new_cfg
= jtag_get_reset_config();
331 * Display the (now-)current reset mode
335 /* minimal JTAG has neither SRST nor TRST (so that's the default) */
336 switch (new_cfg
& (RESET_HAS_TRST
| RESET_HAS_SRST
)) {
338 modes
[0] = "srst_only";
341 modes
[0] = "trst_only";
343 case RESET_TRST_AND_SRST
:
344 modes
[0] = "trst_and_srst";
351 /* normally SRST and TRST are decoupled; but bugs happen ... */
352 switch (new_cfg
& (RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
)) {
353 case RESET_SRST_PULLS_TRST
:
354 modes
[1] = "srst_pulls_trst";
356 case RESET_TRST_PULLS_SRST
:
357 modes
[1] = "trst_pulls_srst";
359 case RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
:
360 modes
[1] = "combined";
363 modes
[1] = "separate";
367 /* TRST-less connectors include Altera, Xilinx, and minimal JTAG */
368 if (new_cfg
& RESET_HAS_TRST
) {
369 if (new_cfg
& RESET_TRST_OPEN_DRAIN
)
370 modes
[3] = " trst_open_drain";
372 modes
[3] = " trst_push_pull";
376 /* SRST-less connectors include TI-14, Xilinx, and minimal JTAG */
377 if (new_cfg
& RESET_HAS_SRST
) {
378 if (new_cfg
& RESET_SRST_NO_GATING
)
379 modes
[2] = " srst_nogate";
381 modes
[2] = " srst_gates_jtag";
383 if (new_cfg
& RESET_SRST_PUSH_PULL
)
384 modes
[4] = " srst_push_pull";
386 modes
[4] = " srst_open_drain";
388 if (new_cfg
& RESET_CNCT_UNDER_SRST
)
389 modes
[5] = " connect_assert_srst";
391 modes
[5] = " connect_deassert_srst";
398 command_print(CMD_CTX
, "%s %s%s%s%s%s",
400 modes
[2], modes
[3], modes
[4], modes
[5]);
405 COMMAND_HANDLER(handle_adapter_nsrst_delay_command
)
408 return ERROR_COMMAND_SYNTAX_ERROR
;
411 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], delay
);
413 jtag_set_nsrst_delay(delay
);
415 command_print(CMD_CTX
, "adapter_nsrst_delay: %u", jtag_get_nsrst_delay());
419 COMMAND_HANDLER(handle_adapter_nsrst_assert_width_command
)
422 return ERROR_COMMAND_SYNTAX_ERROR
;
425 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], width
);
427 jtag_set_nsrst_assert_width(width
);
429 command_print(CMD_CTX
, "adapter_nsrst_assert_width: %u", jtag_get_nsrst_assert_width());
433 COMMAND_HANDLER(handle_adapter_khz_command
)
436 return ERROR_COMMAND_SYNTAX_ERROR
;
438 int retval
= ERROR_OK
;
441 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], khz
);
443 retval
= jtag_config_khz(khz
);
444 if (ERROR_OK
!= retval
)
448 int cur_speed
= jtag_get_speed_khz();
449 retval
= jtag_get_speed_readable(&cur_speed
);
450 if (ERROR_OK
!= retval
)
454 command_print(CMD_CTX
, "adapter speed: %d kHz", cur_speed
);
456 command_print(CMD_CTX
, "adapter speed: RCLK - adaptive");
461 static const struct command_registration interface_command_handlers
[] = {
463 .name
= "adapter_khz",
464 .handler
= handle_adapter_khz_command
,
466 .help
= "With an argument, change to the specified maximum "
467 "jtag speed. For JTAG, 0 KHz signifies adaptive "
469 "With or without argument, display current setting.",
473 .name
= "adapter_name",
475 .jim_handler
= jim_adapter_name
,
476 .help
= "Returns the name of the currently "
477 "selected adapter (driver)",
480 .name
= "adapter_nsrst_delay",
481 .handler
= handle_adapter_nsrst_delay_command
,
483 .help
= "delay after deasserting SRST in ms",
484 .usage
= "[milliseconds]",
487 .name
= "adapter_nsrst_assert_width",
488 .handler
= handle_adapter_nsrst_assert_width_command
,
490 .help
= "delay after asserting SRST in ms",
491 .usage
= "[milliseconds]",
495 .handler
= handle_interface_command
,
496 .mode
= COMMAND_CONFIG
,
497 .help
= "Select a debug adapter interface (driver)",
498 .usage
= "driver_name",
501 .name
= "interface_transports",
502 .handler
= interface_transport_command
,
503 .mode
= COMMAND_CONFIG
,
504 .help
= "Declare transports the interface supports.",
505 .usage
= "transport ... ",
508 .name
= "interface_list",
509 .handler
= handle_interface_list_command
,
511 .help
= "List all built-in debug adapter interfaces (drivers)",
514 .name
= "reset_config",
515 .handler
= handle_reset_config_command
,
517 .help
= "configure adapter reset behavior",
518 .usage
= "[none|trst_only|srst_only|trst_and_srst] "
519 "[srst_pulls_trst|trst_pulls_srst|combined|separate] "
520 "[srst_gates_jtag|srst_nogate] "
521 "[trst_push_pull|trst_open_drain] "
522 "[srst_push_pull|srst_open_drain] "
523 "[connect_deassert_srst|connect_assert_srst]",
525 COMMAND_REGISTRATION_DONE
529 * Register the commands which deal with arbitrary debug adapter drivers.
531 * @todo Remove internal assumptions that all debug adapters use JTAG for
532 * transport. Various types and data structures are not named generically.
534 int interface_register_commands(struct command_context
*ctx
)
536 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)