Added const char** fl_multiple_flash_probe(int *chip_count) function which returns string list of multiple chips found.
Signed-off-by: Lukasz Dmitrowski lukasz.dmitrowski@gmail.com
--- libflashrom.c | 41 +++++++++++++++++++++++++++++++++++++++++ libflashrom.h | 1 + 2 files changed, 42 insertions(+)
diff --git a/libflashrom.c b/libflashrom.c index 3b94215..f88dc68 100644 --- a/libflashrom.c +++ b/libflashrom.c @@ -343,6 +343,47 @@ int fl_flash_probe(fl_flashctx_t **const flashctx, const char *const chip_name) }
/** + * @brief Returns string list of multiple chips found + * + * Probes for all known flash chips and returns string list of found chips. + * Should be used only when multiple chips were found by fl_flash_probe + * + * @param[out] pointer to integer - filled by a number of found chips + * @return String list of multiple chips found + */ +const char** fl_multiple_flash_probe(int *chip_count) +{ + const char **chip_names = NULL; + struct flashctx flashes[6] = {{0}}; + int chip_index = 0; + int i = 0; + + chip_to_probe = NULL; + *chip_count = 0; + + while (*chip_count < ARRAY_SIZE(flashes)) { + chip_index = probe_flash(®istered_masters[i], chip_index, + &flashes[*chip_count], 0); + if (chip_index == -1) + break; + ++chip_index; + ++(*chip_count); + } + + chip_names = malloc((*chip_count) * sizeof(char*)); + + if (!chip_names) { + msg_gerr("Out of memory!"); + } else { + for (; i < *chip_count; ++i) { + chip_names[i] = flashes[i].chip->name; + } + } + + return chip_names; +} + +/** * @brief Returns the size of the specified flash chip in bytes. * * @param flashctx The queried flash context. diff --git a/libflashrom.h b/libflashrom.h index 5308fa3..ae0bfcc 100644 --- a/libflashrom.h +++ b/libflashrom.h @@ -84,6 +84,7 @@ int fl_programmer_shutdown(void); struct flashctx; typedef struct flashctx fl_flashctx_t; int fl_flash_probe(fl_flashctx_t **, const char *chip_name); +const char** fl_multiple_flash_probe(int *chip_count); size_t fl_flash_getsize(const fl_flashctx_t *); int fl_flash_erase(fl_flashctx_t *); void fl_flash_release(fl_flashctx_t *);