Charles Hardin ckhardin at gmail.com

This address the >32 bit problem with drscan
also added a check for bypass in the execute since this will manifest itself
as a memory corruption when this check helps to debug the problem alot easier


git-svn-id: svn://svn.berlios.de/openocd/trunk@794 b42882b7-edfa-0310-969c-e2dbd0fdcd60
This commit is contained in:
oharboe 2008-07-11 17:40:15 +00:00
parent e04f0142ee
commit b06f254b24
3 changed files with 49 additions and 31 deletions

View File

@ -188,7 +188,7 @@ int ceil_f_to_u32(float x)
return y; return y;
} }
char* buf_to_str(u8 *buf, int buf_len, int radix) char* buf_to_str(const u8 *buf, int buf_len, int radix)
{ {
const char *DIGITS = "0123456789abcdef"; const char *DIGITS = "0123456789abcdef";
float factor; float factor;
@ -238,7 +238,7 @@ char* buf_to_str(u8 *buf, int buf_len, int radix)
return str; return str;
} }
int str_to_buf(char* str, int str_len, u8 *buf, int buf_len, int radix) int str_to_buf(const char *str, int str_len, u8 *buf, int buf_len, int radix)
{ {
char *charbuf; char *charbuf;
u32 tmp; u32 tmp;

View File

@ -77,8 +77,8 @@ extern u8* buf_cpy(u8 *from, u8 *to, int size);
extern u8* buf_set_ones(u8 *buf, int count); extern u8* buf_set_ones(u8 *buf, int count);
extern u8* buf_set_buf(u8 *src, int src_start, u8 *dst, int dst_start, int len); extern u8* buf_set_buf(u8 *src, int src_start, u8 *dst, int dst_start, int len);
extern int str_to_buf(char* str, int len, u8 *bin_buf, int buf_size, int radix); extern int str_to_buf(const char *str, int len, u8 *bin_buf, int buf_size, int radix);
extern char* buf_to_str(u8 *buf, int size, int radix); extern char* buf_to_str(const u8 *buf, int size, int radix);
struct scan_field_s; struct scan_field_s;
extern int buf_to_u32_handler(u8 *in_buf, void *priv, struct scan_field_s *field); extern int buf_to_u32_handler(u8 *in_buf, void *priv, struct scan_field_s *field);

View File

@ -603,6 +603,11 @@ int MINIDRIVER(interface_jtag_add_dr_scan)(int num_fields, scan_field_t *fields,
bypass_devices++; bypass_devices++;
device = device->next; device = device->next;
} }
if (bypass_devices >= jtag_num_devices)
{
LOG_ERROR("all devices in bypass");
return ERROR_JTAG_DEVICE_ERROR;
}
/* allocate memory for a new list member */ /* allocate memory for a new list member */
*last_cmd = cmd_queue_alloc(sizeof(jtag_command_t)); *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
@ -1493,7 +1498,6 @@ int jtag_register_commands(struct command_context_s *cmd_ctx)
COMMAND_EXEC, "move to Run-Test/Idle, and execute <num_cycles>"); COMMAND_EXEC, "move to Run-Test/Idle, and execute <num_cycles>");
register_command(cmd_ctx, NULL, "irscan", handle_irscan_command, register_command(cmd_ctx, NULL, "irscan", handle_irscan_command,
COMMAND_EXEC, "execute IR scan <device> <instr> [dev2] [instr2] ..."); COMMAND_EXEC, "execute IR scan <device> <instr> [dev2] [instr2] ...");
add_jim("drscan", Jim_Command_drscan, "execute DR scan <device> <num_bits> <value> <num_bits1> <value2> ..."); add_jim("drscan", Jim_Command_drscan, "execute DR scan <device> <num_bits> <value> <num_bits1> <value2> ...");
register_command(cmd_ctx, NULL, "verify_ircapture", handle_verify_ircapture_command, register_command(cmd_ctx, NULL, "verify_ircapture", handle_verify_ircapture_command,
@ -2043,47 +2047,54 @@ int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **a
return ERROR_OK; return ERROR_OK;
} }
/* FIX!!! this command is busted for > 32 bits */
int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args) int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args)
{ {
int retval; int retval;
scan_field_t *fields; scan_field_t *fields;
int num_fields; int num_fields;
int field_count = 0; int field_count = 0;
int i, j; int i, j, e;
long device;
/* args[1] = device
* args[2] = num_bits
* args[3] = hex string
* ... repeat num bits and hex string ...
*/
if ((argc < 4) || ((argc % 2)!=0)) if ((argc < 4) || ((argc % 2)!=0))
{ {
Jim_WrongNumArgs(interp, 1, args, "wrong arguments");
return JIM_ERR; return JIM_ERR;
} }
for (i = 2; i < argc; i+=2) for (i = 2; i < argc; i+=2)
{ {
long bits; long bits;
Jim_GetLong(interp, args[i], &bits);
if ((bits<=0)||(bits>32)) e = Jim_GetLong(interp, args[i], &bits);
{ if (e != JIM_OK)
// LOG_ERROR("minimum 1/maximum 32 bit fields - patches gratefully accepted!"); return e;
return JIM_ERR;
} }
}
long device; e = Jim_GetLong(interp, args[1], &device);
Jim_GetLong(interp, args[1], &device); if (e != JIM_OK)
return e;
num_fields=(argc-2)/2; num_fields=(argc-2)/2;
fields = malloc(sizeof(scan_field_t) * num_fields); fields = malloc(sizeof(scan_field_t) * num_fields);
for (i = 2; i < argc; i+=2) for (i = 2; i < argc; i+=2)
{ {
long bits; long bits;
int len;
const char *str;
Jim_GetLong(interp, args[i], &bits); Jim_GetLong(interp, args[i], &bits);
long val; str = Jim_GetString(args[i+1], &len);
Jim_GetLong(interp, args[i+1], &val);
fields[field_count].device = device; fields[field_count].device = device;
fields[field_count].num_bits = bits; fields[field_count].num_bits = bits;
fields[field_count].out_value = malloc(CEIL(bits, 8)); fields[field_count].out_value = malloc(CEIL(bits, 8));
buf_set_u32(fields[field_count].out_value, 0, bits, val); str_to_buf(str, len, fields[field_count].out_value, bits, 0);
fields[field_count].out_mask = NULL; fields[field_count].out_mask = NULL;
fields[field_count].in_value = fields[field_count].out_value; fields[field_count].in_value = fields[field_count].out_value;
fields[field_count].in_check_mask = NULL; fields[field_count].in_check_mask = NULL;
@ -2094,19 +2105,26 @@ int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args)
jtag_add_dr_scan(num_fields, fields, -1); jtag_add_dr_scan(num_fields, fields, -1);
retval = jtag_execute_queue(); retval = jtag_execute_queue();
if (retval != ERROR_OK)
{
Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
Jim_AppendStrings(interp, Jim_GetResult(interp), "drscan: jtag execute failed", NULL);
return JIM_ERR;
}
field_count=0; field_count=0;
Jim_Obj *list = Jim_NewListObj(interp, NULL, 0); Jim_Obj *list = Jim_NewListObj(interp, NULL, 0);
for (i = 2; i < argc; i+=2) for (i = 2; i < argc; i+=2)
{ {
long bits; long bits;
char *str;
Jim_GetLong(interp, args[i], &bits); Jim_GetLong(interp, args[i], &bits);
str = buf_to_str(fields[field_count].in_value, bits, 16);
u32 val = buf_get_u32(fields[field_count].in_value, 0, bits);
Jim_ListAppendElement(interp, list, Jim_NewIntObj(interp, val));
free(fields[field_count].out_value); free(fields[field_count].out_value);
Jim_ListAppendElement(interp, list, Jim_NewStringObj(interp, str, strlen(str)));
free(str);
field_count++; field_count++;
} }
@ -2114,7 +2132,7 @@ int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args)
free(fields); free(fields);
return retval?JIM_OK:JIM_ERR; return JIM_OK;
} }
int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)