int cli_target_callback_event_handler(struct target_s *target, enum target_event event, void *priv);
-
int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_reg_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_rwp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_virt2phys_command(command_context_t *cmd_ctx, char *cmd, char **args, int argc);
int handle_profile_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
+int handle_fast_load_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
+int handle_fast_load_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
+
static int jim_array2mem(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
static int jim_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
static int jim_target( Jim_Interp *interp, int argc, Jim_Obj *const *argv);
static int target_array2mem(Jim_Interp *interp, target_t *target, int argc, Jim_Obj *const *argv);
static int target_mem2array(Jim_Interp *interp, target_t *target, int argc, Jim_Obj *const *argv);
-
-
/* targets */
extern target_type_t arm7tdmi_target;
extern target_type_t arm720t_target;
{ .value = TARGET_EVENT_OLD_gdb_program_config , .name = "old-gdb_program_config" },
{ .value = TARGET_EVENT_OLD_pre_resume , .name = "old-pre_resume" },
-
{ .value = TARGET_EVENT_EARLY_HALTED, .name = "early-halted" },
{ .value = TARGET_EVENT_HALTED, .name = "halted" },
{ .value = TARGET_EVENT_RESUMED, .name = "resumed" },
{ .value = TARGET_EVENT_RESUME_START, .name = "resume-start" },
{ .value = TARGET_EVENT_RESUME_END, .name = "resume-end" },
-
{ .name = "gdb-start", .value = TARGET_EVENT_GDB_START },
{ .name = "gdb-end", .value = TARGET_EVENT_GDB_END },
-
/* historical name */
{ .value = TARGET_EVENT_RESET_START, .name = "reset-start" },
{ .value = TARGET_EVENT_RESET_INIT , .name = "reset-init" },
{ .value = TARGET_EVENT_RESET_END, .name = "reset-end" },
-
-
-
-
{ .value = TARGET_EVENT_EXAMINE_START, .name = "examine-start" },
{ .value = TARGET_EVENT_EXAMINE_END, .name = "examine-end" },
-
{ .value = TARGET_EVENT_DEBUG_HALTED, .name = "debug-halted" },
{ .value = TARGET_EVENT_DEBUG_RESUMED, .name = "debug-resumed" },
{ .value = TARGET_EVENT_GDB_ATTACH, .name = "gdb-attach" },
{ .value = TARGET_EVENT_GDB_DETACH, .name = "gdb-detach" },
-
{ .value = TARGET_EVENT_GDB_FLASH_WRITE_START, .name = "gdb-flash-write-start" },
{ .value = TARGET_EVENT_GDB_FLASH_WRITE_END , .name = "gdb-flash-write-end" },
{ .name = NULL, .value = -1 },
};
-
const Jim_Nvp nvp_target_debug_reason [] = {
{ .name = "debug-request" , .value = DBG_REASON_DBGRQ },
{ .name = "breakpoint" , .value = DBG_REASON_BREAKPOINT },
{ .name = NULL, .value = -1 },
};
-
const Jim_Nvp nvp_target_endian[] = {
{ .name = "big", .value = TARGET_BIG_ENDIAN },
{ .name = "little", .value = TARGET_LITTLE_ENDIAN },
{ .name = "be", .value = TARGET_BIG_ENDIAN },
- { .name = "le", .value = TARGET_LITTLE_ENDIAN },
+ { .name = "le", .value = TARGET_LITTLE_ENDIAN },
{ .name = NULL, .value = -1 },
};
{ .name = NULL , .value = -1 },
};
-static int
-max_target_number( void )
+static int max_target_number(void)
{
target_t *t;
int x;
}
/* determine the number of the new target */
-static int
-new_target_number( void )
+static int new_target_number(void)
{
target_t *t;
int x;
return target;
}
-
int target_poll(struct target_s *target)
{
/* We can't poll until after examine */
return retval;
}
-
int target_process_reset(struct command_context_s *cmd_ctx, enum target_reset_mode reset_mode)
{
char buf[100];
return retval;
}
-
static int default_virt2phys(struct target_s *target, u32 virtual, u32 *physical)
{
*physical = virtual;
return ERROR_OK;
}
-
/* Targets that correctly implement init+examine, i.e.
* no communication with target during init:
*
target->type->run_algorithm_imp = target->type->run_algorithm;
target->type->run_algorithm = target_run_algorithm_imp;
-
if (target->type->mmu == NULL)
{
target->type->mmu = default_mmu;
target_call_event_callbacks(target, TARGET_EVENT_EARLY_HALTED);
}
-
LOG_DEBUG("target event %i (%s)",
event,
Jim_Nvp_value2name_simple( nvp_target_event, event )->name );
register_command(cmd_ctx, NULL, "virt2phys", handle_virt2phys_command, COMMAND_ANY, "translate a virtual address into a physical address");
register_command(cmd_ctx, NULL, "profile", handle_profile_command, COMMAND_EXEC, "profiling samples the CPU PC");
+ register_command(cmd_ctx, NULL, "fast_load_image", handle_fast_load_image_command, COMMAND_ANY,
+ "same args as load_image, image stored in memory - mainly for profiling purposes");
+
+ register_command(cmd_ctx, NULL, "fast_load", handle_fast_load_command, COMMAND_ANY,
+ "loads active fast load image to current target - mainly for profiling purposes");
+
+
+
register_jim(cmd_ctx, "target", jim_target, "configure target" );
return ERROR_OK;
}
-
/* Single aligned words are guaranteed to use 16 or 32 bit access
* mode respectively, otherwise data is handled as quickly as
* possible
if((retval = trace_register_commands(cmd_ctx)) != ERROR_OK)
return retval;
-
return retval;
}
}
DumpTargets:
- target = all_targets;
+ target = all_targets;
command_print(cmd_ctx, " CmdName Type Endian AbsChainPos Name State ");
command_print(cmd_ctx, "-- ---------- ---------- ---------- ----------- ------------- ----------");
while (target)
return ERROR_OK;
}
-// every 300ms we check for reset & powerdropout and issue a "reset halt" if
-// so.
+/* every 300ms we check for reset & powerdropout and issue a "reset halt" if so. */
static int powerDropout;
static int srstAsserted;
return ERROR_OK;
}
-
/* process target state changes */
int handle_target(void *priv)
{
target = target->next;
}
-
return retval;
}
return ERROR_OK;
}
-
int handle_poll_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
int retval = ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
-
return retval;
}
{
once=0;
LOG_DEBUG("waiting for target %s...",
- Jim_Nvp_value2name_simple(nvp_target_state,state)->name);
+ Jim_Nvp_value2name_simple(nvp_target_state,state)->name);
}
gettimeofday(&now, NULL);
if ((now.tv_sec > timeout.tv_sec) || ((now.tv_sec == timeout.tv_sec) && (now.tv_usec >= timeout.tv_usec)))
{
LOG_ERROR("timed out while waiting for target %s",
- Jim_Nvp_value2name_simple(nvp_target_state,state)->name);
+ Jim_Nvp_value2name_simple(nvp_target_state,state)->name);
return ERROR_FAIL;
}
}
address = strtoul(args[0], NULL, 0);
-
switch (cmd[2])
{
case 'w':
return ERROR_COMMAND_SYNTAX_ERROR;
}
-
duration_start_measure(&duration);
if (image_open(&image, args[0], (argc >= 3) ? args[2] : NULL) != ERROR_OK)
u32 offset=0;
u32 length=buf_cnt;
-
/* DANGER!!! beware of unsigned comparision here!!! */
if ((image.sections[i].base_address+buf_cnt>=min_address)&&
}
return retval;
}
+
static void writeLong(FILE *f, int l)
{
int i;
}
}
+
static void writeString(FILE *f, char *s)
{
fwrite(s, 1, strlen(s), f);
}
-
-
-// Dump a gmon.out histogram file.
+/* Dump a gmon.out histogram file. */
static void writeGmon(u32 *samples, int sampleNum, char *filename)
{
int i;
if (f==NULL)
return;
fwrite("gmon", 1, 4, f);
- writeLong(f, 0x00000001); // Version
- writeLong(f, 0); // padding
- writeLong(f, 0); // padding
- writeLong(f, 0); // padding
+ writeLong(f, 0x00000001); /* Version */
+ writeLong(f, 0); /* padding */
+ writeLong(f, 0); /* padding */
+ writeLong(f, 0); /* padding */
- fwrite("", 1, 1, f); // GMON_TAG_TIME_HIST
+ fwrite("", 1, 1, f); /* GMON_TAG_TIME_HIST */
- // figure out bucket size
+ /* figure out bucket size */
u32 min=samples[0];
u32 max=samples[0];
for (i=0; i<sampleNum; i++)
int addressSpace=(max-min+1);
- static int const maxBuckets=256*1024; // maximum buckets.
+ static int const maxBuckets=256*1024; /* maximum buckets. */
int length=addressSpace;
if (length > maxBuckets)
{
long long a=address-min;
long long b=length-1;
long long c=addressSpace-1;
- int index=(a*b)/c; // danger!!!! int32 overflows
+ int index=(a*b)/c; /* danger!!!! int32 overflows */
buckets[index]++;
}
- // append binary memory gmon.out &profile_hist_hdr ((char*)&profile_hist_hdr + sizeof(struct gmon_hist_hdr))
- writeLong(f, min); // low_pc
- writeLong(f, max); // high_pc
- writeLong(f, length); // # of samples
- writeLong(f, 64000000); // 64MHz
+ /* append binary memory gmon.out &profile_hist_hdr ((char*)&profile_hist_hdr + sizeof(struct gmon_hist_hdr)) */
+ writeLong(f, min); /* low_pc */
+ writeLong(f, max); /* high_pc */
+ writeLong(f, length); /* # of samples */
+ writeLong(f, 64000000); /* 64MHz */
writeString(f, "seconds");
for (i=0; i<(15-strlen("seconds")); i++)
{
- fwrite("", 1, 1, f); // padding
+ fwrite("", 1, 1, f); /* padding */
}
writeString(f, "s");
-// append binary memory gmon.out profile_hist_data (profile_hist_data + profile_hist_hdr.hist_size)
+ /*append binary memory gmon.out profile_hist_data (profile_hist_data + profile_hist_hdr.hist_size) */
char *data=malloc(2*length);
if (data!=NULL)
int numSamples=0;
int retval=ERROR_OK;
- // hopefully it is safe to cache! We want to stop/restart as quickly as possible.
+ /* hopefully it is safe to cache! We want to stop/restart as quickly as possible. */
reg_t *reg = register_get_by_name(target->reg_cache, "pc", 1);
for (;;)
samples[numSamples++]=t;
retval = target_resume(target, 1, 0, 0, 0); /* current pc, addr = 0, do not handle breakpoints, not debugging */
target_poll(target);
- alive_sleep(10); // sleep 10ms, i.e. <100 samples/second.
+ alive_sleep(10); /* sleep 10ms, i.e. <100 samples/second. */
} else if (target->state == TARGET_RUNNING)
{
- // We want to quickly sample the PC.
+ /* We want to quickly sample the PC. */
if((retval = target_halt(target)) != ERROR_OK)
{
free(samples);
return target_array2mem( interp,target, argc, argv );
}
-
static int target_array2mem(Jim_Interp *interp, target_t *target, int argc, Jim_Obj *const *argv)
{
long l;
return JIM_ERR;
}
-
/* Transfer loop */
/* index counter */
return JIM_OK;
}
-void
-target_all_handle_event( enum target_event e )
+void target_all_handle_event( enum target_event e )
{
target_t *target;
-
LOG_DEBUG( "**all*targets: event: %d, %s",
- e,
- Jim_Nvp_value2name_simple( nvp_target_event, e )->name );
+ e,
+ Jim_Nvp_value2name_simple( nvp_target_event, e )->name );
target = all_targets;
while (target){
}
}
-void
-target_handle_event( target_t *target, enum target_event e )
+void target_handle_event( target_t *target, enum target_event e )
{
target_event_action_t *teap;
int done;
TCFG_CHAIN_POSITION,
};
-
static Jim_Nvp nvp_config_opts[] = {
{ .name = "-type", .value = TCFG_TYPE },
{ .name = "-event", .value = TCFG_EVENT },
{ .name = NULL, .value = -1 }
};
-
-static int
-target_configure( Jim_GetOptInfo *goi,
- target_t *target )
+static int target_configure( Jim_GetOptInfo *goi, target_t *target )
{
Jim_Nvp *n;
Jim_Obj *o;
char *cp;
int e;
-
/* parse config or cget options ... */
while( goi->argc > 0 ){
Jim_SetEmptyResult( goi->interp );
- //Jim_GetOpt_Debug( goi );
+ /* Jim_GetOpt_Debug( goi ); */
if( target->type->target_jim_configure ){
/* target defines a configure function */
}
}
-
{
target_event_action_t *teap;
break;
}
} /* while( goi->argc ) */
+
+
/* done - we return */
return JIM_OK;
}
-
/** this is the 'tcl' handler for the target specific command */
-static int
-tcl_target_func( Jim_Interp *interp,
- int argc,
- Jim_Obj *const *argv )
+static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
{
Jim_GetOptInfo goi;
jim_wide a,b,c;
struct command_context_s *cmd_ctx;
int e;
-
enum {
TS_CMD_CONFIGURE,
TS_CMD_CGET,
{ .name = NULL, .value = -1 },
};
-
/* go past the "command" */
Jim_GetOpt_Setup( &goi, interp, argc-1, argv+1 );
Jim_GetOpt_NvpUnknown( &goi, target_options, 0 );
return e;
}
- // Assume blank result
+ /* Assume blank result */
Jim_SetEmptyResult( goi.interp );
switch( n->value ){
Jim_GetOpt_NvpUnknown( &goi, nvp_assert, 1 );
return e;
}
- // the halt or not param
+ /* the halt or not param */
e = Jim_GetOpt_Wide( &goi, &a);
if( e != JIM_OK ){
return e;
}
- // determine if we should halt or not.
+ /* determine if we should halt or not. */
target->reset_halt = !!a;
- // When this happens - all workareas are invalid.
+ /* When this happens - all workareas are invalid. */
target_free_all_working_areas_restore(target, 0);
- // do the assert
+ /* do the assert */
if( n->value == NVP_ASSERT ){
target->type->assert_reset( target );
} else {
target->type->halt( target );
return JIM_OK;
case TS_CMD_WAITSTATE:
- // params: <name> statename timeoutmsecs
+ /* params: <name> statename timeoutmsecs */
if( goi.argc != 2 ){
Jim_SetResult_sprintf( goi.interp, "%s STATENAME TIMEOUTMSECS", n->name );
return JIM_ERR;
"target: %s wait %s fails (%d) %s",
target->cmd_name,
n->name,
- e, target_strerror_safe(e) );
+ e, target_strerror_safe(e) );
return JIM_ERR;
} else {
return JIM_OK;
return JIM_ERR;
}
-
-static int
-target_create( Jim_GetOptInfo *goi )
+static int target_create( Jim_GetOptInfo *goi )
{
-
Jim_Obj *new_cmd;
Jim_Cmd *cmd;
const char *cp;
return JIM_ERR;
}
-
/* Create it */
target = calloc(1,sizeof(target_t));
/* set target number */
/* Do the rest as "configure" options */
goi->isconfigure = 1;
e = target_configure( goi, target);
+
+ if (target->tap == NULL)
+ {
+ Jim_SetResultString( interp, "-chain-position required when creating target", -1);
+ e=JIM_ERR;
+ }
+
if( e != JIM_OK ){
free( target->type );
free( target );
target->endianness = TARGET_LITTLE_ENDIAN;
}
+ /* incase variant is not set */
+ if (!target->variant)
+ target->variant = strdup("");
+
/* create the target specific commands */
if( target->type->register_commands ){
(*(target->type->register_commands))( cmd_ctx );
return e;
}
-static int
-jim_target( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
+static int jim_target( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
{
int x,r,e;
jim_wide w;
const char *target_cmds[] = {
"create", "types", "names", "current", "number",
"count",
- NULL // terminate
+ NULL /* terminate */
};
LOG_DEBUG("Target command params:");
return JIM_ERR;
}
- //Jim_GetOpt_Debug( &goi );
+ /* Jim_GetOpt_Debug( &goi ); */
r = Jim_GetOpt_Enum( &goi, target_cmds, &x );
if( r != JIM_OK ){
return r;
return JIM_ERR;
}
+
+
+struct FastLoad
+{
+ u32 address;
+ u8 *data;
+ int length;
+
+};
+
+static int fastload_num;
+static struct FastLoad *fastload;
+
+static void free_fastload(void)
+{
+ if (fastload!=NULL)
+ {
+ int i;
+ for (i=0; i<fastload_num; i++)
+ {
+ if (fastload[i].data)
+ free(fastload[i].data);
+ }
+ free(fastload);
+ fastload=NULL;
+ }
+}
+
+
+
+
+int handle_fast_load_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+{
+ u8 *buffer;
+ u32 buf_cnt;
+ u32 image_size;
+ u32 min_address=0;
+ u32 max_address=0xffffffff;
+ int i;
+ int retval;
+
+ image_t image;
+
+ duration_t duration;
+ char *duration_text;
+
+ if ((argc < 1)||(argc > 5))
+ {
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ }
+
+ /* a base address isn't always necessary, default to 0x0 (i.e. don't relocate) */
+ if (argc >= 2)
+ {
+ image.base_address_set = 1;
+ image.base_address = strtoul(args[1], NULL, 0);
+ }
+ else
+ {
+ image.base_address_set = 0;
+ }
+
+
+ image.start_address_set = 0;
+
+ if (argc>=4)
+ {
+ min_address=strtoul(args[3], NULL, 0);
+ }
+ if (argc>=5)
+ {
+ max_address=strtoul(args[4], NULL, 0)+min_address;
+ }
+
+ if (min_address>max_address)
+ {
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ }
+
+ duration_start_measure(&duration);
+
+ if (image_open(&image, args[0], (argc >= 3) ? args[2] : NULL) != ERROR_OK)
+ {
+ return ERROR_OK;
+ }
+
+ image_size = 0x0;
+ retval = ERROR_OK;
+ fastload_num=image.num_sections;
+ fastload=(struct FastLoad *)malloc(sizeof(struct FastLoad)*image.num_sections);
+ if (fastload==NULL)
+ {
+ image_close(&image);
+ return ERROR_FAIL;
+ }
+ memset(fastload, 0, sizeof(struct FastLoad)*image.num_sections);
+ for (i = 0; i < image.num_sections; i++)
+ {
+ buffer = malloc(image.sections[i].size);
+ if (buffer == NULL)
+ {
+ command_print(cmd_ctx, "error allocating buffer for section (%d bytes)", image.sections[i].size);
+ break;
+ }
+
+ if ((retval = image_read_section(&image, i, 0x0, image.sections[i].size, buffer, &buf_cnt)) != ERROR_OK)
+ {
+ free(buffer);
+ break;
+ }
+
+ u32 offset=0;
+ u32 length=buf_cnt;
+
+
+ /* DANGER!!! beware of unsigned comparision here!!! */
+
+ if ((image.sections[i].base_address+buf_cnt>=min_address)&&
+ (image.sections[i].base_address<max_address))
+ {
+ if (image.sections[i].base_address<min_address)
+ {
+ /* clip addresses below */
+ offset+=min_address-image.sections[i].base_address;
+ length-=offset;
+ }
+
+ if (image.sections[i].base_address+buf_cnt>max_address)
+ {
+ length-=(image.sections[i].base_address+buf_cnt)-max_address;
+ }
+
+ fastload[i].address=image.sections[i].base_address+offset;
+ fastload[i].data=malloc(length);
+ if (fastload[i].data==NULL)
+ {
+ free(buffer);
+ break;
+ }
+ memcpy(fastload[i].data, buffer+offset, length);
+ fastload[i].length=length;
+
+ image_size += length;
+ command_print(cmd_ctx, "%u byte written at address 0x%8.8x", length, image.sections[i].base_address+offset);
+ }
+
+ free(buffer);
+ }
+
+ duration_stop_measure(&duration, &duration_text);
+ if (retval==ERROR_OK)
+ {
+ command_print(cmd_ctx, "Loaded %u bytes in %s", image_size, duration_text);
+ command_print(cmd_ctx, "NB!!! image has not been loaded to target, issue a subsequent 'fast_load' to do so.");
+ }
+ free(duration_text);
+
+ image_close(&image);
+
+ if (retval!=ERROR_OK)
+ {
+ free_fastload();
+ }
+
+ return retval;
+}
+
+int handle_fast_load_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+{
+ if (argc>0)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ if (fastload==NULL)
+ {
+ LOG_ERROR("No image in memory");
+ return ERROR_FAIL;
+ }
+ int i;
+ int ms=timeval_ms();
+ int size=0;
+ for (i=0; i<fastload_num;i++)
+ {
+ int retval;
+ target_t *target = get_current_target(cmd_ctx);
+ if ((retval = target_write_buffer(target, fastload[i].address, fastload[i].length, fastload[i].data)) != ERROR_OK)
+ {
+ return retval;
+ }
+ size+=fastload[i].length;
+ }
+ int after=timeval_ms();
+ command_print(cmd_ctx, "Loaded image %f kBytes/s", (float)(size/1024.0)/((float)(after-ms)/1000.0));
+ return ERROR_OK;
+}