/* forward declarations */
-void jtag_add_statemove(enum tap_state endstate);
void jtag_add_pathmove(int num_states, enum tap_state *path);
void jtag_add_runtest(int num_cycles, enum tap_state endstate);
-int jtag_add_reset(int trst, int srst);
void jtag_add_end_state(enum tap_state endstate);
void jtag_add_sleep(u32 us);
int jtag_execute_queue(void);
int handle_endstate_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_runtest_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
-int handle_statemove_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_drscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
{
jtag_event_callback_t *callback = jtag_event_callbacks;
- DEBUG("jtag event: %s", jtag_event_strings[event]);
+ LOG_DEBUG("jtag event: %s", jtag_event_strings[event]);
while (callback)
{
i++;
}
- ERROR("jtag device number %d not defined", num);
+ LOG_ERROR("jtag device number %d not defined", num);
exit(-1);
}
{
if (jtag_trst == 1)
{
- WARNING("JTAG command queued, while TRST is low (TAP in reset)");
+ LOG_WARNING("JTAG command queued, while TRST is low (TAP in reset)");
jtag_error=ERROR_JTAG_TRST_ASSERTED;
return;
}
jtag_prelude1();
if (state != -1)
- cmd_queue_end_state = state;
+ jtag_add_end_state(state);
cmd_queue_cur_state = cmd_queue_end_state;
}
/* if a device isn't listed, the BYPASS register should be selected */
if (!jtag_get_device(i)->bypass)
{
- ERROR("BUG: no scan data for a device not in BYPASS");
+ LOG_ERROR("BUG: no scan data for a device not in BYPASS");
exit(-1);
}
#endif
/* if a device is listed, the BYPASS register must not be selected */
if (jtag_get_device(i)->bypass)
{
- ERROR("BUG: scan data for a device in BYPASS");
+ LOG_ERROR("BUG: scan data for a device in BYPASS");
exit(-1);
}
#endif
/* if a device is listed, the BYPASS register must not be selected */
if (jtag_get_device(i)->bypass)
{
- ERROR("BUG: scan data for a device in BYPASS");
+ LOG_ERROR("BUG: scan data for a device in BYPASS");
exit(-1);
}
#endif
/* if a device isn't listed, the BYPASS register should be selected */
if (!jtag_get_device(i)->bypass)
{
- ERROR("BUG: no scan data for a device not in BYPASS");
+ LOG_ERROR("BUG: no scan data for a device not in BYPASS");
exit(-1);
}
#endif
return ERROR_OK;
}
-void jtag_add_statemove(enum tap_state state)
-{
- jtag_prelude(state);
+void jtag_add_tms()
+{
+ jtag_prelude(TAP_TLR);
+
int retval;
- retval=interface_jtag_add_statemove(cmd_queue_end_state);
+ retval=interface_jtag_add_tms();
if (retval!=ERROR_OK)
jtag_error=retval;
}
-int MINIDRIVER(interface_jtag_add_statemove)(enum tap_state state)
+int MINIDRIVER(interface_jtag_add_tms)()
{
+ enum tap_state state = TAP_TLR;
jtag_command_t **last_cmd = jtag_get_last_command_p();
/* allocate memory for a new list member */
/* the last state has to be a stable state */
if (tap_move_map[path[num_states - 1]] == -1)
{
- ERROR("BUG: TAP path doesn't finish in a stable state");
+ LOG_ERROR("BUG: TAP path doesn't finish in a stable state");
exit(-1);
}
if ((tap_transitions[cur_state].low != path[i])&&
(tap_transitions[cur_state].high != path[i]))
{
- ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_strings[cur_state], tap_state_strings[path[i]]);
+ LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_strings[cur_state], tap_state_strings[path[i]]);
exit(-1);
}
cur_state = path[i];
jtag_error=retval;
}
-int jtag_add_reset(int req_trst, int req_srst)
+void jtag_add_reset(int req_tms_or_trst, int req_srst)
{
int trst_with_tms = 0;
int retval;
- if (req_trst == -1)
- req_trst = jtag_trst;
-
- if (req_srst == -1)
- req_srst = jtag_srst;
-
/* Make sure that jtag_reset_config allows the requested reset */
/* if SRST pulls TRST, we can't fulfill srst == 1 with trst == 0 */
- if (((jtag_reset_config & RESET_SRST_PULLS_TRST) && (req_srst == 1)) && (req_trst == 0))
+ if (((jtag_reset_config & RESET_SRST_PULLS_TRST) && (req_srst == 1)) && (!req_tms_or_trst))
{
- ERROR("requested reset would assert trst");
- return ERROR_JTAG_RESET_WOULD_ASSERT_TRST;
+ LOG_ERROR("BUG: requested reset would assert trst");
+ jtag_error=ERROR_FAIL;
+ return;
}
/* if TRST pulls SRST, we reset with TAP T-L-R */
- if (((jtag_reset_config & RESET_TRST_PULLS_SRST) && (req_trst == 1)) && (req_srst == 0))
+ if (((jtag_reset_config & RESET_TRST_PULLS_SRST) && (req_tms_or_trst)) && (req_srst == 0))
{
- req_trst = 0;
trst_with_tms = 1;
}
if (req_srst && !(jtag_reset_config & RESET_HAS_SRST))
{
- ERROR("requested nSRST assertion, but the current configuration doesn't support this");
- return ERROR_JTAG_RESET_CANT_SRST;
+ LOG_ERROR("BUG: requested SRST assertion, but the current configuration doesn't support this");
+ jtag_error=ERROR_FAIL;
+ return;
}
- if (req_trst && !(jtag_reset_config & RESET_HAS_TRST))
+ if (req_tms_or_trst)
{
- req_trst = 0;
- trst_with_tms = 1;
+ if (!trst_with_tms && (jtag_reset_config & RESET_HAS_TRST))
+ {
+ jtag_trst = 1;
+ } else
+ {
+ trst_with_tms = 1;
+ }
+ } else
+ {
+ jtag_trst = 0;
}
-
- jtag_trst = req_trst;
+
jtag_srst = req_srst;
- retval = interface_jtag_add_reset(req_trst, req_srst);
+ retval = interface_jtag_add_reset(jtag_trst, jtag_srst);
if (retval!=ERROR_OK)
{
jtag_error=retval;
- return retval;
+ return;
}
if (jtag_srst)
{
- DEBUG("SRST line asserted");
+ LOG_DEBUG("SRST line asserted");
}
else
{
- DEBUG("SRST line released");
+ LOG_DEBUG("SRST line released");
if (jtag_nsrst_delay)
jtag_add_sleep(jtag_nsrst_delay * 1000);
}
if (trst_with_tms)
{
- DEBUG("JTAG reset with tms instead of TRST");
+ LOG_DEBUG("JTAG reset with tms instead of TRST");
jtag_add_end_state(TAP_TLR);
- jtag_add_statemove(TAP_TLR);
+ jtag_add_tms();
jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
- return ERROR_OK;
+ return;
}
if (jtag_trst)
/* we just asserted nTRST, so we're now in Test-Logic-Reset,
* and inform possible listeners about this
*/
- DEBUG("TRST line asserted");
+ LOG_DEBUG("TRST line asserted");
cmd_queue_cur_state = TAP_TLR;
jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
}
else
{
- /* the nTRST line got deasserted, so we're still in Test-Logic-Reset,
- * but we might want to add a delay to give the TAP time to settle
- */
- DEBUG("Now in TAP_TLR - Test-Logic-Reset(either due to TRST line asserted or tms reset)");
if (jtag_ntrst_delay)
jtag_add_sleep(jtag_ntrst_delay * 1000);
}
- return ERROR_OK;
}
int MINIDRIVER(interface_jtag_add_reset)(int req_trst, int req_srst)
void jtag_add_end_state(enum tap_state state)
{
cmd_queue_end_state = state;
+ if ((cmd_queue_end_state == TAP_SD)||(cmd_queue_end_state == TAP_SD))
+ {
+ LOG_ERROR("BUG: TAP_SD/SI can't be end state. Calling code should use a larger scan field");
+ }
}
int MINIDRIVER(interface_jtag_add_sleep)(u32 us)
#endif
buf_set_buf(cmd->fields[i].out_value, 0, *buffer, bit_count, cmd->fields[i].num_bits);
#ifdef _DEBUG_JTAG_IO_
- DEBUG("fields[%i].out_value: 0x%s", i, char_buf);
+ LOG_DEBUG("fields[%i].out_value: 0x%s", i, char_buf);
free(char_buf);
#endif
}
char *char_buf;
char_buf = buf_to_str(captured, (num_bits > 64) ? 64 : num_bits, 16);
- DEBUG("fields[%i].in_value: 0x%s", i, char_buf);
+ LOG_DEBUG("fields[%i].in_value: 0x%s", i, char_buf);
free(char_buf);
#endif
{
if (cmd->fields[i].in_handler(cmd->fields[i].in_value, cmd->fields[i].in_handler_priv, cmd->fields+i) != ERROR_OK)
{
- WARNING("in_handler reported a failed check");
+ LOG_WARNING("in_handler reported a failed check");
retval = ERROR_JTAG_QUEUE_FAILED;
}
}
/* We're going to call the error:handler later, but if the in_handler
* reported an error we report this failure upstream
*/
- WARNING("in_handler reported a failed check");
+ LOG_WARNING("in_handler reported a failed check");
retval = ERROR_JTAG_QUEUE_FAILED;
}
}
{
char *in_check_mask_char;
in_check_mask_char = buf_to_str(field->in_check_mask, (num_bits > 64) ? 64 : num_bits, 16);
- WARNING("value captured during scan didn't pass the requested check: captured: 0x%s check_value: 0x%s check_mask: 0x%s", captured_char, in_check_value_char, in_check_mask_char);
+ LOG_WARNING("value captured during scan didn't pass the requested check: captured: 0x%s check_value: 0x%s check_mask: 0x%s", captured_char, in_check_value_char, in_check_mask_char);
free(in_check_mask_char);
}
else
{
- WARNING("value captured during scan didn't pass the requested check: captured: 0x%s check_value: 0x%s", captured_char, in_check_value_char);
+ LOG_WARNING("value captured during scan didn't pass the requested check: captured: 0x%s check_value: 0x%s", captured_char, in_check_value_char);
}
free(captured_char);
{
jtag_device_t *device = priv;
- DEBUG("-");
+ LOG_DEBUG("-");
if (event == JTAG_TRST_ASSERTED)
{
/* if there wasn't a single non-zero bit or if all bits were one, the scan isn't valid */
if ((zero_check == 0x00) || (one_check == 0xff))
{
- ERROR("JTAG communication failure, check connection, JTAG interface, target power etc.");
+ LOG_ERROR("JTAG communication failure, check connection, JTAG interface, target power etc.");
return ERROR_JTAG_INIT_FAILED;
}
part = (idcode & 0xffff000) >> 12;
version = (idcode & 0xf0000000) >> 28;
- INFO("JTAG device found: 0x%8.8x (Manufacturer: 0x%3.3x, Part: 0x%4.4x, Version: 0x%1.1x)",
+ LOG_INFO("JTAG device found: 0x%8.8x (Manufacturer: 0x%3.3x, Part: 0x%4.4x, Version: 0x%1.1x)",
idcode, manufacturer, part, version);
bit_count += 32;
/* see if number of discovered devices matches configuration */
if (device_count != jtag_num_devices)
{
- ERROR("number of discovered devices in JTAG chain (%i) doesn't match configuration (%i)",
+ LOG_ERROR("number of discovered devices in JTAG chain (%i) doesn't match configuration (%i)",
device_count, jtag_num_devices);
- ERROR("check the config file and ensure proper JTAG communication (connections, speed, ...)");
+ LOG_ERROR("check the config file and ensure proper JTAG communication (connections, speed, ...)");
return ERROR_JTAG_INIT_FAILED;
}
if (buf_get_u32(ir_test, chain_pos, 2) != 0x1)
{
char *cbuf = buf_to_str(ir_test, total_ir_length, 16);
- ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf);
+ LOG_ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf);
free(cbuf);
free(ir_test);
return ERROR_JTAG_INIT_FAILED;
if (buf_get_u32(ir_test, chain_pos, 2) != 0x3)
{
char *cbuf = buf_to_str(ir_test, total_ir_length, 16);
- ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf);
+ LOG_ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf);
free(cbuf);
free(ir_test);
return ERROR_JTAG_INIT_FAILED;
COMMAND_EXEC, "toggle reset lines <trst> <srst>");
register_command(cmd_ctx, NULL, "runtest", handle_runtest_command,
COMMAND_EXEC, "move to Run-Test/Idle, and execute <num_cycles>");
- register_command(cmd_ctx, NULL, "statemove", handle_statemove_command,
- COMMAND_EXEC, "move to current endstate or [tap_state]");
register_command(cmd_ctx, NULL, "irscan", handle_irscan_command,
COMMAND_EXEC, "execute IR scan <device> <instr> [dev2] [instr2] ...");
register_command(cmd_ctx, NULL, "drscan", handle_drscan_command,
if (!jtag_interface)
{
/* nothing was previously specified by "interface" command */
- ERROR("JTAG interface has to be specified, see \"interface\" command");
+ LOG_ERROR("JTAG interface has to be specified, see \"interface\" command");
return ERROR_JTAG_INVALID_INTERFACE;
}
int validate_tries = 0;
jtag_device_t *device;
- DEBUG("-");
+ LOG_DEBUG("-");
if (!jtag && jtag_interface_init(cmd_ctx) != ERROR_OK)
return ERROR_JTAG_INIT_FAILED;
device = device->next;
}
- jtag_add_statemove(TAP_TLR);
+ jtag_add_tms();
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...");
+ LOG_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");
+ LOG_ERROR("Could not validate JTAG chain, exit");
return ERROR_JTAG_INVALID_INTERFACE;
}
usleep(10000);
static int default_khz(int khz, int *jtag_speed)
{
- ERROR("Translation from khz to jtag_speed not implemented");
+ LOG_ERROR("Translation from khz to jtag_speed not implemented");
return ERROR_FAIL;
}
/* check whether the interface is already configured */
if (jtag_interface)
{
- WARNING("Interface already configured, ignoring");
+ LOG_WARNING("Interface already configured, ignoring");
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)", args[0]);
- ERROR("compiled-in jtag interfaces:");
+ LOG_ERROR("No valid jtag interface found (%s)", args[0]);
+ LOG_ERROR("compiled-in jtag interfaces:");
for (i = 0; jtag_interfaces[i]; i++)
{
- ERROR("%i: %s", i, jtag_interfaces[i]->name);
+ LOG_ERROR("%i: %s", i, jtag_interfaces[i]->name);
}
return ERROR_JTAG_INVALID_INTERFACE;
int handle_reset_config_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
+ if (argc < 1)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+
if (argc >= 1)
{
if (strcmp(args[0], "none") == 0)
jtag_reset_config = RESET_TRST_AND_SRST;
else
{
- ERROR("invalid reset_config argument, defaulting to none");
+ LOG_ERROR("invalid reset_config argument, defaulting to none");
jtag_reset_config = RESET_NONE;
return ERROR_INVALID_ARGUMENTS;
}
if (argc >= 2)
{
- if (strcmp(args[1], "srst_pulls_trst") == 0)
- jtag_reset_config |= RESET_SRST_PULLS_TRST;
- else if (strcmp(args[1], "trst_pulls_srst") == 0)
- jtag_reset_config |= RESET_TRST_PULLS_SRST;
- else if (strcmp(args[1], "combined") == 0)
- jtag_reset_config |= RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST;
- else if (strcmp(args[1], "separate") == 0)
- jtag_reset_config &= ~(RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST);
- else
+ if (strcmp(args[1], "separate") == 0)
{
- ERROR("invalid reset_config argument, defaulting to none");
- jtag_reset_config = RESET_NONE;
- return ERROR_INVALID_ARGUMENTS;
+ /* seperate reset lines - default */
+ } else
+ {
+ if (strcmp(args[1], "srst_pulls_trst") == 0)
+ jtag_reset_config |= RESET_SRST_PULLS_TRST;
+ else if (strcmp(args[1], "trst_pulls_srst") == 0)
+ jtag_reset_config |= RESET_TRST_PULLS_SRST;
+ else if (strcmp(args[1], "combined") == 0)
+ jtag_reset_config |= RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST;
+ else
+ {
+ LOG_ERROR("invalid reset_config argument, defaulting to none");
+ jtag_reset_config = RESET_NONE;
+ return ERROR_INVALID_ARGUMENTS;
+ }
}
}
jtag_reset_config &= ~RESET_TRST_OPEN_DRAIN;
else
{
- ERROR("invalid reset_config argument, defaulting to none");
+ LOG_ERROR("invalid reset_config argument, defaulting to none");
jtag_reset_config = RESET_NONE;
return ERROR_INVALID_ARGUMENTS;
}
jtag_reset_config &= ~RESET_SRST_PUSH_PULL;
else
{
- ERROR("invalid reset_config argument, defaulting to none");
+ LOG_ERROR("invalid reset_config argument, defaulting to none");
jtag_reset_config = RESET_NONE;
return ERROR_INVALID_ARGUMENTS;
}
{
if (argc < 1)
{
- ERROR("jtag_nsrst_delay <ms> command takes one required argument");
+ LOG_ERROR("jtag_nsrst_delay <ms> command takes one required argument");
exit(-1);
}
else
{
if (argc < 1)
{
- ERROR("jtag_ntrst_delay <ms> command takes one required argument");
+ LOG_ERROR("jtag_ntrst_delay <ms> command takes one required argument");
exit(-1);
}
else
if (jtag == NULL)
{
- ERROR("Interface not selected yet");
+ LOG_ERROR("Interface not selected yet");
return ERROR_COMMAND_SYNTAX_ERROR;
}
}
-int handle_statemove_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
-{
- enum tap_state state;
-
- state = -1;
- if (argc == 1)
- {
- for (state = 0; state < 16; state++)
- {
- if (strcmp(args[0], tap_state_strings[state]) == 0)
- {
- break;
- }
- }
- }
-
- jtag_add_statemove(state);
- jtag_execute_queue();
-
- return ERROR_OK;
-
-}
int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{