Browse Source

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
tags/v0.1.0
oharboe 13 years ago
parent
commit
e3462b228c
11 changed files with 394 additions and 352 deletions
  1. +265
    -258
      src/flash/str9xpec.c
  2. +11
    -2
      src/jtag/jtag.c
  3. +7
    -2
      src/jtag/zy1000.c
  4. +39
    -37
      src/pld/virtex2.c
  5. +3
    -1
      src/target/arm11.c
  6. +11
    -7
      src/target/arm11_dbgtap.c
  7. +9
    -7
      src/target/arm_jtag.c
  8. +2
    -1
      src/target/etb.c
  9. +42
    -37
      src/target/mips_ejtag.c
  10. +3
    -0
      src/target/target.c
  11. +2
    -0
      src/target/xscale.c

+ 265
- 258
src/flash/str9xpec.c
File diff suppressed because it is too large
View File


+ 11
- 2
src/jtag/jtag.c 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));


+ 7
- 2
src/jtag/zy1000.c 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;
}
}


+ 39
- 37
src/pld/virtex2.c View File

@@ -46,11 +46,13 @@ 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)
{
scan_field_t field;
field.device = chain_pos;
field.num_bits = device->ir_length;
field.out_value = calloc(CEIL(field.num_bits, 8), 1);
@@ -61,12 +63,12 @@ int virtex2_set_instr(int chain_pos, u32 new_instr)
field.in_check_mask = NULL;
field.in_handler = NULL;
field.in_handler_priv = NULL;
jtag_add_ir_scan(1, &field, TAP_RTI);
free(field.out_value);
}
return ERROR_OK;
}

@@ -76,7 +78,7 @@ int virtex2_send_32(struct pld_device_s *pld_device, int num_words, u32 *words)
scan_field_t scan_field;
u8 *values;
int i;
values = malloc(num_words * 4);

scan_field.device = virtex2_info->chain_pos;
@@ -88,16 +90,16 @@ int virtex2_send_32(struct pld_device_s *pld_device, int num_words, u32 *words)
scan_field.in_check_mask = NULL;
scan_field.in_handler = NULL;
scan_field.in_handler_priv = NULL;
for (i = 0; i < num_words; i++)
buf_set_u32(values + 4 * i, 0, 32, flip_u32(*words++, 32));
virtex2_set_instr(virtex2_info->chain_pos, 0x5); /* CFG_IN */
jtag_add_dr_scan(1, &scan_field, TAP_PD);
free(values);
return ERROR_OK;
}

