X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Ftarget%2Ftarget.c;h=dd61b04c12a1d6fa2a00006ed982193de8357fb2;hp=c86ee8d4f07fd7ec13043fe26deb8d4a09bdd9fd;hb=8c1ec4f0e1a7dd37a2549d83b6cd5c8c57eb34aa;hpb=0cba0d4df3fe120f08945703506f8405760325c9 diff --git a/src/target/target.c b/src/target/target.c index c86ee8d4f0..dd61b04c12 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -59,29 +59,31 @@ #include #include -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_poll_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -int handle_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -int handle_wait_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -int handle_reset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -int handle_soft_reset_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -int handle_resume_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -int handle_step_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -int handle_md_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -int handle_load_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -int handle_verify_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -int handle_bp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -int handle_rbp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -int handle_wp_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); +static int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); + +static int handle_reg_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_poll_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_wait_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_reset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_soft_reset_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_resume_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_step_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_md_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_load_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_verify_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_test_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_bp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_rbp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_wp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_rwp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_virt2phys_command(command_context_t *cmd_ctx, char *cmd, char **args, int argc); +static int handle_profile_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int handle_fast_load_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static 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); @@ -101,6 +103,7 @@ extern target_type_t xscale_target; extern target_type_t cortexm3_target; extern target_type_t arm11_target; extern target_type_t mips_m4k_target; +extern target_type_t avr_target; target_type_t *target_types[] = { @@ -115,6 +118,7 @@ target_type_t *target_types[] = &cortexm3_target, &arm11_target, &mips_m4k_target, + &avr_target, NULL, }; @@ -229,7 +233,6 @@ const Jim_Nvp nvp_target_debug_reason [] = { { .name = NULL, .value = -1 }, }; - const Jim_Nvp nvp_target_endian[] = { { .name = "big", .value = TARGET_BIG_ENDIAN }, { .name = "little", .value = TARGET_LITTLE_ENDIAN }, @@ -246,8 +249,7 @@ const Jim_Nvp nvp_reset_modes[] = { { .name = NULL , .value = -1 }, }; -static int -max_target_number( void ) +static int max_target_number(void) { target_t *t; int x; @@ -264,8 +266,7 @@ max_target_number( void ) } /* determine the number of the new target */ -static int -new_target_number( void ) +static int new_target_number(void) { target_t *t; int x; @@ -926,15 +927,12 @@ int target_register_commands(struct command_context_s *cmd_ctx) { register_command(cmd_ctx, NULL, "targets", handle_targets_command, COMMAND_EXEC, "change the current command line target (one parameter) or lists targets (with no parameter)"); - 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_jim(cmd_ctx, "target", jim_target, "configure target" ); - /* script procedures */ - 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, "target", jim_target, "configure target" ); + return ERROR_OK; } @@ -987,7 +985,7 @@ int target_write_buffer(struct target_s *target, u32 address, u32 size, u8 *buff /* handle unaligned head bytes */ if (address % 4) { - int unaligned = 4 - (address % 4); + u32 unaligned = 4 - (address % 4); if (unaligned > size) unaligned = size; @@ -1062,7 +1060,7 @@ int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffe /* handle unaligned head bytes */ if (address % 4) { - int unaligned = 4 - (address % 4); + u32 unaligned = 4 - (address % 4); if (unaligned > size) unaligned = size; @@ -1102,7 +1100,7 @@ int target_checksum_memory(struct target_s *target, u32 address, u32 size, u32* { u8 *buffer; int retval; - int i; + u32 i; u32 checksum = 0; if (!target->type->examined) { @@ -1296,6 +1294,21 @@ int target_write_u8(struct target_s *target, u32 address, u8 value) int target_register_user_commands(struct command_context_s *cmd_ctx) { int retval = ERROR_OK; + + + /* 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_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_command(cmd_ctx, NULL, "virt2phys", handle_virt2phys_command, COMMAND_ANY, "translate a virtual address into a physical address"); register_command(cmd_ctx, NULL, "reg", handle_reg_command, COMMAND_EXEC, "display or set a register"); register_command(cmd_ctx, NULL, "poll", handle_poll_command, COMMAND_EXEC, "poll target state"); register_command(cmd_ctx, NULL, "wait_halt", handle_wait_halt_command, COMMAND_EXEC, "wait for target halt [time (s)]"); @@ -1321,6 +1334,7 @@ int target_register_user_commands(struct command_context_s *cmd_ctx) register_command(cmd_ctx, NULL, "load_image", handle_load_image_command, COMMAND_EXEC, "load_image
['bin'|'ihex'|'elf'|'s19'] [min_address] [max_length]"); register_command(cmd_ctx, NULL, "dump_image", handle_dump_image_command, COMMAND_EXEC, "dump_image
"); 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) return retval; @@ -1330,7 +1344,7 @@ int target_register_user_commands(struct command_context_s *cmd_ctx) return retval; } -int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { char *cp; target_t *target = all_targets; @@ -1526,7 +1540,7 @@ int handle_target(void *priv) return retval; } -int handle_reg_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_reg_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { target_t *target; reg_t *reg = NULL; @@ -1637,7 +1651,7 @@ int handle_reg_command(struct command_context_s *cmd_ctx, char *cmd, char **args return ERROR_OK; } -int handle_poll_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_poll_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { int retval = ERROR_OK; target_t *target = get_current_target(cmd_ctx); @@ -1672,7 +1686,7 @@ int handle_poll_command(struct command_context_s *cmd_ctx, char *cmd, char **arg return retval; } -int handle_wait_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_wait_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { int ms = 5000; @@ -1692,32 +1706,41 @@ int handle_wait_halt_command(struct command_context_s *cmd_ctx, char *cmd, char return target_wait_state(target, TARGET_HALTED, ms); } +/* wait for target state to change. The trick here is to have a low + * latency for short waits and not to suck up all the CPU time + * on longer waits. + * + * After 500ms, keep_alive() is invoked + */ int target_wait_state(target_t *target, enum target_state state, int ms) { int retval; - struct timeval timeout, now; + long long then=0, cur; int once=1; - gettimeofday(&timeout, NULL); - timeval_add_time(&timeout, 0, ms * 1000); for (;;) { if ((retval=target_poll(target))!=ERROR_OK) return retval; - keep_alive(); if (target->state == state) { break; } + cur = timeval_ms(); if (once) { once=0; + then = timeval_ms(); LOG_DEBUG("waiting for target %s...", 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))) + if (cur-then>500) + { + keep_alive(); + } + + if ((cur-then)>ms) { LOG_ERROR("timed out while waiting for target %s", Jim_Nvp_value2name_simple(nvp_target_state,state)->name); @@ -1728,7 +1751,7 @@ int target_wait_state(target_t *target, enum target_state state, int ms) return ERROR_OK; } -int handle_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { int retval; target_t *target = get_current_target(cmd_ctx); @@ -1740,10 +1763,20 @@ int handle_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **arg return retval; } + if (argc == 1) + { + int wait; + char *end; + + wait = strtoul(args[0], &end, 0); + if (!*end && !wait) + return ERROR_OK; + } + return handle_wait_halt_command(cmd_ctx, cmd, args, argc); } -int handle_soft_reset_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_soft_reset_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { target_t *target = get_current_target(cmd_ctx); @@ -1754,7 +1787,7 @@ int handle_soft_reset_halt_command(struct command_context_s *cmd_ctx, char *cmd, return ERROR_OK; } -int handle_reset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_reset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { const Jim_Nvp *n; enum target_reset_mode reset_mode = RESET_RUN; @@ -1773,7 +1806,7 @@ int handle_reset_command(struct command_context_s *cmd_ctx, char *cmd, char **ar } -int handle_resume_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_resume_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { int retval; target_t *target = get_current_target(cmd_ctx); @@ -1792,7 +1825,7 @@ int handle_resume_command(struct command_context_s *cmd_ctx, char *cmd, char **a return retval; } -int handle_step_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_step_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { target_t *target = get_current_target(cmd_ctx); @@ -1807,7 +1840,7 @@ int handle_step_command(struct command_context_s *cmd_ctx, char *cmd, char **arg return ERROR_OK; } -int handle_md_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_md_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { const int line_bytecnt = 32; int count = 1; @@ -1884,7 +1917,7 @@ int handle_md_command(struct command_context_s *cmd_ctx, char *cmd, char **args, return retval; } -int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { u32 address = 0; u32 value = 0; @@ -1948,7 +1981,7 @@ int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char **args, } -int handle_load_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_load_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { u8 *buffer; u32 buf_cnt; @@ -2072,7 +2105,7 @@ int handle_load_image_command(struct command_context_s *cmd_ctx, char *cmd, char } -int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { fileio_t fileio; @@ -2144,7 +2177,7 @@ int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cmd, char return ERROR_OK; } -int handle_verify_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_verify_image_command_internal(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, int verify) { u8 *buffer; u32 buf_cnt; @@ -2208,55 +2241,61 @@ int handle_verify_image_command(struct command_context_s *cmd_ctx, char *cmd, ch break; } - /* calculate checksum of image */ - 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 (verify) { - free(buffer); - break; - } + /* calculate checksum of image */ + image_calculate_checksum( buffer, buf_cnt, &checksum ); - if( checksum != mem_checksum ) - { - /* failed crc checksum, fall back to a binary compare */ - u8 *data; - - command_print(cmd_ctx, "checksum mismatch - attempting binary compare"); - - data = (u8*)malloc(buf_cnt); - - /* Can we use 32bit word accesses? */ - int size = 1; - int count = buf_cnt; - if ((count % 4) == 0) + retval = target_checksum_memory(target, image.sections[i].base_address, buf_cnt, &mem_checksum); + if( retval != ERROR_OK ) { - size *= 4; - count /= 4; + free(buffer); + break; } - retval = target->type->read_memory(target, image.sections[i].base_address, size, count, data); - if (retval == ERROR_OK) + + if( checksum != mem_checksum ) { - int t; - for (t = 0; t < buf_cnt; t++) + /* failed crc checksum, fall back to a binary compare */ + u8 *data; + + command_print(cmd_ctx, "checksum mismatch - attempting binary compare"); + + data = (u8*)malloc(buf_cnt); + + /* Can we use 32bit word accesses? */ + int size = 1; + int count = buf_cnt; + if ((count % 4) == 0) { - 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]); - free(data); - free(buffer); - retval=ERROR_FAIL; - goto done; - } - if ((t%16384)==0) + size *= 4; + count /= 4; + } + retval = target->type->read_memory(target, image.sections[i].base_address, size, count, data); + if (retval == ERROR_OK) + { + u32 t; + for (t = 0; t < buf_cnt; t++) { - keep_alive(); + 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]); + free(data); + free(buffer); + retval=ERROR_FAIL; + goto done; + } + if ((t%16384)==0) + { + keep_alive(); + } } } - } - free(data); + free(data); + } + } else + { + command_print(cmd_ctx, "address 0x%08x length 0x%08x", image.sections[i].base_address, buf_cnt); } free(buffer); @@ -2281,7 +2320,17 @@ done: return retval; } -int handle_bp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_verify_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +{ + return handle_verify_image_command_internal(cmd_ctx, cmd, args, argc, 1); +} + +static int handle_test_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +{ + return handle_verify_image_command_internal(cmd_ctx, cmd, args, argc, 0); +} + +static int handle_bp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { int retval; target_t *target = get_current_target(cmd_ctx); @@ -2333,7 +2382,7 @@ int handle_bp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, return ERROR_OK; } -int handle_rbp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_rbp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { target_t *target = get_current_target(cmd_ctx); @@ -2343,7 +2392,7 @@ int handle_rbp_command(struct command_context_s *cmd_ctx, char *cmd, char **args return ERROR_OK; } -int handle_wp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_wp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { target_t *target = get_current_target(cmd_ctx); int retval; @@ -2405,7 +2454,7 @@ int handle_wp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, return ERROR_OK; } -int handle_rwp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_rwp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { target_t *target = get_current_target(cmd_ctx); @@ -2415,7 +2464,7 @@ int handle_rwp_command(struct command_context_s *cmd_ctx, char *cmd, char **args return ERROR_OK; } -int handle_virt2phys_command(command_context_t *cmd_ctx, char *cmd, char **args, int argc) +static int handle_virt2phys_command(command_context_t *cmd_ctx, char *cmd, char **args, int argc) { int retval; target_t *target = get_current_target(cmd_ctx); @@ -2442,36 +2491,44 @@ int handle_virt2phys_command(command_context_t *cmd_ctx, char *cmd, char **args, return retval; } +static void writeData(FILE *f, const void *data, size_t len) +{ + size_t written = fwrite(data, len, 1, f); + if (written != len) + LOG_ERROR("failed to write %zu bytes: %s", len, strerror(errno)); +} + static void writeLong(FILE *f, int l) { int i; for (i=0; i<4; i++) { char c=(l>>(i*8))&0xff; - fwrite(&c, 1, 1, f); + writeData(f, &c, 1); } } static void writeString(FILE *f, char *s) { - fwrite(s, 1, strlen(s), f); + writeData(f, s, strlen(s)); } /* Dump a gmon.out histogram file. */ -static void writeGmon(u32 *samples, int sampleNum, char *filename) +static void writeGmon(u32 *samples, u32 sampleNum, char *filename) { - int i; + u32 i; FILE *f=fopen(filename, "w"); if (f==NULL) return; - fwrite("gmon", 1, 4, f); + writeString(f, "gmon"); writeLong(f, 0x00000001); /* Version */ writeLong(f, 0); /* padding */ writeLong(f, 0); /* padding */ writeLong(f, 0); /* padding */ - fwrite("", 1, 1, f); /* GMON_TAG_TIME_HIST */ + u8 zero = 0; /* GMON_TAG_TIME_HIST */ + writeData(f, &zero, 1); /* figure out bucket size */ u32 min=samples[0]; @@ -2490,8 +2547,8 @@ static void writeGmon(u32 *samples, int sampleNum, char *filename) int addressSpace=(max-min+1); - static int const maxBuckets=256*1024; /* maximum buckets. */ - int length=addressSpace; + static const u32 maxBuckets = 256 * 1024; /* maximum buckets. */ + u32 length = addressSpace; if (length > maxBuckets) { length=maxBuckets; @@ -2520,9 +2577,7 @@ static void writeGmon(u32 *samples, int sampleNum, char *filename) writeLong(f, 64000000); /* 64MHz */ writeString(f, "seconds"); for (i=0; i<(15-strlen("seconds")); i++) - { - fwrite("", 1, 1, f); /* padding */ - } + writeData(f, &zero, 1); writeString(f, "s"); /*append binary memory gmon.out profile_hist_data (profile_hist_data + profile_hist_hdr.hist_size) */ @@ -2542,7 +2597,7 @@ static void writeGmon(u32 *samples, int sampleNum, char *filename) data[i*2+1]=(val>>8)&0xff; } free(buckets); - fwrite(data, 1, length*2, f); + writeData(f, data, length * 2); free(data); } else { @@ -2553,7 +2608,7 @@ static void writeGmon(u32 *samples, int sampleNum, char *filename) } /* profiling samples the CPU PC as quickly as OpenOCD is able, which will be used as a random sampling of PC */ -int handle_profile_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_profile_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { target_t *target = get_current_target(cmd_ctx); struct timeval timeout, now; @@ -2698,7 +2753,8 @@ static int target_mem2array(Jim_Interp *interp, target_t *target, int argc, Jim_ u32 v; const char *varname; u8 buffer[4096]; - int i, n, e, retval; + int n, e, retval; + u32 i; /* argv[1] = name of array to receive the data * argv[2] = desired width @@ -2879,7 +2935,8 @@ static int target_array2mem(Jim_Interp *interp, target_t *target, int argc, Jim_ u32 v; const char *varname; u8 buffer[4096]; - int i, n, e, retval; + int n, e, retval; + u32 i; /* argv[1] = name of array to get the data * argv[2] = desired width @@ -3151,7 +3208,7 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target ) teap = target->event_action; /* replace existing? */ while( teap ){ - if( teap->event == n->value ){ + if( teap->event == (enum target_event)n->value ){ break; } teap = teap->next; @@ -3333,6 +3390,8 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target ) break; } } /* while( goi->argc ) */ + + /* done - we return */ return JIM_OK; } @@ -3831,6 +3890,13 @@ static int target_create( Jim_GetOptInfo *goi ) /* 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 ); @@ -3845,7 +3911,7 @@ static int target_create( Jim_GetOptInfo *goi ) /* 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 ); @@ -3901,7 +3967,7 @@ static int jim_target( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) }; LOG_DEBUG("Target command params:"); - LOG_DEBUG(Jim_Debug_ArgvString( interp, argc, argv) ); + LOG_DEBUG("%s", Jim_Debug_ArgvString(interp, argc, argv)); cmd_ctx = Jim_GetAssocData( interp, "context" ); @@ -3993,3 +4059,197 @@ static int jim_target( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) 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 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_addressmax_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; +} + +static 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; + int retval=ERROR_OK; + for (i=0; i