#endif
#include "target.h"
+#include "target_type.h"
#include "target_request.h"
#include "time_support.h"
#include "register.h"
#include "image.h"
#include "jtag.h"
-#include <inttypes.h>
-
static int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int target_poll(struct target_s *target)
{
/* We can't poll until after examine */
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
/* Fail silently lest we pollute the log */
return ERROR_FAIL;
int target_halt(struct target_s *target)
{
/* We can't poll until after examine */
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
int retval;
/* We can't poll until after examine */
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
return ERROR_FAIL;
}
+ /* disable polling during reset to make reset event scripts
+ * more predictable, i.e. dr/irscan & pathmove in events will
+ * not have JTAG operations injected into the middle of a sequence.
+ */
+ int save_poll = target_continous_poll;
+ target_continous_poll = 0;
+
sprintf( buf, "ocd_process_reset %s", n->name );
retval = Jim_Eval( interp, buf );
+ target_continous_poll = save_poll;
+
if(retval != JIM_OK) {
Jim_PrintErrorMessage(interp);
return ERROR_FAIL;
static int default_examine(struct target_s *target)
{
- target->type->examined = 1;
+ target_set_examined(target);
return ERROR_OK;
}
+int target_examine_one(struct target_s *target)
+{
+ return target->type->examine(target);
+}
+
/* Targets that correctly implement init+examine, i.e.
* no communication with target during init:
*
int target_examine(void)
{
int retval = ERROR_OK;
- target_t *target = all_targets;
- while (target)
+ target_t *target;
+
+ for (target = all_targets; target; target = target->next)
{
- if ((retval = target->type->examine(target))!=ERROR_OK)
+ if (!target->tap->enabled)
+ continue;
+ if ((retval = target_examine_one(target)) != ERROR_OK)
return retval;
- target = target->next;
}
return retval;
}
+const char *target_get_name(struct target_s *target)
+{
+ return target->type->name;
+}
static int target_write_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer)
{
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
static int target_read_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer)
{
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
static int target_soft_reset_halt_imp(struct target_s *target)
{
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
static int target_run_algorithm_imp(struct target_s *target, int num_mem_params, mem_param_t *mem_params, int num_reg_params, reg_param_t *reg_param, u32 entry_point, u32 exit_point, int timeout_ms, void *arch_info)
{
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
return target->type->read_memory(target, address, size, count, buffer);
}
+int target_write_memory(struct target_s *target,
+ u32 address, u32 size, u32 count, u8 *buffer)
+{
+ return target->type->write_memory(target, address, size, count, buffer);
+}
+int target_bulk_write_memory(struct target_s *target,
+ u32 address, u32 count, u8 *buffer)
+{
+ return target->type->bulk_write_memory(target, address, count, buffer);
+}
+
+int target_add_breakpoint(struct target_s *target,
+ struct breakpoint_s *breakpoint)
+{
+ return target->type->add_breakpoint(target, breakpoint);
+}
+int target_remove_breakpoint(struct target_s *target,
+ struct breakpoint_s *breakpoint)
+{
+ return target->type->remove_breakpoint(target, breakpoint);
+}
+
+int target_add_watchpoint(struct target_s *target,
+ struct watchpoint_s *watchpoint)
+{
+ return target->type->add_watchpoint(target, watchpoint);
+}
+int target_remove_watchpoint(struct target_s *target,
+ struct watchpoint_s *watchpoint)
+{
+ return target->type->remove_watchpoint(target, watchpoint);
+}
+
+int target_get_gdb_reg_list(struct target_s *target,
+ struct reg_s **reg_list[], int *reg_list_size)
+{
+ return target->type->get_gdb_reg_list(target, reg_list, reg_list_size);
+}
+int target_step(struct target_s *target,
+ int current, u32 address, int handle_breakpoints)
+{
+ return target->type->step(target, current, address, handle_breakpoints);
+}
+
+
+int target_run_algorithm(struct target_s *target,
+ int num_mem_params, mem_param_t *mem_params,
+ int num_reg_params, reg_param_t *reg_param,
+ u32 entry_point, u32 exit_point,
+ int timeout_ms, void *arch_info)
+{
+ return target->type->run_algorithm(target,
+ num_mem_params, mem_params, num_reg_params, reg_param,
+ entry_point, exit_point, timeout_ms, arch_info);
+}
+
+/// @returns @c true if the target has been examined.
+bool target_was_examined(struct target_s *target)
+{
+ return target->type->examined;
+}
+/// Sets the @c examined flag for the given target.
+void target_set_examined(struct target_s *target)
+{
+ target->type->examined = true;
+}
+// Reset the @c examined flag for the given target.
+void target_reset_examined(struct target_s *target)
+{
+ target->type->examined = false;
+}
+
+
int target_init(struct command_context_s *cmd_ctx)
{
target_t *target = all_targets;
while (target)
{
- target->type->examined = 0;
+ target_reset_examined(target);
if (target->type->examine == NULL)
{
target->type->examine = default_examine;
if ((retval = target->type->init_target(cmd_ctx, target)) != ERROR_OK)
{
- LOG_ERROR("target '%s' init failed", target->type->name);
+ LOG_ERROR("target '%s' init failed", target_get_name(target));
return retval;
}
if (restore&&target->backup_working_area)
{
int retval;
- if((retval = target->type->write_memory(target, area->address, 4, area->size / 4, area->backup)) != ERROR_OK)
+ if((retval = target_write_memory(target, area->address, 4, area->size / 4, area->backup)) != ERROR_OK)
return retval;
}
int retval;
LOG_DEBUG("writing buffer of %i byte at 0x%8.8x", size, address);
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
if (((address % 2) == 0) && (size == 2))
{
- return target->type->write_memory(target, address, 2, 1, buffer);
+ return target_write_memory(target, address, 2, 1, buffer);
}
/* handle unaligned head bytes */
if (unaligned > size)
unaligned = size;
- if ((retval = target->type->write_memory(target, address, 1, unaligned, buffer)) != ERROR_OK)
+ if ((retval = target_write_memory(target, address, 1, unaligned, buffer)) != ERROR_OK)
return retval;
buffer += unaligned;
}
else
{
- if ((retval = target->type->write_memory(target, address, 4, aligned / 4, buffer)) != ERROR_OK)
+ if ((retval = target_write_memory(target, address, 4, aligned / 4, buffer)) != ERROR_OK)
return retval;
}
/* handle tail writes of less than 4 bytes */
if (size > 0)
{
- if ((retval = target->type->write_memory(target, address, 1, size, buffer)) != ERROR_OK)
+ if ((retval = target_write_memory(target, address, 1, size, buffer)) != ERROR_OK)
return retval;
}
int retval;
LOG_DEBUG("reading buffer of %i byte at 0x%8.8x", size, address);
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
int retval;
u32 i;
u32 checksum = 0;
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
int target_blank_check_memory(struct target_s *target, u32 address, u32 size, u32* blank)
{
int retval;
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
int target_read_u32(struct target_s *target, u32 address, u32 *value)
{
u8 value_buf[4];
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
int target_read_u16(struct target_s *target, u32 address, u16 *value)
{
u8 value_buf[2];
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
int target_read_u8(struct target_s *target, u32 address, u8 *value)
{
int retval = target_read_memory(target, address, 1, 1, value);
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
{
int retval;
u8 value_buf[4];
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
LOG_DEBUG("address: 0x%8.8x, value: 0x%8.8x", address, value);
target_buffer_set_u32(target, value_buf, value);
- if ((retval = target->type->write_memory(target, address, 4, 1, value_buf)) != ERROR_OK)
+ if ((retval = target_write_memory(target, address, 4, 1, value_buf)) != ERROR_OK)
{
LOG_DEBUG("failed: %i", retval);
}
{
int retval;
u8 value_buf[2];
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
LOG_DEBUG("address: 0x%8.8x, value: 0x%8.8x", address, value);
target_buffer_set_u16(target, value_buf, value);
- if ((retval = target->type->write_memory(target, address, 2, 1, value_buf)) != ERROR_OK)
+ if ((retval = target_write_memory(target, address, 2, 1, value_buf)) != ERROR_OK)
{
LOG_DEBUG("failed: %i", retval);
}
int target_write_u8(struct target_s *target, u32 address, u8 value)
{
int retval;
- if (!target->type->examined)
+ if (!target_was_examined(target))
{
LOG_ERROR("Target not examined yet");
return ERROR_FAIL;
LOG_DEBUG("address: 0x%8.8x, value: 0x%2.2x", address, value);
- if ((retval = target->type->write_memory(target, address, 1, 1, &value)) != ERROR_OK)
+ if ((retval = target_write_memory(target, address, 1, 1, &value)) != ERROR_OK)
{
LOG_DEBUG("failed: %i", retval);
}
command_print(cmd_ctx,"Target: %s is unknown, try one of:\n", args[0] );
goto DumpTargets;
}
+ if (!target->tap->enabled) {
+ command_print(cmd_ctx,"Target: TAP %s is disabled, "
+ "can't be the current target\n",
+ target->tap->dotted_name);
+ return ERROR_FAIL;
+ }
cmd_ctx->current_target = target->target_number;
return ERROR_OK;
DumpTargets:
target = all_targets;
- command_print(cmd_ctx, " CmdName Type Endian AbsChainPos Name State ");
- command_print(cmd_ctx, "-- ---------- ---------- ---------- ----------- ------------- ----------");
+ command_print(cmd_ctx, " TargetName Type Endian TapName State ");
+ command_print(cmd_ctx, "-- ------------------ ---------- ------ ------------------ ------------");
while (target)
{
- /* XX: abcdefghij abcdefghij abcdefghij abcdefghij */
- command_print(cmd_ctx, "%2d: %-10s %-10s %-10s %10d %14s %s",
+ const char *state;
+ char marker = ' ';
+
+ if (target->tap->enabled)
+ state = Jim_Nvp_value2name_simple(nvp_target_state,
+ target->state)->name;
+ else
+ state = "tap-disabled";
+
+ if (cmd_ctx->current_target == target->target_number)
+ marker = '*';
+
+ /* keep columns lined up to match the headers above */
+ command_print(cmd_ctx, "%2d%c %-18s %-10s %-6s %-18s %s",
target->target_number,
+ marker,
target->cmd_name,
- target->type->name,
- Jim_Nvp_value2name_simple( nvp_target_endian, target->endianness )->name,
- target->tap->abs_chain_position,
+ target_get_name(target),
+ Jim_Nvp_value2name_simple(nvp_target_endian,
+ target->endianness)->name,
target->tap->dotted_name,
- Jim_Nvp_value2name_simple( nvp_target_state, target->state )->name );
+ state);
target = target->next;
}
if (argc == 0)
{
- if((retval = target_poll(target)) != ERROR_OK)
+ command_print(cmd_ctx, "background polling: %s",
+ target_continous_poll ? "on" : "off");
+ if ((retval = target_poll(target)) != ERROR_OK)
return retval;
- if((retval = target_arch_state(target)) != ERROR_OK)
+ if ((retval = target_arch_state(target)) != ERROR_OK)
return retval;
}
const char *value_fmt;
switch (size) {
- case 4: value_fmt = "%8.8x"; break;
- case 2: value_fmt = "%4.2x"; break;
- case 1: value_fmt = "%2.2x"; break;
+ case 4: value_fmt = "%8.8x "; break;
+ case 2: value_fmt = "%4.2x "; break;
+ case 1: value_fmt = "%2.2x "; break;
default:
LOG_ERROR("invalid memory read size: %u", size);
exit(-1);
"0x%8.8x: ", address + (i*size));
}
- u32 value;
+ u32 value=0;
const u8 *value_ptr = buffer + i * size;
switch (size) {
case 4: value = target_buffer_get_u32(target, value_ptr); break;
}
for (i=0; i<count; i++)
{
- int retval = target->type->write_memory(target,
+ int retval = target_write_memory(target,
address + i * wordsize, wordsize, 1, value_buf);
if (ERROR_OK != retval)
return retval;
}
len -= count;
- retval = target->type->write_memory(target, addr, width, count, buffer);
+ retval = target_write_memory(target, addr, width, count, buffer);
if (retval != ERROR_OK) {
/* BOO !*/
LOG_ERROR("array2mem: Write @ 0x%08x, w=%d, cnt=%d, failed", addr, width, count);
LOG_DEBUG( "target: (%d) %s (%s) event: %d (%s) action: %s\n",
target->target_number,
target->cmd_name,
- target->type->name,
+ target_get_name(target),
e,
Jim_Nvp_value2name_simple( nvp_target_event, e )->name,
Jim_GetString( teap->body, NULL ) );
return JIM_ERR;
}
}
- Jim_SetResultString( goi->interp, target->type->name, -1 );
+ Jim_SetResultString( goi->interp, target_get_name(target), -1 );
/* loop for more */
break;
case TCFG_EVENT:
goto no_params;
}
}
- Jim_SetResult( interp, Jim_NewIntObj( goi->interp, target->working_area_size ) );
+ Jim_SetResult(interp, Jim_NewIntObj(goi->interp, target->backup_working_area));
/* loop for more e*/
break;
if( e != JIM_OK ){
return e;
}
- tap = jtag_TapByJimObj( goi->interp, o );
+ tap = jtag_tap_by_jim_obj( goi->interp, o );
if( tap == NULL ){
return JIM_ERR;
}
break;
}
for( x = 0 ; x < c ; x++ ){
- e = target->type->write_memory( target, a, b, 1, target_buf );
+ e = target_write_memory( target, a, b, 1, target_buf );
if( e != ERROR_OK ){
Jim_SetResult_sprintf( interp, "Error writing @ 0x%08x: %d\n", (int)(a), e );
return JIM_ERR;
Jim_WrongNumArgs( goi.interp, 2, argv, "[no parameters]");
return JIM_ERR;
}
+ if (!target->tap->enabled)
+ goto err_tap_disabled;
e = target->type->examine( target );
if( e != ERROR_OK ){
Jim_SetResult_sprintf( interp, "examine-fails: %d", e );
Jim_WrongNumArgs( goi.interp, 2, argv, "[no parameters]");
return JIM_ERR;
}
- if( !(target->type->examined) ){
+ if (!target->tap->enabled)
+ goto err_tap_disabled;
+ if( !(target_was_examined(target)) ){
e = ERROR_TARGET_NOT_EXAMINED;
} else {
e = target->type->poll( target );
if( e != JIM_OK ){
return e;
}
+ if (!target->tap->enabled)
+ goto err_tap_disabled;
/* determine if we should halt or not. */
target->reset_halt = !!a;
/* When this happens - all workareas are invalid. */
Jim_WrongNumArgs( goi.interp, 0, argv, "halt [no parameters]");
return JIM_ERR;
}
+ if (!target->tap->enabled)
+ goto err_tap_disabled;
target->type->halt( target );
return JIM_OK;
case TS_CMD_WAITSTATE:
if( e != JIM_OK ){
return e;
}
+ if (!target->tap->enabled)
+ goto err_tap_disabled;
e = target_wait_state( target, n->value, a );
if( e != ERROR_OK ){
Jim_SetResult_sprintf( goi.interp,
return JIM_OK;
}
return JIM_ERR;
+
+err_tap_disabled:
+ Jim_SetResult_sprintf(interp, "[TAP is disabled]");
+ return JIM_ERR;
}
static int target_create( Jim_GetOptInfo *goi )