minidriver build test driver "minidriver"
[openocd.git] / src / jtag / jtag.c
index 8774bbba09f9564dd0dafc8833ab83e26a22bfaa..e5b79cde5b88ad8030a4dcb0ce53cb865960efba 100644 (file)
@@ -99,6 +99,9 @@ static bool hasKHz = false;
        extern jtag_interface_t zy1000_interface;
 #endif
 
+#if BUILD_MINIDUMMY == 1
+       extern jtag_interface_t minidummy_interface;
+#endif
 #if BUILD_PARPORT == 1
        extern jtag_interface_t parport_interface;
 #endif
@@ -159,6 +162,9 @@ jtag_interface_t *jtag_interfaces[] = {
 #if BUILD_ECOSBOARD == 1
        &zy1000_interface,
 #endif
+#if BUILD_MINIDUMMY == 1
+       &minidummy_interface,
+#endif
 #if BUILD_PARPORT == 1
        &parport_interface,
 #endif
@@ -240,12 +246,12 @@ jtag_tap_t *jtag_all_taps(void)
 int jtag_tap_count(void)
 {
        return jtag_num_taps;
-}
+       }
 
-int jtag_tap_count_enabled(void)
+unsigned jtag_tap_count_enabled(void)
 {
        jtag_tap_t *t;
-       int n;
+       unsigned n;
 
        n = 0;
        t = jtag_all_taps();
@@ -995,14 +1001,77 @@ static void jtag_examine_chain_display(enum log_levels level, const char *msg,
                EXTRACT_MFG(idcode), EXTRACT_PART(idcode), EXTRACT_VER(idcode) );
 }
 
+static bool jtag_idcode_is_final(u32 idcode)
+{
+               return idcode == 0x000000FF || idcode == 0xFFFFFFFF;
+}
+
+/**
+ * This helper checks that remaining bits in the examined chain data are
+ * all as expected, but a single JTAG device requires only 64 bits to be
+ * read back correctly.  This can help identify and diagnose problems
+ * with the JTAG chain earlier, gives more helpful/explicit error messages.
+ */
+static void jtag_examine_chain_end(u8 *idcodes, unsigned count, unsigned max)
+{
+       bool triggered = false;
+       for ( ; count < max - 31; count += 32)
+       {
+               u32 idcode = buf_get_u32(idcodes, count, 32);
+               // do not trigger the warning if the data looks good
+               if (!triggered && jtag_idcode_is_final(idcode))
+                       continue;
+               LOG_WARNING("Unexpected idcode after end of chain: %d 0x%08x",
+                               count, idcode);
+               triggered = true;
+       }
+}
+
+static bool jtag_examine_chain_match_tap(const struct jtag_tap_s *tap)
+{
+       if (0 == tap->expected_ids_cnt)
+       {
+               /// @todo Enable LOG_INFO to ask for reports about unknown TAP IDs.
+#if 0
+               LOG_INFO("Uknown JTAG TAP ID: 0x%08x", tap->idcode)
+               LOG_INFO("Please report the chip name and reported ID code to the openocd project");
+#endif
+               return true;
+       }
+
+       /* Loop over the expected identification codes and test for a match */
+       u8 ii;
+       for (ii = 0; ii < tap->expected_ids_cnt; ii++)
+       {
+               if (tap->idcode == tap->expected_ids[ii])
+                       break;
+       }
+
+       /* If none of the expected ids matched, log an error */
+       if (ii != tap->expected_ids_cnt)
+       {
+               LOG_INFO("JTAG Tap/device matched");
+               return true;
+       }
+       jtag_examine_chain_display(LOG_LVL_ERROR, "got",
+                       tap->dotted_name, tap->idcode);
+       for (ii = 0; ii < tap->expected_ids_cnt; ii++)
+       {
+               char msg[32];
+               snprintf(msg, sizeof(msg), "expected %hhu of %hhu",
+                               ii + 1, tap->expected_ids_cnt);
+               jtag_examine_chain_display(LOG_LVL_ERROR, msg,
+                               tap->dotted_name, tap->expected_ids[ii]);
+       }
+       return false;
+       }
+
 /* Try to examine chain layout according to IEEE 1149.1 ยง12
  */
 static int jtag_examine_chain(void)
