libflashprog: Start a new API for chip enumeration
For now, allow to query all chips, their vendor, name and size.
There's a tricky optimization coming up: We don't want to allocate
additional memory when enumerating the chip database. But, we also
want to use the same API interface to access information about de-
tected chips, which requires dynamic memory. So we have to handle
these distinct cases explicitly. Where `struct flashprog_chips *`
is used, we set it to the special value `FLASHCHIPS_DB` to denote
the flash database. For `struct flashprog_chip *` pointers, we add
chip_from_db(), which tells us whether the given pointer is within
the database range.
Change-Id: I7ecc12e1b74ca11f2be1b3472d6e470da44bfef1
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/481
diff --git a/include/libflashprog.h b/include/libflashprog.h
index e1d4d80..1f46be1 100644
--- a/include/libflashprog.h
+++ b/include/libflashprog.h
@@ -45,6 +45,25 @@
int flashprog_programmer_init(struct flashprog_programmer **, const char *prog_name, const char *prog_params);
int flashprog_programmer_shutdown(struct flashprog_programmer *);
+struct flashprog_chips;
+__attribute__((nonnull))
+int flashprog_chips_all(struct flashprog_chips **);
+__attribute__((nonnull))
+unsigned int flashprog_chips_count(const struct flashprog_chips *);
+void flashprog_chips_release(struct flashprog_chips *);
+
+struct flashprog_chip;
+__attribute__((nonnull))
+const struct flashprog_chip *flashprog_chip_first(const struct flashprog_chips *);
+__attribute__((nonnull))
+const struct flashprog_chip *flashprog_chip_next(const struct flashprog_chip *);
+__attribute__((nonnull))
+const char *flashprog_chip_vendor(const struct flashprog_chip *);
+__attribute__((nonnull))
+const char *flashprog_chip_name(const struct flashprog_chip *);
+__attribute__((nonnull))
+size_t flashprog_chip_size(const struct flashprog_chip *);
+
struct flashprog_flashctx;
int flashprog_flash_probe(struct flashprog_flashctx **, const struct flashprog_programmer *, const char *chip_name);
size_t flashprog_flash_getsize(const struct flashprog_flashctx *);