programmer_init: use struct programmer_entry*

Change-Id: Iacf0f25abc94a84c5d52c8d69a3e8640817b060a
Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.de>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/55121
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
diff --git a/cli_classic.c b/cli_classic.c
index f3ae123..ba6885c 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -562,7 +562,7 @@
 	/* FIXME: Delay calibration should happen in programmer code. */
 	myusec_calibrate_delay();
 
-	if (programmer_init(prog, pparam)) {
+	if (programmer_init(programmer_table[prog], pparam)) {
 		msg_perr("Error: Programmer initialization failed.\n");
 		ret = 1;
 		goto out_shutdown;
diff --git a/flashrom.c b/flashrom.c
index 9a7fb18..c3bab17 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -130,15 +130,15 @@
 	return rc;
 }
 
-int programmer_init(enum programmer prog, const char *param)
+int programmer_init(const struct programmer_entry *prog, const char *param)
 {
 	int ret;
 
-	if (prog >= programmer_table_size) {
+	if (prog == NULL) {
 		msg_perr("Invalid programmer specified!\n");
 		return -1;
 	}
-	programmer = programmer_table[prog];
+	programmer = prog;
 	/* Initialize all programmer specific data. */
 	/* Default to unlimited decode sizes. */
 	max_rom_decode = (const struct decode_sizes) {
diff --git a/libflashrom.c b/libflashrom.c
index 1a8b051..67d3ef3 100644
--- a/libflashrom.c
+++ b/libflashrom.c
@@ -287,7 +287,7 @@
 		list_programmers_linebreak(0, 80, 0);
 		return 1;
 	}
-	return programmer_init(prog, prog_param);
+	return programmer_init(programmer_table[prog], prog_param);
 }
 
 /**
diff --git a/programmer.h b/programmer.h
index 0dda67e..809674f 100644
--- a/programmer.h
+++ b/programmer.h
@@ -178,7 +178,7 @@
 extern const struct programmer_entry *const programmer_table[];
 extern const size_t programmer_table_size;
 
-int programmer_init(enum programmer prog, const char *param);
+int programmer_init(const struct programmer_entry *prog, const char *param);
 int programmer_shutdown(void);
 
 struct bitbang_spi_master {
diff --git a/tests/init_shutdown.c b/tests/init_shutdown.c
index 4d9c549..80440bd 100644
--- a/tests/init_shutdown.c
+++ b/tests/init_shutdown.c
@@ -19,22 +19,22 @@
 #include "io_mock.h"
 #include "programmer.h"
 
-static void run_lifecycle(void **state, enum programmer prog, const char *param)
+static void run_lifecycle(void **state, const struct programmer_entry *prog, const char *param)
 {
 	(void) state; /* unused */
 
-	printf("Testing programmer_init for programmer=%u ...\n", prog);
+	printf("Testing programmer_init for programmer=%s ...\n", prog->name);
 	assert_int_equal(0, programmer_init(prog, strdup(param)));
-	printf("... programmer_init for programmer=%u successful\n", prog);
+	printf("... programmer_init for programmer=%s successful\n", prog->name);
 
-	printf("Testing programmer_shutdown for programmer=%u ...\n", prog);
+	printf("Testing programmer_shutdown for programmer=%s ...\n", prog->name);
 	assert_int_equal(0, programmer_shutdown());
-	printf("... programmer_shutdown for programmer=%u successful\n", prog);
+	printf("... programmer_shutdown for programmer=%s successful\n", prog->name);
 }
 
 void dummy_init_and_shutdown_test_success(void **state)
 {
-	run_lifecycle(state, PROGRAMMER_DUMMY, "bus=parallel+lpc+fwh+spi");
+	run_lifecycle(state, &programmer_dummy, "bus=parallel+lpc+fwh+spi");
 }
 
 struct mec1308_io_state {
@@ -72,7 +72,7 @@
 	io_mock_register(&mec1308_io);
 
 	will_return_always(__wrap_sio_read, 0x4d); /* MEC1308_DEVICE_ID_VAL */
-	run_lifecycle(state, PROGRAMMER_MEC1308, "");
+	run_lifecycle(state, &programmer_mec1308, "");
 
 	io_mock_register(NULL);
 }
@@ -131,7 +131,7 @@
 
 	io_mock_register(&ene_lpc_io);
 
-	run_lifecycle(state, PROGRAMMER_ENE_LPC, "");
+	run_lifecycle(state, &programmer_ene_lpc, "");
 
 	io_mock_register(NULL);
 }
@@ -144,5 +144,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");
 }