flashrom.c: replace enum programmer with struct programmer_entry*

Change-Id: I478c56354d5f482010bfe1560489700bc889717a
Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.de>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/55119
Original-Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/71376
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/flashrom.c b/flashrom.c
index a1f2318..1d376d2 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -43,7 +43,7 @@
 const char flashrom_version[] = FLASHROM_VERSION;
 const char *chip_to_probe = NULL;
 
-static enum programmer programmer = PROGRAMMER_INVALID;
+static const struct programmer_entry *programmer = NULL;
 static const char *programmer_param = NULL;
 
 /*
@@ -144,7 +144,7 @@
 		msg_perr("Invalid programmer specified!\n");
 		return -1;
 	}
-	programmer = prog;
+	programmer = programmer_table[prog];
 	/* Initialize all programmer specific data. */
 	/* Default to unlimited decode sizes. */
 	max_rom_decode = (const struct decode_sizes) {
@@ -161,8 +161,8 @@
 	programmer_may_write = 1;
 
 	programmer_param = param;
-	msg_pdbg("Initializing %s programmer\n", programmer_table[programmer]->name);
-	ret = programmer_table[programmer]->init();
+	msg_pdbg("Initializing %s programmer\n", programmer->name);
+	ret = programmer->init();
 	if (programmer_param && strlen(programmer_param)) {
 		if (ret != 0) {
 			/* It is quite possible that any unhandled programmer parameter would have been valid,
@@ -206,7 +206,7 @@
 
 void *programmer_map_flash_region(const char *descr, uintptr_t phys_addr, size_t len)
 {
-	void *ret = programmer_table[programmer]->map_flash_region(descr, phys_addr, len);
+	void *ret = programmer->map_flash_region(descr, phys_addr, len);
 	msg_gspew("%s: mapping %s from 0x%0*" PRIxPTR " to 0x%0*" PRIxPTR "\n",
 		  __func__, descr, PRIxPTR_WIDTH, phys_addr, PRIxPTR_WIDTH, (uintptr_t) ret);
 	return ret;
@@ -214,7 +214,7 @@
 
 void programmer_unmap_flash_region(void *virt_addr, size_t len)
 {
-	programmer_table[programmer]->unmap_flash_region(virt_addr, len);
+	programmer->unmap_flash_region(virt_addr, len);
 	msg_gspew("%s: unmapped 0x%0*" PRIxPTR "\n", __func__, PRIxPTR_WIDTH, (uintptr_t)virt_addr);
 }
 
@@ -262,7 +262,7 @@
 void programmer_delay(unsigned int usecs)
 {
 	if (usecs > 0)
-		programmer_table[programmer]->delay(usecs);
+		programmer->delay(usecs);
 }
 
 int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start,
@@ -846,12 +846,12 @@
 		  flash->chip->vendor, flash->chip->name, flash->chip->total_size, tmp);
 	free(tmp);
 #if CONFIG_INTERNAL == 1
-	if (programmer_table[programmer]->map_flash_region == physmap)
+	if (programmer->map_flash_region == physmap)
 		msg_cinfo("mapped at physical address 0x%0*" PRIxPTR ".\n",
 			  PRIxPTR_WIDTH, flash->physical_memory);
 	else
 #endif
-		msg_cinfo("on %s.\n", programmer_table[programmer]->name);
+		msg_cinfo("on %s.\n", programmer->name);
 
 	/* Flash registers may more likely not be mapped if the chip was forced.
 	 * Lock info may be stored in registers, so avoid lock info printing. */
@@ -1487,7 +1487,7 @@
 {
 	msg_gerr("Good, writing to the flash chip apparently didn't do anything.\n");
 #if CONFIG_INTERNAL == 1
-	if (programmer == PROGRAMMER_INTERNAL)
+	if (programmer == &programmer_internal)
 		msg_gerr("This means we have to add special support for your board, programmer or flash\n"
 			 "chip. Please report this to the mailing list at flashrom@flashrom.org or on\n"
 			 "IRC (see https://www.flashrom.org/Contact for details), thanks!\n"
@@ -1505,7 +1505,7 @@
 {
 	msg_gerr("Your flash chip is in an unknown state.\n");
 #if CONFIG_INTERNAL == 1
-	if (programmer == PROGRAMMER_INTERNAL)
+	if (programmer == &programmer_internal)
 		msg_gerr("Get help on IRC (see https://www.flashrom.org/Contact) or mail\n"
 			"flashrom@flashrom.org with the subject \"FAILED: <your board name>\"!"
 			"-------------------------------------------------------------------------------\n"
@@ -2001,7 +2001,7 @@
 	}
 
 #if CONFIG_INTERNAL == 1
-	if (programmer == PROGRAMMER_INTERNAL && cb_check_image(newcontents, flash_size) < 0) {
+	if (programmer == &programmer_internal && cb_check_image(newcontents, flash_size) < 0) {
 		if (flashctx->flags.force_boardmismatch) {
 			msg_pinfo("Proceeding anyway because user forced us to.\n");
 		} else {