-{
-       jtag_tap_t *tap;
+       {
        u8 idcode_buffer[JTAG_MAX_CHAIN_SIZE * 4];
-       int bit_count;
-       int device_count = 0;
+       unsigned device_count = 0;
 
        jtag_examine_chain_execute(idcode_buffer, JTAG_MAX_CHAIN_SIZE);
 
@@ -1010,13 +1079,14 @@ static int jtag_examine_chain(void)
                return ERROR_JTAG_INIT_FAILED;
 
        /* point at the 1st tap */
-       tap = jtag_tap_next_enabled(NULL);
-       if( tap == NULL ){
+       jtag_tap_t *tap = jtag_tap_next_enabled(NULL);
+       if (tap == NULL)
+       {
                LOG_ERROR("JTAG: No taps enabled?");
                return ERROR_JTAG_INIT_FAILED;
        }
 
-       for (bit_count = 0; bit_count < (JTAG_MAX_CHAIN_SIZE * 32) - 31;)
+       for (unsigned bit_count = 0; bit_count < (JTAG_MAX_CHAIN_SIZE * 32) - 31;)
        {
                u32 idcode = buf_get_u32(idcode_buffer, bit_count, 32);
                if ((idcode & 1) == 0)
@@ -1029,32 +1099,15 @@ static int jtag_examine_chain(void)
                }
                else
                {
-                       /* some devices, such as AVR will output all 1's instead of TDI
-                       input value at end of chain. */
-                       if ((idcode == 0x000000FF)||(idcode == 0xFFFFFFFF))
-                       {
-                               int unexpected=0;
-                               /* End of chain (invalid manufacturer ID)
-                                *
-                                * The JTAG examine is the very first thing that happens
-                                *
-                                * A single JTAG device requires only 64 bits to be read back correctly.
-                                *
-                                * The code below adds a check that the rest of the data scanned (640 bits)
-                                * are all as expected. This helps diagnose/catch problems with the JTAG chain
-                                *
-                                * earlier and gives more helpful/explicit error messages.
+                       /*
+                        * 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.
                                 */
-                               for (bit_count += 32; bit_count < (JTAG_MAX_CHAIN_SIZE * 32) - 31;bit_count += 32)
+                       if (jtag_idcode_is_final(idcode))
                                {
-                                       idcode = buf_get_u32(idcode_buffer, bit_count, 32);
-                                       if (unexpected||((idcode != 0x000000FF)&&(idcode != 0xFFFFFFFF)))
-                                       {
-                                               LOG_WARNING("Unexpected idcode after end of chain! %d 0x%08x", bit_count, idcode);
-                                               unexpected = 1;
-                                       }
-                               }
-
+                               jtag_examine_chain_end(idcode_buffer,
+                                               bit_count + 32, JTAG_MAX_CHAIN_SIZE * 32);
                                break;
                        }
 
@@ -1068,51 +1121,23 @@ static int jtag_examine_chain(void)
                if (!tap)
                        continue;
 
-               tap->idcode = idcode;
+                       tap->idcode = idcode;
 
-               if (0 == tap->expected_ids_cnt)
-               {
-                       // @todo Enable LOG_INFO to ask for reports about unknown TAP IDs.
-#if 0
-                       LOG_INFO("Uknown JTAG TAP ID: 0x%08x", tap->idcode)
-                       LOG_INFO("Please report the chip name and reported ID code to the openocd project");
-#endif
-                       tap = jtag_tap_next_enabled(tap);
-                       continue;
-               }
-                       /* Loop over the expected identification codes and test for a match */
-               u8 ii;
-               for (ii = 0; ii < tap->expected_ids_cnt; ii++) {
-                       if (tap->idcode == tap->expected_ids[ii]) {
-                               break;
-                       }
-               }
+               // ensure the TAP ID does matches what was expected
+               if (!jtag_examine_chain_match_tap(tap))
+                       return ERROR_JTAG_INIT_FAILED;
 
-               /* If none of the expected ids matched, log an error */
-               if (ii != tap->expected_ids_cnt)
-               {
-                       LOG_INFO("JTAG Tap/device matched");
-                       tap = jtag_tap_next_enabled(tap);
-                       continue;
-               }
-               jtag_examine_chain_display(LOG_LVL_ERROR, "got",
-                               tap->dotted_name, tap->idcode);
-               for (ii = 0; ii < tap->expected_ids_cnt; ii++) {
-                       char msg[20];
-                       snprintf(msg, 20, "expected %hhu of %hhu",
-                                       ii + 1, tap->expected_ids_cnt);
-                       jtag_examine_chain_display(LOG_LVL_ERROR, msg,
-                                       tap->dotted_name, tap->expected_ids[ii]);
-               }
-               return ERROR_JTAG_INIT_FAILED;
+               tap = jtag_tap_next_enabled(tap);
        }
 
        /* see if number of discovered devices matches configuration */
        if (device_count != jtag_tap_count_enabled())
        {
-               LOG_ERROR("number of discovered devices in JTAG chain (%i) doesn't match (enabled) configuration (%i), total taps: %d",
-                                 device_count, jtag_tap_count_enabled(), jtag_tap_count());
-               LOG_ERROR("check the config file and ensure proper JTAG communication (connections, speed, ...)");
+               LOG_ERROR("number of discovered devices in JTAG chain (%i) "
+                               "does not match (enabled) configuration (%i), total taps: %d",
+                               device_count, jtag_tap_count_enabled(), jtag_tap_count());
+               LOG_ERROR("check the config file and ensure proper JTAG communication"
+                               " (connections, speed, ...)");
                return ERROR_JTAG_INIT_FAILED;
        }
 
@@ -1459,12 +1484,12 @@ static int jim_newtap_cmd( Jim_GetOptInfo *goi )
                return ERROR_OK;
        }
 
-       Jim_SetResult_sprintf(goi->interp,
-                       "newtap: %s missing required parameters",
-                       pTap->dotted_name);
+               Jim_SetResult_sprintf( goi->interp,
+                                                          "newtap: %s missing required parameters",
+                                                          pTap->dotted_name);
        jtag_tap_free(pTap);
-       return JIM_ERR;
-}
+               return JIM_ERR;
+       }
 
 static int jim_jtag_command( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
 {
@@ -2114,7 +2139,6 @@ static int handle_jtag_ntrst_delay_command(struct command_context_s *cmd_ctx, ch
        return ERROR_OK;
 }
 
-
 static int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
        int retval=ERROR_OK;
@@ -2199,11 +2223,11 @@ static int handle_endstate_command(struct command_context_s *cmd_ctx, char *cmd,
        tap_state_t state = tap_state_by_name(args[0]);
        if (state < 0)
        {
-               command_print( cmd_ctx, "Invalid state name: %s\n", args[0] );
-               return ERROR_COMMAND_SYNTAX_ERROR;
-       }
-       jtag_set_end_state(state);
-       jtag_execute_queue();
+                       command_print( cmd_ctx, "Invalid state name: %s\n", args[0] );
+                       return ERROR_COMMAND_SYNTAX_ERROR;
+               }
+               jtag_set_end_state(state);
+               jtag_execute_queue();
 
        command_print(cmd_ctx, "current endstate: %s",
                        tap_state_name(cmd_queue_end_state));
@@ -2552,7 +2576,7 @@ static int handle_verify_jtag_command(struct command_context_s *cmd_ctx, char *c
                        jtag_set_verify(false);
                else
                        return ERROR_COMMAND_SYNTAX_ERROR;
-       }
+               }
 
        const char *status = jtag_will_verify() ? "enabled": "disabled";
        command_print(cmd_ctx, "verify jtag capture is %s", status);

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)