- Replace 'while(' with 'while ('.
[openocd.git] / src / jtag / tcl.c
index 121c19abca4b698783716d096c0fd266777848f0..75153636331de5b1fc12c970851a286765a3bf63 100644 (file)
 #include <strings.h>
 #endif
 
-extern bool hasKHz;
+static const Jim_Nvp nvp_jtag_tap_event[] = {
+       { .value = JTAG_TAP_EVENT_ENABLE,       .name = "tap-enable" },
+       { .value = JTAG_TAP_EVENT_DISABLE,      .name = "tap-disable" },
 
-extern const Jim_Nvp nvp_jtag_tap_event[];
+       { .name = NULL, .value = -1 }
+};
 
 /* jtag interfaces (parport, FTDI-USB, TI-USB, ...)
  */
 
-#if BUILD_ECOSBOARD == 1
+#if BUILD_ZY1000 == 1
        extern jtag_interface_t zy1000_interface;
 #elif defined(BUILD_MINIDRIVER_DUMMY)
        extern jtag_interface_t minidummy_interface;
@@ -116,7 +119,7 @@ extern const Jim_Nvp nvp_jtag_tap_event[];
  * or some number of standard driver interfaces, never both.
  */
 jtag_interface_t *jtag_interfaces[] = {
-#if BUILD_ECOSBOARD == 1
+#if BUILD_ZY1000 == 1
        &zy1000_interface,
 #elif defined(BUILD_MINIDRIVER_DUMMY)
        &minidummy_interface,
@@ -167,7 +170,6 @@ jtag_interface_t *jtag_interfaces[] = {
        NULL,
 };
 
-extern struct jtag_interface_s *jtag;
 extern jtag_interface_t *jtag_interface;
 
 /* jtag commands */
@@ -187,6 +189,7 @@ static int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cm
 static int handle_runtest_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 static int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
+static int Jim_Command_pathmove(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
 static int Jim_Command_flush_count(Jim_Interp *interp, int argc, Jim_Obj *const *args);
 
 static int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
@@ -253,7 +256,7 @@ static int jtag_tap_configure_cmd( Jim_GetOptInfo *goi, jtag_tap_t * tap)
                                        jteap = tap->event_action;
                                        /* replace existing? */
                                        while (jteap) {
-                                               if (jteap->event == (enum jtag_tap_event)n->value) {
+                                               if (jteap->event == (enum jtag_event)n->value) {
                                                        break;
                                                }
                                                jteap = jteap->next;
@@ -293,9 +296,15 @@ static int jtag_tap_configure_cmd( Jim_GetOptInfo *goi, jtag_tap_t * tap)
        return JIM_OK;
 }
 
+static int is_bad_irval(int ir_length, jim_wide w)
+{
+       jim_wide v = 1;
 
-extern void jtag_tap_init(jtag_tap_t *tap);
-extern void jtag_tap_free(jtag_tap_t *tap);
+       v <<= ir_length;
+       v -= 1;
+       v = ~v;
+       return (w & v) != 0;
+}
 
 static int jim_newtap_cmd( Jim_GetOptInfo *goi )
 {
@@ -322,16 +331,16 @@ static int jim_newtap_cmd( Jim_GetOptInfo *goi )
                { .name = NULL                          ,       .value = -1 },
        };
 
-       pTap = malloc( sizeof(jtag_tap_t) );
-       memset( pTap, 0, sizeof(*pTap) );
-       if( !pTap ){
-               Jim_SetResult_sprintf( goi->interp, "no memory");
+       pTap = calloc(1, sizeof(jtag_tap_t));
+       if (!pTap) {
+               Jim_SetResult_sprintf(goi->interp, "no memory");
                return JIM_ERR;
        }
+
        /*
         * we expect CHIP + TAP + OPTIONS
         * */
-       if( goi->argc < 3 ){
+       if ( goi->argc < 3 ){
                Jim_SetResult_sprintf(goi->interp, "Missing CHIP TAP OPTIONS ....");
                return JIM_ERR;
        }
@@ -350,9 +359,6 @@ static int jim_newtap_cmd( Jim_GetOptInfo *goi )
        LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
                          pTap->chip, pTap->tapname, pTap->dotted_name, goi->argc);
 
-       /* default is enabled */
-       pTap->enabled = 1;
-
        /* deal with options */
 #define NTREQ_IRLEN      1
 #define NTREQ_IRCAPTURE  2
@@ -361,37 +367,37 @@ static int jim_newtap_cmd( Jim_GetOptInfo *goi )
        /* clear them as we find them */
        reqbits = (NTREQ_IRLEN | NTREQ_IRCAPTURE | NTREQ_IRMASK);
 
-       while( goi->argc ){
+       while ( goi->argc ){
                e = Jim_GetOpt_Nvp( goi, opts, &n );
-               if( e != JIM_OK ){
+               if ( e != JIM_OK ){
                        Jim_GetOpt_NvpUnknown( goi, opts, 0 );
                        return e;
                }
                LOG_DEBUG("Processing option: %s", n->name );
                switch( n->value ){
                case NTAP_OPT_ENABLED:
-                       pTap->enabled = 1;
+                       pTap->disabled_after_reset = false;
                        break;
                case NTAP_OPT_DISABLED:
-                       pTap->enabled = 0;
+                       pTap->disabled_after_reset = true;
                        break;
                case NTAP_OPT_EXPECTED_ID:
                {
-                       u32 *new_expected_ids;
+                       uint32_t *new_expected_ids;
 
                        e = Jim_GetOpt_Wide( goi, &w );
-                       if( e != JIM_OK) {
+                       if ( e != JIM_OK) {
                                Jim_SetResult_sprintf(goi->interp, "option: %s bad parameter", n->name);
                                return e;
                        }
 
-                       new_expected_ids = malloc(sizeof(u32) * (pTap->expected_ids_cnt + 1));
+                       new_expected_ids = malloc(sizeof(uint32_t) * (pTap->expected_ids_cnt + 1));
                        if (new_expected_ids == NULL) {
                                Jim_SetResult_sprintf( goi->interp, "no memory");
                                return JIM_ERR;
                        }
 
-                       memcpy(new_expected_ids, pTap->expected_ids, sizeof(u32) * pTap->expected_ids_cnt);
+                       memcpy(new_expected_ids, pTap->expected_ids, sizeof(uint32_t) * pTap->expected_ids_cnt);
 
                        new_expected_ids[pTap->expected_ids_cnt] = w;
 
@@ -404,32 +410,41 @@ static int jim_newtap_cmd( Jim_GetOptInfo *goi )
                case NTAP_OPT_IRMASK:
                case NTAP_OPT_IRCAPTURE:
                        e = Jim_GetOpt_Wide( goi, &w );
-                       if( e != JIM_OK ){
+                       if ( e != JIM_OK ){
                                Jim_SetResult_sprintf( goi->interp, "option: %s bad parameter", n->name );
                                return e;
                        }
-                       if( (w < 0) || (w > 0xffff) ){
-                               /* wacky value */
-                               Jim_SetResult_sprintf( goi->interp, "option: %s - wacky value: %d (0x%x)",
-                                                                          n->name, (int)(w), (int)(w));
-                               return JIM_ERR;
-                       }
                        switch(n->value){
                        case NTAP_OPT_IRLEN:
+                               if (w > (jim_wide) (8 * sizeof(pTap->ir_capture_value)))
+                                       LOG_WARNING("huge IR length %d", (int) w);
                                pTap->ir_length = w;
                                reqbits &= (~(NTREQ_IRLEN));
                                break;
                        case NTAP_OPT_IRMASK:
+                               if (is_bad_irval(pTap->ir_length, w)) {
+                                       LOG_ERROR("IR mask %x too big",
+                                                       (int) w);
+                                       return ERROR_FAIL;
+                               }
                                pTap->ir_capture_mask = w;
                                reqbits &= (~(NTREQ_IRMASK));
                                break;
                        case NTAP_OPT_IRCAPTURE:
+                               if (is_bad_irval(pTap->ir_length, w)) {
+                                       LOG_ERROR("IR capture %x too big",
+                                                       (int) w);
+                                       return ERROR_FAIL;
+                               }
                                pTap->ir_capture_value = w;
                                reqbits &= (~(NTREQ_IRCAPTURE));
                                break;
                        }
                } /* switch(n->value) */
-       } /* while( goi->argc ) */
+       } /* while ( goi->argc ) */
+
+       /* default is enabled-after-reset */
+       pTap->enabled = !pTap->disabled_after_reset;
 
        /* Did all the required option bits get cleared? */
        if (0 == reqbits)
@@ -445,6 +460,44 @@ static int jim_newtap_cmd( Jim_GetOptInfo *goi )
        return JIM_ERR;
 }
 
+static void jtag_tap_handle_event(jtag_tap_t *tap, enum jtag_event e)
+{
+       jtag_tap_event_action_t * jteap;
+       int done;
+
+       jteap = tap->event_action;
+
+       done = 0;
+       while (jteap) {
+               if (jteap->event == e) {
+                       done = 1;
+                       LOG_DEBUG( "JTAG tap: %s event: %d (%s) action: %s\n",
+                                       tap->dotted_name,
+                                       e,
+                                       Jim_Nvp_value2name_simple(nvp_jtag_tap_event, e)->name,
+                                       Jim_GetString(jteap->body, NULL) );
+                       if (Jim_EvalObj(interp, jteap->body) != JIM_OK) {
+                               Jim_PrintErrorMessage(interp);
+                       } else {
+                               /* NOTE:  we currently assume the handlers
+                                * can't fail.  That presumes later code
+                                * will be verifying the scan chains ...
+                                */
+                               tap->enabled = (e == JTAG_TAP_EVENT_ENABLE);
+                       }
+               }
+
+               jteap = jteap->next;
+       }
+
+       if (!done) {
+               LOG_DEBUG( "event %d %s - no action",
+                               e,
+                               Jim_Nvp_value2name_simple( nvp_jtag_tap_event, e)->name);
+       }
+}
+
+
 static int jim_jtag_command( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
 {
        Jim_GetOptInfo goi;
@@ -482,7 +535,7 @@ static int jim_jtag_command( Jim_Interp *interp, int argc, Jim_Obj *const *argv
        Jim_GetOpt_Setup( &goi, interp, argc-1, argv+1 );
 
        e = Jim_GetOpt_Nvp( &goi, jtag_cmds, &n );
-       if( e != JIM_OK ){
+       if ( e != JIM_OK ){
                Jim_GetOpt_NvpUnknown( &goi, jtag_cmds, 0 );
                return e;
        }
@@ -492,19 +545,19 @@ static int jim_jtag_command( Jim_Interp *interp, int argc, Jim_Obj *const *argv
                /* return the name of the interface */
                /* TCL code might need to know the exact type... */
                /* FUTURE: we allow this as a means to "set" the interface. */
-               if( goi.argc != 0 ){
+               if ( goi.argc != 0 ){
                        Jim_WrongNumArgs( goi.interp, 1, goi.argv-1, "(no params)");
                        return JIM_ERR;
                }
                Jim_SetResultString( goi.interp, jtag_interface->name, -1 );
                return JIM_OK;
        case JTAG_CMD_INIT_RESET:
-               if( goi.argc != 0 ){
+               if ( goi.argc != 0 ){
                        Jim_WrongNumArgs( goi.interp, 1, goi.argv-1, "(no params)");
                        return JIM_ERR;
                }
                e = jtag_init_reset(context);
-               if( e != ERROR_OK ){
+               if ( e != ERROR_OK ){
                        Jim_SetResult_sprintf( goi.interp, "error: %d", e);
                        return JIM_ERR;
                }
@@ -515,39 +568,58 @@ static int jim_jtag_command( Jim_Interp *interp, int argc, Jim_Obj *const *argv
        case JTAG_CMD_TAPISENABLED:
        case JTAG_CMD_TAPENABLE:
        case JTAG_CMD_TAPDISABLE:
-               if( goi.argc != 1 ){
+               if ( goi.argc != 1 ){
                        Jim_SetResultString( goi.interp, "Too many parameters",-1 );
                        return JIM_ERR;
                }
 
                {
                        jtag_tap_t *t;
-                       t = jtag_tap_by_jim_obj( goi.interp, goi.argv[0] );
-                       if( t == NULL ){
+
+                       t = jtag_tap_by_jim_obj(goi.interp, goi.argv[0]);
+                       if (t == NULL)
                                return JIM_ERR;
-                       }
-                       switch( n->value ){
+
+                       switch (n->value) {
                        case JTAG_CMD_TAPISENABLED:
-                               e = t->enabled;
                                break;
                        case JTAG_CMD_TAPENABLE:
-                               jtag_tap_handle_event( t, JTAG_TAP_EVENT_ENABLE);
-                               e = 1;
-                               t->enabled = e;
+                               if (t->enabled)
+                                       break;
+                               jtag_tap_handle_event(t, JTAG_TAP_EVENT_ENABLE);
+                               if (!t->enabled)
+                                       break;
+
+                               /* FIXME add JTAG sanity checks, w/o TLR
+                                *  - scan chain length grew by one (this)
+                                *  - IDs and IR lengths are as expected
+                                */
+
+                               jtag_call_event_callbacks(JTAG_TAP_EVENT_ENABLE);
                                break;
                        case JTAG_CMD_TAPDISABLE:
-                               jtag_tap_handle_event( t, JTAG_TAP_EVENT_DISABLE);
-                               e = 0;
-                               t->enabled = e;
+                               if (!t->enabled)
+                                       break;
+                               jtag_tap_handle_event(t, JTAG_TAP_EVENT_DISABLE);
+                               if (t->enabled)
+                                       break;
+
+                               /* FIXME add JTAG sanity checks, w/o TLR
+                                *  - scan chain length shrank by one (this)
+                                *  - IDs and IR lengths are as expected
+                                */
+
+                               jtag_call_event_callbacks(JTAG_TAP_EVENT_DISABLE);
                                break;
                        }
-                       Jim_SetResult( goi.interp, Jim_NewIntObj( goi.interp, e ) );
+                       e = t->enabled;
+                       Jim_SetResult(goi.interp, Jim_NewIntObj(goi.interp, e));
                        return JIM_OK;
                }
                break;
 
        case JTAG_CMD_CGET:
-               if( goi.argc < 2 ){
+               if ( goi.argc < 2 ){
                        Jim_WrongNumArgs( goi.interp, 0, NULL, "?tap-name? -option ...");
                        return JIM_ERR;
                }
@@ -557,7 +629,7 @@ static int jim_jtag_command( Jim_Interp *interp, int argc, Jim_Obj *const *argv
 
                        Jim_GetOpt_Obj(&goi, &o);
                        t = jtag_tap_by_jim_obj( goi.interp, o );
-                       if( t == NULL ){
+                       if ( t == NULL ){
                                return JIM_ERR;
                        }
 
@@ -567,7 +639,7 @@ static int jim_jtag_command( Jim_Interp *interp, int argc, Jim_Obj *const *argv
                break;
 
        case JTAG_CMD_CONFIGURE:
-               if( goi.argc < 3 ){
+               if ( goi.argc < 3 ){
                        Jim_WrongNumArgs( goi.interp, 0, NULL, "?tap-name? -option ?VALUE? ...");
                        return JIM_ERR;
                }
@@ -577,7 +649,7 @@ static int jim_jtag_command( Jim_Interp *interp, int argc, Jim_Obj *const *argv
 
                        Jim_GetOpt_Obj(&goi, &o);
                        t = jtag_tap_by_jim_obj( goi.interp, o );
-                       if( t == NULL ){
+                       if ( t == NULL ){
                                return JIM_ERR;
                        }
 
@@ -624,6 +696,7 @@ int jtag_register_commands(struct command_context_s *cmd_ctx)
                COMMAND_EXEC, "execute IR scan <device> <instr> [dev2] [instr2] ...");
        register_jim(cmd_ctx, "drscan", Jim_Command_drscan, "execute DR scan <device> <num_bits> <value> <num_bits1> <value2> ...");
        register_jim(cmd_ctx, "flush_count", Jim_Command_flush_count, "returns number of times the JTAG queue has been flushed");
+       register_jim(cmd_ctx, "pathmove", Jim_Command_pathmove, "move JTAG to state1 then to state2, state3, etc. <state1>,<state2>,<stat3>...");
 
        register_command(cmd_ctx, NULL, "verify_ircapture", handle_verify_ircapture_command,
                COMMAND_ANY, "verify value captured during Capture-IR <enable|disable>");
@@ -733,7 +806,7 @@ static int handle_jtag_device_command(struct command_context_s *cmd_ctx, char *c
         * argv[ 3] = not actually used by anything but in the docs
         */
 
-       if( argc < 4 ){
+       if ( argc < 4 ){
                command_print( cmd_ctx, "OLD DEPRECATED SYNTAX: Please use the NEW syntax");
                return ERROR_OK;
        }
@@ -774,7 +847,7 @@ static int handle_jtag_device_command(struct command_context_s *cmd_ctx, char *c
                         Jim_GetString( newargs[9], NULL ) );
 
        e = jim_jtag_command( interp, 10, newargs );
-       if( e != JIM_OK ){
+       if ( e != JIM_OK ){
                command_print( cmd_ctx, "%s", Jim_GetString( Jim_GetResult(interp), NULL ) );
        }
        return e;
@@ -788,8 +861,8 @@ static int handle_scan_chain_command(struct command_context_s *cmd_ctx, char *cm
        command_print(cmd_ctx, "     TapName            | Enabled |   IdCode      Expected    IrLen IrCap  IrMask Instr     ");
        command_print(cmd_ctx, "---|--------------------|---------|------------|------------|------|------|------|---------");
 
-       while( tap ){
-               u32 expected, expected_mask, cur_instr, ii;
+       while ( tap ){
+               uint32_t expected, expected_mask, cur_instr, ii;
                expected = buf_get_u32(tap->expected, 0, tap->ir_length);
                expected_mask = buf_get_u32(tap->expected_mask, 0, tap->ir_length);
                cur_instr = buf_get_u32(tap->cur_instr, 0, tap->ir_length);
@@ -799,16 +872,16 @@ static int handle_scan_chain_command(struct command_context_s *cmd_ctx, char *cm
                                          tap->abs_chain_position,
                                          tap->dotted_name,
                                          tap->enabled ? 'Y' : 'n',
-                                         tap->idcode,
-                                         (tap->expected_ids_cnt > 0 ? tap->expected_ids[0] : 0),
-                                         tap->ir_length,
-                                         expected,
-                                         expected_mask,
-                                         cur_instr);
+                                         (unsigned int)(tap->idcode),
+                                         (unsigned int)(tap->expected_ids_cnt > 0 ? tap->expected_ids[0] : 0),
+                                         (unsigned int)(tap->ir_length),
+                                         (unsigned int)(expected),
+                                         (unsigned int)(expected_mask),
+                                         (unsigned int)(cur_instr));
 
                for (ii = 1; ii < tap->expected_ids_cnt; ii++) {
                        command_print(cmd_ctx, "   |                    |         |            | 0x%08x |      |      |      |         ",
-                                                 tap->expected_ids[ii]);
+                                                 (unsigned int)(tap->expected_ids[ii]));
                }
 
                tap = tap->next_tap;
@@ -935,7 +1008,13 @@ static int handle_jtag_nsrst_delay_command(struct command_context_s *cmd_ctx,
        if (argc > 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
        if (argc == 1)
-               jtag_set_nsrst_delay(strtoul(args[0], NULL, 0));
+       {
+               unsigned delay;
+               int retval = parse_uint(args[0], &delay);
+               if (ERROR_OK != retval)
+                       return retval;
+               jtag_set_nsrst_delay(delay);
+       }
        command_print(cmd_ctx, "jtag_nsrst_delay: %u", jtag_get_nsrst_delay());
        return ERROR_OK;
 }
@@ -946,7 +1025,13 @@ static int handle_jtag_ntrst_delay_command(struct command_context_s *cmd_ctx,
        if (argc > 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
        if (argc == 1)
-               jtag_set_ntrst_delay(strtoul(args[0], NULL, 0));
+       {
+               unsigned delay;
+               int retval = parse_uint(args[0], &delay);
+               if (ERROR_OK != retval)
+                       return retval;
+               jtag_set_ntrst_delay(delay);
+       }
        command_print(cmd_ctx, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay());
        return ERROR_OK;
 }
@@ -961,8 +1046,10 @@ static int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cm
        {
                LOG_DEBUG("handle jtag speed");
 
-               int cur_speed = 0;
-               cur_speed = strtoul(args[0], NULL, 0);
+               unsigned cur_speed = 0;
+               int retval = parse_uint(args[0], &cur_speed);
+               if (ERROR_OK != retval)
+                       return retval;
                retval = jtag_set_speed(cur_speed);
 
        }
@@ -977,44 +1064,28 @@ static int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd,
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        int retval = ERROR_OK;
-       int cur_speed = 0;
        if (argc == 1)
        {
-               LOG_DEBUG("handle jtag khz");
-
-               jtag_set_speed_khz(strtoul(args[0], NULL, 0));
-               if (jtag != NULL)
-               {
-                       LOG_DEBUG("have interface set up");
-                       int speed_div1;
-                       retval = jtag->khz(jtag_get_speed_khz(), &speed_div1);
-                       if (ERROR_OK != retval)
-                       {
-                               jtag_set_speed_khz(0);
-                               return retval;
-                       }
-                       cur_speed = speed_div1;
-
-                       retval = jtag_set_speed(cur_speed);
-               }
-               else
-                       hasKHz = true;
-       }
-
-       cur_speed = jtag_get_speed_khz();
-       if (jtag != NULL)
-       {
-               retval = jtag->speed_div(jtag_get_speed(), &cur_speed);
+               unsigned khz = 0;
+               int retval = parse_uint(args[0], &khz);
+               if (ERROR_OK != retval)
+                       return retval;
+               retval = jtag_config_khz(khz);
                if (ERROR_OK != retval)
                        return retval;
        }
 
+       int cur_speed = jtag_get_speed_khz();
+       retval = jtag_get_speed_readable(&cur_speed);
+       if (ERROR_OK != retval)
+               return retval;
+
        if (cur_speed)
                command_print(cmd_ctx, "%d kHz", cur_speed);
        else
                command_print(cmd_ctx, "RCLK - adaptive");
-       return retval;
 
+       return retval;
 }
 
 static int handle_jtag_reset_command(struct command_context_s *cmd_ctx,
@@ -1054,7 +1125,12 @@ static int handle_runtest_command(struct command_context_s *cmd_ctx,
        if (argc != 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       jtag_add_runtest(strtol(args[0], NULL, 0), jtag_get_end_state());
+       unsigned num_clocks;
+       int retval = parse_uint(args[0], &num_clocks);
+       if (ERROR_OK != retval)
+               return retval;
+
+       jtag_add_runtest(num_clocks, TAP_IDLE);
        jtag_execute_queue();
 
        return ERROR_OK;
@@ -1098,20 +1174,20 @@ static int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, c
         */
        endstate = TAP_IDLE;
 
-       if( argc >= 4 ){
+       if ( argc >= 4 ){
                /* have at least one pair of numbers. */
                /* is last pair the magic text? */
-               if( 0 == strcmp( "-endstate", args[ argc - 2 ] ) ){
+               if ( 0 == strcmp( "-endstate", args[ argc - 2 ] ) ){
                        const char *cpA;
                        const char *cpS;
                        cpA = args[ argc-1 ];
                        for( endstate = 0 ; endstate < TAP_NUM_STATES ; endstate++ ){
                                cpS = tap_state_name( endstate );
-                               if( 0 == strcmp( cpA, cpS ) ){
+                               if ( 0 == strcmp( cpA, cpS ) ){
                                        break;
                                }
                        }
-                       if( endstate >= TAP_NUM_STATES ){
+                       if ( endstate >= TAP_NUM_STATES ){
                                return ERROR_COMMAND_SYNTAX_ERROR;
                        } else {
                                if (!scan_is_safe(endstate))
@@ -1124,9 +1200,11 @@ static int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, c
        }
 
        int num_fields = argc / 2;
+       size_t fields_len = sizeof(scan_field_t) * num_fields;
+       fields = malloc(fields_len);
+       memset(fields, 0, fields_len);
 
-       fields = malloc(sizeof(scan_field_t) * num_fields);
-
+       int retval;
        for (i = 0; i < num_fields; i++)
        {
                tap = jtag_tap_by_string( args[i*2] );
@@ -1139,17 +1217,26 @@ static int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, c
                fields[i].tap = tap;
                fields[i].num_bits = field_size;
                fields[i].out_value = malloc(CEIL(field_size, 8));
-               buf_set_u32(fields[i].out_value, 0, field_size, strtoul(args[i*2+1], NULL, 0));
+
+               uint32_t value;
+               retval = parse_u32(args[i * 2 + 1], &value);
+               if (ERROR_OK != retval)
+                       goto error_return;
+               buf_set_u32(fields[i].out_value, 0, field_size, value);
                fields[i].in_value = NULL;
        }
 
        /* did we have an endstate? */
        jtag_add_ir_scan(num_fields, fields, endstate);
 
-       int retval=jtag_execute_queue();
+       retval = jtag_execute_queue();
 
+error_return:
        for (i = 0; i < num_fields; i++)
-               free(fields[i].out_value);
+       {
+               if (NULL != fields[i].out_value)
+                       free(fields[i].out_value);
+       }
 
        free (fields);
 
@@ -1183,6 +1270,8 @@ static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args
 
        endstate = TAP_IDLE;
 
+       script_debug(interp, "drscan", argc, args);
+
        /* validate arguments as numbers */
        e = JIM_OK;
        for (i = 2; i < argc; i+=2)
@@ -1192,7 +1281,7 @@ static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args
 
                e = Jim_GetLong(interp, args[i], &bits);
                /* If valid - try next arg */
-               if( e == JIM_OK ){
+               if ( e == JIM_OK ){
                        continue;
                }
 
@@ -1210,13 +1299,13 @@ static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args
                /* get arg as a string. */
                cp = Jim_GetString( args[i], NULL );
                /* is it the magic? */
-               if( 0 == strcmp( "-endstate", cp ) ){
+               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 ){
+                       if ( endstate < 0 ){
                                /* update the error message */
                                Jim_SetResult_sprintf(interp,"endstate: %s invalid", cp );
                        } else {
@@ -1232,13 +1321,13 @@ static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args
                }
 
                /* Still an error? */
-               if( e != JIM_OK ){
+               if ( e != JIM_OK ){
                        return e; /* too bad */
                }
        } /* validate args */
 
        tap = jtag_tap_by_jim_obj( interp, args[1] );
-       if( tap == NULL ){
+       if ( tap == NULL ){
                return JIM_ERR;
        }
 
@@ -1294,8 +1383,54 @@ static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args
 }
 
 
+static int Jim_Command_pathmove(Jim_Interp *interp, int argc, Jim_Obj *const *args)
+{
+       tap_state_t states[8];
+
+       if ((argc < 2) || ((size_t)argc > (sizeof(states)/sizeof(*states)+1)))
+       {
+               Jim_WrongNumArgs(interp, 1, args, "wrong arguments");
+               return JIM_ERR;
+       }
+
+       script_debug(interp, "pathmove", argc, args);
+
+       int i;
+       for (i=0; i<argc-1; i++)
+       {
+               const char *cp;
+               cp = Jim_GetString( args[i+1], NULL );
+               states[i] = tap_state_by_name(cp);
+               if ( states[i] < 0 )
+               {
+                       /* update the error message */
+                       Jim_SetResult_sprintf(interp,"endstate: %s invalid", cp );
+                       return JIM_ERR;
+               }
+       }
+
+       if ((jtag_add_statemove(states[0]) != ERROR_OK) || ( jtag_execute_queue()!= ERROR_OK))
+       {
+               Jim_SetResultString(interp, "pathmove: jtag execute failed",-1);
+               return JIM_ERR;
+       }
+
+       jtag_add_pathmove(argc-2, states+1);
+
+       if (jtag_execute_queue()!= ERROR_OK)
+       {
+               Jim_SetResultString(interp, "pathmove: failed",-1);
+               return JIM_ERR;
+       }
+
+       return JIM_OK;
+}
+
+
 static int Jim_Command_flush_count(Jim_Interp *interp, int argc, Jim_Obj *const *args)
 {
+       script_debug(interp, "flush_count", argc, args);
+
        Jim_SetResult(interp, Jim_NewIntObj(interp, jtag_get_flush_queue_count()));
 
        return JIM_OK;
@@ -1304,25 +1439,21 @@ static int Jim_Command_flush_count(Jim_Interp *interp, int argc, Jim_Obj *const
 
 static int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
+       if (argc > 1)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
        if (argc == 1)
        {
                if (strcmp(args[0], "enable") == 0)
-               {
-                       jtag_verify_capture_ir = 1;
-               }
+                       jtag_set_verify_capture_ir(true);
                else if (strcmp(args[0], "disable") == 0)
-               {
-                       jtag_verify_capture_ir = 0;
-               } else
-               {
+                       jtag_set_verify_capture_ir(false);
+               else
                        return ERROR_COMMAND_SYNTAX_ERROR;
-               }
-       } else if (argc != 0)
-       {
-               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
-       command_print(cmd_ctx, "verify Capture-IR is %s", (jtag_verify_capture_ir) ? "enabled": "disabled");
+       const char *status = jtag_will_verify_capture_ir() ? "enabled": "disabled";
+       command_print(cmd_ctx, "verify Capture-IR is %s", status);
 
        return ERROR_OK;
 }
@@ -1371,4 +1502,3 @@ static int handle_tms_sequence_command(struct command_context_s *cmd_ctx, char *
 
        return ERROR_OK;
 }
-

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)