Piotr Ziecik <kosmo@semihalf.com> This patch adds handling blank characters between...
[openocd.git] / src / svf / svf.c
index be2ae5a56a48a1487663bfac7d11d65ad7bcb9a8..510b7b0afa2bc65891c6e6e3d13c8443bfa859ae 100644 (file)
@@ -98,24 +98,24 @@ typedef struct
        tap_state_t paths[8];
 }svf_statemove_t;
 
-svf_statemove_t svf_statemoves[] = 
+svf_statemove_t svf_statemoves[] =
 {
        // from                 to                              num_of_moves,   paths[8]
 //     {TAP_RESET,             TAP_RESET,              1,                              {TAP_RESET}},
        {TAP_RESET,             TAP_IDLE,               2,                              {TAP_RESET, TAP_IDLE}},
        {TAP_RESET,             TAP_DRPAUSE,    6,                              {TAP_RESET, TAP_IDLE, TAP_DRSELECT, TAP_DRCAPTURE, TAP_DREXIT1, TAP_DRPAUSE}},
        {TAP_RESET,             TAP_IRPAUSE,    7,                              {TAP_RESET, TAP_IDLE, TAP_DRSELECT, TAP_IRSELECT, TAP_IRCAPTURE, TAP_IREXIT1, TAP_IRPAUSE}},
-       
+
 //     {TAP_IDLE,              TAP_RESET,              4,                              {TAP_IDLE, TAP_DRSELECT, TAP_IRSELECT, TAP_RESET}},
        {TAP_IDLE,              TAP_IDLE,               1,                              {TAP_IDLE}},
        {TAP_IDLE,              TAP_DRPAUSE,    5,                              {TAP_IDLE, TAP_DRSELECT, TAP_DRCAPTURE, TAP_DREXIT1, TAP_DRPAUSE}},
        {TAP_IDLE,              TAP_IRPAUSE,    6,                              {TAP_IDLE, TAP_DRSELECT, TAP_IRSELECT, TAP_IRCAPTURE, TAP_IREXIT1, TAP_IRPAUSE}},
-       
+
 //     {TAP_DRPAUSE,   TAP_RESET,              6,                              {TAP_DRPAUSE, TAP_DREXIT2, TAP_DRUPDATE, TAP_DRSELECT, TAP_IRSELECT, TAP_RESET}},
        {TAP_DRPAUSE,   TAP_IDLE,               4,                              {TAP_DRPAUSE, TAP_DREXIT2, TAP_DRUPDATE, TAP_IDLE}},
        {TAP_DRPAUSE,   TAP_DRPAUSE,    7,                              {TAP_DRPAUSE, TAP_DREXIT2, TAP_DRUPDATE, TAP_DRSELECT, TAP_DRCAPTURE, TAP_DREXIT1, TAP_DRPAUSE}},
        {TAP_DRPAUSE,   TAP_IRPAUSE,    8,                              {TAP_DRPAUSE, TAP_DREXIT2, TAP_DRUPDATE, TAP_DRSELECT, TAP_IRSELECT, TAP_IRCAPTURE, TAP_IREXIT1, TAP_IRPAUSE}},
-       
+
 //     {TAP_IRPAUSE,   TAP_RESET,              6,                              {TAP_IRPAUSE, TAP_IREXIT2, TAP_IRUPDATE, TAP_DRSELECT, TAP_IRSELECT, TAP_RESET}},
        {TAP_IRPAUSE,   TAP_IDLE,               4,                              {TAP_IRPAUSE, TAP_IREXIT2, TAP_IRUPDATE, TAP_IDLE}},
        {TAP_IRPAUSE,   TAP_DRPAUSE,    7,                              {TAP_IRPAUSE, TAP_IREXIT2, TAP_IRUPDATE, TAP_DRSELECT, TAP_DRCAPTURE, TAP_DREXIT1, TAP_DRPAUSE}},
@@ -304,7 +304,7 @@ static int svf_add_statemove(tap_state_t state_to)
 
        for (index = 0; index < dimof(svf_statemoves); index++)
        {
-               if ((svf_statemoves[index].from == state_from) 
+               if ((svf_statemoves[index].from == state_from)
                        && (svf_statemoves[index].to == state_to))
                {
                        if (TAP_RESET == state_from)
@@ -655,8 +655,8 @@ static int svf_adjust_array_length(uint8_t **arr, int orig_bit_len, int new_bit_
 
 static int svf_copy_hexstring_to_binary(char *str, uint8_t **bin, int orig_bit_len, int bit_len)
 {
-       int i, str_len = strlen(str), str_byte_len = (bit_len + 3) >> 2, loop_cnt;
-       uint8_t ch, need_write = 1;
+       int i, str_len = strlen(str), str_hbyte_len = (bit_len + 3) >> 2;
+       uint8_t ch;
 
        if (ERROR_OK != svf_adjust_array_length(bin, orig_bit_len, bit_len))
        {
@@ -664,75 +664,54 @@ static int svf_copy_hexstring_to_binary(char *str, uint8_t **bin, int orig_bit_l
                return ERROR_FAIL;
        }
 
-       if (str_byte_len > str_len)
-       {
-               loop_cnt = str_byte_len;
-       }
-       else
-       {
-               loop_cnt = str_len;
-       }
-
-       for (i = 0; i < loop_cnt; i++)
+       for (i = 0; i < str_hbyte_len; i++)
        {
-               if (i < str_len)
+               ch = 0;
+               while (str_len > 0)
                {
-                       ch = str[str_len - i - 1];
-                       if ((ch >= '0') && (ch <= '9'))
-                       {
-                               ch = ch - '0';
-                       }
-                       else if ((ch >= 'A') && (ch <= 'F'))
-                       {
-                               ch = ch - 'A' + 10;
-                       }
-                       else
+                       ch = str[--str_len];
+
+                       if (!isblank(ch))
                        {
-                               LOG_ERROR("invalid hex string");
-                               return ERROR_FAIL;
+                               if ((ch >= '0') && (ch <= '9'))
+                               {
+                                       ch = ch - '0';
+                                       break;
+                               }
+                               else if ((ch >= 'A') && (ch <= 'F'))
+                               {
+                                       ch = ch - 'A' + 10;
+                                       break;
+                               }
+                               else
+                               {
+                                       LOG_ERROR("invalid hex string");
+                                       return ERROR_FAIL;
+                               }
                        }
-               }
-               else
-               {
+
                        ch = 0;
                }
 
-               // check valid
-               if (i >= str_byte_len)
+               // write bin
+               if (i % 2)
                {
-                       // all data written, other data should be all '0's and needn't to be written
-                       need_write = 0;
-                       if (ch != 0)
-                       {
-                               LOG_ERROR("value execede length");
-                               return ERROR_FAIL;
-                       }
+                       // MSB
+                       (*bin)[i / 2] |= ch << 4;
                }
-               else if (i == (str_byte_len - 1))
+               else
                {
-                       // last data byte, written if valid
-                       if ((ch & ~((1 << (bit_len - 4 * i)) - 1)) != 0)
-                       {
-                               LOG_ERROR("value execede length");
-                               return ERROR_FAIL;
-                       }
+                       // LSB
+                       (*bin)[i / 2] = 0;
+                       (*bin)[i / 2] |= ch;
                }
+       }
 
-               if (need_write)
-               {
-                       // write bin
-                       if (i % 2)
-                       {
-                               // MSB
-                               (*bin)[i / 2] |= ch << 4;
-                       }
-                       else
-                       {
-                               // LSB
-                               (*bin)[i / 2] = 0;
-                               (*bin)[i / 2] |= ch;
-                       }
-               }
+       // check valid
+       if (str_len > 0 || (ch & ~((1 << (4 - (bit_len % 4))) - 1)) != 0)
+       {
+               LOG_ERROR("value execede length");
+               return ERROR_FAIL;
        }
 
        return ERROR_OK;
@@ -746,7 +725,7 @@ static int svf_check_tdo(void)
        {
                index = svf_check_tdo_para[i].buffer_offset;
                len = svf_check_tdo_para[i].bit_len;
-               if ((svf_check_tdo_para[i].enabled) 
+               if ((svf_check_tdo_para[i].enabled)
                        && buf_cmp_mask(&svf_tdi_buffer[index], &svf_tdo_buffer[index], &svf_mask_buffer[index], len))
                {
                        unsigned bitmask;
@@ -756,11 +735,11 @@ static int svf_check_tdo(void)
                        memcpy(&received, svf_tdi_buffer + index, sizeof(unsigned));
                        memcpy(&expected, svf_tdo_buffer + index, sizeof(unsigned));
                        memcpy(&tapmask, svf_mask_buffer + index, sizeof(unsigned));
-                       LOG_ERROR("tdo check error at line %d", 
+                       LOG_ERROR("tdo check error at line %d",
                                          svf_check_tdo_para[i].line_num);
-                       LOG_ERROR("read = 0x%X, want = 0x%X, mask = 0x%X", 
-                                         received & bitmask, 
-                                         expected & bitmask, 
+                       LOG_ERROR("read = 0x%X, want = 0x%X, mask = 0x%X",
+                                         received & bitmask,
+                                         expected & bitmask,
                                          tapmask & bitmask);
                        return ERROR_FAIL;
                }

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)