X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Ftarget%2Ftarget.c;h=5433316a879eabf2cb9e1fb62c236782d51bdbaf;hp=a427c66af50d37ca41e929f01fe56277e2574e81;hb=fb1a9b2cb2f844a17d26dfeb3d26849364d93e26;hpb=9af5e445b796f3b4a51d41f9d2eeaf1f5cd78e3b diff --git a/src/target/target.c b/src/target/target.c index a427c66af5..5433316a87 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -246,7 +246,7 @@ static int max_target_number(void) t = all_targets; while ( t ){ if ( x < t->target_number ){ - x = (t->target_number)+1; + x = (t->target_number) + 1; } t = t->next; } @@ -268,7 +268,7 @@ static int new_target_number(void) } t = t->next; } - return x+1; + return x + 1; } static int target_continuous_poll = 1; @@ -492,7 +492,7 @@ static int jtag_enable_callback(enum jtag_event event, void *priv) } -/* Targets that correctly implement init+examine, i.e. +/* Targets that correctly implement init + examine, i.e. * no communication with target during init: * * XScale @@ -1014,7 +1014,7 @@ int target_free_working_area_restore(struct target_s *target, working_area_t *ar if (area->free) return ERROR_OK; - if (restore&&target->backup_working_area) + if (restore && target->backup_working_area) { int retval; if ((retval = target_write_memory(target, area->address, 4, area->size / 4, area->backup)) != ERROR_OK) @@ -1079,7 +1079,7 @@ int target_register_commands(struct command_context_s *cmd_ctx) int target_arch_state(struct target_s *target) { int retval; - if (target==NULL) + if (target == NULL) { LOG_USER("No target has been configured"); return ERROR_OK; @@ -1088,10 +1088,10 @@ int target_arch_state(struct target_s *target) LOG_USER("target state: %s", Jim_Nvp_value2name_simple(nvp_target_state,target->state)->name); - if (target->state!=TARGET_HALTED) + if (target->state != TARGET_HALTED) return ERROR_OK; - retval=target->type->arch_state(target); + retval = target->type->arch_state(target); return retval; } @@ -1118,7 +1118,7 @@ int target_write_buffer(struct target_s *target, uint32_t address, uint32_t size 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; @@ -1200,7 +1200,7 @@ int target_read_buffer(struct target_s *target, uint32_t address, uint32_t size, 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; @@ -1466,8 +1466,8 @@ int target_register_user_commands(struct command_context_s *cmd_ctx) /* 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
"); - register_jim(cmd_ctx, "ocd_array2mem", jim_array2mem, "convert a TCL array to memory locations and write the values
"); + register_jim(cmd_ctx, "ocd_mem2array", jim_mem2array, "read memory and return as a TCL array for script processing
"); + register_jim(cmd_ctx, "ocd_array2mem", jim_array2mem, "convert a TCL array to memory locations and write the values
"); 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"); @@ -1483,7 +1483,7 @@ int target_register_user_commands(struct command_context_s *cmd_ctx) 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 [count]"); @@ -1584,7 +1584,7 @@ static int sense_handler(void) 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; @@ -1603,7 +1603,7 @@ static int sense_handler(void) lastPower = current; } - if ((retval=jtag_srst_asserted(&srstAsserted))!=ERROR_OK) + if ((retval = jtag_srst_asserted(&srstAsserted)) != ERROR_OK) return retval; int srstDeasserted; @@ -1681,10 +1681,10 @@ int handle_target(void *priv) /* clear action flags */ - runSrstAsserted=0; - runSrstDeasserted=0; - runPowerRestore=0; - runPowerDropout=0; + runSrstAsserted = 0; + runSrstDeasserted = 0; + runPowerRestore = 0; + runPowerDropout = 0; recursive = 0; } @@ -1851,7 +1851,7 @@ static int handle_poll_command(struct command_context_s *cmd_ctx, char *cmd, cha return retval; } - else if (argc==1) + else if (argc == 1) { if (strcmp(args[0], "on") == 0) { @@ -1904,12 +1904,12 @@ static int handle_wait_halt_command(struct command_context_s *cmd_ctx, char *cmd 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) { @@ -1918,7 +1918,7 @@ int target_wait_state(target_t *target, enum target_state state, int ms) 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); @@ -2070,7 +2070,7 @@ static void handle_md_output(struct command_context_s *cmd_ctx, (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; @@ -2274,27 +2274,27 @@ static int handle_load_image_command(struct command_context_s *cmd_ctx, char *cm 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)&& + if ((image.sections[i].base_address + buf_cnt >= min_address)&& (image.sections[i].base_addressmax_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; @@ -2302,7 +2302,7 @@ static int handle_load_image_command(struct command_context_s *cmd_ctx, char *cm 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); @@ -2314,7 +2314,7 @@ static int handle_load_image_command(struct command_context_s *cmd_ctx, char *cm return retvaltemp; } - if (retval==ERROR_OK) + if (retval == ERROR_OK) { command_print(cmd_ctx, "downloaded %u byte in %s", (unsigned int)image_size, @@ -2390,7 +2390,7 @@ static int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cm if ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK) return retvaltemp; - if (retval==ERROR_OK) + if (retval == ERROR_OK) { command_print(cmd_ctx, "dumped %lld byte in %s", fileio.size, duration_text); @@ -2447,13 +2447,13 @@ static int handle_verify_image_command_internal(struct command_context_s *cmd_ct 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); @@ -2514,10 +2514,10 @@ static int handle_verify_image_command_internal(struct command_context_s *cmd_ct buffer[t]); free(data); free(buffer); - retval=ERROR_FAIL; + retval = ERROR_FAIL; goto done; } - if ((t%16384)==0) + if ((t%16384) == 0) { keep_alive(); } @@ -2544,7 +2544,7 @@ done: return retvaltemp; } - if (retval==ERROR_OK) + if (retval == ERROR_OK) { command_print(cmd_ctx, "verified %u bytes in %s", (unsigned int)image_size, @@ -2790,9 +2790,9 @@ static void writeData(FILE *f, const void *data, size_t len) 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); } @@ -2807,8 +2807,8 @@ static void writeString(FILE *f, char *s) static void writeGmon(uint32_t *samples, uint32_t sampleNum, char *filename) { uint32_t i; - FILE *f=fopen(filename, "w"); - if (f==NULL) + FILE *f = fopen(filename, "w"); + if (f == NULL) return; writeString(f, "gmon"); writeLong(f, 0x00000001); /* Version */ @@ -2820,42 +2820,42 @@ static void writeGmon(uint32_t *samples, uint32_t sampleNum, char *filename) writeData(f, &zero, 1); /* figure out bucket size */ - uint32_t min=samples[0]; - uint32_t max=samples[0]; - for (i=0; isamples[i]) { - min=samples[i]; + min = samples[i]; } if (max maxBuckets) { - length=maxBuckets; + length = maxBuckets; } - int *buckets=malloc(sizeof(int)*length); - if (buckets==NULL) + int *buckets = malloc(sizeof(int)*length); + if (buckets == NULL) { fclose(f); return; } memset(buckets, 0, sizeof(int)*length); - for (i=0; i65535) { - 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); @@ -2903,7 +2903,7 @@ static int handle_profile_command(struct command_context_s *cmd_ctx, char *cmd, struct timeval timeout, now; gettimeofday(&timeout, NULL); - if (argc!=2) + if (argc != 2) { return ERROR_COMMAND_SYNTAX_ERROR; } @@ -2916,12 +2916,12 @@ static int handle_profile_command(struct command_context_s *cmd_ctx, char *cmd, 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); - if (samples==NULL) + 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); @@ -2946,16 +2946,16 @@ static int handle_profile_command(struct command_context_s *cmd_ctx, char *cmd, } else { command_print(cmd_ctx, "Target not halted or running"); - retval=ERROR_OK; + retval = ERROR_OK; break; } - if (retval!=ERROR_OK) + if (retval != ERROR_OK) { break; } gettimeofday(&now, NULL); - if ((numSamples>=maxSample) || ((now.tv_sec >= timeout.tv_sec) && (now.tv_usec >= timeout.tv_usec))) + if ((numSamples >= maxSample) || ((now.tv_sec >= timeout.tv_sec) && (now.tv_usec >= timeout.tv_usec))) { command_print(cmd_ctx, "Profiling completed. %d samples.", numSamples); if ((retval = target_poll(target)) != ERROR_OK) @@ -3028,7 +3028,7 @@ static int jim_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *argv) 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) @@ -3215,7 +3215,7 @@ static int jim_array2mem(Jim_Interp *interp, 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) @@ -3388,7 +3388,7 @@ void target_handle_event( target_t *target, enum target_event e ) e, Jim_Nvp_value2name_simple( nvp_target_event, e )->name, Jim_GetString( teap->body, NULL ) ); - if (Jim_EvalObj( interp, teap->body )!=JIM_OK) + if (Jim_EvalObj( interp, teap->body ) != JIM_OK) { Jim_PrintErrorMessage(interp); } @@ -3749,7 +3749,7 @@ static int tcl_target_func( Jim_Interp *interp, 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"); @@ -3829,7 +3829,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) b = 1; break; } - for( x = 0 ; x < c ; x++ ){ + for ( x = 0 ; x < c ; x++ ){ 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 ); @@ -3895,36 +3895,36 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) Jim_fprintf( interp, interp->cookie_stdout, "0x%08x ", (int)(a) ); switch ( b ){ case 4: - for( x = 0 ; (x < 16) && (x < y) ; x += 4 ){ + for ( x = 0 ; (x < 16) && (x < y) ; x += 4 ){ z = target_buffer_get_u32( target, &(target_buf[ x * 4 ]) ); Jim_fprintf( interp, interp->cookie_stdout, "%08x ", (int)(z) ); } - for( ; (x < 16) ; x += 4 ){ + for ( ; (x < 16) ; x += 4 ){ Jim_fprintf( interp, interp->cookie_stdout, " " ); } break; case 2: - for( x = 0 ; (x < 16) && (x < y) ; x += 2 ){ + for ( x = 0 ; (x < 16) && (x < y) ; x += 2 ){ z = target_buffer_get_u16( target, &(target_buf[ x * 2 ]) ); Jim_fprintf( interp, interp->cookie_stdout, "%04x ", (int)(z) ); } - for( ; (x < 16) ; x += 2 ){ + for ( ; (x < 16) ; x += 2 ){ Jim_fprintf( interp, interp->cookie_stdout, " " ); } break; case 1: default: - for( x = 0 ; (x < 16) && (x < y) ; x += 1 ){ + for ( x = 0 ; (x < 16) && (x < y) ; x += 1 ){ z = target_buffer_get_u8( target, &(target_buf[ x * 4 ]) ); Jim_fprintf( interp, interp->cookie_stdout, "%02x ", (int)(z) ); } - for( ; (x < 16) ; x += 1 ){ + for ( ; (x < 16) ; x += 1 ){ Jim_fprintf( interp, interp->cookie_stdout, " " ); } break; } /* ascii-ify the bytes */ - for( x = 0 ; x < y ; x++ ){ + for ( x = 0 ; x < y ; x++ ){ if ( (target_buf[x] >= 0x20) && (target_buf[x] <= 0x7e) ){ /* good */ @@ -3987,7 +3987,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) 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 ); @@ -4132,7 +4132,7 @@ static int target_create( Jim_GetOptInfo *goi ) e = Jim_GetOpt_String( goi, &cp2, NULL ); cp = cp2; /* now does target type exist */ - for( x = 0 ; target_types[x] ; x++ ){ + for ( x = 0 ; target_types[x] ; x++ ){ if ( 0 == strcmp( cp, target_types[x]->name ) ){ /* found */ break; @@ -4140,8 +4140,8 @@ static int target_create( Jim_GetOptInfo *goi ) } 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] ){ + for ( x = 0 ; target_types[x] ; x++ ){ + if ( target_types[x + 1] ){ Jim_AppendStrings( goi->interp, Jim_GetResult(goi->interp), target_types[x]->name, @@ -4206,7 +4206,7 @@ static int target_create( Jim_GetOptInfo *goi ) if (target->tap == NULL) { Jim_SetResultString( interp, "-chain-position required when creating target", -1); - e=JIM_ERR; + e = JIM_ERR; } if ( e != JIM_OK ){ @@ -4283,7 +4283,7 @@ static int jim_target( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) 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 ..."); @@ -4313,7 +4313,7 @@ static int jim_target( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) return JIM_ERR; } Jim_SetResult( goi.interp, Jim_NewListObj( goi.interp, NULL, 0 ) ); - for( x = 0 ; target_types[x] ; x++ ){ + for ( x = 0 ; target_types[x] ; x++ ){ Jim_ListAppendElement( goi.interp, Jim_GetResult(goi.interp), Jim_NewStringObj( goi.interp, target_types[x]->name, -1 ) ); @@ -4386,16 +4386,16 @@ static struct FastLoad *fastload; static void free_fastload(void) { - if (fastload!=NULL) + if (fastload != NULL) { int i; - for (i=0; i=min_address)&& + if ((image.sections[i].base_address + buf_cnt >= min_address)&& (image.sections[i].base_addressmax_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); - if (fastload[i].data==NULL) + 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); } duration_stop_measure(&duration, &duration_text); - if (retval==ERROR_OK) + if (retval == ERROR_OK) { command_print(cmd_ctx, "Loaded %u bytes in %s", (unsigned int)image_size, duration_text); command_print(cmd_ctx, "NB!!! image has not been loaded to target, issue a subsequent 'fast_load' to do so."); @@ -4504,7 +4504,7 @@ static int handle_fast_load_image_command(struct command_context_s *cmd_ctx, cha image_close(&image); - if (retval!=ERROR_OK) + if (retval != ERROR_OK) { free_fastload(); } @@ -4516,28 +4516,28 @@ static int handle_fast_load_command(struct command_context_s *cmd_ctx, char *cmd { if (argc>0) return ERROR_COMMAND_SYNTAX_ERROR; - if (fastload==NULL) + if (fastload == NULL) { LOG_ERROR("No image in memory"); return ERROR_FAIL; } int i; - int ms=timeval_ms(); - int size=0; - int retval=ERROR_OK; - for (i=0; i