summaryrefslogtreecommitdiff
path: root/src/flash/nor/tcl.c
diff options
context:
space:
mode:
authorDavid Brownell <dbrownell@users.sourceforge.net>2010-01-13 23:33:25 -0800
committerDavid Brownell <dbrownell@users.sourceforge.net>2010-01-13 23:33:25 -0800
commit73566405b6e105b0a8b7f21db48331926bec97ad (patch)
treed1f38082d0c060b6220a265470b35685c8426907 /src/flash/nor/tcl.c
parentd91941d5a01ca0b9d43571edc03ba18741076cca (diff)
downloadopenocd_libswd-73566405b6e105b0a8b7f21db48331926bec97ad.tar.gz
openocd_libswd-73566405b6e105b0a8b7f21db48331926bec97ad.tar.bz2
openocd_libswd-73566405b6e105b0a8b7f21db48331926bec97ad.tar.xz
openocd_libswd-73566405b6e105b0a8b7f21db48331926bec97ad.zip
NOR: add optional "flash erase_address" sector padding
Add a NOR flash mechanism where erase_address ranges can be padded out to sector boundaries, triggering a diagnostic: > flash erase_address 0x0001f980 16 address range 0x0001f980 .. 0x0001f98f is not sector-aligned Command handler execution failed in procedure 'flash' called at file "command.c", line 647 called at file "command.c", line 361 > > flash erase_address pad 0x0001f980 16 Adding extra erase range, 0x0001f800 to 0x0001f97f Adding extra erase range, 0x0001f990 to 0x0001fbff erased address 0x0001f980 (length 16) in 0.095975s (0.163 kb/s) > This addresses what would otherwise be something of a functional regression. An earlier version of the interface had a dangerous problem: it would silently erase data outside the range it was told to erase. Fixing that bug turned up some folk who relied on that unsafe behavior. (The classic problem with interface bugs!) Now they can get that behavior again. If they really need it, just specify "pad". Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Diffstat (limited to 'src/flash/nor/tcl.c')
-rw-r--r--src/flash/nor/tcl.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c
index b7e80df2..cf40a81a 100644
--- a/src/flash/nor/tcl.c
+++ b/src/flash/nor/tcl.c
@@ -203,14 +203,29 @@ COMMAND_HANDLER(handle_flash_erase_address_command)
int retval;
int address;
int length;
-
+ bool do_pad = false;
struct target *target = get_current_target(CMD_CTX);
- if (CMD_ARGC != 2)
+ switch (CMD_ARGC) {
+ case 3:
+ /* Optionally pad out the address range to block/sector
+ * boundaries. We can't know if there's data in that part
+ * of the flash; only do padding if we're told to.
+ */
+ if (strcmp("pad", CMD_ARGV[0]) != 0)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ do_pad = true;
+ CMD_ARGC--;
+ CMD_ARGV++;
+ /* FALL THROUGH */
+ case 2:
+ COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], address);
+ COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], length);
+ break;
+ default:
return ERROR_COMMAND_SYNTAX_ERROR;
+ }
- COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], address);
- COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], length);
if (length <= 0)
{
command_print(CMD_CTX, "Length must be >0");
@@ -229,7 +244,7 @@ COMMAND_HANDLER(handle_flash_erase_address_command)
struct duration bench;
duration_start(&bench);
- retval = flash_erase_address_range(target, address, length);
+ retval = flash_erase_address_range(target, do_pad, address, length);
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
{
@@ -698,9 +713,12 @@ static const struct command_registration flash_exec_command_handlers[] = {
.name = "erase_address",
.handler = handle_flash_erase_address_command,
.mode = COMMAND_EXEC,
- .usage = "address length",
- .help = "Erase flash blocks starting at address "
- "and continuing for length bytes.",
+ .usage = "['pad'] address length",
+ .help = "Erase flash sectors starting at address and "
+ "continuing for length bytes. If 'pad' is specified, "
+ "data outside that range may also be erased: the start "
+ "address may be decreased, and length increased, so "
+ "that all of the first and last sectors are erased.",
},
{
.name = "fillw",