Re: [Openocd-development] [PATCH] Enhancement: Allow -1 as last sector for protection and erase

2009-09-21 Thread David Brownell
On Monday 21 September 2009, Johnny Halfmoon wrote:
> Okay. Like this then:

Merged with some cleanups, including the one noted by Rolf.

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH] Enhancement: Allow -1 as last sector for protection and erase

2009-09-21 Thread David Brownell
On Monday 21 September 2009, Johnny Halfmoon wrote:
> 
> David Brownell wrote:
> > On Sunday 20 September 2009, Johnny Halfmoon wrote:
> >> +   if ((retval = flash_check_sector_parameters(cmd_ctx, 
> >> first, last, p->num_sectors)) !
> > 
> > I had in mind more like
> > 
> > uint32_t value; 
> 
> 
> Okay. Like this then:

Yes!  If I don't hear objections from anyone, I'll
check this in later today.

- Dave

> 
> = = = = = = = = = = = =
> 
> 
>  doc/openocd.texi  |6 ++-
>  src/flash/flash.c |   97 
> +++---
>  2 files changed, 67 insertions(+), 36 deletions(-)
> 
> Index: src/flash/flash.c
> ===
> --- src/flash/flash.c (revision 2736)
> +++ src/flash/flash.c (working copy)
> @@ -559,40 +559,62 @@
>   return ERROR_OK;
>  }
>  
> +int flash_check_sector_parameters(struct command_context_s *cmd_ctx, 
> uint32_t first, uint32_t last, uint num_sectors)
> +{
> + 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);
> + uint32_t bank_nr;
> + uint32_t first;
> + uint32_t last;
>   int retval;
> - flash_bank_t *p = get_flash_bank_by_num(strtoul(args[0], NULL, 
> 0));
> +
> + if ((retval = parse_u32(args[0], &bank_nr)) != ERROR_OK)
> + return retval;
> +
> + flash_bank_t *p = get_flash_bank_by_num(bank_nr);
> + if (!p)
> + return ERROR_OK;
> +
> + if ((retval = parse_u32(args[1], &first)) != ERROR_OK)
> + return retval;
> + if (strcmp(args[2], "last") == 0)
> + last = p->num_sectors - 1;
> + else
> + if ((retval = parse_u32(args[2], &last)) != ERROR_OK)
> + return retval;
> +
> + if ((retval = flash_check_sector_parameters(cmd_ctx, first, 
> last, p->num_sectors)) != ERROR_OK)
> + return retval;
> +
>   duration_t duration;
>   char *duration_text;
> -
>   duration_start_measure(&duration);
>  
> - if (!p)
> - {
> - return ERROR_COMMAND_SYNTAX_ERROR;
> - }
> -
> - if ((retval = flash_driver_erase(p, first, last)) == ERROR_OK)
> - {
> + if ((retval = flash_driver_erase(p, first, last)) == ERROR_OK) {
>   if ((retval = duration_stop_measure(&duration, 
> &duration_text)) != ERROR_OK)
> - {
>   return retval;
> - }
> -
> - command_print(cmd_ctx, "erased sectors %i through %i on 
> flash bank %li in %s",
> - first, last, strtoul(args[0], 0, 0), 
> duration_text);
> + command_print(cmd_ctx, "erased sectors %i through %i on 
> flash bank %i in %s",
> + first, last, bank_nr, duration_text);
>   free(duration_text);
>   }
>   }
>   else
> - {
>   return ERROR_COMMAND_SYNTAX_ERROR;
> - }
>  
>   return ERROR_OK;
>  }
> @@ -601,40 +623,47 @@
>  {
>   if (argc > 3)
>   {
> - int first = strtoul(args[1], NULL, 0);
> - int last = strtoul(args[2], NULL, 0);
> + uint32_t bank_nr;
> + uint32_t first;
> + uint32_t last;
> + int retval;
>   int set;
> - int retval;
> - flash_bank_t *p = get_flash_bank_by_num(strtoul(args[0], NULL, 
> 0));
> +
> + if ((retval = parse_u32(args[0], &bank_nr)) != ERROR_OK)
> + return retval;
> +
> + flash_bank_t *p = get_flash_bank_by_num(bank_nr);
>   if (!p)
> - {
> - command_print(cmd_ctx, "flash bank '#%s' is out of 
> bounds", args[0]);
>   return ERROR_OK;
> - }
>  
> + if ((retval = parse_u32(args[1], &first)) != ERROR_OK)
> + return retval;
> + if (strcmp(args[2], "last") == 0)
> + last = p->num_sectors - 1;
> + else
> + if ((retval = parse_u32(args[2], &last)) != ERROR_OK)
> +

Re: [Openocd-development] [PATCH] Enhancement: Allow -1 as last sector for protection and erase

2009-09-21 Thread Rolf Meeser
Hi Johnny,

it should be 
> +if ( first > last ) {
not
> +if ( first >= last ) {

With first=last you can erase a single sector.

Regards,
Rolf


--- Johnny Halfmoon  schrieb am Mo, 21.9.2009:

> Von: Johnny Halfmoon 
> Betreff: Re: [Openocd-development] [PATCH] Enhancement: Allow -1 as last 
> sector for protection and erase
> An: "David Brownell" 
> CC: openocd-development@lists.berlios.de
> Datum: Montag, 21. September 2009, 21:33
> 
> David Brownell wrote:
> > On Sunday 20 September 2009, Johnny Halfmoon wrote:
> >> +           
>    if ((retval =
> flash_check_sector_parameters(cmd_ctx, first, last,
> p->num_sectors)) !
> > 
> > I had in mind more like
> > 
> >     uint32_t value; 
> 
> 
> Okay. Like this then:
> 
> 
> = = = = = = = = = = = =
> 
> 
>  doc/openocd.texi  |    6 ++-
>  src/flash/flash.c |   97
> +++---
>  2 files changed, 67 insertions(+), 36 deletions(-)
> 
> Index: src/flash/flash.c
> ===
> --- src/flash/flash.c    (revision 2736)
> +++ src/flash/flash.c    (working copy)
> @@ -559,40 +559,62 @@
>      return ERROR_OK;
>  }
>  
> +int flash_check_sector_parameters(struct command_context_s
> *cmd_ctx, uint32_t first, uint32_t last, uint num_sectors)
> +{
> +    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);
> +        uint32_t bank_nr;
> +        uint32_t first;
> +        uint32_t last;
>          int retval;
> -        flash_bank_t *p =
> get_flash_bank_by_num(strtoul(args[0], NULL, 0));
> +
> +        if ((retval =
> parse_u32(args[0], &bank_nr)) != ERROR_OK)
> +           
> return retval;
> +
> +        flash_bank_t *p =
> get_flash_bank_by_num(bank_nr);
> +        if (!p)
> +           
> return ERROR_OK;
> +
> +        if ((retval =
> parse_u32(args[1], &first)) != ERROR_OK)
> +           
> return retval;
> +        if (strcmp(args[2],
> "last") == 0)
> +           
> last = p->num_sectors - 1;
> +        else
> +           
> if ((retval = parse_u32(args[2], &last)) != ERROR_OK)
> +           
>     return retval;
> +
> +        if ((retval =
> flash_check_sector_parameters(cmd_ctx, first, last,
> p->num_sectors)) != ERROR_OK)
> +           
> return retval;
> +
>          duration_t
> duration;
>          char
> *duration_text;
> -
>         
> duration_start_measure(&duration);
>  
> -        if (!p)
> -        {
> -           
> return ERROR_COMMAND_SYNTAX_ERROR;
> -        }
> -
> -        if ((retval =
> flash_driver_erase(p, first, last)) == ERROR_OK)
> -        {
> +        if ((retval =
> flash_driver_erase(p, first, last)) == ERROR_OK) {
>             
> if ((retval = duration_stop_measure(&duration,
> &duration_text)) != ERROR_OK)
> -           
> {
>             
>     return retval;
> -           
> }
> -
> -           
> command_print(cmd_ctx, "erased sectors %i through %i on
> flash bank %li in %s",
> -           
>     first, last, strtoul(args[0], 0, 0),
> duration_text);
> +           
> command_print(cmd_ctx, "erased sectors %i through %i on
> flash bank %i in %s",
> +           
>     first, last, bank_nr, duration_text);
>             
> free(duration_text);
>          }
>      }
>      else
> -    {
>          return
> ERROR_COMMAND_SYNTAX_ERROR;
> -    }
>  
>      return ERROR_OK;
>  }
> @@ -601,40 +623,47 @@
>  {
>      if (argc > 3)
>      {
> -        int first =
> strtoul(args[1], NULL, 0);
> -        int last =
> strtoul(args[2], NULL, 0);
> +        uint32_t bank_nr;
> +        uint32_t first;
> +        uint32_t last;
> +        int retval;
>          int set;
> -        int retval;
> -        flash_bank_t *p =
> get_flash_bank_by_num(strtoul(args[0], NULL, 0));
> +
> +        if ((retval =
> parse_u32(args[0], &am

Re: [Openocd-development] [PATCH] Enhancement: Allow -1 as last sector for protection and erase

2009-09-21 Thread Johnny Halfmoon

David Brownell wrote:
> On Sunday 20 September 2009, Johnny Halfmoon wrote:
>> +   if ((retval = flash_check_sector_parameters(cmd_ctx, first, 
>> last, p->num_sectors)) !
> 
> I had in mind more like
> 
>   uint32_t value; 


Okay. Like this then:


= = = = = = = = = = = =


 doc/openocd.texi  |6 ++-
 src/flash/flash.c |   97 +++---
 2 files changed, 67 insertions(+), 36 deletions(-)

Index: src/flash/flash.c
===
--- src/flash/flash.c   (revision 2736)
+++ src/flash/flash.c   (working copy)
@@ -559,40 +559,62 @@
return ERROR_OK;
 }
 
+int flash_check_sector_parameters(struct command_context_s *cmd_ctx, uint32_t 
first, uint32_t last, uint num_sectors)
+{
+   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);
+   uint32_t bank_nr;
+   uint32_t first;
+   uint32_t last;
int retval;
-   flash_bank_t *p = get_flash_bank_by_num(strtoul(args[0], NULL, 
0));
+
+   if ((retval = parse_u32(args[0], &bank_nr)) != ERROR_OK)
+   return retval;
+
+   flash_bank_t *p = get_flash_bank_by_num(bank_nr);
+   if (!p)
+   return ERROR_OK;
+
+   if ((retval = parse_u32(args[1], &first)) != ERROR_OK)
+   return retval;
+   if (strcmp(args[2], "last") == 0)
+   last = p->num_sectors - 1;
+   else
+   if ((retval = parse_u32(args[2], &last)) != ERROR_OK)
+   return retval;
+
+   if ((retval = flash_check_sector_parameters(cmd_ctx, first, 
last, p->num_sectors)) != ERROR_OK)
+   return retval;
+
duration_t duration;
char *duration_text;
-
duration_start_measure(&duration);
 
-   if (!p)
-   {
-   return ERROR_COMMAND_SYNTAX_ERROR;
-   }
-
-   if ((retval = flash_driver_erase(p, first, last)) == ERROR_OK)
-   {
+   if ((retval = flash_driver_erase(p, first, last)) == ERROR_OK) {
if ((retval = duration_stop_measure(&duration, 
&duration_text)) != ERROR_OK)
-   {
return retval;
-   }
-
-   command_print(cmd_ctx, "erased sectors %i through %i on 
flash bank %li in %s",
-   first, last, strtoul(args[0], 0, 0), 
duration_text);
+   command_print(cmd_ctx, "erased sectors %i through %i on 
flash bank %i in %s",
+   first, last, bank_nr, duration_text);
free(duration_text);
}
}
else
-   {
return ERROR_COMMAND_SYNTAX_ERROR;
-   }
 
return ERROR_OK;
 }
@@ -601,40 +623,47 @@
 {
if (argc > 3)
{
-   int first = strtoul(args[1], NULL, 0);
-   int last = strtoul(args[2], NULL, 0);
+   uint32_t bank_nr;
+   uint32_t first;
+   uint32_t last;
+   int retval;
int set;
-   int retval;
-   flash_bank_t *p = get_flash_bank_by_num(strtoul(args[0], NULL, 
0));
+
+   if ((retval = parse_u32(args[0], &bank_nr)) != ERROR_OK)
+   return retval;
+
+   flash_bank_t *p = get_flash_bank_by_num(bank_nr);
if (!p)
-   {
-   command_print(cmd_ctx, "flash bank '#%s' is out of 
bounds", args[0]);
return ERROR_OK;
-   }
 
+   if ((retval = parse_u32(args[1], &first)) != ERROR_OK)
+   return retval;
+   if (strcmp(args[2], "last") == 0)
+   last = p->num_sectors - 1;
+   else
+   if ((retval = parse_u32(args[2], &last)) != ERROR_OK)
+   return retval;
+
if (strcmp(args[3], "on") == 0)
set = 1;
else if (strcmp(args[3], "off") == 0)
set = 0;
else
-   {
return ERROR_

Re: [Openocd-development] [PATCH] Enhancement: Allow -1 as last sector for protection and erase

2009-09-20 Thread David Brownell
On Sunday 20 September 2009, Johnny Halfmoon wrote:
> +   if ((retval = flash_check_sector_parameters(cmd_ctx, first, 
> last, p->num_sectors)) !

I had in mind more like

uint32_t value;

retval = parse_u32(argv[X], &value);
if (retval != ERROR_OK)
return retval;

to replace the various unchecked

int value = strtoul(argv[X]);

statements.  That would cover the cases where the string was
not "last" (or "first"?) but was a broken number string.

You're right that there are _additional_ error cases to cope
with too ... you seem to have had your eyes on some different
failures in error checking than I did!  :)

How about updating your patch to swap out strtoul() calls
like that, so both sets of errors get checked?

You would be able to get rid of those check for negative
numbers that way, too.

- Dave

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH] Enhancement: Allow -1 as last sector for protection and erase

2009-09-20 Thread Johnny Halfmoon

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


Re: [Openocd-development] [PATCH] Enhancement: Allow -1 as last sector for protection and erase

2009-09-20 Thread Audrius Urmanavičius
On Sun, Sep 20, 2009 at 10:23 PM, Michael Schwingen
 wrote:
> David Brownell wrote:
>> Good point; Øyvind's suggestion (keyword "last") seems
>> to be the best overall solution then.
>>
>
> That would be my favourite, unless it needs ridiculous amounts of code
> to implement.

Agree 100%. What about the counterpart "first" to the "last" then? :-)

# flash erase 0 first last

Would look cute!


Kind regards,
Audrius Urmanavicius
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH] Enhancement: Allow -1 as last sector for protection and erase

2009-09-20 Thread Michael Schwingen
David Brownell wrote:
> Good point; Øyvind's suggestion (keyword "last") seems
> to be the best overall solution then.
>   

That would be my favourite, unless it needs ridiculous amounts of code
to implement.

cu
Michael


___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH] Enhancement: Allow -1 as last sector for protection and erase

2009-09-20 Thread Øyvind Harboe
Could you use a keyword like "last", rather than try to
overload the meaning of integers?

Using -1 is quicker, easier and more seductive


-- 
Øyvind Harboe
Embedded software and hardware consulting services
http://www.zylin.com
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH] Enhancement: Allow -1 as last sector for protection and erase

2009-09-20 Thread Michael Schwingen
David Brownell wrote:
>>  
>> +if (last < 0)
>> +last = p->num_sectors - 1;
>> +
>> 
>
> This relies on the lack of error checking for testing "first"
> and "last" ... better to add error checking, and then use zero
> as the magic number.
>   
Hm - would'nt that trigger when trying to erase only sector 0?

cu
Michael

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH] Enhancement: Allow -1 as last sector for protection and erase

2009-09-20 Thread David Brownell
On Sunday 20 September 2009, Johnny Halfmoon wrote:
> This patch slightly enhances the behaviour of the standard erase and protect 
> functions. After applying this patch, defining -1 as the last sector tells 
> OpenOCD to protect or erase the entire flash bank. The relevant part in the 
> OpenOCD has been updated.
> 
> Signed-off-by: Johnny Halfmoon 
> 
> ---
>  
>  doc/openocd.texi  |6 --
>  src/flash/flash.c |6 ++
>  2 files changed, 10 insertions(+), 2 deletions(-)
> 
> Index: trunk/src/flash/flash.c
> ===
> --- trunk/src/flash/flash.c   (revision 2736)
> +++ trunk/src/flash/flash.c   (working copy)
> @@ -577,6 +577,9 @@
>   return ERROR_COMMAND_SYNTAX_ERROR;
>   }
>  
> + if (last < 0)
> + last = p->num_sectors - 1;
> +

This relies on the lack of error checking for testing "first"
and "last" ... better to add error checking, and then use zero
as the magic number.

Zero would also fit in better to the docs for "erase_address"
which is *supposed* to accept zero to specify a similar special
case ... but unfortunately, tests "<= 0" for the error case
instead of "< 0" as it should.  Sigh; bug to fix.

>   if ((retval = flash_driver_erase(p, first, last)) == ERROR_OK)
>   {
>   if ((retval = duration_stop_measure(&duration, 
> &duration_text)) != ERROR_OK)
> @@ -621,6 +624,9 @@
>   return ERROR_COMMAND_SYNTAX_ERROR;
>   }
>  
> + if (last < 0)
> + last = p->num_sectors - 1;
> +

Ditto, as regards "last < 0" and error checking.

>   retval = flash_driver_protect(p, set, first, last);
>   if (retval == ERROR_OK)
>   {
> Index: trunk/doc/openocd.texi
> ===
> --- trunk/doc/openocd.texi(revision 2736)
> +++ trunk/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 
> -1 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 -1 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
> 
> 


___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH] Enhancement: Allow -1 as last sector for protection and erase

2009-09-20 Thread Johnny Halfmoon
This patch slightly enhances the behaviour of the standard erase and protect 
functions. After applying this patch, defining -1 as the last sector tells 
OpenOCD to protect or erase the entire flash bank. The relevant part in the 
OpenOCD has been updated.

Signed-off-by: Johnny Halfmoon 

---
 
 doc/openocd.texi  |6 --
 src/flash/flash.c |6 ++
 2 files changed, 10 insertions(+), 2 deletions(-)

Index: trunk/src/flash/flash.c
===
--- trunk/src/flash/flash.c (revision 2736)
+++ trunk/src/flash/flash.c (working copy)
@@ -577,6 +577,9 @@
return ERROR_COMMAND_SYNTAX_ERROR;
}
 
+   if (last < 0)
+   last = p->num_sectors - 1;
+
if ((retval = flash_driver_erase(p, first, last)) == ERROR_OK)
{
if ((retval = duration_stop_measure(&duration, 
&duration_text)) != ERROR_OK)
@@ -621,6 +624,9 @@
return ERROR_COMMAND_SYNTAX_ERROR;
}
 
+   if (last < 0)
+   last = p->num_sectors - 1;
+
retval = flash_driver_protect(p, set, first, last);
if (retval == ERROR_OK)
{
Index: trunk/doc/openocd.texi
===
--- trunk/doc/openocd.texi  (revision 2736)
+++ trunk/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 
-1 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 -1 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