From daa49cf9bc2fe012446266660f78cbb0451a5852 Mon Sep 17 00:00:00 2001 From: Marcel Telka Date: Thu, 13 Mar 2003 19:37:29 +0000 Subject: [PATCH] 2003-03-13 Marcel Telka * include/chain.h: New file. * src/tap/chain.c: Ditto. * src/tap/Makefile.am (libtap_a_SOURCES): Added chain.c. * include/Makefile.am (noinst_HEADERS): Added chain.h. * src/jtag.c: Encapsulated parts, cable and TAP state into one object - chain. All relevant function parameters changed to `chain'. * src/tap/state.c: `trst' state moved to cable drivers. All cable drivers changed. * include/cable.h (cable_driver_t) : Changed return value from void to int. All cable drivers changed. (cable_driver_t) : New function. Implemented this function to all cable drivers. * include/part.h (part_shift_instruction, part_shift_data_register) (parts_shift_instructions, parts_shift_data_registers): Funcions removed. * src/part/part.c (part_shift_instruction, part_shift_data_register) (parts_shift_instructions, parts_shift_data_registers): Ditto. * src/tap/cable/arcom.c: Removed dependency on state.h. * src/tap/cable/byteblaster.c: Ditto. * src/tap/cable/dlc5.c: Ditto. * src/tap/cable/ea253.c: Ditto. * src/tap/cable/ei012.c: Ditto. * src/tap/cable/mpcbdm.c: Ditto. * src/tap/cable/wiggler.c: Ditto. * include/state.h (bit): Replaced with common.h include. (Unknown_State, Run_Test_Idle, Select_DR_Scan, Select_IR_Scan): Removed parentheses. * include/tap.h (write_command): Removed unused declaration. * src/detect.h: Removed file. * src/jtag.h: New file with common jtag function declarations. * src/Makefile.am (jtag_SOURCES): Removed detect.h, added jtag.h. * src/cfi.c: Added jtag.h include. Moved common function declarations to jtag.h file. * src/detect.c: Ditto. * src/discovery.c: Ditto. * src/flash.c: Ditto. * src/help.c: Ditto. * src/jtag.c: Ditto. * src/readmem.c: Ditto. * src/jtag.c (jtag_create_jtagdir, jtag_load_history, jtag_save_history, jtag_parse_line) (jtag_readline_loop, jtag_parse_file, jtag_parse_rc): Changed functions to `static'. * src/tap/tap.c: Added l10n support. * po/POTFILES.in: Added src/tap/chain.c and src/tap/tap.c. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@392 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/ChangeLog | 47 +++++++++ jtag/include/Makefile.am | 1 + jtag/include/bus.h | 13 +-- jtag/include/cable.h | 10 +- jtag/include/chain.h | 51 ++++++++++ jtag/include/part.h | 4 - jtag/include/state.h | 25 ++--- jtag/include/tap.h | 12 +-- jtag/po/POTFILES.in | 2 + jtag/src/Makefile.am | 2 +- jtag/src/bus/ixp425.c | 37 +++---- jtag/src/bus/pxa2x0.c | 38 +++---- jtag/src/bus/sa1110.c | 39 ++++---- jtag/src/cfi.c | 66 +++++++------ jtag/src/detect.c | 15 +-- jtag/src/discovery.c | 41 ++++---- jtag/src/flash-amd.c | 71 +++++++------- jtag/src/flash-intel.c | 113 ++++++++++----------- jtag/src/flash.c | 55 ++++++----- jtag/src/flash.h | 21 ++-- jtag/src/help.c | 2 + jtag/src/jtag.c | 163 ++++++++++++++----------------- jtag/src/{detect.h => jtag.h} | 28 ++++-- jtag/src/part/part.c | 58 ----------- jtag/src/readmem.c | 36 +++---- jtag/src/tap/Makefile.am | 1 + jtag/src/tap/cable/arcom.c | 34 ++++--- jtag/src/tap/cable/byteblaster.c | 22 +++-- jtag/src/tap/cable/dlc5.c | 22 +++-- jtag/src/tap/cable/ea253.c | 34 ++++--- jtag/src/tap/cable/ei012.c | 34 ++++--- jtag/src/tap/cable/mpcbdm.c | 35 ++++--- jtag/src/tap/cable/wiggler.c | 34 ++++--- jtag/src/tap/chain.c | 155 +++++++++++++++++++++++++++++ jtag/src/tap/state.c | 89 ++++++++--------- jtag/src/tap/tap.c | 67 +++++++------ 36 files changed, 854 insertions(+), 623 deletions(-) create mode 100644 jtag/include/chain.h rename jtag/src/{detect.h => jtag.h} (55%) create mode 100644 jtag/src/tap/chain.c diff --git a/jtag/ChangeLog b/jtag/ChangeLog index 5b15750d..9df8067f 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,50 @@ +2003-03-13 Marcel Telka + + * include/chain.h: New file. + * src/tap/chain.c: Ditto. + * src/tap/Makefile.am (libtap_a_SOURCES): Added chain.c. + * include/Makefile.am (noinst_HEADERS): Added chain.h. + * src/jtag.c: Encapsulated parts, cable and TAP state into one object - chain. + All relevant function parameters changed to `chain'. + * src/tap/state.c: `trst' state moved to cable drivers. + All cable drivers changed. + * include/cable.h (cable_driver_t) : Changed return value from void to int. + All cable drivers changed. + (cable_driver_t) : New function. + Implemented this function to all cable drivers. + * include/part.h (part_shift_instruction, part_shift_data_register) + (parts_shift_instructions, parts_shift_data_registers): Funcions removed. + * src/part/part.c (part_shift_instruction, part_shift_data_register) + (parts_shift_instructions, parts_shift_data_registers): Ditto. + * src/tap/cable/arcom.c: Removed dependency on state.h. + * src/tap/cable/byteblaster.c: Ditto. + * src/tap/cable/dlc5.c: Ditto. + * src/tap/cable/ea253.c: Ditto. + * src/tap/cable/ei012.c: Ditto. + * src/tap/cable/mpcbdm.c: Ditto. + * src/tap/cable/wiggler.c: Ditto. + + * include/state.h (bit): Replaced with common.h include. + (Unknown_State, Run_Test_Idle, Select_DR_Scan, Select_IR_Scan): Removed parentheses. + * include/tap.h (write_command): Removed unused declaration. + + * src/detect.h: Removed file. + * src/jtag.h: New file with common jtag function declarations. + * src/Makefile.am (jtag_SOURCES): Removed detect.h, added jtag.h. + * src/cfi.c: Added jtag.h include. Moved common function declarations to jtag.h file. + * src/detect.c: Ditto. + * src/discovery.c: Ditto. + * src/flash.c: Ditto. + * src/help.c: Ditto. + * src/jtag.c: Ditto. + * src/readmem.c: Ditto. + + * src/jtag.c (jtag_create_jtagdir, jtag_load_history, jtag_save_history, jtag_parse_line) + (jtag_readline_loop, jtag_parse_file, jtag_parse_rc): Changed functions to `static'. + + * src/tap/tap.c: Added l10n support. + * po/POTFILES.in: Added src/tap/chain.c and src/tap/tap.c. + 2003-03-13 Marcel Telka * include/part.h: Renamed types part to part_t, parts to parts_t, diff --git a/jtag/include/Makefile.am b/jtag/include/Makefile.am index 8f1df3fa..a2debf77 100644 --- a/jtag/include/Makefile.am +++ b/jtag/include/Makefile.am @@ -25,6 +25,7 @@ noinst_HEADERS = \ bsbit.h \ bus.h \ cable.h \ + chain.h \ data_register.h \ gettext.h \ instruction.h \ diff --git a/jtag/include/bus.h b/jtag/include/bus.h index 748594a4..f40dd162 100644 --- a/jtag/include/bus.h +++ b/jtag/include/bus.h @@ -28,14 +28,15 @@ #include #include "part.h" +#include "chain.h" typedef struct { - int (*bus_width)( parts *ps ); - void (*bus_read_start)( parts *, uint32_t ); - uint32_t (*bus_read_next)( parts *, uint32_t ); - uint32_t (*bus_read_end)( parts * ); - uint32_t (*bus_read)( parts *, uint32_t ); - void (*bus_write)( parts *, uint32_t, uint32_t ); + int (*bus_width)( chain_t * ); + void (*bus_read_start)( chain_t *, uint32_t ); + uint32_t (*bus_read_next)( chain_t *, uint32_t ); + uint32_t (*bus_read_end)( chain_t * ); + uint32_t (*bus_read)( chain_t *, uint32_t ); + void (*bus_write)( chain_t *, uint32_t, uint32_t ); } bus_driver_t; extern bus_driver_t *bus_driver; diff --git a/jtag/include/cable.h b/jtag/include/cable.h index 88e8bde3..79c4e380 100644 --- a/jtag/include/cable.h +++ b/jtag/include/cable.h @@ -28,6 +28,8 @@ #include +#define cable_t cable_driver_t + typedef struct { const char *name; const char *description; @@ -35,17 +37,13 @@ typedef struct { void (*done)( void ); void (*clock)( int, int ); int (*get_tdo)( void ); - void (*set_trst)( int ); + int (*set_trst)( int ); + int (*get_trst)( void ); } cable_driver_t; extern uint32_t frequency; void cable_wait( 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 - extern cable_driver_t *cable_drivers[]; #endif /* CABLE_H */ diff --git a/jtag/include/chain.h b/jtag/include/chain.h new file mode 100644 index 00000000..7aa9cf4d --- /dev/null +++ b/jtag/include/chain.h @@ -0,0 +1,51 @@ +/* + * $Id$ + * + * 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 Marcel Telka , 2003. + * + */ + +#ifndef CHAIN_H +#define CHAIN_H + +#include "cable.h" +#include "part.h" + +typedef struct { + int state; + parts_t *parts; + cable_t *cable; +} chain_t; + +chain_t *chain_alloc( void ); +void chain_free( chain_t *chain ); +int chain_connect( chain_t *chain, cable_t *cable, unsigned int port ); +void chain_clock( chain_t *chain, int tms, int tdi ); +int chain_set_trst( chain_t *chain, int trst ); +int chain_get_trst( chain_t *chain ); +void chain_shift_instructions( chain_t *chain ); +void chain_shift_data_registers( chain_t *chain ); + +typedef struct { + chain_t **chains; + int size; /* allocated chains array size */ +} chains_t; + +#endif /* CHAIN_H */ diff --git a/jtag/include/part.h b/jtag/include/part.h index 674b0680..f498be10 100644 --- a/jtag/include/part.h +++ b/jtag/include/part.h @@ -58,8 +58,6 @@ part *read_part( FILE *f, tap_register_t *idr ); instruction *part_find_instruction( part_t *p, const char *iname ); data_register *part_find_data_register( part_t *p, const char *drname ); void part_set_instruction( part_t *p, const char *iname ); -void part_shift_instruction( part_t *p, int exit ); -void part_shift_data_register( part_t *p, int exit ); void part_set_signal( part_t *p, const char *pname, int out, int val ); int part_get_signal( part_t *p, const char *pname ); @@ -75,8 +73,6 @@ parts *parts_alloc( void ); void parts_free( parts_t *ps ); int parts_add_part( parts_t *ps, part_t *p ); void parts_set_instruction( parts_t *ps, const char *iname ); -void parts_shift_instructions( parts_t *ps ); -void parts_shift_data_registers( parts_t *ps ); void parts_print( parts_t *ps, int header ); #endif /* PART_H */ diff --git a/jtag/include/state.h b/jtag/include/state.h index fc98acd8..2ea7f73d 100644 --- a/jtag/include/state.h +++ b/jtag/include/state.h @@ -25,7 +25,9 @@ #ifndef STATE_H #define STATE_H -#define bit(b) (1 << (b)) +#include + +#include "chain.h" #define TAPSTAT_DR bit(0) #define TAPSTAT_IR bit(1) @@ -36,17 +38,17 @@ #define TAPSTAT_PAUSE bit(6) /* to Pause with TMS = 0 */ #define TAPSTAT_RESET bit(7) /* Test-Logic-Reset or unknown state */ -#define Unknown_State (TAPSTAT_RESET) +#define Unknown_State TAPSTAT_RESET #define Test_Logic_Reset (TAPSTAT_RESET | TAPSTAT_IDLE) -#define Run_Test_Idle (TAPSTAT_IDLE) -#define Select_DR_Scan (TAPSTAT_DR) +#define Run_Test_Idle TAPSTAT_IDLE +#define Select_DR_Scan TAPSTAT_DR #define Capture_DR (TAPSTAT_DR | TAPSTAT_SHIFT | TAPSTAT_CAPTURE) #define Shift_DR (TAPSTAT_DR | TAPSTAT_SHIFT) #define Exit1_DR (TAPSTAT_DR | TAPSTAT_UPDATE | TAPSTAT_PAUSE) #define Pause_DR (TAPSTAT_DR | TAPSTAT_PAUSE) #define Exit2_DR (TAPSTAT_DR | TAPSTAT_SHIFT | TAPSTAT_UPDATE) #define Update_DR (TAPSTAT_DR | TAPSTAT_IDLE) -#define Select_IR_Scan (TAPSTAT_IR) +#define Select_IR_Scan TAPSTAT_IR #define Capture_IR (TAPSTAT_IR | TAPSTAT_SHIFT | TAPSTAT_CAPTURE) #define Shift_IR (TAPSTAT_IR | TAPSTAT_SHIFT) #define Exit1_IR (TAPSTAT_IR | TAPSTAT_UPDATE | TAPSTAT_PAUSE) @@ -54,12 +56,11 @@ #define Exit2_IR (TAPSTAT_IR | TAPSTAT_SHIFT | TAPSTAT_UPDATE) #define Update_IR (TAPSTAT_IR | TAPSTAT_IDLE) -int tap_state( void ); -int tap_state_init( void ); -int tap_state_done( void ); -int tap_state_reset( void ); -int tap_state_set_trst( int trst ); -int tap_state_get_trst( void ); -int tap_state_clock( int tms ); +int tap_state( chain_t *chain ); +int tap_state_init( chain_t *chain ); +int tap_state_done( chain_t *chain ); +int tap_state_reset( chain_t *chain ); +int tap_state_set_trst( chain_t *chain, int old_trst, int new_trst ); +int tap_state_clock( chain_t *chain, int tms ); #endif /* STATE_H */ diff --git a/jtag/include/tap.h b/jtag/include/tap.h index 57b50fff..765126d6 100644 --- a/jtag/include/tap.h +++ b/jtag/include/tap.h @@ -25,12 +25,12 @@ #ifndef TAP_H #define TAP_H -#include +#include "register.h" +#include "chain.h" -void tap_reset( void ); -void tap_capture_dr( void ); -void tap_capture_ir( void ); -void tap_shift_register( const tap_register *in, tap_register *out, int exit ); -void write_command( const tap_register *c, tap_register *cout, int len ); +void tap_reset( chain_t *chain ); +void tap_capture_dr( chain_t *chain ); +void tap_capture_ir( chain_t *chain ); +void tap_shift_register( chain_t *chain, const tap_register *in, tap_register *out, int exit ); #endif /* TAP_H */ diff --git a/jtag/po/POTFILES.in b/jtag/po/POTFILES.in index a8b69cdb..e5dbd8d6 100644 --- a/jtag/po/POTFILES.in +++ b/jtag/po/POTFILES.in @@ -2,3 +2,5 @@ src/help.c src/jtag.c +src/tap/chain.c +src/tap/tap.c diff --git a/jtag/src/Makefile.am b/jtag/src/Makefile.am index e0f7184a..36106d2b 100644 --- a/jtag/src/Makefile.am +++ b/jtag/src/Makefile.am @@ -31,10 +31,10 @@ bin_PROGRAMS = jtag jtag_SOURCES = \ jtag.c \ + jtag.h \ detect.c \ discovery.c \ readmem.c \ - detect.h \ cfi.c \ flash.h \ flash.c \ diff --git a/jtag/src/bus/ixp425.c b/jtag/src/bus/ixp425.c index 00ae3174..4a1e5196 100644 --- a/jtag/src/bus/ixp425.c +++ b/jtag/src/bus/ixp425.c @@ -26,6 +26,7 @@ #include "part.h" #include "bus.h" +#include "chain.h" /* IXP425 must be at position 0 in JTAG chain */ @@ -92,9 +93,9 @@ setup_data( part *p, uint32_t d ) } void -ixp425_bus_read_start( parts *ps, uint32_t adr ) +ixp425_bus_read_start( chain_t *chain, uint32_t adr ) { - part *p = ps->parts[0]; + part_t *p = chain->parts->parts[0]; select_flash( p ); part_set_signal( p, "EX_RD", 1, 0 ); @@ -103,16 +104,16 @@ ixp425_bus_read_start( parts *ps, uint32_t adr ) setup_address( p, adr ); set_data_in( p ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); } uint32_t -ixp425_bus_read_next( parts *ps, uint32_t adr ) +ixp425_bus_read_next( chain_t *chain, uint32_t adr ) { - part *p = ps->parts[0]; + part_t *p = chain->parts->parts[0]; setup_address( p, adr ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); { int i; @@ -129,15 +130,15 @@ ixp425_bus_read_next( parts *ps, uint32_t adr ) } uint32_t -ixp425_bus_read_end( parts *ps ) +ixp425_bus_read_end( chain_t *chain ) { - part *p = ps->parts[0]; + part_t *p = chain->parts->parts[0]; unselect_flash( p ); part_set_signal( p, "EX_RD", 1, 1 ); part_set_signal( p, "EX_WR", 1, 1 ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); { int i; @@ -154,16 +155,16 @@ ixp425_bus_read_end( parts *ps ) } uint32_t -ixp425_bus_read( parts *ps, uint32_t adr ) +ixp425_bus_read( chain_t *chain, uint32_t adr ) { - ixp425_bus_read_start( ps, adr ); - return ixp425_bus_read_end( ps ); + ixp425_bus_read_start( chain, adr ); + return ixp425_bus_read_end( chain ); } void -ixp425_bus_write( parts *ps, uint32_t adr, uint32_t data ) +ixp425_bus_write( chain_t *chain, uint32_t adr, uint32_t data ) { - part *p = ps->parts[0]; + part_t *p = chain->parts->parts[0]; select_flash( p ); part_set_signal( p, "EX_RD", 1, 1 ); @@ -171,17 +172,17 @@ ixp425_bus_write( parts *ps, uint32_t adr, uint32_t data ) setup_address( p, adr ); setup_data( p, data ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); part_set_signal( p, "EX_WR", 1, 0 ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); part_set_signal( p, "EX_WR", 1, 1 ); unselect_flash( p ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); } int -ixp425_bus_width( parts *ps ) +ixp425_bus_width( chain_t *chain ) { return 16; } diff --git a/jtag/src/bus/pxa2x0.c b/jtag/src/bus/pxa2x0.c index 3413de73..1aaaab2e 100644 --- a/jtag/src/bus/pxa2x0.c +++ b/jtag/src/bus/pxa2x0.c @@ -70,9 +70,9 @@ setup_data( part *p, uint32_t d ) } void -pxa250_bus_read_start( parts *ps, uint32_t adr ) +pxa250_bus_read_start( chain_t *chain, uint32_t adr ) { - part *p = ps->parts[0]; + part_t *p = chain->parts->parts[0]; /* see Figure 6-13 in [1] */ part_set_signal( p, "nCS[0]", 1, 0 ); @@ -88,17 +88,17 @@ pxa250_bus_read_start( parts *ps, uint32_t adr ) setup_address( p, adr ); set_data_in( p ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); } uint32_t -pxa250_bus_read_next( parts *ps, uint32_t adr ) +pxa250_bus_read_next( chain_t *chain, uint32_t adr ) { - part *p = ps->parts[0]; + part_t *p = chain->parts->parts[0]; /* see Figure 6-13 in [1] */ setup_address( p, adr ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); { int i; @@ -115,16 +115,16 @@ pxa250_bus_read_next( parts *ps, uint32_t adr ) } uint32_t -pxa250_bus_read_end( parts *ps ) +pxa250_bus_read_end( chain_t *chain ) { - part *p = ps->parts[0]; + part_t *p = chain->parts->parts[0]; /* see Figure 6-13 in [1] */ part_set_signal( p, "nCS[0]", 1, 1 ); part_set_signal( p, "nOE", 1, 1 ); part_set_signal( p, "nSDCAS", 1, 1 ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); { int i; @@ -141,17 +141,17 @@ pxa250_bus_read_end( parts *ps ) } uint32_t -pxa250_bus_read( parts *ps, uint32_t adr ) +pxa250_bus_read( chain_t *chain, uint32_t adr ) { - pxa250_bus_read_start( ps, adr ); - return pxa250_bus_read_end( ps ); + pxa250_bus_read_start( chain, adr ); + return pxa250_bus_read_end( chain ); } void -pxa250_bus_write( parts *ps, uint32_t adr, uint32_t data ) +pxa250_bus_write( chain_t *chain, uint32_t adr, uint32_t data ) { /* see Figure 6-17 in [1] */ - part *p = ps->parts[0]; + part_t *p = chain->parts->parts[0]; part_set_signal( p, "nCS[0]", 1, 0 ); part_set_signal( p, "DQM[0]", 1, 0 ); @@ -166,18 +166,18 @@ pxa250_bus_write( parts *ps, uint32_t adr, uint32_t data ) setup_address( p, adr ); setup_data( p, data ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); part_set_signal( p, "nWE", 1, 0 ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); part_set_signal( p, "nWE", 1, 1 ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); } int -pxa250_bus_width( parts *ps ) +pxa250_bus_width( chain_t *chain ) { - part *p = ps->parts[0]; + part_t *p = chain->parts->parts[0]; uint8_t boot_sel = (part_get_signal( p, "BOOT_SEL[2]" ) << 2) | (part_get_signal( p, "BOOT_SEL[1]" ) << 1) | part_get_signal( p, "BOOT_SEL[0]" ); diff --git a/jtag/src/bus/sa1110.c b/jtag/src/bus/sa1110.c index 607f173d..738bfb5b 100644 --- a/jtag/src/bus/sa1110.c +++ b/jtag/src/bus/sa1110.c @@ -30,6 +30,7 @@ #include "part.h" #include "bus.h" +#include "chain.h" /* SA1110 must be at position 0 in JTAG chain */ @@ -70,10 +71,10 @@ setup_data( part *p, uint32_t d ) } static void -sa1110_bus_read_start( parts *ps, uint32_t adr ) +sa1110_bus_read_start( chain_t *chain, uint32_t adr ) { /* see Figure 10-12 in [1] */ - part *p = ps->parts[0]; + part_t *p = chain->parts->parts[0]; part_set_signal( p, "nCS0", 1, (adr >> 27) != 0 ); part_set_signal( p, "nCS1", 1, (adr >> 27) != 1 ); @@ -88,17 +89,17 @@ sa1110_bus_read_start( parts *ps, uint32_t adr ) setup_address( p, adr ); set_data_in( p ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); } static uint32_t -sa1110_bus_read_next( parts *ps, uint32_t adr ) +sa1110_bus_read_next( chain_t *chain, uint32_t adr ) { /* see Figure 10-12 in [1] */ - part *p = ps->parts[0]; + part_t *p = chain->parts->parts[0]; setup_address( p, adr ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); { int i; @@ -115,10 +116,10 @@ sa1110_bus_read_next( parts *ps, uint32_t adr ) } static uint32_t -sa1110_bus_read_end( parts *ps ) +sa1110_bus_read_end( chain_t *chain ) { /* see Figure 10-12 in [1] */ - part *p = ps->parts[0]; + part_t *p = chain->parts->parts[0]; part_set_signal( p, "nCS0", 1, 1 ); part_set_signal( p, "nCS1", 1, 1 ); @@ -127,7 +128,7 @@ sa1110_bus_read_end( parts *ps ) part_set_signal( p, "nCS4", 1, 1 ); part_set_signal( p, "nCS5", 1, 1 ); part_set_signal( p, "nOE", 1, 1 ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); { int i; @@ -144,17 +145,17 @@ sa1110_bus_read_end( parts *ps ) } static uint32_t -sa1110_bus_read( parts *ps, uint32_t adr ) +sa1110_bus_read( chain_t *chain, uint32_t adr ) { - sa1110_bus_read_start( ps, adr ); - return sa1110_bus_read_end( ps ); + sa1110_bus_read_start( chain, adr ); + return sa1110_bus_read_end( chain ); } static void -sa1110_bus_write( parts *ps, uint32_t adr, uint32_t data ) +sa1110_bus_write( chain_t *chain, uint32_t adr, uint32_t data ) { /* see Figure 10-16 in [1] */ - part *p = ps->parts[0]; + part_t *p = chain->parts->parts[0]; part_set_signal( p, "nCS0", 1, (adr >> 27) != 0 ); part_set_signal( p, "nCS1", 1, (adr >> 27) != 1 ); @@ -169,10 +170,10 @@ sa1110_bus_write( parts *ps, uint32_t adr, uint32_t data ) setup_address( p, adr ); setup_data( p, data ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); part_set_signal( p, "nWE", 1, 0 ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); part_set_signal( p, "nWE", 1, 1 ); part_set_signal( p, "nCS0", 1, 1 ); part_set_signal( p, "nCS1", 1, 1 ); @@ -180,13 +181,13 @@ sa1110_bus_write( parts *ps, uint32_t adr, uint32_t data ) part_set_signal( p, "nCS3", 1, 1 ); part_set_signal( p, "nCS4", 1, 1 ); part_set_signal( p, "nCS5", 1, 1 ); - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); } static int -sa1110_bus_width( parts *ps ) +sa1110_bus_width( chain_t *chain ) { - if (part_get_signal( ps->parts[0], "ROM_SEL" )) { + if (part_get_signal( chain->parts->parts[0], "ROM_SEL" )) { printf( "ROM_SEL: 32 bits\n" ); return 32; } else { diff --git a/jtag/src/cfi.c b/jtag/src/cfi.c index c0dffee2..36a8fa35 100644 --- a/jtag/src/cfi.c +++ b/jtag/src/cfi.c @@ -32,42 +32,44 @@ #include #include +#include "jtag.h" #include "bus.h" +#include "chain.h" /* function to cover 2x16 and 1x16 modes */ -#define BW16(x) ( (bus_width(ps) == 16) ? x : ( (x<<16) | x ) ) +#define BW16(x) ( (bus_width(chain) == 16) ? x : ( (x<<16) | x ) ) static uint16_t -read2( parts *ps, uint32_t adr, int o ) +read2( chain_t *chain, uint32_t adr, int o ) { uint16_t r; - bus_read_start( ps, adr << o ); - r = bus_read_next( ps, (adr + 1) << o ); - return ((bus_read_end( ps ) & 0xFF) << 8) | (r & 0xFF); + bus_read_start( chain, adr << o ); + r = bus_read_next( chain, (adr + 1) << o ); + return ((bus_read_end( chain ) & 0xFF) << 8) | (r & 0xFF); } cfi_query_structure_t * -detect_cfi( parts *ps ) +detect_cfi( chain_t *chain ) { cfi_query_structure_t *cfi; int o = 2; uint32_t tmp; - if (bus_width(ps) == 16) + if (bus_width( chain ) == 16) o = 1; /* detect CFI capable devices - see Table 1 in [1] */ - bus_write( ps, CFI_CMD_QUERY_OFFSET << o, BW16(CFI_CMD_QUERY) ); - if (bus_read( ps, CFI_QUERY_ID_OFFSET << o ) != BW16('Q')) { + bus_write( chain, CFI_CMD_QUERY_OFFSET << o, BW16(CFI_CMD_QUERY) ); + if (bus_read( chain, CFI_QUERY_ID_OFFSET << o ) != BW16('Q')) { printf( "No CFI device detected (Q)!\n" ); return NULL; } - if (bus_read( ps, (CFI_QUERY_ID_OFFSET + 1) << o ) != BW16('R')) { + if (bus_read( chain, (CFI_QUERY_ID_OFFSET + 1) << o ) != BW16('R')) { printf( "No CFI device detected (R)!\n" ); return NULL; } - if (bus_read( ps, (CFI_QUERY_ID_OFFSET + 2) << o ) != BW16('Y')) { + if (bus_read( chain, (CFI_QUERY_ID_OFFSET + 2) << o ) != BW16('Y')) { printf( "No CFI device detected (Y)!\n" ); return NULL; } @@ -81,60 +83,60 @@ detect_cfi( parts *ps ) /* TODO: Low chip only (bits 15:0) */ /* Identification string - see Table 6 in [1] */ - cfi->identification_string.pri_id_code = read2( ps, PRI_VENDOR_ID_OFFSET, o ); + cfi->identification_string.pri_id_code = read2( chain, PRI_VENDOR_ID_OFFSET, o ); cfi->identification_string.pri_vendor_tbl = NULL; - cfi->identification_string.alt_id_code = read2( ps, ALT_VENDOR_ID_OFFSET, o ); + cfi->identification_string.alt_id_code = read2( chain, ALT_VENDOR_ID_OFFSET, o ); cfi->identification_string.alt_vendor_tbl = NULL; /* System interface information - see Table 7 in [1] */ - tmp = bus_read( ps, VCC_MIN_WEV_OFFSET << o ); + tmp = bus_read( chain, VCC_MIN_WEV_OFFSET << o ); cfi->system_interface_info.vcc_min_wev = ((tmp >> 4) & 0xF) * 1000 + (tmp & 0xF) * 100; - tmp = bus_read( ps, VCC_MAX_WEV_OFFSET << o ); + tmp = bus_read( chain, VCC_MAX_WEV_OFFSET << o ); cfi->system_interface_info.vcc_max_wev = ((tmp >> 4) & 0xF) * 1000 + (tmp & 0xF) * 100; - tmp = bus_read( ps, VPP_MIN_WEV_OFFSET << o ); + tmp = bus_read( chain, VPP_MIN_WEV_OFFSET << o ); cfi->system_interface_info.vpp_min_wev = ((tmp >> 4) & 0xF) * 1000 + (tmp & 0xF) * 100; - tmp = bus_read( ps, VPP_MAX_WEV_OFFSET << o ); + tmp = bus_read( chain, VPP_MAX_WEV_OFFSET << o ); cfi->system_interface_info.vpp_max_wev = ((tmp >> 4) & 0xF) * 1000 + (tmp & 0xF) * 100; /* TODO: Add out of range checks for timeouts */ - tmp = bus_read( ps, TYP_SINGLE_WRITE_TIMEOUT_OFFSET << o ) & 0xFF; + tmp = bus_read( chain, TYP_SINGLE_WRITE_TIMEOUT_OFFSET << o ) & 0xFF; cfi->system_interface_info.typ_single_write_timeout = tmp ? (1 << tmp) : 0; - tmp = bus_read( ps, TYP_BUFFER_WRITE_TIMEOUT_OFFSET << o ) & 0xFF; + tmp = bus_read( chain, TYP_BUFFER_WRITE_TIMEOUT_OFFSET << o ) & 0xFF; cfi->system_interface_info.typ_buffer_write_timeout = tmp ? (1 << tmp) : 0; - tmp = bus_read( ps, TYP_BLOCK_ERASE_TIMEOUT_OFFSET << o ) & 0xFF; + tmp = bus_read( chain, TYP_BLOCK_ERASE_TIMEOUT_OFFSET << o ) & 0xFF; cfi->system_interface_info.typ_block_erase_timeout = tmp ? (1 << tmp) : 0; - tmp = bus_read( ps, TYP_CHIP_ERASE_TIMEOUT_OFFSET << o ) & 0xFF; + tmp = bus_read( chain, TYP_CHIP_ERASE_TIMEOUT_OFFSET << o ) & 0xFF; cfi->system_interface_info.typ_chip_erase_timeout = tmp ? (1 << tmp) : 0; - tmp = bus_read( ps, MAX_SINGLE_WRITE_TIMEOUT_OFFSET << o ) & 0xFF; + tmp = bus_read( chain, MAX_SINGLE_WRITE_TIMEOUT_OFFSET << o ) & 0xFF; cfi->system_interface_info.max_single_write_timeout = (tmp ? (1 << tmp) : 0) * cfi->system_interface_info.typ_single_write_timeout; - tmp = bus_read( ps, MAX_BUFFER_WRITE_TIMEOUT_OFFSET << o ) & 0xFF; + tmp = bus_read( chain, MAX_BUFFER_WRITE_TIMEOUT_OFFSET << o ) & 0xFF; cfi->system_interface_info.max_buffer_write_timeout = (tmp ? (1 << tmp) : 0) * cfi->system_interface_info.typ_buffer_write_timeout; - tmp = bus_read( ps, MAX_BLOCK_ERASE_TIMEOUT_OFFSET << o ) & 0xFF; + tmp = bus_read( chain, MAX_BLOCK_ERASE_TIMEOUT_OFFSET << o ) & 0xFF; cfi->system_interface_info.max_block_erase_timeout = (tmp ? (1 << tmp) : 0) * cfi->system_interface_info.typ_block_erase_timeout; - tmp = bus_read( ps, MAX_CHIP_ERASE_TIMEOUT_OFFSET << o ) & 0xFF; + tmp = bus_read( chain, MAX_CHIP_ERASE_TIMEOUT_OFFSET << o ) & 0xFF; cfi->system_interface_info.max_chip_erase_timeout = (tmp ? (1 << tmp) : 0) * cfi->system_interface_info.typ_chip_erase_timeout; /* Device geometry - see Table 8 in [1] */ /* TODO: Add out of range check */ - cfi->device_geometry.device_size = 1 << (bus_read( ps, DEVICE_SIZE_OFFSET << o ) & 0xFF); + cfi->device_geometry.device_size = 1 << (bus_read( chain, DEVICE_SIZE_OFFSET << o ) & 0xFF); - cfi->device_geometry.device_interface = read2( ps, FLASH_DEVICE_INTERFACE_OFFSET, o ); + cfi->device_geometry.device_interface = read2( chain, FLASH_DEVICE_INTERFACE_OFFSET, o ); /* TODO: Add out of range check */ - cfi->device_geometry.max_bytes_write = 1 << read2( ps, MAX_BYTES_WRITE_OFFSET, o ); + cfi->device_geometry.max_bytes_write = 1 << read2( chain, MAX_BYTES_WRITE_OFFSET, o ); - tmp = bus_read( ps, NUMBER_OF_ERASE_REGIONS_OFFSET << o ) & 0xFF; + tmp = bus_read( chain, NUMBER_OF_ERASE_REGIONS_OFFSET << o ) & 0xFF; cfi->device_geometry.number_of_erase_regions = tmp; cfi->device_geometry.erase_block_regions = malloc( tmp * sizeof (cfi_erase_block_region_t) ); @@ -148,8 +150,8 @@ detect_cfi( parts *ps ) int i; for (i = 0, a = ERASE_BLOCK_REGION_OFFSET; i < tmp; i++, a += 4) { - uint32_t y = read2( ps, a, o ); - uint32_t z = read2( ps, a + 2, o ) << 8; + uint32_t y = read2( chain, a, o ); + uint32_t z = read2( chain, a + 2, o ) << 8; if (z == 0) z = 128; cfi->device_geometry.erase_block_regions[i].erase_block_size = z; @@ -160,7 +162,7 @@ detect_cfi( parts *ps ) /* TODO: Intel Primary Algorithm Extended Query Table - see Table 5. in [2] */ /* Read Array */ - bus_write( ps, 0, (CFI_CMD_READ_ARRAY1 << 16) | CFI_CMD_READ_ARRAY1 ); + bus_write( chain, 0, (CFI_CMD_READ_ARRAY1 << 16) | CFI_CMD_READ_ARRAY1 ); return cfi; } diff --git a/jtag/src/detect.c b/jtag/src/detect.c index cebba85c..44fca20a 100644 --- a/jtag/src/detect.c +++ b/jtag/src/detect.c @@ -31,8 +31,9 @@ #include "tap.h" #include "cable.h" #include "part.h" +#include "chain.h" -#include "detect.h" +#include "jtag.h" struct id_record { char name[20]; @@ -156,7 +157,7 @@ find_record( char *filename, tap_register *key, struct id_record *idr ) } parts * -detect_parts( char *db_path ) +detect_parts( chain_t *chain, char *db_path ) { char data_path[1024]; char manufacturer[MAXLEN_MANUFACTURER + 1]; @@ -178,9 +179,9 @@ detect_parts( char *db_path ) return NULL; } - tap_reset(); + tap_reset( chain ); - tap_capture_dr(); + tap_capture_dr( chain ); for (;;) { tap_register *key; struct id_record idr; @@ -188,7 +189,7 @@ detect_parts( char *db_path ) FILE *f; part *part; - tap_shift_register( zeros, id, 0 ); + tap_shift_register( chain, zeros, id, 0 ); if (!register_compare( id, zeros )) break; /* end of chain */ @@ -292,8 +293,8 @@ detect_parts( char *db_path ) fclose( f ); } - tap_clock( 1, 0 ); /* Exit1-DR */ - tap_clock( 1, 0 ); /* Update-DR */ + chain_clock( chain, 1, 0 ); /* Exit1-DR */ + chain_clock( chain, 1, 0 ); /* Update-DR */ register_free( zeros ); register_free( ones ); diff --git a/jtag/src/discovery.c b/jtag/src/discovery.c index 8e45ba88..f025eb1e 100644 --- a/jtag/src/discovery.c +++ b/jtag/src/discovery.c @@ -32,6 +32,9 @@ #include "cable.h" #include "tap.h" +#include "chain.h" + +#include "jtag.h" #define DETECT_PATTERN_SIZE 8 #define MAX_REGISTER_LENGTH 1024 @@ -39,7 +42,7 @@ #define TEST_THRESHOLD 100 /* in % */ static int -detect_register_size( FILE *f ) +detect_register_size( chain_t *chain, FILE *f ) { int len; tap_register *rz; @@ -67,8 +70,8 @@ detect_register_size( FILE *f ) fprintf( f, "\t\tPattern: %s, ", s - DETECT_PATTERN_SIZE ); for (i = 0; i < TEST_COUNT; i++) { - tap_shift_register( rz, NULL, 0 ); - tap_shift_register( rpat, rout, 0 ); + tap_shift_register( chain, rz, NULL, 0 ); + tap_shift_register( chain, rpat, rout, 0 ); register_shift_right( rout, len ); @@ -96,20 +99,20 @@ detect_register_size( FILE *f ) } static void -jtag_reset( void ) +jtag_reset( chain_t *chain ) { - tap_set_trst( 0 ); + chain_set_trst( chain, 0 ); sleep( 1 ); - tap_set_trst( 1 ); + chain_set_trst( chain, 1 ); sleep( 1 ); - tap_reset(); + tap_reset( chain ); } #define MAX_CHAIN_LENGTH 128 void -discovery( const char *filename ) +discovery( chain_t *chain, const char *filename ) { int i; int irlen; @@ -138,11 +141,11 @@ discovery( const char *filename ) printf( "Detecting JTAG chain length:\n" ); fprintf( f, "Detecting JTAG chain length:\n" ); - jtag_reset(); + jtag_reset( chain ); - tap_capture_dr(); + tap_capture_dr( chain ); for (i = 0; i < MAX_CHAIN_LENGTH; i++) { - tap_shift_register( zeros, id, 0 ); + tap_shift_register( chain, zeros, id, 0 ); if (!register_compare( id, zeros )) break; /* end of chain */ @@ -169,13 +172,13 @@ discovery( const char *filename ) } /* detecting IR size */ - jtag_reset(); + jtag_reset( chain ); printf( "Detecting IR size...\n" ); fprintf( f, "Detecting IR size:\n" ); - tap_capture_ir(); - irlen = detect_register_size( f ); + tap_capture_ir( chain ); + irlen = detect_register_size( chain, f ); printf( "IR length is %d\n\n", irlen ); fprintf( f, "IR length is %d\n\n", irlen ); @@ -200,16 +203,16 @@ discovery( const char *filename ) for (;;) { int rs; - jtag_reset(); + jtag_reset( chain ); - tap_capture_ir(); - tap_shift_register( ir, NULL, 1 ); + tap_capture_ir( chain ); + tap_shift_register( chain, ir, NULL, 1 ); printf( "Detecting DR size for IR %s ...\n", register_get_string( ir ) ); fprintf( f, "Detecting DR size for IR %s:\n", register_get_string( ir ) ); - tap_capture_dr(); - rs = detect_register_size( f ); + tap_capture_dr( chain ); + rs = detect_register_size( chain, f ); printf( "DR length for IR %s is %d\n\n", register_get_string( ir ), rs ); fprintf( f, "DR length for IR %s is %d\n\n", register_get_string( ir ), rs ); diff --git a/jtag/src/flash-amd.c b/jtag/src/flash-amd.c index 48889c16..3b68a9d1 100644 --- a/jtag/src/flash-amd.c +++ b/jtag/src/flash-amd.c @@ -37,17 +37,18 @@ #include #include "flash.h" +#include "chain.h" static int dbg = 0; -static int amd_flash_erase_block( parts *ps, uint32_t adr ); -static int amd_flash_unlock_block( parts *ps, uint32_t adr ); -static int amd_flash_program( parts *ps, uint32_t adr, uint32_t data ); -static void amd_flash_read_array( parts *ps); +static int amd_flash_erase_block( chain_t *chain, uint32_t adr ); +static int amd_flash_unlock_block( chain_t *chain, uint32_t adr ); +static int amd_flash_program( chain_t *chain, uint32_t adr, uint32_t data ); +static void amd_flash_read_array( chain_t *chain ); /* autodetect, we can handle this chip */ static int -amd_flash_autodetect( parts *ps, cfi_query_structure_t *cfi ) +amd_flash_autodetect( chain_t *chain, cfi_query_structure_t *cfi ) { return (cfi->identification_string.pri_id_code == CFI_VENDOR_AMD_SCS); } @@ -96,15 +97,15 @@ amdstatus29( parts *ps, uint32_t adr, uint32_t data ) * second implementation: see [1], page 30 */ static int -amdstatus( parts *ps, uint32_t adr, int data ) +amdstatus( chain_t *chain, uint32_t adr, int data ) { int timeout; uint32_t togglemask = ((1 << 6) << 16) + (1 << 6); /* DQ 6 */ /* int dq5mask = ((1 << 5) << 16) + (1 << 5); DQ5 */ for (timeout = 0; timeout < 100; timeout++) { - uint32_t data1 = bus_read( ps, adr ); - uint32_t data2 = bus_read( ps, adr ); + uint32_t data1 = bus_read( chain, adr ); + uint32_t data2 = bus_read( chain, adr ); /*printf("amdstatus %d: %04X/%04X %04X/%04X \n", */ /* timeout, data1, data2, (data1 & togglemask), (data2 & togglemask)); */ @@ -142,17 +143,17 @@ amdisprotected( parts *ps, uint32_t adr ) #endif /* 0 */ static void -amd_flash_print_info( parts *ps ) +amd_flash_print_info( chain_t *chain ) { int o = 2; int mid, cid, prot; - bus_write( ps, 0x0555 << o, 0x00aa00aa ); /* autoselect p29 */ - bus_write( ps, 0x02aa << o, 0x00550055 ); - bus_write( ps, 0x0555 << o, 0x00900090 ); - mid = bus_read( ps, 0x00 << o ) & 0xFFFF; - cid = bus_read( ps, 0x01 << o ) & 0xFFFF; - prot = bus_read( ps, 0x02 << o ) & 0xFF; - amd_flash_read_array(ps); /* AMD reset */ + bus_write( chain, 0x0555 << o, 0x00aa00aa ); /* autoselect p29 */ + bus_write( chain, 0x02aa << o, 0x00550055 ); + bus_write( chain, 0x0555 << o, 0x00900090 ); + mid = bus_read( chain, 0x00 << o ) & 0xFFFF; + cid = bus_read( chain, 0x01 << o ) & 0xFFFF; + prot = bus_read( chain, 0x02 << o ) & 0xFF; + amd_flash_read_array( chain ); /* AMD reset */ printf( "Chip: AMD Flash\n\tManufacturer: " ); switch (mid) { case 0x0001: @@ -175,7 +176,7 @@ amd_flash_print_info( parts *ps ) } static int -amd_flash_erase_block( parts *ps, uint32_t adr ) +amd_flash_erase_block( chain_t *chain, uint32_t adr ) { int o = 2; @@ -183,34 +184,34 @@ amd_flash_erase_block( parts *ps, uint32_t adr ) /* printf("protected: %d\n", amdisprotected(ps, adr)); */ - bus_write( ps, 0x0555 << o, 0x00aa00aa ); /* autoselect p29, sector erase */ - bus_write( ps, 0x02aa << o, 0x00550055 ); - bus_write( ps, 0x0555 << o, 0x00800080 ); - bus_write( ps, 0x0555 << o, 0x00aa00aa ); - bus_write( ps, 0x02aa << o, 0x00550055 ); - bus_write( ps, adr, 0x00300030 ); + bus_write( chain, 0x0555 << o, 0x00aa00aa ); /* autoselect p29, sector erase */ + bus_write( chain, 0x02aa << o, 0x00550055 ); + bus_write( chain, 0x0555 << o, 0x00800080 ); + bus_write( chain, 0x0555 << o, 0x00aa00aa ); + bus_write( chain, 0x02aa << o, 0x00550055 ); + bus_write( chain, adr, 0x00300030 ); - if (amdstatus(ps, adr, 0xffff)) { + if (amdstatus( chain, adr, 0xffff )) { printf( "flash_erase_block 0x%08X DONE\n", adr ); - amd_flash_read_array( ps ); /* AMD reset */ + amd_flash_read_array( chain ); /* AMD reset */ return 0; } printf( "flash_erase_block 0x%08X FAILED\n", adr ); /* Read Array */ - amd_flash_read_array( ps ); /* AMD reset */ + amd_flash_read_array( chain ); /* AMD reset */ return CFI_INTEL_ERROR_UNKNOWN; } static int -amd_flash_unlock_block( parts *ps, uint32_t adr ) +amd_flash_unlock_block( chain_t *chain, uint32_t adr ) { printf( "flash_unlock_block 0x%08X IGNORE\n", adr ); return 0; } static int -amd_flash_program( parts *ps, uint32_t adr, uint32_t data ) +amd_flash_program( chain_t *chain, uint32_t adr, uint32_t data ) { int o = 2; int status; @@ -218,22 +219,22 @@ amd_flash_program( parts *ps, uint32_t adr, uint32_t data ) if (dbg) printf("\nflash_program 0x%08X = 0x%08X\n", adr, data); - bus_write( ps, 0x0555 << o, 0x00aa00aa ); /* autoselect p29, program */ - bus_write( ps, 0x02aa << o, 0x00550055 ); - bus_write( ps, 0x0555 << o, 0x00A000A0 ); + bus_write( chain, 0x0555 << o, 0x00aa00aa ); /* autoselect p29, program */ + bus_write( chain, 0x02aa << o, 0x00550055 ); + bus_write( chain, 0x0555 << o, 0x00A000A0 ); - bus_write( ps, adr, data ); - status = amdstatus( ps, adr, data ); + bus_write( chain, adr, data ); + status = amdstatus( chain, adr, data ); /* amd_flash_read_array(ps); */ return !status; } static void -amd_flash_read_array( parts *ps) +amd_flash_read_array( chain_t *chain ) { /* Read Array */ - bus_write( ps, 0x0, 0x00F000F0 ); /* AMD reset */ + bus_write( chain, 0x0, 0x00F000F0 ); /* AMD reset */ } flash_driver_t amd_32_flash_driver = { diff --git a/jtag/src/flash-intel.c b/jtag/src/flash-intel.c index efc3c0ab..534cdb8a 100644 --- a/jtag/src/flash-intel.c +++ b/jtag/src/flash-intel.c @@ -41,33 +41,34 @@ #include #include "flash.h" +#include "chain.h" -static int intel_flash_erase_block( parts *ps, uint32_t adr ); -static int intel_flash_unlock_block( parts *ps, uint32_t adr ); -static int intel_flash_program( parts *ps, uint32_t adr, uint32_t data ); -static int intel_flash_erase_block32( parts *ps, uint32_t adr ); -static int intel_flash_unlock_block32( parts *ps, uint32_t adr ); -static int intel_flash_program32( parts *ps, uint32_t adr, uint32_t data ); +static int intel_flash_erase_block( chain_t *chain, uint32_t adr ); +static int intel_flash_unlock_block( chain_t *chain, uint32_t adr ); +static int intel_flash_program( chain_t *chain, uint32_t adr, uint32_t data ); +static int intel_flash_erase_block32( chain_t *chain, uint32_t adr ); +static int intel_flash_unlock_block32( chain_t *chain, uint32_t adr ); +static int intel_flash_program32( chain_t *chain, uint32_t adr, uint32_t data ); /* autodetect, we can handle this chip */ static int -intel_flash_autodetect32( parts *ps, cfi_query_structure_t *cfi ) +intel_flash_autodetect32( chain_t *chain, cfi_query_structure_t *cfi ) { - return (cfi->identification_string.pri_id_code == CFI_VENDOR_INTEL_ECS) && (bus_width( ps ) == 32); + return (cfi->identification_string.pri_id_code == CFI_VENDOR_INTEL_ECS) && (bus_width( chain ) == 32); } static int -intel_flash_autodetect( parts *ps, cfi_query_structure_t *cfi ) +intel_flash_autodetect( chain_t *chain, cfi_query_structure_t *cfi ) { - return (cfi->identification_string.pri_id_code == CFI_VENDOR_INTEL_ECS) && (bus_width( ps ) == 16); + return (cfi->identification_string.pri_id_code == CFI_VENDOR_INTEL_ECS) && (bus_width( chain ) == 16); } static -void _intel_flash_print_info( parts *ps, int o ) +void _intel_flash_print_info( chain_t *chain, int o ) { uint32_t mid, cid; - mid = (bus_read( ps, 0x00 << o ) & 0xFF); + mid = (bus_read( chain, 0x00 << o ) & 0xFF); switch (mid) { case STD_MIC_INTEL: printf( "Manufacturer: %s\n", STD_MICN_INTEL ); @@ -78,7 +79,7 @@ void _intel_flash_print_info( parts *ps, int o ) } printf( "Chip: " ); - cid = (bus_read( ps, 0x01 << o ) & 0xFFFF); + cid = (bus_read( chain, 0x01 << o ) & 0xFFFF); switch (cid) { case 0x0016: printf( "28F320J3A\n" ); @@ -113,51 +114,51 @@ void _intel_flash_print_info( parts *ps, int o ) } /* Read Array */ - bus_write( ps, 0 << o, 0x00FF00FF ); + bus_write( chain, 0 << o, 0x00FF00FF ); } static -void intel_flash_print_info( parts *ps ) +void intel_flash_print_info( chain_t *chain ) { int o = 1; /* Intel Primary Algorithm Extended Query Table - see Table 5. in [3] */ /* TODO */ /* Clear Status Register */ - bus_write( ps, 0 << o, 0x0050 ); + bus_write( chain, 0 << o, 0x0050 ); /* Read Identifier Command */ - bus_write( ps, 0 << 0, 0x0090 ); + bus_write( chain, 0 << 0, 0x0090 ); - _intel_flash_print_info( ps, o ); + _intel_flash_print_info( chain, o ); } static -void intel_flash_print_info32( parts *ps ) +void intel_flash_print_info32( chain_t *chain ) { int o = 2; /* Intel Primary Algorithm Extended Query Table - see Table 5. in [3] */ /* TODO */ /* Clear Status Register */ - bus_write( ps, 0 << o, 0x00500050 ); + bus_write( chain, 0 << o, 0x00500050 ); /* Read Identifier Command */ - bus_write( ps, 0 << 0, 0x00900090 ); + bus_write( chain, 0 << 0, 0x00900090 ); - _intel_flash_print_info( ps, o ); + _intel_flash_print_info( chain, o ); } static int -intel_flash_erase_block( parts *ps, uint32_t adr ) +intel_flash_erase_block( chain_t *chain, uint32_t adr ) { uint16_t sr; - bus_write( ps, 0, CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); - bus_write( ps, adr, CFI_INTEL_CMD_BLOCK_ERASE ); - bus_write( ps, adr, CFI_INTEL_CMD_CONFIRM ); + bus_write( chain, 0, CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); + bus_write( chain, adr, CFI_INTEL_CMD_BLOCK_ERASE ); + bus_write( chain, adr, CFI_INTEL_CMD_CONFIRM ); - while (!((sr = bus_read( ps, 0 ) & 0xFE) & CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ + while (!((sr = bus_read( chain, 0 ) & 0xFE) & CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ switch (sr & ~CFI_INTEL_SR_READY) { case 0: @@ -179,15 +180,15 @@ intel_flash_erase_block( parts *ps, uint32_t adr ) } static int -intel_flash_unlock_block( parts *ps, uint32_t adr ) +intel_flash_unlock_block( chain_t *chain, uint32_t adr ) { uint16_t sr; - bus_write( ps, 0, CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); - bus_write( ps, adr, CFI_INTEL_CMD_LOCK_SETUP ); - bus_write( ps, adr, CFI_INTEL_CMD_UNLOCK_BLOCK ); + bus_write( chain, 0, CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); + bus_write( chain, adr, CFI_INTEL_CMD_LOCK_SETUP ); + bus_write( chain, adr, CFI_INTEL_CMD_UNLOCK_BLOCK ); - while (!((sr = bus_read( ps, 0 ) & 0xFE) & CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ + while (!((sr = bus_read( chain, 0 ) & 0xFE) & CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ if (sr != CFI_INTEL_SR_READY) { printf("flash: unknown error while unblocking\n"); @@ -197,15 +198,15 @@ intel_flash_unlock_block( parts *ps, uint32_t adr ) } static int -intel_flash_program( parts *ps, uint32_t adr, uint32_t data ) +intel_flash_program( chain_t *chain, uint32_t adr, uint32_t data ) { uint16_t sr; - bus_write( ps, 0, CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); - bus_write( ps, adr, CFI_INTEL_CMD_PROGRAM1 ); - bus_write( ps, adr, data ); + bus_write( chain, 0, CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); + bus_write( chain, adr, CFI_INTEL_CMD_PROGRAM1 ); + bus_write( chain, adr, data ); - while (!((sr = bus_read( ps, 0 ) & 0xFE) & CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ + while (!((sr = bus_read( chain, 0 ) & 0xFE) & CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ if (sr != CFI_INTEL_SR_READY) { printf("flash: unknown error while programming\n"); @@ -215,15 +216,15 @@ intel_flash_program( parts *ps, uint32_t adr, uint32_t data ) } static int -intel_flash_erase_block32( parts *ps, uint32_t adr ) +intel_flash_erase_block32( chain_t *chain, uint32_t adr ) { uint32_t sr; - bus_write( ps, 0, (CFI_INTEL_CMD_CLEAR_STATUS_REGISTER << 16) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); - bus_write( ps, adr, (CFI_INTEL_CMD_BLOCK_ERASE << 16) | CFI_INTEL_CMD_BLOCK_ERASE ); - bus_write( ps, adr, (CFI_INTEL_CMD_CONFIRM << 16) | CFI_INTEL_CMD_CONFIRM ); + bus_write( chain, 0, (CFI_INTEL_CMD_CLEAR_STATUS_REGISTER << 16) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); + bus_write( chain, adr, (CFI_INTEL_CMD_BLOCK_ERASE << 16) | CFI_INTEL_CMD_BLOCK_ERASE ); + bus_write( chain, adr, (CFI_INTEL_CMD_CONFIRM << 16) | CFI_INTEL_CMD_CONFIRM ); - while (((sr = bus_read( ps, 0 ) & 0x00FE00FE) & ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ + while (((sr = bus_read( chain, 0 ) & 0x00FE00FE) & ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ if (sr != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) { printf( "\nsr = 0x%08X\n", sr ); @@ -233,15 +234,15 @@ intel_flash_erase_block32( parts *ps, uint32_t adr ) } static int -intel_flash_unlock_block32( parts *ps, uint32_t adr ) +intel_flash_unlock_block32( chain_t *chain, uint32_t adr ) { uint32_t sr; - bus_write( ps, 0, (CFI_INTEL_CMD_CLEAR_STATUS_REGISTER << 16) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); - bus_write( ps, adr, (CFI_INTEL_CMD_LOCK_SETUP << 16) | CFI_INTEL_CMD_LOCK_SETUP ); - bus_write( ps, adr, (CFI_INTEL_CMD_UNLOCK_BLOCK << 16) | CFI_INTEL_CMD_UNLOCK_BLOCK ); + bus_write( chain, 0, (CFI_INTEL_CMD_CLEAR_STATUS_REGISTER << 16) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); + bus_write( chain, adr, (CFI_INTEL_CMD_LOCK_SETUP << 16) | CFI_INTEL_CMD_LOCK_SETUP ); + bus_write( chain, adr, (CFI_INTEL_CMD_UNLOCK_BLOCK << 16) | CFI_INTEL_CMD_UNLOCK_BLOCK ); - while (((sr = bus_read( ps, 0 ) & 0x00FE00FE) & ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ + while (((sr = bus_read( chain, 0 ) & 0x00FE00FE) & ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ if (sr != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) { printf( "\nsr = 0x%08X\n", sr ); @@ -251,15 +252,15 @@ intel_flash_unlock_block32( parts *ps, uint32_t adr ) } static int -intel_flash_program32( parts *ps, uint32_t adr, uint32_t data ) +intel_flash_program32( chain_t *chain, uint32_t adr, uint32_t data ) { uint32_t sr; - bus_write( ps, 0, (CFI_INTEL_CMD_CLEAR_STATUS_REGISTER << 16) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); - bus_write( ps, adr, (CFI_INTEL_CMD_PROGRAM1 << 16) | CFI_INTEL_CMD_PROGRAM1 ); - bus_write( ps, adr, data ); + bus_write( chain, 0, (CFI_INTEL_CMD_CLEAR_STATUS_REGISTER << 16) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); + bus_write( chain, adr, (CFI_INTEL_CMD_PROGRAM1 << 16) | CFI_INTEL_CMD_PROGRAM1 ); + bus_write( chain, adr, data ); - while (((sr = bus_read( ps, 0 ) & 0x00FE00FE) & ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ + while (((sr = bus_read( chain, 0 ) & 0x00FE00FE) & ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ if (sr != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) { printf( "\nsr = 0x%08X\n", sr ); @@ -269,17 +270,17 @@ intel_flash_program32( parts *ps, uint32_t adr, uint32_t data ) } static void -intel_flash_readarray32( parts *ps ) +intel_flash_readarray32( chain_t *chain ) { /* Read Array */ - bus_write( ps, 0, 0x00FF00FF ); + bus_write( chain, 0, 0x00FF00FF ); } static void -intel_flash_readarray( parts *ps ) +intel_flash_readarray( chain_t *chain ) { /* Read Array */ - bus_write( ps, 0, 0x00FF00FF ); + bus_write( chain, 0, 0x00FF00FF ); } flash_driver_t intel_32_flash_driver = { diff --git a/jtag/src/flash.c b/jtag/src/flash.c index a9ff1403..aaea1fa8 100644 --- a/jtag/src/flash.c +++ b/jtag/src/flash.c @@ -45,6 +45,8 @@ #include "bus.h" #include "flash.h" +#include "jtag.h" + extern flash_driver_t amd_32_flash_driver; extern flash_driver_t intel_32_flash_driver; extern flash_driver_t intel_16_flash_driver; @@ -59,13 +61,13 @@ flash_driver_t *flash_drivers[] = { flash_driver_t *flash_driver = NULL; void -set_flash_driver( parts *ps, cfi_query_structure_t *cfi ) +set_flash_driver( chain_t *chain, cfi_query_structure_t *cfi ) { int i; flash_driver = NULL; for (i = 0; flash_drivers[i] != NULL; i++) - if (flash_drivers[i]->flash_autodetect( ps, cfi )) { + if (flash_drivers[i]->flash_autodetect( chain, cfi )) { flash_driver = flash_drivers[i]; return; } @@ -76,16 +78,17 @@ set_flash_driver( parts *ps, cfi_query_structure_t *cfi ) } /* check for flashmem - set driver */ -void -flashcheck( parts *ps, cfi_query_structure_t **cfi ) +static void +flashcheck( chain_t *chain, cfi_query_structure_t **cfi ) { + parts_t *ps = chain->parts; part *p = ps->parts[0]; int o = 0; flash_driver = NULL; printf( "Note: Supported configuration is 2 x 16 bit or 1 x 16 bit only\n" ); - switch (bus_width( ps )) { + switch (bus_width( chain )) { case 16: o = 1; break; @@ -99,28 +102,29 @@ flashcheck( parts *ps, cfi_query_structure_t **cfi ) /* EXTEST */ part_set_instruction( p, "EXTEST" ); - parts_shift_instructions( ps ); + chain_shift_instructions( chain ); - *cfi = detect_cfi( ps ); + *cfi = detect_cfi( chain ); if (!*cfi) { printf( "Flash not found!\n" ); return; } - set_flash_driver( ps, *cfi ); + set_flash_driver( chain, *cfi ); if (!flash_driver) { printf( "Flash not supported!\n" ); return; } - flash_driver->flash_print_info( ps ); + flash_driver->flash_print_info( chain ); } void -flashmsbin( parts *ps, FILE *f ) +flashmsbin( chain_t *chain, FILE *f ) { + parts_t *ps = chain->parts; uint32_t adr; cfi_query_structure_t *cfi = 0; - flashcheck( ps, &cfi ); + flashcheck( chain, &cfi ); if (!cfi || !flash_driver) { printf( "no flash driver found\n" ); return; @@ -149,9 +153,9 @@ flashmsbin( parts *ps, FILE *f ) last = (start + len - 1) / (cfi->device_geometry.erase_block_regions[0].erase_block_size * 2); for (; first <= last; first++) { adr = first * cfi->device_geometry.erase_block_regions[0].erase_block_size * 2; - flash_unlock_block( ps, adr ); + flash_unlock_block( chain, adr ); printf( "block %d unlocked\n", first ); - printf( "erasing block %d: %d\n", first, flash_erase_block( ps, adr ) ); + printf( "erasing block %d: %d\n", first, flash_erase_block( chain, adr ) ); } } @@ -180,7 +184,7 @@ flashmsbin( parts *ps, FILE *f ) printf( "addr: 0x%08X\r", a ); fflush(stdout); fread( &data, sizeof data, 1, f ); - if (flash_program( ps, a, data )) { + if (flash_program( chain, a, data )) { printf( "\nflash error\n" ); return; } @@ -190,7 +194,7 @@ flashmsbin( parts *ps, FILE *f ) } printf( "\n" ); - flash_readarray(ps); + flash_readarray( chain ); fseek( f, 15, SEEK_SET ); printf( "verify:\n" ); @@ -219,7 +223,7 @@ flashmsbin( parts *ps, FILE *f ) printf( "addr: 0x%08X\r", a ); fflush( stdout ); fread( &data, sizeof data, 1, f ); - readed = bus_read( ps, a ); + readed = bus_read( chain, a ); if (data != readed) { printf( "\nverify error: 0x%08X vs. 0x%08X at addr %08X\n", readed, data, a ); @@ -233,20 +237,21 @@ flashmsbin( parts *ps, FILE *f ) /* BYPASS */ parts_set_instruction( ps, "BYPASS" ); - parts_shift_instructions( ps ); + chain_shift_instructions( chain ); printf( "Done.\n" ); } void -flashmem( parts *ps, FILE *f, uint32_t addr ) +flashmem( chain_t *chain, FILE *f, uint32_t addr ) { + parts_t *ps = chain->parts; uint32_t adr; cfi_query_structure_t *cfi = NULL; int *erased; int i; - flashcheck( ps, &cfi ); + flashcheck( chain, &cfi ); if (!cfi || !flash_driver) { printf( "no flash driver found\n" ); return; @@ -270,9 +275,9 @@ flashmem( parts *ps, FILE *f, uint32_t addr ) int block_no = adr / (cfi->device_geometry.erase_block_regions[0].erase_block_size * flash_driver->buswidth / 2); if (!erased[block_no]) { - flash_unlock_block( ps, adr ); + flash_unlock_block( chain, adr ); printf( "\nblock %d unlocked\n", block_no ); - printf( "erasing block %d: %d\n", block_no, flash_erase_block( ps, adr ) ); + printf( "erasing block %d: %d\n", block_no, flash_erase_block( chain, adr ) ); erased[block_no] = 1; } @@ -284,7 +289,7 @@ flashmem( parts *ps, FILE *f, uint32_t addr ) data = htons( *((uint16_t *) &b[bc]) ); else data = * ((uint32_t *) &b[bc]); - if (flash_program( ps, adr, data )) { + if (flash_program( chain, adr, data )) { printf( "\nflash error\n" ); return; } @@ -293,7 +298,7 @@ flashmem( parts *ps, FILE *f, uint32_t addr ) } printf( "\n" ); - flash_readarray( ps ); + flash_readarray( chain ); if (flash_driver->buswidth == 4) { /* TODO: not available in 1 x 16 bit mode */ fseek( f, 0, SEEK_SET ); @@ -313,7 +318,7 @@ flashmem( parts *ps, FILE *f, uint32_t addr ) printf( "addr: 0x%08X\r", adr ); fflush( stdout ); - readed = bus_read( ps, adr ); + readed = bus_read( chain, adr ); if (data != readed) { printf( "\nverify error:\nreaded: 0x%08X\nexpected: 0x%08X\n", readed, data ); return; @@ -326,7 +331,7 @@ flashmem( parts *ps, FILE *f, uint32_t addr ) /* BYPASS */ parts_set_instruction( ps, "BYPASS" ); - parts_shift_instructions( ps ); + chain_shift_instructions( chain ); free( erased ); } diff --git a/jtag/src/flash.h b/jtag/src/flash.h index ca573980..9889486c 100644 --- a/jtag/src/flash.h +++ b/jtag/src/flash.h @@ -27,23 +27,22 @@ #define FLASH_H #include -#include "part.h" -#include "bus.h" #include -/* from cfi.c */ -cfi_query_structure_t *detect_cfi( parts *ps ); +#include "part.h" +#include "bus.h" +#include "chain.h" typedef struct { int buswidth; /* supported bus width, 1/2/4 bytes */ const char *name; const char *description; - int (*flash_autodetect)( parts *ps, cfi_query_structure_t * ); - void (*flash_print_info)( parts *ps ); - int (*flash_erase_block)( parts *ps, uint32_t adr ); - int (*flash_unlock_block)( parts *ps, uint32_t adr ); - int (*flash_program)( parts *ps, uint32_t adr, uint32_t data ); - void (*flash_readarray)( parts *ps ); + int (*flash_autodetect)( chain_t *, cfi_query_structure_t * ); + void (*flash_print_info)( chain_t * ); + int (*flash_erase_block)( chain_t *, uint32_t ); + int (*flash_unlock_block)( chain_t *, uint32_t ); + int (*flash_program)( chain_t *, uint32_t, uint32_t ); + void (*flash_readarray)( chain_t *chain ); } flash_driver_t; extern flash_driver_t *flash_driver; @@ -55,7 +54,7 @@ extern flash_driver_t *flash_drivers[]; #define flash_program flash_driver->flash_program #define flash_readarray flash_driver->flash_readarray -extern void set_flash_driver( parts *ps, cfi_query_structure_t *cfi ); +extern void set_flash_driver( chain_t *chain, cfi_query_structure_t *cfi ); #define CFI_INTEL_ERROR_UNKNOWN 1 #define CFI_INTEL_ERROR_UNSUPPORTED 2 diff --git a/jtag/src/help.c b/jtag/src/help.c index 8bb66dff..d3ca8ace 100644 --- a/jtag/src/help.c +++ b/jtag/src/help.c @@ -37,6 +37,8 @@ #include "cable.h" #include "flash.h" +#include "jtag.h" + void help( const char *cmd ) { diff --git a/jtag/src/jtag.c b/jtag/src/jtag.c index c93a86b6..ea0ba365 100644 --- a/jtag/src/jtag.c +++ b/jtag/src/jtag.c @@ -40,18 +40,17 @@ #include #include "part.h" -#include "cable.h" #include "tap.h" -#include "detect.h" #include "bus.h" +#include "jtag.h" + #ifndef HAVE_GETLINE ssize_t getline( char **lineptr, size_t *n, FILE *stream ); #endif -cable_driver_t *cable = NULL; -parts *ps = NULL; +chain_t *chain = NULL; bus_driver_t *bus_driver = NULL; static char * @@ -60,22 +59,13 @@ get_token( char *buf ) return strtok( buf, " \f\n\r\t\v" ); } -void detectflash( parts *ps ); -void readmem( parts *ps, FILE *f, uint32_t addr, uint32_t len ); -void flashmem( parts *ps, FILE *f, uint32_t addr ); -void flashmsbin( parts *ps, FILE *f ); - -void help( const char *cmd ); - -void discovery( const char *filename ); - -int jtag_parse_file( const char *filename ); +static int jtag_parse_file( const char *filename ); #define JTAGDIR ".jtag" #define HISTORYFILE "history" #define RCFILE "rc" -void +static void jtag_create_jtagdir( void ) { char *home = getenv( "HOME" ); @@ -98,7 +88,7 @@ jtag_create_jtagdir( void ) free( jdir ); } -void +static void jtag_load_history( void ) { char *home = getenv( "HOME" ); @@ -124,7 +114,7 @@ jtag_load_history( void ) free( file ); } -void +static void jtag_save_history( void ) { char *home = getenv( "HOME" ); @@ -148,7 +138,7 @@ jtag_save_history( void ) free( file ); } -int +static int jtag_parse_line( char *line ) { char *t; @@ -237,8 +227,8 @@ jtag_parse_line( char *line ) } if (strcmp( t, "none" ) == 0) { - printf( _("Changed cable to 'none'\n") ); - cable = NULL; + chain_connect( chain, NULL, 0 ); + printf( _("Cable disconnected\n") ); return 1; } @@ -251,23 +241,21 @@ jtag_parse_line( char *line ) return 1; } - cable = cable_drivers[i]; - printf( _("Initializing %s on parallel port at 0x%x\n"), cable->description, port ); - if (!cable->init( port )) { + printf( _("Initializing %s on parallel port at 0x%x\n"), cable_drivers[i]->description, port ); + if (chain_connect( chain, cable_drivers[i], port )) { printf( _("Error: Cable driver initialization failed!\n") ); - cable = NULL; return 1; } - cable->set_trst( 0 ); - cable->set_trst( 1 ); - tap_reset(); + chain_set_trst( chain, 0 ); + chain_set_trst( chain, 1 ); + tap_reset( chain ); return 1; } if (strcmp( t, "discovery" ) == 0) { - if (!cable) { + if (!chain->cable) { printf( _("Error: Cable not configured. Use 'cable' command first!\n") ); return 1; } @@ -281,12 +269,12 @@ jtag_parse_line( char *line ) printf( _("syntax error!\n") ); return 1; } - discovery( t ); + discovery( chain, t ); return 1; } if (strcmp( t, "detect" ) == 0) { - if (!cable) { + if (!chain->cable) { printf( _("Error: Cable not configured. Use 'cable' command first!\n") ); return 1; } @@ -296,23 +284,23 @@ jtag_parse_line( char *line ) return 1; } - parts_free( ps ); - ps = detect_parts( JTAG_DATA_DIR ); - if (!ps->len) { - parts_free( ps ); - ps = NULL; + parts_free( chain->parts ); + chain->parts = detect_parts( chain, JTAG_DATA_DIR ); + if (!chain->parts->len) { + parts_free( chain->parts ); + chain->parts = NULL; return 1; } - parts_set_instruction( ps, "SAMPLE/PRELOAD" ); - parts_shift_instructions( ps ); - parts_shift_data_registers( ps ); - parts_set_instruction( ps, "BYPASS" ); - parts_shift_instructions( ps ); - if (strcmp( ps->parts[0]->part, "SA1110" ) == 0) + parts_set_instruction( chain->parts, "SAMPLE/PRELOAD" ); + chain_shift_instructions( chain ); + chain_shift_data_registers( chain ); + parts_set_instruction( chain->parts, "BYPASS" ); + chain_shift_instructions( chain ); + if (strcmp( chain->parts->parts[0]->part, "SA1110" ) == 0) bus_driver = &sa1110_bus_driver; - if (strcmp( ps->parts[0]->part, "PXA250" ) == 0) + if (strcmp( chain->parts->parts[0]->part, "PXA250" ) == 0) bus_driver = &pxa250_bus_driver; - if (strcmp( ps->parts[0]->part, "IXP425" ) == 0) + if (strcmp( chain->parts->parts[0]->part, "IXP425" ) == 0) bus_driver = &ixp425_bus_driver; return 1; } @@ -322,12 +310,12 @@ jtag_parse_line( char *line ) int msbin = 0; uint32_t addr = 0; - if (!cable) { + if (!chain->cable) { printf( _("Error: Cable not configured. Use 'cable' command first!\n") ); return 1; } - if (!ps) { + if (!chain->parts) { printf( _("Run \"detect\" first.\n") ); return 1; } @@ -361,9 +349,9 @@ jtag_parse_line( char *line ) return 1; } if (msbin) - flashmsbin( ps, f ); + flashmsbin( chain, f ); else - flashmem( ps, f, addr ); + flashmem( chain, f, addr ); fclose( f ); return 1; } @@ -373,12 +361,12 @@ jtag_parse_line( char *line ) uint32_t addr = 0; uint32_t len = 0; - if (!cable) { + if (!chain->cable) { printf( _("Error: Cable not configured. Use 'cable' command first!\n") ); return 1; } - if (!ps) { + if (!chain->parts) { printf( _("Run \"detect\" first.\n") ); return 1; } @@ -419,7 +407,7 @@ jtag_parse_line( char *line ) printf( _("Unable to create file `%s'!\n"), t ); return 1; } - readmem( ps, f, addr, len ); + readmem( chain, f, addr, len ); fclose( f ); return 1; @@ -431,17 +419,17 @@ jtag_parse_line( char *line ) return 1; } - if (!cable) { + if (!chain->cable) { printf( _("Error: Cable not configured. Use 'cable' command first!\n") ); return 1; } - if (!ps) { + if (!chain->parts) { printf( _("Run \"detect\" first.\n") ); return 1; } - detectflash( ps ); + detectflash( chain ); return 1; } @@ -451,24 +439,24 @@ jtag_parse_line( char *line ) return 1; } - if (!cable) { + if (!chain->cable) { printf( _("Error: Cable not configured. Use 'cable' command first!\n") ); return 1; } - parts_print( ps, 1 ); + parts_print( chain->parts, 1 ); return 1; } if (strcmp( t, "instruction" ) == 0) { int n; - if (!cable) { + if (!chain->cable) { printf( _("Error: Cable not configured. Use 'cable' command first!\n") ); return 1; } - if (!ps) { + if (!chain->parts) { printf( _("Run \"detect\" first.\n") ); return 1; } @@ -485,7 +473,7 @@ jtag_parse_line( char *line ) return 1; } - if ((n < 0) || (n >= ps->len)) { + if ((n < 0) || (n >= chain->parts->len)) { printf( _("instruction: invalid part number\n") ); return 1; } @@ -501,15 +489,15 @@ jtag_parse_line( char *line ) return 1; } - part_set_instruction( ps->parts[n], t ); - if (ps->parts[n]->active_instruction == NULL) + part_set_instruction( chain->parts->parts[n], t ); + if (chain->parts->parts[n]->active_instruction == NULL) printf( _("instruction: unknown instruction %s\n"), t ); return 1; } if (strcmp( t, "shift" ) == 0) { - if (!cable) { + if (!chain->cable) { printf( _("Error: Cable not configured. Use 'cable' command first!\n") ); return 1; } @@ -517,12 +505,12 @@ jtag_parse_line( char *line ) t = get_token( NULL ); if (t && (strcmp( t, "ir" ) == 0)) { - parts_shift_instructions( ps ); + chain_shift_instructions( chain ); return 1; } if (t && (strcmp( t, "dr" ) == 0)) { - parts_shift_data_registers( ps ); + chain_shift_data_registers( chain ); return 1; } @@ -535,12 +523,12 @@ jtag_parse_line( char *line ) int dir; tap_register *r; - if (!cable) { + if (!chain->cable) { printf( _("Error: Cable not configured. Use 'cable' command first!\n") ); return 1; } - if (!ps) { + if (!chain->parts) { printf( _("Run \"detect\" first.\n") ); return 1; } @@ -557,7 +545,7 @@ jtag_parse_line( char *line ) return 1; } - if ((n < 0) || (n >= ps->len)) { + if ((n < 0) || (n >= chain->parts->len)) { printf( _("dr: invalid part number\n") ); return 1; } @@ -582,9 +570,9 @@ jtag_parse_line( char *line ) } if (dir) - r = ps->parts[n]->active_instruction->data_register->out; + r = chain->parts->parts[n]->active_instruction->data_register->out; else - r = ps->parts[n]->active_instruction->data_register->in; + r = chain->parts->parts[n]->active_instruction->data_register->in; printf( "%s\n", register_get_string( r ) ); return 1; @@ -596,12 +584,12 @@ jtag_parse_line( char *line ) int dir; char *s; - if (!cable) { + if (!chain->cable) { printf( _("Error: Cable not configured. Use 'cable' command first!\n") ); return 1; } - if (!ps) { + if (!chain->parts) { printf( _("Run \"detect\" first.\n") ); return 1; } @@ -623,7 +611,7 @@ jtag_parse_line( char *line ) return 1; } - if ((n < 0) || (n >= ps->len)) { + if ((n < 0) || (n >= chain->parts->len)) { printf( _("set: invalid part number\n") ); return 1; } @@ -665,7 +653,7 @@ jtag_parse_line( char *line ) return 1; } - part_set_signal( ps->parts[n], s, dir, data ); + part_set_signal( chain->parts->parts[n], s, dir, data ); return 1; } @@ -674,12 +662,12 @@ jtag_parse_line( char *line ) int n; int data; - if (!cable) { + if (!chain->cable) { printf( _("Error: Cable not configured. Use 'cable' command first!\n") ); return 1; } - if (!ps) { + if (!chain->parts) { printf( _("Run \"detect\" first.\n") ); return 1; } @@ -701,7 +689,7 @@ jtag_parse_line( char *line ) return 1; } - if ((n < 0) || (n >= ps->len)) { + if ((n < 0) || (n >= chain->parts->len)) { printf( _("get: invalid part number\n") ); return 1; } @@ -712,7 +700,7 @@ jtag_parse_line( char *line ) return 1; } - data = part_get_signal( ps->parts[n], t ); + data = part_get_signal( chain->parts->parts[n], t ); if (data != -1) printf( _("%s = %d\n"), t, data ); @@ -740,7 +728,7 @@ jtag_parse_line( char *line ) return 1; } -void +static void jtag_readline_loop( const char *prompt ) { char *line = NULL; @@ -759,7 +747,7 @@ jtag_readline_loop( const char *prompt ) free( line ); } -int +static int jtag_parse_file( const char *filename ) { FILE *f; @@ -783,7 +771,7 @@ jtag_parse_file( const char *filename ) return go; } -void +static void jtag_parse_rc( void ) { char *home = getenv( "HOME" ); @@ -825,6 +813,12 @@ main( void ) "There is absolutely no warranty for %s.\n\n"), PACKAGE_STRING, PACKAGE, PACKAGE ); + chain = chain_alloc(); + if (!chain) { + printf( _("Out of memory\n") ); + return -1; + } + printf( _("Warning: %s may damage your hardware! Type \"quit\" for exit!\n\n"), PACKAGE ); printf( _("Type \"help\" for help.\n\n") ); @@ -843,16 +837,7 @@ main( void ) /* Save history */ jtag_save_history(); - parts_free( ps ); - - if (cable) { - cable->set_trst( 0 ); - cable->set_trst( 1 ); - tap_reset(); - cable->done(); - - cable = NULL; - } + chain_free( chain ); return 0; } diff --git a/jtag/src/detect.h b/jtag/src/jtag.h similarity index 55% rename from jtag/src/detect.h rename to jtag/src/jtag.h index 1b529f1d..b41d2bea 100644 --- a/jtag/src/detect.h +++ b/jtag/src/jtag.h @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) 2002 ETC s.r.o. + * 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,15 +18,31 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * - * Written by Marcel Telka , 2002. + * Written by Marcel Telka , 2003. * */ -#ifndef DETECT_H -#define DETECT_H +#ifndef JTAG_H +#define JTAG_H + +#include +#include + +#include #include "part.h" +#include "chain.h" + +parts_t *detect_parts( chain_t* chain, char *db_path ); +void detectflash( chain_t *chain ); +void readmem( chain_t *chain, FILE *f, uint32_t addr, uint32_t len ); +void flashmem( chain_t *chain, FILE *f, uint32_t addr ); +void flashmsbin( chain_t *chain, FILE *f ); + +void help( const char *cmd ); + +void discovery( chain_t *chain, const char *filename ); -parts *detect_parts( char *db_path ); +cfi_query_structure_t *detect_cfi( chain_t *chain ); -#endif /* DETECT_H */ +#endif /* JTAG_H */ diff --git a/jtag/src/part/part.c b/jtag/src/part/part.c index 597965b2..b37a05c7 100644 --- a/jtag/src/part/part.c +++ b/jtag/src/part/part.c @@ -26,7 +26,6 @@ #include #include "part.h" -#include "tap.h" /* part */ @@ -130,24 +129,6 @@ void part_set_instruction( part *p, const char *iname ) p->active_instruction = part_find_instruction( p, iname ); } -void -part_shift_instruction( part *p, int exit ) -{ - if (!p || !p->active_instruction) - return; - - tap_shift_register( p->active_instruction->value, NULL, exit ); -} - -void -part_shift_data_register( part *p, int exit ) -{ - if (!p || !p->active_instruction || !p->active_instruction->data_register) - return; - - tap_shift_register( p->active_instruction->data_register->in, p->active_instruction->data_register->out, exit ); -} - void part_set_signal( part *p, const char *pname, int out, int val ) { @@ -281,45 +262,6 @@ parts_set_instruction( parts *ps, const char *iname ) ps->parts[i]->active_instruction = part_find_instruction( ps->parts[i], iname ); } -void -parts_shift_instructions( parts *ps ) -{ - int i; - - if (!ps) - return; - - tap_capture_ir(); - - for (i = 0; i < ps->len; i++) { - if (!ps->parts[i]->active_instruction) { - printf( "%s(%s:%d) Part without active instruction\n", __FUNCTION__, __FILE__, __LINE__ ); - continue; - } - tap_shift_register( ps->parts[i]->active_instruction->value, NULL, (i + 1) == ps->len ); - } -} - -void -parts_shift_data_registers( parts *ps ) -{ - int i; - - if (!ps) - return; - - tap_capture_dr(); - - for (i = 0; i < ps->len; i++) { - if (!ps->parts[i]->active_instruction) { - printf( "%s(%s:%d) Part without active instruction\n", __FUNCTION__, __FILE__, __LINE__ ); - continue; - } - tap_shift_register( ps->parts[i]->active_instruction->data_register->in, - ps->parts[i]->active_instruction->data_register->out, (i + 1) == ps->len ); - } -} - void parts_print( parts *ps, int header ) { diff --git a/jtag/src/readmem.c b/jtag/src/readmem.c index 8b17cf64..7bda247b 100644 --- a/jtag/src/readmem.c +++ b/jtag/src/readmem.c @@ -38,19 +38,20 @@ #include #include +#include "jtag.h" + #include /* for ntohs */ - #include "part.h" #include "bus.h" #include "flash.h" - -cfi_query_structure_t *detect_cfi( parts * ); +#include "chain.h" void -detectflash( parts *ps ) +detectflash( chain_t *chain ) { + parts_t *ps = chain->parts; part *p = ps->parts[0]; int o = 0; cfi_query_structure_t *cfi; @@ -62,7 +63,7 @@ detectflash( parts *ps ) printf( "Note: Supported configuration is 2 x 16 bit or 1 x 16 bit only\n" ); - switch (bus_width( ps )) { + switch (bus_width( chain )) { case 16: o = 1; break; @@ -76,9 +77,9 @@ detectflash( parts *ps ) /* EXTEST */ part_set_instruction( p, "EXTEST" ); - parts_shift_instructions( ps ); + chain_shift_instructions( chain ); - cfi = detect_cfi( ps ); + cfi = detect_cfi( chain ); if (!cfi) { printf( "Flash not found!\n" ); return; @@ -210,14 +211,15 @@ detectflash( parts *ps ) } } - set_flash_driver( ps, cfi ); + set_flash_driver( chain, cfi ); if (flash_driver) - flash_driver->flash_print_info( ps ); + flash_driver->flash_print_info( chain ); } void -readmem( parts *ps, FILE *f, uint32_t addr, uint32_t len ) +readmem( chain_t *chain, FILE *f, uint32_t addr, uint32_t len ) { + parts_t *ps = chain->parts; part *p = ps->parts[0]; int step = 0; uint32_t a; @@ -228,7 +230,7 @@ readmem( parts *ps, FILE *f, uint32_t addr, uint32_t len ) return; } - step = bus_width( ps ) / 8; + step = bus_width( chain ) / 8; if (step == 0) { printf( "Unknown bus width!\n" ); @@ -237,7 +239,7 @@ readmem( parts *ps, FILE *f, uint32_t addr, uint32_t len ) /* EXTEST */ part_set_instruction( p, "EXTEST" ); - parts_shift_instructions( ps ); + chain_shift_instructions( chain ); addr = addr & (~(step - 1)); len = (len + step - 1) & (~(step - 1)); @@ -251,7 +253,7 @@ readmem( parts *ps, FILE *f, uint32_t addr, uint32_t len ) } printf( "reading:\n" ); - bus_read_start( ps, addr ); + bus_read_start( chain, addr ); for (a = addr + step; a <= addr + len; a += step) { uint32_t d = 0; uint16_t d16 = 0; @@ -260,15 +262,15 @@ readmem( parts *ps, FILE *f, uint32_t addr, uint32_t len ) if (a < addr + len) { if (step == 2) - d16 = bus_read_next( ps, a ); + d16 = bus_read_next( chain, a ); else - d = bus_read_next( ps, a ); + d = bus_read_next( chain, a ); } else { if (step == 2) - d16 = bus_read_end( ps ); + d16 = bus_read_end( chain ); else - d = bus_read_end( ps ); + d = bus_read_end( chain ); } if (step == 2) *((uint16_t *) &b[bc]) = ntohs(d16); diff --git a/jtag/src/tap/Makefile.am b/jtag/src/tap/Makefile.am index 8304840a..56f85cc1 100644 --- a/jtag/src/tap/Makefile.am +++ b/jtag/src/tap/Makefile.am @@ -27,6 +27,7 @@ libtap_a_SOURCES = \ tap.c \ register.c \ state.c \ + chain.c \ cable.c \ cable/arcom.c \ cable/byteblaster.c \ diff --git a/jtag/src/tap/cable/arcom.c b/jtag/src/tap/cable/arcom.c index 19794b76..7f57920d 100644 --- a/jtag/src/tap/cable/arcom.c +++ b/jtag/src/tap/cable/arcom.c @@ -26,7 +26,6 @@ #include #include "cable.h" -#include "state.h" /* * data D[7:0] (pins 9:2) @@ -45,16 +44,16 @@ */ #define TDO 7 +static int trst; static unsigned int port; static int arcom_init( unsigned int aport ) { - tap_state_init(); port = aport; if (((port + 2 <= 0x400) && ioperm( port, 2, 1 )) || ((port + 2 > 0x400) && iopl( 3 ))) return 0; - tap_state_set_trst( (inb( port ) >> TRST) & 1 ); + trst = (inb( port ) >> TRST) & 1; return 1; } @@ -66,39 +65,41 @@ arcom_done( void ) ioperm( port, 2, 0 ); else iopl( 0 ); - - tap_state_done(); } static void arcom_clock( int tms, int tdi ) { - int trst = tap_state_get_trst(); - - tms &= 1; - tdi &= 1; + tms = tms ? 1 : 0; + tdi = tdi ? 1 : 0; outb( (trst << TRST) | (0 << TCK) | (tms << TMS) | (tdi << TDI), port ); cable_wait(); outb( (trst << TRST) | (1 << TCK) | (tms << TMS) | (tdi << TDI), port ); cable_wait(); - - tap_state_clock( tms ); } static int arcom_get_tdo( void ) { - outb( (tap_state_get_trst() << TRST) | (0 << TCK), port ); + outb( (trst << TRST) | (0 << TCK), port ); cable_wait(); return ((inb( port + 1 ) ^ 0x80) >> TDO) & 1; /* BUSY is inverted */ } -static void +static int arcom_set_trst( int new_trst ) { - tap_state_set_trst( new_trst ); - outb( (new_trst & 1) << TRST, port ); + trst = new_trst ? 1 : 0; + + outb( trst << TRST, port ); + return trst; +} + +static int +arcom_get_trst( void ) +{ + return trst; } cable_driver_t arcom_cable_driver = { @@ -108,5 +109,6 @@ cable_driver_t arcom_cable_driver = { arcom_done, arcom_clock, arcom_get_tdo, - arcom_set_trst + arcom_set_trst, + arcom_get_trst }; diff --git a/jtag/src/tap/cable/byteblaster.c b/jtag/src/tap/cable/byteblaster.c index 2fabd73e..74b21f2c 100644 --- a/jtag/src/tap/cable/byteblaster.c +++ b/jtag/src/tap/cable/byteblaster.c @@ -34,7 +34,6 @@ #include #include "cable.h" -#include "state.h" /* * data D[7:0] (pins 9:2) @@ -57,7 +56,6 @@ static unsigned int port; static int byteblaster_init( unsigned int aport ) { - tap_state_init(); port = aport; return !(((port + 2 <= 0x400) && ioperm( port, 2, 1 )) || ((port + 2 > 0x400) && iopl( 3 ))); } @@ -69,22 +67,18 @@ byteblaster_done( void ) ioperm( port, 2, 0 ); else iopl( 0 ); - - tap_state_done(); } static void byteblaster_clock( int tms, int tdi ) { - tms &= 1; - tdi &= 1; + tms = tms ? 1 : 0; + tdi = tdi ? 1 : 0; outb( (0 << TCK) | (tms << TMS) | (tdi << TDI), port ); cable_wait(); outb( (1 << TCK) | (tms << TMS) | (tdi << TDI), port ); cable_wait(); - - tap_state_clock( tms ); } static int @@ -95,9 +89,16 @@ byteblaster_get_tdo( void ) return ((inb( port + 1 ) ^ 0x80) >> TDO) & 1; /* BUSY is inverted */ } -static void +static int byteblaster_set_trst( int new_trst ) { + return 1; +} + +static int +byteblaster_get_trst( void ) +{ + return 1; } cable_driver_t byteblaster_cable_driver = { @@ -107,5 +108,6 @@ cable_driver_t byteblaster_cable_driver = { byteblaster_done, byteblaster_clock, byteblaster_get_tdo, - byteblaster_set_trst + byteblaster_set_trst, + byteblaster_get_trst }; diff --git a/jtag/src/tap/cable/dlc5.c b/jtag/src/tap/cable/dlc5.c index 81aa72a2..eacefe53 100644 --- a/jtag/src/tap/cable/dlc5.c +++ b/jtag/src/tap/cable/dlc5.c @@ -30,7 +30,6 @@ #include #include "cable.h" -#include "state.h" /* see Figure B-1 in [1] */ @@ -57,7 +56,6 @@ static unsigned int port; static int dlc5_init( unsigned int aport ) { - tap_state_init(); port = aport; return !(((port + 2 <= 0x400) && ioperm( port, 2, 1 )) || ((port + 2 > 0x400) && iopl( 3 ))); } @@ -69,22 +67,18 @@ dlc5_done( void ) ioperm( port, 2, 0 ); else iopl( 0 ); - - tap_state_done(); } static void dlc5_clock( int tms, int tdi ) { - tms &= 1; - tdi &= 1; + tms = tms ? 1 : 0; + tdi = tdi ? 1 : 0; outb( (1 << PROG) | (0 << TCK) | (tms << TMS) | (tdi << TDI), port ); cable_wait(); outb( (1 << PROG) | (1 << TCK) | (tms << TMS) | (tdi << TDI), port ); cable_wait(); - - tap_state_clock( tms ); } static int @@ -95,9 +89,16 @@ dlc5_get_tdo( void ) return ((inb( port + 1 ) ^ 0x80) >> TDO) & 1; /* BUSY is inverted */ } -static void +static int dlc5_set_trst( int new_trst ) { + return 1; +} + +static int +dlc5_get_trst( void ) +{ + return 1; } cable_driver_t dlc5_cable_driver = { @@ -107,5 +108,6 @@ cable_driver_t dlc5_cable_driver = { dlc5_done, dlc5_clock, dlc5_get_tdo, - dlc5_set_trst + dlc5_set_trst, + dlc5_get_trst }; diff --git a/jtag/src/tap/cable/ea253.c b/jtag/src/tap/cable/ea253.c index 6e7d644b..c2e2d7aa 100644 --- a/jtag/src/tap/cable/ea253.c +++ b/jtag/src/tap/cable/ea253.c @@ -26,7 +26,6 @@ #include #include "cable.h" -#include "state.h" /* * data D[7:0] (pins 9:2) @@ -45,16 +44,16 @@ */ #define TDO 4 +static int trst; static unsigned int port; static int ea253_init( unsigned int aport ) { - tap_state_init(); port = aport; if (((port + 2 <= 0x400) && ioperm( port, 2, 1 )) || ((port + 2 > 0x400) && iopl( 3 ))) return 0; - tap_state_set_trst( (inb( port ) >> TRST) & 1 ); + trst = (inb( port ) >> TRST) & 1; return 1; } @@ -66,39 +65,41 @@ ea253_done( void ) ioperm( port, 2, 0 ); else iopl( 0 ); - - tap_state_done(); } static void ea253_clock( int tms, int tdi ) { - int trst = tap_state_get_trst(); - - tms &= 1; - tdi &= 1; + tms = tms ? 1 : 0; + tdi = tdi ? 1 : 0; outb( (trst << TRST) | (0 << TCK) | (tms << TMS) | (tdi << TDI), port ); cable_wait(); outb( (trst << TRST) | (1 << TCK) | (tms << TMS) | (tdi << TDI), port ); cable_wait(); - - tap_state_clock( tms ); } static int ea253_get_tdo( void ) { - outb( (tap_state_get_trst() << TRST) | (0 << TCK), port ); + outb( (trst << TRST) | (0 << TCK), port ); cable_wait(); return ((inb( port + 1 ) ^ 0x80) >> TDO) & 1; /* BUSY is inverted */ } -static void +static int ea253_set_trst( int new_trst ) { - tap_state_set_trst( new_trst ); - outb( (new_trst & 1) << TRST, port ); + trst = new_trst ? 1 : 0; + + outb( trst << TRST, port ); + return trst; +} + +static int +ea253_get_trst( void ) +{ + return trst; } cable_driver_t ea253_cable_driver = { @@ -108,5 +109,6 @@ cable_driver_t ea253_cable_driver = { ea253_done, ea253_clock, ea253_get_tdo, - ea253_set_trst + ea253_set_trst, + ea253_get_trst }; diff --git a/jtag/src/tap/cable/ei012.c b/jtag/src/tap/cable/ei012.c index d1317698..a98982e0 100644 --- a/jtag/src/tap/cable/ei012.c +++ b/jtag/src/tap/cable/ei012.c @@ -27,7 +27,6 @@ #include #include "cable.h" -#include "state.h" /* * data D[7:0] (pins 9:2) @@ -46,16 +45,16 @@ */ #define TDO 7 +static int trst; static unsigned int port; static int ei012_init( unsigned int aport ) { - tap_state_init(); port = aport; if (((port + 2 <= 0x400) && ioperm( port, 2, 1 )) || ((port + 2 > 0x400) && iopl( 3 ))) return 0; - tap_state_set_trst( (inb( port ) >> TRST) & 1 ); + trst = (inb( port ) >> TRST) & 1; return 1; } @@ -67,39 +66,41 @@ ei012_done( void ) ioperm( port, 2, 0 ); else iopl( 0 ); - - tap_state_done(); } static void ei012_clock( int tms, int tdi ) { - int trst = tap_state_get_trst(); - - tms &= 1; - tdi &= 1; + tms = tms ? 1 : 0; + tdi = tdi ? 1 : 0; outb( (trst << TRST) | (0 << TCK) | (tms << TMS) | (tdi << TDI), port ); cable_wait(); outb( (trst << TRST) | (1 << TCK) | (tms << TMS) | (tdi << TDI), port ); cable_wait(); - - tap_state_clock( tms ); } static int ei012_get_tdo( void ) { - outb( (tap_state_get_trst() << TRST) | (0 << TCK), port ); + outb( (trst << TRST) | (0 << TCK), port ); cable_wait(); return ((inb( port + 1 ) ^ 0x80) >> TDO) & 1; /* BUSY is inverted */ } -static void +static int ei012_set_trst( int new_trst ) { - tap_state_set_trst( new_trst ); - outb( (new_trst & 1) << TRST, port ); + trst = new_trst ? 1 : 0; + + outb( trst << TRST, port ); + return trst; +} + +static int +ei012_get_trst( void ) +{ + return trst; } cable_driver_t ei012_cable_driver = { @@ -109,5 +110,6 @@ cable_driver_t ei012_cable_driver = { ei012_done, ei012_clock, ei012_get_tdo, - ei012_set_trst + ei012_set_trst, + ei012_get_trst }; diff --git a/jtag/src/tap/cable/mpcbdm.c b/jtag/src/tap/cable/mpcbdm.c index d91d8abf..d12ff75a 100644 --- a/jtag/src/tap/cable/mpcbdm.c +++ b/jtag/src/tap/cable/mpcbdm.c @@ -30,7 +30,6 @@ #include #include "cable.h" -#include "state.h" /* * data @@ -50,18 +49,19 @@ */ #define TDO 5 +static int trst; static unsigned int port; static int mpcbdm_init( unsigned int aport ) { - tap_state_init(); port = aport; if (((port + 3 <= 0x400) && ioperm( port, 3, 1 )) || ((port + 3 > 0x400) && iopl( 3 ))) return 0; outb( (1 << TRST) | (1 << TRST1), port + 2 ); - tap_state_set_trst( 1 ); + trst = 1; + return 1; } @@ -72,17 +72,13 @@ mpcbdm_done( void ) ioperm( port, 3, 0 ); else iopl( 0 ); - - tap_state_done(); } static void mpcbdm_clock( int tms, int tdi ) { - int trst = tap_state_get_trst(); - - tms &= 1; - tdi &= 1; + tms = tms ? 1 : 0; + tdi = tdi ? 1 : 0; outb( (0 << TCK) | (tms << TMS) | (tdi << TDI), port ); outb( (trst << TRST) | (trst << TRST1), port + 2 ); @@ -90,24 +86,30 @@ mpcbdm_clock( int tms, int tdi ) outb( (1 << TCK) | (tms << TMS) | (tdi << TDI), port ); outb( (trst << TRST) | (trst << TRST1), port + 2 ); cable_wait(); - - tap_state_clock( tms ); } static int mpcbdm_get_tdo( void ) { outb( (0 << TCK), port ); - outb( (tap_state_get_trst() << TRST) | (tap_state_get_trst() << TRST1), port + 2 ); + outb( (trst << TRST) | (trst << TRST1), port + 2 ); cable_wait(); return ((inb( port + 1 ) ^ 0x80) >> TDO) & 1; /* BUSY is inverted */ } -static void +static int mpcbdm_set_trst( int new_trst ) { - tap_state_set_trst( new_trst ); - outb( (new_trst & 1) << TRST | (new_trst & 1) << TRST1, port + 2 ); + trst = new_trst ? 1 : 0; + + outb( (trst << TRST) | (trst << TRST1), port + 2 ); + return trst; +} + +static int +mpcdbm_get_trst( void ) +{ + return trst; } cable_driver_t mpcbdm_cable_driver = { @@ -117,5 +119,6 @@ cable_driver_t mpcbdm_cable_driver = { mpcbdm_done, mpcbdm_clock, mpcbdm_get_tdo, - mpcbdm_set_trst + mpcbdm_set_trst, + mpcdbm_get_trst }; diff --git a/jtag/src/tap/cable/wiggler.c b/jtag/src/tap/cable/wiggler.c index b9a7c86e..edc9467c 100644 --- a/jtag/src/tap/cable/wiggler.c +++ b/jtag/src/tap/cable/wiggler.c @@ -30,7 +30,6 @@ #include #include "cable.h" -#include "state.h" /* * data D[7:0] (pins 9:2) @@ -49,16 +48,16 @@ */ #define TDO 7 +static int trst; static unsigned int port; static int wiggler_init( unsigned int aport ) { - tap_state_init(); port = aport; if (((port + 2 <= 0x400) && ioperm( port, 2, 1 )) || ((port + 2 > 0x400) && iopl( 3 ))) return 0; - tap_state_set_trst( (inb( port ) >> TRST) & 1 ); + trst = (inb( port ) >> TRST) & 1; return 1; } @@ -70,39 +69,41 @@ wiggler_done( void ) ioperm( port, 2, 0 ); else iopl( 0 ); - - tap_state_done(); } static void wiggler_clock( int tms, int tdi ) { - int trst = tap_state_get_trst(); - - tms &= 1; - tdi &= 1; + tms = tms ? 1 : 0; + tdi = tdi ? 1 : 0; outb( (trst << TRST) | (0 << TCK) | (tms << TMS) | (tdi << TDI), port ); cable_wait(); outb( (trst << TRST) | (1 << TCK) | (tms << TMS) | (tdi << TDI), port ); cable_wait(); - - tap_state_clock( tms ); } static int wiggler_get_tdo( void ) { - outb( (tap_state_get_trst() << TRST) | (0 << TCK), port ); + outb( (trst << TRST) | (0 << TCK), port ); cable_wait(); return ((inb( port + 1 ) ^ 0x80) >> TDO) & 1; /* BUSY is inverted */ } -static void +static int wiggler_set_trst( int new_trst ) { - tap_state_set_trst( new_trst ); - outb( (new_trst & 1) << TRST, port ); + trst = new_trst ? 1 : 0; + + outb( trst << TRST, port ); + return trst; +} + +static int +wiggler_get_trst( void ) +{ + return trst; } cable_driver_t wiggler_cable_driver = { @@ -112,5 +113,6 @@ cable_driver_t wiggler_cable_driver = { wiggler_done, wiggler_clock, wiggler_get_tdo, - wiggler_set_trst + wiggler_set_trst, + wiggler_get_trst }; diff --git a/jtag/src/tap/chain.c b/jtag/src/tap/chain.c new file mode 100644 index 00000000..bce112e8 --- /dev/null +++ b/jtag/src/tap/chain.c @@ -0,0 +1,155 @@ +/* + * $Id$ + * + * 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 Marcel Telka , 2003. + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "gettext.h" +#define _(s) gettext(s) +#define N_(s) gettext_noop(s) +#define P_(s,p,n) ngettext(s,p,n) + +#include + +#include "chain.h" +#include "state.h" +#include "tap.h" + +chain_t * +chain_alloc( void ) +{ + chain_t *chain = malloc( sizeof (chain_t) ); + if (!chain) + return NULL; + + chain->cable = NULL; + chain->parts = NULL; + tap_state_init( chain ); + + return chain; +} + +void +chain_free( chain_t *chain ) +{ + if (!chain) + return; + + if (chain->cable) { + chain->cable->set_trst( 0 ); + chain->cable->set_trst( 1 ); + tap_reset( chain ); + chain->cable->done(); + } + tap_state_done( chain ); + /* cable_free( chain->cable ); */ + parts_free( chain->parts ); + free( chain ); +} + +int +chain_connect( chain_t *chain, cable_t *cable, unsigned int port ) +{ + if (chain->cable) { + tap_state_done( chain ); + chain->cable->done(); + chain->cable = NULL; + } + if (!cable || !cable->init( port )) + return -1; + + chain->cable = cable; + return 0; +} + +void +chain_clock( chain_t *chain, int tms, int tdi ) +{ + if (!chain || !chain->cable) + return; + + chain->cable->clock( tms, tdi ); + tap_state_clock( chain, tms ); +} + +int +chain_set_trst( chain_t *chain, int trst ) +{ + int old_trst = chain->cable->get_trst(); + trst = chain->cable->set_trst( trst ); + tap_state_set_trst( chain, old_trst, trst ); + return trst; +} + +int +chain_get_trst( chain_t *chain ) +{ + return chain->cable->get_trst(); +} + +void +chain_shift_instructions( chain_t *chain ) +{ + int i; + parts_t *ps; + + if (!chain || !chain->parts) + return; + + ps = chain->parts; + + tap_capture_ir( chain ); + + for (i = 0; i < ps->len; i++) { + if (!ps->parts[i]->active_instruction) { + printf( _("%s(%d) Part without active instruction\n"), __FILE__, __LINE__ ); + continue; + } + tap_shift_register( chain, ps->parts[i]->active_instruction->value, NULL, (i + 1) == ps->len ); + } +} + +void +chain_shift_data_registers( chain_t *chain ) +{ + int i; + parts_t *ps; + + if (!chain || !chain->parts) + return; + + ps = chain->parts; + + tap_capture_dr( chain ); + + for (i = 0; i < ps->len; i++) { + if (!ps->parts[i]->active_instruction) { + printf( _("%s(%d) Part without active instruction\n"), __FILE__, __LINE__ ); + continue; + } + tap_shift_register( chain, ps->parts[i]->active_instruction->data_register->in, + ps->parts[i]->active_instruction->data_register->out, (i + 1) == ps->len ); + } +} diff --git a/jtag/src/tap/state.c b/jtag/src/tap/state.c index edb6de38..3f405ef1 100644 --- a/jtag/src/tap/state.c +++ b/jtag/src/tap/state.c @@ -24,136 +24,129 @@ */ #include "state.h" - -static int state = Unknown_State; -static int trst = 1; +#include "chain.h" int -tap_state( void ) +tap_state( chain_t *chain ) { - return state; + return chain->state; } int -tap_state_init( void ) +tap_state_init( chain_t *chain ) { - return state = Unknown_State; + return chain->state = Unknown_State; } int -tap_state_done( void ) +tap_state_done( chain_t *chain ) { - return state = Unknown_State; + return chain->state = Unknown_State; } int -tap_state_reset( void ) +tap_state_reset( chain_t *chain ) { - return state = Test_Logic_Reset; + return chain->state = Test_Logic_Reset; } int -tap_state_set_trst( int new_trst ) +tap_state_set_trst( chain_t *chain, int old_trst, int new_trst ) { - if (trst != (new_trst & 1)) { - if (trst) - state = Unknown_State; - else - state = Test_Logic_Reset; + old_trst = old_trst ? 1 : 0; + new_trst = new_trst ? 1 : 0; - trst = new_trst & 1; + if (old_trst != new_trst) { + if (new_trst) + chain->state = Test_Logic_Reset; + else + chain->state = Unknown_State; } - return state; -} - -int -tap_state_get_trst( void ) -{ - return trst; + return chain->state; } int -tap_state_clock( int tms ) +tap_state_clock( chain_t *chain, int tms ) { - if (tms & 1) { - switch (state) { + if (tms) { + switch (chain->state) { case Test_Logic_Reset: break; case Run_Test_Idle: case Update_DR: case Update_IR: - state = Select_DR_Scan; + chain->state = Select_DR_Scan; break; case Select_DR_Scan: - state = Select_IR_Scan; + chain->state = Select_IR_Scan; break; case Capture_DR: case Shift_DR: - state = Exit1_DR; + chain->state = Exit1_DR; break; case Exit1_DR: case Exit2_DR: - state = Update_DR; + chain->state = Update_DR; break; case Pause_DR: - state = Exit2_DR; + chain->state = Exit2_DR; break; case Select_IR_Scan: - state = Test_Logic_Reset; + chain->state = Test_Logic_Reset; break; case Capture_IR: case Shift_IR: - state = Exit1_IR; + chain->state = Exit1_IR; break; case Exit1_IR: case Exit2_IR: - state = Update_IR; + chain->state = Update_IR; break; case Pause_IR: - state = Exit2_IR; + chain->state = Exit2_IR; break; default: - state = Unknown_State; + chain->state = Unknown_State; break; } } else { - switch (state) { + switch (chain->state) { case Test_Logic_Reset: case Run_Test_Idle: case Update_DR: case Update_IR: - state = Run_Test_Idle; + chain->state = Run_Test_Idle; break; case Select_DR_Scan: - state = Capture_DR; + chain->state = Capture_DR; break; case Capture_DR: case Shift_DR: case Exit2_DR: - state = Shift_DR; + chain->state = Shift_DR; break; case Exit1_DR: case Pause_DR: - state = Pause_DR; + chain->state = Pause_DR; break; case Select_IR_Scan: - state = Capture_IR; + chain->state = Capture_IR; break; case Capture_IR: case Shift_IR: case Exit2_IR: - state = Shift_IR; + chain->state = Shift_IR; break; case Exit1_IR: case Pause_IR: - state = Pause_IR; + chain->state = Pause_IR; break; default: - state = Unknown_State; + chain->state = Unknown_State; break; } } - return state; + return chain->state; } diff --git a/jtag/src/tap/tap.c b/jtag/src/tap/tap.c index 6b725071..c36eff22 100644 --- a/jtag/src/tap/tap.c +++ b/jtag/src/tap/tap.c @@ -22,69 +22,78 @@ * */ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "gettext.h" +#define _(s) gettext(s) +#define N_(s) gettext_noop(s) +#define P_(s,p,n) ngettext(s,p,n) + #include #include "register.h" #include "tap.h" -#include "cable.h" #include "state.h" +#include "chain.h" void -tap_reset( void ) +tap_reset( chain_t *chain ) { - tap_state_reset(); + tap_state_reset( chain ); - tap_clock( 1, 0 ); - tap_clock( 1, 0 ); - tap_clock( 1, 0 ); - tap_clock( 1, 0 ); - tap_clock( 1, 0 ); /* Test-Logic-Reset */ + chain_clock( chain, 1, 0 ); + chain_clock( chain, 1, 0 ); + chain_clock( chain, 1, 0 ); + chain_clock( chain, 1, 0 ); + chain_clock( chain, 1, 0 ); /* Test-Logic-Reset */ - tap_clock( 0, 0 ); /* Run-Test/Idle */ + chain_clock( chain, 0, 0 ); /* Run-Test/Idle */ } void -tap_shift_register( const tap_register *in, tap_register *out, int exit ) +tap_shift_register( chain_t *chain, const tap_register *in, tap_register *out, int exit ) { int i; - if (!(tap_state() & TAPSTAT_SHIFT)) - printf( "tap_shift_register: Invalid state: %2X\n", tap_state() ); + if (!(tap_state( chain ) & TAPSTAT_SHIFT)) + printf( _("%s: Invalid state: %2X\n"), "tap_shift_register", tap_state( chain ) ); /* Capture-DR, Capture-IR, Shift-DR, Shift-IR, Exit2-DR or Exit2-IR state */ - if (tap_state() & TAPSTAT_CAPTURE) - tap_clock( 0, 0 ); /* save last TDO bit :-) */ + if (tap_state( chain ) & TAPSTAT_CAPTURE) + chain_clock( chain, 0, 0 ); /* save last TDO bit :-) */ for (i = 0; i < in->len; i++) { if (out && (i < out->len)) - out->data[i] = tap_get_tdo(); - tap_clock( (exit && ((i + 1) == in->len)) ? 1 : 0, in->data[i] ); /* Shift (& Exit1) */ + out->data[i] = chain->cable->get_tdo(); + chain_clock( chain, (exit && ((i + 1) == in->len)) ? 1 : 0, in->data[i] ); /* Shift (& Exit1) */ } /* Shift-DR, Shift-IR, Exit1-DR or Exit1-IR state */ if (exit) { - tap_clock( 1, 0 ); /* Update-DR or Update-IR */ - tap_clock( 0, 0 ); /* Run-Test/Idle */ + chain_clock( chain, 1, 0 ); /* Update-DR or Update-IR */ + chain_clock( chain, 0, 0 ); /* Run-Test/Idle */ } } void -tap_capture_dr( void ) +tap_capture_dr( chain_t *chain ) { - if ((tap_state() & (TAPSTAT_RESET | TAPSTAT_IDLE)) != TAPSTAT_IDLE) - printf( "tap_capture_dr: Invalid state: %2X\n", tap_state() ); + if ((tap_state( chain ) & (TAPSTAT_RESET | TAPSTAT_IDLE)) != TAPSTAT_IDLE) + printf( _("%s: Invalid state: %2X\n"), "tap_capture_dr", tap_state( chain ) ); /* Run-Test/Idle or Update-DR or Update-IR state */ - tap_clock( 1, 0 ); /* Select-DR-Scan */ - tap_clock( 0, 0 ); /* Capture-DR */ + chain_clock( chain, 1, 0 ); /* Select-DR-Scan */ + chain_clock( chain, 0, 0 ); /* Capture-DR */ } void -tap_capture_ir( void ) +tap_capture_ir( chain_t *chain ) { - if ((tap_state() & (TAPSTAT_RESET | TAPSTAT_IDLE)) != TAPSTAT_IDLE) - printf( "tap_capture_ir: Invalid state: %2X\n", tap_state() ); + if ((tap_state( chain ) & (TAPSTAT_RESET | TAPSTAT_IDLE)) != TAPSTAT_IDLE) + printf( _("%s: Invalid state: %2X\n"), "tap_capture_ir", tap_state( chain ) ); /* Run-Test/Idle or Update-DR or Update-IR state */ - tap_clock( 1, 0 ); /* Select-DR-Scan */ - tap_clock( 1, 0 ); /* Select-IR-Scan */ - tap_clock( 0, 0 ); /* Capture-IR */ + chain_clock( chain, 1, 0 ); /* Select-DR-Scan */ + chain_clock( chain, 1, 0 ); /* Select-IR-Scan */ + chain_clock( chain, 0, 0 ); /* Capture-IR */ }