On Wed, Jul 02, 2008 at 03:20:36AM +0200, Carl-Daniel Hailfinger wrote:
> 3. cleanup/fix/bandaid for the code either improves functionality
> and reduces readability or the other way round
I split my patch into two; one that only cleans up probe_flash(), and
another (which is now very simple) that removes false positives (and
true positives when unknown chip is 2nd or 3rd).
//Peter
flashrom: probe_flash() cleanup for better code readability
Signed-off-by: Peter Stuge <[EMAIL PROTECTED]>
Index: flashrom.c
===================================================================
--- flashrom.c (revision 3401)
+++ flashrom.c (working copy)
@@ -102,18 +102,15 @@
struct flashchip *probe_flash(struct flashchip *flash, int force)
{
volatile uint8_t *bios;
- unsigned long flash_baseaddr, size;
+ unsigned long flash_baseaddr = 0, size;
- while (flash->name != NULL) {
- if (chip_to_probe && strcmp(flash->name, chip_to_probe) != 0) {
- flash++;
+ for (; 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 +147,21 @@
}
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)
+ break;
+
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)
flashrom: Only find "unknown .. SPI chip" if no other chip was found
This removes the false positive matches we've been seeing, and also removes
the true positive match in case there is more than one flash chip and the 2nd
or 3rd are unknown - but I think that case is uncommon enough to warrant the
improvement in the common case. Use flashrom -frc forced read if you
encounter the uncommon case, and/or add the flash chip to the flashchips array.
Signed-off-by: Peter Stuge <[EMAIL PROTECTED]>
--- flashrom.c.cleaned 2008-07-02 04:41:35.000000000 +0200
+++ flashrom.c 2008-07-02 04:43:16.000000000 +0200
@@ -99,12 +99,13 @@
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;
+ struct flashchip *flash;
unsigned long flash_baseaddr = 0, size;
- for (; flash && flash->name; 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: ",
@@ -150,9 +151,13 @@
if (force)
break;
- if (flash->probe(flash) == 1)
+ if (flash->probe(flash) != 1)
+ goto notfound;
+
+ if (first_flash == flashchips || flash->model_id != GENERIC_DEVICE_ID)
break;
+notfound:
munmap((void *)bios, size);
}
--
coreboot mailing list
[email protected]
http://www.coreboot.org/mailman/listinfo/coreboot