diff --git a/jtag/ChangeLog b/jtag/ChangeLog index 39b7bf0a..80836a5a 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,18 @@ +2003-01-08 Marcel Telka + + * include/Makefile.am: Removed ctrl.h, added cable.h. + * include/ctrl.h: Removed obsolete file. + * include/cable.h: Added common declarations for JTAG cable drivers. + * src/detect.c: Replaced ctrl.h include with cable.h (JTAG cable driver support). + * src/discovery.c: Ditto. + * src/tap/tap.c: Ditto. + * src/help.c: Added help for new command 'cable'. + * src/jtag.c: Added support for JTAG cable drivers, added new command 'cable'. + * src/tap/Makefile.am: Removed ctrl.c, added cable/ea253.c, updated includes. + * src/tap/ctrl.c: Removed obsolete file. + * src/tap/state.c: Changed default TRST state to 1. + * src/tap/cable/ea253.c: Added driver for EA253 JTAG cable. + 2003-01-06 Marcel Telka * src/discovery.c (discovery): Fixed memory leaks, added out of memory test, diff --git a/jtag/NEWS b/jtag/NEWS index 47951560..1f972c6d 100644 --- a/jtag/NEWS +++ b/jtag/NEWS @@ -3,6 +3,7 @@ Changes since 0.1: * Completed JTAG declarations for Xilinx XCR3128XL-CS144. * Fixed crash if flash memory is not detected. * Added new 'discovery' command for discovery unknown JTAG chains. + * Added JTAG cable driver support and new 'cable' command. jtag-0.1 (2002-11-25): diff --git a/jtag/README b/jtag/README index 8a9f7b52..c6764cbe 100644 --- a/jtag/README +++ b/jtag/README @@ -35,7 +35,8 @@ Supported hardware ------------------ JTAG adapters: -- various parallel port JTAG adapters +- various parallel port JTAG adapters/cables (for complete list see + 'help cable' command) JTAG-aware parts (chips): - Atmel ATmega128 (partial support) @@ -76,12 +77,10 @@ Build & installation instructions 1. Download and install required software (see previous section). 2. Download and unpack jtag sources. -3. Setup your parallel cable configuration in src/tap/ctrl.c file. - Please set correct TCK, TDI, TMS, TRST, TDO and 'port' values in the file. -4. Run ./configure script. Use optional --with-include parameter. +3. Run ./configure script. Use optional --with-include parameter. See `./configure --help` for more info. -5. Run `make`. -6. Run `make install`. +4. Run `make`. +5. Run `make install`. Running JTAG tools @@ -98,7 +97,15 @@ jtag> This is "jtag command prompt". Type "help" and press for initial help about available commands. To exit JTAG Tools type "quit" and press . -===> First task: Detect parts on the JTAG chain. +===> First task: Select JTAG cable and parallel port address. + +Type "help cable" for list of supported JTAG cables. +Type "cable" command with arguments. Exmaple: + +jtag> cable parallel 0x378 EA253 +Initilizing cable EA253 on parallel port at 0x378 + +===> Second task: Detect parts on the JTAG chain. Type "detect" at the jtag command prompt: jtag> detect @@ -121,7 +128,7 @@ doesn't work, or your JTAG-aware chip doesn't support JTAG ID detection "detect" command is required before all other commands. -===> Second task: Print current JTAG chain status. +===> Third task: Print current JTAG chain status. Type "print" at the jtag command prompt. Here is an output example: @@ -131,7 +138,7 @@ jtag> print 0 Intel PXA250 C0 BYPASS BR jtag> -===> Third task: Sample device pin status. +===> Fourth task: Sample device pin status. jtag> instruction 0 SAMPLE/PRELOAD jtag> shift ir @@ -151,7 +158,7 @@ jtag> Note: BSR is "Boundary Scan Register" -===> Fourth task: Burn flash connected to the part. +===> Fifth task: Burn flash connected to the part. jtag> flashmem 0 brux.b 0x00000000 diff --git a/jtag/THANKS b/jtag/THANKS index 2d2b5899..01cbfdcb 100644 --- a/jtag/THANKS +++ b/jtag/THANKS @@ -1 +1,4 @@ +jtag-0.1 +-------- + Thanks to Holger Schurig for suggestion about readmem functionality and his feedback. diff --git a/jtag/include/Makefile.am b/jtag/include/Makefile.am index 4b798dfe..875a6dd4 100644 --- a/jtag/include/Makefile.am +++ b/jtag/include/Makefile.am @@ -23,7 +23,7 @@ noinst_HEADERS = \ bsbit.h \ - ctrl.h \ + cable.h \ data_register.h \ instruction.h \ part.h \ diff --git a/jtag/include/ctrl.h b/jtag/include/cable.h similarity index 58% rename from jtag/include/ctrl.h rename to jtag/include/cable.h index 4ad9585a..f90abd16 100644 --- a/jtag/include/ctrl.h +++ b/jtag/include/cable.h @@ -1,7 +1,8 @@ /* * $Id$ * - * Copyright (C) 2002 ETC s.r.o. + * Cable driver interface + * 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 @@ -18,22 +19,28 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * - * Written by Marcel Telka , 2002. + * Written by Marcel Telka , 2003. * */ -#ifndef CTRL_H -#define CTRL_H +#ifndef CABLE_H +#define CABLE_H -/* - * low level tap functions, hardware dependent - */ -int tap_init( void ); -void tap_done( void ); +#include + +typedef struct { + int (*init)( unsigned int ); + void (*done)( void ); + void (*clock)( int, int ); + int (*get_tdo)( void ); + void (*set_trst)( int ); +} cable_driver_t; -void tap_clock( int tms, int tdi ); -int tap_get_tdo( void ); +extern cable_driver_t *cable; +#define tap_clock cable->clock +#define tap_get_tdo cable->get_tdo +#define tap_set_trst cable->set_trst -void tap_set_trst( int new_trst ); +extern cable_driver_t ea253_cable_driver; -#endif /* CTRL_H */ +#endif /* CABLE_H */ diff --git a/jtag/src/detect.c b/jtag/src/detect.c index 9b5f8295..faf07587 100644 --- a/jtag/src/detect.c +++ b/jtag/src/detect.c @@ -29,7 +29,7 @@ #include "register.h" #include "tap.h" -#include "ctrl.h" +#include "cable.h" #include "part.h" #include "detect.h" diff --git a/jtag/src/discovery.c b/jtag/src/discovery.c index 77f28e87..396e10d8 100644 --- a/jtag/src/discovery.c +++ b/jtag/src/discovery.c @@ -30,7 +30,7 @@ #include #include -#include "ctrl.h" +#include "cable.h" #include "tap.h" #define DETECT_PATTERN_SIZE 8 diff --git a/jtag/src/help.c b/jtag/src/help.c index 3a102190..8be28485 100644 --- a/jtag/src/help.c +++ b/jtag/src/help.c @@ -38,6 +38,7 @@ help( const char *cmd ) "\n" "quit exit from %s\n" "help display this help\n" + "cable select JTAG cable\n" "detect detect parts on the JTAG chain\n" "discovery discovery unknown parts in the JTAG chain\n" "print display JTAG chain list/status\n" @@ -61,6 +62,17 @@ help( const char *cmd ) "Usage: help [COMMAND]\n" "Print short help for COMMAND, or list of available commands.\n" ); + else if (strcmp( cmd, "cable" ) == 0) + printf( + "Usage: cable parallel PORTADDR CABLE\n" + "Select JTAG cable connected to parallel port.\n" + "\n" + "PORTADDR parallel port address (e.g. 0x378)\n" + "CABLE cable type\n" + "\n" + "List of supported cables:\n" + "none, EA253\n" + ); else if (strcmp( cmd, "detect" ) == 0) printf( "Usage: detect\n" diff --git a/jtag/src/jtag.c b/jtag/src/jtag.c index fb65dc8b..fbdf5d79 100644 --- a/jtag/src/jtag.c +++ b/jtag/src/jtag.c @@ -32,12 +32,14 @@ #include #include "part.h" -#include "ctrl.h" +#include "cable.h" #include "tap.h" #include "detect.h" #include "bus.h" +cable_driver_t *cable = NULL; + bus_driver_t *bus_driver = NULL; static char * @@ -72,14 +74,6 @@ main( void ) printf( "Warning: %s may damage your hardware! Type \"quit\" for exit!\n\n", PACKAGE ); printf( "Type \"help\" for help.\n\n" ); - if (!tap_init()) { - printf( "TAP initialization failed! Exiting.\n" ); - return 1; - } - - tap_set_trst( 0 ); - tap_set_trst( 1 ); - for (;;) { char *t; @@ -106,7 +100,70 @@ main( void ) continue; } + if (strcmp( t, "cable" ) == 0) { + unsigned int port; + + t = get_token( NULL ); + if (!t) { + printf( "Missing argument(s)\n" ); + continue; + } + if (strcmp( t, "parallel" ) != 0) { + printf( "syntax error!\n" ); + continue; + } + + t = get_token( NULL ); + if (!t) { + printf( "Missing argument(s)\n" ); + continue; + } + if ((sscanf( t, "0x%x", &port ) != 1) && (sscanf( t, "%d", &port ) != 1)) { + printf( "syntax error\n" ); + continue; + } + + t = get_token( NULL ); + if (!t) { + printf( "Missing argument(s)\n" ); + continue; + } + + if (get_token( NULL )) { + printf( "syntax error!\n" ); + continue; + } + + if (strcmp( t, "none" ) == 0) { + printf( "Changed cable to 'none'\n" ); + cable = NULL; + } else if (strcmp( t, "EA253" ) == 0) { + cable = &ea253_cable_driver; + + if (!cable->init( port )) { + cable = NULL; + } + } else { + printf( "Unknown cable: %s\n", t ); + continue; + } + + if (cable) { + cable->set_trst( 0 ); + cable->set_trst( 1 ); + + tap_reset(); + } + + continue; + } + if (strcmp( t, "discovery" ) == 0) { + if (!cable) { + printf( "Error: Cable not configured. Use 'cable' command first!\n" ); + continue; + } + t = get_token( NULL ); if (!t) { printf( "discovery: missing filename\n" ); @@ -121,9 +178,14 @@ main( void ) } if (strcmp( t, "detect" ) == 0) { + if (!cable) { + printf( "Error: Cable not configured. Use 'cable' command first!\n" ); + continue; + } + t = get_token( NULL ); - if (ps) - parts_free( ps ); + + parts_free( ps ); ps = detect_parts( JTAG_DATA_DIR ); if (!ps->len) continue; @@ -144,6 +206,11 @@ main( void ) int msbin = 0; uint32_t addr = 0; + if (!cable) { + printf( "Error: Cable not configured. Use 'cable' command first!\n" ); + continue; + } + if (!ps) { printf( "Run \"detect\" first.\n" ); continue; @@ -192,6 +259,11 @@ main( void ) uint32_t addr = 0; uint32_t len = 0; + if (!cable) { + printf( "Error: Cable not configured. Use 'cable' command first!\n" ); + continue; + } + if (!ps) { printf( "Run \"detect\" first.\n" ); continue; @@ -242,6 +314,11 @@ main( void ) } if (strcmp( t, "detectflash" ) == 0) { + if (!cable) { + printf( "Error: Cable not configured. Use 'cable' command first!\n" ); + continue; + } + if (!ps) { printf( "Run \"detect\" first.\n" ); continue; @@ -252,6 +329,11 @@ main( void ) } if (strcmp( t, "print" ) == 0) { + if (!cable) { + printf( "Error: Cable not configured. Use 'cable' command first!\n" ); + continue; + } + parts_print( ps, 1 ); continue; } @@ -259,6 +341,11 @@ main( void ) if (strcmp( t, "instruction" ) == 0) { int n; + if (!cable) { + printf( "Error: Cable not configured. Use 'cable' command first!\n" ); + continue; + } + if (!ps) { printf( "Run \"detect\" first.\n" ); continue; @@ -293,6 +380,11 @@ main( void ) } if (strcmp( t, "shift" ) == 0) { + if (!cable) { + printf( "Error: Cable not configured. Use 'cable' command first!\n" ); + continue; + } + t = get_token( NULL ); if (t && (strcmp( t, "ir" ) == 0)) { @@ -312,6 +404,11 @@ main( void ) if (strcmp( t, "dr" ) == 0) { int n; + if (!cable) { + printf( "Error: Cable not configured. Use 'cable' command first!\n" ); + continue; + } + if (!ps) { printf( "Run \"detect\" first.\n" ); continue; @@ -355,8 +452,14 @@ main( void ) free( line ); parts_free( ps ); - tap_reset(); - tap_done(); + if (cable) { + cable->set_trst( 0 ); + cable->set_trst( 1 ); + tap_reset(); + cable->done(); + + cable = NULL; + } return 0; } diff --git a/jtag/src/tap/Makefile.am b/jtag/src/tap/Makefile.am index 83572dd9..f53fa2b9 100644 --- a/jtag/src/tap/Makefile.am +++ b/jtag/src/tap/Makefile.am @@ -24,9 +24,9 @@ noinst_LIBRARIES = libtap.a libtap_a_SOURCES = \ - ctrl.c \ tap.c \ register.c \ - state.c + state.c \ + cable/ea253.c -INCLUDES = -I$(top_srcdir)/include +INCLUDES = -I$(top_srcdir)/include $(OPENWINCE_INC) diff --git a/jtag/src/tap/ctrl.c b/jtag/src/tap/cable/ea253.c similarity index 74% rename from jtag/src/tap/ctrl.c rename to jtag/src/tap/cable/ea253.c index 3927c869..13919db2 100644 --- a/jtag/src/tap/ctrl.c +++ b/jtag/src/tap/cable/ea253.c @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 2002 ETC s.r.o. + * Copyright (C) 2002, 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 @@ -18,21 +18,21 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * - * Written by Marcel Telka , 2002. + * Written by Marcel Telka , 2002, 2003. * */ #include #include -#include "ctrl.h" +#include "cable.h" #include "state.h" /* * data D[7:0] (pins 9:2) */ -#define TCK 0 -#define TDI 1 +#define TDI 0 +#define TCK 1 #define TMS 2 #define TRST 4 @@ -43,15 +43,16 @@ * 4 - SEL (pin 13) * 3 - ERROR (pin 15) */ -#define TDO 7 +#define TDO 4 -static unsigned short int port = 0x378; +static unsigned int port; -int -tap_init( void ) +static int +ea253_init( unsigned int aport ) { tap_state_init(); - printf( "Initilizing parallel TAP on port 0x%x\n", port ); + port = aport; + printf( "Initilizing cable EA253 on parallel port at 0x%x\n", port ); if (ioperm( port, 2, 1 )) { printf( "Error: Initialization failed!\n" ); return 0; @@ -61,16 +62,16 @@ tap_init( void ) return 1; } -void -tap_done( void ) +static void +ea253_done( void ) { ioperm( port, 2, 0 ); tap_state_done(); } -void -tap_clock( int tms, int tdi ) +static void +ea253_clock( int tms, int tdi ) { int trst = tap_state_get_trst(); @@ -83,16 +84,24 @@ tap_clock( int tms, int tdi ) tap_state_clock( tms ); } -int -tap_get_tdo( void ) +static int +ea253_get_tdo( void ) { outb( (tap_state_get_trst() << TRST) | (0 << TCK), port ); return ((inb( port + 1 ) ^ 0x80) >> TDO) & 1; /* BUSY is inverted */ } -void -tap_set_trst( int new_trst ) +static void +ea253_set_trst( int new_trst ) { tap_state_set_trst( new_trst ); outb( (new_trst & 1) << TRST, port ); } + +cable_driver_t ea253_cable_driver = { + ea253_init, + ea253_done, + ea253_clock, + ea253_get_tdo, + ea253_set_trst +}; diff --git a/jtag/src/tap/state.c b/jtag/src/tap/state.c index 8205fc69..5b52623a 100644 --- a/jtag/src/tap/state.c +++ b/jtag/src/tap/state.c @@ -26,7 +26,7 @@ #include "state.h" static int state = Unknown_State; -static int trst = 0; +static int trst = 1; int tap_state( void ) diff --git a/jtag/src/tap/tap.c b/jtag/src/tap/tap.c index df60dc57..e3ffa694 100644 --- a/jtag/src/tap/tap.c +++ b/jtag/src/tap/tap.c @@ -26,7 +26,7 @@ #include "register.h" #include "tap.h" -#include "ctrl.h" +#include "cable.h" #include "state.h" void