From b067b0d946ef9bd86067b52d4bb2bb42471b96e2 Mon Sep 17 00:00:00 2001 From: Kolja Waschk Date: Thu, 3 Apr 2008 20:22:22 +0000 Subject: [PATCH] 1933730 "idcode" command (by U.Bonnes) git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1151 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/ChangeLog | 6 +++ jtag/THANKS | 1 + jtag/include/jtag.h | 1 + jtag/src/cmd/Makefile.am | 1 + jtag/src/cmd/cmd.c | 2 + jtag/src/cmd/idcode.c | 68 +++++++++++++++++++++++++++++++ jtag/src/tap/Makefile.am | 1 + jtag/src/tap/idcode.c | 80 +++++++++++++++++++++++++++++++++++++ jtag/src/tap/parport/ftdi.c | 13 +++++- 9 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 jtag/src/cmd/idcode.c create mode 100644 jtag/src/tap/idcode.c diff --git a/jtag/ChangeLog b/jtag/ChangeLog index 776bcd4f..0a5ccbb5 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,9 @@ +2008-04-03 Kolja Waschk + + * include/jtag.h, src/cmd/cmd.c, src/cmd/idcode.c, src/cmd/Makefile.am, + src/tap/parport/ftdi.c, src/tap/idcode.c, src/tap/Makefile.am, THANKS: + [1933730] new "idcode" command (by U.Bonnes) + 2008-04-03 Arnim Laeuger [ 1929235 ] Use less global and static variables: diff --git a/jtag/THANKS b/jtag/THANKS index ea232c6a..a814250d 100644 --- a/jtag/THANKS +++ b/jtag/THANKS @@ -7,6 +7,7 @@ Shaju Abraham Beregnyei Balazs Krzysztof Blaszkowski Eugene Boldenkov +Uwe Bonnes Cliff Brake Martin Buck Ian Campbell diff --git a/jtag/include/jtag.h b/jtag/include/jtag.h index 61a64633..d363ffc7 100644 --- a/jtag/include/jtag.h +++ b/jtag/include/jtag.h @@ -45,6 +45,7 @@ int jtag_parse_stream( chain_t *chain, FILE *f ); int detect_parts( chain_t *chain, char *db_path ); int detect_register_size( chain_t *chain ); void discovery( chain_t *chain ); +void idcode( chain_t *chain , unsigned int bytes); void readmem( bus_t *bus, FILE *f, uint32_t addr, uint32_t len ); void writemem( bus_t *bus, FILE *f, uint32_t addr, uint32_t len ); diff --git a/jtag/src/cmd/Makefile.am b/jtag/src/cmd/Makefile.am index e3cf841e..3dae1fcc 100644 --- a/jtag/src/cmd/Makefile.am +++ b/jtag/src/cmd/Makefile.am @@ -30,6 +30,7 @@ libcmd_a_SOURCES = \ cable.c \ reset.c \ discovery.c \ + idcode.c \ detect.c \ detectflash.c \ help.c \ diff --git a/jtag/src/cmd/cmd.c b/jtag/src/cmd/cmd.c index 9aa32fa6..bca268a2 100644 --- a/jtag/src/cmd/cmd.c +++ b/jtag/src/cmd/cmd.c @@ -37,6 +37,7 @@ extern cmd_t cmd_frequency; extern cmd_t cmd_cable; extern cmd_t cmd_reset; extern cmd_t cmd_discovery; +extern cmd_t cmd_idcode; extern cmd_t cmd_detect; extern cmd_t cmd_signal; extern cmd_t cmd_scan; @@ -79,6 +80,7 @@ const cmd_t *cmds[] = { &cmd_cable, &cmd_reset, &cmd_discovery, + &cmd_idcode, &cmd_detect, &cmd_signal, &cmd_scan, diff --git a/jtag/src/cmd/idcode.c b/jtag/src/cmd/idcode.c new file mode 100644 index 00000000..5cff75ac --- /dev/null +++ b/jtag/src/cmd/idcode.c @@ -0,0 +1,68 @@ +/* + * $Id: idcode.c 1102 2008-02-27 03:38:31Z jiez $ + * + * Copyright (C) 2003 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Uwe Bonnes , 2008. + * + */ +#include "sysdep.h" + +#include + +#include "jtag.h" + +#include "cmd.h" + +static int +cmd_idcode_run( chain_t *chain, char *params[] ) +{ + unsigned int bytes=0; + + if (cmd_params( params ) == 1) { + bytes = 0; + } + + else if (cmd_params( params ) >2) + return -1; + + else if (cmd_get_number( params[1], &bytes )) + return -1; + + printf( _("Reading %d bytes if idcode\n"), bytes ); + idcode( chain , bytes); + return 1; +} + +static void +cmd_idcode_help( void ) +{ + printf( _( + "Usage: %s [BYTES]\n" + "Read [BYTES]|all IDCODEs of all parts in a JTAG chain.\n" + "\n" + "BYTES must be an unsigned integer, Use 0 for BYTES to read all bytes\n" + ), "idcode" ); +} + +cmd_t cmd_idcode = { + "idcode", + N_("Read IDCODEs of all parts in a JTAG chain"), + cmd_idcode_help, + cmd_idcode_run +}; diff --git a/jtag/src/tap/Makefile.am b/jtag/src/tap/Makefile.am index fc4a2436..a70fe950 100644 --- a/jtag/src/tap/Makefile.am +++ b/jtag/src/tap/Makefile.am @@ -32,6 +32,7 @@ libtap_a_SOURCES = \ chain.c \ detect.c \ discovery.c \ + idcode.c \ parport.c \ usbconn.c \ cable.c \ diff --git a/jtag/src/tap/idcode.c b/jtag/src/tap/idcode.c new file mode 100644 index 00000000..f0ea3b5c --- /dev/null +++ b/jtag/src/tap/idcode.c @@ -0,0 +1,80 @@ +/* + * $Id: idcode.c 1120 2008-03-15 02:27:13Z jiez $ + * + * Copyright (C) 2003 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Uwe Bonnes , 2008. + * + */ +#include "sysdep.h" + +#include +#include + +#include "cable.h" +#include "tap.h" +#include "chain.h" + +#include "jtag.h" + +void +idcode( chain_t *chain , unsigned int bytes) +{ + int i; + int hit = 0; + tap_register *rz; + tap_register *rout; + tap_register *rnull; + + chain_set_trst( chain, 0 ); + chain_set_trst( chain, 1 ); + + tap_reset( chain ); + tap_capture_dr( chain ); + + /* read in chunks of 8 bytes */ + rz = register_fill( register_alloc( 8 ), 0); + rnull = register_fill( register_alloc( 8 ), 0 ); + rout = register_alloc( 8 ); + + if (!rz || !rout || !rnull) + { + printf(_("Allocation failed\n")); + } + printf(_("Read")); + for (i=0; i<((bytes)?bytes:1000); i++) + { + tap_shift_register( chain, rz, rout, 0 ); + printf(_(" %s"), register_get_string(rout)); + if (!bytes) + { + /* Abort Reading when a null IDCODE has been read */ + if (!register_compare(rout, rnull)) + hit++; + else + hit = 0; + if (hit >3) + break; + } + } + register_free( rz ); + register_free( rnull ); + register_free( rout ); + printf(_("\n")); +} + diff --git a/jtag/src/tap/parport/ftdi.c b/jtag/src/tap/parport/ftdi.c index 6ea6d4c1..295c3338 100644 --- a/jtag/src/tap/parport/ftdi.c +++ b/jtag/src/tap/parport/ftdi.c @@ -465,7 +465,13 @@ static int ftdi_flush_output ( ftdi_params_t *p ) { int xferred; + int i; + unsigned char * q; + // printf("ftdi_flush_output, length %d", p->outcount); + // for (i=0, q=p->outbuf; ioutcount; i++, q++) + // printf(" %01x", *q); + // printf("\n"); xferred = ftdi_write_data(p->fc, p->outbuf, p->outcount); if (xferred < 0) printf( _("Error from ftdi_write_data(): %d\n"), xferred); @@ -539,12 +545,15 @@ ftdi_get_data( parport_t *parport ) { unsigned char d; ftdi_params_t *p = parport->params; + int res = 0; if (p->fc) { while(ftdi_read_data( p->fc, &d, 1) == 0); - return d; + res = d; } else - return 0; + res = 0; + // printf("ftdi_get_data %01x\n", d); + return res; } static int