int jtag_nsrst_delay = 0; /* default to no nSRST delay */
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 at91rm9200_interface;
#endif
+#if BUILD_GW16012 == 1
+ extern jtag_interface_t gw16012_interface;
+#endif
+
jtag_interface_t *jtag_interfaces[] = {
#if BUILD_PARPORT == 1
&parport_interface,
#endif
#if BUILD_AT91RM9200 == 1
&at91rm9200_interface,
+#endif
+#if BUILD_GW16012 == 1
+ &gw16012_interface,
#endif
NULL,
};
/* if a device is listed, the BYPASS register must not be selected */
if (jtag_get_device(i)->bypass)
{
- ERROR("BUG: scan data for a device in BYPASS");
- exit(-1);
+ WARNING("scan data for a device in BYPASS");
}
}
}
*last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
last_comand_pointer = &((*last_cmd)->next);
(*last_cmd)->next = NULL;
- (*last_cmd)->type = JTAG_RUNTEST;
+ (*last_cmd)->type = JTAG_PATHMOVE;
(*last_cmd)->cmd.pathmove = cmd_queue_alloc(sizeof(pathmove_command_t));
(*last_cmd)->cmd.pathmove->num_states = num_states;
if (cmd->fields[i].out_value)
{
#ifdef _DEBUG_JTAG_IO_
- char* char_buf = buf_to_str(cmd->fields[i].out_value, cmd->fields[i].num_bits, 16);
+ char* char_buf = buf_to_str(cmd->fields[i].out_value, (cmd->fields[i].num_bits > 64) ? 64 : cmd->fields[i].num_bits, 16);
#endif
buf_set_buf(cmd->fields[i].out_value, 0, *buffer, bit_count, cmd->fields[i].num_bits);
#ifdef _DEBUG_JTAG_IO_
#ifdef _DEBUG_JTAG_IO_
char *char_buf;
- char_buf = buf_to_str(captured, num_bits, 16);
+ char_buf = buf_to_str(captured, (num_bits > 64) ? 64 : num_bits, 16);
DEBUG("fields[%i].in_value: 0x%s", i, char_buf);
free(char_buf);
#endif
if ((cmd->fields[i].in_check_mask && buf_cmp_mask(captured, cmd->fields[i].in_check_value, cmd->fields[i].in_check_mask, num_bits))
|| (!cmd->fields[i].in_check_mask && buf_cmp(captured, cmd->fields[i].in_check_mask, num_bits)))
{
- char *captured_char = buf_to_str(captured, num_bits, 16);
- char *in_check_value_char = buf_to_str(cmd->fields[i].in_check_value, num_bits, 16);
- char *in_check_mask_char = buf_to_str(cmd->fields[i].in_check_mask, num_bits, 16);
+ char *captured_char = buf_to_str(captured, (num_bits > 64) ? 64 : num_bits, 16);
+ char *in_check_value_char = buf_to_str(cmd->fields[i].in_check_value, (num_bits > 64) ? 64 : num_bits, 16);
+ char *in_check_mask_char = buf_to_str(cmd->fields[i].in_check_mask, (num_bits > 64) ? 64 : num_bits, 16);
/* TODO: error reporting */
WARNING("value captured during scan didn't pass the requested check: captured: 0x%s check_value: 0x%s check_mask: 0x%s", captured_char, in_check_value_char, in_check_mask_char);
retval = ERROR_JTAG_QUEUE_FAILED;
usleep(us);
}
+/* Try to examine chain layout according to IEEE 1149.1 ยง12
+ */
+int jtag_examine_chain()
+{
+ scan_field_t field;
+ u8 idcode_buffer[JTAG_MAX_CHAIN_SIZE * 4];
+ int i;
+ int bit_count;
+ int device_count = 0;
+ u8 valid = 0x0;
+
+ field.device = 0;
+ field.num_bits = sizeof(idcode_buffer) * 8;
+ field.out_value = idcode_buffer;
+ field.out_mask = NULL;
+ field.in_value = idcode_buffer;
+ field.in_check_value = NULL;
+ field.in_check_mask = NULL;
+ field.in_handler = NULL;
+ field.in_handler_priv = NULL;
+
+ for (i = 0; i < JTAG_MAX_CHAIN_SIZE; i++)
+ {
+ buf_set_u32(idcode_buffer, 0, 32, 0x000000FF);
+ }
+
+ jtag_add_plain_dr_scan(1, &field, TAP_TLR);
+ jtag_execute_queue();
+
+ for (i = 0; i < JTAG_MAX_CHAIN_SIZE * 4; i++)
+ {
+ valid |= idcode_buffer[i];
+ }
+
+ /* if there wasn't a single non-zero bit, the scan isn't valid */
+ if (!valid)
+ {
+ ERROR("JTAG communication failure, check connection, JTAG interface, target power etc.");
+ exit(-1);
+ }
+
+ for (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)
+ {
+ /* LSB must not be 0, this indicates a device in bypass */
+ device_count++;
+
+ bit_count += 1;
+ }
+ else
+ {
+ u32 manufacturer;
+ u32 part;
+ u32 version;
+
+ if (idcode == 0x000000FF)
+ {
+ /* End of chain (invalid manufacturer ID) */
+ break;
+ }
+
+ device_count++;
+
+ manufacturer = (idcode & 0xffe) >> 1;
+ part = (idcode & 0xffff000) >> 12;
+ version = (idcode & 0xf0000000) >> 28;
+
+ DEBUG("JTAG device found: 0x%8.8x (Manufacturer: 0x%3.3x, Part: 0x%4.4x, Version: 0x%1.1x",
+ idcode, manufacturer, part, version);
+
+ bit_count += 32;
+ }
+ }
+
+ /* see if number of discovered devices matches configuration */
+ if (device_count != jtag_num_devices)
+ {
+ ERROR("number of discovered devices in JTAG chain (%i) doesn't match configuration (%i)",
+ device_count, jtag_num_devices);
+ exit(-1);
+ }
+
+ return ERROR_OK;
+}
+
int jtag_validate_chain()
{
jtag_device_t *device = jtag_devices;
jtag_add_statemove(TAP_TLR);
jtag_execute_queue();
+ jtag_examine_chain();
+
jtag_validate_chain();
return ERROR_OK;