X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fjtag%2Fjtag.c;h=5ec8297d246f565fb3836bb9a67c443d0edf80c2;hb=5279d519f8e98d6a134e77b54669512f618672bd;hp=c4015118ca96f2543d578b790a56993518eee24e;hpb=e482118106c63edd3c9f6647e4232e90b4c16066;p=openocd.git diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c index c4015118ca..5ec8297d24 100644 --- a/src/jtag/jtag.c +++ b/src/jtag/jtag.c @@ -204,8 +204,8 @@ jtag_interface_t *jtag_interfaces[] = { 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 */ @@ -379,7 +379,7 @@ void cmd_queue_free() 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; @@ -472,7 +472,7 @@ int jtag_add_ir_scan(int num_fields, scan_field_t *fields, enum tap_state state, 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; @@ -526,7 +526,7 @@ int jtag_add_plain_ir_scan(int num_fields, scan_field_t *fields, enum tap_state 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; @@ -625,7 +625,8 @@ int jtag_add_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state, 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(); @@ -1168,7 +1169,7 @@ int jtag_examine_chain() 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++) @@ -1264,7 +1265,7 @@ int jtag_validate_chain() 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; @@ -1332,105 +1333,106 @@ int jtag_register_commands(struct command_context_s *cmd_ctx) 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; - + int 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) @@ -1610,7 +1612,7 @@ int handle_endstate_command(struct command_context_s *cmd_ctx, char *cmd, char * if (argc < 1) { - return ERROR_COMMAND_SYNTAX_ERROR; + return ERROR_COMMAND_SYNTAX_ERROR; } else { @@ -1634,10 +1636,10 @@ int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cmd, char int srst = -1; int retval; - if (argc < 1) + if (argc < 2) { - return ERROR_COMMAND_SYNTAX_ERROR; - + return ERROR_COMMAND_SYNTAX_ERROR; + } if (args[0][0] == '1') @@ -1646,7 +1648,7 @@ int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cmd, char trst = 0; else { - return ERROR_COMMAND_SYNTAX_ERROR; + return ERROR_COMMAND_SYNTAX_ERROR; } if (args[1][0] == '1') @@ -1655,9 +1657,12 @@ int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cmd, char srst = 0; else { - return ERROR_COMMAND_SYNTAX_ERROR; + 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) @@ -1681,7 +1686,7 @@ int handle_runtest_command(struct command_context_s *cmd_ctx, char *cmd, char ** { if (argc < 1) { - return ERROR_COMMAND_SYNTAX_ERROR; + return ERROR_COMMAND_SYNTAX_ERROR; } jtag_add_runtest(strtol(args[0], NULL, 0), -1); @@ -1721,7 +1726,7 @@ int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **a if ((argc < 2) || (argc % 2)) { - return ERROR_COMMAND_SYNTAX_ERROR; + return ERROR_COMMAND_SYNTAX_ERROR; } fields = malloc(sizeof(scan_field_t) * argc / 2); @@ -1740,7 +1745,7 @@ int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **a 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++) @@ -1761,7 +1766,7 @@ int handle_drscan_command(struct command_context_s *cmd_ctx, char *cmd, char **a if ((argc < 2) || (argc % 2)) { - return ERROR_COMMAND_SYNTAX_ERROR; + return ERROR_COMMAND_SYNTAX_ERROR; } for (i = 0; i < argc; i+=2) @@ -1799,7 +1804,7 @@ int handle_drscan_command(struct command_context_s *cmd_ctx, char *cmd, char **a } } - 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++) @@ -1812,7 +1817,7 @@ int handle_drscan_command(struct command_context_s *cmd_ctx, char *cmd, char **a int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { - if (argc == 1) + if (argc == 1) { if (strcmp(args[0], "enable") == 0) { @@ -1821,16 +1826,16 @@ int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, char *cmd else if (strcmp(args[0], "disable") == 0) { jtag_verify_capture_ir = 0; - } else - { - return ERROR_COMMAND_SYNTAX_ERROR; + } else + { + return ERROR_COMMAND_SYNTAX_ERROR; } - } else if (argc != 0) - { - return ERROR_COMMAND_SYNTAX_ERROR; - } - - command_print(cmd_ctx, "verify Capture-IR is %s", (jtag_verify_capture_ir) ? "enabled": "disabled"); + } else if (argc != 0) + { + return ERROR_COMMAND_SYNTAX_ERROR; + } + + command_print(cmd_ctx, "verify Capture-IR is %s", (jtag_verify_capture_ir) ? "enabled": "disabled"); return ERROR_OK; }