Add new flash-chip preparation step after probing
Change-Id: I57fd63ddc4c8ccd07b0744df33d6a499bfeae9ff
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/321
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
diff --git a/flashprog.c b/flashprog.c
index 687d379..e4151da 100644
--- a/flashprog.c
+++ b/flashprog.c
@@ -661,6 +661,9 @@
if (flash->chip->probe(flash) != 1)
goto notfound;
+ if (flash->chip->prepare_access && flash->chip->prepare_access(flash, PREPARE_POST_PROBE))
+ goto notfound;
+
/* If this is the first chip found, accept it.
* If this is not the first chip found, accept it only if it is
* a non-generic match. SFDP and CFI are generic matches.
diff --git a/include/flash.h b/include/flash.h
index 4304bb8..b3ad235 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -238,6 +238,7 @@
enum preparation_steps {
PREPARE_PROBE,
+ PREPARE_POST_PROBE,
PREPARE_FULL,
};
diff --git a/memory_bus.c b/memory_bus.c
index 8badfda..b9cd68c 100644
--- a/memory_bus.c
+++ b/memory_bus.c
@@ -46,6 +46,9 @@
int prepare_memory_access(struct flashctx *flash, enum preparation_steps prep)
{
+ if (prep == PREPARE_POST_PROBE)
+ return 0;
+
/* Init pointers to the fail-safe state to distinguish them later from legit values. */
flash->virtual_memory = (chipaddr)ERROR_PTR;
flash->virtual_registers = (chipaddr)ERROR_PTR;
@@ -66,6 +69,9 @@
int prepare_memory_register_access(struct flashctx *flash, enum preparation_steps prep)
{
+ if (prep == PREPARE_POST_PROBE)
+ return 0;
+
if (prepare_memory_access(flash, prep))
return 1;