Replace flashprog_chip_match() w/ simpler flashprog_bus_match_chip()
We drop all the prints that were kept for comparison with the old probe
sequence. Now that we actually don't run a probe function per chip from
the database, the output would be quite confusing.
The remaining dropped boilerplate is not needed anymore, as all callers
already take care of flashprog_bus_probe() special cases like ID_NONE.
Change-Id: Icf0f37df4b5cf26fe7e2535cbaa15040631bdd1c
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/490
diff --git a/cli_classic.c b/cli_classic.c
index 2ba971f..916845a 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -598,8 +598,6 @@
free(flash_args.prog_name);
free(flash_args.chip);
free(log_args.logfile);
- /* clean up global variables */
- chip_to_probe = NULL;
ret |= close_logfile();
return ret;
}
diff --git a/flashprog.c b/flashprog.c
index f1bad69..113b3f6 100644
--- a/flashprog.c
+++ b/flashprog.c
@@ -36,7 +36,6 @@
#include "version.h"
const char flashprog_version[] = FLASHPROG_VERSION;
-const char *chip_to_probe = NULL;
static const struct programmer_entry *programmer = NULL;
static char *programmer_param = NULL;
@@ -646,56 +645,6 @@
mst->probed = true;
}
-bool flashprog_chip_match(struct registered_master *const mst, const struct flashchip *const chip)
-{
- static const char *const id_names[] = {
- [ID_82802AB] = "82802AB",
- [ID_JEDEC] = "JEDEC",
- [ID_JEDEC_29GL] = "JEDEC_29GL",
- [ID_OPAQUE] = "OPAQUE",
- [ID_SPI_AT25F] = "SPI_AT25F",
- [ID_SPI_RDID] = "SPI_RDID",
- [ID_SPI_REMS] = "SPI_REMS",
- [ID_SPI_RES1] = "SPI_RES1",
- [ID_SPI_RES2] = "SPI_RES2",
- [ID_SPI_RES3] = "SPI_RES3",
- [ID_SPI_SFDP] = "SPI_SFDP",
- [ID_SPI_ST95] = "SPI_ST95",
- [ID_W29EE011] = "W29EE011",
- [ID_EDI] = "EDI",
- };
-
- msg_gdbg("Probing for %s %s, %d kB: ", chip->vendor, chip->name, chip->total_size);
-
- if (chip_to_probe) {
- /* We are looking for a particular chip.
- If it can't be probed, assume it's there... */
- if (chip->id.type == ID_NONE)
- return true;
- /* ...otherwise, limit the probing sequences by its properties. */
- flashprog_bus_probe(mst, chip);
- } else {
- flashprog_bus_probe(mst, NULL);
- }
-
- struct found_id *found_id;
- for (found_id = mst->found_ids; found_id; found_id = found_id->next) {
- if (found_id->info.id.type != chip->id.type)
- continue;
-
- if (found_id->info.id.type < ARRAY_SIZE(id_names))
- msg_cdbg("%s: id1 0x%02x, id2 0x%02x ",
- id_names[found_id->info.id.type],
- found_id->info.id.id1, found_id->info.id.id2);
-
- if (mst->probing.match(chip, &found_id->info))
- break;
- }
-
- msg_cdbg("\n");
- return !!found_id;
-}
-
/* Even if an error is found, the function will keep going and check the rest. */
static int selfcheck_eraseblocks(const struct flashchip *chip, const char *label)
{
diff --git a/include/chipdrivers/probing.h b/include/chipdrivers/probing.h
index 7bca406..5e07983 100644
--- a/include/chipdrivers/probing.h
+++ b/include/chipdrivers/probing.h
@@ -86,7 +86,6 @@
struct registered_master;
void flashprog_bus_probe(struct registered_master *, const struct flashchip *);
-bool flashprog_chip_match(struct registered_master *, const struct flashchip *);
struct flashprog_chips;
struct flashprog_flashctx;
diff --git a/include/flash.h b/include/flash.h
index e494a8c..32824a7 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -548,7 +548,6 @@
/* flashprog.c */
extern const char flashprog_version[];
-extern const char *chip_to_probe;
char *flashbuses_to_text(enum chipbustype bustype);
int map_flash(struct flashctx *flash);
void unmap_flash(struct flashctx *flash);
diff --git a/libflashprog/chips.c b/libflashprog/chips.c
index ac5cdc2..12b4197 100644
--- a/libflashprog/chips.c
+++ b/libflashprog/chips.c
@@ -58,6 +58,19 @@
return 0;
}
+static bool flashprog_bus_match_chip(struct registered_master *bus, const struct flashprog_chip *chip)
+{
+ struct found_id *found_id;
+ for (found_id = bus->found_ids; found_id; found_id = found_id->next) {
+ if (found_id->info.id.type != chip->id.type)
+ continue;
+
+ if (bus->probing.match(chip, &found_id->info))
+ break;
+ }
+ return !!found_id;
+}
+
static int flashprog_chips_probe_bus(struct flashprog_chips *chips,
struct registered_master *bus)
{
@@ -71,7 +84,7 @@
(flashchips[chip].id.model == GENERIC_DEVICE_ID)))
continue;
- if (!flashprog_chip_match(bus, &flashchips[chip]))
+ if (!flashprog_bus_match_chip(bus, &flashchips[chip]))
continue;
struct chip_entry *const entry = malloc(sizeof(*entry));
@@ -116,7 +129,7 @@
return NULL;
flashprog_bus_probe(bus, chip);
- if (flashprog_chip_match(bus, chip))
+ if (flashprog_bus_match_chip(bus, chip))
return &bus->common;
}