Piotr Ziecik <kosmo@semihalf.com> This patch adds handling blank characters between hex digits in

SVF file, making OpenOCD compatible with files generated by
Altera Quatrus II 9.0.

git-svn-id: svn://svn.berlios.de/openocd/trunk@2600 b42882b7-edfa-0310-969c-e2dbd0fdcd60
__archive__
oharboe 2009-08-20 08:55:34 +00:00
parent ef30f22fd3
commit afae28fb2c
1 changed files with 38 additions and 59 deletions

View File

@ -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) 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; int i, str_len = strlen(str), str_hbyte_len = (bit_len + 3) >> 2;
uint8_t ch, need_write = 1; uint8_t ch;
if (ERROR_OK != svf_adjust_array_length(bin, orig_bit_len, bit_len)) if (ERROR_OK != svf_adjust_array_length(bin, orig_bit_len, bit_len))
{ {
@ -664,27 +664,24 @@ static int svf_copy_hexstring_to_binary(char *str, uint8_t **bin, int orig_bit_l
return ERROR_FAIL; return ERROR_FAIL;
} }
if (str_byte_len > str_len) for (i = 0; i < str_hbyte_len; i++)
{ {
loop_cnt = str_byte_len; ch = 0;
} while (str_len > 0)
else
{ {
loop_cnt = str_len; ch = str[--str_len];
}
for (i = 0; i < loop_cnt; i++) if (!isblank(ch))
{ {
if (i < str_len)
{
ch = str[str_len - i - 1];
if ((ch >= '0') && (ch <= '9')) if ((ch >= '0') && (ch <= '9'))
{ {
ch = ch - '0'; ch = ch - '0';
break;
} }
else if ((ch >= 'A') && (ch <= 'F')) else if ((ch >= 'A') && (ch <= 'F'))
{ {
ch = ch - 'A' + 10; ch = ch - 'A' + 10;
break;
} }
else else
{ {
@ -692,34 +689,10 @@ static int svf_copy_hexstring_to_binary(char *str, uint8_t **bin, int orig_bit_l
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
else
{
ch = 0; ch = 0;
} }
// check valid
if (i >= str_byte_len)
{
// 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;
}
}
else if (i == (str_byte_len - 1))
{
// last data byte, written if valid
if ((ch & ~((1 << (bit_len - 4 * i)) - 1)) != 0)
{
LOG_ERROR("value execede length");
return ERROR_FAIL;
}
}
if (need_write)
{
// write bin // write bin
if (i % 2) if (i % 2)
{ {
@ -733,6 +706,12 @@ static int svf_copy_hexstring_to_binary(char *str, uint8_t **bin, int orig_bit_l
(*bin)[i / 2] |= ch; (*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; return ERROR_OK;