[flashrom] [PATCH] No default driver if more than one driver is available

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Fri Jul 6 03:28:35 CEST 2012


If only one programmer driver is compiled in, make that driver the
default. If more than one driver is compiled in, require --programmer
specification at the command line.

3 results from a default flashrom configuration:

compiler at p35:/sources/tmptrees/ready/flashrom-programmer_no_default>
./flashrom
flashrom v0.9.5.2-r1547 on Linux 2.6.34.10-0.6-default (i686)
Please select a programmer with --programmer . Valid choices are:
internal, dummy, nic3com, nicrealtek, gfxnvidia, drkaiser, satasii,
ft2232_spi,
serprog, buspirate_spi, rayer_spi, pony_spi, nicintel, nicintel_spi,
ogp_spi,
satamv, linux_spi

compiler at p35:/sources/tmptrees/ready/flashrom-programmer_no_default>
./flashrom -p foo
flashrom v0.9.5.2-r1547 on Linux 2.6.34.10-0.6-default (i686)
Error: Unknown programmer foo. Valid choices are:
internal, dummy, nic3com, nicrealtek, gfxnvidia, drkaiser, satasii,
ft2232_spi,
serprog, buspirate_spi, rayer_spi, pony_spi, nicintel, nicintel_spi,
ogp_spi,
satamv, linux_spi
Please run "flashrom --help" for usage info.

compiler at p35:/sources/tmptrees/ready/flashrom-programmer_no_default>
./flashrom -p internal -p internal
flashrom v0.9.5.2-r1547 on Linux 2.6.34.10-0.6-default (i686)
Error: --programmer specified more than once. You can separate multiple
parameters for a programmer with ",". Please see the man page for details.
Please run "flashrom --help" for usage info.

1 result from a flashrom configuration with only dummy compiled in:

compiler at p35:/sources/tmptrees/ready/flashrom-programmer_no_default>
./flashrom
flashrom v0.9.5.2-r1547 on Linux 2.6.34.10-0.6-default (i686)
Calibrating delay loop... OK.
No EEPROM/flash device found.
Note: flashrom can never write if the flash chip isn't found automatically.


This patch represents rough consensus from IRC. I would like to require
--programmer in all cases to make sure nobody gets bitten by two
different single-programmer builds (e.g. dediprog and internal), but
this patch is already a step in the right direction.

Please check that the printed error messages make sense. I took the
liberty of removing "flashrom is free software..." from the output to
keep this mail readable.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>

Index: flashrom-programmer_no_default/cli_classic.c
===================================================================
--- flashrom-programmer_no_default/cli_classic.c	(Revision 1547)
+++ flashrom-programmer_no_default/cli_classic.c	(Arbeitskopie)
@@ -31,20 +31,19 @@
 #include "flashchips.h"
 #include "programmer.h"
 
-#if CONFIG_INTERNAL == 1
-static enum programmer default_programmer = PROGRAMMER_INTERNAL;
-#elif CONFIG_DUMMY == 1
-static enum programmer default_programmer = PROGRAMMER_DUMMY;
-#else
-/* If neither internal nor dummy are selected, we must pick a sensible default.
- * Since there is no reason to prefer a particular external programmer, we fail
- * if more than one of them is selected. If only one is selected, it is clear
- * that the user wants that one to become the default.
+/* If only one programmer is compiled in, it is the default.
+ * In all other cases there is no default and the user has to specify the programmer with -p .
  */
+static enum programmer default_programmer =
 #if CONFIG_NIC3COM+CONFIG_NICREALTEK+CONFIG_NICNATSEMI+CONFIG_GFXNVIDIA+CONFIG_DRKAISER+CONFIG_SATASII+CONFIG_ATAHPT+CONFIG_FT2232_SPI+CONFIG_SERPROG+CONFIG_BUSPIRATE_SPI+CONFIG_DEDIPROG+CONFIG_RAYER_SPI+CONFIG_NICINTEL+CONFIG_NICINTEL_SPI+CONFIG_OGP_SPI+CONFIG_SATAMV > 1
-#error Please enable either CONFIG_DUMMY or CONFIG_INTERNAL or disable support for all programmers except one.
+	PROGRAMMER_INVALID
+#else
+#if CONFIG_INTERNAL == 1
+	PROGRAMMER_INTERNAL
 #endif
-static enum programmer default_programmer =
+#if CONFIG_DUMMY == 1
+	PROGRAMMER_DUMMY
+#endif
 #if CONFIG_NIC3COM == 1
 	PROGRAMMER_NIC3COM
 #endif
@@ -96,8 +95,8 @@
 #if CONFIG_LINUX_SPI == 1
 	PROGRAMMER_LINUX_SPI
 #endif
+#endif
 ;
-#endif
 
 static void cli_classic_usage(const char *name)
 {
@@ -107,11 +106,11 @@
 #endif
 	         "-E|-r <file>|-w <file>|-v <file>]\n"
 	       "       [-c <chipname>] [-l <file>] [-o <file>]\n"
-	       "       [-i <image>] [-p <programmername>[:<parameters>]]\n\n");
+	       "       [-i <image>] -p <programmername>[:<parameters>]\n\n");
 
 	printf("Please note that the command line interface for flashrom has "
 	         "changed between\n"
-	       "0.9.1 and 0.9.2 and will change again before flashrom 1.0.\n"
+	       "0.9.5 and 0.9.6 and will change again before flashrom 1.0.\n"
 	       "Do not use flashrom in scripts or other automated tools "
 	         "without checking\n"
 	       "that your flashrom version won't interpret options in a "
@@ -360,8 +359,8 @@
 				}
 			}
 			if (prog == PROGRAMMER_INVALID) {
-				fprintf(stderr, "Error: Unknown programmer "
-					"%s.\n", optarg);
+				fprintf(stderr, "Error: Unknown programmer %s. Valid choices are:\n", optarg);
+				list_programmers_linebreak(0, 80, 0);
 				cli_classic_abort_usage();
 			}
 			break;
@@ -469,7 +468,15 @@
 	}
 
 	if (prog == PROGRAMMER_INVALID)
-		prog = default_programmer;
+		if (default_programmer == PROGRAMMER_INVALID) {
+			/* More than one programmer compiled in, there is no default choice. */
+			msg_perr("Please select a programmer with --programmer . Valid choices are:\n");
+			list_programmers_linebreak(0, 80, 0);
+			ret = 1;
+			goto out;
+		} else {
+			prog = default_programmer;
+		}
 
 	/* FIXME: Delay calibration should happen in programmer code. */
 	myusec_calibrate_delay();


-- 
http://www.hailfinger.org/





More information about the flashrom mailing list