@@ -112,7 +114,7 @@ int virtex2_receive_32(struct pld_device_s *pld_device, int num_words, u32 *word
{
virtex2_pld_device_t *virtex2_info = pld_device->driver_priv;
scan_field_t scan_field;
scan_field.device = virtex2_info->chain_pos;
scan_field.num_bits = 32;
scan_field.out_value = NULL;
@@ -121,37 +123,37 @@ int virtex2_receive_32(struct pld_device_s *pld_device, int num_words, u32 *word
scan_field.in_check_value = NULL;
scan_field.in_check_mask = NULL;
scan_field.in_handler = virtex2_jtag_buf_to_u32;
virtex2_set_instr(virtex2_info->chain_pos, 0x4); /* CFG_OUT */
while (num_words--)
{
scan_field.in_handler_priv = words++;
jtag_add_dr_scan(1, &scan_field, TAP_PD);
}
return ERROR_OK;
}

int virtex2_read_stat(struct pld_device_s *pld_device, u32 *status)
{
u32 data[5];
jtag_add_tlr();
data[0] = 0xaa995566; /* synch word */
data[1] = 0x2800E001; /* Type 1, read, address 7, 1 word */
data[2] = 0x20000000; /* NOOP (Type 1, read, address 0, 0 words */
data[3] = 0x20000000; /* NOOP */
data[4] = 0x20000000; /* NOOP */
virtex2_send_32(pld_device, 5, data);
virtex2_receive_32(pld_device, 1, status);
jtag_execute_queue();
LOG_DEBUG("status: 0x%8.8x", *status);
return ERROR_OK;
}

@@ -171,29 +173,29 @@ int virtex2_load(struct pld_device_s *pld_device, char *filename)
field.in_check_mask = NULL;
field.in_handler = NULL;
field.in_handler_priv = NULL;
if ((retval = xilinx_read_bit_file(&bit_file, filename)) != ERROR_OK)
return retval;
jtag_add_end_state(TAP_RTI);
virtex2_set_instr(virtex2_info->chain_pos, 0xb); /* JPROG_B */
jtag_execute_queue();
jtag_add_sleep(1000);
virtex2_set_instr(virtex2_info->chain_pos, 0x5); /* CFG_IN */
jtag_execute_queue();
for (i = 0; i < bit_file.length; i++)
bit_file.data[i] = flip_u32(bit_file.data[i], 8);
field.num_bits = bit_file.length * 8;
field.out_value = bit_file.data;

jtag_add_dr_scan(1, &field, TAP_PD);
jtag_execute_queue();
jtag_add_tlr();
jtag_add_end_state(TAP_RTI);
virtex2_set_instr(virtex2_info->chain_pos, 0xc); /* JSTART */
jtag_add_runtest(13, TAP_RTI);
@@ -212,13 +214,13 @@ int virtex2_handle_read_stat_command(struct command_context_s *cmd_ctx, char *cm
pld_device_t *device;
virtex2_pld_device_t *virtex2_info;
u32 status;
if (argc < 1)
{
command_print(cmd_ctx, "usage: virtex2 read_stat <num>");
return ERROR_OK;
}
device = get_pld_device_by_num(strtoul(args[0], NULL, 0));
if (!device)
{
@@ -227,11 +229,11 @@ int virtex2_handle_read_stat_command(struct command_context_s *cmd_ctx, char *cm
}

virtex2_info = device->driver_priv;
virtex2_read_stat(device, &status);
command_print(cmd_ctx, "virtex2 status register: 0x%8.8x", status);
return ERROR_OK;
}

@@ -248,17 +250,17 @@ int virtex2_register_commands(struct command_context_s *cmd_ctx)
int virtex2_pld_device_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct pld_device_s *pld_device)
{
virtex2_pld_device_t *virtex2_info;
if (argc < 2)
{
LOG_WARNING("incomplete pld device 'virtex2' configuration");
return ERROR_PLD_DEVICE_INVALID;
}
virtex2_info = malloc(sizeof(virtex2_pld_device_t));
pld_device->driver_priv = virtex2_info;
virtex2_info->chain_pos = strtoul(args[1], NULL, 0);
return ERROR_OK;
}

+ 3
- 1
src/target/arm11.c View File

@@ -710,7 +710,7 @@ int arm11_target_request_data(struct target_s *target, u32 size, u8 *buffer)
int arm11_halt(struct target_s *target)
{
int retval = ERROR_OK;
FNC_INFO;

arm11_common_t * arm11 = target->arch_info;
@@ -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)
{


+ 11
- 7
src/target/arm11_dbgtap.c 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)
{
@@ -139,7 +143,7 @@ static int arm11_in_handler_SCAN_N(u8 *in_value, void *priv, struct scan_field_s
}

/** Select and write to Scan Chain Register (SCREG)
*
*
* This function sets the instruction register to SCAN_N and writes
* the data register with the selected chain number.
*
@@ -178,11 +182,11 @@ void arm11_add_debug_SCAN_N(arm11_common_t * arm11, u8 chain, enum tap_state sta
}

/** Write an instruction into the ITR register
*
*
* \param arm11 Target state variable.
* \param inst An ARM11 processor instruction/opcode.
* \param flag Optional parameter to retrieve the InstCompl flag
* (this will be written when the JTAG chain is executed).
* (this will be written when the JTAG chain is executed).
* \param state Pass the final TAP state or -1 for the default
* value (Run-Test/Idle).
*
@@ -212,7 +216,7 @@ void arm11_add_debug_INST(arm11_common_t * arm11, u32 inst, u8 * flag, enum tap_
*
* \param arm11 Target state variable.
* \return DSCR content
*
*
* \remarks This is a stand-alone function that executes the JTAG command queue.
*/
u32 arm11_read_DSCR(arm11_common_t * arm11)
@@ -244,7 +248,7 @@ u32 arm11_read_DSCR(arm11_common_t * arm11)
*
* \param arm11 Target state variable.
* \param dscr DSCR content
*
*
* \remarks This is a stand-alone function that executes the JTAG command queue.
*/
void arm11_write_DSCR(arm11_common_t * arm11, u32 dscr)
@@ -272,7 +276,7 @@ void arm11_write_DSCR(arm11_common_t * arm11, u32 dscr)
*
* \param dscr DSCR value to analyze
* \return Debug reason
*
*
*/
enum target_debug_reason arm11_get_DSCR_debug_reason(u32 dscr)
{
@@ -514,7 +518,7 @@ void arm11_run_instr_data_to_core_noack(arm11_common_t * arm11, u32 opcode, u32
{
jtag_add_dr_scan(asizeof(chain5_fields), chain5_fields, TAP_PD);
jtag_add_pathmove(asizeof(arm11_MOVE_PD_RTI_PD_with_delay),
arm11_MOVE_PD_RTI_PD_with_delay);
arm11_MOVE_PD_RTI_PD_with_delay);
}
else
{


+ 9
- 7
src/target/arm_jtag.c View File

@@ -39,12 +39,14 @@
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)
{
scan_field_t field;
u8 t[4];
field.device = jtag_info->chain_pos;
field.num_bits = device->ir_length;
field.out_value = t;
@@ -57,7 +59,7 @@ int arm_jtag_set_instr(arm_jtag_t *jtag_info, u32 new_instr, in_handler_t handl
field.in_handler_priv = NULL;
jtag_add_ir_scan(1, &field, -1);
}
return ERROR_OK;
}

@@ -68,7 +70,7 @@ int arm_jtag_scann(arm_jtag_t *jtag_info, u32 new_scan_chain)
{
u32 values[1];
int num_bits[1];
values[0]=new_scan_chain;
num_bits[0]=jtag_info->scann_size;

@@ -82,7 +84,7 @@ int arm_jtag_scann(arm_jtag_t *jtag_info, u32 new_scan_chain)
num_bits,
values,
-1);
jtag_info->cur_scan_chain = new_scan_chain;
}

@@ -92,12 +94,12 @@ int arm_jtag_scann(arm_jtag_t *jtag_info, u32 new_scan_chain)
int arm_jtag_reset_callback(enum jtag_event event, void *priv)
{
arm_jtag_t *jtag_info = priv;
if (event == JTAG_TRST_ASSERTED)
{
jtag_info->cur_scan_chain = 0;
}
return ERROR_OK;
}



+ 2
- 1
src/target/etb.c 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;
}



+ 42
- 37
src/target/mips_ejtag.c View File

@@ -35,12 +35,14 @@
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)
{
scan_field_t field;
u8 t[4];
field.device = ejtag_info->chain_pos;
field.num_bits = device->ir_length;
field.out_value = t;
@@ -53,18 +55,18 @@ int mips_ejtag_set_instr(mips_ejtag_t *ejtag_info, int new_instr, in_handler_t h
field.in_handler_priv = NULL;
jtag_add_ir_scan(1, &field, -1);
}
return ERROR_OK;
}

int mips_ejtag_get_idcode(mips_ejtag_t *ejtag_info, u32 *idcode, in_handler_t handler)
{
scan_field_t field;
jtag_add_end_state(TAP_RTI);
mips_ejtag_set_instr(ejtag_info, EJTAG_INST_IDCODE, NULL);
field.device = ejtag_info->chain_pos;
field.num_bits = 32;
field.out_value = NULL;
@@ -75,23 +77,23 @@ int mips_ejtag_get_idcode(mips_ejtag_t *ejtag_info, u32 *idcode, in_handler_t ha
field.in_handler = NULL;
field.in_handler_priv = NULL;
jtag_add_dr_scan(1, &field, -1);
if (jtag_execute_queue() != ERROR_OK)
{
LOG_ERROR("register read failed");
}
return ERROR_OK;
}

int mips_ejtag_get_impcode(mips_ejtag_t *ejtag_info, u32 *impcode, in_handler_t handler)
{
scan_field_t field;
jtag_add_end_state(TAP_RTI);
mips_ejtag_set_instr(ejtag_info, EJTAG_INST_IMPCODE, NULL);
field.device = ejtag_info->chain_pos;
field.num_bits = 32;
field.out_value = NULL;
@@ -102,12 +104,12 @@ int mips_ejtag_get_impcode(mips_ejtag_t *ejtag_info, u32 *impcode, in_handler_t
field.in_handler = NULL;
field.in_handler_priv = NULL;
jtag_add_dr_scan(1, &field, -1);
if (jtag_execute_queue() != ERROR_OK)
{
LOG_ERROR("register read failed");
}
return ERROR_OK;
}

@@ -115,10 +117,13 @@ 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;
field.device = ejtag_info->chain_pos;
field.num_bits = 32;
field.out_value = t;
@@ -130,18 +135,18 @@ int mips_ejtag_drscan_32(mips_ejtag_t *ejtag_info, u32 *data)
field.in_handler = NULL;
field.in_handler_priv = NULL;
jtag_add_dr_scan(1, &field, -1);
if ((retval = jtag_execute_queue()) != ERROR_OK)
{
LOG_ERROR("register read failed");
return retval;
}
return ERROR_OK;
}

int mips_ejtag_step_enable(mips_ejtag_t *ejtag_info)
{
{
u32 code[] = {
MIPS32_MTC0(1,31,0), /* move $1 to COP0 DeSave */
MIPS32_MFC0(1,23,0), /* move COP0 Debug to $1 */
@@ -152,10 +157,10 @@ int mips_ejtag_step_enable(mips_ejtag_t *ejtag_info)
MIPS32_B(NEG16(7)),
MIPS32_NOP,
};
mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
0, NULL, 0, NULL, 1);
return ERROR_OK;
}
int mips_ejtag_step_disable(mips_ejtag_t *ejtag_info)
@@ -178,17 +183,17 @@ int mips_ejtag_step_disable(mips_ejtag_t *ejtag_info)
MIPS32_B(NEG16(15)),
MIPS32_NOP,
};
mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
0, NULL, 0, NULL, 1);
return ERROR_OK;
}

