mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 23:22:37 +02:00
Fix and clean up cli_classic.c
Don't ignore -i if it is specified before -l Check if image mentioned by -i is present in layout file Consolidate duplicated programmer_shutdown calls Kill outdated comments Finish parameter checking before -L/-z is executed Corresponding to flashrom svn r1373. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: David Hendricks <dhendrix@google.com>
This commit is contained in:
parent
25b5a597e1
commit
d5660141ec
@ -117,6 +117,7 @@ int cli_classic(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
int operation_specified = 0;
|
int operation_specified = 0;
|
||||||
int i;
|
int i;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
static const char optstring[] = "r:Rw:v:nVEfc:m:l:i:p:Lzh";
|
static const char optstring[] = "r:Rw:v:nVEfc:m:l:i:p:Lzh";
|
||||||
static const struct option long_options[] = {
|
static const struct option long_options[] = {
|
||||||
@ -232,8 +233,14 @@ int cli_classic(int argc, char *argv[])
|
|||||||
cli_classic_abort_usage();
|
cli_classic_abort_usage();
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
|
/* FIXME: -l has to be specified before -i. */
|
||||||
tempstr = strdup(optarg);
|
tempstr = strdup(optarg);
|
||||||
find_romentry(tempstr);
|
if (find_romentry(tempstr)) {
|
||||||
|
fprintf(stderr, "Error: image %s not found in "
|
||||||
|
"layout file or -i specified before "
|
||||||
|
"-l\n", tempstr);
|
||||||
|
cli_classic_abort_usage();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
if (++operation_specified > 1) {
|
if (++operation_specified > 1) {
|
||||||
@ -313,6 +320,11 @@ int cli_classic(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (optind < argc) {
|
||||||
|
fprintf(stderr, "Error: Extra parameter found.\n");
|
||||||
|
cli_classic_abort_usage();
|
||||||
|
}
|
||||||
|
|
||||||
/* FIXME: Print the actions flashrom will take. */
|
/* FIXME: Print the actions flashrom will take. */
|
||||||
|
|
||||||
if (list_supported) {
|
if (list_supported) {
|
||||||
@ -327,11 +339,6 @@ int cli_classic(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (optind < argc) {
|
|
||||||
fprintf(stderr, "Error: Extra parameter found.\n");
|
|
||||||
cli_classic_abort_usage();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if CONFIG_INTERNAL == 1
|
#if CONFIG_INTERNAL == 1
|
||||||
if ((programmer != PROGRAMMER_INTERNAL) && (lb_part || lb_vendor)) {
|
if ((programmer != PROGRAMMER_INTERNAL) && (lb_part || lb_vendor)) {
|
||||||
fprintf(stderr, "Error: --mainboard requires the internal "
|
fprintf(stderr, "Error: --mainboard requires the internal "
|
||||||
@ -360,8 +367,8 @@ int cli_classic(int argc, char *argv[])
|
|||||||
|
|
||||||
if (programmer_init(pparam)) {
|
if (programmer_init(pparam)) {
|
||||||
fprintf(stderr, "Error: Programmer initialization failed.\n");
|
fprintf(stderr, "Error: Programmer initialization failed.\n");
|
||||||
programmer_shutdown();
|
ret = 1;
|
||||||
exit(1);
|
goto out_shutdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(flashes); i++) {
|
for (i = 0; i < ARRAY_SIZE(flashes); i++) {
|
||||||
@ -377,8 +384,8 @@ int cli_classic(int argc, char *argv[])
|
|||||||
for (i = 0; i < chipcount; i++)
|
for (i = 0; i < chipcount; i++)
|
||||||
printf(" %s", flashes[i].name);
|
printf(" %s", flashes[i].name);
|
||||||
printf("\nPlease specify which chip to use with the -c <chipname> option.\n");
|
printf("\nPlease specify which chip to use with the -c <chipname> option.\n");
|
||||||
programmer_shutdown();
|
ret = 1;
|
||||||
exit(1);
|
goto out_shutdown;
|
||||||
} else if (!chipcount) {
|
} else if (!chipcount) {
|
||||||
printf("No EEPROM/flash device found.\n");
|
printf("No EEPROM/flash device found.\n");
|
||||||
if (!force || !chip_to_probe) {
|
if (!force || !chip_to_probe) {
|
||||||
@ -389,15 +396,14 @@ int cli_classic(int argc, char *argv[])
|
|||||||
startchip = probe_flash(0, &flashes[0], 1);
|
startchip = probe_flash(0, &flashes[0], 1);
|
||||||
if (startchip == -1) {
|
if (startchip == -1) {
|
||||||
printf("Probing for flash chip '%s' failed.\n", chip_to_probe);
|
printf("Probing for flash chip '%s' failed.\n", chip_to_probe);
|
||||||
programmer_shutdown();
|
ret = 1;
|
||||||
exit(1);
|
goto out_shutdown;
|
||||||
}
|
}
|
||||||
printf("Please note that forced reads most likely contain garbage.\n");
|
printf("Please note that forced reads most likely contain garbage.\n");
|
||||||
return read_flash_to_file(&flashes[0], filename);
|
return read_flash_to_file(&flashes[0], filename);
|
||||||
}
|
}
|
||||||
// FIXME: flash writes stay enabled!
|
ret = 1;
|
||||||
programmer_shutdown();
|
goto out_shutdown;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fill_flash = &flashes[0];
|
fill_flash = &flashes[0];
|
||||||
@ -409,22 +415,19 @@ int cli_classic(int argc, char *argv[])
|
|||||||
(!force)) {
|
(!force)) {
|
||||||
fprintf(stderr, "Chip is too big for this programmer "
|
fprintf(stderr, "Chip is too big for this programmer "
|
||||||
"(-V gives details). Use --force to override.\n");
|
"(-V gives details). Use --force to override.\n");
|
||||||
programmer_shutdown();
|
ret = 1;
|
||||||
return 1;
|
goto out_shutdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(read_it | write_it | verify_it | erase_it)) {
|
if (!(read_it | write_it | verify_it | erase_it)) {
|
||||||
printf("No operations were specified.\n");
|
printf("No operations were specified.\n");
|
||||||
// FIXME: flash writes stay enabled!
|
goto out_shutdown;
|
||||||
programmer_shutdown();
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filename && !erase_it) {
|
if (!filename && !erase_it) {
|
||||||
printf("Error: No filename specified.\n");
|
printf("Error: No filename specified.\n");
|
||||||
// FIXME: flash writes stay enabled!
|
ret = 1;
|
||||||
programmer_shutdown();
|
goto out_shutdown;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Always verify write operations unless -n is used. */
|
/* Always verify write operations unless -n is used. */
|
||||||
@ -437,4 +440,8 @@ int cli_classic(int argc, char *argv[])
|
|||||||
*/
|
*/
|
||||||
programmer_delay(100000);
|
programmer_delay(100000);
|
||||||
return doit(fill_flash, force, filename, read_it, write_it, erase_it, verify_it);
|
return doit(fill_flash, force, filename, read_it, write_it, erase_it, verify_it);
|
||||||
|
|
||||||
|
out_shutdown:
|
||||||
|
programmer_shutdown();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user