spi25: Replace spi_read_chunked() with more abstract version
The new flashprog_read_chunked() takes a low-level reading function as
argument. This allows us to make use of the chunking with non-SPI read
functions.
Change-Id: Ica1b616e75e4e7682120928588e231c82cf4cf70
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/74865
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
diff --git a/helpers.c b/helpers.c
index 5b47b68..27b9cf1 100644
--- a/helpers.c
+++ b/helpers.c
@@ -20,6 +20,21 @@
#include <string.h>
#include "flash.h"
+int flashprog_read_chunked(struct flashctx *const flash, uint8_t *dst, unsigned int start, unsigned int len,
+ const unsigned int chunksize, readfunc_t *const read)
+{
+ int ret;
+ size_t to_read;
+ for (; len; len -= to_read, dst += to_read, start += to_read) {
+ to_read = min(chunksize, len);
+ ret = read(flash, dst, start, to_read);
+ if (ret)
+ return ret;
+ flashprog_progress_add(flash, to_read);
+ }
+ return 0;
+}
+
/* Returns the minimum number of bits needed to represent the given address.
* FIXME: use mind-blowing implementation. */
uint32_t address_to_bits(uint32_t addr)