tap post reset event added. Allows omap3530 to send 100 runtest idle tickle's after...
[openocd.git] / src / jtag / core.c
index 06e015c4aa03bdea3f412aa6ecdd3e3b35108494..acd84e9a8e7c644826a72eb8fedb423979f291d3 100644 (file)
@@ -62,6 +62,7 @@ static const char *jtag_event_strings[] =
 {
        [JTAG_TRST_ASSERTED] = "JTAG controller reset (TLR or TRST)",
        [JTAG_TAP_EVENT_ENABLE] = "TAP enabled",
+       [JTAG_TAP_EVENT_POST_RESET] = "post reset",
        [JTAG_TAP_EVENT_DISABLE] = "TAP disabled",
 };
 
@@ -339,6 +340,8 @@ void jtag_add_ir_scan_noverify(int in_count, const scan_field_t *in_fields,
 
 void jtag_add_ir_scan(int in_num_fields, scan_field_t *in_fields, tap_state_t state)
 {
+       assert(state != TAP_RESET);
+
        if (jtag_verify && jtag_verify_capture_ir)
        {
                /* 8 x 32 bit id's is enough for all invocations */
@@ -361,6 +364,8 @@ void jtag_add_ir_scan(int in_num_fields, scan_field_t *in_fields, tap_state_t st
 void jtag_add_plain_ir_scan(int in_num_fields, const scan_field_t *in_fields,
                tap_state_t state)
 {
+       assert(state != TAP_RESET);
+
        jtag_prelude(state);
 
        int retval = interface_jtag_add_plain_ir_scan(
@@ -439,6 +444,8 @@ void jtag_add_dr_scan_check(int in_num_fields, scan_field_t *in_fields, tap_stat
 void jtag_add_dr_scan(int in_num_fields, const scan_field_t *in_fields,
                tap_state_t state)
 {
+       assert(state != TAP_RESET);
+       
        jtag_prelude(state);
 
        int retval;
@@ -449,6 +456,8 @@ void jtag_add_dr_scan(int in_num_fields, const scan_field_t *in_fields,
 void jtag_add_plain_dr_scan(int in_num_fields, const scan_field_t *in_fields,
                tap_state_t state)
 {
+       assert(state != TAP_RESET);
+       
        jtag_prelude(state);
 
        int retval;
@@ -460,6 +469,8 @@ void jtag_add_dr_out(jtag_tap_t* tap,
                int num_fields, const int* num_bits, const uint32_t* value,
                tap_state_t end_state)
 {
+       assert(end_state != TAP_RESET);
+       
        assert(end_state != TAP_INVALID);
 
        cmd_queue_cur_state = end_state;
@@ -473,6 +484,9 @@ void jtag_add_tlr(void)
 {
        jtag_prelude(TAP_RESET);
        jtag_set_error(interface_jtag_add_tlr());
+
+       jtag_notify_reset();
+
        jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
 }
 
@@ -585,61 +599,48 @@ void jtag_add_clocks(int num_cycles)
 void jtag_add_reset(int req_tlr_or_trst, int req_srst)
 {
        int trst_with_tlr = 0;
-       int new_srst;
+       int new_srst = 0;
        int new_trst = 0;
 
-       /* FIX!!! there are *many* different cases here. A better
-        * approach is needed for legal combinations of transitions...
+       /* Without SRST, we must use target-specific JTAG operations
+        * on each target; callers should not be requesting SRST when
+        * that signal doesn't exist.
+        *
+        * RESET_SRST_PULLS_TRST is a board or chip level quirk, which
+        * can kick in even if the JTAG adapter can't drive TRST.
         */
-       if ((jtag_reset_config & RESET_HAS_SRST)&&
-                       (jtag_reset_config & RESET_HAS_TRST)&&
-                       ((jtag_reset_config & RESET_SRST_PULLS_TRST) == 0))
-       {
-               if (((req_tlr_or_trst&&!jtag_trst)||
-                               (!req_tlr_or_trst && jtag_trst))&&
-                               ((req_srst&&!jtag_srst)||
-                                               (!req_srst && jtag_srst)))
-               {
-                       /* FIX!!! srst_pulls_trst allows 1,1 => 0,0 transition.... */
-                       //LOG_ERROR("BUG: transition of req_tlr_or_trst and req_srst in the same jtag_add_reset() call is undefined");
+       if (req_srst) {
+               if (!(jtag_reset_config & RESET_HAS_SRST)) {
+                       LOG_ERROR("BUG: can't assert SRST");
+                       jtag_set_error(ERROR_FAIL);
+                       return;
                }
+               if ((jtag_reset_config & RESET_SRST_PULLS_TRST) != 0
+                               && !req_tlr_or_trst) {
+                       LOG_ERROR("BUG: can't assert only SRST");
+                       jtag_set_error(ERROR_FAIL);
+                       return;
+               }
+               new_srst = 1;
        }
 
-       /* Make sure that jtag_reset_config allows the requested reset */
-       /* if SRST pulls TRST, we can't fulfill srst == 1 with trst == 0 */
-       if (((jtag_reset_config & RESET_SRST_PULLS_TRST) && (req_srst == 1)) && (!req_tlr_or_trst))
-       {
-               LOG_ERROR("BUG: requested reset would assert trst");
-               jtag_set_error(ERROR_FAIL);
-               return;
-       }
-
-       /* if TRST pulls SRST, we reset with TAP T-L-R */
-       if (((jtag_reset_config & RESET_TRST_PULLS_SRST) && (req_tlr_or_trst)) && (req_srst == 0))
-       {
-               trst_with_tlr = 1;
-       }
-
-       if (req_srst && !(jtag_reset_config & RESET_HAS_SRST))
-       {
-               LOG_ERROR("BUG: requested SRST assertion, but the current configuration doesn't support this");
-               jtag_set_error(ERROR_FAIL);
-               return;
-       }
-
-       if (req_tlr_or_trst)
-       {
-               if (!trst_with_tlr && (jtag_reset_config & RESET_HAS_TRST))
-               {
-                       new_trst = 1;
-               } else
-               {
+       /* JTAG reset (entry to TAP_RESET state) can always be achieved
+        * using TCK and TMS; that may go through a TAP_{IR,DR}UPDATE
+        * state first.  TRST accelerates it, and bypasses those states.
+        *
+        * RESET_TRST_PULLS_SRST is a board or chip level quirk, which
+        * can kick in even if the JTAG adapter can't drive SRST.
+        */
+       if (req_tlr_or_trst) {
+               if (!(jtag_reset_config & RESET_HAS_TRST))
                        trst_with_tlr = 1;
-               }
+               else if ((jtag_reset_config & RESET_TRST_PULLS_SRST) != 0
+                               && !req_srst)
+                       trst_with_tlr = 1;
+               else
+                       new_trst = 1;
        }
 
-       new_srst = req_srst;
-
        /* Maybe change TRST and/or SRST signal state */
        if (jtag_srst != new_srst || jtag_trst != new_trst) {
                int retval;
@@ -696,6 +697,8 @@ void jtag_add_reset(int req_tlr_or_trst, int req_srst)
                        LOG_DEBUG("TRST line released");
                        if (jtag_ntrst_delay)
                                jtag_add_sleep(jtag_ntrst_delay * 1000);
+
+                       jtag_notify_reset();
                }
        }
 }
@@ -831,6 +834,7 @@ static int jtag_reset_callback(enum jtag_event event, void *priv)
        {
                tap->enabled = !tap->disabled_after_reset;
 
+               /* current instruction is either BYPASS or IDCODE */
                buf_set_ones(tap->cur_instr, tap->ir_length);
                tap->bypass = 1;
        }
@@ -863,7 +867,8 @@ static int jtag_examine_chain_execute(uint8_t *idcode_buffer, unsigned num_idcod
        for (unsigned i = 0; i < JTAG_MAX_CHAIN_SIZE; i++)
                buf_set_u32(idcode_buffer, i * 32, 32, 0x000000FF);
 
-       jtag_add_plain_dr_scan(1, &field, TAP_RESET);
+       jtag_add_plain_dr_scan(1, &field, TAP_DRPAUSE);
+       jtag_add_tlr();
        return jtag_execute_queue();
 }
 
@@ -951,7 +956,7 @@ static bool jtag_examine_chain_match_tap(const struct jtag_tap_s *tap)
        /* If none of the expected ids matched, log an error */
        if (ii != tap->expected_ids_cnt)
        {
-               LOG_INFO("JTAG Tap/device matched");
+               LOG_DEBUG("JTAG Tap/device matched");
                return true;
        }
        jtag_examine_chain_display(LOG_LVL_ERROR, "got",
@@ -987,20 +992,26 @@ int jtag_examine_chain(void)
                return ERROR_JTAG_INIT_FAILED;
        }
 
-       for (unsigned bit_count = 0; bit_count < (JTAG_MAX_CHAIN_SIZE * 32) - 31;)
+       for (unsigned bit_count = 0;
+                       tap && bit_count < (JTAG_MAX_CHAIN_SIZE * 32) - 31;
+                       tap = jtag_tap_next_enabled(tap))
        {
                uint32_t idcode = buf_get_u32(idcode_buffer, bit_count, 32);
+
                if ((idcode & 1) == 0)
                {
                        /* LSB must not be 0, this indicates a device in bypass */
                        LOG_WARNING("Tap/Device does not have IDCODE");
                        idcode = 0;
+                       tap->hasidcode = false;
 
                        bit_count += 1;
                }
                else
                {
-                       /*
+                       tap->hasidcode = true;
+
+                       /*
                         * End of chain (invalid manufacturer ID) some devices, such
                         * as AVR will output all 1's instead of TDI input value at
                         * end of chain.
@@ -1025,10 +1036,8 @@ int jtag_examine_chain(void)
                tap->idcode = idcode;
 
                // ensure the TAP ID does matches what was expected
-               if (!jtag_examine_chain_match_tap(tap))
+               if (!jtag_examine_chain_match_tap(tap))
                        return ERROR_JTAG_INIT_FAILED;
-
-               tap = jtag_tap_next_enabled(tap);
        }
 
        /* see if number of discovered devices matches configuration */
@@ -1073,8 +1082,13 @@ int jtag_validate_chain(void)
        field.in_value = ir_test;
 
 
-       jtag_add_plain_ir_scan(1, &field, TAP_RESET);
-       jtag_execute_queue();
+       jtag_add_plain_ir_scan(1, &field, TAP_IRPAUSE);
+       jtag_add_tlr();
+
+       int retval;
+       retval = jtag_execute_queue();
+       if (retval != ERROR_OK)
+               return retval;
 
        tap = NULL;
        chain_pos = 0;
@@ -1086,7 +1100,8 @@ int jtag_validate_chain(void)
                }
 
                val = buf_get_u32(ir_test, chain_pos, 2);
-               if (val != 0x1)
+               /* Only fail this check if we have IDCODE for this device */
+               if ((val != 0x1)&&(tap->hasidcode))
                {
                        char *cbuf = buf_to_str(ir_test, total_ir_length, 16);
                        LOG_ERROR("Could not validate JTAG scan chain, IR mismatch, scan returned 0x%s. tap=%s pos=%d expected 0x1 got %0x", cbuf, jtag_tap_name(tap), chain_pos, val);

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)