Thomas Heijligen has uploaded this change for review.

View Change

default programmer: use programmer name instead of enum for default programmer

Change-Id: I976447787c6f6bfbdc0145d80d61e1ddcf97ac33
Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.de>
---
M Makefile
M cli_classic.c
M meson.build
M meson_options.txt
M tests/init_shutdown.c
M util/manibuilder/README.md
6 files changed, 39 insertions(+), 16 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/23/55123/1
diff --git a/Makefile b/Makefile
index 4eb4191..4f60d0b 100644
--- a/Makefile
+++ b/Makefile
@@ -44,14 +44,12 @@
# system attached to an external programmer while the default programmer is set to the internal programmer, and
# you forget to use the -p parameter. This would (try to) overwrite the existing firmware of the computer
# running flashrom). Please do not enable this without thinking about the possible consequences. Possible
-# values are those specified in enum programmer in programmer.h (which depend on other CONFIG_* options
-# evaluated below, namely those that enable/disable the various programmers).
-# Compilation will fail for unspecified values.
-CONFIG_DEFAULT_PROGRAMMER ?= PROGRAMMER_INVALID
+# values can be found when running 'flashrom --list-supported' under the 'Supported programmers' section.
+CONFIG_DEFAULT_PROGRAMMER_NAME ?=
# The following adds a default parameter for the default programmer set above (only).
-CONFIG_DEFAULT_PROGRAMMER_ARGS ?= ''
+CONFIG_DEFAULT_PROGRAMMER_ARGS ?=
# Example: compiling with
-# make CONFIG_DEFAULT_PROGRAMMER=PROGRAMMER_SERPROG CONFIG_DEFAULT_PROGRAMMER_ARGS="dev=/dev/ttyUSB0:1500000"
+# make CONFIG_DEFAULT_PROGRAMMER_NAME=serprog CONFIG_DEFAULT_PROGRAMMER_ARGS="dev=/dev/ttyUSB0:1500000"
# would make executing './flashrom' (almost) equivialent to './flashrom -p serprog:dev=/dev/ttyUSB0:1500000'.

# If your compiler spits out excessive warnings, run make WARNERROR=no
@@ -868,8 +866,12 @@
# Programmer drivers and programmer support infrastructure.
# Depending on the CONFIG_* variables set and verified above we set compiler flags and parameters below.

-FEATURE_CFLAGS += -D'CONFIG_DEFAULT_PROGRAMMER=$(CONFIG_DEFAULT_PROGRAMMER)'
+ifdef CONFIG_DEFAULT_PROGRAMMER_NAME
+FEATURE_CFLAGS += -D'CONFIG_DEFAULT_PROGRAMMER_NAME=$(CONFIG_DEFAULT_PROGRAMMER_NAME)'
+endif
+ifdef CONFIG_DEFAULT_PROGRAMMER_ARGS
FEATURE_CFLAGS += -D'CONFIG_DEFAULT_PROGRAMMER_ARGS="$(CONFIG_DEFAULT_PROGRAMMER_ARGS)"'
+endif

ifeq ($(CONFIG_INTERNAL), yes)
FEATURE_CFLAGS += -D'CONFIG_INTERNAL=1'
diff --git a/cli_classic.c b/cli_classic.c
index 4537e1e..49bec6d 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -172,7 +172,6 @@
int read_it = 0, extract_it = 0, write_it = 0, erase_it = 0, verify_it = 0;
int dont_verify_it = 0, dont_verify_all = 0, list_supported = 0, operation_specified = 0;
struct flashrom_layout *layout = NULL;
- // enum programmer prog = PROGRAMMER_INVALID;
static const struct programmer_entry *prog = NULL;
enum {
OPTION_IFD = 0x0100,
@@ -544,12 +543,24 @@
}

