summaryrefslogtreecommitdiffstats
path: root/flashrom.c
diff options
context:
space:
mode:
authorCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2009-08-12 14:34:35 +0000
committerCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2009-08-12 14:34:35 +0000
commit37fc469ca2cc2e7ec21b9afae8627f3445dd40a4 (patch)
treec4233a1eca860cdb27fd10c779923be72267eb74 /flashrom.c
parentef58a9ce3f9ae3ce0db34861f0c2d24373712138 (diff)
downloadast2050-flashrom-37fc469ca2cc2e7ec21b9afae8627f3445dd40a4.zip
ast2050-flashrom-37fc469ca2cc2e7ec21b9afae8627f3445dd40a4.tar.gz
Add a new field for the names of programmers and use it to match against user input
Use programmer.name to match the --programmer parameter instead of hardcoding the name of every single programmer in main(). -p dummyfoo won't be mistaken for -p dummy anymore. Corresponding to flashrom svn r680. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Stefan Reinauer <stepan@coresystems.de>
Diffstat (limited to 'flashrom.c')
-rw-r--r--flashrom.c68
1 files changed, 38 insertions, 30 deletions
diff --git a/flashrom.c b/flashrom.c
index a51fd63..217701a 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -38,6 +38,7 @@ char *programmer_param = NULL;
const struct programmer_entry programmer_table[] = {
{
+ .name = "internal",
.init = internal_init,
.shutdown = internal_shutdown,
.map_flash_region = physmap,
@@ -54,6 +55,7 @@ const struct programmer_entry programmer_table[] = {
},
{
+ .name = "dummy",
.init = dummy_init,
.shutdown = dummy_shutdown,
.map_flash_region = dummy_map,
@@ -70,6 +72,7 @@ const struct programmer_entry programmer_table[] = {
},
{
+ .name = "nic3com",
.init = nic3com_init,
.shutdown = nic3com_shutdown,
.map_flash_region = fallback_map,
@@ -86,6 +89,7 @@ const struct programmer_entry programmer_table[] = {
},
{
+ .name = "satasii",
.init = satasii_init,
.shutdown = satasii_shutdown,
.map_flash_region = fallback_map,
@@ -102,6 +106,7 @@ const struct programmer_entry programmer_table[] = {
},
{
+ .name = "it87spi",
.init = it87spi_init,
.shutdown = fallback_shutdown,
.map_flash_region = fallback_map,
@@ -118,6 +123,7 @@ const struct programmer_entry programmer_table[] = {
},
{
+ .name = "ft2232spi",
.init = ft2232_spi_init,
.shutdown = fallback_shutdown,
.map_flash_region = fallback_map,
@@ -134,6 +140,7 @@ const struct programmer_entry programmer_table[] = {
},
{
+ .name = "serprog",
.init = serprog_init,
.shutdown = serprog_shutdown,
.map_flash_region = fallback_map,
@@ -149,7 +156,7 @@ const struct programmer_entry programmer_table[] = {
.delay = serprog_delay,
},
- {},
+ {}, /* This entry corresponds to PROGRAMMER_INVALID. */
};
int programmer_init(void)
@@ -523,6 +530,8 @@ int main(int argc, char *argv[])
FILE *image;
/* Probe for up to three flash chips. */
struct flashchip *flash, *flashes[3];
+ const char *name;
+ int namelen;
int opt;
int option_index = 0;
int force = 0;
@@ -565,6 +574,12 @@ int main(int argc, char *argv[])
printf_debug("%s\n", argv[i]);
}
+ /* Safety check. */
+ if (ARRAY_SIZE(programmer_table) - 1 != PROGRAMMER_INVALID) {
+ fprintf(stderr, "Programmer table miscompilation!\n");
+ exit(1);
+ }
+
setbuf(stdout, NULL);
while ((opt = getopt_long(argc, argv, "rRwvnVEfc:m:l:i:p:Lzh",
long_options, &option_index)) != EOF) {
@@ -641,35 +656,28 @@ int main(int argc, char *argv[])
list_supported_wiki = 1;
break;
case 'p':
- if (strncmp(optarg, "internal", 8) == 0) {
- programmer = PROGRAMMER_INTERNAL;
- if (optarg[8] == '=')
- programmer_param = strdup(optarg + 9);
- } else if (strncmp(optarg, "dummy", 5) == 0) {
- programmer = PROGRAMMER_DUMMY;
- if (optarg[5] == '=')
- programmer_param = strdup(optarg + 6);
- } else if (strncmp(optarg, "nic3com", 7) == 0) {
- programmer = PROGRAMMER_NIC3COM;
- if (optarg[7] == '=')
- programmer_param = strdup(optarg + 8);
- } else if (strncmp(optarg, "satasii", 7) == 0) {
- programmer = PROGRAMMER_SATASII;
- if (optarg[7] == '=')
- programmer_param = strdup(optarg + 8);
- } else if (strncmp(optarg, "it87spi", 7) == 0) {
- programmer = PROGRAMMER_IT87SPI;
- if (optarg[7] == '=')
- programmer_param = strdup(optarg + 8);
- } else if (strncmp(optarg, "ft2232spi", 9) == 0) {
- programmer = PROGRAMMER_FT2232SPI;
- if (optarg[9] == '=')
- programmer_param = strdup(optarg + 10);
- } else if (strncmp(optarg, "serprog", 7) == 0) {
- programmer = PROGRAMMER_SERPROG;
- if (optarg[7] == '=')
- programmer_param = strdup(optarg + 8);
- } else {
+ for (programmer = 0; programmer < PROGRAMMER_INVALID; programmer++) {
+ name = programmer_table[programmer].name;
+ namelen = strlen(name);
+ if (strncmp(optarg, name, namelen) == 0) {
+ switch (optarg[namelen]) {
+ case '=':
+ programmer_param = strdup(optarg + namelen + 1);
+ break;
+ case '\0':
+ break;
+ default:
+ /* The continue refers to the
+ * for loop. It is here to be
+ * able to differentiate between
+ * foo and foobar.
+ */
+ continue;
+ }
+ break;
+ }
+ }
+ if (programmer == PROGRAMMER_INVALID) {
printf("Error: Unknown programmer.\n");
exit(1);
}
OpenPOWER on IntegriCloud