jtag_interface_t *jtag = NULL;
/* configuration */
-char* jtag_interface = NULL;
-int jtag_speed = -1;
+jtag_interface_t *jtag_interface = NULL;
+int jtag_speed = 0;
/* forward declarations */
device = device->next;
i++;
}
-
- return NULL;
+
+ ERROR("jtag device number %d not defined", num);
+ exit(-1);
}
void* cmd_queue_alloc(size_t size)
cmd_queue_pages = NULL;
}
-int jtag_add_ir_scan(int num_fields, scan_field_t *fields, enum tap_state state, void *dummy_anachronism)
+int jtag_add_ir_scan(int num_fields, scan_field_t *fields, enum tap_state state)
{
jtag_command_t **last_cmd;
jtag_device_t *device;
return ERROR_OK;
}
-int jtag_add_plain_ir_scan(int num_fields, scan_field_t *fields, enum tap_state state, void *dummy_anachronism)
+int jtag_add_plain_ir_scan(int num_fields, scan_field_t *fields, enum tap_state state)
{
jtag_command_t **last_cmd;
int i;
return ERROR_OK;
}
-int jtag_add_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state, void *dummy_anachronism)
+int jtag_add_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state)
{
int i, j;
int bypass_devices = 0;
return ERROR_OK;
}
-int jtag_add_plain_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state, void *dummy_anachronism)
+
+int jtag_add_plain_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state)
{
int i;
jtag_command_t **last_cmd = jtag_get_last_command_p();
return ERROR_JTAG_NOT_IMPLEMENTED;
}
- if (jtag->support_pathmove)
- {
- /* allocate memory for a new list member */
- *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
- last_comand_pointer = &((*last_cmd)->next);
- (*last_cmd)->next = NULL;
- (*last_cmd)->type = JTAG_PATHMOVE;
+ /* allocate memory for a new list member */
+ *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
+ last_comand_pointer = &((*last_cmd)->next);
+ (*last_cmd)->next = NULL;
+ (*last_cmd)->type = JTAG_PATHMOVE;
+
+ (*last_cmd)->cmd.pathmove = cmd_queue_alloc(sizeof(pathmove_command_t));
+ (*last_cmd)->cmd.pathmove->num_states = num_states;
+ (*last_cmd)->cmd.pathmove->path = cmd_queue_alloc(sizeof(enum tap_state) * num_states);
- (*last_cmd)->cmd.pathmove = cmd_queue_alloc(sizeof(pathmove_command_t));
- (*last_cmd)->cmd.pathmove->num_states = num_states;
- (*last_cmd)->cmd.pathmove->path = cmd_queue_alloc(sizeof(enum tap_state) * num_states);
-
- for (i = 0; i < num_states; i++)
- (*last_cmd)->cmd.pathmove->path[i] = path[i];
- }
- else
- {
- /* validate the desired path, and see if it fits a default path */
- int begin = 0;
- int end = 0;
- int j;
-
- for (i = 0; i < num_states; i++)
- {
- for (j = i; j < num_states; j++)
- {
- if (tap_move_map[path[j]] != -1)
- {
- end = j;
- break;
- }
- }
-
- if (begin - end <= 7) /* a default path spans no more than 7 states */
- {
- jtag_add_statemove(path[end]);
- }
- else
- {
- ERROR("encountered a TAP path that can't be fulfilled by default paths");
- return ERROR_JTAG_NOT_IMPLEMENTED;
- }
-
- i = end;
- }
- }
+ for (i = 0; i < num_states; i++)
+ (*last_cmd)->cmd.pathmove->path[i] = path[i];
if (cmd_queue_cur_state == TAP_TLR && cmd_queue_end_state != TAP_TLR)
jtag_call_event_callbacks(JTAG_TRST_RELEASED);
free(captured_char);
free(in_check_value_char);
+
+ retval = ERROR_JTAG_QUEUE_FAILED;
}
}
return retval;
}
-int jtag_cancel_queue(void)
-{
- cmd_queue_free();
- jtag_command_queue = NULL;
- last_comand_pointer = &jtag_command_queue;
-
- return ERROR_OK;
-}
-
int jtag_reset_callback(enum jtag_event event, void *priv)
{
jtag_device_t *device = priv;
buf_set_u32(idcode_buffer, i * 32, 32, 0x000000FF);
}
- jtag_add_plain_dr_scan(1, &field, TAP_TLR, NULL);
+ jtag_add_plain_dr_scan(1, &field, TAP_TLR);
jtag_execute_queue();
for (i = 0; i < JTAG_MAX_CHAIN_SIZE * 4; i++)
field.in_handler = NULL;
field.in_handler_priv = NULL;
- jtag_add_plain_ir_scan(1, &field, TAP_TLR, NULL);
+ jtag_add_plain_ir_scan(1, &field, TAP_TLR);
jtag_execute_queue();
device = jtag_devices;
register_command(cmd_ctx, NULL, "jtag_speed", handle_jtag_speed_command,
COMMAND_ANY, "set jtag speed (if supported) <speed>");
register_command(cmd_ctx, NULL, "jtag_device", handle_jtag_device_command,
- COMMAND_CONFIG, NULL);
+ COMMAND_CONFIG, "jtag_device <ir_length> <ir_expected> <ir_mask>");
register_command(cmd_ctx, NULL, "reset_config", handle_reset_config_command,
COMMAND_CONFIG, NULL);
register_command(cmd_ctx, NULL, "jtag_nsrst_delay", handle_jtag_nsrst_delay_command,
return ERROR_OK;
}
+int jtag_interface_init(struct command_context_s *cmd_ctx)
+{
+ if (!jtag_interface)
+ {
+ /* nothing was previously specified by "interface" command */
+ ERROR("JTAG interface has to be specified, see \"interface\" command");
+ return ERROR_JTAG_INVALID_INTERFACE;
+ }
+
+ if (jtag_interface->init() != ERROR_OK)
+ return ERROR_JTAG_INIT_FAILED;
+
+ jtag = jtag_interface;
+ return ERROR_OK;
+}
+
int jtag_init(struct command_context_s *cmd_ctx)
{
int i, validate_tries = 0;
-
+ jtag_device_t *device;
+
DEBUG("-");
+
+ if (!jtag && jtag_interface_init(cmd_ctx) != ERROR_OK)
+ return ERROR_JTAG_INIT_FAILED;
- if (jtag_speed == -1)
- jtag_speed = 0;
+ device = jtag_devices;
+ jtag_ir_scan_size = 0;
+ jtag_num_devices = 0;
+ while (device != NULL)
+ {
+ jtag_ir_scan_size += device->ir_length;
+ jtag_num_devices++;
+ device = device->next;
+ }
- if (jtag_interface && (jtag_interface[0] != 0))
- /* configuration var 'jtag_interface' is set, and not empty */
- for (i = 0; jtag_interfaces[i]; i++)
- {
- if (strcmp(jtag_interface, jtag_interfaces[i]->name) == 0)
- {
- jtag_device_t *device;
- device = jtag_devices;
+ jtag_add_statemove(TAP_TLR);
+ jtag_execute_queue();
+
+ /* examine chain first, as this could discover the real chain layout */
+ if (jtag_examine_chain() != ERROR_OK)
+ {
+ ERROR("trying to validate configured JTAG chain anyway...");
+ }
- if (jtag_interfaces[i]->init() != ERROR_OK)
- return ERROR_JTAG_INIT_FAILED;
- jtag = jtag_interfaces[i];
+ while (jtag_validate_chain() != ERROR_OK)
+ {
+ validate_tries++;
+ if (validate_tries > 5)
+ {
+ ERROR("Could not validate JTAG chain, exit");
+ jtag = NULL;
+ return ERROR_JTAG_INVALID_INTERFACE;
+ }
+ usleep(10000);
+ }
- jtag_ir_scan_size = 0;
- jtag_num_devices = 0;
- while (device != NULL)
- {
- jtag_ir_scan_size += device->ir_length;
- jtag_num_devices++;
- device = device->next;
- }
-
- jtag_add_statemove(TAP_TLR);
- jtag_execute_queue();
+ return ERROR_OK;
+}
- /* examine chain first, as this could discover the real chain layout */
- if (jtag_examine_chain() != ERROR_OK)
- {
- ERROR("trying to validate configured JTAG chain anyway...");
- }
-
- while (jtag_validate_chain() != ERROR_OK)
- {
- validate_tries++;
- if (validate_tries > 5)
- {
- ERROR("Could not validate JTAG chain, exit");
- jtag = NULL;
- return ERROR_JTAG_INVALID_INTERFACE;
- }
- usleep(10000);
- }
+int handle_interface_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+{
+ int i;
- return ERROR_OK;
- }
+ /* check whether the interface is already configured */
+ if (jtag_interface)
+ {
+ WARNING("Interface already configured, ignoring");
+ return ERROR_OK;
+ }
+
+ /* interface name is a mandatory argument */
+ if (argc < 1 || args[0][0] == '\0')
+ {
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ }
+
+ for (i=0; jtag_interfaces[i]; i++)
+ {
+ if (strcmp(args[0], jtag_interfaces[i]->name) == 0)
+ {
+ if (jtag_interfaces[i]->register_commands(cmd_ctx) != ERROR_OK)
+ exit(-1);
+
+ jtag_interface = jtag_interfaces[i];
+ return ERROR_OK;
}
-
+ }
+
/* no valid interface was found (i.e. the configuration option,
* didn't match one of the compiled-in interfaces
*/
- ERROR("No valid jtag interface found (%s)", jtag_interface);
+ ERROR("No valid jtag interface found (%s)", args[0]);
ERROR("compiled-in jtag interfaces:");
for (i = 0; jtag_interfaces[i]; i++)
{
ERROR("%i: %s", i, jtag_interfaces[i]->name);
}
-
- jtag = NULL;
- return ERROR_JTAG_INVALID_INTERFACE;
-}
-int handle_interface_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
-{
- int i;
-
- /* only if the configuration var isn't overwritten from cmdline */
- if (!jtag_interface)
- {
- if (args[0] && (args[0][0] != 0))
- {
- for (i=0; jtag_interfaces[i]; i++)
- {
- if (strcmp(args[0], jtag_interfaces[i]->name) == 0)
- {
- if (jtag_interfaces[i]->register_commands(cmd_ctx) != ERROR_OK)
- exit(-1);
-
- jtag_interface = jtag_interfaces[i]->name;
-
- return ERROR_OK;
- }
- }
- }
-
- /* remember the requested interface name, so we can complain about it later */
- jtag_interface = strdup(args[0]);
- DEBUG("'interface' command didn't specify a valid interface");
- }
-
- return ERROR_OK;
+ return ERROR_JTAG_INVALID_INTERFACE;
}
int handle_jtag_device_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
if (argc < 1)
{
- command_print(cmd_ctx, "usage: endstate <tap_state>");
+ return ERROR_COMMAND_SYNTAX_ERROR;
}
else
{
{
int trst = -1;
int srst = -1;
- char *usage = "usage: jtag_reset <trst> <srst>";
int retval;
- if (argc < 1)
+ if (argc < 2)
{
- command_print(cmd_ctx, usage);
- return ERROR_OK;
+ return ERROR_COMMAND_SYNTAX_ERROR;
+
}
if (args[0][0] == '1')
trst = 0;
else
{
- command_print(cmd_ctx, usage);
- return ERROR_OK;
+ return ERROR_COMMAND_SYNTAX_ERROR;
}
if (args[1][0] == '1')
srst = 0;
else
{
- command_print(cmd_ctx, usage);
- return ERROR_OK;
+ return ERROR_COMMAND_SYNTAX_ERROR;
}
+ if (!jtag && jtag_interface_init(cmd_ctx) != ERROR_OK)
+ return ERROR_JTAG_INIT_FAILED;
+
if ((retval = jtag_add_reset(trst, srst)) != ERROR_OK)
{
switch (retval)
{
if (argc < 1)
{
- command_print(cmd_ctx, "usage: runtest <num_cycles>");
- return ERROR_OK;
+ return ERROR_COMMAND_SYNTAX_ERROR;
}
jtag_add_runtest(strtol(args[0], NULL, 0), -1);
if ((argc < 2) || (argc % 2))
{
- command_print(cmd_ctx, "usage: irscan <device> <instr> [dev2] [instr2] ...");
- return ERROR_OK;
+ return ERROR_COMMAND_SYNTAX_ERROR;
}
fields = malloc(sizeof(scan_field_t) * argc / 2);
fields[i].in_handler_priv = NULL;
}
- jtag_add_ir_scan(argc / 2, fields, -1, NULL);
+ jtag_add_ir_scan(argc / 2, fields, -1);
jtag_execute_queue();
for (i = 0; i < argc / 2; i++)
if ((argc < 2) || (argc % 2))
{
- command_print(cmd_ctx, "usage: drscan <device> <var> [dev2] [var2]");
- return ERROR_OK;
+ return ERROR_COMMAND_SYNTAX_ERROR;
}
for (i = 0; i < argc; i+=2)
}
}
- jtag_add_dr_scan(num_fields, fields, -1, NULL);
+ jtag_add_dr_scan(num_fields, fields, -1);
jtag_execute_queue();
for (i = 0; i < argc / 2; i++)
int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
- if (argc == 0)
- {
- command_print(cmd_ctx, "verify Capture-IR is %s", (jtag_verify_capture_ir) ? "enabled": "disabled");
- return ERROR_OK;
- }
-
- if (strcmp(args[0], "enable") == 0)
+ if (argc == 1)
{
- jtag_verify_capture_ir = 1;
- }
- else if (strcmp(args[0], "disable") == 0)
+ if (strcmp(args[0], "enable") == 0)
+ {
+ jtag_verify_capture_ir = 1;
+ }
+ else if (strcmp(args[0], "disable") == 0)
+ {
+ jtag_verify_capture_ir = 0;
+ } else
+ {
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ }
+ } else if (argc != 0)
{
- jtag_verify_capture_ir = 0;
+ return ERROR_COMMAND_SYNTAX_ERROR;
}
+ command_print(cmd_ctx, "verify Capture-IR is %s", (jtag_verify_capture_ir) ? "enabled": "disabled");
+
return ERROR_OK;
}