if (prog == NULL) {
- if (CONFIG_DEFAULT_PROGRAMMER != PROGRAMMER_INVALID) {
- prog = programmer_table[CONFIG_DEFAULT_PROGRAMMER];
+ #ifdef CONFIG_DEFAULT_PROGRAMMER_NAME
+ #define PASTER(x) &programmer_ ## x
+ #define EVALUATOR(x) PASTER(x)
+ static const struct programmer_entry *default_programmer = EVALUATOR(CONFIG_DEFAULT_PROGRAMMER_NAME);
+ #else
+ static const struct programmer_entry *default_programmer = NULL;
+ #endif
+
+ #ifndef CONFIG_DEFAULT_PROGRAMMER_ARGS
+ #define CONFIG_DEFAULT_PROGRAMMER_ARGS ""
+ #endif
+
+ if (default_programmer) {
+ prog = default_programmer;
/* We need to strdup here because we free(pparam) unconditionally later. */
pparam = strdup(CONFIG_DEFAULT_PROGRAMMER_ARGS);
msg_pinfo("Using default programmer \"%s\" with arguments \"%s\".\n",
- programmer_table[CONFIG_DEFAULT_PROGRAMMER]->name, pparam);
+ default_programmer->name, pparam);
} else {
msg_perr("Please select a programmer with the --programmer parameter.\n"
#if CONFIG_INTERNAL == 1
diff --git a/meson.build b/meson.build
index 1912605..0ce75b7 100644
--- a/meson.build
+++ b/meson.build
@@ -69,6 +69,8 @@
config_lspcon_i2c_spi = get_option('config_lspcon_i2c_spi')
config_realtek_mst_i2c_spi = get_option('config_realtek_mst_i2c_spi')
config_print_wiki= get_option('print_wiki')
+config_default_programmer_name = get_option('default_programmer_name')
+config_default_programmer_args = get_option('default_programmer_args')

cargs = []
deps = []
@@ -436,6 +438,14 @@
cargs += '-DCONFIG_PRINT_WIKI=1'
endif

+if config_default_programmer_name != ''
+ cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=' + config_default_programmer_name
+endif
+
+if config_default_programmer_args != ''
+ cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS=' + config_default_programmer_args
+endif
+
# we can't just link_with libflashrom as we require all the internal symbols...
executable(
'flashrom',
@@ -450,9 +460,7 @@
deps,
],
c_args : [
- cargs,
- '-DCONFIG_DEFAULT_PROGRAMMER=PROGRAMMER_INVALID',
- '-DCONFIG_DEFAULT_PROGRAMMER_ARGS=""',
+ cargs
],
install : true,
install_dir : sbindir,
diff --git a/meson_options.txt b/meson_options.txt
index cd92f10..86a38c8 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,6 +1,8 @@
option('pciutils', type : 'boolean', value : true, description : 'use pciutils')
option('usb', type : 'boolean', value : true, description : 'use libusb1')
option('print_wiki', type : 'boolean', value : true, description : 'Print Wiki')
+option('default_programmer_name', type : 'string', description : 'default programmer')
+option('default_programmer_args', type : 'string', description : 'default programmer arguments')

option('config_atahpt', type : 'boolean', value : false, description : 'Highpoint (HPT) ATA/RAID controllers')
option('config_atapromise', type : 'boolean', value : false, description : 'Promise ATA controller')
diff --git a/tests/init_shutdown.c b/tests/init_shutdown.c
index 85c29e2..e9977c5 100644
--- a/tests/init_shutdown.c
+++ b/tests/init_shutdown.c
@@ -44,5 +44,5 @@
* and the fallback to getpagesize(). This test does the latter (fallback to
* getpagesize).
*/
- run_lifecycle(state, PROGRAMMER_LINUX_SPI, "dev=/dev/null");
+ run_lifecycle(state, &programmer_linux_spi, "dev=/dev/null");
}
diff --git a/util/manibuilder/README.md b/util/manibuilder/README.md
index b00d618..193cd29 100644
--- a/util/manibuilder/README.md
+++ b/util/manibuilder/README.md
@@ -63,7 +63,7 @@
[...]
mani@63536fc102a5:~/flashrom$ make
[...]
- cc -MMD -Os -Wall -Wshadow -Werror -I/usr/include/libusb-1.0 -D'CONFIG_DEFAULT_PROGRAMMER=PROGRAMMER_INVALID' -D'CONFIG_DEFAULT_PROGRAMMER_ARGS="''"' -D'CONFIG_SERPROG=1' -D'CONFIG_PONY_SPI=1' -D'CONFIG_BITBANG_SPI=1' -D'CONFIG_GFXNVIDIA=1' -D'CONFIG_SATASII=1' -D'CONFIG_ATAVIA=1' -D'CONFIG_IT8212=1' -D'CONFIG_FT2232_SPI=1' -D'CONFIG_USBBLASTER_SPI=1' -D'CONFIG_PICKIT2_SPI=1' -D'HAVE_FT232H=1' -D'CONFIG_DUMMY=1' -D'CONFIG_DRKAISER=1' -D'CONFIG_NICINTEL=1' -D'CONFIG_NICINTEL_SPI=1' -D'CONFIG_NICINTEL_EEPROM=1' -D'CONFIG_OGP_SPI=1' -D'CONFIG_BUSPIRATE_SPI=1' -D'CONFIG_DEDIPROG=1' -D'CONFIG_DEVELOPERBOX_SPI=1' -D'CONFIG_LINUX_MTD=1' -D'CONFIG_LINUX_SPI=1' -D'CONFIG_CH341A_SPI=1' -D'CONFIG_DIGILENT_SPI=1' -D'NEED_PCI=1' -D'NEED_RAW_ACCESS=1' -D'NEED_LIBUSB0=1' -D'NEED_LIBUSB1=1' -D'HAVE_UTSNAME=1' -D'HAVE_CLOCK_GETTIME=1' -D'FLASHROM_VERSION="p1.0-141-g9cecc7e"' -o libflashrom.o -c libflashrom.c
+ cc -MMD -Os -Wall -Wshadow -Werror -I/usr/include/libusb-1.0 -D'CONFIG_SERPROG=1' -D'CONFIG_PONY_SPI=1' -D'CONFIG_BITBANG_SPI=1' -D'CONFIG_GFXNVIDIA=1' -D'CONFIG_SATASII=1' -D'CONFIG_ATAVIA=1' -D'CONFIG_IT8212=1' -D'CONFIG_FT2232_SPI=1' -D'CONFIG_USBBLASTER_SPI=1' -D'CONFIG_PICKIT2_SPI=1' -D'HAVE_FT232H=1' -D'CONFIG_DUMMY=1' -D'CONFIG_DRKAISER=1' -D'CONFIG_NICINTEL=1' -D'CONFIG_NICINTEL_SPI=1' -D'CONFIG_NICINTEL_EEPROM=1' -D'CONFIG_OGP_SPI=1' -D'CONFIG_BUSPIRATE_SPI=1' -D'CONFIG_DEDIPROG=1' -D'CONFIG_DEVELOPERBOX_SPI=1' -D'CONFIG_LINUX_MTD=1' -D'CONFIG_LINUX_SPI=1' -D'CONFIG_CH341A_SPI=1' -D'CONFIG_DIGILENT_SPI=1' -D'NEED_PCI=1' -D'NEED_RAW_ACCESS=1' -D'NEED_LIBUSB0=1' -D'NEED_LIBUSB1=1' -D'HAVE_UTSNAME=1' -D'HAVE_CLOCK_GETTIME=1' -D'FLASHROM_VERSION="p1.0-141-g9cecc7e"' -o libflashrom.o -c libflashrom.c
libflashrom.c:386:12: error: 'flashrom_layout_parse_fmap' defined but not used [-Werror=unused-function]
static int flashrom_layout_parse_fmap(struct flashrom_layout **layout,
^~~~~~~~~~~~~~~~~~~~~~~~~~

To view, visit change 55123. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I976447787c6f6bfbdc0145d80d61e1ddcf97ac33
Gerrit-Change-Number: 55123
Gerrit-PatchSet: 1
Gerrit-Owner: Thomas Heijligen <src@posteo.de>
Gerrit-MessageType: newchange