int mips_ejtag_config_step(mips_ejtag_t *ejtag_info, int enable_step)
{
{
if (enable_step)
return mips_ejtag_step_enable(ejtag_info);
return mips_ejtag_step_enable(ejtag_info);
return mips_ejtag_step_disable(ejtag_info);
}

@@ -197,18 +202,18 @@ int mips_ejtag_enter_debug(mips_ejtag_t *ejtag_info)
u32 ejtag_ctrl;
jtag_add_end_state(TAP_RTI);
mips_ejtag_set_instr(ejtag_info, EJTAG_INST_CONTROL, NULL);
/* set debug break bit */
ejtag_ctrl = ejtag_info->ejtag_ctrl | EJTAG_CTRL_JTAGBRK;
mips_ejtag_drscan_32(ejtag_info, &ejtag_ctrl);
/* break bit will be cleared by hardware */
ejtag_ctrl = ejtag_info->ejtag_ctrl;
mips_ejtag_drscan_32(ejtag_info, &ejtag_ctrl);
LOG_DEBUG("ejtag_ctrl: 0x%8.8x", ejtag_ctrl);
if((ejtag_ctrl & EJTAG_CTRL_BRKST) == 0)
LOG_DEBUG("Failed to enter Debug Mode!");
return ERROR_OK;
}

