Modified erase command to allow mass and segment erase.

This commit is contained in:
Daniel Beer 2010-09-23 16:08:45 +12:00
parent b9e5db63d5
commit 0dade4228e
4 changed files with 41 additions and 7 deletions

View File

@ -124,8 +124,10 @@ const struct cmddb_record commands[] = {
.name = "erase",
.func = cmd_erase,
.help =
"erase\n"
" Erase the device under test.\n"
"erase [all|segment] [address]\n"
" Erase the device under test. With no arguments, erases all of main\n"
" memory. Specify arguments to perform a mass erase, or to erase\n"
" individual segments.\n"
},
{
.name = "step",

View File

@ -138,11 +138,38 @@ int cmd_reset(char **arg)
int cmd_erase(char **arg)
{
const char *type_text = get_arg(arg);
const char *seg_text = get_arg(arg);
device_erase_type_t type = DEVICE_ERASE_MAIN;
address_t segment = 0;
if (seg_text && expr_eval(stab_default, seg_text, &segment) < 0) {
printc_err("erase: invalid expression: %s\n", seg_text);
return -1;
}
if (type_text) {
if (!strcasecmp(type_text, "all")) {
type = DEVICE_ERASE_ALL;
} else if (!strcasecmp(type_text, "segment")) {
type = DEVICE_ERASE_SEGMENT;
if (!seg_text) {
printc_err("erase: expected segment "
"address\n");
return -1;
}
} else {
printc_err("erase: unknown erase type: %s\n",
type_text);
return -1;
}
}
if (device_default->ctl(device_default, DEVICE_CTL_HALT) < 0)
return -1;
printc("Erasing...\n");
return device_default->erase(device_default, DEVICE_ERASE_MAIN, 0);
return device_default->erase(device_default, type, segment);
}
int cmd_step(char **arg)

View File

@ -168,9 +168,14 @@ length (64 bytes) is disassembled and shown.
If symbols are available, then all addresses used as operands are
translated into \fIsymbol\fR+\fIoffset\fR form.
.IP "\fBerase\fR"
Erase the device under test. All code memory is erased (but not
information or boot memory).
.IP "\fBerase\fR [\fIall\fR|\fIsegment\fR] [\fIaddress\fR]"
Erase the device under test. With no arguments, all code memory is erased
(but not information or boot memory). With the argument "all", a mass
erase is performed (the results may depend on the state of the LOCKA
bit in the flash memory controller).
Specify "segment" and a memory address to erase an individual flash
segment.
.IP "\fBgdb\fR [\fIport\fR]"
Start a GDB remote stub, optionally specifying a TCP port to listen on.
If no port is given, the default port is 2000.

2
sim.c
View File

@ -530,7 +530,7 @@ static int sim_erase(device_t dev_base, device_erase_type_t type,
break;
case DEVICE_ERASE_ALL:
memset(dev->memory + 0x1000, 0xff, 256);
memset(dev->memory, 0xff, MEM_SIZE);
break;
case DEVICE_ERASE_SEGMENT: