- 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
This commit is contained in:
drath
2007-08-14 09:48:54 +00:00
parent abbd2b62ad
commit 29000b204d
14 changed files with 652 additions and 228 deletions

View File

@@ -68,9 +68,13 @@ AC_ARG_ENABLE(gw16012,
AS_HELP_STRING([--enable-gw16012], [Enable building support for the Gateworks GW16012 JTAG Programmer]),
[build_gw16012=$enableval], [build_gw16012=no])
AC_ARG_ENABLE(presto,
AS_HELP_STRING([--enable-presto], [Enable building support for ASIX Presto Programmer]),
[build_presto=$enableval], [build_presto=no])
AC_ARG_ENABLE(presto_libftdi,
AS_HELP_STRING([--enable-presto_libftdi], [Enable building support for ASIX Presto Programmer using the libftdi driver]),
[build_presto_libftdi=$enableval], [build_presto_libftdi=no])
AC_ARG_ENABLE(presto_ftd2xx,
AS_HELP_STRING([--enable-presto_ftd2xx], [Enable building support for ASIX Presto Programmer using the FTD2XX driver]),
[build_presto_ftd2xx=$enableval], [build_presto_ftd2xx=no])
AC_ARG_ENABLE(usbprog,
AS_HELP_STRING([--enable-usbprog], [Enable building support for the usbprog JTAG Programmer]),
@@ -185,11 +189,18 @@ else
AC_DEFINE(BUILD_GW16012, 0, [0 if you don't want the Gateworks GW16012 driver.])
fi
if test $build_presto = yes; then
if test $build_presto_libftdi = yes; then
build_bitq=yes
AC_DEFINE(BUILD_PRESTO, 1, [1 if you want the ASIX PRESTO driver.])
AC_DEFINE(BUILD_PRESTO_LIBFTDI, 1, [1 if you want the ASIX PRESTO driver using libftdi.])
else
AC_DEFINE(BUILD_PRESTO, 0, [0 if you don't want the ASIX PRESTO driver.])
AC_DEFINE(BUILD_PRESTO_LIBFTDI, 0, [0 if you don't want the ASIX PRESTO driver using libftdi.])
fi
if test $build_presto_ftd2xx = yes; then
build_bitq=yes
AC_DEFINE(BUILD_PRESTO_FTD2XX, 1, [1 if you want the ASIX PRESTO driver using FTD2XX.])
else
AC_DEFINE(BUILD_PRESTO_FTD2XX, 0, [0 if you don't want the ASIX PRESTO driver using FTD2XX.])
fi
if test $build_bitq = yes; then
@@ -222,7 +233,8 @@ AM_CONDITIONAL(FT2232_LIBFTDI, test $build_ft2232_libftdi = yes)
AM_CONDITIONAL(FT2232_FTD2XX, test $build_ft2232_ftd2xx = yes)
AM_CONDITIONAL(AMTJTAGACCEL, test $build_amtjtagaccel = yes)
AM_CONDITIONAL(GW16012, test $build_gw16012 = yes)
AM_CONDITIONAL(PRESTO, test $build_presto = yes)
AM_CONDITIONAL(PRESTO_LIBFTDI, test $build_presto_libftdi = yes)
AM_CONDITIONAL(PRESTO_FTD2XX, test $build_presto_ftd2xx = yes)
AM_CONDITIONAL(USBPROG, test $build_usbprog = yes)
AM_CONDITIONAL(OOCD_TRACE, test $build_oocd_trace = yes)
AM_CONDITIONAL(IS_CYGWIN, test $is_cygwin = yes)

View File

@@ -19,6 +19,9 @@ endif
if FT2232_LIBFTDI
FTDI2232LIB = -lftdi
else
if PRESTO_LIBFTDI
FTDI2232LIB = -lftdi
endif
FTDI2232LIB =
endif
@@ -41,7 +44,7 @@ endif
if FT2232_FTD2XX
FTD2XXLIB = $(FTD2XXLDADD)
else
if PRESTO
if PRESTO_FTD2XX
FTD2XXLIB = $(FTD2XXLDADD)
else
FTD2XXLIB =

View File

@@ -326,7 +326,15 @@ int at91sam7_read_part_info(struct flash_bank_s *bank)
at91sam7_info->cidr_version = cidr&0x001F;
bank->size = NVPSIZ[at91sam7_info->cidr_nvpsiz];
at91sam7_info->target_name = "Unknown";
/* Support just for bulk erase of the whole device */
bank->num_sectors = 1;
bank->sectors = malloc(sizeof(flash_sector_t));
bank->sectors[0].offset = 0;
bank->sectors[0].size = bank->size;
bank->sectors[0].is_erased = -1;
bank->sectors[0].is_protected = -1;
DEBUG("nvptyp: 0x%3.3x, arch: 0x%4.4x", at91sam7_info->cidr_nvptyp, at91sam7_info->cidr_arch );
/* Read main and master clock freqency register */
@@ -565,22 +573,27 @@ int at91sam7_erase(struct flash_bank_s *bank, int first, int last)
return ERROR_FLASH_OPERATION_FAILED;
}
if ((first < 0) || (last < first) || (last >= at91sam7_info->num_lockbits))
if ((first < 0) || (last < first) || (last >= bank->num_sectors))
{
return ERROR_FLASH_SECTOR_INVALID;
if ((first == 0) && (last == (at91sam7_info->num_lockbits-1)))
{
WARNING("Sector numbers based on lockbit count, probably a deprecated script");
last = bank->num_sectors-1;
}
else return ERROR_FLASH_SECTOR_INVALID;
}
if ((first != 0) || (last != (bank->num_sectors-1)))
{
WARNING("Can only erase the whole flash area, pages are autoerased on write");
return ERROR_FLASH_OPERATION_FAILED;
}
/* Configure the flash controller timing */
at91sam7_read_clock_info(bank);
at91sam7_set_flash_mode(bank,FMR_TIMING_FLASH);
at91sam7_set_flash_mode(bank,FMR_TIMING_FLASH);
if ((first == 0) && (last == (at91sam7_info->num_lockbits-1)))
{
return at91sam7_flash_command(bank, EA, 0);
}
WARNING("Can only erase the whole flash area, pages are autoerased on write");
return ERROR_FLASH_OPERATION_FAILED;
return at91sam7_flash_command(bank, EA, 0);
}
int at91sam7_protect(struct flash_bank_s *bank, int set, int first, int last)

View File

@@ -738,24 +738,36 @@ int flash_erase(target_t *target, u32 addr, u32 length)
int flash_write(target_t *target, image_t *image, u32 *image_size, char **error_str, u32 *failed)
{
int last_section;
int section;
int next_section;
int retval;
*image_size = 0;
/* for each section in the image */
for (section = 0; section < image->num_sections; section++)
last_section = 0;
section = 0;
while (section < image->num_sections)
{
u32 offset = 0;
u32 address = image->sections[section].base_address;
u32 size = image->sections[section].size;
failed[section] = 0;
/* collect consecutive sections */
next_section = section + 1;
while ((next_section < image->num_sections)
&& (image->sections[next_section].base_address == (address + size)))
{
size += image->sections[next_section].size;
next_section++;
}
while (size != 0)
{
flash_bank_t *c;
u32 thisrun_size = size;
u32 buffer_size;
u32 size_read;
u8 *buffer;
@@ -767,23 +779,50 @@ int flash_write(target_t *target, image_t *image, u32 *image_size, char **error_
break;
}
/* check whether it fits, split into multiple runs if not */
/* check whether cumulated sections fit the bank, split into multiple runs if not */
if ((address + size) > (c->base + c->size))
thisrun_size = c->base + c->size - address;
buffer = malloc(thisrun_size);
if (((retval = image_read_section(image, section, offset, size, buffer, &size_read)) != ERROR_OK)
|| (thisrun_size != size_read))
buffer_size = 0;
while (buffer_size < thisrun_size)
{
*error_str = malloc(FLASH_MAX_ERROR_STR);
snprintf(*error_str, FLASH_MAX_ERROR_STR, "error reading from image");
return ERROR_IMAGE_TEMPORARILY_UNAVAILABLE;
u32 thissection_size = image->sections[section].size - offset;
if ((retval = image_read_section(image, section, offset,
MIN(thisrun_size, thissection_size),
buffer + buffer_size, &size_read)) != ERROR_OK)
{
*error_str = malloc(FLASH_MAX_ERROR_STR);
snprintf(*error_str, FLASH_MAX_ERROR_STR, "error reading from image");
return ERROR_IMAGE_TEMPORARILY_UNAVAILABLE;
}
/* see if we're done with the current section */
if (thissection_size < thisrun_size)
{
/* start with the next section */
offset = 0;
failed[section] = 0;
section++;
}
else
{
/* continue inside the current section */
offset += size_read;
}
buffer_size += size_read;
}
if ((retval = c->driver->write(c, buffer, address - c->base, thisrun_size)) != ERROR_OK)
{
/* mark the current section as failed */
failed[section] = 1;
int i;
/* mark sections as failed */
for (i = last_section; i <= section; i++)
failed[i] = 1;
*error_str = malloc(FLASH_MAX_ERROR_STR);
switch (retval)
{
@@ -817,12 +856,11 @@ int flash_write(target_t *target, image_t *image, u32 *image_size, char **error_
free(buffer);
offset += thisrun_size;
address += thisrun_size;
size -= thisrun_size;
*image_size += thisrun_size;
last_section = section;
}
*image_size += image->sections[section].size;
}
return ERROR_OK;

View File

@@ -256,7 +256,7 @@ int handle_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, cha
int nand_register_commands(struct command_context_s *cmd_ctx)
{
nand_cmd = register_command(cmd_ctx, NULL, "nand", NULL, COMMAND_ANY, NULL);
nand_cmd = register_command(cmd_ctx, NULL, "nand", NULL, COMMAND_ANY, "NAND specific commands");
register_command(cmd_ctx, nand_cmd, "device", handle_nand_device_command, COMMAND_CONFIG, NULL);

View File

@@ -65,9 +65,12 @@ else
BITQFILES =
endif
if PRESTO
if PRESTO_LIBFTDI
PRESTOFILES = presto.c
else
if PRESTO_FTD2XX
PRESTOFILES = presto.c
endif
PRESTOFILES =
endif

View File

@@ -162,7 +162,7 @@ jtag_event_callback_t *jtag_event_callbacks;
extern jtag_interface_t gw16012_interface;
#endif
#if BUILD_PRESTO == 1
#if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
extern jtag_interface_t presto_interface;
#endif
@@ -192,7 +192,7 @@ jtag_interface_t *jtag_interfaces[] = {
#if BUILD_GW16012 == 1
&gw16012_interface,
#endif
#if BUILD_PRESTO == 1
#if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
&presto_interface,
#endif
#if BUILD_USBPROG == 1

File diff suppressed because it is too large Load Diff

View File

@@ -18,7 +18,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#define OPENOCD_VERSION "Open On-Chip Debugger (2007-08-10 22:30 CEST)"
#define OPENOCD_VERSION "Open On-Chip Debugger (2007-08-14 11:45 CEST)"
#ifdef HAVE_CONFIG_H
#include "config.h"

View File

@@ -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;
}

View File

@@ -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 <file> <address> <size>");
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;

View File

@@ -27,6 +27,7 @@
#include "target_request.h"
#include "binarybuffer.h"
#include "command.h"
#include "trace.h"
#include <stdlib.h>
#include <string.h>
@@ -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;

View File

@@ -25,8 +25,76 @@
#include "log.h"
#include "trace.h"
#include "target.h"
#include "command.h"
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
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;
for (i = 0; i < trace->trace_history_size; i++)
if (trace->trace_history_overflowed)
{
if (trace->trace_history[i] < trace->num_trace_points)
first = trace->trace_history_pos;
last = trace->trace_history_pos - 1;
}
for (i = first; (i % trace->trace_history_size) != last; i++)
{
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;
}

View File

@@ -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 */