@@ -216,12 +221,12 @@ int mips_ejtag_exit_debug(mips_ejtag_t *ejtag_info, int enable_interrupts)
{
u32 inst;
inst = MIPS32_DRET;
/* TODO : enable/disable interrrupts */
/* execute our dret instruction */
mips32_pracc_exec(ejtag_info, 1, &inst, 0, NULL, 0, NULL, 0);
return ERROR_OK;
}

@@ -245,23 +250,23 @@ int mips_ejtag_read_debug(mips_ejtag_t *ejtag_info, u32* debug_reg)
MIPS32_B(NEG16(14)),
MIPS32_NOP,
};
mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
0, NULL, 1, debug_reg, 1);
return ERROR_OK;
}

int mips_ejtag_init(mips_ejtag_t *ejtag_info)
{
u32 ejtag_version;
mips_ejtag_get_impcode(ejtag_info, &ejtag_info->impcode, NULL);
LOG_DEBUG("impcode: 0x%8.8x", ejtag_info->impcode);
/* get ejtag version */
ejtag_version = ((ejtag_info->impcode >> 29) & 0x07);
switch (ejtag_version)
{
case 0:
@@ -289,12 +294,12 @@ int mips_ejtag_init(mips_ejtag_t *ejtag_info)
ejtag_info->impcode & (1<<14) ? " noDMA": " DMA",
ejtag_info->impcode & (1<<0) ? " MIPS64": " MIPS32"
);
if((ejtag_info->impcode & (1<<14)) == 0)
LOG_DEBUG("EJTAG: DMA Access Mode Support Enabled");
/* set initial state for ejtag control reg */
ejtag_info->ejtag_ctrl = EJTAG_CTRL_ROCC | EJTAG_CTRL_PRACC | EJTAG_CTRL_PROBEN | EJTAG_CTRL_SETDEV;
return ERROR_OK;
}

+ 3
- 0
src/target/target.c 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 {


+ 2
- 0
src/target/xscale.c 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)
{


Loading…
Cancel
Save