diff --git a/jtag/ChangeLog b/jtag/ChangeLog index 8b006ccd..dabbe9a3 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,31 @@ +2008-03-15 Jie Zhang + + * include/jtag.h (jtag_parse_line): Declare. + (jtag_parse_stream): Declare. + * src/discovery.c: Move ... + * src/tap/discovery.c: ... here. + * src/detect.c: Move ... + * src/tap/detect.c: ... here. + * src/tap/Makefile.am (libtap_a_SOURCES): Add detect.c and + discovery.c. + * src/readmem.c: Move ... + * src/bus/readmem.c: ... here. + * src/writemem.c: Move ... + * src/bus/writemem.c: ... here. + * src/bus/Makefile.am (libbus_a_SOURCES): Add readmem.c and + writemem.c. + * src/flash.c: Move ... + * src/flash/flash.c: ... here. + * src/flash/Makefile.am (libflash_a_SOURCES): Add flash.c. + * src/jtag.c (get_token, jtag_parse_line, jtag_parse_stream, + jtag_parse_file): Move to ... + * src/cmd/parse.c: ... here. + * src/cmd/Makefile.am (libbus_a_SOURCES): Add parse.c. + * src/Makefile.am (jtag_SOURCES): Remove detect.c, discovery.c, + readmem.c, writemem.c and flash.c. + (jtag_LDADD): Add -ltap and -lflash one more time to resolve + undefined references. + 2008-03-14 Arnim Laeuger * configure.ac: format AC_ARG_ENABLE help with AS_HELP_STRING macro diff --git a/jtag/include/jtag.h b/jtag/include/jtag.h index ee2af1b9..61a64633 100644 --- a/jtag/include/jtag.h +++ b/jtag/include/jtag.h @@ -39,6 +39,8 @@ extern int big_endian; extern int debug_mode; int jtag_parse_file( chain_t *chain, const char *filename ); +int jtag_parse_line( chain_t *chain, char *line ); +int jtag_parse_stream( chain_t *chain, FILE *f ); int detect_parts( chain_t *chain, char *db_path ); int detect_register_size( chain_t *chain ); diff --git a/jtag/src/Makefile.am b/jtag/src/Makefile.am index 5fe41872..79c14f0b 100644 --- a/jtag/src/Makefile.am +++ b/jtag/src/Makefile.am @@ -44,12 +44,7 @@ bin_PROGRAMS = \ bsdl2jtag jtag_SOURCES = \ - jtag.c \ - detect.c \ - discovery.c \ - readmem.c \ - writemem.c \ - flash.c + jtag.c bsdl2jtag_SOURCES = \ bsdl2jtag.c @@ -76,6 +71,8 @@ jtag_LDADD = \ -Llib -ljtaglib \ -Lflash -lflash \ -Lcmd -lcmd \ + -Ltap -ltap \ + -Lflash -lflash \ -Lbus -lbus \ -lm \ @FTD2XXLIB@ \ diff --git a/jtag/src/bus/Makefile.am b/jtag/src/bus/Makefile.am index 940e9d4a..710f201a 100644 --- a/jtag/src/bus/Makefile.am +++ b/jtag/src/bus/Makefile.am @@ -46,6 +46,7 @@ libbus_a_SOURCES = \ prototype.c \ pxa2x0.c \ pxa2x0_mc.h \ + readmem.c \ sa1110.c \ s3c4510x.c \ sh7727.c \ @@ -56,4 +57,5 @@ libbus_a_SOURCES = \ tx4925.c \ jopcyc.c \ sharc21065l.c \ + writemem.c \ zefant-xs3.c diff --git a/jtag/src/readmem.c b/jtag/src/bus/readmem.c similarity index 100% rename from jtag/src/readmem.c rename to jtag/src/bus/readmem.c diff --git a/jtag/src/writemem.c b/jtag/src/bus/writemem.c similarity index 100% rename from jtag/src/writemem.c rename to jtag/src/bus/writemem.c diff --git a/jtag/src/cmd/Makefile.am b/jtag/src/cmd/Makefile.am index 90d423ae..e3cf841e 100644 --- a/jtag/src/cmd/Makefile.am +++ b/jtag/src/cmd/Makefile.am @@ -52,6 +52,7 @@ libcmd_a_SOURCES = \ shell.c \ set.c \ endian.c \ + parse.c \ peekpoke.c \ readmem.c \ writemem.c \ diff --git a/jtag/src/cmd/parse.c b/jtag/src/cmd/parse.c new file mode 100644 index 00000000..951ac7d8 --- /dev/null +++ b/jtag/src/cmd/parse.c @@ -0,0 +1,120 @@ +/* + * parse.c + * + * Copyright (C) 2002, 2003 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * 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 , 2002, 2003. + * Modified by Ajith Kumar P.C , 20/09/2006. + * + */ + +#include "sysdep.h" + +#include +#include +#include + +#include "chain.h" +#include "cmd.h" +#include "jtag.h" + + +static char * +get_token( char *buf ) +{ + char *t = strtok( buf, " \f\n\r\t\v" ); + if (t && (*t == '#')) + return NULL; + return t; +} + +int +jtag_parse_line( chain_t *chain, char *line ) +{ + char *t; + int l; + int n; + char **a; + int r; + + if (!line || !(strlen( line ) > 0)) + return 1; + + t = get_token( line ); + if (!t) + return 1; + + n = 0; + l = 0; + a = NULL; + while (t) { + if (n + 2 > l) { + char **newa; + l = (l < 16) ? 16 : (l * 2); + newa = realloc( a, l * sizeof (char *) ); + if (!newa) { + free( a ); + printf( _("Out of memory\n") ); + return 1; + } + a = newa; + } + a[n++] = t; + a[n] = NULL; + + t = get_token( NULL ); + } + + r = cmd_run( chain, a ); + if(debug_mode & 1)printf("Return in jtag_parse_line r=%d\n",r); + free( a ); + return r; +} + +int +jtag_parse_stream( chain_t *chain, FILE *f ) +{ + int go = 1; + char *line = NULL; + size_t n = 0; + + while (go && (getline( &line, &n, f ) != -1)) + if ((strlen(line) > 0) && (line[0] != '#')) + go = jtag_parse_line(chain, line); + + free(line); + + return go; +} + +int +jtag_parse_file( chain_t *chain, const char *filename ) +{ + FILE *f; + int go; + + f = fopen( filename, "r" ); + if (!f) + return -1; + + go = jtag_parse_stream( chain, f ); + + fclose(f); + if(debug_mode & 1)printf("File Closed gp=%d\n",go); + return go; +} diff --git a/jtag/src/flash/Makefile.am b/jtag/src/flash/Makefile.am index 08036829..b7583660 100644 --- a/jtag/src/flash/Makefile.am +++ b/jtag/src/flash/Makefile.am @@ -30,6 +30,7 @@ libflash_a_SOURCES = \ amd_flash.c \ cfi.c \ detectflash.c \ + flash.c \ intel.c \ jedec.c diff --git a/jtag/src/flash.c b/jtag/src/flash/flash.c similarity index 100% rename from jtag/src/flash.c rename to jtag/src/flash/flash.c diff --git a/jtag/src/jtag.c b/jtag/src/jtag.c index 6678eb1f..452ff11f 100644 --- a/jtag/src/jtag.c +++ b/jtag/src/jtag.c @@ -60,15 +60,6 @@ int big_endian = 0; int interactive = 0; extern cfi_array_t *cfi_array; -static char * -get_token( char *buf ) -{ - char *t = strtok( buf, " \f\n\r\t\v" ); - if (t && (*t == '#')) - return NULL; - return t; -} - #define JTAGDIR ".jtag" #define HISTORYFILE "history" #define RCFILE "rc" @@ -152,50 +143,6 @@ jtag_save_history( void ) #endif /* HAVE_READLINE_HISTORY */ #endif -static int -jtag_parse_line( chain_t *chain, char *line ) -{ - char *t; - int l; - int n; - char **a; - int r; - - if (!line || !(strlen( line ) > 0)) - return 1; - - t = get_token( line ); - if (!t) - return 1; - - n = 0; - l = 0; - a = NULL; - while (t) { - if (n + 2 > l) { - char **newa; - l = (l < 16) ? 16 : (l * 2); - newa = realloc( a, l * sizeof (char *) ); - if (!newa) { - free( a ); - printf( _("Out of memory\n") ); - return 1; - } - a = newa; - } - a[n++] = t; - a[n] = NULL; - - t = get_token( NULL ); - } - - r = cmd_run( chain, a ); - if(debug_mode & 1)printf("Return in jtag_parse_line r=%d\n",r); - free( a ); - return r; -} - - static int jtag_readline_multiple_commands_support(chain_t *chain, char * line) /* multiple commands should be separated with '::' */ { int r; @@ -265,39 +212,6 @@ jtag_readline_loop( chain_t *chain, const char *prompt ) #endif } -static int -jtag_parse_stream( chain_t *chain, FILE *f ) -{ - int go = 1; - char *line = NULL; - size_t n = 0; - - while (go && (getline( &line, &n, f ) != -1)) - if ((strlen(line) > 0) && (line[0] != '#')) - go = jtag_parse_line(chain, line); - - free(line); - - return go; -} - -int -jtag_parse_file( chain_t *chain, const char *filename ) -{ - FILE *f; - int go; - - f = fopen( filename, "r" ); - if (!f) - return -1; - - go = jtag_parse_stream( chain, f ); - - fclose(f); - if(debug_mode & 1)printf("File Closed gp=%d\n",go); - return go; -} - static int jtag_parse_rc( chain_t *chain ) { diff --git a/jtag/src/tap/Makefile.am b/jtag/src/tap/Makefile.am index d92c52e0..ed5e2077 100644 --- a/jtag/src/tap/Makefile.am +++ b/jtag/src/tap/Makefile.am @@ -30,6 +30,8 @@ libtap_a_SOURCES = \ register.c \ state.c \ chain.c \ + detect.c \ + discovery.c \ parport.c \ parport/direct.c \ parport/ppdev.c \ diff --git a/jtag/src/detect.c b/jtag/src/tap/detect.c similarity index 100% rename from jtag/src/detect.c rename to jtag/src/tap/detect.c diff --git a/jtag/src/discovery.c b/jtag/src/tap/discovery.c similarity index 100% rename from jtag/src/discovery.c rename to jtag/src/tap/discovery.c