Commit 20e4e77c authored by drath's avatar drath
Browse files

- renamed M5960 USB JTAG to "flyswatter"

- make ep93xx and at91rm9200 bitbang JTAG interfaces dependant on ARM host (thanks to Vincent Palatin)
- various whitespace fixes
- removed various warnings
- add support for Debian GNU/kFreeBSD (thanks to Uwe Hermann)
- fix OpenOCD compilation for various platforms (thanks to Uwe Hermann and Vincent Palatin)
- switched order of JTAG chain examination and validation (examine first, then multiple validation tries even if examination failed)
- added target_request subsystem to handle requests from the target (debug messages and tracepoints implemented, future enhancements might include
semihosting, all ARM7/9 only for now)
- added support for GDB vFlashXXX packets (thanks to Pavel Chromy)
- added support for receiving data via ARM7/9 DCC
- reworked flash writing. the 'flash write' command is now deprecated and replaced by 'flash write_binary' (old syntax and behaviour) and 'flash
write_image' (write image files (bin, hex, elf, s19) to a target).
- added support for AMD/ST/SST 29F400B non-cfi flashes



git-svn-id: svn://svn.berlios.de/openocd/trunk@190 b42882b7-edfa-0310-969c-e2dbd0fdcd60
parent 835e6440
......@@ -69,7 +69,7 @@ features and additional RS232 UART.
The Signalyzer offers support for a wide variety of target voltages from 1.2V to
5.5V. A second connector provides access to a TTL level UART.
* American Microsystem M5960 USB JTAG programmer.
* TinCanTools 'Flyswatter' USB JTAG programmer.
* Turtelizer 2: http://www.ethernut.de/en/hardware/turtelizer/index.html
Another USB JTAG programmer, with freely available schematics. It supports
......
......@@ -47,13 +47,22 @@ AC_ARG_ENABLE(amtjtagaccel,
AS_HELP_STRING([--enable-amtjtagaccel], [Enable building the Amontec JTAG-Accelerator driver]),
[build_amtjtagaccel=$enableval], [build_amtjtagaccel=no])
AC_ARG_ENABLE(ep93xx,
AS_HELP_STRING([--enable-ep93xx], [Enable building support for EP93xx based SBCs]),
[build_ep93xx=$enableval], [build_ep93xx=no])
AC_ARG_ENABLE(at91rm9200,
AS_HELP_STRING([--enable-at91rm9200], [Enable building support for AT91RM9200 based SBCs]),
[build_at91rm9200=$enableval], [build_at91rm9200=no])
case "${host_cpu}" in
arm*)
AC_ARG_ENABLE(ep93xx,
AS_HELP_STRING([--enable-ep93xx], [Enable building support for EP93xx based SBCs]),
[build_ep93xx=$enableval], [build_ep93xx=no])
AC_ARG_ENABLE(at91rm9200,
AS_HELP_STRING([--enable-at91rm9200], [Enable building support for AT91RM9200 based SBCs]),
[build_at91rm9200=$enableval], [build_at91rm9200=no])
;;
*)
build_ep93xx=no
build_at91rm9200=no
;;
esac
AC_ARG_ENABLE(gw16012,
AS_HELP_STRING([--enable-gw16012], [Enable building support for the Gateworks GW16012 JTAG Programmer]),
......
......@@ -32,7 +32,7 @@ OpenOCD supports various different types of JTAG interfaces/programmers:
* Amontec JTAGkey\-Tiny
* Olimex ARM\-USB\-OCD
* eVerve Signalyzer
* American Microsystem M5960
* TinCanTools 'Flyswatter'
* Turtelizer 2
* Hitex STR9-comSTICK
* Luminary Micro evb_lm3s811
......
......@@ -131,8 +131,7 @@ int at91sam7_register_commands(struct command_context_s *cmd_ctx)
u32 at91sam7_get_flash_status(flash_bank_t *bank)
{
at91sam7_flash_bank_t *at91sam7_info = bank->driver_priv;
target_t *target = at91sam7_info->target;
target_t *target = bank->target;
u32 fsr;
target_read_u32(target, MC_FSR, &fsr);
......@@ -144,7 +143,7 @@ u32 at91sam7_get_flash_status(flash_bank_t *bank)
void at91sam7_read_clock_info(flash_bank_t *bank)
{
at91sam7_flash_bank_t *at91sam7_info = bank->driver_priv;
target_t *target = at91sam7_info->target;
target_t *target = bank->target;
u32 mckr, mcfr, pllr;
unsigned long tmp = 0, mainfreq;
......@@ -203,7 +202,7 @@ void at91sam7_set_flash_mode(flash_bank_t *bank,int mode)
{
u32 fmr, fmcn = 0, fws = 0;
at91sam7_flash_bank_t *at91sam7_info = bank->driver_priv;
target_t *target = at91sam7_info->target;
target_t *target = bank->target;
if (mode && (mode != at91sam7_info->flashmode))
{
......@@ -272,7 +271,7 @@ int at91sam7_flash_command(struct flash_bank_s *bank,u8 cmd,u16 pagen)
{
u32 fcr;
at91sam7_flash_bank_t *at91sam7_info = bank->driver_priv;
target_t *target = at91sam7_info->target;
target_t *target = bank->target;
fcr = (0x5A<<24) | (pagen<<8) | cmd;
target_write_u32(target, MC_FCR, fcr);
......@@ -299,10 +298,10 @@ int at91sam7_flash_command(struct flash_bank_s *bank,u8 cmd,u16 pagen)
int at91sam7_read_part_info(struct flash_bank_s *bank)
{
at91sam7_flash_bank_t *at91sam7_info = bank->driver_priv;
target_t *target = at91sam7_info->target;
target_t *target = bank->target;
u32 cidr, status;
if (at91sam7_info->target->state != TARGET_HALTED)
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
......@@ -525,6 +524,8 @@ int at91sam7_protect_check(struct flash_bank_s *bank)
return ERROR_OK;
}
/* flash_bank at91sam7 0 0 0 0 <target#>
*/
int at91sam7_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
{
at91sam7_flash_bank_t *at91sam7_info;
......@@ -538,13 +539,6 @@ int at91sam7_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, ch
at91sam7_info = malloc(sizeof(at91sam7_flash_bank_t));
bank->driver_priv = at91sam7_info;
at91sam7_info->target = get_target_by_num(strtoul(args[5], NULL, 0));
if (!at91sam7_info->target)
{
ERROR("no target '%s' configured", args[5]);
exit(-1);
}
/* part wasn't probed for info yet */
at91sam7_info->cidr = 0;
......@@ -555,7 +549,7 @@ int at91sam7_erase(struct flash_bank_s *bank, int first, int last)
{
at91sam7_flash_bank_t *at91sam7_info = bank->driver_priv;
if (at91sam7_info->target->state != TARGET_HALTED)
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
......@@ -596,7 +590,7 @@ int at91sam7_protect(struct flash_bank_s *bank, int set, int first, int last)
at91sam7_flash_bank_t *at91sam7_info = bank->driver_priv;
if (at91sam7_info->target->state != TARGET_HALTED)
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
......@@ -644,11 +638,11 @@ int at91sam7_protect(struct flash_bank_s *bank, int set, int first, int last)
int at91sam7_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
{
at91sam7_flash_bank_t *at91sam7_info = bank->driver_priv;
target_t *target = at91sam7_info->target;
target_t *target = bank->target;
u32 dst_min_alignment, wcount, bytes_remaining = count;
u32 first_page, last_page, pagen, buffer_pos;
if (at91sam7_info->target->state != TARGET_HALTED)
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
......@@ -809,7 +803,7 @@ int at91sam7_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd,
at91sam7_info = bank->driver_priv;
if (at91sam7_info->target->state != TARGET_HALTED)
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
......
......@@ -25,7 +25,6 @@
typedef struct at91sam7_flash_bank_s
{
struct target_s *target;
u32 working_area;
u32 working_area_size;
......
......@@ -84,6 +84,10 @@ cfi_fixup_t cfi_jedec_fixups[] = {
{CFI_MFR_SST, 0x00D5, cfi_fixup_non_cfi, NULL},
{CFI_MFR_SST, 0x00D6, cfi_fixup_non_cfi, NULL},
{CFI_MFR_SST, 0x00D7, cfi_fixup_non_cfi, NULL},
{CFI_MFR_ST, 0x00D5, cfi_fixup_non_cfi, NULL},
{CFI_MFR_ST, 0x00D6, cfi_fixup_non_cfi, NULL},
{CFI_MFR_AMD, 0x2223, cfi_fixup_non_cfi, NULL},
{CFI_MFR_AMD, 0x22ab, cfi_fixup_non_cfi, NULL},
{0, 0, NULL, NULL}
};
......@@ -137,7 +141,6 @@ inline u32 flash_address(flash_bank_t *bank, int sector, u32 offset)
void cfi_command(flash_bank_t *bank, u8 cmd, u8 *cmd_buf)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
int i;
/* clear whole buffer, to ensure bits that exceed the bus_width
......@@ -146,7 +149,7 @@ void cfi_command(flash_bank_t *bank, u8 cmd, u8 *cmd_buf)
for (i = 0; i < CFI_MAX_BUS_WIDTH; i++)
cmd_buf[i] = 0;
if (cfi_info->target->endianness == TARGET_LITTLE_ENDIAN)
if (bank->target->endianness == TARGET_LITTLE_ENDIAN)
{
for (i = bank->bus_width; i > 0; i--)
{
......@@ -168,13 +171,12 @@ void cfi_command(flash_bank_t *bank, u8 cmd, u8 *cmd_buf)
*/
u8 cfi_query_u8(flash_bank_t *bank, int sector, u32 offset)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
target_t *target = cfi_info->target;
target_t *target = bank->target;
u8 data[CFI_MAX_BUS_WIDTH];
target->type->read_memory(target, flash_address(bank, sector, offset), bank->bus_width, 1, data);
if (cfi_info->target->endianness == TARGET_LITTLE_ENDIAN)
if (bank->target->endianness == TARGET_LITTLE_ENDIAN)
return data[0];
else
return data[bank->bus_width - 1];
......@@ -186,14 +188,13 @@ u8 cfi_query_u8(flash_bank_t *bank, int sector, u32 offset)
*/
u8 cfi_get_u8(flash_bank_t *bank, int sector, u32 offset)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
target_t *target = cfi_info->target;
target_t *target = bank->target;
u8 data[CFI_MAX_BUS_WIDTH];
int i;
target->type->read_memory(target, flash_address(bank, sector, offset), bank->bus_width, 1, data);
if (cfi_info->target->endianness == TARGET_LITTLE_ENDIAN)
if (bank->target->endianness == TARGET_LITTLE_ENDIAN)
{
for (i = 0; i < bank->bus_width / bank->chip_width; i++)
data[0] |= data[i];
......@@ -212,13 +213,12 @@ u8 cfi_get_u8(flash_bank_t *bank, int sector, u32 offset)
u16 cfi_query_u16(flash_bank_t *bank, int sector, u32 offset)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
target_t *target = cfi_info->target;
target_t *target = bank->target;
u8 data[CFI_MAX_BUS_WIDTH * 2];
target->type->read_memory(target, flash_address(bank, sector, offset), bank->bus_width, 2, data);
if (cfi_info->target->endianness == TARGET_LITTLE_ENDIAN)
if (bank->target->endianness == TARGET_LITTLE_ENDIAN)
return data[0] | data[bank->bus_width] << 8;
else
return data[bank->bus_width - 1] | data[(2 * bank->bus_width) - 1] << 8;
......@@ -226,13 +226,12 @@ u16 cfi_query_u16(flash_bank_t *bank, int sector, u32 offset)
u32 cfi_query_u32(flash_bank_t *bank, int sector, u32 offset)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
target_t *target = cfi_info->target;
target_t *target = bank->target;
u8 data[CFI_MAX_BUS_WIDTH * 4];
target->type->read_memory(target, flash_address(bank, sector, offset), bank->bus_width, 4, data);
if (cfi_info->target->endianness == TARGET_LITTLE_ENDIAN)
if (bank->target->endianness == TARGET_LITTLE_ENDIAN)
return data[0] | data[bank->bus_width] << 8 | data[bank->bus_width * 2] << 16 | data[bank->bus_width * 3] << 24;
else
return data[bank->bus_width - 1] | data[(2* bank->bus_width) - 1] << 8 |
......@@ -241,8 +240,7 @@ u32 cfi_query_u32(flash_bank_t *bank, int sector, u32 offset)
void cfi_intel_clear_status_register(flash_bank_t *bank)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
target_t *target = cfi_info->target;
target_t *target = bank->target;
u8 command[8];
if (target->state != TARGET_HALTED)
......@@ -334,7 +332,7 @@ int cfi_read_intel_pri_ext(flash_bank_t *bank)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
cfi_intel_pri_ext_t *pri_ext = malloc(sizeof(cfi_intel_pri_ext_t));
target_t *target = cfi_info->target;
target_t *target = bank->target;
u8 command[8];
cfi_info->pri_ext = pri_ext;
......@@ -389,7 +387,7 @@ int cfi_read_spansion_pri_ext(flash_bank_t *bank)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
cfi_spansion_pri_ext_t *pri_ext = malloc(sizeof(cfi_spansion_pri_ext_t));
target_t *target = cfi_info->target;
target_t *target = bank->target;
u8 command[8];
cfi_info->pri_ext = pri_ext;
......@@ -450,7 +448,7 @@ int cfi_read_atmel_pri_ext(flash_bank_t *bank)
cfi_atmel_pri_ext_t atmel_pri_ext;
cfi_flash_bank_t *cfi_info = bank->driver_priv;
cfi_spansion_pri_ext_t *pri_ext = malloc(sizeof(cfi_spansion_pri_ext_t));
target_t *target = cfi_info->target;
target_t *target = bank->target;
u8 command[8];
/* ATMEL devices use the same CFI primary command set (0x2) as AMD/Spansion,
......@@ -619,13 +617,6 @@ int cfi_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **
cfi_info->jedec_probe = 0;
cfi_info->not_cfi = 0;
cfi_info->target = get_target_by_num(strtoul(args[5], NULL, 0));
if (!cfi_info->target)
{
ERROR("no target '%s' configured", args[5]);
exit(-1);
}
for (i = 6; i < argc; i++)
{
if (strcmp(args[i], "x16_as_x8") == 0)
......@@ -649,7 +640,7 @@ int cfi_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **
int cfi_intel_erase(struct flash_bank_s *bank, int first, int last)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
target_t *target = cfi_info->target;
target_t *target = bank->target;
u8 command[8];
int i;
......@@ -685,7 +676,7 @@ int cfi_spansion_erase(struct flash_bank_s *bank, int first, int last)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
cfi_spansion_pri_ext_t *pri_ext = cfi_info->pri_ext;
target_t *target = cfi_info->target;
target_t *target = bank->target;
u8 command[8];
int i;
......@@ -731,7 +722,7 @@ int cfi_erase(struct flash_bank_s *bank, int first, int last)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
if (cfi_info->target->state != TARGET_HALTED)
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
......@@ -765,7 +756,7 @@ int cfi_intel_protect(struct flash_bank_s *bank, int set, int first, int last)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
cfi_intel_pri_ext_t *pri_ext = cfi_info->pri_ext;
target_t *target = cfi_info->target;
target_t *target = bank->target;
u8 command[8];
int retry = 0;
int i;
......@@ -860,7 +851,7 @@ int cfi_protect(struct flash_bank_s *bank, int set, int first, int last)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
if (cfi_info->target->state != TARGET_HALTED)
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
......@@ -889,8 +880,7 @@ int cfi_protect(struct flash_bank_s *bank, int set, int first, int last)
void cfi_add_byte(struct flash_bank_s *bank, u8 *word, u8 byte)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
target_t *target = cfi_info->target;
target_t *target = bank->target;
int i;
......@@ -913,7 +903,7 @@ void cfi_add_byte(struct flash_bank_s *bank, u8 *word, u8 byte)
int cfi_intel_write_block(struct flash_bank_s *bank, u8 *buffer, u32 address, u32 count)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
target_t *target = cfi_info->target;
target_t *target = bank->target;
reg_param_t reg_params[7];
armv4_5_algorithm_t armv4_5_info;
working_area_t *source;
......@@ -1122,7 +1112,7 @@ int cfi_spansion_write_block(struct flash_bank_s *bank, u8 *buffer, u32 address,
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
cfi_spansion_pri_ext_t *pri_ext = cfi_info->pri_ext;
target_t *target = cfi_info->target;
target_t *target = bank->target;
reg_param_t reg_params[10];
armv4_5_algorithm_t armv4_5_info;
working_area_t *source;
......@@ -1383,7 +1373,7 @@ int cfi_spansion_write_block(struct flash_bank_s *bank, u8 *buffer, u32 address,
int cfi_intel_write_word(struct flash_bank_s *bank, u8 *word, u32 address)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
target_t *target = cfi_info->target;
target_t *target = bank->target;
u8 command[8];
cfi_intel_clear_status_register(bank);
......@@ -1408,7 +1398,7 @@ int cfi_spansion_write_word(struct flash_bank_s *bank, u8 *word, u32 address)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
cfi_spansion_pri_ext_t *pri_ext = cfi_info->pri_ext;
target_t *target = cfi_info->target;
target_t *target = bank->target;
u8 command[8];
cfi_command(bank, 0xaa, command);
......@@ -1458,7 +1448,7 @@ int cfi_write_word(struct flash_bank_s *bank, u8 *word, u32 address)
int cfi_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
target_t *target = cfi_info->target;
target_t *target = bank->target;
u32 address = bank->base + offset; /* address of first byte to be programmed */
u32 write_p, copy_p;
int align; /* number of unaligned bytes */
......@@ -1466,7 +1456,7 @@ int cfi_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
int i;
int retval;
if (cfi_info->target->state != TARGET_HALTED)
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
......@@ -1632,7 +1622,7 @@ void cfi_fixup_0002_unlock_addresses(flash_bank_t *bank, void *param)
int cfi_probe(struct flash_bank_s *bank)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
target_t *target = cfi_info->target;
target_t *target = bank->target;
u8 command[8];
int num_sectors = 0;
int i;
......@@ -1855,7 +1845,7 @@ int cfi_probe(struct flash_bank_s *bank)
int cfi_erase_check(struct flash_bank_s *bank)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
target_t *target = cfi_info->target;
target_t *target = bank->target;
int i;
int retval;
......@@ -1967,7 +1957,7 @@ int cfi_intel_protect_check(struct flash_bank_s *bank)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
cfi_intel_pri_ext_t *pri_ext = cfi_info->pri_ext;
target_t *target = cfi_info->target;
target_t *target = bank->target;
u8 command[CFI_MAX_BUS_WIDTH];
int i;
......@@ -1998,7 +1988,7 @@ int cfi_spansion_protect_check(struct flash_bank_s *bank)
{
cfi_flash_bank_t *cfi_info = bank->driver_priv;
cfi_spansion_pri_ext_t *pri_ext = cfi_info->pri_ext;
target_t *target = cfi_info->target;
target_t *target = bank->target;
u8 command[8];
int i;
......
......@@ -25,7 +25,6 @@
typedef struct cfi_flash_bank_s
{
struct target_s *target;
working_area_t *write_algorithm;
working_area_t *erase_check_algorithm;
......
......@@ -25,6 +25,9 @@
#include "command.h"
#include "target.h"
#include "time_support.h"
#include "fileio.h"
#include "image.h"
#include "log.h"
#include <string.h>
#include <unistd.h>
......@@ -32,10 +35,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fileio.h>
#include <image.h>
#include "log.h"
#include <inttypes.h>
/* command handlers */
int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
......@@ -46,6 +46,8 @@ int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, char *cm
int handle_flash_protect_check_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_flash_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_flash_write_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_flash_write_binary_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_flash_protect_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
/* flash drivers
......@@ -100,8 +102,12 @@ int flash_init(struct command_context_s *cmd_ctx)
"check protection state of sectors in flash bank <num>");
register_command(cmd_ctx, flash_cmd, "erase", handle_flash_erase_command, COMMAND_EXEC,
"erase sectors at <bank> <first> <last>");
register_command(cmd_ctx, flash_cmd, "write", handle_flash_write_command, COMMAND_EXEC,
register_command(cmd_ctx, flash_cmd, "write", handle_flash_write_binary_command, COMMAND_EXEC,
"DEPRECATED, use 'write_binary' or 'write_image' instead");
register_command(cmd_ctx, flash_cmd, "write_binary", handle_flash_write_binary_command, COMMAND_EXEC,
"write binary <bank> <file> <offset>");
register_command(cmd_ctx, flash_cmd, "write_image", handle_flash_write_image_command, COMMAND_EXEC,
"write image <file> [offset] [type]");
register_command(cmd_ctx, flash_cmd, "protect", handle_flash_protect_command, COMMAND_EXEC,
"set protection of sectors at <bank> <first> <last> <on|off>");
}
......@@ -125,16 +131,24 @@ flash_bank_t *get_flash_bank_by_num(int num)
return NULL;
}
/* flash_bank <driver> <base> <size> <chip_width> <bus_width> [driver_options ...]
/* flash_bank <driver> <base> <size> <chip_width> <bus_width> <target> [driver_options ...]
*/
int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
int i;
int found = 0;
target_t *target;
if (argc < 5)
if (argc < 6)
{
WARNING("incomplete flash_bank configuration");
WARNING("flash_bank <driver> <base> <size> <chip_width> <bus_width> <target> [driver_options ...]");
return ERROR_OK;
}
if ((target = get_target_by_num(strtoul(args[5], NULL, 0))) == NULL)
{
ERROR("target %lu not defined", strtoul(args[5], NULL, 0));
return ERROR_OK;
}
......@@ -152,6 +166,7 @@ int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char
}
c = malloc(sizeof(flash_bank_t));
c->target = target;
c->driver = flash_drivers[i];
c->driver_priv = NULL;
c->base = strtoul(args[1], NULL, 0);
......@@ -226,9 +241,9 @@ int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cmd, char
return ERROR_OK;
}
for (p = flash_banks; p; p = p->next)
for (p = flash_banks; p; p = p->next, i++)
{
if (i++ == strtoul(args[0], NULL, 0))
if (i == strtoul(args[0], NULL, 0))
{
char buf[1024];
......@@ -494,15 +509,96 @@ int handle_flash_protect_command(struct command_context_s *cmd_ctx, char *cmd, c
return ERROR_OK;
}
int handle_flash_write_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
target_t *target = get_current_target(cmd_ctx);
image_t image;
u32 image_size;
char *error_str;
u32 *failed;
int i;
duration_t duration;
char *duration_text;
int retval;
if (!strcmp(cmd, "write"))
{
command_print(cmd_ctx, "'flash write' has been deprecated in favor of 'flash write_binary' and 'flash write_image'");
DEBUG("'flash write' has been deprecated in favor of 'flash write_binary' and 'flash write_image'");
}
if (argc < 1)
{
command_print(cmd_ctx, "usage: flash write <file> [offset] [type]");
return ERROR_OK;
}
if (!target)
{
ERROR("no target selected");
return ERROR_OK;
}
duration_start_measure(&duration);
if (argc >= 2)
{
image.base_address_set = 1;
image.base_address = strtoul(args[1], NULL, 0);
}
else
{
image.base_address_set = 0;
image.base_address = 0x0;
}
image.start_address_set = 0;
if (image_open(&image, args[0], (argc == 4) ? args[2] : NULL) != ERROR_OK)
{
command_print(cmd_ctx, "flash write error: %s", image.error_str);
return ERROR_OK;
}
failed = malloc(sizeof(u32) * image.num_sections);
if ((retval = flash_write(target, &image, &image_size, &error_str, failed)) != ERROR_OK)
{
command_print(cmd_ctx, "failed writing image %s: %s", args[0], error_str);
free(error_str);
}
for (i = 0; i < image.num_sections; i++)
{
if (failed[i])
{
command_print(cmd_ctx, "didn't write section at 0x%8.8x, size 0x%8.8x",
image.sections[i].base_address, image.sections[i].size);
}
}
duration_stop_measure(&duration, &duration_text);
command_print(cmd_ctx, "wrote %u byte from file %s in %s (%f kb/s)",
image_size, args[0], duration_text,
(float)image_size / 1024.0 / ((float)duration.duration.tv_sec + ((float)duration.duration.tv_usec / 1000000.0)));