opaque: Move probing into PREPARE_POST_PROBE hook
To get rid of the flash context in probing, we have to split the
detection of chip parameters out into a preparation step. Below
the opaque-master API, things could actually stay as they are,
we rename `.probe` to `.prepare` though for completeness.
Change-Id: Ic8418e6c5bdc49f5133cdb21efed0bf6dc2f820e
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/449
diff --git a/opaque.c b/opaque.c
index 33ba766..a005d91 100644
--- a/opaque.c
+++ b/opaque.c
@@ -28,7 +28,14 @@
int probe_opaque(struct flashctx *flash)
{
- return flash->mst.opaque->probe(flash);
+ return 1;
+}
+
+int prepare_opaque(struct flashctx *flash, enum preparation_steps step)
+{
+ if (step != PREPARE_POST_PROBE)
+ return 0;
+ return flash->mst.opaque->prepare(flash) ? 0 : -1;
}
int read_opaque(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
@@ -57,7 +64,7 @@
}
}
- if (!mst->probe || !mst->read || !mst->write || !mst->erase) {
+ if (!mst->prepare || !mst->read || !mst->write || !mst->erase) {
msg_perr("%s called with incomplete master definition.\n"
"Please report a bug at flashprog@flashprog.org\n",
__func__);