summaryrefslogtreecommitdiff
path: root/src/jtag
diff options
context:
space:
mode:
authordrath <drath@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2007-01-22 14:47:00 +0000
committerdrath <drath@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2007-01-22 14:47:00 +0000
commit4fc97d3f2726efa147cfdb0c456eace51550e1e3 (patch)
treef6bbfc0aa3ceebdf723c23f84b3e764548c1add4 /src/jtag
parentadaed4c1c776f0830387eb86c3d81f00f240be6e (diff)
downloadopenocd_libswd-4fc97d3f2726efa147cfdb0c456eace51550e1e3.tar.gz
openocd_libswd-4fc97d3f2726efa147cfdb0c456eace51550e1e3.tar.bz2
openocd_libswd-4fc97d3f2726efa147cfdb0c456eace51550e1e3.tar.xz
openocd_libswd-4fc97d3f2726efa147cfdb0c456eace51550e1e3.zip
- fix incorrect parsing of whitespace in command.c (thanks to Magnus Lundin)
- fix infinite recursion in target_init_handler (thanks to jw and Magnus Lundin) - fix CFI flash handlign with buswidth < 32bit (thanks to Daniele Orio for reporting this) - add support for reading JTAG device id (currently only as debug output on startup) - cleaned up handling of EmbeddedICE registers. Supported functionality and register size now determined by EmbeddedICE version number. - small cleanups/fixes git-svn-id: svn://svn.berlios.de/openocd/trunk@124 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/jtag')
-rw-r--r--src/jtag/jtag.c96
-rw-r--r--src/jtag/jtag.h2
2 files changed, 95 insertions, 3 deletions
diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c
index 263eed1a..cc9f8dc4 100644
--- a/src/jtag/jtag.c
+++ b/src/jtag/jtag.c
@@ -115,6 +115,10 @@ int jtag_verify_capture_ir = 1;
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;
@@ -597,8 +601,7 @@ int jtag_add_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state)
/* 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");
}
}
}
@@ -1116,6 +1119,93 @@ void jtag_sleep(u32 us)
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;
@@ -1244,6 +1334,8 @@ int jtag_init(struct command_context_s *cmd_ctx)
jtag_add_statemove(TAP_TLR);
jtag_execute_queue();
+ jtag_examine_chain();
+
jtag_validate_chain();
return ERROR_OK;
diff --git a/src/jtag/jtag.h b/src/jtag/jtag.h
index 7ad38278..19f81ce6 100644
--- a/src/jtag/jtag.h
+++ b/src/jtag/jtag.h
@@ -25,7 +25,7 @@
#include "command.h"
-#if 0
+#if 1
#define _DEBUG_JTAG_IO_
#endif