From 29000b204d039bc1123027eba755329ab36a3dde Mon Sep 17 00:00:00 2001 From: drath Date: Tue, 14 Aug 2007 09:48:54 +0000 Subject: - reworked presto.c to allow use of either FTD2XX or libftdi (libftdi not functional yet). Configure option changed from --enable-presto to --enable-presto_ftd2xx and --enable-presto_libftdi - completed trace point support for use with ARM7/9 DCC - completed debug message output with support for HEX dumps (1, 2 or 4 byte quantities) - fixed bug in delete_debug_msg_receiver (thanks to Pavel Chromy) - fixed bug in image_add_section (thanks to Pavel Chromy) - at91sam7 sector erase reworked (thanks to Pavel Chromy) - merge consecutive sections during flash image write to work around possible section alignment issues with LPC2000 targets git-svn-id: svn://svn.berlios.de/openocd/trunk@194 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- src/target/image.c | 33 ++++++++------ src/target/target.c | 6 ++- src/target/target_request.c | 64 ++++++++++++++++---------- src/target/trace.c | 109 ++++++++++++++++++++++++++++++++++++++++++-- src/target/trace.h | 9 +++- 5 files changed, 175 insertions(+), 46 deletions(-) (limited to 'src/target') diff --git a/src/target/image.c b/src/target/image.c index c85f387d..0c203f6b 100644 --- a/src/target/image.c +++ b/src/target/image.c @@ -878,30 +878,37 @@ int image_read_section(image_t *image, int section, u32 offset, u32 size, u8 *bu int image_add_section(image_t *image, u32 base, u32 size, int flags, u8 *data) { + image_section_t *section; + /* only image builder supports adding sections */ if (image->type != IMAGE_BUILDER) return ERROR_INVALID_ARGUMENTS; - /* see if it's enough to extend an existing section */ - if (((image->sections[image->num_sections - 1].base_address + image->sections[image->num_sections - 1].size) == base) - && (image->sections[image->num_sections - 1].flags == flags)) + /* see if there's a previous section */ + if (image->num_sections) { - u32 old_size = image->sections[image->num_sections - 1].size; - image->sections[image->num_sections - 1].size += size; - image->sections[image->num_sections - 1].private = realloc(image->sections[image->num_sections - 1].private, image->sections[image->num_sections - 1].size); - memcpy((u8*)image->sections[image->num_sections - 1].private + old_size, data, size); + section = &image->sections[image->num_sections - 1]; - return ERROR_OK; + /* see if it's enough to extend the last section, + * adding data to previous sections or merging is not supported */ + if (((section->base_address + section->size) == base) && (section->flags == flags)) + { + section->private = realloc(section->private, section->size + size); + memcpy((u8*)section->private + section->size, data, size); + section->size += size; + return ERROR_OK; + } } /* allocate new section */ image->num_sections++; image->sections = realloc(image->sections, sizeof(image_section_t) * image->num_sections); - image->sections[image->num_sections - 1].base_address = base; - image->sections[image->num_sections - 1].size = size; - image->sections[image->num_sections - 1].flags = flags; - image->sections[image->num_sections - 1].private = malloc(sizeof(u8) * size); - memcpy((u8*)image->sections[image->num_sections - 1].private, data, size); + section = &image->sections[image->num_sections - 1]; + section->base_address = base; + section->size = size; + section->flags = flags; + section->private = malloc(sizeof(u8) * size); + memcpy((u8*)section->private, data, size); return ERROR_OK; } diff --git a/src/target/target.c b/src/target/target.c index 905b1074..de71b140 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -885,6 +885,7 @@ int target_register_user_commands(struct command_context_s *cmd_ctx) register_command(cmd_ctx, NULL, "dump_binary", handle_dump_image_command, COMMAND_EXEC, "[DEPRECATED] dump_binary
"); target_request_register_commands(cmd_ctx); + trace_register_commands(cmd_ctx); return ERROR_OK; } @@ -1006,10 +1007,13 @@ int handle_target_command(struct command_context_s *cmd_ctx, char *cmd, char **a /* initialize trace information */ (*last_target_p)->trace_info = malloc(sizeof(trace_t)); (*last_target_p)->trace_info->num_trace_points = 0; + (*last_target_p)->trace_info->trace_points_size = 0; (*last_target_p)->trace_info->trace_points = NULL; (*last_target_p)->trace_info->trace_history_size = 0; (*last_target_p)->trace_info->trace_history = NULL; - + (*last_target_p)->trace_info->trace_history_pos = 0; + (*last_target_p)->trace_info->trace_history_overflowed = 0; + (*last_target_p)->type->target_command(cmd_ctx, cmd, args, argc, *last_target_p); found = 1; diff --git a/src/target/target_request.c b/src/target/target_request.c index e8409020..9dc58607 100644 --- a/src/target/target_request.c +++ b/src/target/target_request.c @@ -27,6 +27,7 @@ #include "target_request.h" #include "binarybuffer.h" #include "command.h" +#include "trace.h" #include #include @@ -54,35 +55,46 @@ int target_asciimsg(target_t *target, u32 length) int target_hexmsg(target_t *target, int size, u32 length) { - if (size == 1) - { - u8 *data = malloc(CEIL(length * sizeof(u8), 4) * 4); - - target->type->target_request_data(target, CEIL(length * sizeof(u8), 4), (u8*)data); - - free(data); - } - else if (size == 2) - { - u16 *data = malloc(CEIL(length * sizeof(u16), 4) * 4); - - target->type->target_request_data(target, CEIL(length * sizeof(u16), 4), (u8*)data); + u8 *data = malloc(CEIL(length * size, 4) * 4); + char line[128]; + int line_len; + debug_msg_receiver_t *c = target->dbgmsg; + int i; + + DEBUG("size: %i, length: %i", size, length); - free(data); - } - else if (size == 4) - { - u32 *data = malloc(CEIL(length * sizeof(u32), 4) * 4); - - target->type->target_request_data(target, CEIL(length * sizeof(u32), 4), (u8*)data); + target->type->target_request_data(target, CEIL(length * size, 4), (u8*)data); - free(data); - } - else + line_len = 0; + for (i = 0; i < length; i++) { - ERROR("invalid debug message type"); + switch (size) + { + case 4: + line_len += snprintf(line + line_len, 128 - line_len, "%8.8x ", le_to_h_u32(data + (4*i))); + break; + case 2: + line_len += snprintf(line + line_len, 128 - line_len, "%4.4x ", le_to_h_u16(data + (2*i))); + break; + case 1: + line_len += snprintf(line + line_len, 128 - line_len, "%2.2x ", data[i]); + break; + } + + if ((i%8 == 7) || (i == length - 1)) + { + while (c) + { + command_print(c->cmd_ctx, "%s", line); + c = c->next; + } + c = target->dbgmsg; + line_len = 0; + } } + free(data); + return ERROR_OK; } @@ -96,7 +108,7 @@ int target_request(target_t *target, u32 request) switch (target_req_cmd) { case TARGET_REQ_TRACEMSG: - DEBUG("tracepoint: %i", (request & 0xffffff00) >> 8); + trace_point(target, (request & 0xffffff00) >> 8); break; case TARGET_REQ_DEBUGMSG: if (((request & 0xff00) >> 8) == 0) @@ -196,6 +208,8 @@ int delete_debug_msg_receiver(struct command_context_s *cmd_ctx, target_t *targe do { + p = &target->dbgmsg; + c = *p; while (c) { debug_msg_receiver_t *next = c->next; diff --git a/src/target/trace.c b/src/target/trace.c index 3eec3d83..536e34a5 100644 --- a/src/target/trace.c +++ b/src/target/trace.c @@ -25,8 +25,76 @@ #include "log.h" #include "trace.h" #include "target.h" +#include "command.h" #include +#include +#include + +int trace_point(target_t *target, int number) +{ + trace_t *trace = target->trace_info; + + DEBUG("tracepoint: %i", number); + + if (number < trace->num_trace_points) + trace->trace_points[number].hit_counter++; + + if (trace->trace_history_size) + { + trace->trace_history[trace->trace_history_pos++] = number; + if (trace->trace_history_pos == trace->trace_history_size) + { + trace->trace_history_pos = 0; + trace->trace_history_overflowed = 1; + } + } + + return ERROR_OK; +} + +int handle_trace_point_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +{ + target_t *target = get_current_target(cmd_ctx); + trace_t *trace = target->trace_info; + + if (argc == 0) + { + int i; + + for (i = 0; i < trace->num_trace_points; i++) + { + command_print(cmd_ctx, "trace point 0x%8.8x (%"PRIi64" times hit)", + trace->trace_points[i].address, + trace->trace_points[i].hit_counter); + } + + return ERROR_OK; + } + + if (!strcmp(args[0], "clear")) + { + if (trace->trace_points) + free(trace->trace_points); + trace->num_trace_points = 0; + trace->trace_points_size = 0; + + return ERROR_OK; + } + + /* resize array if necessary */ + if (!trace->trace_points || (trace->trace_points_size == trace->num_trace_points)) + { + trace->trace_points = realloc(trace->trace_points, sizeof(trace_point_t) * (trace->trace_points_size + 32)); + trace->trace_points_size += 32; + } + + trace->trace_points[trace->num_trace_points].address = strtoul(args[0], NULL, 0); + trace->trace_points[trace->num_trace_points].hit_counter = 0; + trace->num_trace_points++; + + return ERROR_OK; +} int handle_trace_history_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { @@ -35,6 +103,15 @@ int handle_trace_history_command(struct command_context_s *cmd_ctx, char *cmd, c if (argc > 0) { + trace->trace_history_pos = 0; + trace->trace_history_overflowed = 0; + + if (!strcmp(args[0], "clear")) + { + /* clearing is implicit, we've just reset position anyway */ + return ERROR_OK; + } + if (trace->trace_history) free(trace->trace_history); @@ -46,24 +123,46 @@ int handle_trace_history_command(struct command_context_s *cmd_ctx, char *cmd, c else { int i; + int first = 0; + int last = trace->trace_history_pos; + + if (trace->trace_history_overflowed) + { + first = trace->trace_history_pos; + last = trace->trace_history_pos - 1; + } - for (i = 0; i < trace->trace_history_size; i++) + for (i = first; (i % trace->trace_history_size) != last; i++) { - if (trace->trace_history[i] < trace->num_trace_points) + if (trace->trace_history[i % trace->trace_history_size] < trace->num_trace_points) { u32 address; - address = trace->trace_points[trace->trace_history[i]].address; + address = trace->trace_points[trace->trace_history[i % trace->trace_history_size]].address; command_print(cmd_ctx, "trace point %i: 0x%8.8x", - trace->trace_history[i], + trace->trace_history[i % trace->trace_history_size], address); } else { - command_print(cmd_ctx, "trace point %i: -not defined-", trace->trace_history[i]); + command_print(cmd_ctx, "trace point %i: -not defined-", trace->trace_history[i % trace->trace_history_size]); } } } return ERROR_OK; } + +int trace_register_commands(struct command_context_s *cmd_ctx) +{ + command_t *trace_cmd = + register_command(cmd_ctx, NULL, "trace", NULL, COMMAND_ANY, "trace commands"); + + register_command(cmd_ctx, trace_cmd, "history", handle_trace_history_command, + COMMAND_EXEC, "display trace history, ['clear'] history or set [size]"); + + register_command(cmd_ctx, trace_cmd, "point", handle_trace_point_command, + COMMAND_EXEC, "display trace points, ['clear'] list of trace points, or add new tracepoint at [address]"); + + return ERROR_OK; +} diff --git a/src/target/trace.h b/src/target/trace.h index 7267cd38..0279d51f 100644 --- a/src/target/trace.h +++ b/src/target/trace.h @@ -31,9 +31,12 @@ typedef struct trace_point_s typedef struct trace_s { int num_trace_points; + int trace_points_size; trace_point_t *trace_points; int trace_history_size; u32 *trace_history; + int trace_history_pos; + int trace_history_overflowed; } trace_t; typedef enum trace_status @@ -45,7 +48,9 @@ typedef enum trace_status TRACE_OVERFLOWED = 0x8, } trace_status_t; -#define ERROR_TRACE_IMAGE_UNAVAILABLE -(1500) -#define ERROR_TRACE_INSTRUCTION_UNAVAILABLE -(1500) +extern int trace_point(struct target_s *target, int number); + +#define ERROR_TRACE_IMAGE_UNAVAILABLE -(1500) +#define ERROR_TRACE_INSTRUCTION_UNAVAILABLE -(1501) #endif /* TRACE_H */ -- cgit v1.2.3