programmer: Move .max_rom_decode into struct master_common
This is useful information from a chipdriver perspective. It also saves
us the open-coded tracking of the "registered master" in `cli_classic.c`
right away.
Change-Id: I532e9b1802184520852fe0b45650239ea252a60d
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/430
diff --git a/cli_classic.c b/cli_classic.c
index a49e045..2593f62 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -170,14 +170,14 @@
}
/* 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)
+static bool max_decode_exceeded(const struct flashctx *const flash)
{
- if (flashprog_flash_getsize(flash) <= mst->max_rom_decode)
+ if (flashprog_flash_getsize(flash) <= flash->mst.common->max_rom_decode)
return false;
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);
+ "may fail.\n", flash->chip->total_size, flash->mst.common->max_rom_decode / KiB);
return true;
}
@@ -450,15 +450,12 @@
free(tempstr);
chip_to_probe = flash_args.chip;
- 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++;
}
@@ -532,7 +529,7 @@
print_chip_support_status(fill_flash->chip);
- if (max_decode_exceeded(matched_master, fill_flash) && !force) {
+ if (max_decode_exceeded(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;
diff --git a/include/programmer.h b/include/programmer.h
index 46b50f1..04c4b42 100644
--- a/include/programmer.h
+++ b/include/programmer.h
@@ -274,6 +274,8 @@
char *extract_programmer_param(const char *param_name);
struct master_common {
+ size_t max_rom_decode;
+
int (*adapt_voltage)(const struct master_common *, unsigned int min_mv, unsigned int max_mv);
};
@@ -472,7 +474,6 @@
#define DEFAULT_MAX_DECODE_PARALLEL (16*MiB)
#define MAX_ROM_DECODE_UNLIMITED UINT32_MAX
struct registered_master {
- size_t max_rom_decode;
enum chipbustype buses_supported;
struct bus_probing probing;
diff --git a/opaque.c b/opaque.c
index f03b70a..f54a032 100644
--- a/opaque.c
+++ b/opaque.c
@@ -63,10 +63,12 @@
__func__);
return ERROR_FLASHPROG_BUG;
}
- rmst.max_rom_decode = MAX_ROM_DECODE_UNLIMITED;
rmst.buses_supported = BUS_PROG;
rmst.opaque = *mst;
if (data)
rmst.opaque.data = data;
+
+ rmst.common.max_rom_decode = MAX_ROM_DECODE_UNLIMITED;
+
return register_master(&rmst);
}
diff --git a/parallel.c b/parallel.c
index 5746862..3e32d59 100644
--- a/parallel.c
+++ b/parallel.c
@@ -84,13 +84,15 @@
return ERROR_FLASHPROG_BUG;
}
- if (max_rom_decode)
- rmst.max_rom_decode = max_rom_decode;
- else
- rmst.max_rom_decode = DEFAULT_MAX_DECODE_PARALLEL;
rmst.buses_supported = buses;
rmst.par = *mst;
if (data)
rmst.par.data = data;
+
+ if (max_rom_decode)
+ rmst.common.max_rom_decode = max_rom_decode;
+ else
+ rmst.common.max_rom_decode = DEFAULT_MAX_DECODE_PARALLEL;
+
return register_master(&rmst);
}
diff --git a/spi.c b/spi.c
index 15809c6..2ad84c0 100644
--- a/spi.c
+++ b/spi.c
@@ -224,10 +224,6 @@
return ERROR_FLASHPROG_BUG;
}
- if (max_rom_decode)
- rmst.max_rom_decode = max_rom_decode;
- else
- rmst.max_rom_decode = MAX_ROM_DECODE_UNLIMITED;
rmst.buses_supported = BUS_SPI;
rmst.probing.probe_count = ARRAY_SIZE(spi_probes);
rmst.probing.probes = spi_probes;
@@ -235,6 +231,12 @@
rmst.spi = *mst;
if (data)
rmst.spi.data = data;
+
+ if (max_rom_decode)
+ rmst.common.max_rom_decode = max_rom_decode;
+ else
+ rmst.common.max_rom_decode = MAX_ROM_DECODE_UNLIMITED;
+
return register_master(&rmst);
}