added -E option for chip erase, remove duplicated code

git-svn-id: svn://svn.coreboot.org/coreboot/trunk@1815 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
Li-Ta Lo
2004-12-08 20:10:01 +00:00
parent 19b6945a40
commit 257a58b60d
6 changed files with 49 additions and 147 deletions

View File

@@ -194,7 +194,8 @@ int main(int argc, char *argv[])
FILE *image;
struct flashchip *flash;
int opt;
int read_it = 0, write_it = 0, verify_it = 0, verbose = 0;
int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0,
verbose = 0;
char *filename = NULL;
@@ -211,7 +212,7 @@ int main(int argc, char *argv[])
setbuf(stdout, NULL);
while ((opt = getopt(argc, argv, "rwvVc:s:e:")) != EOF) {
while ((opt = getopt(argc, argv, "rwvVEc:s:e:")) != EOF) {
switch (opt) {
case 'r':
read_it = 1;
@@ -228,6 +229,9 @@ int main(int argc, char *argv[])
case 'V':
verbose = 1;
break;
case 'E':
erase_it = 1;
break;
case 's':
tempstr = strdup(optarg);
sscanf(tempstr,"%x",&exclude_start_position);
@@ -266,14 +270,18 @@ int main(int argc, char *argv[])
}
printf("Part is %s\n", flash->name);
if (!filename) {
if (!filename && !erase_it) {
printf("OK, only ENABLING flash write, but NOT FLASHING\n");
return 0;
}
size = flash->total_size * 1024;
buf = (char *) calloc(size, sizeof(char));
if (read_it) {
if (erase_it) {
printf("Erasing flash chip\n");
flash->erase(flash);
exit(0);
} else if (read_it) {
if ((image = fopen(filename, "w")) == NULL) {
perror(filename);
exit(1);