Patch attached.

//Peter
flashrom: probe_flash() cleanup and remove false positive unknown .. SPI chip

Restructure probe_flash() for some readability, and now only find an unknown
.. SPI chip if it is the first flash chip found in the system.

This also removes the true positive match when there is more than one flash
chip and the 2nd or 3rd are unknown but I think that case is uncommon enough
to warrant this improvement for the common case. The uncommon case can still
use the -frc forced read.

Signed-off-by: Peter Stuge <[EMAIL PROTECTED]>

Index: flashrom.c
===================================================================
--- flashrom.c	(revision 3401)
+++ flashrom.c	(working copy)
@@ -99,21 +99,19 @@
 	return 0;
 }
 
-struct flashchip *probe_flash(struct flashchip *flash, int force)
+struct flashchip *probe_flash(struct flashchip *first_flash, int force)
 {
 	volatile uint8_t *bios;
-	unsigned long flash_baseaddr, size;
+	struct flashchip *flash;
+	unsigned long flash_baseaddr = 0, size;
 
-	while (flash->name != NULL) {
-		if (chip_to_probe && strcmp(flash->name, chip_to_probe) != 0) {
-			flash++;
+	for (flash = first_flash; flash && flash->name; flash++) {
+		if (chip_to_probe && strcmp(flash->name, chip_to_probe) != 0)
 			continue;
-		}
 		printf_debug("Probing for %s %s, %d KB: ",
 			     flash->vendor, flash->name, flash->total_size);
 		if (!flash->probe && !force) {
 			printf_debug("failed! flashrom has no probe function for this flash chip.\n");
-			flash++;
 			continue;
 		}
 
@@ -150,18 +148,25 @@
 		}
 		flash->virtual_memory = bios;
 
-		if (force || flash->probe(flash) == 1) {
-			printf("Found chip \"%s %s\" (%d KB) at physical address 0x%lx.\n",
-			       flash->vendor, flash->name, flash->total_size,
-			       flash_baseaddr);
-			return flash;
-		}
+		if (force)
+			break;
+
+		if (flash->probe(flash) != 1)
+			goto notfound;
+
+		if (first_flash == flashchips || flash->model_id != GENERIC_DEVICE_ID)
+			break;
+
+notfound:
 		munmap((void *)bios, size);
-
-		flash++;
 	}
 
-	return NULL;
+	if (!flash || !flash->name)
+		return NULL;
+
+	printf("Found chip \"%s %s\" (%d KB) at physical address 0x%lx.\n",
+	       flash->vendor, flash->name, flash->total_size, flash_baseaddr);
+	return flash;
 }
 
 int verify_flash(struct flashchip *flash, uint8_t *buf)
-- 
coreboot mailing list
[email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to