memory_mapped: Reduce `decode_sizes` to a single `max_rom_decode`
We used to store the maximum decode size, i.e. the maximum memory-mapped
range of the flash chip, per bus type (Parallel, LPC, FWH, SPI). There
was no programmer in the tree that really made use of it, though:
* The chipset drivers usually focus on a single bus type. And even if
they advertise the whole default set (PAR, LPC, FWH), they only pro-
vide a maximum decode size for one of them. The latter is probably
wrong, should really more than one bus type be supported.
* PCI and external programmers all support only a single bus type, with
the exception of `serprog` which doesn't set a maximum decode size.
What made the distinction even less useful is that for some chips that
support multiple bus types, i.e. LPC+FWH, we can't even detect which
type it is. The existing code around this also only tried to provide
the best possible warning message at the expense of breaking the pro-
grammer abstraction.
Hence, unify the set of sizes into a single `max_rom_decode` property.
We store it inside the `registered_master` struct right away, to avoid
any more use of globals.
Change-Id: I2aaea18d5b4255eb843a625b016ee74bb145ed85
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/72531
diff --git a/cli_classic.c b/cli_classic.c
index 79159c3..fede2ca 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -189,48 +189,16 @@
return ret;
}
-/* Returns the number of buses commonly supported by the current programmer and flash chip where the latter
- * can not be completely accessed due to size/address limits of the programmer. */
-static unsigned int count_max_decode_exceedings(const struct flashctx *flash,
- const struct decode_sizes *max_rom_decode_)
+/* Returns true if the flash chip cannot be completely accessed due to size/address limits of the programmer. */
+static bool max_decode_exceeded(const struct registered_master *const mst, const struct flashctx *const flash)
{
- unsigned int limitexceeded = 0;
- uint32_t size = flash->chip->total_size * 1024;
- enum chipbustype buses = flash->mst->buses_supported & flash->chip->bustype;
+ if (flashprog_flash_getsize(flash) <= mst->max_rom_decode)
+ return false;
- if ((buses & BUS_PARALLEL) && (max_rom_decode_->parallel < size)) {
- limitexceeded++;
- msg_pdbg("Chip size %u kB is bigger than supported "
- "size %u kB of chipset/board/programmer "
- "for %s interface, "
- "probe/read/erase/write may fail. ", size / 1024,
- max_rom_decode_->parallel / 1024, "Parallel");
- }
- if ((buses & BUS_LPC) && (max_rom_decode_->lpc < size)) {
- limitexceeded++;
- msg_pdbg("Chip size %u kB is bigger than supported "
- "size %u kB of chipset/board/programmer "
- "for %s interface, "
- "probe/read/erase/write may fail. ", size / 1024,
- max_rom_decode_->lpc / 1024, "LPC");
- }
- if ((buses & BUS_FWH) && (max_rom_decode_->fwh < size)) {
- limitexceeded++;
- msg_pdbg("Chip size %u kB is bigger than supported "
- "size %u kB of chipset/board/programmer "
- "for %s interface, "
- "probe/read/erase/write may fail. ", size / 1024,
- max_rom_decode_->fwh / 1024, "FWH");
- }
- if ((buses & BUS_SPI) && (max_rom_decode_->spi < size)) {
- limitexceeded++;
- msg_pdbg("Chip size %u kB is bigger than supported "
- "size %u kB of chipset/board/programmer "
- "for %s interface, "
- "probe/read/erase/write may fail. ", size / 1024,
- max_rom_decode_->spi / 1024, "SPI");
- }
- return limitexceeded;
+ msg_pdbg("Chip size %u kB is bigger than supported size %zu kB of\n"
+ "chipset/board/programmer for memory-mapped interface, probe/read/erase/write\n"
+ "may fail.\n", flash->chip->total_size, mst->max_rom_decode / KiB);
+ return true;
}
int main(int argc, char *argv[])
@@ -604,12 +572,15 @@
msg_pdbg("The following protocols are supported: %s.\n", tempstr);
free(tempstr);
+ struct registered_master *matched_master = NULL;
for (j = 0; j < registered_master_count; j++) {
startchip = 0;
while (chipcount < (int)ARRAY_SIZE(flashes)) {
startchip = probe_flash(®istered_masters[j], startchip, &flashes[chipcount], 0);
if (startchip == -1)
break;
+ if (chipcount == 0)
+ matched_master = ®istered_masters[j];
chipcount++;
startchip++;
}
@@ -680,16 +651,7 @@
print_chip_support_status(fill_flash->chip);
- unsigned int limitexceeded = count_max_decode_exceedings(fill_flash, &max_rom_decode);
- if (limitexceeded > 0 && !force) {
- enum chipbustype commonbuses = fill_flash->mst->buses_supported & fill_flash->chip->bustype;
-
- /* Sometimes chip and programmer have more than one bus in common,
- * and the limit is not exceeded on all buses. Tell the user. */
- if ((bitcount(commonbuses) > limitexceeded)) {
- msg_pdbg("There is at least one interface available which could support the size of\n"
- "the selected flash chip.\n");
- }
+ if (max_decode_exceeded(matched_master, fill_flash) && !force) {
msg_cerr("This flash chip is too big for this programmer (--verbose/-V gives details).\n"
"Use --force/-f to override at your own risk.\n");
ret = 1;