Change tap_state naming to be consistent with SVF documentation.
[openocd.git] / src / xsvf / xsvf.c
index d732871a5fc5e6dd1bbfb0132075d741e4e43405..1f594be56152ebe5dc06de8a75e570f174580cbd 100644 (file)
@@ -5,6 +5,9 @@
  *   Copyright (C) 2007,2008 Ã˜yvind Harboe                                 *
  *   oyvind.harboe@zylin.com                                               *
  *                                                                         *
+ *   Copyright (C) 2008 Peter Hettkamp                                     *
+ *   peter.hettkamp@htp-tel.de                                             *
+ *                                                                         *
  *   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     *
@@ -59,9 +62,9 @@ int xenddr = 0;
 
 enum tap_state xsvf_to_tap[] =
 {
-       TAP_TLR, TAP_RTI,
-       TAP_SDS, TAP_CD, TAP_SD, TAP_E1D, TAP_PD, TAP_E2D, TAP_UD,
-       TAP_SIS, TAP_CI, TAP_SI, TAP_E1I, TAP_PI, TAP_E2I, TAP_UI,
+       TAP_RESET, TAP_IDLE,
+       TAP_DRSELECT, TAP_DRCAPTURE, TAP_DRSHIFT, TAP_DREXIT1, TAP_DRPAUSE, TAP_DREXIT2, TAP_DRUPDATE,
+       TAP_IRSELECT, TAP_IRCAPTURE, TAP_IRSHIFT, TAP_IREXIT1, TAP_IRPAUSE, TAP_IREXIT2, TAP_IRUPDATE,
 };
 
 int tap_to_xsvf[] =
