jtag: retire tap field
[openocd.git] / src / jtag / core.c
index 77cf48ac284abd4802a988acabf8ea8af28843b9..2e09cb6d58bcb5e026af80cc2a50f2ef539fad25 100644 (file)
@@ -42,7 +42,7 @@
 /// The number of JTAG queue flushes (for profiling and debugging purposes).
 static int jtag_flush_queue_count;
 
-static void jtag_add_scan_check(void (*jtag_add_scan)(int in_num_fields, const struct scan_field *in_fields, tap_state_t state),
+static void jtag_add_scan_check(struct jtag_tap *active, void (*jtag_add_scan)(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, tap_state_t state),
                int in_num_fields, struct scan_field *in_fields, tap_state_t state);
 
 /**
@@ -352,17 +352,17 @@ void jtag_alloc_in_value32(struct scan_field *field)
        interface_jtag_alloc_in_value32(field);
 }
 
-void jtag_add_ir_scan_noverify(int in_count, const struct scan_field *in_fields,
+void jtag_add_ir_scan_noverify(struct jtag_tap *active, int in_count, const struct scan_field *in_fields,
                tap_state_t state)
 {
        jtag_prelude(state);
 
-       int retval = interface_jtag_add_ir_scan(in_count, in_fields, state);
+       int retval = interface_jtag_add_ir_scan(active, in_count, in_fields, state);
        jtag_set_error(retval);
 }
 
 
-void jtag_add_ir_scan(int in_num_fields, struct scan_field *in_fields, tap_state_t state)
+void jtag_add_ir_scan(struct jtag_tap *active, int in_num_fields, struct scan_field *in_fields, tap_state_t state)
 {
        assert(state != TAP_RESET);
 
@@ -375,13 +375,13 @@ void jtag_add_ir_scan(int in_num_fields, struct scan_field *in_fields, tap_state
                        /* if we are to run a verification of the ir scan, we need to get the input back.
                         * We may have to allocate space if the caller didn't ask for the input back.
                         */
-                       in_fields[j].check_value = in_fields[j].tap->expected;
-                       in_fields[j].check_mask = in_fields[j].tap->expected_mask;
+                       in_fields[j].check_value = active->expected;
+                       in_fields[j].check_mask = active->expected_mask;
                }
-               jtag_add_scan_check(jtag_add_ir_scan_noverify, in_num_fields, in_fields, state);
+               jtag_add_scan_check(active, jtag_add_ir_scan_noverify, in_num_fields, in_fields, state);
        } else
        {
-               jtag_add_ir_scan_noverify(in_num_fields, in_fields, state);
+               jtag_add_ir_scan_noverify(active, in_num_fields, in_fields, state);
        }
 }
 
@@ -405,7 +405,7 @@ static int jtag_check_value_mask_callback(jtag_callback_data_t data0, jtag_callb
        return jtag_check_value_inner((uint8_t *)data0, (uint8_t *)data1, (uint8_t *)data2, (int)data3);
 }
 
