probing: Pass full struct flashchip into probes
In case we want to probe for a particular chip, we can filter the
actual probing sequences by its properties.
We'll use `struct flashchip` internally and `struct flashprog_chip`
will be used only close to the libflashprog API. This way, we can
separate the two later again if necessary.
Change-Id: Id8b13d28fcaefee62746c9391fe86b4b3b09a428
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/441
diff --git a/include/chipdrivers/edi.h b/include/chipdrivers/edi.h
index 3a1d768..4d641cc 100644
--- a/include/chipdrivers/edi.h
+++ b/include/chipdrivers/edi.h
@@ -22,8 +22,9 @@
struct flashprog_flashctx;
struct master_common;
struct bus_probe;
+struct flashchip;
-struct found_id *probe_edi(const struct bus_probe *, const struct master_common *);
+struct found_id *probe_edi(const struct bus_probe *, const struct master_common *, const struct flashchip *chip);
int edi_chip_block_erase(struct flashprog_flashctx *, unsigned int page, unsigned int size);
int edi_chip_write(struct flashprog_flashctx *, const uint8_t *buf, unsigned int start, unsigned int len);
diff --git a/include/chipdrivers/probing.h b/include/chipdrivers/probing.h
index 18eb347..9d00970 100644
--- a/include/chipdrivers/probing.h
+++ b/include/chipdrivers/probing.h
@@ -69,20 +69,20 @@
struct id_info_ext info;
};
-struct flashprog_chip;
struct master_common;
+struct flashchip;
struct bus_probe {
unsigned int priority;
enum id_type type;
- struct found_id *(*run)(const struct bus_probe *, const struct master_common *);
+ struct found_id *(*run)(const struct bus_probe *, const struct master_common *, const struct flashchip *);
void *arg;
};
struct bus_probing {
unsigned int probe_count;
const struct bus_probe *probes;
- bool (*match)(const struct flashprog_chip *, const struct id_info_ext *);
+ bool (*match)(const struct flashchip *, const struct id_info_ext *);
};
struct flashprog_flashctx;
diff --git a/include/chipdrivers/spi.h b/include/chipdrivers/spi.h
index 547885c..94a6a1f 100644
--- a/include/chipdrivers/spi.h
+++ b/include/chipdrivers/spi.h
@@ -21,6 +21,7 @@
struct flashprog_flashctx;
struct master_common;
struct bus_probe;
+struct flashchip;
/* spi.c */
int spi_aai_write(struct flashprog_flashctx *, const uint8_t *buf, unsigned int start, unsigned int len);
@@ -28,10 +29,10 @@
int spi_chip_read(struct flashprog_flashctx *, uint8_t *buf, unsigned int start, int unsigned len);
/* spi25.c */
-struct found_id *probe_spi_rdid(const struct bus_probe *, const struct master_common *);
-struct found_id *probe_spi_rems(const struct bus_probe *, const struct master_common *);
-struct found_id *probe_spi_res(const struct bus_probe *, const struct master_common *);
-struct found_id *probe_spi_at25f(const struct bus_probe *, const struct master_common *);
+struct found_id *probe_spi_rdid(const struct bus_probe *, const struct master_common *, const struct flashchip *);
+struct found_id *probe_spi_rems(const struct bus_probe *, const struct master_common *, const struct flashchip *);
+struct found_id *probe_spi_res(const struct bus_probe *, const struct master_common *, const struct flashchip *);
+struct found_id *probe_spi_at25f(const struct bus_probe *, const struct master_common *, const struct flashchip *);
int spi_simple_write_cmd(struct flashprog_flashctx *, uint8_t op, unsigned int poll_delay);
int spi_write_enable(struct flashprog_flashctx *);
@@ -119,7 +120,7 @@
int spi_erase_at45cs_sector(struct flashprog_flashctx *, unsigned int addr, unsigned int blocklen);
/* spi95.c */
-struct found_id *probe_spi_st95(const struct bus_probe *, const struct master_common *);
+struct found_id *probe_spi_st95(const struct bus_probe *, const struct master_common *, const struct flashchip *);
int spi_block_erase_emulation(struct flashprog_flashctx *, unsigned int addr, unsigned int blocklen);
/* writeprotect_ranges.c */
@@ -130,7 +131,7 @@
void decode_range_spi25_2x_block(size_t *start, size_t *len, const struct wp_bits *, size_t chip_len);
/* sfdp.c */
-struct found_id *probe_spi_sfdp(const struct bus_probe *, const struct master_common *);
+struct found_id *probe_spi_sfdp(const struct bus_probe *, const struct master_common *, const struct flashchip *);
int spi_prepare_sfdp(struct flashprog_flashctx *, enum preparation_steps);
#endif /* !__CHIPDRIVERS_SPI_H__ */
diff --git a/include/flash.h b/include/flash.h
index 0f14037..aca1b77 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -244,8 +244,7 @@
PREPARE_FULL,
};
-#define flashchip flashprog_chip
-struct flashprog_chip {
+struct flashchip {
const char *vendor;
const char *name;