@@ -73,19 +76,24 @@ int tap_to_xsvf[] =
 /* xsvf has it's own definition of a statemove. This needs
  * to be handled according to the specs, which has nothing
  * to do with the JTAG spec or OpenOCD as such.
- * 
+ *
  * Implemented via jtag_add_pathmove().
  */
 void xsvf_add_statemove(enum tap_state state)
 {
        enum tap_state moves[7]; /* max # of transitions */
-       int i; 
+       int i;
        enum tap_state curstate = cmd_queue_cur_state;
        u8 move = TAP_MOVE(cmd_queue_cur_state, state);
-       
-       if ((state != TAP_TLR) && (state == cmd_queue_cur_state))
+
+       if ((state != TAP_RESET) && (state == cmd_queue_cur_state))
                return;
 
+       if(state==TAP_RESET)
+       {
+               jtag_add_tlr();
+               return;
+       }
        for (i=0; i<7; i++)
        {
                int j = (move >> i) & 1;
@@ -127,7 +135,7 @@ int xsvf_read_xstates(int fd, enum tap_state *path, int max_path, int *path_len)
 {
        char c;
        unsigned char uc;
-       
+
        while ((read(fd, &c, 1) > 0) && (c == 0x12))
        {
                if (*path_len > max_path)
@@ -141,9 +149,9 @@ int xsvf_read_xstates(int fd, enum tap_state *path, int max_path, int *path_len)
                }
                path[(*path_len)++] = xsvf_to_tap[uc];
        }
-       
+
        lseek(fd, -1, SEEK_CUR);
-       
+
        return ERROR_OK;
 }
 
@@ -158,10 +166,13 @@ int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
        int do_abort = 0;
        int unsupported = 0;
        int tdo_mismatch = 0;
-       
+
        int runtest_requires_tck = 0;
-       
-       int device = -1;        /* use -1 to indicate a "plain" xsvf file which accounts for additional devices in the scan chain, otherwise the device that should be affected */
+
+       jtag_tap_t *tap = NULL;
+       /* use NULL to indicate a "plain" xsvf file which accounts for
+          additional devices in the scan chain, otherwise the device
+          that should be affected */
 
        if (argc < 2)
        {
@@ -171,7 +182,11 @@ int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
 
        if (strcmp(args[0], "plain") != 0)
        {
-               device = strtoul(args[0], NULL, 0);
+         tap = jtag_TapByString( args[0] );
+         if( !tap ){
+           command_print( cmd_ctx, "Tap: %s unknown", args[0] );
+           return ERROR_OK;
+         }
        }
 
        if ((xsvf_fd = open(args[1], O_RDONLY)) < 0)
@@ -179,7 +194,7 @@ int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
                command_print(cmd_ctx, "file %s not found", args[0]);
                return ERROR_OK;
        }
-       
+
        if ((argc > 2) && (strcmp(args[2], "virt2") == 0))
        {
                runtest_requires_tck = 1;
@@ -194,7 +209,7 @@ int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
                                if (jtag_execute_queue() != ERROR_OK)
                                {
                                        tdo_mismatch = 1;
-                                       break;  
+                                       break;
                                }
                                break;
                        case 0x01:      /* XTDOMASK */
@@ -214,7 +229,7 @@ int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
                                        else
                                        {
                                                scan_field_t field;
-                                               field.device = device;
+                                               field.tap = tap;
                                                field.num_bits = c;
                                                field.out_value = ir_buf;
                                                field.out_mask = NULL;
@@ -223,10 +238,10 @@ int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
                                                field.in_check_mask = NULL;
                                                field.in_handler = NULL;
                                                field.in_handler_priv = NULL;
-                                               if (device == -1)
-                                                       jtag_add_plain_ir_scan(1, &field, TAP_PI);
+                                               if (tap == NULL)
+                                                       jtag_add_plain_ir_scan(1, &field, TAP_IRPAUSE);
                                                else
-                                                       jtag_add_ir_scan(1, &field, TAP_PI);
+                                                       jtag_add_ir_scan(1, &field, TAP_IRPAUSE);
                                                if (jtag_execute_queue() != ERROR_OK)
                                                {
                                                        tdo_mismatch = 1;
@@ -239,7 +254,7 @@ int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
                                                                jtag_add_runtest(xruntest, xsvf_to_tap[xendir]);
                                                        else
                                                        {
-                                                               xsvf_add_statemove(TAP_RTI);
+                                                               xsvf_add_statemove(TAP_IDLE);
                                                                jtag_add_sleep(xruntest);
                                                                xsvf_add_statemove(xsvf_to_tap[xendir]);
                                                        }
@@ -257,20 +272,20 @@ int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
                                else
                                {
                                        scan_field_t field;
-                                       field.device = device;
+                                       field.tap = tap;
                                        field.num_bits = xsdrsize;
                                        field.out_value = dr_out_buf;
                                        field.out_mask = NULL;
                                        field.in_value = NULL;
                                        jtag_set_check_value(&field, dr_in_buf, dr_in_mask, NULL);
-                                       if (device == -1)
-                                               jtag_add_plain_dr_scan(1, &field, TAP_PD);
+                                       if (tap == NULL)
+                                               jtag_add_plain_dr_scan(1, &field, TAP_DRPAUSE);
                                        else
-                                               jtag_add_dr_scan(1, &field, TAP_PD);
+                                               jtag_add_dr_scan(1, &field, TAP_DRPAUSE);
                                        if (jtag_execute_queue() != ERROR_OK)
                                        {
                                                tdo_mismatch = 1;
-                                               break;  
+                                               break;
                                        }
                                        if (xruntest)
                                        {
@@ -278,7 +293,7 @@ int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
                                                        jtag_add_runtest(xruntest, xsvf_to_tap[xenddr]);
                                                else
                                                {
-                                                       xsvf_add_statemove(TAP_RTI);
+                                                       xsvf_add_statemove(TAP_IDLE);
                                                        jtag_add_sleep(xruntest);
                                                        xsvf_add_statemove(xsvf_to_tap[xenddr]);
                                                }
@@ -331,20 +346,20 @@ int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
                                        else
                                        {
                                                scan_field_t field;
-                                               field.device = device;
+                                               field.tap = tap;
                                                field.num_bits = xsdrsize;
                                                field.out_value = dr_out_buf;
                                                field.out_mask = NULL;
                                                field.in_value = NULL;
                                                jtag_set_check_value(&field, dr_in_buf, dr_in_mask, NULL);
-                                               if (device == -1)
-                                                       jtag_add_plain_dr_scan(1, &field, TAP_PD);
+                                               if (tap == NULL)
+                                                       jtag_add_plain_dr_scan(1, &field, TAP_DRPAUSE);
                                                else
-                                                       jtag_add_dr_scan(1, &field, TAP_PD);
+                                                       jtag_add_dr_scan(1, &field, TAP_DRPAUSE);
                                                if (jtag_execute_queue() != ERROR_OK)
                                                {
                                                        tdo_mismatch = 1;
-                                                       break;  
+                                                       break;
                                                }
                                                if (xruntest)
                                                {
@@ -352,7 +367,7 @@ int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
                                                                jtag_add_runtest(xruntest, xsvf_to_tap[xenddr]);
                                                        else
                                                        {
-                                                               xsvf_add_statemove(TAP_RTI);
+                                                               xsvf_add_statemove(TAP_IDLE);
                                                                jtag_add_sleep(xruntest);
                                                                xsvf_add_statemove(xsvf_to_tap[xenddr]);
                                                        }
@@ -401,7 +416,27 @@ int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
                                                do_abort = 1;
                                        else
                                        {
-                                               jtag_add_pathmove(path_len, path);
+                                               int i,lasti;
+                                               /* here the trick is that jtag_add_pathmove() must end in a stable
+                                               state, so we must only invoke jtag_add_tlr() when we absolutely
+                                               have to
+                                               */
+                                               for(i=0,lasti=0;i<path_len;i++)
+                                               {
+                                                       if(path[i]==TAP_RESET)
+                                                       {
+                                                               if(i>lasti)
+                                                               {
+                                                                       jtag_add_pathmove(i-lasti,path+lasti);
+                                                               }
+                                                               lasti=i+1;
+                                                               jtag_add_tlr();
+                                                       }
+                                               }
+                                               if(i>=lasti)
+                                               {
+                                                       jtag_add_pathmove(i-lasti, path+lasti);
+                                               }
                                        }
                                        free(path);
                                }
@@ -454,7 +489,7 @@ int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
                                        else
                                        {
                                                scan_field_t field;
-                                               field.device = device;
+                                               field.tap = tap;
                                                field.num_bits = us;
                                                field.out_value = ir_buf;
                                                field.out_mask = NULL;
@@ -463,7 +498,7 @@ int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
                                                field.in_check_mask = NULL;
                                                field.in_handler = NULL;
                                                field.in_handler_priv = NULL;
-                                               if (device == -1)
+                                               if (tap == NULL)
                                                        jtag_add_plain_ir_scan(1, &field, xsvf_to_tap[xendir]);
                                                else
                                                        jtag_add_ir_scan(1, &field, xsvf_to_tap[xendir]);
@@ -501,7 +536,7 @@ int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
                if (do_abort || unsupported || tdo_mismatch)
                        break;
        }
-       
+
        if (tdo_mismatch)
        {
                command_print(cmd_ctx, "TDO mismatch, aborting");
@@ -519,18 +554,18 @@ int handle_xsvf_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
                command_print(cmd_ctx, "premature end detected, aborting");
                return ERROR_OK;
        }
-       
+
        if (dr_out_buf)
                free(dr_out_buf);
-       
+
        if (dr_in_buf)
                free(dr_in_buf);
-       
+
        if (dr_in_mask)
                free(dr_in_mask);
 
        close(xsvf_fd);
-       
+
        command_print(cmd_ctx, "XSVF file programmed successfully");
 
        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)