Fair enough. Try this then (with some added parameter checking)... = = =
doc/openocd.texi | 6 ++++-- src/flash/flash.c | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 5 deletions(-) Index: src/flash/flash.c =================================================================== --- src/flash/flash.c (revision 2736) +++ src/flash/flash.c (working copy) @@ -559,12 +559,34 @@ return ERROR_OK; } +int flash_check_sector_parameters(struct command_context_s *cmd_ctx, int first, int last, int num_sectors) +{ + int retval = 0; + + if ( first < 0 || last < 0) + { + command_print(cmd_ctx, "ERROR: negative sectors are not valid"); + return ERROR_FAIL; + } + if ( first >= last ) + { + command_print(cmd_ctx, "ERROR: last sector must be > first sector"); + return ERROR_FAIL; + } + if ( last > (num_sectors - 1) ) + { + command_print(cmd_ctx, "ERROR: last sector must be =< %d", num_sectors - 1); + return ERROR_FAIL; + } + return ERROR_OK; +} + static int handle_flash_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { if (argc > 2) { int first = strtoul(args[1], NULL, 0); - int last = strtoul(args[2], NULL, 0); + int last; int retval; flash_bank_t *p = get_flash_bank_by_num(strtoul(args[0], NULL, 0)); duration_t duration; @@ -577,6 +599,16 @@ return ERROR_COMMAND_SYNTAX_ERROR; } + if (strcmp(args[2], "last") == 0) + last = p->num_sectors - 1; + else + last = strtoul(args[2], NULL, 0); + + if ((retval = flash_check_sector_parameters(cmd_ctx, first, last, p->num_sectors)) != ERROR_OK) + { + return retval; + } + if ((retval = flash_driver_erase(p, first, last)) == ERROR_OK) { if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK) @@ -602,7 +634,7 @@ if (argc > 3) { int first = strtoul(args[1], NULL, 0); - int last = strtoul(args[2], NULL, 0); + int last; int set; int retval; flash_bank_t *p = get_flash_bank_by_num(strtoul(args[0], NULL, 0)); @@ -621,6 +653,16 @@ return ERROR_COMMAND_SYNTAX_ERROR; } + if (strcmp(args[2], "last") == 0) + last = p->num_sectors - 1; + else + last = strtoul(args[2], NULL, 0); + + if ((retval = flash_check_sector_parameters(cmd_ctx, first, last, p->num_sectors)) != ERROR_OK) + { + return retval; + } + retval = flash_driver_protect(p, set, first, last); if (retval == ERROR_OK) { @@ -632,7 +674,6 @@ else { return ERROR_COMMAND_SYNTAX_ERROR; - } return ERROR_OK; Index: doc/openocd.texi =================================================================== --- doc/openocd.texi (revision 2736) +++ doc/openocd.texi (working copy) @@ -3071,7 +3071,8 @@ @anchor{flash erase_sector} @deffn Command {flash erase_sector} num first last Erase sectors in bank @var{num}, starting at sector @var{first} up to and including -...@var{last}. Sector numbering starts at 0. +...@var{last}. Sector numbering starts at 0. Defining a @var{last} sector of "last" is +equivalent to defining (max_sectors-1), i.e. erasing the entire bank. The @var{num} parameter is a value shown by @command{flash banks}. @end deffn @@ -3144,7 +3145,8 @@ @anchor{flash protect} @deffn Command {flash protect} num first last (on|off) Enable (@var{on}) or disable (@var{off}) protection of flash sectors -...@var{first} to @var{last} of flash bank @var{num}. +...@var{first} to @var{last} of flash bank @var{num}. Defining a @var{last} sector of "last" +is equivalent to defining (max_sectors-1), i.e. protecting the entire bank. The @var{num} parameter is a value shown by @command{flash banks}. @end deffn _______________________________________________ Openocd-development mailing list Openocd-development@lists.berlios.de https://lists.berlios.de/mailman/listinfo/openocd-development