X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Ftarget%2Ftarget.c;h=5433316a879eabf2cb9e1fb62c236782d51bdbaf;hp=3dee1891967d2c560c1fe587699fead5c72a8720;hb=fb1a9b2cb2f844a17d26dfeb3d26849364d93e26;hpb=3c2eabd20f5182c53f0bfb0c6f2a9f2595434e87 diff --git a/src/target/target.c b/src/target/target.c index 3dee189196..5433316a87 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -82,6 +82,7 @@ extern target_type_t arm9tdmi_target; extern target_type_t arm920t_target; extern target_type_t arm966e_target; extern target_type_t arm926ejs_target; +extern target_type_t fa526_target; extern target_type_t feroceon_target; extern target_type_t xscale_target; extern target_type_t cortexm3_target; @@ -98,6 +99,7 @@ target_type_t *target_types[] = &arm720t_target, &arm966e_target, &arm926ejs_target, + &fa526_target, &feroceon_target, &xscale_target, &cortexm3_target, @@ -142,7 +144,7 @@ const char *target_strerror_safe( int err ) const Jim_Nvp *n; n = Jim_Nvp_value2name_simple( nvp_error_target, err ); - if( n->name == NULL ){ + if ( n->name == NULL ){ return "unknown"; } else { return n->name; @@ -242,9 +244,9 @@ static int max_target_number(void) x = -1; t = all_targets; - while( t ){ - if( x < t->target_number ){ - x = (t->target_number)+1; + while ( t ){ + if ( x < t->target_number ){ + x = (t->target_number) + 1; } t = t->next; } @@ -260,13 +262,13 @@ static int new_target_number(void) /* number is 0 based */ x = -1; t = all_targets; - while(t){ - if( x < t->target_number ){ + while (t){ + if ( x < t->target_number ){ x = t->target_number; } t = t->next; } - return x+1; + return x + 1; } static int target_continuous_poll = 1; @@ -351,7 +353,7 @@ static target_t *get_target_by_num(int num) target_t *target = all_targets; while (target){ - if( target->target_number == num ){ + if ( target->target_number == num ){ return target; } target = target->next; @@ -427,7 +429,7 @@ int target_process_reset(struct command_context_s *cmd_ctx, enum target_reset_mo int retval; Jim_Nvp *n; n = Jim_Nvp_value2name_simple( nvp_reset_modes, reset_mode ); - if( n->name == NULL ){ + if ( n->name == NULL ){ LOG_ERROR("invalid reset mode"); return ERROR_FAIL; } @@ -444,7 +446,7 @@ int target_process_reset(struct command_context_s *cmd_ctx, enum target_reset_mo target_continuous_poll = save_poll; - if(retval != JIM_OK) { + if (retval != JIM_OK) { Jim_PrintErrorMessage(interp); return ERROR_FAIL; } @@ -490,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 @@ -683,9 +685,9 @@ int target_init(struct command_context_s *cmd_ctx) if (all_targets) { - if((retval = target_register_user_commands(cmd_ctx)) != ERROR_OK) + if ((retval = target_register_user_commands(cmd_ctx)) != ERROR_OK) return retval; - if((retval = target_register_timer_callback(handle_target, 100, 1, NULL)) != ERROR_OK) + if ((retval = target_register_timer_callback(handle_target, 100, 1, NULL)) != ERROR_OK) return retval; } @@ -932,8 +934,8 @@ int target_alloc_working_area(struct target_s *target, uint32_t size, working_ar /* only allocate multiples of 4 byte */ if (size % 4) { - LOG_ERROR("BUG: code tried to allocate unaligned number of bytes, padding"); - size = CEIL(size, 4); + LOG_ERROR("BUG: code tried to allocate unaligned number of bytes (0x%08x), padding", ((unsigned)(size))); + size = (size + 3) & (~3); } /* see if there's already a matching working area */ @@ -967,7 +969,8 @@ int target_alloc_working_area(struct target_s *target, uint32_t size, working_ar if (free_size < size) { - LOG_WARNING("not enough working area available(requested %d, free %d)", size, free_size); + LOG_WARNING("not enough working area available(requested %u, free %u)", + (unsigned)(size), (unsigned)(free_size)); return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; } @@ -980,7 +983,7 @@ int target_alloc_working_area(struct target_s *target, uint32_t size, working_ar { int retval; new_wa->backup = malloc(new_wa->size); - if((retval = target_read_memory(target, new_wa->address, 4, new_wa->size / 4, new_wa->backup)) != ERROR_OK) + if ((retval = target_read_memory(target, new_wa->address, 4, new_wa->size / 4, new_wa->backup)) != ERROR_OK) { free(new_wa->backup); free(new_wa); @@ -1011,10 +1014,10 @@ 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) + if ((retval = target_write_memory(target, area->address, 4, area->size / 4, area->backup)) != ERROR_OK) return retval; } @@ -1076,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; @@ -1085,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; } @@ -1099,7 +1102,8 @@ int target_arch_state(struct target_s *target) int target_write_buffer(struct target_s *target, uint32_t address, uint32_t size, uint8_t *buffer) { int retval; - LOG_DEBUG("writing buffer of %i byte at 0x%8.8x", size, address); + LOG_DEBUG("writing buffer of %i byte at 0x%8.8x", + (int)size, (unsigned)address); if (!target_was_examined(target)) { @@ -1114,7 +1118,9 @@ 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)", address, size); + LOG_ERROR("address + size wrapped(0x%08x, 0x%08x)", + (unsigned)address, + (unsigned)size); return ERROR_FAIL; } @@ -1178,7 +1184,8 @@ int target_write_buffer(struct target_s *target, uint32_t address, uint32_t size int target_read_buffer(struct target_s *target, uint32_t address, uint32_t size, uint8_t *buffer) { int retval; - LOG_DEBUG("reading buffer of %i byte at 0x%8.8x", size, address); + LOG_DEBUG("reading buffer of %i byte at 0x%8.8x", + (int)size, (unsigned)address); if (!target_was_examined(target)) { @@ -1193,7 +1200,9 @@ 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%08x, 0x%08x)", address, size); + LOG_ERROR("address + size wrapped(0x%08" PRIx32 ", 0x%08" PRIx32 ")", + address, + size); return ERROR_FAIL; } @@ -1259,7 +1268,7 @@ int target_checksum_memory(struct target_s *target, uint32_t address, uint32_t s buffer = malloc(size); if (buffer == NULL) { - LOG_ERROR("error allocating buffer for section (%d bytes)", size); + LOG_ERROR("error allocating buffer for section (%d bytes)", (int)size); return ERROR_INVALID_ARGUMENTS; } retval = target_read_buffer(target, address, size, buffer); @@ -1317,12 +1326,15 @@ int target_read_u32(struct target_s *target, uint32_t address, uint32_t *value) if (retval == ERROR_OK) { *value = target_buffer_get_u32(target, value_buf); - LOG_DEBUG("address: 0x%8.8x, value: 0x%8.8x", address, *value); + LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%8.8" PRIx32 "", + address, + *value); } else { *value = 0x0; - LOG_DEBUG("address: 0x%8.8x failed", address); + LOG_DEBUG("address: 0x%8.8" PRIx32 " failed", + address); } return retval; @@ -1342,12 +1354,15 @@ int target_read_u16(struct target_s *target, uint32_t address, uint16_t *value) if (retval == ERROR_OK) { *value = target_buffer_get_u16(target, value_buf); - LOG_DEBUG("address: 0x%8.8x, value: 0x%4.4x", address, *value); + LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%4.4x", + address, + *value); } else { *value = 0x0; - LOG_DEBUG("address: 0x%8.8x failed", address); + LOG_DEBUG("address: 0x%8.8" PRIx32 " failed", + address); } return retval; @@ -1364,12 +1379,15 @@ int target_read_u8(struct target_s *target, uint32_t address, uint8_t *value) if (retval == ERROR_OK) { - LOG_DEBUG("address: 0x%8.8x, value: 0x%2.2x", address, *value); + LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%2.2x", + address, + *value); } else { *value = 0x0; - LOG_DEBUG("address: 0x%8.8x failed", address); + LOG_DEBUG("address: 0x%8.8" PRIx32 " failed", + address); } return retval; @@ -1385,7 +1403,9 @@ int target_write_u32(struct target_s *target, uint32_t address, uint32_t value) return ERROR_FAIL; } - LOG_DEBUG("address: 0x%8.8x, value: 0x%8.8x", address, value); + LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%8.8" PRIx32 "", + address, + value); target_buffer_set_u32(target, value_buf, value); if ((retval = target_write_memory(target, address, 4, 1, value_buf)) != ERROR_OK) @@ -1406,7 +1426,9 @@ int target_write_u16(struct target_s *target, uint32_t address, uint16_t value) return ERROR_FAIL; } - LOG_DEBUG("address: 0x%8.8x, value: 0x%8.8x", address, value); + LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%8.8x", + address, + value); target_buffer_set_u16(target, value_buf, value); if ((retval = target_write_memory(target, address, 2, 1, value_buf)) != ERROR_OK) @@ -1426,7 +1448,8 @@ int target_write_u8(struct target_s *target, uint32_t address, uint8_t value) return ERROR_FAIL; } - LOG_DEBUG("address: 0x%8.8x, value: 0x%2.2x", address, value); + LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%2.2x", + address, value); if ((retval = target_write_memory(target, address, 1, 1, &value)) != ERROR_OK) { @@ -1443,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"); @@ -1460,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]"); @@ -1481,9 +1504,9 @@ int target_register_user_commands(struct command_context_s *cmd_ctx) register_command(cmd_ctx, NULL, "verify_image", handle_verify_image_command, COMMAND_EXEC, "verify_image [offset] [type]"); register_command(cmd_ctx, NULL, "test_image", handle_test_image_command, COMMAND_EXEC, "test_image [offset] [type]"); - if((retval = target_request_register_commands(cmd_ctx)) != ERROR_OK) + if ((retval = target_request_register_commands(cmd_ctx)) != ERROR_OK) return retval; - if((retval = trace_register_commands(cmd_ctx)) != ERROR_OK) + if ((retval = trace_register_commands(cmd_ctx)) != ERROR_OK) return retval; return retval; @@ -1561,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; @@ -1580,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; @@ -1658,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; } @@ -1680,7 +1703,7 @@ int handle_target(void *priv) if (!powerDropout && !srstAsserted) { /* polling may fail silently until the target has been examined */ - if((retval = target_poll(target)) != ERROR_OK) + if ((retval = target_poll(target)) != ERROR_OK) return retval; } } @@ -1705,13 +1728,19 @@ static int handle_reg_command(struct command_context_s *cmd_ctx, char *cmd, char reg_cache_t *cache = target->reg_cache; count = 0; - while(cache) + while (cache) { int i; for (i = 0; i < cache->num_regs; i++) { value = buf_to_str(cache->reg_list[i].value, cache->reg_list[i].size, 16); - command_print(cmd_ctx, "(%i) %s (/%i): 0x%s (dirty: %i, valid: %i)", count++, cache->reg_list[i].name, cache->reg_list[i].size, value, cache->reg_list[i].dirty, cache->reg_list[i].valid); + command_print(cmd_ctx, "(%i) %s (/%i): 0x%s (dirty: %i, valid: %i)", + count++, + cache->reg_list[i].name, + (int)(cache->reg_list[i].size), + value, + cache->reg_list[i].dirty, + cache->reg_list[i].valid); free(value); } cache = cache->next; @@ -1730,7 +1759,7 @@ static int handle_reg_command(struct command_context_s *cmd_ctx, char *cmd, char reg_cache_t *cache = target->reg_cache; count = 0; - while(cache) + while (cache) { int i; for (i = 0; i < cache->num_regs; i++) @@ -1774,7 +1803,7 @@ static int handle_reg_command(struct command_context_s *cmd_ctx, char *cmd, char arch_type->get(reg); } value = buf_to_str(reg->value, reg->size, 16); - command_print(cmd_ctx, "%s (/%i): 0x%s", reg->name, reg->size, value); + command_print(cmd_ctx, "%s (/%i): 0x%s", reg->name, (int)(reg->size), value); free(value); return ERROR_OK; } @@ -1789,7 +1818,7 @@ static int handle_reg_command(struct command_context_s *cmd_ctx, char *cmd, char arch_type->set(reg, buf); value = buf_to_str(reg->value, reg->size, 16); - command_print(cmd_ctx, "%s (/%i): 0x%s", reg->name, reg->size, value); + command_print(cmd_ctx, "%s (/%i): 0x%s", reg->name, (int)(reg->size), value); free(value); free(buf); @@ -1822,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) { @@ -1875,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) { @@ -1889,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); @@ -1954,7 +1983,7 @@ static int handle_reset_command(struct command_context_s *cmd_ctx, char *cmd, ch { const Jim_Nvp *n; n = Jim_Nvp_name2value_simple( nvp_reset_modes, args[0] ); - if( (n->name == NULL) || (n->value == RESET_UNKNOWN) ){ + if ( (n->name == NULL) || (n->value == RESET_UNKNOWN) ){ return ERROR_COMMAND_SYNTAX_ERROR; } reset_mode = n->value; @@ -1967,6 +1996,7 @@ static int handle_reset_command(struct command_context_s *cmd_ctx, char *cmd, ch static int handle_resume_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { + int current = 1; if (argc > 1) return ERROR_COMMAND_SYNTAX_ERROR; @@ -1982,9 +2012,10 @@ static int handle_resume_command(struct command_context_s *cmd_ctx, char *cmd, c int retval = parse_u32(args[0], &addr); if (ERROR_OK != retval) return retval; + current = 0; } - return target_resume(target, 0, addr, 1, 0); + return target_resume(target, current, addr, 1, 0); } static int handle_step_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) @@ -2035,10 +2066,11 @@ static void handle_md_output(struct command_context_s *cmd_ctx, { output_len += snprintf(output + output_len, sizeof(output) - output_len, - "0x%8.8x: ", address + (i*size)); + "0x%8.8x: ", + (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; @@ -2230,7 +2262,9 @@ static int handle_load_image_command(struct command_context_s *cmd_ctx, char *cm buffer = malloc(image.sections[i].size); if (buffer == NULL) { - command_print(cmd_ctx, "error allocating buffer for section (%d bytes)", image.sections[i].size); + command_print(cmd_ctx, + "error allocating buffer for section (%d bytes)", + (int)(image.sections[i].size)); break; } @@ -2240,47 +2274,51 @@ 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; } image_size += length; - command_print(cmd_ctx, "%u byte written at address 0x%8.8x", length, image.sections[i].base_address+offset); + command_print(cmd_ctx, "%u byte written at address 0x%8.8" PRIx32 "", + (unsigned int)length, + image.sections[i].base_address + offset); } free(buffer); } - if((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK) + if ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK) { image_close(&image); return retvaltemp; } - if (retval==ERROR_OK) + if (retval == ERROR_OK) { - command_print(cmd_ctx, "downloaded %u byte in %s", image_size, duration_text); + command_print(cmd_ctx, "downloaded %u byte in %s", + (unsigned int)image_size, + duration_text); } free(duration_text); @@ -2346,13 +2384,13 @@ static int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cm address += this_run_size; } - if((retvaltemp = fileio_close(&fileio)) != ERROR_OK) + if ((retvaltemp = fileio_close(&fileio)) != ERROR_OK) return retvaltemp; - if((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK) + 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); @@ -2409,19 +2447,21 @@ 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); if (buffer == NULL) { - command_print(cmd_ctx, "error allocating buffer for section (%d bytes)", image.sections[i].size); + command_print(cmd_ctx, + "error allocating buffer for section (%d bytes)", + (int)(image.sections[i].size)); break; } if ((retval = image_read_section(&image, i, 0x0, image.sections[i].size, buffer, &buf_cnt)) != ERROR_OK) @@ -2436,13 +2476,13 @@ static int handle_verify_image_command_internal(struct command_context_s *cmd_ct image_calculate_checksum( buffer, buf_cnt, &checksum ); retval = target_checksum_memory(target, image.sections[i].base_address, buf_cnt, &mem_checksum); - if( retval != ERROR_OK ) + if ( retval != ERROR_OK ) { free(buffer); break; } - if( checksum != mem_checksum ) + if ( checksum != mem_checksum ) { /* failed crc checksum, fall back to a binary compare */ uint8_t *data; @@ -2467,13 +2507,17 @@ static int handle_verify_image_command_internal(struct command_context_s *cmd_ct { if (data[t] != buffer[t]) { - command_print(cmd_ctx, "Verify operation failed address 0x%08x. Was 0x%02x instead of 0x%02x\n", t + image.sections[i].base_address, data[t], buffer[t]); + command_print(cmd_ctx, + "Verify operation failed address 0x%08x. Was 0x%02x instead of 0x%02x\n", + (unsigned)(t + image.sections[i].base_address), + data[t], + buffer[t]); free(data); free(buffer); - retval=ERROR_FAIL; + retval = ERROR_FAIL; goto done; } - if ((t%16384)==0) + if ((t%16384) == 0) { keep_alive(); } @@ -2484,7 +2528,9 @@ static int handle_verify_image_command_internal(struct command_context_s *cmd_ct } } else { - command_print(cmd_ctx, "address 0x%08x length 0x%08x", image.sections[i].base_address, buf_cnt); + command_print(cmd_ctx, "address 0x%08" PRIx32 " length 0x%08" PRIx32 "", + image.sections[i].base_address, + buf_cnt); } free(buffer); @@ -2492,15 +2538,17 @@ static int handle_verify_image_command_internal(struct command_context_s *cmd_ct } done: - if((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK) + if ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK) { image_close(&image); return retvaltemp; } - if (retval==ERROR_OK) + if (retval == ERROR_OK) { - command_print(cmd_ctx, "verified %u bytes in %s", image_size, duration_text); + command_print(cmd_ctx, "verified %u bytes in %s", + (unsigned int)image_size, + duration_text); } free(duration_text); @@ -2529,15 +2577,17 @@ static int handle_bp_command_list(struct command_context_s *cmd_ctx) { char* buf = buf_to_str(breakpoint->orig_instr, breakpoint->length, 16); - command_print(cmd_ctx, "0x%8.8x, 0x%x, %i, 0x%s", - breakpoint->address, breakpoint->length, + command_print(cmd_ctx, "0x%8.8" PRIx32 ", 0x%x, %i, 0x%s", + breakpoint->address, + breakpoint->length, breakpoint->set, buf); free(buf); } else { - command_print(cmd_ctx, "0x%8.8x, 0x%x, %i", - breakpoint->address, breakpoint->length, breakpoint->set); + command_print(cmd_ctx, "0x%8.8" PRIx32 ", 0x%x, %i", + breakpoint->address, + breakpoint->length, breakpoint->set); } breakpoint = breakpoint->next; @@ -2551,7 +2601,7 @@ static int handle_bp_command_set(struct command_context_s *cmd_ctx, target_t *target = get_current_target(cmd_ctx); int retval = breakpoint_add(target, addr, length, hw); if (ERROR_OK == retval) - command_print(cmd_ctx, "breakpoint set at 0x%8.8x", addr); + command_print(cmd_ctx, "breakpoint set at 0x%8.8" PRIx32 "", addr); else LOG_ERROR("Failure setting breakpoint"); return retval; @@ -2617,7 +2667,13 @@ static int handle_wp_command(struct command_context_s *cmd_ctx, char *cmd, char while (watchpoint) { - command_print(cmd_ctx, "address: 0x%8.8x, len: 0x%8.8x, r/w/a: %i, value: 0x%8.8x, mask: 0x%8.8x", watchpoint->address, watchpoint->length, watchpoint->rw, watchpoint->value, watchpoint->mask); + command_print(cmd_ctx, + "address: 0x%8.8" PRIx32 ", len: 0x%8.8x, r/w/a: %i, value: 0x%8.8" PRIx32 ", mask: 0x%8.8" PRIx32 "", + watchpoint->address, + watchpoint->length, + (int)(watchpoint->rw), + watchpoint->value, + watchpoint->mask); watchpoint = watchpoint->next; } return ERROR_OK; @@ -2643,7 +2699,7 @@ static int handle_wp_command(struct command_context_s *cmd_ctx, char *cmd, char return retval; // fall through case 3: - switch(args[2][0]) + switch (args[2][0]) { case 'r': type = WPT_READ; @@ -2719,7 +2775,7 @@ static int handle_virt2phys_command(command_context_t *cmd_ctx, target_t *target = get_current_target(cmd_ctx); retval = target->type->virt2phys(target, va, &pa); if (retval == ERROR_OK) - command_print(cmd_ctx, "Physical address 0x%08x", pa); + command_print(cmd_ctx, "Physical address 0x%08" PRIx32 "", pa); return retval; } @@ -2734,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); } @@ -2751,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 */ @@ -2764,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); @@ -2847,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; } @@ -2860,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); @@ -2882,7 +2938,7 @@ static int handle_profile_command(struct command_context_s *cmd_ctx, char *cmd, } else if (target->state == TARGET_RUNNING) { /* We want to quickly sample the PC. */ - if((retval = target_halt(target)) != ERROR_OK) + if ((retval = target_halt(target)) != ERROR_OK) { free(samples); return retval; @@ -2890,19 +2946,19 @@ 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) + if ((retval = target_poll(target)) != ERROR_OK) { free(samples); return retval; @@ -2911,7 +2967,7 @@ static int handle_profile_command(struct command_context_s *cmd_ctx, char *cmd, { target_resume(target, 1, 0, 0, 0); /* current pc, addr = 0, do not handle breakpoints, not debugging */ } - if((retval = target_poll(target)) != ERROR_OK) + if ((retval = target_poll(target)) != ERROR_OK) { free(samples); return retval; @@ -2972,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) @@ -3055,7 +3111,9 @@ static int target_mem2array(Jim_Interp *interp, target_t *target, int argc, Jim_ } else { char buf[100]; Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - sprintf(buf, "mem2array address: 0x%08x is not aligned for %d byte reads", addr, width); + sprintf(buf, "mem2array address: 0x%08" PRIx32 " is not aligned for %" PRId32 " byte reads", + addr, + width); Jim_AppendStrings(interp, Jim_GetResult(interp), buf , NULL); return JIM_ERR; } @@ -3077,7 +3135,10 @@ static int target_mem2array(Jim_Interp *interp, target_t *target, int argc, Jim_ retval = target_read_memory( target, addr, width, count, buffer ); if (retval != ERROR_OK) { /* BOO !*/ - LOG_ERROR("mem2array: Read @ 0x%08x, w=%d, cnt=%d, failed", addr, width, count); + LOG_ERROR("mem2array: Read @ 0x%08x, w=%d, cnt=%d, failed", + (unsigned int)addr, + (int)width, + (int)count); Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); Jim_AppendStrings(interp, Jim_GetResult(interp), "mem2array: cannot read memory", NULL); e = JIM_ERR; @@ -3154,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) @@ -3237,7 +3298,9 @@ static int target_array2mem(Jim_Interp *interp, target_t *target, int argc, Jim_ } else { char buf[100]; Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - sprintf(buf, "array2mem address: 0x%08x is not aligned for %d byte reads", addr, width); + sprintf(buf, "array2mem address: 0x%08x is not aligned for %d byte reads", + (unsigned int)addr, + (int)width); Jim_AppendStrings(interp, Jim_GetResult(interp), buf , NULL); return JIM_ERR; } @@ -3276,7 +3339,10 @@ static int target_array2mem(Jim_Interp *interp, target_t *target, int argc, Jim_ 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_ERROR("array2mem: Write @ 0x%08x, w=%d, cnt=%d, failed", + (unsigned int)addr, + (int)width, + (int)count); Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); Jim_AppendStrings(interp, Jim_GetResult(interp), "array2mem: cannot read memory", NULL); e = JIM_ERR; @@ -3294,8 +3360,8 @@ 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 ); + (int)e, + Jim_Nvp_value2name_simple( nvp_target_event, e )->name ); target = all_targets; while (target){ @@ -3312,8 +3378,8 @@ void target_handle_event( target_t *target, enum target_event e ) teap = target->event_action; done = 0; - while( teap ){ - if( teap->event == e ){ + while ( teap ){ + if ( teap->event == e ){ done = 1; LOG_DEBUG( "target: (%d) %s (%s) event: %d (%s) action: %s\n", target->target_number, @@ -3322,14 +3388,14 @@ 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); } } teap = teap->next; } - if( !done ){ + if ( !done ){ LOG_DEBUG( "event: %d %s - no action", e, Jim_Nvp_value2name_simple( nvp_target_event, e )->name ); @@ -3371,38 +3437,38 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target ) int e; /* parse config or cget options ... */ - while( goi->argc > 0 ){ + while ( goi->argc > 0 ){ Jim_SetEmptyResult( goi->interp ); /* Jim_GetOpt_Debug( goi ); */ - if( target->type->target_jim_configure ){ + if ( target->type->target_jim_configure ){ /* target defines a configure function */ /* target gets first dibs on parameters */ e = (*(target->type->target_jim_configure))( target, goi ); - if( e == JIM_OK ){ + if ( e == JIM_OK ){ /* more? */ continue; } - if( e == JIM_ERR ){ + if ( e == JIM_ERR ){ /* An error */ return e; } /* otherwise we 'continue' below */ } e = Jim_GetOpt_Nvp( goi, nvp_config_opts, &n ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ Jim_GetOpt_NvpUnknown( goi, nvp_config_opts, 0 ); return e; } - switch( n->value ){ + switch ( n->value ){ case TCFG_TYPE: /* not setable */ - if( goi->isconfigure ){ + if ( goi->isconfigure ){ Jim_SetResult_sprintf( goi->interp, "not setable: %s", n->name ); return JIM_ERR; } else { no_params: - if( goi->argc != 0 ){ + if ( goi->argc != 0 ){ Jim_WrongNumArgs( goi->interp, goi->argc, goi->argv, "NO PARAMS"); return JIM_ERR; } @@ -3411,24 +3477,24 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target ) /* loop for more */ break; case TCFG_EVENT: - if( goi->argc == 0 ){ + if ( goi->argc == 0 ){ Jim_WrongNumArgs( goi->interp, goi->argc, goi->argv, "-event ?event-name? ..."); return JIM_ERR; } e = Jim_GetOpt_Nvp( goi, nvp_target_event, &n ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ Jim_GetOpt_NvpUnknown( goi, nvp_target_event, 1 ); return e; } - if( goi->isconfigure ){ - if( goi->argc != 1 ){ + if ( goi->isconfigure ){ + if ( goi->argc != 1 ){ Jim_WrongNumArgs( goi->interp, goi->argc, goi->argv, "-event ?event-name? ?EVENT-BODY?"); return JIM_ERR; } } else { - if( goi->argc != 0 ){ + if ( goi->argc != 0 ){ Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-event ?event-name?"); return JIM_ERR; } @@ -3439,21 +3505,21 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target ) teap = target->event_action; /* replace existing? */ - while( teap ){ - if( teap->event == (enum target_event)n->value ){ + while ( teap ){ + if ( teap->event == (enum target_event)n->value ){ break; } teap = teap->next; } - if( goi->isconfigure ){ - if( teap == NULL ){ + if ( goi->isconfigure ){ + if ( teap == NULL ){ /* create new */ teap = calloc( 1, sizeof(*teap) ); } teap->event = n->value; Jim_GetOpt_Obj( goi, &o ); - if( teap->body ){ + if ( teap->body ){ Jim_DecrRefCount( interp, teap->body ); } teap->body = Jim_DuplicateObj( goi->interp, o ); @@ -3475,7 +3541,7 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target ) Jim_SetEmptyResult(goi->interp); } else { /* get */ - if( teap == NULL ){ + if ( teap == NULL ){ Jim_SetEmptyResult( goi->interp ); } else { Jim_SetResult( goi->interp, Jim_DuplicateObj( goi->interp, teap->body ) ); @@ -3486,15 +3552,15 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target ) break; case TCFG_WORK_AREA_VIRT: - if( goi->isconfigure ){ + if ( goi->isconfigure ){ target_free_all_working_areas(target); e = Jim_GetOpt_Wide( goi, &w ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ return e; } target->working_area_virt = w; } else { - if( goi->argc != 0 ){ + if ( goi->argc != 0 ){ goto no_params; } } @@ -3503,15 +3569,15 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target ) break; case TCFG_WORK_AREA_PHYS: - if( goi->isconfigure ){ + if ( goi->isconfigure ){ target_free_all_working_areas(target); e = Jim_GetOpt_Wide( goi, &w ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ return e; } target->working_area_phys = w; } else { - if( goi->argc != 0 ){ + if ( goi->argc != 0 ){ goto no_params; } } @@ -3520,15 +3586,15 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target ) break; case TCFG_WORK_AREA_SIZE: - if( goi->isconfigure ){ + if ( goi->isconfigure ){ target_free_all_working_areas(target); e = Jim_GetOpt_Wide( goi, &w ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ return e; } target->working_area_size = w; } else { - if( goi->argc != 0 ){ + if ( goi->argc != 0 ){ goto no_params; } } @@ -3537,16 +3603,16 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target ) break; case TCFG_WORK_AREA_BACKUP: - if( goi->isconfigure ){ + if ( goi->isconfigure ){ target_free_all_working_areas(target); e = Jim_GetOpt_Wide( goi, &w ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ return e; } /* make this exactly 1 or 0 */ target->backup_working_area = (!!w); } else { - if( goi->argc != 0 ){ + if ( goi->argc != 0 ){ goto no_params; } } @@ -3555,20 +3621,20 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target ) break; case TCFG_ENDIAN: - if( goi->isconfigure ){ + if ( goi->isconfigure ){ e = Jim_GetOpt_Nvp( goi, nvp_target_endian, &n ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ Jim_GetOpt_NvpUnknown( goi, nvp_target_endian, 1 ); return e; } target->endianness = n->value; } else { - if( goi->argc != 0 ){ + if ( goi->argc != 0 ){ goto no_params; } } n = Jim_Nvp_value2name_simple( nvp_target_endian, target->endianness ); - if( n->name == NULL ){ + if ( n->name == NULL ){ target->endianness = TARGET_LITTLE_ENDIAN; n = Jim_Nvp_value2name_simple( nvp_target_endian, target->endianness ); } @@ -3577,20 +3643,20 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target ) break; case TCFG_VARIANT: - if( goi->isconfigure ){ - if( goi->argc < 1 ){ + if ( goi->isconfigure ){ + if ( goi->argc < 1 ){ Jim_SetResult_sprintf( goi->interp, "%s ?STRING?", n->name ); return JIM_ERR; } - if( target->variant ){ + if ( target->variant ){ free((void *)(target->variant)); } e = Jim_GetOpt_String( goi, &cp, NULL ); target->variant = strdup(cp); } else { - if( goi->argc != 0 ){ + if ( goi->argc != 0 ){ goto no_params; } } @@ -3598,22 +3664,22 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target ) /* loop for more */ break; case TCFG_CHAIN_POSITION: - if( goi->isconfigure ){ + if ( goi->isconfigure ){ Jim_Obj *o; jtag_tap_t *tap; target_free_all_working_areas(target); e = Jim_GetOpt_Obj( goi, &o ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ return e; } tap = jtag_tap_by_jim_obj( goi->interp, o ); - if( tap == NULL ){ + if ( tap == NULL ){ return JIM_ERR; } /* make this exactly 1 or 0 */ target->tap = tap; } else { - if( goi->argc != 0 ){ + if ( goi->argc != 0 ){ goto no_params; } } @@ -3621,7 +3687,7 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target ) /* loop for more e*/ break; } - } /* while( goi->argc ) */ + } /* while ( goi->argc ) */ /* done - we return */ @@ -3683,23 +3749,23 @@ 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"); /* commands here are in an NVP table */ e = Jim_GetOpt_Nvp( &goi, target_options, &n ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ Jim_GetOpt_NvpUnknown( &goi, target_options, 0 ); return e; } /* Assume blank result */ Jim_SetEmptyResult( goi.interp ); - switch( n->value ){ + switch ( n->value ){ case TS_CMD_CONFIGURE: - if( goi.argc < 2 ){ + if ( goi.argc < 2 ){ Jim_WrongNumArgs( goi.interp, goi.argc, goi.argv, "missing: -option VALUE ..."); return JIM_ERR; } @@ -3707,7 +3773,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) return target_configure( &goi, target ); case TS_CMD_CGET: // some things take params - if( goi.argc < 1 ){ + if ( goi.argc < 1 ){ Jim_WrongNumArgs( goi.interp, 0, goi.argv, "missing: ?-option?"); return JIM_ERR; } @@ -3723,7 +3789,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) * argv[3] = optional count. */ - if( (goi.argc == 2) || (goi.argc == 3) ){ + if ( (goi.argc == 2) || (goi.argc == 3) ){ /* all is well */ } else { mwx_error: @@ -3732,24 +3798,24 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) } e = Jim_GetOpt_Wide( &goi, &a ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ goto mwx_error; } e = Jim_GetOpt_Wide( &goi, &b ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ goto mwx_error; } if (goi.argc == 3) { e = Jim_GetOpt_Wide( &goi, &c ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ goto mwx_error; } } else { c = 1; } - switch( n->value ){ + switch ( n->value ){ case TS_CMD_MWW: target_buffer_set_u32( target, target_buf, b ); b = 4; @@ -3763,9 +3829,9 @@ 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 ){ + if ( e != ERROR_OK ){ Jim_SetResult_sprintf( interp, "Error writing @ 0x%08x: %d\n", (int)(a), e ); return JIM_ERR; } @@ -3783,24 +3849,24 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) * argv[1] = address * argv[2] = optional count */ - if( (goi.argc == 2) || (goi.argc == 3) ){ + if ( (goi.argc == 2) || (goi.argc == 3) ){ Jim_SetResult_sprintf( goi.interp, "expected: %s ADDR [COUNT]", n->name ); return JIM_ERR; } e = Jim_GetOpt_Wide( &goi, &a ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ return JIM_ERR; } - if( goi.argc ){ + if ( goi.argc ){ e = Jim_GetOpt_Wide( &goi, &c ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ return JIM_ERR; } } else { c = 1; } b = 1; /* shut up gcc */ - switch( n->value ){ + switch ( n->value ){ case TS_CMD_MDW: b = 4; break; @@ -3815,51 +3881,51 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) /* convert to "bytes" */ c = c * b; /* count is now in 'BYTES' */ - while( c > 0 ){ + while ( c > 0 ){ y = c; - if( y > 16 ){ + if ( y > 16 ){ y = 16; } e = target_read_memory( target, a, b, y / b, target_buf ); - if( e != ERROR_OK ){ + if ( e != ERROR_OK ){ Jim_SetResult_sprintf( interp, "error reading target @ 0x%08lx", (int)(a) ); return JIM_ERR; } Jim_fprintf( interp, interp->cookie_stdout, "0x%08x ", (int)(a) ); - switch( b ){ + 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++ ){ - if( (target_buf[x] >= 0x20) && + for ( x = 0 ; x < y ; x++ ){ + if ( (target_buf[x] >= 0x20) && (target_buf[x] <= 0x7e) ){ /* good */ } else { @@ -3868,7 +3934,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) } } /* space pad */ - while( x < 16 ){ + while ( x < 16 ){ target_buf[x] = ' '; x++; } @@ -3888,31 +3954,31 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) return target_array2mem( goi.interp, target, goi.argc, goi.argv ); break; case TS_CMD_EXAMINE: - if( goi.argc ){ + if ( goi.argc ){ 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 ){ + if ( e != ERROR_OK ){ Jim_SetResult_sprintf( interp, "examine-fails: %d", e ); return JIM_ERR; } return JIM_OK; case TS_CMD_POLL: - if( goi.argc ){ + if ( goi.argc ){ Jim_WrongNumArgs( goi.interp, 2, argv, "[no parameters]"); return JIM_ERR; } if (!target->tap->enabled) goto err_tap_disabled; - if( !(target_was_examined(target)) ){ + if ( !(target_was_examined(target)) ){ e = ERROR_TARGET_NOT_EXAMINED; } else { e = target->type->poll( target ); } - if( e != ERROR_OK ){ + if ( e != ERROR_OK ){ Jim_SetResult_sprintf( interp, "poll-fails: %d", e ); return JIM_ERR; } else { @@ -3920,18 +3986,18 @@ 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"); + if ( goi.argc != 2 ){ + Jim_WrongNumArgs( interp, 2, argv, "t | f|assert | deassert BOOL"); return JIM_ERR; } e = Jim_GetOpt_Nvp( &goi, nvp_assert, &n ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ Jim_GetOpt_NvpUnknown( &goi, nvp_assert, 1 ); return e; } /* the halt or not param */ e = Jim_GetOpt_Wide( &goi, &a); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ return e; } if (!target->tap->enabled) @@ -3942,14 +4008,14 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) target_free_all_working_areas_restore(target, 0); /* do the assert */ - if( n->value == NVP_ASSERT ){ + if ( n->value == NVP_ASSERT ){ target->type->assert_reset( target ); } else { target->type->deassert_reset( target ); } return JIM_OK; case TS_CMD_HALT: - if( goi.argc ){ + if ( goi.argc ){ Jim_WrongNumArgs( goi.interp, 0, argv, "halt [no parameters]"); return JIM_ERR; } @@ -3959,23 +4025,23 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) return JIM_OK; case TS_CMD_WAITSTATE: /* params: statename timeoutmsecs */ - if( goi.argc != 2 ){ + if ( goi.argc != 2 ){ Jim_SetResult_sprintf( goi.interp, "%s STATENAME TIMEOUTMSECS", n->name ); return JIM_ERR; } e = Jim_GetOpt_Nvp( &goi, nvp_target_state, &n ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ Jim_GetOpt_NvpUnknown( &goi, nvp_target_state,1 ); return e; } e = Jim_GetOpt_Wide( &goi, &a ); - if( e != JIM_OK ){ + 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 ){ + if ( e != ERROR_OK ){ Jim_SetResult_sprintf( goi.interp, "target: %s wait %s fails (%d) %s", target->cmd_name, @@ -3997,7 +4063,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) target->cmd_name ); command_print( cmd_ctx, "%-25s | Body", "Event"); command_print( cmd_ctx, "------------------------- | ----------------------------------------"); - while( teap ){ + while ( teap ){ command_print( cmd_ctx, "%-25s | %s", Jim_Nvp_value2name_simple( nvp_target_event, teap->event )->name, @@ -4008,7 +4074,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) return JIM_OK; } case TS_CMD_CURSTATE: - if( goi.argc != 0 ){ + if ( goi.argc != 0 ){ Jim_WrongNumArgs( goi.interp, 0, argv, "[no parameters]"); return JIM_ERR; } @@ -4016,12 +4082,12 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) Jim_Nvp_value2name_simple(nvp_target_state,target->state)->name,-1); return JIM_OK; case TS_CMD_INVOKE_EVENT: - if( goi.argc != 1 ){ + if ( goi.argc != 1 ){ Jim_SetResult_sprintf( goi.interp, "%s ?EVENTNAME?",n->name); return JIM_ERR; } e = Jim_GetOpt_Nvp( &goi, nvp_target_event, &n ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ Jim_GetOpt_NvpUnknown( &goi, nvp_target_event, 1 ); return e; } @@ -4047,7 +4113,7 @@ static int target_create( Jim_GetOptInfo *goi ) struct command_context_s *cmd_ctx; cmd_ctx = Jim_GetAssocData(goi->interp, "context"); - if( goi->argc < 3 ){ + if ( goi->argc < 3 ){ Jim_WrongNumArgs( goi->interp, 1, goi->argv, "?name? ?type? ..options..."); return JIM_ERR; } @@ -4056,7 +4122,7 @@ static int target_create( Jim_GetOptInfo *goi ) Jim_GetOpt_Obj( goi, &new_cmd ); /* does this command exist? */ cmd = Jim_GetCommand( goi->interp, new_cmd, JIM_ERRMSG ); - if( cmd ){ + if ( cmd ){ cp = Jim_GetString( new_cmd, NULL ); Jim_SetResult_sprintf(goi->interp, "Command/target: %s Exists", cp); return JIM_ERR; @@ -4066,16 +4132,16 @@ 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++ ){ - if( 0 == strcmp( cp, target_types[x]->name ) ){ + for ( x = 0 ; target_types[x] ; x++ ){ + if ( 0 == strcmp( cp, target_types[x]->name ) ){ /* found */ break; } } - if( target_types[x] == NULL ){ + 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, @@ -4140,16 +4206,16 @@ 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 ){ + if ( e != JIM_OK ){ free( target->type ); free( target ); return e; } - if( target->endianness == TARGET_ENDIAN_UNKNOWN ){ + if ( target->endianness == TARGET_ENDIAN_UNKNOWN ){ /* default endian to little if not specified */ target->endianness = TARGET_LITTLE_ENDIAN; } @@ -4159,10 +4225,10 @@ static int target_create( Jim_GetOptInfo *goi ) target->variant = strdup(""); /* create the target specific commands */ - if( target->type->register_commands ){ + if ( target->type->register_commands ){ (*(target->type->register_commands))( cmd_ctx ); } - if( target->type->target_create ){ + if ( target->type->target_create ){ (*(target->type->target_create))( target, goi->interp ); } @@ -4170,7 +4236,7 @@ static int target_create( Jim_GetOptInfo *goi ) { target_t **tpp; tpp = &(all_targets); - while( *tpp ){ + while ( *tpp ){ tpp = &( (*tpp)->next ); } *tpp = target; @@ -4217,50 +4283,50 @@ 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 ){ + if ( goi.argc == 0 ){ Jim_WrongNumArgs(interp, 1, argv, "missing: command ..."); return JIM_ERR; } /* Jim_GetOpt_Debug( &goi ); */ r = Jim_GetOpt_Enum( &goi, target_cmds, &x ); - if( r != JIM_OK ){ + if ( r != JIM_OK ){ return r; } - switch(x){ + switch (x){ default: Jim_Panic(goi.interp,"Why am I here?"); return JIM_ERR; case TG_CMD_CURRENT: - if( goi.argc != 0 ){ + if ( goi.argc != 0 ){ Jim_WrongNumArgs( goi.interp, 1, goi.argv, "Too many parameters"); return JIM_ERR; } Jim_SetResultString( goi.interp, get_current_target( cmd_ctx )->cmd_name, -1 ); return JIM_OK; case TG_CMD_TYPES: - if( goi.argc != 0 ){ + if ( goi.argc != 0 ){ Jim_WrongNumArgs( goi.interp, 1, goi.argv, "Too many parameters" ); 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 ) ); } return JIM_OK; case TG_CMD_NAMES: - if( goi.argc != 0 ){ + if ( goi.argc != 0 ){ Jim_WrongNumArgs( goi.interp, 1, goi.argv, "Too many parameters" ); return JIM_ERR; } Jim_SetResult( goi.interp, Jim_NewListObj( goi.interp, NULL, 0 ) ); target = all_targets; - while( target ){ + while ( target ){ Jim_ListAppendElement( goi.interp, Jim_GetResult(goi.interp), Jim_NewStringObj( goi.interp, target->cmd_name, -1 ) ); @@ -4268,25 +4334,25 @@ static int jim_target( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) } return JIM_OK; case TG_CMD_CREATE: - if( goi.argc < 3 ){ + if ( goi.argc < 3 ){ Jim_WrongNumArgs( goi.interp, goi.argc, goi.argv, "?name ... config options ..."); return JIM_ERR; } return target_create( &goi ); break; case TG_CMD_NUMBER: - if( goi.argc != 1 ){ + if ( goi.argc != 1 ){ Jim_SetResult_sprintf( goi.interp, "expected: target number ?NUMBER?"); return JIM_ERR; } e = Jim_GetOpt_Wide( &goi, &w ); - if( e != JIM_OK ){ + if ( e != JIM_OK ){ return JIM_ERR; } { target_t *t; t = get_target_by_num(w); - if( t == NULL ){ + if ( t == NULL ){ Jim_SetResult_sprintf( goi.interp,"Target: number %d does not exist", (int)(w)); return JIM_ERR; } @@ -4294,7 +4360,7 @@ static int jim_target( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) return JIM_OK; } case TG_CMD_COUNT: - if( goi.argc != 0 ){ + if ( goi.argc != 0 ){ Jim_WrongNumArgs( goi.interp, 0, goi.argv, ""); return JIM_ERR; } @@ -4320,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", length, image.sections[i].base_address+offset); + command_print(cmd_ctx, "%u byte written at address 0x%8.8x", + (unsigned int)length, + ((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", image_size, duration_text); + 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."); } free(duration_text); image_close(&image); - if (retval!=ERROR_OK) + if (retval != ERROR_OK) { free_fastload(); } @@ -4447,26 +4516,36 @@ 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