libflashprog: Introduce new probing API flashprog_flash_probe_chip()
This new probing API acts about the same as the old one, except that
it accepts a `struct flashprog_chip *` handle instead of a chip name.
Under the hood, however, it uses our new bus probing directly.
We introduce a new function, flashprog_flash_prepare_context(), that
creates a flash context from a probed chip, and the bus it was found
on. This will be the single place that creates flash contexts in the
future.
Change-Id: I1a344aedf573d92f8f297e6eed8daadb511ebc10
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/484
diff --git a/include/chipdrivers/probing.h b/include/chipdrivers/probing.h
index 090f2ab..2e081d1 100644
--- a/include/chipdrivers/probing.h
+++ b/include/chipdrivers/probing.h
@@ -88,4 +88,10 @@
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;
+struct flashprog_programmer;
+const struct master_common *flashprog_chip_probe(const struct flashprog_programmer *, const struct flashchip *);
+int flashprog_flash_prepare_context(struct flashprog_flashctx **, const struct flashprog_programmer *, const struct master_common *, const struct flashchip *);
+
#endif /* !__PROBING_H__ */
diff --git a/include/flash.h b/include/flash.h
index 3ad9d1f..31b4f0c 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -440,10 +440,10 @@
uintptr_t physical_registers;
chipaddr virtual_registers;
union {
- struct master_common *common;
- struct par_master *par;
- struct spi_master *spi;
- struct opaque_master *opaque;
+ const struct master_common *common;
+ const struct par_master *par;
+ const struct spi_master *spi;
+ const struct opaque_master *opaque;
} mst;
const struct flashprog_layout *layout;
struct flashprog_layout *default_layout;
diff --git a/include/libflashprog.h b/include/libflashprog.h
index 8afd8d5..6f4193b 100644
--- a/include/libflashprog.h
+++ b/include/libflashprog.h
@@ -122,6 +122,8 @@
struct flashprog_flashctx;
int flashprog_flash_probe(struct flashprog_flashctx **, const struct flashprog_programmer *, const char *chip_name);
+__attribute__((nonnull))
+int flashprog_flash_probe_chip(struct flashprog_flashctx **, const struct flashprog_programmer *, const struct flashprog_chip *);
size_t flashprog_flash_getsize(const struct flashprog_flashctx *);
int flashprog_flash_erase(struct flashprog_flashctx *);
void flashprog_flash_release(struct flashprog_flashctx *);