Add infrastructure to probe per bus
Add some infrastructure around per-bus probing functions. Each function
is provided a private parameter, e.g. the expected length of an ID. This
will allow us to implement probing functions that are only called as of-
ten as necessary. The results will be stored in the `registered_master`
structure, to be compared to database entries later.
The probe_buses() wrapper can be used for chip entries, and allows us to
transition the existing probing functions one by one. Once all functions
have been ported, probe_flash() can be adapted as well and the wrapper
will become obsolete.
Change-Id: I6e82b6d61df50234096ac39acab58a4014203933
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/74899
diff --git a/helpers.c b/helpers.c
index 5f2b02d..b892c20 100644
--- a/helpers.c
+++ b/helpers.c
@@ -20,6 +20,26 @@
#include <string.h>
#include "flash.h"
+/* Check if raw data is all 0 or all 1. */
+bool flashprog_no_data(const void *const raw_data, const size_t len)
+{
+ const uint8_t *const raw_end = (const uint8_t *)raw_data + len;
+ const uint8_t patterns[] = { 0x00, 0xff };
+ size_t i;
+
+ for (i = 0; i < ARRAY_SIZE(patterns); ++i) {
+ const uint8_t *raw_ptr;
+ for (raw_ptr = raw_data; raw_ptr < raw_end; ++raw_ptr) {
+ if (*raw_ptr != patterns[i])
+ break;
+ }
+ if (raw_ptr == raw_end)
+ return true;
+ }
+
+ return false;
+}
+
int flashprog_read_chunked(struct flashctx *const flash, uint8_t *dst, unsigned int start, unsigned int len,
unsigned int chunksize, readfunc_t *const read)
{