adapter: add command "adapter [de]assert srst|trst [[de]assert srst|trst]"
[openocd.git] / src / jtag / core.c
index 84e93967753bd5f94194f7b4fbb0521aff64bb02..871b4d2bd07b83fe6010c3d63d5a787747ee945c 100644 (file)
@@ -35,6 +35,8 @@
 #include "interface.h"
 #include <transport/transport.h>
 #include <helper/jep106.h>
+#include <jtag/hla/hla_transport.h>
+#include <jtag/hla/hla_interface.h>
 
 #ifdef HAVE_STRINGS_H
 #include <strings.h>
@@ -836,7 +838,75 @@ int default_interface_jtag_execute_queue(void)
                return ERROR_FAIL;
        }
 
-       return jtag->execute_queue();
+       int result = jtag->execute_queue();
+
+#if !BUILD_ZY1000
+       /* Only build this if we use a regular driver with a command queue.
+        * Otherwise jtag_command_queue won't be found at compile/link time. Its
+        * definition is in jtag/commands.c, which is only built/linked by
+        * jtag/Makefile.am if MINIDRIVER_DUMMY || !MINIDRIVER, but those variables
+        * aren't accessible here. */
+       struct jtag_command *cmd = jtag_command_queue;
+       while (debug_level >= LOG_LVL_DEBUG && cmd) {
+               switch (cmd->type) {
+                       case JTAG_SCAN:
+                               LOG_DEBUG_IO("JTAG %s SCAN to %s",
+                                               cmd->cmd.scan->ir_scan ? "IR" : "DR",
+                                               tap_state_name(cmd->cmd.scan->end_state));
+                               for (int i = 0; i < cmd->cmd.scan->num_fields; i++) {
+                                       struct scan_field *field = cmd->cmd.scan->fields + i;
+                                       if (field->out_value) {
+                                               char *str = buf_to_str(field->out_value, field->num_bits, 16);
+                                               LOG_DEBUG_IO("  %db out: %s", field->num_bits, str);
+                                               free(str);
+                                       }
+                                       if (field->in_value) {
+                                               char *str = buf_to_str(field->in_value, field->num_bits, 16);
+                                               LOG_DEBUG_IO("  %db  in: %s", field->num_bits, str);
+                                               free(str);
+                                       }
+                               }
+                               break;
+                       case JTAG_TLR_RESET:
+                               LOG_DEBUG_IO("JTAG TLR RESET to %s",
+                                               tap_state_name(cmd->cmd.statemove->end_state));
+                               break;
+                       case JTAG_RUNTEST:
+                               LOG_DEBUG_IO("JTAG RUNTEST %d cycles to %s",
+                                               cmd->cmd.runtest->num_cycles,
+                                               tap_state_name(cmd->cmd.runtest->end_state));
+                               break;
+                       case JTAG_RESET:
+                               {
+                                       const char *reset_str[3] = {
+                                               "leave", "deassert", "assert"
+                                       };
+                                       LOG_DEBUG_IO("JTAG RESET %s TRST, %s SRST",
+                                                       reset_str[cmd->cmd.reset->trst + 1],
+                                                       reset_str[cmd->cmd.reset->srst + 1]);
+                               }
+                               break;
+                       case JTAG_PATHMOVE:
+                               LOG_DEBUG_IO("JTAG PATHMOVE (TODO)");
+                               break;
+                       case JTAG_SLEEP:
+                               LOG_DEBUG_IO("JTAG SLEEP (TODO)");
+                               break;
+                       case JTAG_STABLECLOCKS:
+                               LOG_DEBUG_IO("JTAG STABLECLOCKS (TODO)");
+                               break;
+                       case JTAG_TMS:
+                               LOG_DEBUG_IO("JTAG TMS (TODO)");
+                               break;
+                       default:
+                               LOG_ERROR("Unknown JTAG command: %d", cmd->type);
+                               break;
+               }
+               cmd = cmd->next;
+       }
+#endif
+
+       return result;
 }
 
 void jtag_execute_queue_noclear(void)
