Let the flash context directly point to the used master
We used to have a pointer to a full `registered_master` struct in
our flash context. Beside the used master, this contained a bit
mask of supported buses. Oddly convenient, this bit mask invited
to bypass the chip driver and break the abstraction. It allowed
to place bus-specific details virtually anywhere in flashprog,
making it harder to find a good place for them.
So, get rid of the `buses_supported` bit mask by pointing directly
to the master. Only the chip driver will implicitly know which type
of master is used.
Change-Id: I9ce13d8df0e7ccc67519d888dd9cb2e2ff8d6682
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/72533
diff --git a/include/flash.h b/include/flash.h
index 340af59..db47219 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -350,7 +350,11 @@
/* Some flash devices have an additional register space; semantics are like above. */
uintptr_t physical_registers;
chipaddr virtual_registers;
- struct registered_master *mst;
+ union {
+ struct par_master *par;
+ struct spi_master *spi;
+ struct opaque_master *opaque;
+ } mst;
const struct flashprog_layout *layout;
struct flashprog_layout *default_layout;
struct {
@@ -432,6 +436,7 @@
void unmap_flash(struct flashctx *flash);
int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
int erase_flash(struct flashctx *flash);
+struct registered_master;
int probe_flash(struct registered_master *mst, int startchip, struct flashctx *fill_flash, int force);
int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int start, unsigned int len);
void emergency_help_message(void);
diff --git a/include/programmer.h b/include/programmer.h
index 418eadd..edef52b 100644
--- a/include/programmer.h
+++ b/include/programmer.h
@@ -498,11 +498,11 @@
/* spi_master feature checks */
static inline bool spi_master_4ba(const struct flashctx *const flash)
{
- return flash->mst->spi.features & SPI_MASTER_4BA;
+ return flash->mst.spi->features & SPI_MASTER_4BA;
}
static inline bool spi_master_no_4ba_modes(const struct flashctx *const flash)
{
- return flash->mst->spi.features & SPI_MASTER_NO_4BA_MODES;
+ return flash->mst.spi->features & SPI_MASTER_NO_4BA_MODES;
}
/* usbdev.c */