jtag_get_device() now returns NULL and reports error instead of invoking exit()

git-svn-id: svn://svn.berlios.de/openocd/trunk@1176 b42882b7-edfa-0310-969c-e2dbd0fdcd60
This commit is contained in:
oharboe 2008-11-19 08:22:47 +00:00
parent cb434c21af
commit e3462b228c
11 changed files with 394 additions and 352 deletions

View File

@ -114,10 +114,8 @@ int str9xpec_register_commands(struct command_context_s *cmd_ctx)
int str9xpec_set_instr(int chain_pos, u32 new_instr, enum tap_state end_state)
{
jtag_device_t *device = jtag_get_device(chain_pos);
if (device == NULL)
{
LOG_DEBUG("Invalid Target");
return ERROR_TARGET_INVALID;
}
@ -1267,6 +1265,7 @@ int str9xpec_handle_flash_unlock_command(struct command_context_s *cmd_ctx, char
int str9xpec_handle_flash_enable_turbo_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
int retval;
flash_bank_t *bank;
u32 chain_pos;
jtag_device_t* dev0;
@ -1293,12 +1292,17 @@ int str9xpec_handle_flash_enable_turbo_command(struct command_context_s *cmd_ctx
/* remove arm core from chain - enter turbo mode */
str9xpec_set_instr(chain_pos+2, 0xD, TAP_RTI);
jtag_execute_queue();
if ((retval=jtag_execute_queue())!=ERROR_OK)
return retval;
/* modify scan chain - str9 core has been removed */
dev0 = jtag_get_device(chain_pos);
if (dev0 == NULL)
return ERROR_FAIL;
str9xpec_info->devarm = jtag_get_device(chain_pos+1);
dev2 = jtag_get_device(chain_pos+2);
if (dev2 == NULL)
return ERROR_FAIL;
dev0->next = dev2;
jtag_num_devices--;
@ -1330,6 +1334,9 @@ int str9xpec_handle_flash_disable_turbo_command(struct command_context_s *cmd_ct
chain_pos = str9xpec_info->chain_pos;
dev0 = jtag_get_device(chain_pos);
if (dev0 == NULL)
return ERROR_FAIL;
/* exit turbo mode via TLR */
str9xpec_set_instr(chain_pos, ISC_NOOP, TAP_TLR);

View File

@ -369,7 +369,7 @@ jtag_device_t* jtag_get_device(int num)
}
LOG_ERROR("jtag device number %d not defined", num);
exit(-1);
return NULL;
}
void* cmd_queue_alloc(size_t size)
@ -477,6 +477,10 @@ int MINIDRIVER(interface_jtag_add_ir_scan)(int num_fields, scan_field_t *fields,
{
int found = 0;
device = jtag_get_device(i);
if (device == NULL)
{
exit(-1);
}
scan_size = device->ir_length;
(*last_cmd)->cmd.scan->fields[i].device = i;
(*last_cmd)->cmd.scan->fields[i].num_bits = scan_size;
@ -2120,7 +2124,12 @@ int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **a
for (i = 0; i < argc / 2; i++)
{
int device = strtoul(args[i*2], NULL, 0);
int field_size = jtag_get_device(device)->ir_length;
jtag_device_t *device_ptr=jtag_get_device(device);
if (device==NULL)
{
return ERROR_FAIL;
}
int field_size = device_ptr->ir_length;
fields[i].device = device;
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));

View File

@ -501,6 +501,11 @@ int interface_jtag_add_ir_scan(int num_fields, scan_field_t *fields, enum tap_st
int pause=i==(jtag_num_devices-1);
int found = 0;
device = jtag_get_device(i);
if (device==NULL)
{
return ERROR_FAIL;
}
scan_size = device->ir_length;
/* search the list */
@ -521,7 +526,7 @@ int interface_jtag_add_ir_scan(int num_fields, scan_field_t *fields, enum tap_st
scanFields(1, fields+j, TAP_SI, pause);
/* update device information */
buf_cpy(fields[j].out_value, jtag_get_device(i)->cur_instr, scan_size);
buf_cpy(fields[j].out_value, device->cur_instr, scan_size);
device->bypass = 0;
break;
@ -539,7 +544,7 @@ int interface_jtag_add_ir_scan(int num_fields, scan_field_t *fields, enum tap_st
tmp.num_bits = scan_size;
scanFields(1, &tmp, TAP_SI, pause);
/* update device information */
buf_cpy(tmp.out_value, jtag_get_device(i)->cur_instr, scan_size);
buf_cpy(tmp.out_value, device->cur_instr, scan_size);
device->bypass = 1;
}
}

View File

@ -46,6 +46,8 @@ pld_driver_t virtex2_pld =
int virtex2_set_instr(int chain_pos, u32 new_instr)
{
jtag_device_t *device = jtag_get_device(chain_pos);
if (device==NULL)
return ERROR_FAIL;
if (buf_get_u32(device->cur_instr, 0, device->ir_length) != new_instr)
{

View File

@ -1535,6 +1535,8 @@ int arm11_target_create(struct target_s *target, Jim_Interp *interp)
}
jtag_device_t *device = jtag_get_device(target->chain_position);
if (device==NULL)
return ERROR_FAIL;
if (device->ir_length != 5)
{

View File

@ -102,6 +102,10 @@ void arm11_setup_field(arm11_common_t * arm11, int num_bits, void * out_data, vo
void arm11_add_IR(arm11_common_t * arm11, u8 instr, enum tap_state state)
{
jtag_device_t *device = jtag_get_device(arm11->jtag_info.chain_pos);
if (device==NULL)
{
/* FIX!!!! error is logged, but not propagated back up the call stack... */
}
if (buf_get_u32(device->cur_instr, 0, 5) == instr)
{

View File

@ -39,6 +39,8 @@
int arm_jtag_set_instr(arm_jtag_t *jtag_info, u32 new_instr, in_handler_t handler)
{
jtag_device_t *device = jtag_get_device(jtag_info->chain_pos);
if (device==NULL)
return ERROR_FAIL;
if (buf_get_u32(device->cur_instr, 0, device->ir_length) != new_instr)
{

View File

@ -63,6 +63,8 @@ int handle_etb_config_command(struct command_context_s *cmd_ctx, char *cmd, char
int etb_set_instr(etb_t *etb, u32 new_instr)
{
jtag_device_t *device = jtag_get_device(etb->chain_pos);
if (device==NULL)
return ERROR_FAIL;
if (buf_get_u32(device->cur_instr, 0, device->ir_length) != new_instr)
{
@ -440,7 +442,6 @@ int handle_etb_config_command(struct command_context_s *cmd_ctx, char *cmd, char
if (!jtag_device)
{
LOG_ERROR("jtag device number '%s' not defined", args[1]);
return ERROR_FAIL;
}

View File

@ -35,6 +35,8 @@
int mips_ejtag_set_instr(mips_ejtag_t *ejtag_info, int new_instr, in_handler_t handler)
{
jtag_device_t *device = jtag_get_device(ejtag_info->chain_pos);
if (device==NULL)
return ERROR_FAIL;
if (buf_get_u32(device->cur_instr, 0, device->ir_length) != new_instr)
{
@ -115,6 +117,9 @@ int mips_ejtag_drscan_32(mips_ejtag_t *ejtag_info, u32 *data)
{
jtag_device_t *device;
device = jtag_get_device(ejtag_info->chain_pos);
if (device==NULL)
return ERROR_FAIL;
scan_field_t field;
u8 t[4];
int retval;

View File

@ -3400,6 +3400,9 @@ target_configure( Jim_GetOptInfo *goi,
if( e != JIM_OK ){
return e;
}
if (jtag_get_device(w)==NULL)
return JIM_ERR;
/* make this exactly 1 or 0 */
target->chain_position = w;
} else {

View File

@ -215,6 +215,8 @@ int xscale_get_arch_pointers(target_t *target, armv4_5_common_t **armv4_5_p, xsc
int xscale_jtag_set_instr(int chain_pos, u32 new_instr)
{
jtag_device_t *device = jtag_get_device(chain_pos);
if (device==NULL)
return ERROR_FAIL;
if (buf_get_u32(device->cur_instr, 0, device->ir_length) != new_instr)
{