- "flash write_binary" is now "flash write_bank" to clarify the focus of the
command and reduce confusion with "flash write_image". - retired deprecated "flash erase" & "flash write". - added flash_driver_protect/write/erase() that are wafer thin frontend functions to low level driver functions. They implement checks that were inconsistently handled by the drivers, e.g. check for target halted was done in a spotty fashion. - use return ERROR_COMMAND_SYNTAX_ERROR to print out syntax of command instead of having lots of inlined replicas of the command line syntax(some of which were wrong). - use logging instead of dubious translation of error values to human understandable explanations of why things failed. The lower levels log the precise reason and the higher levels can ammend context as the error propagates up the call stack. - simplified flash API slightly with logging instead of allocating and returning information that the caller then has to translate into print statements. git-svn-id: svn://svn.berlios.de/openocd/trunk@337 b42882b7-edfa-0310-969c-e2dbd0fdcd60
This commit is contained in:
parent
d8456e4826
commit
815c3b3533
|
@ -738,11 +738,6 @@ int at91sam7_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
|
|||
u32 first_page, last_page, pagen, buffer_pos;
|
||||
u8 flashplane;
|
||||
|
||||
if (bank->target->state != TARGET_HALTED)
|
||||
{
|
||||
return ERROR_TARGET_NOT_HALTED;
|
||||
}
|
||||
|
||||
if (at91sam7_info->cidr == 0)
|
||||
{
|
||||
at91sam7_read_part_info(bank);
|
||||
|
|
|
@ -1375,11 +1375,11 @@ int cfi_spansion_write_block(struct flash_bank_s *bank, u8 *buffer, u32 address,
|
|||
}
|
||||
|
||||
/* allocate working area */
|
||||
if (target_alloc_working_area(target, 24 * 4,
|
||||
&cfi_info->write_algorithm) != ERROR_OK)
|
||||
retval=target_alloc_working_area(target, 24 * 4,
|
||||
&cfi_info->write_algorithm);
|
||||
if (retval != ERROR_OK)
|
||||
{
|
||||
WARNING("no working area available, can't do block memory writes");
|
||||
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* write algorithm code to working area */
|
||||
|
@ -1645,11 +1645,6 @@ int cfi_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
|
|||
int i;
|
||||
int retval;
|
||||
|
||||
if (bank->target->state != TARGET_HALTED)
|
||||
{
|
||||
return ERROR_TARGET_NOT_HALTED;
|
||||
}
|
||||
|
||||
if (offset + count > bank->size)
|
||||
return ERROR_FLASH_DST_OUT_OF_BANK;
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ int handle_flash_erase_address_command(struct command_context_s *cmd_ctx, char *
|
|||
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_bank_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);
|
||||
int handle_flash_auto_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
|
||||
|
@ -83,6 +83,70 @@ flash_bank_t *flash_banks;
|
|||
static command_t *flash_cmd;
|
||||
static int auto_erase = 0;
|
||||
|
||||
/* wafer thin wrapper for invoking the flash driver */
|
||||
static int flash_driver_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
|
||||
{
|
||||
int retval=ERROR_OK;
|
||||
if (bank->target->state != TARGET_HALTED)
|
||||
{
|
||||
ERROR("target not halted - aborting flash write");
|
||||
retval=ERROR_TARGET_NOT_HALTED;
|
||||
} else
|
||||
{
|
||||
retval=bank->driver->write(bank, buffer, offset, count);
|
||||
}
|
||||
if (retval!=ERROR_OK)
|
||||
{
|
||||
ERROR("Writing to flash bank at address 0x%08x at offset 0x%8.8x", bank->base, offset);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int flash_driver_erase(struct flash_bank_s *bank, int first, int last)
|
||||
{
|
||||
int retval=ERROR_OK;
|
||||
if (bank->target->state != TARGET_HALTED)
|
||||
{
|
||||
ERROR("target not halted - aborting flash erase");
|
||||
retval=ERROR_TARGET_NOT_HALTED;
|
||||
} else if ((first < 0) || (last < first) || (last >= bank->num_sectors))
|
||||
{
|
||||
ERROR("invalid flash sector");
|
||||
retval=ERROR_FLASH_SECTOR_INVALID;
|
||||
} else
|
||||
{
|
||||
retval=bank->driver->erase(bank, first, last);
|
||||
}
|
||||
if (retval!=ERROR_OK)
|
||||
{
|
||||
ERROR("Failed erasing banks %d to %d", first, last);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
int flash_driver_protect(struct flash_bank_s *bank, int set, int first, int last)
|
||||
{
|
||||
int retval;
|
||||
if (bank->target->state != TARGET_HALTED)
|
||||
{
|
||||
ERROR("target not halted - aborting flash erase");
|
||||
retval=ERROR_TARGET_NOT_HALTED;
|
||||
} else if ((first < 0) || (last < first) || (last >= bank->num_sectors))
|
||||
{
|
||||
ERROR("invalid flash sector");
|
||||
retval=ERROR_FLASH_SECTOR_INVALID;
|
||||
} else
|
||||
{
|
||||
retval=bank->driver->protect(bank, set, first, last);
|
||||
}
|
||||
if (retval!=ERROR_OK)
|
||||
{
|
||||
ERROR("Failed protecting banks %d to %d", first, last);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
int flash_register_commands(struct command_context_s *cmd_ctx)
|
||||
{
|
||||
flash_cmd = register_command(cmd_ctx, NULL, "flash", NULL, COMMAND_ANY, NULL);
|
||||
|
@ -107,16 +171,12 @@ int flash_init_drivers(struct command_context_s *cmd_ctx)
|
|||
"check erase state of sectors in flash bank <num>");
|
||||
register_command(cmd_ctx, flash_cmd, "protect_check", handle_flash_protect_check_command, COMMAND_EXEC,
|
||||
"check protection state of sectors in flash bank <num>");
|
||||
register_command(cmd_ctx, flash_cmd, "erase", handle_flash_erase_command, COMMAND_EXEC,
|
||||
"DEPRECATED, use 'erase_sector' instead");
|
||||
register_command(cmd_ctx, flash_cmd, "erase_sector", handle_flash_erase_command, COMMAND_EXEC,
|
||||
"erase sectors at <bank> <first> <last>");
|
||||
register_command(cmd_ctx, flash_cmd, "erase_address", handle_flash_erase_address_command, COMMAND_EXEC,
|
||||
"erase address range <address> <length>");
|
||||
register_command(cmd_ctx, flash_cmd, "write", handle_flash_write_binary_command, COMMAND_EXEC,
|
||||
"DEPRECATED, use 'write_binary' 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_bank", handle_flash_write_bank_command, COMMAND_EXEC,
|
||||
"write binary data to <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,
|
||||
|
@ -138,7 +198,7 @@ flash_bank_t *get_flash_bank_by_num_noprobe(int num)
|
|||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
ERROR("Flash bank %d does not exist", num);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -264,8 +324,7 @@ int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cmd, char
|
|||
|
||||
if (argc != 1)
|
||||
{
|
||||
command_print(cmd_ctx, "usage: flash info <num>");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
for (p = flash_banks; p; p = p->next, i++)
|
||||
|
@ -317,8 +376,7 @@ int handle_flash_probe_command(struct command_context_s *cmd_ctx, char *cmd, cha
|
|||
|
||||
if (argc != 1)
|
||||
{
|
||||
command_print(cmd_ctx, "usage: flash probe <num>");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
p = get_flash_bank_by_num_noprobe(strtoul(args[0], NULL, 0));
|
||||
|
@ -354,8 +412,7 @@ int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, char *cm
|
|||
|
||||
if (argc != 1)
|
||||
{
|
||||
command_print(cmd_ctx, "usage: flash erase_check <num>");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
p = get_flash_bank_by_num(strtoul(args[0], NULL, 0));
|
||||
|
@ -371,10 +428,6 @@ int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, char *cm
|
|||
args[0], p->base);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]);
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
@ -392,8 +445,7 @@ int handle_flash_erase_address_command(struct command_context_s *cmd_ctx, char *
|
|||
|
||||
if (argc != 2)
|
||||
{
|
||||
command_print(cmd_ctx, "usage: flash erase_address <address> <length>");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
address = strtoul(args[0], NULL, 0);
|
||||
|
@ -401,14 +453,13 @@ int handle_flash_erase_address_command(struct command_context_s *cmd_ctx, char *
|
|||
if (length <= 0)
|
||||
{
|
||||
command_print(cmd_ctx, "Length must be >0");
|
||||
return ERROR_INVALID_ARGUMENTS;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
p = get_flash_bank_by_addr(target, address);
|
||||
if (p == NULL)
|
||||
{
|
||||
command_print(cmd_ctx, "No flash at that address");
|
||||
return ERROR_INVALID_ARGUMENTS;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
/* We can't know if we did a resume + halt, in which case we no longer know the erased state */
|
||||
|
@ -416,30 +467,7 @@ int handle_flash_erase_address_command(struct command_context_s *cmd_ctx, char *
|
|||
|
||||
duration_start_measure(&duration);
|
||||
|
||||
if ((retval = flash_erase_address_range(target, address, length)) != ERROR_OK)
|
||||
{
|
||||
switch (retval)
|
||||
{
|
||||
case ERROR_TARGET_NOT_HALTED:
|
||||
command_print(cmd_ctx, "can't work with this flash while target is running");
|
||||
break;
|
||||
case ERROR_INVALID_ARGUMENTS:
|
||||
command_print(cmd_ctx, "usage: flash erase_address <address> <length>");
|
||||
break;
|
||||
case ERROR_FLASH_BANK_INVALID:
|
||||
command_print(cmd_ctx, "no '%s' flash found at 0x%8.8x", p->driver->name, p->base);
|
||||
break;
|
||||
case ERROR_FLASH_OPERATION_FAILED:
|
||||
command_print(cmd_ctx, "flash erase error");
|
||||
break;
|
||||
case ERROR_FLASH_SECTOR_INVALID:
|
||||
command_print(cmd_ctx, "sector number(s) invalid");
|
||||
break;
|
||||
default:
|
||||
command_print(cmd_ctx, "unknown error");
|
||||
}
|
||||
}
|
||||
else
|
||||
if ((retval = flash_erase_address_range(target, address, length)) == ERROR_OK)
|
||||
{
|
||||
duration_stop_measure(&duration, &duration_text);
|
||||
command_print(cmd_ctx, "erased address 0x%8.8x length %i in %s", address, length, duration_text);
|
||||
|
@ -456,8 +484,7 @@ int handle_flash_protect_check_command(struct command_context_s *cmd_ctx, char *
|
|||
|
||||
if (argc != 1)
|
||||
{
|
||||
command_print(cmd_ctx, "usage: flash protect_check <num>");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
p = get_flash_bank_by_num(strtoul(args[0], NULL, 0));
|
||||
|
@ -478,7 +505,7 @@ int handle_flash_protect_check_command(struct command_context_s *cmd_ctx, char *
|
|||
}
|
||||
else
|
||||
{
|
||||
command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]);
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
|
@ -499,37 +526,10 @@ int handle_flash_erase_command(struct command_context_s *cmd_ctx, char *cmd, cha
|
|||
|
||||
if (!p)
|
||||
{
|
||||
command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]);
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if ((retval = p->driver->erase(p, first, last)) != ERROR_OK)
|
||||
{
|
||||
switch (retval)
|
||||
{
|
||||
case ERROR_TARGET_NOT_HALTED:
|
||||
command_print(cmd_ctx, "can't work with this flash while target is running");
|
||||
break;
|
||||
case ERROR_INVALID_ARGUMENTS:
|
||||
command_print(cmd_ctx, "usage: flash_erase <bank> <first> <last>");
|
||||
break;
|
||||
case ERROR_FLASH_BANK_INVALID:
|
||||
command_print(cmd_ctx, "no '%s' flash found at 0x%8.8x", p->driver->name, p->base);
|
||||
break;
|
||||
case ERROR_FLASH_OPERATION_FAILED:
|
||||
command_print(cmd_ctx, "flash erase error");
|
||||
break;
|
||||
case ERROR_FLASH_SECTOR_INVALID:
|
||||
command_print(cmd_ctx, "sector number(s) invalid");
|
||||
break;
|
||||
case ERROR_OK:
|
||||
command_print(cmd_ctx, "erased flash sectors %i to %i", first, last);
|
||||
break;
|
||||
default:
|
||||
command_print(cmd_ctx, "unknown error");
|
||||
}
|
||||
}
|
||||
else
|
||||
if ((retval = flash_driver_erase(p, first, last)) == ERROR_OK)
|
||||
{
|
||||
duration_stop_measure(&duration, &duration_text);
|
||||
|
||||
|
@ -539,7 +539,7 @@ int handle_flash_erase_command(struct command_context_s *cmd_ctx, char *cmd, cha
|
|||
}
|
||||
else
|
||||
{
|
||||
command_print(cmd_ctx, "usage: flash erase <bank> <first> <last>");
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
|
@ -566,44 +566,19 @@ int handle_flash_protect_command(struct command_context_s *cmd_ctx, char *cmd, c
|
|||
set = 0;
|
||||
else
|
||||
{
|
||||
command_print(cmd_ctx, "usage: flash protect <bank> <first> <last> <on|off>");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if ((retval = p->driver->protect(p, set, first, last)) != ERROR_OK)
|
||||
{
|
||||
switch (retval)
|
||||
{
|
||||
case ERROR_TARGET_NOT_HALTED:
|
||||
command_print(cmd_ctx, "can't work with this flash while target is running");
|
||||
break;
|
||||
case ERROR_INVALID_ARGUMENTS:
|
||||
command_print(cmd_ctx, "usage: flash protect <bank> <first> <last> <on|off>");
|
||||
break;
|
||||
case ERROR_FLASH_BANK_INVALID:
|
||||
command_print(cmd_ctx, "no '%s' flash found at 0x%8.8x", p->driver->name, p->base);
|
||||
break;
|
||||
case ERROR_FLASH_OPERATION_FAILED:
|
||||
command_print(cmd_ctx, "flash program error");
|
||||
break;
|
||||
case ERROR_FLASH_SECTOR_INVALID:
|
||||
command_print(cmd_ctx, "sector number(s) invalid");
|
||||
break;
|
||||
case ERROR_OK:
|
||||
command_print(cmd_ctx, "protection of flash sectors %i to %i turned %s", first, last, args[3]);
|
||||
break;
|
||||
default:
|
||||
command_print(cmd_ctx, "unknown error");
|
||||
}
|
||||
}
|
||||
else
|
||||
retval = flash_driver_protect(p, set, first, last);
|
||||
if (retval == ERROR_OK)
|
||||
{
|
||||
command_print(cmd_ctx, "%s protection for sectors %i through %i on flash bank %i", (set) ? "set" : "cleared", first, last, strtoul(args[0], 0, 0));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
command_print(cmd_ctx, "usage: flash protect <bank> <first> <last> <on|off>");
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
|
@ -615,10 +590,6 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
|
|||
|
||||
image_t image;
|
||||
u32 written;
|
||||
char *error_str;
|
||||
int *failed;
|
||||
|
||||
int i;
|
||||
|
||||
duration_t duration;
|
||||
char *duration_text;
|
||||
|
@ -627,8 +598,8 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
|
|||
|
||||
if (argc < 1)
|
||||
{
|
||||
command_print(cmd_ctx, "usage: flash %s <file> [offset] [type]", cmd);
|
||||
return ERROR_INVALID_ARGUMENTS;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
}
|
||||
|
||||
if (!target)
|
||||
|
@ -659,46 +630,29 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
|
|||
return retval;
|
||||
}
|
||||
|
||||
failed = malloc(sizeof(int) * image.num_sections);
|
||||
|
||||
error_str = NULL;
|
||||
|
||||
retval = flash_write(target, &image, &written, &error_str, failed, auto_erase);
|
||||
retval = flash_write(target, &image, &written, auto_erase);
|
||||
|
||||
if (retval != ERROR_OK)
|
||||
{
|
||||
if (error_str)
|
||||
{
|
||||
command_print(cmd_ctx, "failed writing image %s: %s", args[0], error_str);
|
||||
free(error_str);
|
||||
}
|
||||
image_close(&image);
|
||||
free(failed);
|
||||
return retval;
|
||||
}
|
||||
|
||||
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);
|
||||
if (retval == ERROR_OK)
|
||||
{
|
||||
command_print(cmd_ctx, "wrote %u byte from file %s in %s (%f kb/s)",
|
||||
written, args[0], duration_text,
|
||||
(float)written / 1024.0 / ((float)duration.duration.tv_sec + ((float)duration.duration.tv_usec / 1000000.0)));
|
||||
}
|
||||
free(duration_text);
|
||||
free(failed);
|
||||
|
||||
image_close(&image);
|
||||
|
||||
return ERROR_OK;
|
||||
return retval;
|
||||
}
|
||||
|
||||
int handle_flash_write_binary_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
|
||||
int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
|
||||
{
|
||||
u32 offset;
|
||||
u8 *buffer;
|
||||
|
@ -712,10 +666,9 @@ int handle_flash_write_binary_command(struct command_context_s *cmd_ctx, char *c
|
|||
int retval;
|
||||
flash_bank_t *p;
|
||||
|
||||
if (argc < 3)
|
||||
if (argc != 3)
|
||||
{
|
||||
command_print(cmd_ctx, "usage: flash write_binary <bank> <file> <offset>");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
duration_start_measure(&duration);
|
||||
|
@ -741,50 +694,22 @@ int handle_flash_write_binary_command(struct command_context_s *cmd_ctx, char *c
|
|||
return ERROR_OK;
|
||||
}
|
||||
|
||||
if ((retval = p->driver->write(p, buffer, offset, buf_cnt)) != ERROR_OK)
|
||||
{
|
||||
command_print(cmd_ctx, "failed writing file %s to flash bank %i at offset 0x%8.8x",
|
||||
args[1], strtoul(args[0], NULL, 0), strtoul(args[2], NULL, 0));
|
||||
|
||||
switch (retval)
|
||||
{
|
||||
case ERROR_TARGET_NOT_HALTED:
|
||||
command_print(cmd_ctx, "can't work with this flash while target is running");
|
||||
break;
|
||||
case ERROR_INVALID_ARGUMENTS:
|
||||
command_print(cmd_ctx, "usage: flash write <bank> <file> <offset>");
|
||||
break;
|
||||
case ERROR_FLASH_BANK_INVALID:
|
||||
command_print(cmd_ctx, "no '%s' flash found at 0x%8.8x", p->driver->name, p->base);
|
||||
break;
|
||||
case ERROR_FLASH_OPERATION_FAILED:
|
||||
command_print(cmd_ctx, "flash program error");
|
||||
break;
|
||||
case ERROR_FLASH_DST_BREAKS_ALIGNMENT:
|
||||
command_print(cmd_ctx, "offset breaks required alignment");
|
||||
break;
|
||||
case ERROR_FLASH_DST_OUT_OF_BANK:
|
||||
command_print(cmd_ctx, "destination is out of flash bank (offset and/or file too large)");
|
||||
break;
|
||||
case ERROR_FLASH_SECTOR_NOT_ERASED:
|
||||
command_print(cmd_ctx, "destination sector(s) not erased");
|
||||
break;
|
||||
default:
|
||||
command_print(cmd_ctx, "unknown error");
|
||||
}
|
||||
}
|
||||
retval = flash_driver_write(p, buffer, offset, buf_cnt);
|
||||
|
||||
free(buffer);
|
||||
|
||||
duration_stop_measure(&duration, &duration_text);
|
||||
if (retval!=ERROR_OK)
|
||||
{
|
||||
command_print(cmd_ctx, "wrote %"PRIi64" byte from file %s to flash bank %i at offset 0x%8.8x in %s (%f kb/s)",
|
||||
fileio.size, args[1], strtoul(args[0], NULL, 0), offset, duration_text,
|
||||
(float)fileio.size / 1024.0 / ((float)duration.duration.tv_sec + ((float)duration.duration.tv_usec / 1000000.0)));
|
||||
}
|
||||
free(duration_text);
|
||||
|
||||
fileio_close(&fileio);
|
||||
|
||||
return ERROR_OK;
|
||||
return retval;
|
||||
}
|
||||
|
||||
void flash_set_dirty(void)
|
||||
|
@ -822,7 +747,7 @@ flash_bank_t *get_flash_bank_by_addr(target_t *target, u32 addr)
|
|||
if ((addr >= c->base) && (addr < c->base + c->size) && target == c->target)
|
||||
return c;
|
||||
}
|
||||
|
||||
ERROR("No flash at address 0x%08x\n", addr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -846,7 +771,7 @@ int flash_erase_address_range(target_t *target, u32 addr, u32 length)
|
|||
if (addr != c->base)
|
||||
return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
|
||||
|
||||
return c->driver->erase(c, 0, c->num_sectors - 1);
|
||||
return flash_driver_erase(c, 0, c->num_sectors - 1);
|
||||
}
|
||||
|
||||
/* check whether it fits */
|
||||
|
@ -869,14 +794,13 @@ int flash_erase_address_range(target_t *target, u32 addr, u32 length)
|
|||
if( first == -1 || last == -1 )
|
||||
return ERROR_OK;
|
||||
|
||||
return c->driver->erase(c, first, last);
|
||||
return flash_driver_erase(c, first, last);
|
||||
}
|
||||
|
||||
/* write (optional verify) an image to flash memory of the given target */
|
||||
int flash_write(target_t *target, image_t *image, u32 *written, char **error_str, int *failed, int erase)
|
||||
int flash_write(target_t *target, image_t *image, u32 *written, int erase)
|
||||
{
|
||||
int retval;
|
||||
int i;
|
||||
|
||||
int section;
|
||||
u32 section_offset;
|
||||
|
@ -888,10 +812,6 @@ int flash_write(target_t *target, image_t *image, u32 *written, char **error_str
|
|||
if (written)
|
||||
*written = 0;
|
||||
|
||||
if (failed != NULL)
|
||||
for (i = 0; i < image->num_sections; i++)
|
||||
failed[i] = 0;
|
||||
|
||||
if (erase)
|
||||
{
|
||||
/* assume all sectors need erasing - stops any problems
|
||||
|
@ -921,15 +841,6 @@ int flash_write(target_t *target, image_t *image, u32 *written, char **error_str
|
|||
/* find the corresponding flash bank */
|
||||
if ((c = get_flash_bank_by_addr(target, run_address)) == NULL)
|
||||
{
|
||||
if (failed == NULL)
|
||||
{
|
||||
if (error_str == NULL)
|
||||
return ERROR_FLASH_DST_OUT_OF_BANK; /* abort operation */
|
||||
*error_str = malloc(FLASH_MAX_ERROR_STR);
|
||||
snprintf(*error_str, FLASH_MAX_ERROR_STR, "no flash mapped at requested address");
|
||||
return ERROR_FLASH_DST_OUT_OF_BANK; /* abort operation */
|
||||
}
|
||||
failed[section] = ERROR_FLASH_DST_OUT_OF_BANK; /* mark the section as failed */
|
||||
section++; /* and skip it */
|
||||
section_offset = 0;
|
||||
continue;
|
||||
|
@ -974,18 +885,7 @@ int flash_write(target_t *target, image_t *image, u32 *written, char **error_str
|
|||
{
|
||||
free(buffer);
|
||||
|
||||
if (error_str == NULL)
|
||||
return ERROR_IMAGE_TEMPORARILY_UNAVAILABLE;
|
||||
|
||||
*error_str = malloc(FLASH_MAX_ERROR_STR);
|
||||
|
||||
/* if image_read_section returned an error there's an error string we can pass on */
|
||||
if (retval != ERROR_OK)
|
||||
snprintf(*error_str, FLASH_MAX_ERROR_STR, "error reading from image: %s", image->error_str);
|
||||
else
|
||||
snprintf(*error_str, FLASH_MAX_ERROR_STR, "error reading from image");
|
||||
|
||||
return ERROR_IMAGE_TEMPORARILY_UNAVAILABLE;
|
||||
return retval;
|
||||
}
|
||||
|
||||
buffer_size += size_read;
|
||||
|
@ -1009,44 +909,16 @@ int flash_write(target_t *target, image_t *image, u32 *written, char **error_str
|
|||
if (retval == ERROR_OK)
|
||||
{
|
||||
/* write flash sectors */
|
||||
retval = c->driver->write(c, buffer, run_address - c->base, run_size);
|
||||
retval = flash_driver_write(c, buffer, run_address - c->base, run_size);
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
|
||||
if (retval != ERROR_OK)
|
||||
{
|
||||
if (error_str == NULL)
|
||||
return retval; /* abort operation */
|
||||
|
||||
*error_str = malloc(FLASH_MAX_ERROR_STR);
|
||||
switch (retval)
|
||||
{
|
||||
case ERROR_TARGET_NOT_HALTED:
|
||||
snprintf(*error_str, FLASH_MAX_ERROR_STR, "can't flash image while target is running");
|
||||
break;
|
||||
case ERROR_INVALID_ARGUMENTS:
|
||||
snprintf(*error_str, FLASH_MAX_ERROR_STR, "flash driver can't fulfill request");
|
||||
break;
|
||||
case ERROR_FLASH_OPERATION_FAILED:
|
||||
snprintf(*error_str, FLASH_MAX_ERROR_STR, "flash program error");
|
||||
break;
|
||||
case ERROR_FLASH_DST_BREAKS_ALIGNMENT:
|
||||
snprintf(*error_str, FLASH_MAX_ERROR_STR, "offset breaks required alignment");
|
||||
break;
|
||||
case ERROR_FLASH_DST_OUT_OF_BANK:
|
||||
snprintf(*error_str, FLASH_MAX_ERROR_STR, "no flash mapped at requested address");
|
||||
break;
|
||||
case ERROR_FLASH_SECTOR_NOT_ERASED:
|
||||
snprintf(*error_str, FLASH_MAX_ERROR_STR, "destination sector(s) not erased");
|
||||
break;
|
||||
default:
|
||||
snprintf(*error_str, FLASH_MAX_ERROR_STR, "unknown error: %i", retval);
|
||||
}
|
||||
|
||||
return retval; /* abort operation */
|
||||
}
|
||||
|
||||
if (written != NULL)
|
||||
*written += run_size; /* add run size to total written counter */
|
||||
}
|
||||
|
@ -1058,14 +930,16 @@ int handle_flash_auto_erase_command(struct command_context_s *cmd_ctx, char *cmd
|
|||
{
|
||||
if (argc != 1)
|
||||
{
|
||||
command_print(cmd_ctx, "usage: flash auto_erase <on|off>");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
}
|
||||
|
||||
if (strcmp(args[0], "on") == 0)
|
||||
auto_erase = 1;
|
||||
else if (strcmp(args[0], "off") == 0)
|
||||
auto_erase = 0;
|
||||
else
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
|
|
@ -40,8 +40,19 @@ typedef struct flash_driver_s
|
|||
char *name;
|
||||
int (*register_commands)(struct command_context_s *cmd_ctx);
|
||||
int (*flash_bank_command)(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
|
||||
/* low level flash erase. Only invoke from flash_driver_erase()
|
||||
*
|
||||
* Will only be invoked when target is halted.
|
||||
*/
|
||||
int (*erase)(struct flash_bank_s *bank, int first, int last);
|
||||
/* invoked only from flash_driver_protect().
|
||||
*
|
||||
* Only invoked if target is halted
|
||||
*/
|
||||
int (*protect)(struct flash_bank_s *bank, int set, int first, int last);
|
||||
/* low level flash write. Will only be invoked if the target is halted.
|
||||
* use the flash_driver_write() wrapper to invoke.
|
||||
*/
|
||||
int (*write)(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count);
|
||||
int (*probe)(struct flash_bank_s *bank);
|
||||
int (*erase_check)(struct flash_bank_s *bank);
|
||||
|
@ -68,7 +79,7 @@ extern int flash_register_commands(struct command_context_s *cmd_ctx);
|
|||
extern int flash_init_drivers(struct command_context_s *cmd_ctx);
|
||||
|
||||
extern int flash_erase_address_range(target_t *target, u32 addr, u32 length);
|
||||
extern int flash_write(target_t *target, image_t *image, u32 *written, char **error, int *failed, int erase);
|
||||
extern int flash_write(target_t *target, image_t *image, u32 *written, int erase);
|
||||
extern void flash_set_dirty(void);
|
||||
|
||||
extern flash_bank_t *get_flash_bank_by_num(int num);
|
||||
|
|
|
@ -416,16 +416,6 @@ int lpc2000_erase(struct flash_bank_s *bank, int first, int last)
|
|||
u32 result_table[2];
|
||||
int status_code;
|
||||
|
||||
if (bank->target->state != TARGET_HALTED)
|
||||
{
|
||||
return ERROR_TARGET_NOT_HALTED;
|
||||
}
|
||||
|
||||
if ((first < 0) || (last < first) || (last >= bank->num_sectors))
|
||||
{
|
||||
return ERROR_FLASH_SECTOR_INVALID;
|
||||
}
|
||||
|
||||
param_table[0] = first;
|
||||
param_table[1] = last;
|
||||
param_table[2] = lpc2000_info->cclk;
|
||||
|
|
|
@ -881,8 +881,7 @@ int handle_lpc3180_select_command(struct command_context_s *cmd_ctx, char *cmd,
|
|||
|
||||
if ((argc < 1) || (argc > 2))
|
||||
{
|
||||
command_print(cmd_ctx, "usage: lpc3180 select <num> <'mlc'|'slc'>");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
device = get_nand_device_by_num(strtoul(args[0], NULL, 0));
|
||||
|
@ -906,7 +905,7 @@ int handle_lpc3180_select_command(struct command_context_s *cmd_ctx, char *cmd,
|
|||
}
|
||||
else
|
||||
{
|
||||
command_print(cmd_ctx, "usage: lpc3180 select <'mlc'|'slc'>");
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1024,8 +1024,8 @@ int handle_nand_info_command(struct command_context_s *cmd_ctx, char *cmd, char
|
|||
|
||||
if ((argc < 1) || (argc > 3))
|
||||
{
|
||||
command_print(cmd_ctx, "usage: nand info <num> [<first> <last>]");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
}
|
||||
|
||||
if (argc == 2)
|
||||
|
@ -1091,8 +1091,7 @@ int handle_nand_probe_command(struct command_context_s *cmd_ctx, char *cmd, char
|
|||
|
||||
if (argc != 1)
|
||||
{
|
||||
command_print(cmd_ctx, "usage: nand probe <num>");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
p = get_nand_device_by_num(strtoul(args[0], NULL, 0));
|
||||
|
@ -1126,8 +1125,8 @@ int handle_nand_erase_command(struct command_context_s *cmd_ctx, char *cmd, char
|
|||
|
||||
if (argc != 3)
|
||||
{
|
||||
command_print(cmd_ctx, "usage: nand erase <num> <first> <last>");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
}
|
||||
|
||||
p = get_nand_device_by_num(strtoul(args[0], NULL, 0));
|
||||
|
@ -1166,8 +1165,8 @@ int handle_nand_check_bad_blocks_command(struct command_context_s *cmd_ctx, char
|
|||
|
||||
if ((argc < 1) || (argc > 3) || (argc == 2))
|
||||
{
|
||||
command_print(cmd_ctx, "usage: nand check_bad_blocks <num> [<first> <last>]");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
}
|
||||
|
||||
if (argc == 3)
|
||||
|
@ -1206,8 +1205,8 @@ int handle_nand_copy_command(struct command_context_s *cmd_ctx, char *cmd, char
|
|||
|
||||
if (argc != 4)
|
||||
{
|
||||
command_print(cmd_ctx, "usage: nand copy <num> <offset> <length> <ram-address>");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
}
|
||||
|
||||
p = get_nand_device_by_num(strtoul(args[0], NULL, 0));
|
||||
|
@ -1239,8 +1238,8 @@ int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cmd, char
|
|||
|
||||
if (argc < 3)
|
||||
{
|
||||
command_print(cmd_ctx, "usage: nand write <num> <file> <offset> [options]");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
}
|
||||
|
||||
p = get_nand_device_by_num(strtoul(args[0], NULL, 0));
|
||||
|
@ -1353,8 +1352,7 @@ int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd, char
|
|||
|
||||
if (argc < 4)
|
||||
{
|
||||
command_print(cmd_ctx, "usage: nand dump <num> <filename> <address> <size> [options]");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
p = get_nand_device_by_num(strtoul(args[0], NULL, 0));
|
||||
|
@ -1475,8 +1473,7 @@ int handle_nand_raw_access_command(struct command_context_s *cmd_ctx, char *cmd,
|
|||
|
||||
if ((argc < 1) || (argc > 2))
|
||||
{
|
||||
command_print(cmd_ctx, "usage: nand raw_access <num> ['enable'|'disable']");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
p = get_nand_device_by_num(strtoul(args[0], NULL, 0));
|
||||
|
@ -1496,7 +1493,7 @@ int handle_nand_raw_access_command(struct command_context_s *cmd_ctx, char *cmd,
|
|||
}
|
||||
else
|
||||
{
|
||||
command_print(cmd_ctx, "usage: nand raw_access ['enable'|disable']");
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -514,11 +514,6 @@ int stellaris_erase(struct flash_bank_s *bank, int first, int last)
|
|||
stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
|
||||
target_t *target = bank->target;
|
||||
|
||||
if (bank->target->state != TARGET_HALTED)
|
||||
{
|
||||
return ERROR_TARGET_NOT_HALTED;
|
||||
}
|
||||
|
||||
if (stellaris_info->did1 == 0)
|
||||
{
|
||||
stellaris_read_part_info(bank);
|
||||
|
@ -817,11 +812,6 @@ int stellaris_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count
|
|||
DEBUG("(bank=%08X buffer=%08X offset=%08X count=%08X)",
|
||||
(unsigned int)bank, (unsigned int)buffer, offset, count);
|
||||
|
||||
if (bank->target->state != TARGET_HALTED)
|
||||
{
|
||||
return ERROR_TARGET_NOT_HALTED;
|
||||
}
|
||||
|
||||
if (stellaris_info->did1 == 0)
|
||||
{
|
||||
stellaris_read_part_info(bank);
|
||||
|
|
|
@ -356,11 +356,6 @@ int stm32x_erase(struct flash_bank_s *bank, int first, int last)
|
|||
int i;
|
||||
u32 status;
|
||||
|
||||
if (target->state != TARGET_HALTED)
|
||||
{
|
||||
return ERROR_TARGET_NOT_HALTED;
|
||||
}
|
||||
|
||||
/* unlock flash registers */
|
||||
target_write_u32(target, STM32_FLASH_KEYR, KEY1);
|
||||
target_write_u32(target, STM32_FLASH_KEYR, KEY2);
|
||||
|
@ -552,11 +547,6 @@ int stm32x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
|
|||
u8 status;
|
||||
u32 retval;
|
||||
|
||||
if (target->state != TARGET_HALTED)
|
||||
{
|
||||
return ERROR_TARGET_NOT_HALTED;
|
||||
}
|
||||
|
||||
if (offset & 0x1)
|
||||
{
|
||||
WARNING("offset 0x%x breaks required 2-byte alignment", offset);
|
||||
|
|
|
@ -314,11 +314,6 @@ int str7x_erase(struct flash_bank_s *bank, int first, int last)
|
|||
u32 retval;
|
||||
u32 b0_sectors = 0, b1_sectors = 0;
|
||||
|
||||
if (bank->target->state != TARGET_HALTED)
|
||||
{
|
||||
return ERROR_TARGET_NOT_HALTED;
|
||||
}
|
||||
|
||||
for (i = first; i <= last; i++)
|
||||
{
|
||||
if (str7x_info->sector_bank[i] == 0)
|
||||
|
@ -573,11 +568,6 @@ int str7x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
|
|||
u32 check_address = offset;
|
||||
int i;
|
||||
|
||||
if (bank->target->state != TARGET_HALTED)
|
||||
{
|
||||
return ERROR_TARGET_NOT_HALTED;
|
||||
}
|
||||
|
||||
if (offset & 0x7)
|
||||
{
|
||||
WARNING("offset 0x%x breaks required 8-byte alignment", offset);
|
||||
|
|
|
@ -248,11 +248,6 @@ int str9x_erase(struct flash_bank_s *bank, int first, int last)
|
|||
u32 adr;
|
||||
u8 status;
|
||||
|
||||
if (bank->target->state != TARGET_HALTED)
|
||||
{
|
||||
return ERROR_TARGET_NOT_HALTED;
|
||||
}
|
||||
|
||||
for (i = first; i <= last; i++)
|
||||
{
|
||||
adr = bank->base + bank->sectors[i].offset;
|
||||
|
@ -442,11 +437,6 @@ int str9x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
|
|||
u32 bank_adr;
|
||||
int i;
|
||||
|
||||
if (bank->target->state != TARGET_HALTED)
|
||||
{
|
||||
return ERROR_TARGET_NOT_HALTED;
|
||||
}
|
||||
|
||||
if (offset & 0x1)
|
||||
{
|
||||
WARNING("offset 0x%x breaks required 2-byte alignment", offset);
|
||||
|
@ -600,8 +590,7 @@ int str9x_handle_flash_config_command(struct command_context_s *cmd_ctx, char *c
|
|||
|
||||
if (argc < 5)
|
||||
{
|
||||
command_print(cmd_ctx, "usage: str9x flash_config <bank> <bbsize> <nbsize> <bbstart> <nbstart>");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
bank = get_flash_bank_by_num(strtoul(args[0], NULL, 0));
|
||||
|
|
|
@ -881,8 +881,7 @@ int str9xpec_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd
|
|||
|
||||
if (argc < 1)
|
||||
{
|
||||
command_print(cmd_ctx, "usage: str9xpec part_id <num>");
|
||||
return ERROR_OK;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
bank = get_flash_bank_by_num(strtoul(args[0], NULL, 0));
|
||||
|
|
|
@ -184,7 +184,7 @@ int handle_field_command(struct command_context_s *cmd_ctx, char *cmd, char **ar
|
|||
{
|
||||
|
||||
if (argc < 2)
|
||||
command_print(cmd_ctx, "usage: field <var> <field> [value|'flip']");
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
if (argc >= 2)
|
||||
{
|
||||
|
@ -220,7 +220,7 @@ int handle_script_command(struct command_context_s *cmd_ctx, char *cmd, char **a
|
|||
int echo;
|
||||
|
||||
if (argc != 1)
|
||||
command_print(cmd_ctx, "usage: script <file>");
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
script_file = open_file_from_path(cmd_ctx, args[0], "r");
|
||||
|
||||
|
|
|
@ -1744,23 +1744,16 @@ int gdb_v_packet(connection_t *connection, target_t *target, char *packet, int p
|
|||
if (!strcmp(packet, "vFlashDone"))
|
||||
{
|
||||
u32 written;
|
||||
char *error_str;
|
||||
|
||||
/* process the flashing buffer. No need to erase as GDB
|
||||
* always issues a vFlashErase first. */
|
||||
if ((result = flash_write(gdb_service->target, gdb_connection->vflash_image, &written, &error_str, NULL, 0)) != ERROR_OK)
|
||||
if ((result = flash_write(gdb_service->target, gdb_connection->vflash_image, &written, 0)) != ERROR_OK)
|
||||
{
|
||||
if (result == ERROR_FLASH_DST_OUT_OF_BANK)
|
||||
gdb_put_packet(connection, "E.memtype", 9);
|
||||
else
|
||||
gdb_send_error(connection, EIO);
|
||||
|
||||
if (error_str)
|
||||
{
|
||||
ERROR("flash writing failed: %s", error_str);
|
||||
free(error_str);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG("wrote %u bytes from vFlash image to flash", written);
|
||||
|
|
|
@ -254,6 +254,9 @@ int target_write_u32(struct target_s *target, u32 address, u32 value);
|
|||
int target_write_u16(struct target_s *target, u32 address, u16 value);
|
||||
int target_write_u8(struct target_s *target, u32 address, u8 value);
|
||||
|
||||
/* Issues USER() statements with target state information */
|
||||
int target_arch_state(struct target_s *target);
|
||||
|
||||
#define ERROR_TARGET_INVALID (-300)
|
||||
#define ERROR_TARGET_INIT_FAILED (-301)
|
||||
#define ERROR_TARGET_TIMEOUT (-302)
|
||||
|
|
Loading…
Reference in New Issue