From 851277f003a403dca285d2c14f64c30ef6698d2f Mon Sep 17 00:00:00 2001 From: Kolja Waschk Date: Wed, 7 Nov 2007 09:44:52 +0000 Subject: [PATCH] Remaining diffs from gumstix repository: Add debug, test and shell command, aliases for parts, small fixes. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@731 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/src/bsdl2jtag.c | 25 ++++----- jtag/src/bus/ppc440gx_ebc8.c | 1 + jtag/src/cmd/Makefile.am | 3 ++ jtag/src/cmd/cmd.c | 6 +++ jtag/src/cmd/debug.c | 70 ++++++++++++++++++++++++ jtag/src/cmd/part.c | 32 +++++++++-- jtag/src/cmd/print.c | 26 +++++++-- jtag/src/cmd/script.c | 24 ++++++--- jtag/src/cmd/shell.c | 80 +++++++++++++++++++++++++++ jtag/src/cmd/signal.c | 38 ++++++++++--- jtag/src/cmd/test.c | 101 +++++++++++++++++++++++++++++++++++ jtag/src/detect.c | 18 ++++++- jtag/src/part/part.c | 4 +- jtag/src/part/signal.c | 1 + 14 files changed, 392 insertions(+), 37 deletions(-) create mode 100644 jtag/src/cmd/debug.c create mode 100644 jtag/src/cmd/shell.c create mode 100644 jtag/src/cmd/test.c diff --git a/jtag/src/bsdl2jtag.c b/jtag/src/bsdl2jtag.c index 81293563..519a7b32 100644 --- a/jtag/src/bsdl2jtag.c +++ b/jtag/src/bsdl2jtag.c @@ -32,11 +32,11 @@ #define BSBIT_INTERNAL 4 #define BSBIT_BIDIR 5 -char dev_name[64]=""; -int IR_l=0; -int BR_l=0; -int idcode[64]; -int id_num=0; +static char dev_name[64]=""; +static int IR_l=0; +static int BR_l=0; +static int idcode[64]; +static int id_num=0; struct bsbit { int bit; char name[32]; @@ -47,13 +47,13 @@ struct bsbit { int control_value; int control_state; } *bs_bits; -char insts[100][2][64]; -int inst_num=0; -char pins[2048][16], pinsp[2048][1024]; -int pins_num=-1; +static char insts[100][2][64]; +static int inst_num=0; +static char pins[2048][16], pinsp[2048][1024]; +static int pins_num=-1; -char line[1024], pline[1024]; -int mode; +static char line[1024], pline[1024]; +static int mode; int endline(void) { @@ -63,7 +63,7 @@ int endline(void) { // if(pline[0])printf("%s\n", pline); if(!strncmp(pline, "entity ", 7)) { - if(dev_name[0]==0) sscanf(pline, "entity %s", dev_name); + if(dev_name[0]=='\0') (void)sscanf(pline, "entity %s", dev_name); mode=0; } else if(!strncmp(pline, "attribute ", 10)) { @@ -79,6 +79,7 @@ int endline(void) { if(i!=2) return -3; BR_l=j; bs_bits=malloc(BR_l * sizeof(struct bsbit)); + if(bs_bits==NULL)return -80; /* djf */ for(i=0;i, 2003.i + * + */ + +#include "sysdep.h" + +#include +#include +//#include +//#include "part.h" +//#include "bssignal.h" +#include "jtag.h" + +#include "cmd.h" + +static int +cmd_debug_run( char *params[] ) +{ + int data,i; + signal_t *s; + + if (cmd_params( params ) != 2) + return -1; + + if (cmd_get_number( params[1], &i )) + return 1; + + debug_mode = i; + return 1; +} + +static void +cmd_debug_help( void ) +{ + printf( _( + "Usage: %s n\n" + "Enabled debugging.\n" + "\n" + "n =1 fileio, 2=tap commands, 4 =?\n" + ), "debug n" ); +} + +cmd_t cmd_debug = { + "debug", + N_("debug jtag program"), + cmd_debug_help, + cmd_debug_run +}; + diff --git a/jtag/src/cmd/part.c b/jtag/src/cmd/part.c index ca2c81a9..a531a008 100644 --- a/jtag/src/cmd/part.c +++ b/jtag/src/cmd/part.c @@ -36,6 +36,18 @@ cmd_part_run( char *params[] ) { unsigned int n; +/* part alias U1 (3 params) */ + if(cmd_params( params ) == 3) { + if(strcasecmp(params[1],"alias") == 0) { +part_t *part; + part = chain->parts->parts[chain->active_part]; + part->alias = malloc(strlen(params[2])+1); + strcpy(part->alias,params[2]); + return 1; + } + } + + if (cmd_params( params ) != 2) return -1; @@ -47,8 +59,22 @@ cmd_part_run( char *params[] ) return 1; } - if (cmd_get_number( params[1], &n )) - return -1; +/* Search for alias too djf */ + if (cmd_get_number( params[1], &n )) { + + /* Search all parts to check their aliases */ + int i; + char *a; + + for(i=0;iparts->len;i++) { + a = chain->parts->parts[i]->alias; + if(a && strcmp(a,params[1]) == 0)break; + } + if(i < chain->parts->len)n = i; + + + else return -1; + } if (n >= chain->parts->len) { printf( _("%s: invalid part number\n"), "part" ); @@ -67,7 +93,7 @@ cmd_part_help( void ) "Usage: %s PART\n" "Change active part for current JTAG chain.\n" "\n" - "PART part number\n" + "PART part number | alias\n" ), "part" ); } diff --git a/jtag/src/cmd/print.c b/jtag/src/cmd/print.c index 4e0d38fe..b26142da 100644 --- a/jtag/src/cmd/print.c +++ b/jtag/src/cmd/print.c @@ -58,10 +58,24 @@ cmd_print_run( char *params[] ) } if (cmd_params( params ) == 2) { - if ((strcasecmp( params[1], "chain" ) != 0) && (strcasecmp( params[1], "bus") != 0)) - return -1; if (strcasecmp( params[1], "bus") == 0) noheader = 1; + + if (strcasecmp( params[1], "signals") == 0) { + + printf("Signals:\n"); + part_t *part; + signal_t *s; + part = chain->parts->parts[chain->active_part]; + for(s = part->signals;s != NULL;s = s->next) { + if(s->pin)printf("%s %s",s->name,s->pin); + else printf("%s",s->name); + if(s->input)printf("\tinput=%s",s->input->name); + if(s->output)printf("\toutput=%s",s->output->name); + printf("\n"); + } + return(1); + } } if (noheader == 0) { @@ -87,7 +101,11 @@ cmd_print_run( char *params[] ) if (cmd_params( params ) == 1) { if (chain->parts->len > chain->active_part) { - printf( _(" %3d "), chain->active_part ); + if(chain->parts->parts[chain->active_part]->alias) + printf( _(" %3d %s "), chain->active_part,chain->parts->parts[chain->active_part]->alias ); + else + printf( _(" %3d "), chain->active_part); + part_print( chain->parts->parts[chain->active_part] ); } if (bus != NULL) { @@ -138,7 +156,7 @@ static void cmd_print_help( void ) { printf( _( - "Usage: %s [chain|bus]\n" + "Usage: %s [chain|bus|signals]\n" "Display JTAG chain status.\n" "\n" "Display list of the parts connected to the JTAG chain including\n" diff --git a/jtag/src/cmd/script.c b/jtag/src/cmd/script.c index ae0e073d..1d871cff 100644 --- a/jtag/src/cmd/script.c +++ b/jtag/src/cmd/script.c @@ -33,15 +33,25 @@ static int cmd_script_run( char *params[] ) { - int go; +int i,j; - if (cmd_params( params ) != 2) + int go; + i = 0; j = 1; + if (cmd_params( params ) == 3) { + sscanf(params[2],"%d",&j); /* loop n times option */ + } + else if (cmd_params( params ) != 2) return -1; - go = jtag_parse_file( params[1] ); - if (go < 0) - printf( _("Unable to open file `%s'!\n"), params[1] ); + for(i=0;i, 2003. + * shell.c added by djf + */ + +#include "sysdep.h" + +//#include +//#include +#include +//#include "part.h" +//#include "bssignal.h" +#include "jtag.h" + +#include "cmd.h" + +static int +cmd_shell_run( char *params[] ) +{ +int n,l1,l2; +char *t; + + if((n=cmd_params( params )) == 1) + return -1; + + /* I must apologize to everyone who knows what they are doing for + * the following. If you can pass a shell argument past strtok the + * please fix this. + */ + + l1 = strlen(params[1]); + l2 = strlen(params[2]); + t = malloc(l1+l2+2); /* space + term */ + strcpy(t,params[1]); /* main command */ + + if(n == 3) { + *(t+l1)= ' '; /* add space */ + strcpy((t+l1+1),params[2]); + } + system(t); + + return 1; +} + +static void +cmd_shell_help( void ) +{ + printf( _( + "Usage: %s cmmd\n" + "Shell out to os for a command.\n" + "\n" + "CMMD OS Shell Command\n" + ), "shell cmmd" ); +} + +cmd_t cmd_shell = { + "shell", + N_("shell cmmd"), + cmd_shell_help, + cmd_shell_run +}; diff --git a/jtag/src/cmd/signal.c b/jtag/src/cmd/signal.c index 9359826d..e0e15ccd 100644 --- a/jtag/src/cmd/signal.c +++ b/jtag/src/cmd/signal.c @@ -37,8 +37,9 @@ cmd_signal_run( char *params[] ) { part_t *part; signal_t *s; + int i; - if (cmd_params( params ) < 2) + if ((i = cmd_params( params )) < 2) return -1; @@ -56,12 +57,33 @@ cmd_signal_run( char *params[] ) } part = chain->parts->parts[chain->active_part]; - if (part_find_signal( part, params[1] ) != NULL) { - printf( _("Signal '%s' already defined\n"), params[1] ); - return 1; + if ((s = part_find_signal( part, params[1] )) != NULL) { + if(i == 3) { + printf("Defining pin for signal %s\m",s->name); + + if(s->pin)free(s->pin); /* erase old */ + + /* Allocate the space for the pin number & copy it */ + s->pin = malloc(strlen(params[2])+1); + strcpy(s->pin,params[2]); + + return 1; + } + else { + printf( _("Signal '%s' already defined\n"), params[1] ); + return 1; + } + } + + s = signal_alloc( params[1]); + + if(i == 3) { /* Add pin number */ + /* Allocate the space for the pin number & copy it */ + s->pin = malloc(strlen(params[2])+1); + strcpy(s->pin,params[2]); + } - s = signal_alloc( params[1] ); if (!s) { printf( _("out of memory\n") ); return 1; @@ -77,11 +99,11 @@ static void cmd_signal_help( void ) { printf( _( - "Usage: %s SIGNAL [PINLIST...]\n" + "Usage: %s SIGNAL [PIN#]\n" "Define new signal with name SIGNAL for a part.\n" "\n" - "SIGNAL New signal name\n" - "PINLIST List of pins for a signal (not used)\n" + "SIGNAL New signal name\n" + "PIN# List of pin # for a signal\n" ), "signal" ); } diff --git a/jtag/src/cmd/test.c b/jtag/src/cmd/test.c new file mode 100644 index 00000000..35b06d64 --- /dev/null +++ b/jtag/src/cmd/test.c @@ -0,0 +1,101 @@ +/* + * $Id: test.c,v 1.0 2005/10/10 00:00:0 DJF $ + * + * Copyright (C) 2005 Protoparts + * + * 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 David Farrell, 2005 + * based on templates by and portions Written by Marcel Telka , 2003.i + * + */ + +#include "sysdep.h" + +#include +#include +//#include +#include "part.h" +#include "bssignal.h" +#include "jtag.h" + +#include "cmd.h" + +static int +cmd_test_run( char *params[] ) +{ + int data,i; + signal_t *s; + + if (cmd_params( params ) != 4) + return -1; + + if (strcmp( params[1], "signal") != 0) + return -1; + + if (!cmd_test_cable()) + return 1; + + if (!chain->parts) { + printf( _("Run \"detect\" first.\n") ); + return 1; + } + + if (chain->active_part >= chain->parts->len) { + printf( _("%s: no active part\n"), "get" ); + return 1; + } + + s = part_find_signal( chain->parts->parts[chain->active_part], params[2] ); + if (!s) { + printf( _("signal '%s' not found\n"), params[2] ); + return 1; + } + + /* values 0,1,X since X is not a number, the following failure exits clean + * and doesnt test anything, as it should. + */ + if (cmd_get_number( params[3], &i )) + return 1; + + data = part_get_signal( chain->parts->parts[chain->active_part], s ); + if (data != -1) { + if(data != i) { + printf( _("%s = %d\n"), params[2], data ); + return -99; + } + } + return 1; +} + +static void +cmd_test_help( void ) +{ + printf( _( + "Usage: %s SIGNAL 0/1\n" + "Test signal state from output BSR (Boundary Scan Register).\n" + "\n" + "SIGNAL signal name (from JTAG declaration file)\n" + ), "get signal" ); +} + +cmd_t cmd_test = { + "test", + N_("test external signal value"), + cmd_test_help, + cmd_test_run +}; + diff --git a/jtag/src/detect.c b/jtag/src/detect.c index 7e69eeb5..42f76f1e 100644 --- a/jtag/src/detect.c +++ b/jtag/src/detect.c @@ -160,6 +160,20 @@ find_record( char *filename, tap_register *key, struct id_record *idr ) return r; } +unsigned long bits_to_long(tap_register *t) { +int i; +unsigned long l,b; + + l = 0; b=1; + for(i=0;i < t->len ;i++) { + if(t->data[i] & 1)l |= b; + b <<= 1; +// printf("%01d",t->data[i]); + } + return l; +} + + int detect_parts( chain_t *chain, char *db_path ) { @@ -246,7 +260,7 @@ detect_parts( chain_t *chain, char *db_path ) did = id; } - printf( _("Device Id: %s\n"), register_get_string( did ) ); + printf( _("Device Id: %s (0x%08X)\n"), register_get_string( did ), bits_to_long(did) ); part = part_alloc( did ); if (part == NULL) { printf( _("Out of memory\n") ); @@ -297,7 +311,7 @@ detect_parts( chain_t *chain, char *db_path ) } register_free( key ); - printf( _(" Part: %s\n"), idr.fullname ); + printf( _(" Part(%d): %s\n"), chain->active_part, idr.fullname ); if (strlen( idr.fullname ) > MAXLEN_PART) printf( _("Warning: Part too long\n") ); strncpy( partname, idr.fullname, MAXLEN_PART ); diff --git a/jtag/src/part/part.c b/jtag/src/part/part.c index 38fcc664..8fd361c3 100644 --- a/jtag/src/part/part.c +++ b/jtag/src/part/part.c @@ -37,7 +37,7 @@ part_alloc( const tap_register *id ) part_t *p = malloc( sizeof *p ); if (!p) return NULL; - + p->alias = NULL; /* djf */ p->id = register_duplicate( id ); p->manufacturer[0] = '\0'; p->part[0] = '\0'; @@ -65,6 +65,8 @@ part_free( part_t *p ) /* id */ free( p->id ); + if(p->alias)free(p->alias); /* djf */ + /* signals */ while (p->signals) { signal_t *s = p->signals; diff --git a/jtag/src/part/signal.c b/jtag/src/part/signal.c index 52b98350..c1285e48 100644 --- a/jtag/src/part/signal.c +++ b/jtag/src/part/signal.c @@ -39,6 +39,7 @@ signal_alloc( const char *name ) free( s ); return NULL; } + s->pin = NULL; /* djf hack pin number */ s->next = NULL; s->input = NULL; s->output = NULL;