* Copyright (C) 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
+ * Copyright (C) 2007,2008 Øyvind Harboe *
+ * oyvind.harboe@zylin.com *
+ * *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
jtag_event_callback_t *jtag_event_callbacks;
/* speed in kHz*/
-static int speed1 = 0, speed2 = 0;
+static int speed_khz = 0;
/* flag if the kHz speed was defined */
static int hasKHz = 0;
/* configuration */
jtag_interface_t *jtag_interface = NULL;
int jtag_speed = 0;
-int jtag_speed_post_reset = 0;
+
/* forward declarations */
return t + offset;
}
-void cmd_queue_free()
+void cmd_queue_free(void)
{
cmd_queue_page_t *page = cmd_queue_pages;
cmd_queue_pages = NULL;
}
-static void jtag_prelude1()
+static void jtag_prelude1(void)
{
if (jtag_trst == 1)
{
}
}
-
-
-
void jtag_add_plain_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state)
{
int retval;
for (i=0; i<num_states; i++)
{
+ if (path[i] == TAP_TLR)
+ {
+ LOG_ERROR("BUG: TAP_TLR is not a valid state for pathmove sequences");
+ exit(-1);
+ }
if ((tap_transitions[cur_state].low != path[i])&&
(tap_transitions[cur_state].high != path[i]))
{
jtag_prelude1();
- cmd_queue_cur_state = path[num_states - 1];
retval=interface_jtag_add_pathmove(num_states, path);
+ cmd_queue_cur_state = path[num_states - 1];
if (retval!=ERROR_OK)
jtag_error=retval;
}
-
int MINIDRIVER(interface_jtag_add_pathmove)(int num_states, enum tap_state *path)
{
jtag_command_t **last_cmd = jtag_get_last_command_p();
(*last_cmd)->cmd.reset->trst = req_trst;
(*last_cmd)->cmd.reset->srst = req_srst;
-
return ERROR_OK;
}
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))
+ if ((cmd_queue_end_state == TAP_SD)||(cmd_queue_end_state == TAP_SI))
{
LOG_ERROR("BUG: TAP_SD/SI can't be end state. Calling code should use a larger scan field");
}
void jtag_add_sleep(u32 us)
{
+ keep_alive(); /* we might be running on a very slow JTAG clk */
int retval=interface_jtag_add_sleep(us);
if (retval!=ERROR_OK)
jtag_error=retval;
}
return bit_count;
-
}
int jtag_read_buffer(u8 *buffer, scan_command_t *cmd)
/* LSB must not be 0, this indicates a device in bypass */
device_count++;
+ LOG_WARNING("Device was in bypass after TRST/TMS reset");
+
bit_count += 1;
}
else
if (idcode == 0x000000FF)
{
- /* End of chain (invalid manufacturer ID) */
+ int unexpected=0;
+ /* End of chain (invalid manufacturer ID)
+ *
+ * The JTAG examine is the very first thing that happens
+ *
+ * A single JTAG device requires only 64 bits to be read back correctly.
+ *
+ * The code below adds a check that the rest of the data scanned (640 bits)
+ * are all as expected. This helps diagnose/catch problems with the JTAG chain
+ *
+ * earlier and gives more helpful/explicit error messages.
+ */
+ for (bit_count += 32; bit_count < (JTAG_MAX_CHAIN_SIZE * 32) - 31;bit_count += 32)
+ {
+ idcode = buf_get_u32(idcode_buffer, bit_count, 32);
+ if (unexpected||(idcode != 0x000000FF))
+ {
+ LOG_WARNING("Unexpected idcode after end of chain! %d 0x%08x", bit_count, idcode);
+ unexpected = 1;
+ }
+ }
+
break;
}
return ERROR_OK;
}
-int jtag_validate_chain()
+int jtag_validate_chain(void)
{
jtag_device_t *device = jtag_devices;
int total_ir_length = 0;
register_command(cmd_ctx, NULL, "interface", handle_interface_command,
COMMAND_CONFIG, NULL);
register_command(cmd_ctx, NULL, "jtag_speed", handle_jtag_speed_command,
- COMMAND_ANY, "set jtag speed (if supported) <reset speed> [<post reset speed, default value is reset speed>]");
+ COMMAND_ANY, "set jtag speed (if supported)");
register_command(cmd_ctx, NULL, "jtag_khz", handle_jtag_khz_command,
COMMAND_ANY, "same as jtag_speed, except it takes maximum khz as arguments. 0 KHz = RTCK.");
register_command(cmd_ctx, NULL, "jtag_device", handle_jtag_device_command,
}
if(hasKHz)
{
- /*stay on "reset speed"*/
- jtag_interface->khz(speed1, &jtag_speed);
- jtag_interface->khz(speed2, &jtag_speed_post_reset);
+ jtag_interface->khz(speed_khz, &jtag_speed);
hasKHz = 0;
}
return jtag_init_reset(cmd_ctx);
}
-
static int default_khz(int khz, int *jtag_speed)
{
LOG_ERROR("Translation from khz to jtag_speed not implemented");
int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
- int cur_speed = 0;
+ int retval=ERROR_OK;
- if (argc != 0)
+ if (argc == 1)
{
- if ((argc<1) || (argc>2))
- return ERROR_COMMAND_SYNTAX_ERROR;
-
LOG_DEBUG("handle jtag speed");
-
- if (argc >= 1)
- cur_speed = jtag_speed = jtag_speed_post_reset = strtoul(args[0], NULL, 0);
- if (argc == 2)
- cur_speed = jtag_speed_post_reset = strtoul(args[1], NULL, 0);
+
+ int cur_speed = 0;
+ cur_speed = jtag_speed = strtoul(args[0], NULL, 0);
/* this command can be called during CONFIG,
* in which case jtag isn't initialized */
if (jtag)
{
- jtag->speed_div(jtag_speed, &speed1);
- jtag->speed_div(jtag_speed_post_reset, &speed2);
- jtag->speed(cur_speed);
+ retval=jtag->speed(cur_speed);
}
- }
- command_print(cmd_ctx, "jtag_speed: %d, %d", jtag_speed, jtag_speed_post_reset);
+ } else if (argc == 0)
+ {
+ } else
+ {
+ retval=ERROR_COMMAND_SYNTAX_ERROR;
+ }
+ command_print(cmd_ctx, "jtag_speed: %d", jtag_speed);
- return ERROR_OK;
+ return retval;
}
int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
+ int retval=ERROR_OK;
LOG_DEBUG("handle jtag khz");
- if (argc>2)
- return ERROR_COMMAND_SYNTAX_ERROR;
-
- if(argc != 0)
+ if(argc == 1)
{
-
- if (argc >= 1)
- speed1 = speed2 = strtoul(args[0], NULL, 0);
- if (argc == 2)
- speed2 = strtoul(args[1], NULL, 0);
-
+ speed_khz = strtoul(args[0], NULL, 0);
if (jtag != NULL)
{
int cur_speed = 0;
LOG_DEBUG("have interface set up");
- int speed_div1, speed_div2;
- if (jtag->khz(speed1, &speed_div1)!=ERROR_OK)
+ int speed_div1;
+ if ((retval=jtag->khz(speed_khz, &speed_div1))!=ERROR_OK)
{
- speed1 = speed2 = 0;
- return ERROR_OK;
- }
- if (jtag->khz(speed2, &speed_div2)!=ERROR_OK)
- {
- speed1 = speed2 = 0;
- return ERROR_OK;
+ speed_khz = 0;
+ return retval;
}
- if (argc >= 1)
- cur_speed = jtag_speed = jtag_speed_post_reset = speed_div1;
- if (argc == 2)
- cur_speed = jtag_speed_post_reset = speed_div2;
+ cur_speed = jtag_speed = speed_div1;
- jtag->speed(cur_speed);
+ retval=jtag->speed(cur_speed);
} else
{
hasKHz = 1;
}
+ } else if (argc==0)
+ {
+ } else
+ {
+ retval=ERROR_COMMAND_SYNTAX_ERROR;
}
- command_print(cmd_ctx, "jtag_khz: %d, %d", speed1, speed2);
-
- return ERROR_OK;
-}
+ command_print(cmd_ctx, "jtag_khz: %d", speed_khz);
+ return retval;
+}
int handle_endstate_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 i;
scan_field_t *fields;
int num_fields;
int field_count = 0;
- int i, j, e;
+ int i, e;
long device;
/* args[1] = device