Forced read functionality was disabled when programmer registration was merged in r.
We now support registering more than one controller at once for each bus type. This can happen e.g. if one SPI controller has an attached flash chip and one controller doesn't. In such a case we rely on the probe mechanism to find exactly one chip, and the probe mechanism will remember which controller/bus the flash chip is attached to. A forced read does not have the luxury of knowing which compatible controller to use, so this case is handled by always picking the first one. That may or may not be the correct one, but there is no way (yet) to specify which controller a flash chip is attached to.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-forced_read_reenable/cli_classic.c =================================================================== --- flashrom-forced_read_reenable/cli_classic.c (Revision 1495) +++ flashrom-forced_read_reenable/cli_classic.c (Arbeitskopie) @@ -456,11 +456,27 @@ printf("Note: flashrom can never write if the flash " "chip isn't found automatically.\n"); } -#if 0 // FIXME: What happens for a forced chip read if multiple compatible programmers are registered? if (force && read_it && chip_to_probe) { + struct registered_programmer *pgm; + int compatible_programmers = 0; printf("Force read (-f -r -c) requested, pretending " "the chip is there:\n"); - startchip = probe_flash(0, &flashes[0], 1); + /* This loop just counts compatible controllers. */ + for (j = 0; j < registered_programmer_count; j++) { + pgm = ®istered_programmers[j]; + if (pgm->buses_supported & flashes[0].bustype) + compatible_programmers++; + } + if (compatible_programmers > 1) + printf("More than one compatible controller " + "found for the requested flash chip, " + "using the first one.\n"); + for (j = 0; j < registered_programmer_count; j++) { + pgm = ®istered_programmers[j]; + startchip = probe_flash(pgm, 0, &flashes[0], 1); + if (startchip != -1) + break; + } if (startchip == -1) { printf("Probing for flash chip '%s' failed.\n", chip_to_probe); @@ -471,7 +487,6 @@ "contain garbage.\n"); return read_flash_to_file(&flashes[0], filename); } -#endif ret = 1; goto out_shutdown; } else if (!chip_to_probe) {
what about something like this? single loop, more obvious(?) execution flow printf is misaligned, but you get the idea.
Signed-off-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at ---
cli_classic.c | 19 ++++++++++++++++--- 1 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/cli_classic.c b/cli_classic.c index 7661612..df1f668 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -456,11 +456,25 @@ int main(int argc, char *argv[]) printf("Note: flashrom can never write if the flash " "chip isn't found automatically.\n"); } -#if 0 // FIXME: What happens for a forced chip read if multiple compatible programmers are registered? if (force && read_it && chip_to_probe) { + struct registered_programmer *pgm; + struct registered_programmer *first_pgm = NULL; printf("Force read (-f -r -c) requested, pretending " "the chip is there:\n"); - startchip = probe_flash(0, &flashes[0], 1); + for (j = 0; j < registered_programmer_count; j++) { + pgm = ®istered_programmers[j]; + if (pgm->buses_supported & flashes[0].bustype) { + if (first_pgm == NULL) + first_pgm = pgm; + else { + printf("More than one compatible controller " + "found for the requested flash chip, " + "using the first one.\n"); + break; + } + } + } + startchip = probe_flash(first_pgm, 0, &flashes[0], 1); if (startchip == -1) { printf("Probing for flash chip '%s' failed.\n", chip_to_probe); @@ -471,7 +485,6 @@ int main(int argc, char *argv[]) "contain garbage.\n"); return read_flash_to_file(&flashes[0], filename); } -#endif ret = 1; goto out_shutdown; } else if (!chip_to_probe) {
Am 16.02.2012 19:15 schrieb Carl-Daniel Hailfinger:
Forced read functionality was disabled when programmer registration was merged in r.
We now support registering more than one controller at once for each bus type. This can happen e.g. if one SPI controller has an attached flash chip and one controller doesn't. In such a case we rely on the probe mechanism to find exactly one chip, and the probe mechanism will remember which controller/bus the flash chip is attached to. A forced read does not have the luxury of knowing which compatible controller to use, so this case is handled by always picking the first one. That may or may not be the correct one, but there is no way (yet) to specify which controller a flash chip is attached to.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-forced_read_reenable/cli_classic.c =================================================================== --- flashrom-forced_read_reenable/cli_classic.c (Revision 1495) +++ flashrom-forced_read_reenable/cli_classic.c (Arbeitskopie) @@ -168,7 +168,7 @@ struct flashctx *fill_flash; const char *name; int namelen, opt, i, j; - int startchip = 0, chipcount = 0, option_index = 0, force = 0; + int startchip = -1, chipcount = 0, option_index = 0, force = 0; #if CONFIG_PRINT_WIKI == 1 int list_supported_wiki = 0; #endif @@ -456,11 +456,27 @@ printf("Note: flashrom can never write if the flash " "chip isn't found automatically.\n"); } -#if 0 // FIXME: What happens for a forced chip read if multiple compatible programmers are registered? if (force && read_it && chip_to_probe) { + struct registered_programmer *pgm; + int compatible_programmers = 0; printf("Force read (-f -r -c) requested, pretending " "the chip is there:\n"); - startchip = probe_flash(0, &flashes[0], 1); + /* This loop just counts compatible controllers. */ + for (j = 0; j < registered_programmer_count; j++) { + pgm = ®istered_programmers[j]; + if (pgm->buses_supported & flashes[0].bustype) + compatible_programmers++; + } + if (compatible_programmers > 1) + printf("More than one compatible controller " + "found for the requested flash chip, " + "using the first one.\n"); + for (j = 0; j < registered_programmer_count; j++) { + pgm = ®istered_programmers[j]; + startchip = probe_flash(pgm, 0, &flashes[0], 1); + if (startchip != -1) + break; + } if (startchip == -1) { printf("Probing for flash chip '%s' failed.\n", chip_to_probe); @@ -471,7 +487,6 @@ "contain garbage.\n"); return read_flash_to_file(&flashes[0], filename); } -#endif ret = 1; goto out_shutdown; } else if (!chip_to_probe) {
On Thu, 16 Feb 2012 21:18:06 +0100 Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net wrote:
Am 16.02.2012 19:15 schrieb Carl-Daniel Hailfinger:
Forced read functionality was disabled when programmer registration was merged in r.
We now support registering more than one controller at once for each bus type. This can happen e.g. if one SPI controller has an attached flash chip and one controller doesn't. In such a case we rely on the probe mechanism to find exactly one chip, and the probe mechanism will remember which controller/bus the flash chip is attached to. A forced read does not have the luxury of knowing which compatible controller to use, so this case is handled by always picking the first one. That may or may not be the correct one, but there is no way (yet) to specify which controller a flash chip is attached to.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
as discussed on IRC this one does not segfault when there are no registered programmers, hence Acked-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at
Am 16.02.2012 21:24 schrieb Stefan Tauner:
On Thu, 16 Feb 2012 21:18:06 +0100 Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net wrote:
Am 16.02.2012 19:15 schrieb Carl-Daniel Hailfinger:
Forced read functionality was disabled when programmer registration was merged in r.
We now support registering more than one controller at once for each bus type. This can happen e.g. if one SPI controller has an attached flash chip and one controller doesn't. In such a case we rely on the probe mechanism to find exactly one chip, and the probe mechanism will remember which controller/bus the flash chip is attached to. A forced read does not have the luxury of knowing which compatible controller to use, so this case is handled by always picking the first one. That may or may not be the correct one, but there is no way (yet) to specify which controller a flash chip is attached to.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
as discussed on IRC this one does not segfault when there are no registered programmers, hence Acked-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at
Thanks, committed in r1496.
Regards, Carl-Daniel