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/transport.h>
46 * Holds support for configuring debug adapters from TCl scripts.
49 extern struct jtag_interface
*jtag_interface
;
50 const char *jtag_only
[] = { "jtag", NULL
};
53 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);
71 static int default_khz(int khz
, int *jtag_speed
)
73 LOG_ERROR("Translation from khz to jtag_speed not implemented");
77 static int default_speed_div(int speed
, int *khz
)
79 LOG_ERROR("Translation from jtag_speed to khz not implemented");
83 static int default_power_dropout(int *dropout
)
85 *dropout
= 0; /* by default we can't detect power dropout */
89 static int default_srst_asserted(int *srst_asserted
)
91 *srst_asserted
= 0; /* by default we can't detect srst asserted */
95 COMMAND_HANDLER(interface_transport_command
)
100 retval
= CALL_COMMAND_HANDLER(transport_list_parse
, &transports
);
101 if (retval
!= ERROR_OK
) {
105 retval
= allow_transports(CMD_CTX
, (const char **)transports
);
107 if (retval
!= ERROR_OK
) {
108 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
)
134 /* check whether the interface is already configured */
137 LOG_WARNING("Interface already configured, ignoring");
141 /* interface name is a mandatory argument */
142 if (CMD_ARGC
!= 1 || CMD_ARGV
[0][0] == '\0')
143 return ERROR_COMMAND_SYNTAX_ERROR
;
145 for (unsigned i
= 0; NULL
!= jtag_interfaces
[i
]; i
++)
147 if (strcmp(CMD_ARGV
[0], jtag_interfaces
[i
]->name
) != 0)
150 if (NULL
!= jtag_interfaces
[i
]->commands
)
152 retval
= register_commands(CMD_CTX
, NULL
,
153 jtag_interfaces
[i
]->commands
);
154 if (ERROR_OK
!= retval
)
158 jtag_interface
= jtag_interfaces
[i
];
160 /* LEGACY SUPPORT ... adapter drivers must declare what
161 * transports they allow. Until they all do so, assume
162 * the legacy drivers are JTAG-only
164 if (!jtag_interface
->transports
)
165 LOG_WARNING("Adapter driver '%s' did not declare "
166 "which transports it allows; assuming "
167 "legacy JTAG-only", jtag_interface
->name
);
168 retval
= allow_transports(CMD_CTX
, jtag_interface
->transports
169 ? jtag_interface
->transports
: jtag_only
);
170 if (ERROR_OK
!= retval
)
173 if (jtag_interface
->khz
== NULL
)
174 jtag_interface
->khz
= default_khz
;
175 if (jtag_interface
->speed_div
== NULL
)
176 jtag_interface
->speed_div
= default_speed_div
;
177 if (jtag_interface
->power_dropout
== NULL
)
178 jtag_interface
->power_dropout
= default_power_dropout
;
179 if (jtag_interface
->srst_asserted
== NULL
)
180 jtag_interface
->srst_asserted
= default_srst_asserted
;
185 /* no valid interface was found (i.e. the configuration option,
186 * didn't match one of the compiled-in interfaces
188 LOG_ERROR("The specified debug interface was not found (%s)",
190 CALL_COMMAND_HANDLER(handle_interface_list_command
);
191 return ERROR_JTAG_INVALID_INTERFACE
;
194 COMMAND_HANDLER(handle_reset_config_command
)
199 /* Original versions cared about the order of these tokens:
200 * reset_config signals [combination [trst_type [srst_type]]]
201 * They also clobbered the previous configuration even on error.
203 * Here we don't care about the order, and only change values
204 * which have been explicitly specified.
206 for (; CMD_ARGC
; CMD_ARGC
--, CMD_ARGV
++) {
211 m
= RESET_SRST_NO_GATING
;
212 if (strcmp(*CMD_ARGV
, "srst_gates_jtag") == 0)
213 /* default: don't use JTAG while SRST asserted */;
214 else if (strcmp(*CMD_ARGV
, "srst_nogate") == 0)
215 tmp
= RESET_SRST_NO_GATING
;
219 LOG_ERROR("extra reset_config %s spec (%s)",
220 "gating", *CMD_ARGV
);
221 return ERROR_INVALID_ARGUMENTS
;
227 m
= RESET_HAS_TRST
| RESET_HAS_SRST
;
228 if (strcmp(*CMD_ARGV
, "none") == 0)
230 else if (strcmp(*CMD_ARGV
, "trst_only") == 0)
231 tmp
= RESET_HAS_TRST
;
232 else if (strcmp(*CMD_ARGV
, "srst_only") == 0)
233 tmp
= RESET_HAS_SRST
;
234 else if (strcmp(*CMD_ARGV
, "trst_and_srst") == 0)
235 tmp
= RESET_HAS_TRST
| RESET_HAS_SRST
;
239 LOG_ERROR("extra reset_config %s spec (%s)",
240 "signal", *CMD_ARGV
);
241 return ERROR_INVALID_ARGUMENTS
;
246 /* combination (options for broken wiring) */
247 m
= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
248 if (strcmp(*CMD_ARGV
, "separate") == 0)
249 /* separate reset lines - default */;
250 else if (strcmp(*CMD_ARGV
, "srst_pulls_trst") == 0)
251 tmp
|= RESET_SRST_PULLS_TRST
;
252 else if (strcmp(*CMD_ARGV
, "trst_pulls_srst") == 0)
253 tmp
|= RESET_TRST_PULLS_SRST
;
254 else if (strcmp(*CMD_ARGV
, "combined") == 0)
255 tmp
|= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
259 LOG_ERROR("extra reset_config %s spec (%s)",
260 "combination", *CMD_ARGV
);
261 return ERROR_INVALID_ARGUMENTS
;
266 /* trst_type (NOP without HAS_TRST) */
267 m
= RESET_TRST_OPEN_DRAIN
;
268 if (strcmp(*CMD_ARGV
, "trst_open_drain") == 0)
269 tmp
|= RESET_TRST_OPEN_DRAIN
;
270 else if (strcmp(*CMD_ARGV
, "trst_push_pull") == 0)
271 /* push/pull from adapter - default */;
275 LOG_ERROR("extra reset_config %s spec (%s)",
276 "trst_type", *CMD_ARGV
);
277 return ERROR_INVALID_ARGUMENTS
;
282 /* srst_type (NOP without HAS_SRST) */
283 m
|= RESET_SRST_PUSH_PULL
;
284 if (strcmp(*CMD_ARGV
, "srst_push_pull") == 0)
285 tmp
|= RESET_SRST_PUSH_PULL
;
286 else if (strcmp(*CMD_ARGV
, "srst_open_drain") == 0)
287 /* open drain from adapter - default */;
291 LOG_ERROR("extra reset_config %s spec (%s)",
292 "srst_type", *CMD_ARGV
);
293 return ERROR_INVALID_ARGUMENTS
;
298 /* caller provided nonsense; fail */
299 LOG_ERROR("unknown reset_config flag (%s)", *CMD_ARGV
);
300 return ERROR_INVALID_ARGUMENTS
;
303 /* Remember the bits which were specified (mask)
304 * and their new values (new_cfg).
310 /* clear previous values of those bits, save new values */
312 int old_cfg
= jtag_get_reset_config();
316 jtag_set_reset_config(new_cfg
);
318 new_cfg
= jtag_get_reset_config();
322 * Display the (now-)current reset mode
326 /* minimal JTAG has neither SRST nor TRST (so that's the default) */
327 switch (new_cfg
& (RESET_HAS_TRST
| RESET_HAS_SRST
)) {
329 modes
[0] = "srst_only";
332 modes
[0] = "trst_only";
334 case RESET_TRST_AND_SRST
:
335 modes
[0] = "trst_and_srst";
342 /* normally SRST and TRST are decoupled; but bugs happen ... */
343 switch (new_cfg
& (RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
)) {
344 case RESET_SRST_PULLS_TRST
:
345 modes
[1] = "srst_pulls_trst";
347 case RESET_TRST_PULLS_SRST
:
348 modes
[1] = "trst_pulls_srst";
350 case RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
:
351 modes
[1] = "combined";
354 modes
[1] = "separate";
358 /* TRST-less connectors include Altera, Xilinx, and minimal JTAG */
359 if (new_cfg
& RESET_HAS_TRST
) {
360 if (new_cfg
& RESET_TRST_OPEN_DRAIN
)
361 modes
[3] = " trst_open_drain";
363 modes
[3] = " trst_push_pull";
367 /* SRST-less connectors include TI-14, Xilinx, and minimal JTAG */
368 if (new_cfg
& RESET_HAS_SRST
) {
369 if (new_cfg
& RESET_SRST_NO_GATING
)
370 modes
[2] = " srst_nogate";
372 modes
[2] = " srst_gates_jtag";
374 if (new_cfg
& RESET_SRST_PUSH_PULL
)
375 modes
[4] = " srst_push_pull";
377 modes
[4] = " srst_open_drain";
383 command_print(CMD_CTX
, "%s %s%s%s%s",
385 modes
[2], modes
[3], modes
[4]);
390 COMMAND_HANDLER(handle_adapter_nsrst_delay_command
)
393 return ERROR_COMMAND_SYNTAX_ERROR
;
397 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], delay
);
399 jtag_set_nsrst_delay(delay
);
401 command_print(CMD_CTX
, "adapter_nsrst_delay: %u", jtag_get_nsrst_delay());
405 COMMAND_HANDLER(handle_adapter_nsrst_assert_width_command
)
408 return ERROR_COMMAND_SYNTAX_ERROR
;
412 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], width
);
414 jtag_set_nsrst_assert_width(width
);
416 command_print(CMD_CTX
, "adapter_nsrst_assert_width: %u", jtag_get_nsrst_assert_width());
422 COMMAND_HANDLER(handle_adapter_khz_command
)
425 return ERROR_COMMAND_SYNTAX_ERROR
;
427 int retval
= ERROR_OK
;
431 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], khz
);
433 retval
= jtag_config_khz(khz
);
434 if (ERROR_OK
!= retval
)
438 int cur_speed
= jtag_get_speed_khz();
439 retval
= jtag_get_speed_readable(&cur_speed
);
440 if (ERROR_OK
!= retval
)
444 command_print(CMD_CTX
, "%d kHz", cur_speed
);
446 command_print(CMD_CTX
, "RCLK - adaptive");
451 static const struct command_registration interface_command_handlers
[] = {
453 .name
= "adapter_khz",
454 .handler
= handle_adapter_khz_command
,
456 .help
= "With an argument, change to the specified maximum "
457 "jtag speed. For JTAG, 0 KHz signifies adaptive "
459 "With or without argument, display current setting.",
463 .name
= "adapter_name",
465 .jim_handler
= jim_adapter_name
,
466 .help
= "Returns the name of the currently "
467 "selected adapter (driver)",
470 .name
= "adapter_nsrst_delay",
471 .handler
= handle_adapter_nsrst_delay_command
,
473 .help
= "delay after deasserting SRST in ms",
474 .usage
= "[milliseconds]",
477 .name
= "adapter_nsrst_assert_width",
478 .handler
= handle_adapter_nsrst_assert_width_command
,
480 .help
= "delay after asserting SRST in ms",
481 .usage
= "[milliseconds]",
485 .handler
= handle_interface_command
,
486 .mode
= COMMAND_CONFIG
,
487 .help
= "Select a debug adapter interface (driver)",
488 .usage
= "driver_name",
491 .name
= "interface_transports",
492 .handler
= interface_transport_command
,
493 .mode
= COMMAND_CONFIG
,
494 .help
= "Declare transports the interface supports.",
495 .usage
= "transport ... ",
498 .name
= "interface_list",
499 .handler
= handle_interface_list_command
,
501 .help
= "List all built-in debug adapter interfaces (drivers)",
504 .name
= "reset_config",
505 .handler
= handle_reset_config_command
,
507 .help
= "configure adapter reset behavior",
508 .usage
= "[none|trst_only|srst_only|trst_and_srst] "
509 "[srst_pulls_trst|trst_pulls_srst|combined|separate] "
510 "[srst_gates_jtag|srst_nogate] "
511 "[trst_push_pull|trst_open_drain] "
512 "[srst_push_pull|srst_open_drain]",
514 COMMAND_REGISTRATION_DONE
518 * Register the commands which deal with arbitrary debug adapter drivers.
520 * @todo Remove internal assumptions that all debug adapters use JTAG for
521 * transport. Various types and data structures are not named generically.
523 int interface_register_commands(struct command_context
*ctx
)
525 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)