Dirk Behme> In [1] Rick proposed
Dirk Behme> "... that the C function for the irscan and drscan
Dirk Behme> commands needs to look for another argument
Dirk Behme> (namely the end state) and add a call to
Dirk Behme> jtag_set_end_state.  This might also be
Dirk Behme> handled already with a 'end_state' command. "

Dirk/Kees,

Is this what you are talking about? Please try the attached **UNTESTED** PATCH... It compiles....

This patch adds 2 options to the IRSCAN and DRSCAN commands, '-endstate NAME'

I don't understand/know enough details of what exactly is going on with the OMAP icepick, but the attached (UNTESTED, I KNOW IT COMPILES) patch attempts to do basically what rick suggested.

-Duane.

Index: openocd/src/jtag/jtag.c
===================================================================
--- openocd/src/jtag/jtag.c     (revision 1394)
+++ openocd/src/jtag/jtag.c     (working copy)
@@ -2650,7 +2650,7 @@
 
 int handle_endstate_command(struct command_context_s *cmd_ctx, char *cmd, char 
**args, int argc)
 {
-       tap_state_t state;
+       int state;
 
        if (argc < 1)
        {
@@ -2658,14 +2658,13 @@
        }
        else
        {
-               for (state = 0; state < 16; state++)
-               {
-                       if (strcmp(args[0], tap_state_name(state)) == 0)
-                       {
-                               jtag_add_end_state(state);
-                               jtag_execute_queue();
-                       }
+               state = tap_state_by_name( args[0] );
+               if( state < 0 ){
+                       command_print( cmd_ctx, "Invalid state name: %s\n", 
args[0] );
+                       return ERROR_COMMAND_SYNTAX_ERROR;
                }
+               jtag_add_end_state( (tap_state_t)(state));
+               jtag_execute_queue();
        }
        command_print(cmd_ctx, "current endstate: %s", 
tap_state_name(cmd_queue_end_state));
 
@@ -2728,12 +2727,41 @@
        int i;
        scan_field_t *fields;
        jtag_tap_t *tap;
+       int endstate;
 
        if ((argc < 2) || (argc % 2))
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
+       // optional "-endstate"
+       //          "statename"
+       // at the end of the arguments.
+       // assume none.
+       endstate = -1;
+       if( argc >= 4 ){
+               // have at least one pair of numbers.
+               // is last pair the magic text?
+               if( 0 == strcmp( "-endstate", args[ argc - 2 ] ) ){
+                       const char *cpA;
+                       const char *cpS;
+                       cpA = args[ argc-1 ];
+                       for( endstate = 0 ; endstate < 16 ; endstate++ ){
+                               cpS = tap_state_name( endstate );
+                               if( 0 == strcmp( cpA, cpS ) ){
+                                       break;
+                               }
+                       }
+                       if( endstate >= 16 ){
+                               return ERROR_COMMAND_SYNTAX_ERROR;
+                       } else {
+                               // found - remove the last 2 args
+                               argc -= 2;
+                       }
+               }
+       }
+
+
        fields = malloc(sizeof(scan_field_t) * argc / 2);
 
        for (i = 0; i < argc / 2; i++)
@@ -2756,6 +2784,10 @@
        }
 
        jtag_add_ir_scan(argc / 2, fields, -1);
+       // did we have an endstate?
+       if( endstate >= 0 ){
+               jtag_add_end_state(endstate);
+       }
        jtag_execute_queue();
 
        for (i = 0; i < argc / 2; i++)
@@ -2774,11 +2806,16 @@
        int field_count = 0;
        int i, e;
        jtag_tap_t *tap;
+       int endstate;
 
        /* args[1] = device
         * args[2] = num_bits
         * args[3] = hex string
         * ... repeat num bits and hex string ...
+        * 
+        * .. optionally:
+     *     args[N-2] = "-endstate"
+        *     args[N-1] = statename
         */
        if ((argc < 4) || ((argc % 2)!=0))
        {
@@ -2786,15 +2823,56 @@
                return JIM_ERR;
        }
 
+       /* assume no endstate */
+       endstate = -1;
+       // validate arguments as numbers
+       e = JIM_OK;
        for (i = 2; i < argc; i+=2)
        {
                long bits;
+               const char *cp;
+               
 
                e = Jim_GetLong(interp, args[i], &bits);
-               if (e != JIM_OK)
+               /* If valid - try next arg */
+               if( e == JIM_OK ){
+                       continue;
+               }
+
+               /* Not valid.. are we at the end? */
+               if ( ((i+2) != argc) ){
+                       /* nope, then error */
                        return e;
-       }
+               }
 
+               /* it could be: "-endstate FOO" */
+
+               /* get arg as a string. */
+               cp = Jim_GetString( args[i], NULL );
+               /* is it the magic? */
+               if( 0 == strcmp( "-endstate", cp ) ){
+                       /* is the statename valid? */
+                       cp = Jim_GetString( args[i+1], NULL );
+
+                       /* see if it is a valid state name */
+                       endstate = tap_state_by_name(cp);
+                       if( endstate < 0 ){
+                               /* update the error message */
+                               Jim_SetResult_sprintf(interp,"endstate: %s 
invalid", cp );
+                       } else {
+                               /* valid - so clear the error */
+                               e = JIM_OK;
+                               /* and remove the last 2 args */
+                               argc -= 2;
+                       }
+               }
+
+               /* Still an error? */
+               if( e != JIM_OK ){
+                       return e; /* too bad */
+               } 
+       } /* validate args */
+
        tap = jtag_TapByJimObj( interp, args[1] );
        if( tap == NULL ){
                return JIM_ERR;
@@ -2822,8 +2900,12 @@
                fields[field_count].in_handler = NULL;
                fields[field_count++].in_handler_priv = NULL;
        }
-
+               
        jtag_add_dr_scan(num_fields, fields, -1);
+       // did we get an end state?
+       if( endstate >= 0 ){
+               jtag_add_end_state( (tap_state_t)endstate );
+       }
        retval = jtag_execute_queue();
        if (retval != ERROR_OK)
        {
@@ -3189,4 +3271,19 @@
        return ret;
 }
 
+int
+tap_state_by_name( const char *name )
+{
+       int x;
+       
+       for( x = 0 ; x < 16 ; x++ ){
+               /* be nice to the human */
+               if( 0 == strcasecmp( name, tap_state_name(x) ) ){
+                       return x;
+               }
+       }
+       /* not found */
+       return -1;
+}
+
 /*-----</Cable Helper API>--------------------------------------*/
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to