* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
extern struct target_type xscale_target;
extern struct target_type cortexm3_target;
extern struct target_type cortexa8_target;
+extern struct target_type cortexr4_target;
extern struct target_type arm11_target;
extern struct target_type mips_m4k_target;
extern struct target_type avr_target;
extern struct target_type dsp5680xx_target;
extern struct target_type testee_target;
extern struct target_type avr32_ap7k_target;
-extern struct target_type stm32_stlink_target;
+extern struct target_type hla_target;
+extern struct target_type nds32_v2_target;
+extern struct target_type nds32_v3_target;
+extern struct target_type nds32_v3m_target;
static struct target_type *target_types[] = {
&arm7tdmi_target,
&xscale_target,
&cortexm3_target,
&cortexa8_target,
+ &cortexr4_target,
&arm11_target,
&mips_m4k_target,
&avr_target,
&dsp5680xx_target,
&testee_target,
&avr32_ap7k_target,
- &stm32_stlink_target,
+ &hla_target,
+ &nds32_v2_target,
+ &nds32_v3_target,
+ &nds32_v3m_target,
NULL,
};
/* try as tcltarget name */
for (target = all_targets; target; target = target->next) {
- if (target->cmd_name == NULL)
+ if (target_name(target) == NULL)
continue;
- if (strcmp(id, target->cmd_name) == 0)
+ if (strcmp(id, target_name(target)) == 0)
return target;
}
for (target = all_targets; target; target = target->next) {
if (target->target_number == (int)num) {
LOG_WARNING("use '%s' as target identifier, not '%u'",
- target->cmd_name, num);
+ target_name(target), num);
return target;
}
}
return target->type->name;
}
-static int target_write_memory_imp(struct target *target, uint32_t address,
- uint32_t size, uint32_t count, const uint8_t *buffer)
-{
- if (!target_was_examined(target)) {
- LOG_ERROR("Target not examined yet");
- return ERROR_FAIL;
- }
- return target->type->write_memory_imp(target, address, size, count, buffer);
-}
-
-static int target_read_memory_imp(struct target *target, uint32_t address,
- uint32_t size, uint32_t count, uint8_t *buffer)
-{
- if (!target_was_examined(target)) {
- LOG_ERROR("Target not examined yet");
- return ERROR_FAIL;
- }
- return target->type->read_memory_imp(target, address, size, count, buffer);
-}
-
-static int target_soft_reset_halt_imp(struct target *target)
+static int target_soft_reset_halt(struct target *target)
{
if (!target_was_examined(target)) {
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
}
- if (!target->type->soft_reset_halt_imp) {
+ if (!target->type->soft_reset_halt) {
LOG_ERROR("Target %s does not support soft_reset_halt",
target_name(target));
return ERROR_FAIL;
}
- return target->type->soft_reset_halt_imp(target);
+ return target->type->soft_reset_halt(target);
}
/**
uint32_t entry_point, uint32_t exit_point, void *arch_info)
{
int retval;
+ int timeout = 0;
/* Set up working area. First word is write pointer, second word is read pointer,
* rest is fifo data area. */
* less than buffer size / flash speed. This is very unlikely to
* run when using high latency connections such as USB. */
alive_sleep(10);
+
+ /* to stop an infinite loop on some targets check and increment a timeout
+ * this issue was observed on a stellaris using the new ICDI interface */
+ if (timeout++ >= 500) {
+ LOG_ERROR("timeout waiting for algorithm, a target reset is recommended");
+ return ERROR_FLASH_OPERATION_FAILED;
+ }
continue;
}
+ /* reset our timeout */
+ timeout = 0;
+
/* Limit to the amount of data we actually want to write */
if (thisrun_bytes > count * block_size)
thisrun_bytes = count * block_size;
int target_read_memory(struct target *target,
uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
{
+ if (!target_was_examined(target)) {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
return target->type->read_memory(target, address, size, count, buffer);
}
-static int target_read_phys_memory(struct target *target,
+int target_read_phys_memory(struct target *target,
uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
{
+ if (!target_was_examined(target)) {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
return target->type->read_phys_memory(target, address, size, count, buffer);
}
int target_write_memory(struct target *target,
uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
{
+ if (!target_was_examined(target)) {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
return target->type->write_memory(target, address, size, count, buffer);
}
-static int target_write_phys_memory(struct target *target,
+int target_write_phys_memory(struct target *target,
uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
{
+ if (!target_was_examined(target)) {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
return target->type->write_phys_memory(target, address, size, count, buffer);
}
-int target_bulk_write_memory(struct target *target,
+static int target_bulk_write_memory_default(struct target *target,
uint32_t address, uint32_t count, const uint8_t *buffer)
{
- return target->type->bulk_write_memory(target, address, count, buffer);
+ return target_write_memory(target, address, 4, count, buffer);
}
int target_add_breakpoint(struct target *target,
struct breakpoint *breakpoint)
{
if ((target->state != TARGET_HALTED) && (breakpoint->type != BKPT_HARD)) {
- LOG_WARNING("target %s is not halted", target->cmd_name);
+ LOG_WARNING("target %s is not halted", target_name(target));
return ERROR_TARGET_NOT_HALTED;
}
return target->type->add_breakpoint(target, breakpoint);
struct breakpoint *breakpoint)
{
if (target->state != TARGET_HALTED) {
- LOG_WARNING("target %s is not halted", target->cmd_name);
+ LOG_WARNING("target %s is not halted", target_name(target));
return ERROR_TARGET_NOT_HALTED;
}
return target->type->add_context_breakpoint(target, breakpoint);
struct breakpoint *breakpoint)
{
if (target->state != TARGET_HALTED) {
- LOG_WARNING("target %s is not halted", target->cmd_name);
+ LOG_WARNING("target %s is not halted", target_name(target));
return ERROR_TARGET_NOT_HALTED;
}
return target->type->add_hybrid_breakpoint(target, breakpoint);
struct watchpoint *watchpoint)
{
if (target->state != TARGET_HALTED) {
- LOG_WARNING("target %s is not halted", target->cmd_name);
+ LOG_WARNING("target %s is not halted", target_name(target));
return ERROR_TARGET_NOT_HALTED;
}
return target->type->add_watchpoint(target, watchpoint);
return retval;
}
- /**
- * @todo get rid of those *memory_imp() methods, now that all
- * callers are using target_*_memory() accessors ... and make
- * sure the "physical" paths handle the same issues.
- */
- /* a non-invasive way(in terms of patches) to add some code that
- * runs before the type->write/read_memory implementation
- */
- type->write_memory_imp = target->type->write_memory;
- type->write_memory = target_write_memory_imp;
-
- type->read_memory_imp = target->type->read_memory;
- type->read_memory = target_read_memory_imp;
-
- type->soft_reset_halt_imp = target->type->soft_reset_halt;
- type->soft_reset_halt = target_soft_reset_halt_imp;
-
/* Sanity-check MMU support ... stub in what we must, to help
* implement it in stages, but warn if we need to do so.
*/
if (target->type->write_buffer == NULL)
target->type->write_buffer = target_write_buffer_default;
+ if (target->type->bulk_write_memory == NULL)
+ target->type->bulk_write_memory = target_bulk_write_memory_default;
+
return ERROR_OK;
}
return ERROR_OK;
}
-static int backoff_times;
-static int backoff_count;
-
/* process target state changes */
static int handle_target(void *priv)
{
recursive = 0;
}
- if (backoff_times > backoff_count) {
- /* do not poll this time as we failed previously */
- backoff_count++;
- return ERROR_OK;
- }
- backoff_count = 0;
-
/* Poll targets for state changes unless that's globally disabled.
* Skip targets that are currently disabled.
*/
if (!target->tap->enabled)
continue;
+ if (target->backoff.times > target->backoff.count) {
+ /* do not poll this time as we failed previously */
+ target->backoff.count++;
+ continue;
+ }
+ target->backoff.count = 0;
+
/* only poll target if we've got power and srst isn't asserted */
if (!powerDropout && !srstAsserted) {
/* polling may fail silently until the target has been examined */
retval = target_poll(target);
if (retval != ERROR_OK) {
/* 100ms polling interval. Increase interval between polling up to 5000ms */
- if (backoff_times * polling_interval < 5000) {
- backoff_times *= 2;
- backoff_times++;
+ if (target->backoff.times * polling_interval < 5000) {
+ target->backoff.times *= 2;
+ target->backoff.times++;
}
- LOG_USER("Polling target failed, GDB will be halted. Polling again in %dms",
- backoff_times * polling_interval);
+ LOG_USER("Polling target %s failed, GDB will be halted. Polling again in %dms",
+ target_name(target),
+ target->backoff.times * polling_interval);
/* Tell GDB to halt the debugger. This allows the user to
* run monitor commands to handle the situation.
return retval;
}
/* Since we succeeded, we reset backoff count */
- if (backoff_times > 0)
- LOG_USER("Polling succeeded again");
- backoff_times = 0;
+ if (target->backoff.times > 0)
+ LOG_USER("Polling target %s succeeded again", target_name(target));
+ target->backoff.times = 0;
}
}
LOG_USER("requesting target halt and executing a soft reset");
- target->type->soft_reset_halt(target);
+ target_soft_reset_halt(target);
return ERROR_OK;
}
return (target_fill_mem(target, a, fn, data_size, b, c) == ERROR_OK) ? JIM_OK : JIM_ERR;
}
+/**
+* @brief Reads an array of words/halfwords/bytes from target memory starting at specified address.
+*
+* Usage: mdw [phys] <address> [<count>] - for 32 bit reads
+* mdh [phys] <address> [<count>] - for 16 bit reads
+* mdb [phys] <address> [<count>] - for 8 bit reads
+*
+* Count defaults to 1.
+*
+* Calls target_read_memory or target_read_phys_memory depending on
+* the presence of the "phys" argument
+* Reads the target memory in blocks of max. 32 bytes, and returns an array of ints formatted
+* to int representation in base16.
+* Also outputs read data in a human readable form using command_print
+*
+* @param phys if present target_read_phys_memory will be used instead of target_read_memory
+* @param address address where to start the read. May be specified in decimal or hex using the standard "0x" prefix
+* @param count optional count parameter to read an array of values. If not specified, defaults to 1.
+* @returns: JIM_ERR on error or JIM_OK on success and sets the result string to an array of ascii formatted numbers
+* on success, with [<count>] number of elements.
+*
+* In case of little endian target:
+* Example1: "mdw 0x00000000" returns "10123456"
+* Exmaple2: "mdh 0x00000000 1" returns "3456"
+* Example3: "mdb 0x00000000" returns "56"
+* Example4: "mdh 0x00000000 2" returns "3456 1012"
+* Example5: "mdb 0x00000000 3" returns "56 34 12"
+**/
static int jim_target_md(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
const char *cmd_name = Jim_GetString(argv[0], NULL);
fn = target_read_phys_memory;
}
- jim_wide a;
- e = Jim_GetOpt_Wide(&goi, &a);
+ /* Read address parameter */
+ jim_wide addr;
+ e = Jim_GetOpt_Wide(&goi, &addr);
if (e != JIM_OK)
return JIM_ERR;
- jim_wide c;
+
+ /* If next parameter exists, read it out as the count parameter, if not, set it to 1 (default) */
+ jim_wide count;
if (goi.argc == 1) {
- e = Jim_GetOpt_Wide(&goi, &c);
+ e = Jim_GetOpt_Wide(&goi, &count);
if (e != JIM_OK)
return JIM_ERR;
} else
- c = 1;
+ count = 1;
/* all args must be consumed */
if (goi.argc != 0)
return JIM_ERR;
- jim_wide b = 1; /* shut up gcc */
+ jim_wide dwidth = 1; /* shut up gcc */
if (strcasecmp(cmd_name, "mdw") == 0)
- b = 4;
+ dwidth = 4;
else if (strcasecmp(cmd_name, "mdh") == 0)
- b = 2;
+ dwidth = 2;
else if (strcasecmp(cmd_name, "mdb") == 0)
- b = 1;
+ dwidth = 1;
else {
LOG_ERROR("command '%s' unknown: ", cmd_name);
return JIM_ERR;
}
/* convert count to "bytes" */
- c = c * b;
+ int bytes = count * dwidth;
struct target *target = Jim_CmdPrivData(goi.interp);
uint8_t target_buf[32];
jim_wide x, y, z;
- while (c > 0) {
- y = c;
- if (y > 16)
- y = 16;
- e = fn(target, a, b, y / b, target_buf);
+ while (bytes > 0) {
+ y = (bytes < 16) ? bytes : 16; /* y = min(bytes, 16); */
+
+ /* Try to read out next block */
+ e = fn(target, addr, dwidth, y / dwidth, target_buf);
+
if (e != ERROR_OK) {
- char tmp[10];
- snprintf(tmp, sizeof(tmp), "%08lx", (long)a);
- Jim_SetResultFormatted(interp, "error reading target @ 0x%s", tmp);
+ Jim_SetResultFormatted(interp, "error reading target @ 0x%08lx", (long)addr);
return JIM_ERR;
}
- command_print(NULL, "0x%08x ", (int)(a));
- switch (b) {
+ command_print_sameline(NULL, "0x%08x ", (int)(addr));
+ switch (dwidth) {
case 4:
for (x = 0; x < 16 && x < y; x += 4) {
z = target_buffer_get_u32(target, &(target_buf[x]));
- command_print(NULL, "%08x ", (int)(z));
+ command_print_sameline(NULL, "%08x ", (int)(z));
}
for (; (x < 16) ; x += 4)
- command_print(NULL, " ");
+ command_print_sameline(NULL, " ");
break;
case 2:
for (x = 0; x < 16 && x < y; x += 2) {
z = target_buffer_get_u16(target, &(target_buf[x]));
- command_print(NULL, "%04x ", (int)(z));
+ command_print_sameline(NULL, "%04x ", (int)(z));
}
for (; (x < 16) ; x += 2)
- command_print(NULL, " ");
+ command_print_sameline(NULL, " ");
break;
case 1:
default:
for (x = 0 ; (x < 16) && (x < y) ; x += 1) {
z = target_buffer_get_u8(target, &(target_buf[x]));
- command_print(NULL, "%02x ", (int)(z));
+ command_print_sameline(NULL, "%02x ", (int)(z));
}
for (; (x < 16) ; x += 1)
- command_print(NULL, " ");
+ command_print_sameline(NULL, " ");
break;
}
/* ascii-ify the bytes */
/* terminate */
target_buf[16] = 0;
/* print - with a newline */
- command_print(NULL, "%s\n", target_buf);
+ command_print_sameline(NULL, "%s\n", target_buf);
/* NEXT... */
- c -= 16;
- a += 16;
+ bytes -= 16;
+ addr += 16;
}
return JIM_OK;
}
/* found */
break;
}
+
+ /* check for deprecated name */
+ if (target_types[x]->deprecated_name) {
+ if (0 == strcmp(cp, target_types[x]->deprecated_name)) {
+ /* found */
+ LOG_WARNING("target name is deprecated use: \'%s\'", target_types[x]->name);
+ break;
+ }
+ }
}
if (target_types[x] == NULL) {
Jim_SetResultFormatted(goi->interp, "Unknown target type %s, try one of ", cp);
}
/* now - create the new target name command */
- const const struct command_registration target_subcommands[] = {
+ const struct command_registration target_subcommands[] = {
{
.chain = target_instance_command_handlers,
},
},
COMMAND_REGISTRATION_DONE
};
- const const struct command_registration target_commands[] = {
+ const struct command_registration target_commands[] = {
{
.name = cp,
.mode = COMMAND_ANY,
struct command_context *cmd_ctx = current_command_context(interp);
assert(cmd_ctx != NULL);
- Jim_SetResultString(interp, get_current_target(cmd_ctx)->cmd_name, -1);
+ Jim_SetResultString(interp, target_name(get_current_target(cmd_ctx)), -1);
return JIM_OK;
}
target->head = head;
curr = curr->next;
}
- if (target->rtos)
+
+ if (target && target->rtos)
retval = rtos_smp_init(head->target);
+
return retval;
}