t = all_targets;
while ( t ){
if ( x < t->target_number ){
- x = (t->target_number)+1;
+ x = (t->target_number) + 1;
}
t = t->next;
}
}
t = t->next;
}
- return x+1;
+ return x + 1;
}
static int target_continuous_poll = 1;
}
-/* Targets that correctly implement init+examine, i.e.
+/* Targets that correctly implement init + examine, i.e.
* no communication with target during init:
*
* XScale
if (target->state != TARGET_HALTED)
return ERROR_OK;
- retval=target->type->arch_state(target);
+ retval = target->type->arch_state(target);
return retval;
}
if ((address + size - 1) < address)
{
/* GDB can request this when e.g. PC is 0xfffffffc*/
- LOG_ERROR("address+size wrapped(0x%08x, 0x%08x)",
+ LOG_ERROR("address + size wrapped(0x%08x, 0x%08x)",
(unsigned)address,
(unsigned)size);
return ERROR_FAIL;
if ((address + size - 1) < address)
{
/* GDB can request this when e.g. PC is 0xfffffffc*/
- LOG_ERROR("address+size wrapped(0x%08" PRIx32 ", 0x%08" PRIx32 ")",
+ LOG_ERROR("address + size wrapped(0x%08" PRIx32 ", 0x%08" PRIx32 ")",
address,
size);
return ERROR_FAIL;
/* script procedures */
register_command(cmd_ctx, NULL, "profile", handle_profile_command, COMMAND_EXEC, "profiling samples the CPU PC");
- register_jim(cmd_ctx, "ocd_mem2array", jim_mem2array, "read memory and return as a TCL array for script processing <ARRAYNAME> <WIDTH=32/16/8> <ADDRESS> <COUNT>");
- register_jim(cmd_ctx, "ocd_array2mem", jim_array2mem, "convert a TCL array to memory locations and write the values <ARRAYNAME> <WIDTH=32/16/8> <ADDRESS> <COUNT>");
+ register_jim(cmd_ctx, "ocd_mem2array", jim_mem2array, "read memory and return as a TCL array for script processing <ARRAYNAME> <WIDTH = 32/16/8> <ADDRESS> <COUNT>");
+ register_jim(cmd_ctx, "ocd_array2mem", jim_array2mem, "convert a TCL array to memory locations and write the values <ARRAYNAME> <WIDTH = 32/16/8> <ADDRESS> <COUNT>");
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, "halt", handle_halt_command, COMMAND_EXEC, "halt target");
register_command(cmd_ctx, NULL, "resume", handle_resume_command, COMMAND_EXEC, "resume target [addr]");
register_command(cmd_ctx, NULL, "step", handle_step_command, COMMAND_EXEC, "step one instruction from current PC or [addr]");
- register_command(cmd_ctx, NULL, "reset", handle_reset_command, COMMAND_EXEC, "reset target [run|halt|init] - default is run");
+ register_command(cmd_ctx, NULL, "reset", handle_reset_command, COMMAND_EXEC, "reset target [run | halt | init] - default is run");
register_command(cmd_ctx, NULL, "soft_reset_halt", handle_soft_reset_halt_command, COMMAND_EXEC, "halt the target and do a soft reset");
register_command(cmd_ctx, NULL, "mdw", handle_md_command, COMMAND_EXEC, "display memory words <addr> [count]");
static int prevPowerdropout = 0;
int retval;
- if ((retval=jtag_power_dropout(&powerDropout)) != ERROR_OK)
+ if ((retval = jtag_power_dropout(&powerDropout)) != ERROR_OK)
return retval;
int powerRestored;
lastPower = current;
}
- if ((retval=jtag_srst_asserted(&srstAsserted)) != ERROR_OK)
+ if ((retval = jtag_srst_asserted(&srstAsserted)) != ERROR_OK)
return retval;
int srstDeasserted;
/* clear action flags */
- runSrstAsserted=0;
- runSrstDeasserted=0;
- runPowerRestore=0;
- runPowerDropout=0;
+ runSrstAsserted = 0;
+ runSrstDeasserted = 0;
+ runPowerRestore = 0;
+ runPowerDropout = 0;
recursive = 0;
}
int target_wait_state(target_t *target, enum target_state state, int ms)
{
int retval;
- long long then=0, cur;
- int once=1;
+ long long then = 0, cur;
+ int once = 1;
for (;;)
{
- if ((retval=target_poll(target)) != ERROR_OK)
+ if ((retval = target_poll(target)) != ERROR_OK)
return retval;
if (target->state == state)
{
cur = timeval_ms();
if (once)
{
- once=0;
+ once = 0;
then = timeval_ms();
LOG_DEBUG("waiting for target %s...",
Jim_Nvp_value2name_simple(nvp_target_state,state)->name);
}
- if (cur-then>500)
+ if (cur-then > 500)
{
keep_alive();
}
- if ((cur-then)>ms)
+ if ((cur-then) > ms)
{
LOG_ERROR("timed out while waiting for target %s",
Jim_Nvp_value2name_simple(nvp_target_state,state)->name);
(unsigned)(address + (i*size)));
}
- uint32_t value=0;
+ uint32_t value = 0;
const uint8_t *value_ptr = buffer + i * size;
switch (size) {
case 4: value = target_buffer_get_u32(target, value_ptr); break;
break;
}
- uint32_t offset=0;
- uint32_t length=buf_cnt;
+ uint32_t offset = 0;
+ uint32_t 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 + buf_cnt >= min_address)&&
+ (image.sections[i].base_address < max_address))
{
- if (image.sections[i].base_address<min_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)
+ if (image.sections[i].base_address + buf_cnt > max_address)
{
- length -= (image.sections[i].base_address+buf_cnt)-max_address;
+ length -= (image.sections[i].base_address + buf_cnt)-max_address;
}
- if ((retval = target_write_buffer(target, image.sections[i].base_address+offset, length, buffer+offset)) != ERROR_OK)
+ if ((retval = target_write_buffer(target, image.sections[i].base_address + offset, length, buffer + offset)) != ERROR_OK)
{
free(buffer);
break;
image_size += length;
command_print(cmd_ctx, "%u byte written at address 0x%8.8" PRIx32 "",
(unsigned int)length,
- image.sections[i].base_address+offset);
+ image.sections[i].base_address + offset);
}
free(buffer);
image.start_address_set = 0;
- if ((retval=image_open(&image, args[0], (argc == 3) ? args[2] : NULL)) != ERROR_OK)
+ if ((retval = image_open(&image, args[0], (argc == 3) ? args[2] : NULL)) != ERROR_OK)
{
return retval;
}
image_size = 0x0;
- retval=ERROR_OK;
+ retval = ERROR_OK;
for (i = 0; i < image.num_sections; i++)
{
buffer = malloc(image.sections[i].size);
buffer[t]);
free(data);
free(buffer);
- retval=ERROR_FAIL;
+ retval = ERROR_FAIL;
goto done;
}
if ((t%16384) == 0)
static void writeLong(FILE *f, int l)
{
int i;
- for (i=0; i<4; i++)
+ for (i = 0; i < 4; i++)
{
- char c=(l >> (i*8))&0xff;
+ char c = (l >> (i*8))&0xff;
writeData(f, &c, 1);
}
static void writeGmon(uint32_t *samples, uint32_t sampleNum, char *filename)
{
uint32_t i;
- FILE *f=fopen(filename, "w");
+ FILE *f = fopen(filename, "w");
if (f == NULL)
return;
writeString(f, "gmon");
writeData(f, &zero, 1);
/* figure out bucket size */
- uint32_t min=samples[0];
- uint32_t max=samples[0];
- for (i=0; i<sampleNum; i++)
+ uint32_t min = samples[0];
+ uint32_t max = samples[0];
+ for (i = 0; i < sampleNum; i++)
{
- if (min>samples[i])
+ if (min > samples[i])
{
- min=samples[i];
+ min = samples[i];
}
- if (max<samples[i])
+ if (max < samples[i])
{
- max=samples[i];
+ max = samples[i];
}
}
- int addressSpace=(max-min+1);
+ int addressSpace = (max-min + 1);
static const uint32_t maxBuckets = 256 * 1024; /* maximum buckets. */
uint32_t length = addressSpace;
if (length > maxBuckets)
{
- length=maxBuckets;
+ length = maxBuckets;
}
- int *buckets=malloc(sizeof(int)*length);
+ int *buckets = malloc(sizeof(int)*length);
if (buckets == NULL)
{
fclose(f);
return;
}
memset(buckets, 0, sizeof(int)*length);
- for (i=0; i<sampleNum;i++)
+ for (i = 0; i < sampleNum;i++)
{
- uint32_t address=samples[i];
- long long a=address-min;
- long long b=length-1;
- long long c=addressSpace-1;
- int index=(a*b)/c; /* danger!!!! int32 overflows */
+ uint32_t address = samples[i];
+ long long a = address-min;
+ long long b = length-1;
+ long long c = addressSpace-1;
+ int index = (a*b)/c; /* danger!!!! int32 overflows */
buckets[index]++;
}
writeLong(f, length); /* # of samples */
writeLong(f, 64000000); /* 64MHz */
writeString(f, "seconds");
- for (i=0; i<(15-strlen("seconds")); i++)
+ for (i = 0; i < (15-strlen("seconds")); i++)
writeData(f, &zero, 1);
writeString(f, "s");
/*append binary memory gmon.out profile_hist_data (profile_hist_data + profile_hist_hdr.hist_size) */
- char *data=malloc(2*length);
+ char *data = malloc(2*length);
if (data != NULL)
{
- for (i=0; i<length;i++)
+ for (i = 0; i < length;i++)
{
int val;
- val=buckets[i];
- if (val>65535)
+ val = buckets[i];
+ if (val > 65535)
{
- val=65535;
+ val = 65535;
}
data[i*2]=val&0xff;
- data[i*2+1]=(val >> 8)&0xff;
+ data[i*2 + 1]=(val >> 8)&0xff;
}
free(buckets);
writeData(f, data, length * 2);
command_print(cmd_ctx, "Starting profiling. Halting and resuming the target as often as we can...");
- static const int maxSample=10000;
- uint32_t *samples=malloc(sizeof(uint32_t)*maxSample);
+ static const int maxSample = 10000;
+ uint32_t *samples = malloc(sizeof(uint32_t)*maxSample);
if (samples == NULL)
return ERROR_OK;
- int numSamples=0;
+ int numSamples = 0;
/* 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);
} else
{
command_print(cmd_ctx, "Target not halted or running");
- retval=ERROR_OK;
+ retval = ERROR_OK;
break;
}
if (retval != ERROR_OK)
return JIM_ERR;
}
- return target_mem2array(interp, target, argc-1, argv+1);
+ return target_mem2array(interp, target, argc-1, argv + 1);
}
static int target_mem2array(Jim_Interp *interp, target_t *target, int argc, Jim_Obj *const *argv)
return JIM_ERR;
}
- return target_array2mem( interp,target, argc-1, argv+1 );
+ return target_array2mem( interp,target, argc-1, argv + 1 );
}
static int target_array2mem(Jim_Interp *interp, target_t *target, int argc, Jim_Obj *const *argv)
};
/* go past the "command" */
- Jim_GetOpt_Setup( &goi, interp, argc-1, argv+1 );
+ Jim_GetOpt_Setup( &goi, interp, argc-1, argv + 1 );
target = Jim_CmdPrivData( goi.interp );
cmd_ctx = Jim_GetAssocData(goi.interp, "context");
break;
case TS_CMD_RESET:
if ( goi.argc != 2 ){
- Jim_WrongNumArgs( interp, 2, argv, "t|f|assert|deassert BOOL");
+ Jim_WrongNumArgs( interp, 2, argv, "t | f|assert | deassert BOOL");
return JIM_ERR;
}
e = Jim_GetOpt_Nvp( &goi, nvp_assert, &n );
if ( target_types[x] == NULL ){
Jim_SetResult_sprintf( goi->interp, "Unknown target type %s, try one of ", cp );
for ( x = 0 ; target_types[x] ; x++ ){
- if ( target_types[x+1] ){
+ if ( target_types[x + 1] ){
Jim_AppendStrings( goi->interp,
Jim_GetResult(goi->interp),
target_types[x]->name,
if (target->tap == NULL)
{
Jim_SetResultString( interp, "-chain-position required when creating target", -1);
- e=JIM_ERR;
+ e = JIM_ERR;
}
if ( e != JIM_OK ){
cmd_ctx = Jim_GetAssocData( interp, "context" );
- Jim_GetOpt_Setup( &goi, interp, argc-1, argv+1 );
+ Jim_GetOpt_Setup( &goi, interp, argc-1, argv + 1 );
if ( goi.argc == 0 ){
Jim_WrongNumArgs(interp, 1, argv, "missing: command ...");
if (fastload != NULL)
{
int i;
- for (i=0; i<fastload_num; i++)
+ for (i = 0; i < fastload_num; i++)
{
if (fastload[i].data)
free(fastload[i].data);
}
free(fastload);
- fastload=NULL;
+ fastload = NULL;
}
}
uint8_t *buffer;
uint32_t buf_cnt;
uint32_t image_size;
- uint32_t min_address=0;
- uint32_t max_address=0xffffffff;
+ uint32_t min_address = 0;
+ uint32_t max_address = 0xffffffff;
int i;
image_t image;
image_size = 0x0;
retval = ERROR_OK;
- fastload_num=image.num_sections;
- fastload=(struct FastLoad *)malloc(sizeof(struct FastLoad)*image.num_sections);
+ fastload_num = image.num_sections;
+ fastload = (struct FastLoad *)malloc(sizeof(struct FastLoad)*image.num_sections);
if (fastload == NULL)
{
image_close(&image);
break;
}
- uint32_t offset=0;
- uint32_t length=buf_cnt;
+ uint32_t offset = 0;
+ uint32_t 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 + buf_cnt >= min_address)&&
+ (image.sections[i].base_address < max_address))
{
- if (image.sections[i].base_address<min_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)
+ if (image.sections[i].base_address + buf_cnt > max_address)
{
- length -= (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);
+ 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;
+ 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",
(unsigned int)length,
- ((unsigned int)(image.sections[i].base_address+offset)));
+ ((unsigned int)(image.sections[i].base_address + offset)));
}
free(buffer);
static int handle_fast_load_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
- if (argc>0)
+ if (argc > 0)
return ERROR_COMMAND_SYNTAX_ERROR;
if (fastload == NULL)
{
return ERROR_FAIL;
}
int i;
- int ms=timeval_ms();
- int size=0;
- int retval=ERROR_OK;
- for (i=0; i<fastload_num;i++)
+ int ms = timeval_ms();
+ int size = 0;
+ int retval = ERROR_OK;
+ for (i = 0; i < fastload_num;i++)
{
target_t *target = get_current_target(cmd_ctx);
command_print(cmd_ctx, "Write to 0x%08x, length 0x%08x",
}
size += fastload[i].length;
}
- int after=timeval_ms();
+ int after = timeval_ms();
command_print(cmd_ctx, "Loaded image %f kBytes/s", (float)(size/1024.0)/((float)(after-ms)/1000.0));
return retval;
}