-static void jtag_add_scan_check(void (*jtag_add_scan)(int in_num_fields, const struct scan_field *in_fields, tap_state_t state),
+static void jtag_add_scan_check(struct jtag_tap *active, void (*jtag_add_scan)(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, tap_state_t state),
                int in_num_fields, struct scan_field *in_fields, tap_state_t state)
 {
        for (int i = 0; i < in_num_fields; i++)
@@ -419,7 +419,7 @@ static void jtag_add_scan_check(void (*jtag_add_scan)(int in_num_fields, const s
                field->modified = 1;
        }
 
-       jtag_add_scan(in_num_fields, in_fields, state);
+       jtag_add_scan(active, in_num_fields, in_fields, state);
 
        for (int i = 0; i < in_num_fields; i++)
        {
@@ -442,19 +442,19 @@ static void jtag_add_scan_check(void (*jtag_add_scan)(int in_num_fields, const s
        }
 }
 
-void jtag_add_dr_scan_check(int in_num_fields, struct scan_field *in_fields, tap_state_t state)
+void jtag_add_dr_scan_check(struct jtag_tap *active, int in_num_fields, struct scan_field *in_fields, tap_state_t state)
 {
        if (jtag_verify)
        {
-               jtag_add_scan_check(jtag_add_dr_scan, in_num_fields, in_fields, state);
+               jtag_add_scan_check(active, jtag_add_dr_scan, in_num_fields, in_fields, state);
        } else
        {
-               jtag_add_dr_scan(in_num_fields, in_fields, state);
+               jtag_add_dr_scan(active, in_num_fields, in_fields, state);
        }
 }
 
 
-void jtag_add_dr_scan(int in_num_fields, const struct scan_field *in_fields,
+void jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields,
                tap_state_t state)
 {
        assert(state != TAP_RESET);
@@ -462,7 +462,7 @@ void jtag_add_dr_scan(int in_num_fields, const struct scan_field *in_fields,
        jtag_prelude(state);
 
        int retval;
-       retval = interface_jtag_add_dr_scan(in_num_fields, in_fields, state);
+       retval = interface_jtag_add_dr_scan(active, in_num_fields, in_fields, state);
        jtag_set_error(retval);
 }
 
@@ -488,6 +488,35 @@ void jtag_add_tlr(void)
        jtag_notify_event(JTAG_TRST_ASSERTED);
 }
 
+/**
+ * If supported by the underlying adapter, this clocks a raw bit sequence
+ * onto TMS for switching betwen JTAG and SWD modes.
+ *
+ * DO NOT use this to bypass the integrity checks and logging provided
+ * by the jtag_add_pathmove() and jtag_add_statemove() calls.
+ *
+ * @param nbits How many bits to clock out.
+ * @param seq The bit sequence.  The LSB is bit 0 of seq[0].
+ * @param state The JTAG tap state to record on completion.  Use
+ *     TAP_INVALID to represent being in in SWD mode.
+ *
+ * @todo Update naming conventions to stop assuming everything is JTAG.
+ */
+int jtag_add_tms_seq(unsigned nbits, const uint8_t *seq, enum tap_state state)
+{
+       int retval;
+
+       if (!(jtag->supported & DEBUG_CAP_TMS_SEQ))
+               return ERROR_JTAG_NOT_IMPLEMENTED;
+
+       jtag_checks();
+       cmd_queue_cur_state = state;
+
+       retval = interface_add_tms_seq(nbits, seq, state);
+       jtag_set_error(retval);
+       return retval;
+}
+
 void jtag_add_pathmove(int num_states, const tap_state_t *path)
 {
        tap_state_t cur_state = cmd_queue_cur_state;
@@ -530,10 +559,12 @@ int jtag_add_statemove(tap_state_t goal_state)
 {
        tap_state_t cur_state = cmd_queue_cur_state;
 
-       LOG_DEBUG("cur_state=%s goal_state=%s",
-               tap_state_name(cur_state),
-               tap_state_name(goal_state));
-
+       if (goal_state != cur_state)
+       {
+               LOG_DEBUG("cur_state=%s goal_state=%s",
+                       tap_state_name(cur_state),
+                       tap_state_name(goal_state));
+       }
 
        /* If goal is RESET, be paranoid and force that that transition
         * (e.g. five TCK cycles, TMS high).  Else trust "cur_state".
@@ -863,7 +894,6 @@ void jtag_sleep(uint32_t us)
 static int jtag_examine_chain_execute(uint8_t *idcode_buffer, unsigned num_idcode)
 {
        struct scan_field field = {
-                       .tap = NULL,
                        .num_bits = num_idcode * 32,
                        .out_value = idcode_buffer,
                        .in_value = idcode_buffer,
@@ -958,16 +988,25 @@ static bool jtag_examine_chain_end(uint8_t *idcodes, unsigned count, unsigned ma
 
 static bool jtag_examine_chain_match_tap(const struct jtag_tap *tap)
 {
+       uint32_t idcode = tap->idcode;
+
        /* ignore expected BYPASS codes; warn otherwise */
-       if (0 == tap->expected_ids_cnt && !tap->idcode)
+       if (0 == tap->expected_ids_cnt && !idcode)
                return true;
 
+       /* optionally ignore the JTAG version field */
+       uint32_t mask = tap->ignore_version ? ~(0xff << 24) : ~0;
+
+       idcode &= mask;
+
        /* Loop over the expected identification codes and test for a match */
        unsigned ii, limit = tap->expected_ids_cnt;
 
        for (ii = 0; ii < limit; ii++)
        {
-               if (tap->idcode == tap->expected_ids[ii])
+               uint32_t expected = tap->expected_ids[ii] & mask;
+
+               if (idcode == expected)
                        return true;
 
                /* treat "-expected-id 0" as a "don't-warn" wildcard */
@@ -1161,7 +1200,6 @@ static int jtag_validate_ircapture(void)
        /* after this scan, all TAPs will capture BYPASS instructions */
        buf_set_ones(ir_test, total_ir_length);
 
-       field.tap = NULL;
        field.num_bits = total_ir_length;
        field.out_value = ir_test;
        field.in_value = ir_test;
@@ -1612,6 +1650,13 @@ bool jtag_will_verify_capture_ir()
 
 int jtag_power_dropout(int *dropout)
 {
+       if (jtag == NULL)
+       {
+               /* TODO: as the jtag interface is not valid all
+                * we can do at the moment is exit OpenOCD */
+               LOG_ERROR("No Valid JTAG Interface Configured.");
+               exit(-1);
+       }
        return jtag->power_dropout(dropout);
 }
 

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)