static int jtag_nsrst_delay = 0; /* default to no nSRST delay */
static int jtag_ntrst_delay = 0; /* default to no nTRST delay */
-/* maximum number of JTAG devices expected in the chain
- */
-#define JTAG_MAX_CHAIN_SIZE 20
-
/* callbacks to inform high-level handlers about JTAG state changes */
jtag_event_callback_t *jtag_event_callbacks;
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
#if BUILD_ECOSBOARD == 1
&zy1000_interface,
#endif
+#if BUILD_MINIDUMMY == 1
+ &minidummy_interface,
+#endif
#if BUILD_PARPORT == 1
&parport_interface,
#endif
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();
alive_sleep(us/1000);
}
+/// maximum number of JTAG devices expected in the chain
+#define JTAG_MAX_CHAIN_SIZE 20
+
#define EXTRACT_MFG(X) (((X) & 0xffe) >> 1)
#define EXTRACT_PART(X) (((X) & 0xffff000) >> 12)
#define EXTRACT_VER(X) (((X) & 0xf0000000) >> 28)
-/* Try to examine chain layout according to IEEE 1149.1 §12
- */
-static int jtag_examine_chain(void)
+static int jtag_examine_chain_execute(u8 *idcode_buffer, unsigned num_idcode)
+{
+ scan_field_t field = {
+ .tap = NULL,
+ .num_bits = num_idcode * 32,
+ .out_value = idcode_buffer,
+ .in_value = idcode_buffer,
+ };
+
+ // initialize to the end of chain ID value
+ 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);
+ return jtag_execute_queue();
+}
+
+static bool jtag_examine_chain_check(u8 *idcodes, unsigned count)
{
- jtag_tap_t *tap;
- scan_field_t field;
- u8 idcode_buffer[JTAG_MAX_CHAIN_SIZE * 4];
- int i;
- int bit_count;
- int device_count = 0;
u8 zero_check = 0x0;
u8 one_check = 0xff;
- field.tap = NULL;
- field.num_bits = sizeof(idcode_buffer) * 8;
- field.out_value = idcode_buffer;
+ for (unsigned i = 0; i < count * 4; i++)
+ {
+ zero_check |= idcodes[i];
+ one_check &= idcodes[i];
+ }
- field.in_value = idcode_buffer;
+ /* if there wasn't a single non-zero bit or if all bits were one,
+ * the scan is not valid */
+ if (zero_check == 0x00 || one_check == 0xff)
+ {
+ LOG_ERROR("JTAG communication failure: check connection, "
+ "JTAG interface, target power etc.");
+ return false;
+ }
+ return true;
+}
+static void jtag_examine_chain_display(enum log_levels level, const char *msg,
+ const char *name, u32 idcode)
+{
+ log_printf_lf(level, __FILE__, __LINE__, __FUNCTION__,
+ "JTAG tap: %s %16.16s: 0x%08x "
+ "(mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x)",
+ name, msg, idcode,
+ 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;
+ }
+}
- for (i = 0; i < JTAG_MAX_CHAIN_SIZE; i++)
+static bool jtag_examine_chain_match_tap(const struct jtag_tap_s *tap)
+{
+ if (0 == tap->expected_ids_cnt)
{
- buf_set_u32(idcode_buffer, i * 32, 32, 0x000000FF);
+ /// @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;
}
- jtag_add_plain_dr_scan(1, &field, TAP_RESET);
- jtag_execute_queue();
+ /* 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;
+ }
- for (i = 0; i < JTAG_MAX_CHAIN_SIZE * 4; i++)
+ /* If none of the expected ids matched, log an error */
+ if (ii != tap->expected_ids_cnt)
{
- zero_check |= idcode_buffer[i];
- one_check &= idcode_buffer[i];
+ 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;
}
- /* if there wasn't a single non-zero bit or if all bits were one, the scan isn't valid */
- if ((zero_check == 0x00) || (one_check == 0xff))
+/* Try to examine chain layout according to IEEE 1149.1 §12
+ */
+static int jtag_examine_chain(void)
{
- LOG_ERROR("JTAG communication failure, check connection, JTAG interface, target power etc.");
+ u8 idcode_buffer[JTAG_MAX_CHAIN_SIZE * 4];
+ unsigned device_count = 0;
+
+ jtag_examine_chain_execute(idcode_buffer, JTAG_MAX_CHAIN_SIZE);
+
+ if (!jtag_examine_chain_check(idcode_buffer, JTAG_MAX_CHAIN_SIZE))
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)
}
else
{
- u32 manufacturer;
- u32 part;
- u32 version;
-
- /* 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;
}
- manufacturer = EXTRACT_MFG(idcode);
- part = EXTRACT_PART(idcode);
- version = EXTRACT_VER(idcode);
-
- LOG_INFO("JTAG tap: %s tap/device found: 0x%8.8x (Manufacturer: 0x%3.3x, Part: 0x%4.4x, Version: 0x%1.1x)",
- ((tap != NULL) ? (tap->dotted_name) : "(not-named)"),
- idcode, manufacturer, part, version);
+ jtag_examine_chain_display(LOG_LVL_INFO, "tap/device found",
+ tap ? tap->dotted_name : "(not-named)",
+ idcode);
bit_count += 32;
}
- if (tap)
- {
- tap->idcode = idcode;
+ device_count++;
+ if (!tap)
+ continue;
- if (tap->expected_ids_cnt > 0) {
- /* 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;
- }
- }
+ tap->idcode = idcode;
- /* If none of the expected ids matched, log an error */
- if (ii == tap->expected_ids_cnt) {
- LOG_ERROR("JTAG tap: %s got: 0x%08x (mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x)",
- tap->dotted_name,
- idcode,
- EXTRACT_MFG( tap->idcode ),
- EXTRACT_PART( tap->idcode ),
- EXTRACT_VER( tap->idcode ) );
- for (ii = 0; ii < tap->expected_ids_cnt; ii++) {
- LOG_ERROR("JTAG tap: %s expected %hhu of %hhu: 0x%08x (mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x)",
- tap->dotted_name,
- ii + 1,
- tap->expected_ids_cnt,
- tap->expected_ids[ii],
- EXTRACT_MFG( tap->expected_ids[ii] ),
- EXTRACT_PART( tap->expected_ids[ii] ),
- EXTRACT_VER( tap->expected_ids[ii] ) );
- }
+ // ensure the TAP ID does matches what was expected
+ if (!jtag_examine_chain_match_tap(tap))
+ return ERROR_JTAG_INIT_FAILED;
- return ERROR_JTAG_INIT_FAILED;
- } else {
- LOG_INFO("JTAG Tap/device matched");
- }
- } else {
-#if 0
- LOG_INFO("JTAG TAP ID: 0x%08x - Unknown - please report (A) chipname and (B) idcode to the openocd project",
- tap->idcode);
-#endif
- }
- tap = jtag_tap_next_enabled(tap);
- }
- device_count++;
+ 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;
}
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 )
{
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;
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));
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);