From 902e35d7e0f9e403f57bfa247176dcff0ccc95ae Mon Sep 17 00:00:00 2001 From: Marcel Telka Date: Wed, 13 Aug 2003 21:58:07 +0000 Subject: [PATCH] 2003-08-13 Marcel Telka * include/jtag.h (detect_register_size): Added function declaration. * src/discovery.c (detect_register_size): Changed to non-static. * src/detect.c (detect_parts): Added support for parts without IDCODE. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@510 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/ChangeLog | 6 +++ jtag/NEWS | 2 +- jtag/TODO | 1 - jtag/include/jtag.h | 1 + jtag/src/detect.c | 118 +++++++++++++++++++++++++++++++------------ jtag/src/discovery.c | 2 +- 6 files changed, 96 insertions(+), 34 deletions(-) diff --git a/jtag/ChangeLog b/jtag/ChangeLog index 2947b992..969f4ac5 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,9 @@ +2003-08-13 Marcel Telka + + * include/jtag.h (detect_register_size): Added function declaration. + * src/discovery.c (detect_register_size): Changed to non-static. + * src/detect.c (detect_parts): Added support for parts without IDCODE. + 2003-08-13 Marcel Telka * src/bus/sa1110.c (sa1110_bus_width): Removed bus width printing. diff --git a/jtag/NEWS b/jtag/NEWS index 35ac42c2..3be2bf4a 100644 --- a/jtag/NEWS +++ b/jtag/NEWS @@ -18,7 +18,6 @@ jtag-0.5: * Added new command 'part', syntax changes for 'set', 'get', 'dr', 'instruction', and 'print' commands. * Added support for multiple buses, added new 'bus' command to change active bus. - * Added 1 x 8 bit AMD Flash driver (patch 772499, Matan Ziv-Av). * Added initial JTAG declarations for Broadcom BCM3310 (see support request 770145 for more info, thanks to Ramses VI). * Fixed invalid memory allocation size (core dump) in jtag_parse_line() function. @@ -26,6 +25,7 @@ jtag-0.5: * Added new commands 'signal', 'register', 'bit', and enhanced 'instruction' command to allow create JTAG declarations from command line (or script). * JTAG declarations are now executed as scripts. + * Added support for parts without IDCODE instruction. * Added support for "downto" in bit vectors and "observe_only" into bsdl2jtag (patch 787346, Brad Parker). * Minor bugs fixed. diff --git a/jtag/TODO b/jtag/TODO index 3b791fe1..6dc501bc 100644 --- a/jtag/TODO +++ b/jtag/TODO @@ -1,7 +1,6 @@ $Id$ * Write documentation. -* Add support for non-IDCODE-capable parts. * Support for display the result of a boundary scan formated according to the CPU definitions (e.g. MA[0-26] = 0x00001c00). * Remove direct relation between JTAG instruction and data register (e.g. ARM7TDMI). * SVF player. diff --git a/jtag/include/jtag.h b/jtag/include/jtag.h index 0214cf03..8aa63b17 100644 --- a/jtag/include/jtag.h +++ b/jtag/include/jtag.h @@ -41,6 +41,7 @@ extern int big_endian; int jtag_parse_file( const char *filename ); parts_t *detect_parts( chain_t *chain, char *db_path ); +int detect_register_size( chain_t *chain ); void discovery( chain_t *chain ); void readmem( bus_t *bus, FILE *f, uint32_t addr, uint32_t len ); diff --git a/jtag/src/detect.c b/jtag/src/detect.c index 5bb83af8..920eaafb 100644 --- a/jtag/src/detect.c +++ b/jtag/src/detect.c @@ -163,22 +163,62 @@ find_record( char *filename, tap_register *key, struct id_record *idr ) parts_t * detect_parts( chain_t *chain, char *db_path ) { + int irlen; + tap_register *ir; + int chlen; + tap_register *one; + tap_register *ones; + tap_register *br; + tap_register *id; + parts_t *ps; + int i; + char data_path[1024]; char *cmd[3] = {"script", data_path, NULL}; char manufacturer[MAXLEN_MANUFACTURER + 1]; char partname[MAXLEN_PART + 1]; char stepping[MAXLEN_STEPPING + 1]; - tap_register *zeros = register_fill( register_alloc( 32 ), 0 ); - tap_register *ones = register_fill( register_alloc( 32 ), 1 ); - tap_register *id = register_alloc( 32 ); - parts_t *ps = parts_alloc(); + /* Detect IR length */ + tap_reset( chain ); + tap_capture_ir( chain ); + irlen = detect_register_size( chain ); + if (irlen < 1) + return NULL; + + printf( _("IR length: %d\n"), irlen ); + + /* Allocate IR */ + ir = register_fill( register_alloc( irlen ), 1 ); + if (ir == NULL) { + printf( _("out of memory\n") ); + return NULL; + } - if (!zeros || !ones || !id || !ps) { - printf( _("%s: out of memory\n"), __FUNCTION__ ); + tap_shift_register( chain, ir, NULL, 1 ); + register_free( ir ); - register_free( zeros ); + /* Detect chain length */ + tap_capture_dr( chain ); + chlen = detect_register_size( chain ); + if (chlen < 1) { + printf( _("Unable to detect JTAG chain length\n") ); + return NULL; + } + printf( _("Chain length: %d\n"), chlen ); + + /* Allocate registers and parts */ + one = register_fill( register_alloc( 1 ), 1 ); + ones = register_fill( register_alloc( 31 ), 1 ); + br = register_alloc( 1 ); + id = register_alloc( 32 ); + ps = parts_alloc(); + if (!one || !ones || !br || !id || !ps) { + printf( _("out of memory\n") ); + + register_free( one ); register_free( ones ); + register_free( br ); register_free( id ); parts_free( ps ); return NULL; @@ -186,25 +226,38 @@ detect_parts( chain_t *chain, char *db_path ) chain->parts = ps; chain->active_part = 0; + /* Detect parts */ tap_reset( chain ); - tap_capture_dr( chain ); - for (;;) { + + for (i = 0; i < chlen; i++) { + part_t *part; + tap_register *did = br; /* detected id (length is 1 or 32) */ tap_register *key; struct id_record idr; char *p; - part_t *part; - tap_shift_register( chain, zeros, id, 0 ); - if (!register_compare( id, zeros )) - break; /* end of chain */ + tap_shift_register( chain, one, br, 0 ); + if (register_compare( one, br ) == 0) { + /* part with id */ + tap_shift_register( chain, ones, id, 0 ); + register_shift_left( id, 1 ); + id->data[0] = 1; + did = id; + } - if (!register_compare( ones, id )) { - printf( _("%s: bad JTAG connection (TDO is 1)\n"), __FUNCTION__ ); + printf( _("Device Id: %s\n"), register_get_string( did ) ); + part = part_alloc( did ); + if (part == NULL) { + printf( _("Out of memory\n") ); break; } + parts_add_part( ps, part ); + + if (did == br) + continue; - printf( _("Device Id: %s\n"), register_get_string( id ) ); + /* find JTAG declarations for a part with id */ strcpy( data_path, db_path ); /* FIXME: Buffer overrun */ @@ -283,26 +336,29 @@ detect_parts( chain_t *chain, char *db_path ) strcat( data_path, idr.name ); printf( _(" Filename: %s\n"), data_path ); - part = part_alloc( id ); - if (part) { - parts_add_part( ps, part ); - chain->active_part = ps->len - 1; - strcpy( part->manufacturer, manufacturer ); - strcpy( part->part, partname ); - strcpy( part->stepping, stepping ); - cmd_run( cmd ); + + /* run JTAG declarations */ + chain->active_part = ps->len - 1; + strcpy( part->manufacturer, manufacturer ); + strcpy( part->part, partname ); + strcpy( part->stepping, stepping ); + cmd_run( cmd ); + if (part->active_instruction == NULL) part->active_instruction = part_find_instruction( part, "IDCODE" ); - } else { - printf( _("Out of memory\n") ); - exit( 1 ); - } } - chain_clock( chain, 1, 0 ); /* Exit1-DR */ - chain_clock( chain, 1, 0 ); /* Update-DR */ + for (i = 0; i < 32; i++) { + tap_shift_register( chain, one, br, 0 ); + if (register_compare( one, br ) != 0) { + printf( _("Error: Unable to detect JTAG chain end!\n") ); + break; + } + } + tap_shift_register( chain, one, NULL, 1 ); - register_free( zeros ); + register_free( one ); register_free( ones ); + register_free( br ); register_free( id ); return ps; diff --git a/jtag/src/discovery.c b/jtag/src/discovery.c index 2174639c..21466072 100644 --- a/jtag/src/discovery.c +++ b/jtag/src/discovery.c @@ -38,7 +38,7 @@ #define TEST_COUNT 1 #define TEST_THRESHOLD 100 /* in % */ -static int +int detect_register_size( chain_t *chain ) { int len;