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 <jhalfm...@milksnot.com> schrieb am Mo, 21.9.2009: > Von: Johnny Halfmoon <jhalfm...@milksnot.com> > Betreff: Re: [Openocd-development] [PATCH] Enhancement: Allow -1 as last > sector for protection and erase > An: "David Brownell" <davi...@pacbell.net> > 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], &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_COMMAND_SYNTAX_ERROR; > - } > > + 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) > - { > - > command_print(cmd_ctx, "%s protection for sectors %i through > %i on flash bank %li", > + 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)); > + > last, bank_nr); > } > } > 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 > _______________________________________________ Openocd-development mailing list Openocd-development@lists.berlios.de https://lists.berlios.de/mailman/listinfo/openocd-development