[flashrom] [PATCH] Fix flashrom running on boards with coreboot.

Stefan Tauner stefan.tauner at student.tuwien.ac.at
Sun Sep 16 02:56:15 CEST 2012


In r1577 we removed the discrimination of coreboot IDs and user-specified
mainboards. The problem is that the board enable code required to find
a board enable if either of these model strings were set. Therefore boards
running coreboot that do not need a board enable failed to execute flashrom
since then. This patch fixes this by handling coreboot IDs and user-supplied
IDs differently again.

Signed-off-by: Stefan Tauner <stefan.tauner at student.tuwien.ac.at>
---
Carl-Daniel noticed that the order of the board_match_name() calls were
odd. The result was that in the case the user supplied a mainboard model
that differed from the one in the cb table, and if the user forced
flashrom to not abort, then the board enable matching the cb table would
have been used instead of the one the user supplied. this is wrong or at
least confusing.

 board_enable.c |   20 +++++++++++++++-----
 internal.c     |   10 +++-------
 programmer.h   |    2 +-
 3 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/board_enable.c b/board_enable.c
index b23ef8f..8528747 100644
--- a/board_enable.c
+++ b/board_enable.c
@@ -2495,7 +2495,6 @@ static const struct board_match *board_match_name(const char *vendor, const char
 	if (partmatch)
 		return partmatch;
 
-	msg_perr("No suitable board enable found for vendor=\"%s\", model=\"%s\".\n", vendor, model);
 	return NULL;
 }
 
@@ -2605,16 +2604,27 @@ void board_handle_before_laptop(void)
 	board_handle_phase(P2);
 }
 
-int board_flash_enable(const char *vendor, const char *model)
+int board_flash_enable(const char *vendor, const char *model, const char *cb_vendor, const char *cb_model)
 {
 	const struct board_match *board = NULL;
 	int ret = 0;
 
-	if (vendor && model) {
+	if (vendor != NULL  && model != NULL) {
 		board = board_match_name(vendor, model);
-		if (!board) /* if a board was given it has to match, else we abort here. */
+		if (!board) { /* If a board was given by the user it has to match, else we abort here. */
+			msg_perr("No suitable board enable found for vendor=\"%s\", model=\"%s\".\n",
+				 vendor, model);
 			return 1;
-	} else {
+		}
+	}
+	if (board == NULL && cb_vendor != NULL && cb_model != NULL) {
+		board = board_match_name(cb_vendor, cb_model);
+		if (!board) { /* Failure is an option here, because many cb boards don't require an enable. */
+			msg_pdbg2("No board enable found matching coreboot IDs vendor=\"%s\", model=\"%s\".\n",
+				  vendor, model);
+		}
+	}
+	if (board == NULL) {
 		board = board_match_pci_ids(P3);
 		if (!board) /* i.e. there is just no board enable available for this board */
 			return 0;
diff --git a/internal.c b/internal.c
index 7b6cff2..b4414a5 100644
--- a/internal.c
+++ b/internal.c
@@ -257,12 +257,8 @@ int internal_init(void)
 	}
 
 #if defined(__i386__) || defined(__x86_64__)
-	if (cb_parse_table(&cb_vendor, &cb_model) == 0) { /* coreboot IDs valid */
-		/* If no -p internal:mainboard was given but there are valid coreboot IDs then use those. */
-		if (board_vendor == NULL || board_model == NULL) {
-			board_vendor = cb_vendor;
-			board_model = cb_model;
-		} else if (strcasecmp(board_vendor, cb_vendor) || strcasecmp(board_model, cb_model)) {
+	if ((cb_parse_table(&cb_vendor, &cb_model) == 0) && (board_vendor != NULL) && (board_model != NULL)) {
+		if (strcasecmp(board_vendor, cb_vendor) || strcasecmp(board_model, cb_model)) {
 			msg_pinfo("WARNING: The mainboard IDs set by -p internal:mainboard (%s:%s) do not\n"
 				  "         match the current coreboot IDs of the mainboard (%s:%s).\n",
 				  board_vendor, board_model, cb_vendor, cb_model);
@@ -339,7 +335,7 @@ int internal_init(void)
 	init_superio_ite();
 #endif
 
-	if (board_flash_enable(board_vendor, board_model)) {
+	if (board_flash_enable(board_vendor, board_model, cb_vendor, cb_model)) {
 		msg_perr("Aborting to be safe.\n");
 		return 1;
 	}
diff --git a/programmer.h b/programmer.h
index 51b9c40..dedec67 100644
--- a/programmer.h
+++ b/programmer.h
@@ -256,7 +256,7 @@ void sio_write(uint16_t port, uint8_t reg, uint8_t data);
 void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
 void board_handle_before_superio(void);
 void board_handle_before_laptop(void);
-int board_flash_enable(const char *vendor, const char *model);
+int board_flash_enable(const char *vendor, const char *model, const char *cb_vendor, const char *cb_model);
 
 /* chipset_enable.c */
 int chipset_flash_enable(void);
-- 
Kind regards, Stefan Tauner





More information about the flashrom mailing list