@@ -1107,7 +1177,8 @@ static int jtag_examine_chain(void)
 
                if ((idcode & 1) == 0) {
                        /* Zero for LSB indicates a device in bypass */
-                       LOG_INFO("TAP %s does not have IDCODE", tap->dotted_name);
+                       LOG_INFO("TAP %s does not have valid IDCODE (idcode=0x%x)",
+                                       tap->dotted_name, idcode);
                        tap->hasidcode = false;
                        tap->idcode = 0;
 
@@ -1348,19 +1419,6 @@ int adapter_init(struct command_context *cmd_ctx)
                return retval;
        jtag = jtag_interface;
 
-       /* LEGACY SUPPORT ... adapter drivers  must declare what
-        * transports they allow.  Until they all do so, assume
-        * the legacy drivers are JTAG-only
-        */
-       if (!transports_are_declared()) {
-               LOG_ERROR("Adapter driver '%s' did not declare "
-                       "which transports it allows; assuming "
-                       "JTAG-only", jtag->name);
-               retval = allow_transports(cmd_ctx, jtag_only);
-               if (retval != ERROR_OK)
-                       return retval;
-       }
-
        if (jtag->speed == NULL) {
                LOG_INFO("This adapter doesn't support configurable speed");
                return ERROR_OK;
@@ -1832,6 +1890,57 @@ bool transport_is_jtag(void)
        return get_current_transport() == &jtag_transport;
 }
 
+int adapter_resets(int trst, int srst)
+{
+       if (get_current_transport() == NULL) {
+               LOG_ERROR("transport is not selected");
+               return ERROR_FAIL;
+       }
+
+       if (transport_is_jtag()) {
+               if (srst == SRST_ASSERT && !(jtag_reset_config & RESET_HAS_SRST)) {
+                       LOG_ERROR("adapter has no srst signal");
+                       return ERROR_FAIL;
+               }
+
+               /* adapters without trst signal will eventually use tlr sequence */
+               jtag_add_reset(trst, srst);
+               return ERROR_OK;
+       } else if (transport_is_swd()) {
+               if (trst == TRST_ASSERT) {
+                       LOG_ERROR("transport swd has no trst signal");
+                       return ERROR_FAIL;
+               }
+
+               if (srst == SRST_ASSERT && !(jtag_reset_config & RESET_HAS_SRST)) {
+                       LOG_ERROR("adapter has no srst signal");
+                       return ERROR_FAIL;
+               }
+               swd_add_reset(srst);
+               return ERROR_OK;
+       } else if (transport_is_hla()) {
+               if (trst == TRST_ASSERT) {
+                       LOG_ERROR("transport %s has no trst signal",
+                               get_current_transport()->name);
+                       return ERROR_FAIL;
+               }
+
+               if (srst == SRST_ASSERT && !(jtag_reset_config & RESET_HAS_SRST)) {
+                       LOG_ERROR("adapter has no srst signal");
+                       return ERROR_FAIL;
+               }
+               return hl_interface_reset(srst);
+       }
+
+       if (trst == TRST_DEASSERT && srst == SRST_DEASSERT)
+               return ERROR_OK;
+
+       LOG_ERROR("reset is not supported on transport %s",
+               get_current_transport()->name);
+
+       return ERROR_FAIL;
+}
+
 void adapter_assert_reset(void)
 {
        if (transport_is_jtag()) {
@@ -1862,12 +1971,13 @@ void adapter_deassert_reset(void)
 }
 
 int adapter_config_trace(bool enabled, enum tpiu_pin_protocol pin_protocol,
-                        uint32_t port_size, unsigned int *trace_freq)
+               uint32_t port_size, unsigned int *trace_freq,
+               unsigned int traceclkin_freq, uint16_t *prescaler)
 {
-       if (jtag->config_trace)
-               return jtag->config_trace(enabled, pin_protocol, port_size,
-                                         trace_freq);
-       else if (enabled) {
+       if (jtag->config_trace) {
+               return jtag->config_trace(enabled, pin_protocol, port_size, trace_freq,
+                       traceclkin_freq, prescaler);
+       else if (enabled) {
                LOG_ERROR("The selected interface does not support tracing");
                return ERROR_FAIL;
        }

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)