diff --git a/jtag/ChangeLog b/jtag/ChangeLog index bd473ce5..5e312072 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,12 @@ +2008-02-18 Arnim Laeuger + + * src/bsdl/bsdl.c, src/bsdl/bsdl_flex.l, src/bsdl/bsdl_bison.y, + src/bsdl/bsdl.h, src/bsdl/bsdl_sem.c: support quiet scanning of files + in include.c + * src/cmd/include.c (cmd_include_run): check and read file if it's BSDL + syntax -> [ 1895936 ] + * doc/UrJTAG.txt: add note about BSDL support in 'include' + 2008-02-18 Kolja Waschk * doc/UrJTAG.txt: How to use initbus (and ejtag/prototype bus driver) diff --git a/jtag/doc/UrJTAG.txt b/jtag/doc/UrJTAG.txt index 9a2fa307..cd60a3e2 100644 --- a/jtag/doc/UrJTAG.txt +++ b/jtag/doc/UrJTAG.txt @@ -582,9 +582,10 @@ followed by the word "help". Example: ===== include ===== -Run commands from a named script file installed with UrJTAG. The directory -prefix is added automatically (e.g. /usr/share/urjtag/, depending on your -installation), unless the file name starts with a dot or slash. +Run commands from a named script file installed with UrJTAG or applies a BSDL +file to the active part. The directory prefix is added automatically +(e.g. /usr/share/urjtag/, depending on your installation), unless the file +name starts with a dot or slash. For example, the following startup sequence configures the cable, chain, and loads definitions and bus driver for a Samsung S3C4510B CPU to peek its memory @@ -595,6 +596,9 @@ at 0x0: jtag> include samsung/s3c4510b/s3c4510b jtag> peek 0x0000 +If the file contains valid BSDL syntax, it will be converted to native +commands on the fly. + Optionally, a number X may be specified following the file name, to cause an X times repetition of the command sequency from the file. diff --git a/jtag/src/bsdl/bsdl.c b/jtag/src/bsdl/bsdl.c index 7b3468f0..62628cf1 100644 --- a/jtag/src/bsdl/bsdl.c +++ b/jtag/src/bsdl/bsdl.c @@ -59,6 +59,9 @@ void bsdl_msg(int type, const char *format, ...) case BSDL_MSG_ERR: printf("-E- "); break; + case BSDL_MSG_FATAL: + printf("-F- "); + break; default: printf("-?- "); break; @@ -128,6 +131,7 @@ int bsdl_read_file(const char *BSDL_File_Name, int mode, const char *idcode) parser_priv->jtag_ctrl.part = NULL; parser_priv->jtag_ctrl.mode = mode; + parser_priv->jtag_ctrl.debug = bsdl_debug; parser_priv->jtag_ctrl.idcode = NULL; bsdlparse(parser_priv); @@ -137,7 +141,8 @@ int bsdl_read_file(const char *BSDL_File_Name, int mode, const char *idcode) if (bsdl_debug) bsdl_msg(BSDL_MSG_NOTE, _("BSDL file '%s' compiled correctly\n"), BSDL_File_Name); } else { - bsdl_msg(BSDL_MSG_ERR, _("BSDL file '%s' contains errors, stopping\n"), BSDL_File_Name); + if (bsdl_debug || (mode >= 0)) + bsdl_msg(BSDL_MSG_ERR, _("BSDL file '%s' contains errors, stopping\n"), BSDL_File_Name); } if (Compile_Errors == 0) @@ -169,7 +174,8 @@ int bsdl_read_file(const char *BSDL_File_Name, int mode, const char *idcode) } } - free(parser_priv->jtag_ctrl.idcode); + if (parser_priv->jtag_ctrl.idcode) + free(parser_priv->jtag_ctrl.idcode); parser_priv->jtag_ctrl.idcode = NULL; } bsdl_parser_deinit(parser_priv); diff --git a/jtag/src/bsdl/bsdl.h b/jtag/src/bsdl/bsdl.h index 5de957ef..ab04f630 100644 --- a/jtag/src/bsdl/bsdl.h +++ b/jtag/src/bsdl/bsdl.h @@ -26,9 +26,10 @@ /* message types for bsdl_msg() */ -#define BSDL_MSG_NOTE 0 -#define BSDL_MSG_WARN 1 -#define BSDL_MSG_ERR 2 +#define BSDL_MSG_NOTE 0 +#define BSDL_MSG_WARN 1 +#define BSDL_MSG_ERR 2 +#define BSDL_MSG_FATAL 3 /* private data of the flex scanner @@ -111,6 +112,7 @@ struct port_desc { with jtag internals */ struct jtag_ctrl { int mode; + int debug; char *idcode; /* IDCODE string */ part_t *part; struct port_desc port_desc; diff --git a/jtag/src/bsdl/bsdl_bison.y b/jtag/src/bsdl/bsdl_bison.y index 4710db08..a7d944ce 100644 --- a/jtag/src/bsdl/bsdl_bison.y +++ b/jtag/src/bsdl/bsdl_bison.y @@ -211,7 +211,7 @@ Begin_BSDL : ENTITY IDENTIFIER IS | error {Print_Error(priv_data, _("Improper Entity declaration")); Print_Error(priv_data, _("Check if source file is BSDL")); - YYABORT; /* Probably not a BSDL source file */ + BUMP_ERROR; YYABORT; /* Probably not a BSDL source file */ } ; Part_1 : VHDL_Generic /* 1994 and later */ @@ -916,27 +916,29 @@ static void Store_Text(parser_priv_t *priv_data, char *Source) static void Print_Error(parser_priv_t *priv_data, const char *Errmess) { if (priv_data->Reading_Package) - bsdl_msg(BSDL_MSG_ERR, _("Error in Package %s, Line %d, %s.\n"), + bsdl_msg(BSDL_MSG_ERR, _("In Package %s, Line %d, %s.\n"), priv_data->Package_File_Name, bsdl_flex_get_lineno(priv_data->scanner), Errmess); else - bsdl_msg(BSDL_MSG_ERR, _("Error, Line %d, %s.\n"), - bsdl_flex_get_lineno(priv_data->scanner), - Errmess); + if (priv_data->jtag_ctrl.debug || (priv_data->jtag_ctrl.mode >= 0)) + bsdl_msg(BSDL_MSG_ERR, _("Line %d, %s.\n"), + bsdl_flex_get_lineno(priv_data->scanner), + Errmess); } /*----------------------------------------------------------------------*/ static void Print_Warning(parser_priv_t *priv_data, const char *Warnmess) { if (priv_data->Reading_Package) - bsdl_msg(BSDL_MSG_WARN, _("Warning in Package %s, Line %d, %s.\n"), + bsdl_msg(BSDL_MSG_WARN, _("In Package %s, Line %d, %s.\n"), priv_data->Package_File_Name, bsdl_flex_get_lineno(priv_data->scanner), Warnmess); else - bsdl_msg(BSDL_MSG_WARN, _("Warning, Line %d, %s.\n"), - bsdl_flex_get_lineno(priv_data->scanner), - Warnmess); + if (priv_data->jtag_ctrl.debug || (priv_data->jtag_ctrl.mode >= 0)) + bsdl_msg(BSDL_MSG_WARN, _("Line %d, %s.\n"), + bsdl_flex_get_lineno(priv_data->scanner), + Warnmess); } /*----------------------------------------------------------------------*/ static void Give_Up_And_Quit(parser_priv_t *priv_data) diff --git a/jtag/src/bsdl/bsdl_flex.l b/jtag/src/bsdl/bsdl_flex.l index 7865d40f..137d9b18 100644 --- a/jtag/src/bsdl/bsdl_flex.l +++ b/jtag/src/bsdl/bsdl_flex.l @@ -423,13 +423,13 @@ void *bsdl_flex_init(FILE *f) /* Change input file from STDIN to BSDL file */ /* get our scanner structure */ if (yylex_init(&scanner) != 0) { - bsdl_msg(BSDL_MSG_ERR, _("Scanner could not be initialized\n") ); + bsdl_msg(BSDL_MSG_FATAL, _("Scanner could not be initialized\n") ); return NULL; } yyset_in(f, scanner); if (!(extra = (scan_extra_t *)malloc(sizeof(scan_extra_t)))) { - bsdl_msg(BSDL_MSG_ERR, _("Out of memory, %s line %i\n"), __FILE__, __LINE__); + bsdl_msg(BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__); yylex_destroy(scanner); return NULL; } @@ -469,7 +469,7 @@ static char *new_string(const char *str) strncpy(n_str, str, n_str_size-1); n_str[n_str_size-1] = '\0'; /* set very last element to EOS */ } else - bsdl_msg(BSDL_MSG_ERR, _("Out of memory, %s line %i\n"), __FILE__, __LINE__); + bsdl_msg(BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__); return(n_str); } @@ -509,7 +509,7 @@ void bsdl_flex_switch_file(yyscan_t scanner, char *filename) f = fopen(db_file, "r"); if (!f) - bsdl_msg(BSDL_MSG_ERR, _("Cannot open file %s or %s.\n"), filename, db_file); + bsdl_msg(BSDL_MSG_FATAL, _("Cannot open file %s or %s.\n"), filename, db_file); free(db_file); if (!f) return; @@ -528,8 +528,6 @@ void bsdl_flex_switch_buffer(yyscan_t scanner, const char *buffer) struct yyguts_t * yyg = (struct yyguts_t*)scanner; int lineno; -/* printf("bsdl_flex_switch_buffer(%s)\n", buffer);*/ - lineno = yyget_lineno(scanner); /* yy_scan_string() switches to the string buffer internally, so we must save the current buffer state explicitly by pushing the stack diff --git a/jtag/src/bsdl/bsdl_sem.c b/jtag/src/bsdl/bsdl_sem.c index 1237fb8a..eb960ce2 100644 --- a/jtag/src/bsdl/bsdl_sem.c +++ b/jtag/src/bsdl/bsdl_sem.c @@ -149,7 +149,8 @@ static void free_ainfo_list(struct ainfo_elem *ai) static void free_string_list(struct string_elem *sl) { if (sl) { - free(sl->string); + if (sl->string) + free(sl->string); free_string_list(sl->next); free(sl); } @@ -171,10 +172,22 @@ static void free_string_list(struct string_elem *sl) void bsdl_sem_deinit(parser_priv_t *priv) { struct access_data *ad = &(priv->jtag_ctrl.access_data); + struct port_desc *pd = &(priv->jtag_ctrl.port_desc); - free_ainfo_list(ad->ainfo_list); + if (ad->ainfo_list) { + free_ainfo_list(ad->ainfo_list); + ad->ainfo_list = NULL; + } - free_instr_list(priv->jtag_ctrl.instr_list); + if (priv->jtag_ctrl.instr_list) { + free_instr_list(priv->jtag_ctrl.instr_list); + priv->jtag_ctrl.instr_list = NULL; + } + + if (pd->names_list) { + free_string_list(pd->names_list); + pd->names_list = NULL; + } } @@ -240,7 +253,7 @@ void bsdl_set_instruction_length(parser_priv_t *priv, int len) * * Parameters * priv : private data container for parser related tasks - * name : base name of the port, memory get's free'd + * name : base name of the port, memory get's free'd lateron * * Returns * void @@ -257,7 +270,7 @@ void bsdl_prt_add_name(parser_priv_t *priv, char *name) pd->names_list = new_string; } else - bsdl_msg(BSDL_MSG_ERR, _("Out of memory, %s line %i\n"), __FILE__, __LINE__); + bsdl_msg(BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__); } @@ -369,14 +382,16 @@ void bsdl_prt_apply_port(parser_priv_t *priv) free(port_string); } else - bsdl_msg(BSDL_MSG_ERR, _("Out of memory, %s line %i\n"), __FILE__, __LINE__); + bsdl_msg(BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__); name = name->next; } } - free_string_list(pd->names_list); - pd->names_list = NULL; + if (pd->names_list) { + free_string_list(pd->names_list); + pd->names_list = NULL; + } } @@ -487,7 +502,7 @@ void bsdl_add_instruction(parser_priv_t *priv, char *instr, char *opcode) priv->jtag_ctrl.instr_list = new_instr; } else - bsdl_msg(BSDL_MSG_ERR, _("Out of memory, %s line %i\n"), __FILE__, __LINE__); + bsdl_msg(BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__); } @@ -574,13 +589,13 @@ void bsdl_ci_set_cell_spec(parser_priv_t *priv, ci->port_name = port_string; } else { - bsdl_msg(BSDL_MSG_ERR, _("Out of memory, %s line %i\n"), __FILE__, __LINE__); + bsdl_msg(BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__); ci->port_name = NULL; } free(name->string); free(name); - name = NULL; + priv->jtag_ctrl.port_desc.names_list = NULL; } @@ -703,10 +718,14 @@ void bsdl_ci_apply_cell_info(parser_priv_t *priv, int bit_num) } /* free malloc'ed memory */ - if (ci->port_name) + if (ci->port_name) { free(ci->port_name); - if (ci->basic_safe_value) + ci->port_name = NULL; + } + if (ci->basic_safe_value) { free(ci->basic_safe_value); + ci->basic_safe_value = NULL; + } } @@ -762,7 +781,7 @@ void bsdl_ac_add_instruction(parser_priv_t *priv, char *instr) ad->instr_list = new_instr; } else - bsdl_msg(BSDL_MSG_ERR, _("Out of memory, %s line %i\n"), __FILE__, __LINE__); + bsdl_msg(BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__); } @@ -793,7 +812,7 @@ void bsdl_ac_apply_assoc(parser_priv_t *priv) ad->ainfo_list = new_ainfo; } else - bsdl_msg(BSDL_MSG_ERR, _("Out of memory, %s line %i\n"), __FILE__, __LINE__); + bsdl_msg(BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__); /* clean up obsolete temporary entries */ ad->reg = NULL; diff --git a/jtag/src/cmd/include.c b/jtag/src/cmd/include.c index 656bf3ac..4cd056d5 100644 --- a/jtag/src/cmd/include.c +++ b/jtag/src/cmd/include.c @@ -31,6 +31,7 @@ #include "jtag.h" #include "cmd.h" +#include "bsdl.h" static int cmd_include_run( char *params[] ) @@ -43,7 +44,7 @@ cmd_include_run( char *params[] ) return -1; /* If "params[1]" begins with a slash, or dots followed by a slash, - * assume that user wants to ignore the search path */ + * assume that user wants to ignore the search path */ path = params[1]; while( *path == '.' ) path++; @@ -64,6 +65,18 @@ cmd_include_run( char *params[] ) return 1; } +#ifdef ENABLE_BSDL + /* perform a test read to check for BSDL syntax */ + if (bsdl_read_file( path, -1, NULL ) >= 0) + { + /* it seems to be a proper BSDL file, so re-read and execute */ + go = bsdl_read_file( path, 1, NULL ); + + free( path ); + return go >= 0 ? 1 : 0; + } +#endif + if (cmd_params( params ) > 2) { sscanf(params[2],"%d",&j); /* loop n times option */ };