Commit 815c3b35 authored by oharboe's avatar oharboe
Browse files

- "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
parent d8456e48
......@@ -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;
......
This diff is collapsed.
......@@ -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,22 +1744,15 @@ 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
{
......
......@@ -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)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment