From 876bf9bf4cd5fc2640d91811fb69c0d36f9e2c18 Mon Sep 17 00:00:00 2001 From: David Brownell Date: Sun, 4 Apr 2010 00:42:05 -0700 Subject: [PATCH] target: are we running algorithm code? Fixing one bug can easily uncover another .... in this case, making sure that we properly invalidate some cached NOR state when resuming arbitrary target code turned up an issue when the code wasn't quite arbitrary (and we couldn't know that, but some parts of OpenOCD assumed the cache would not be invalidated. Specifically: some flash drivers (like CFI) update that state in loops with downloaded algorithms, thus invalidating the state as it's probed. + Add a new target state flag, to record whether the target is running downloaded algorithm code. + Use that flag to add a special case: "trust" downloaded algorithms not to corrupt that cached state, bypassing cache invalidation. Also update some of the documentation to stipulate that this flavor of trustworthiness is now *required* ... not just a fortuitous acident. Signed-off-by: David Brownell --- src/target/target.c | 9 ++++++++- src/target/target.h | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/target/target.c b/src/target/target.c index 75c41d381..286933f45 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -478,9 +478,14 @@ int target_resume(struct target *target, int current, uint32_t address, int hand * themselves. We want flash drivers and infrastructure to * be able to rely on (non-invalidated) cached state. * + * For now we require that algorithms provided by OpenOCD are + * used only by code which properly maintains that cached state. + * state + * * REVISIT do the same for NAND ; maybe other flash flavors too... */ - nor_resume(target); + if (!target->running_alg) + nor_resume(target); return retval; } @@ -659,10 +664,12 @@ int target_run_algorithm(struct target *target, goto done; } + target->running_alg = true; retval = target->type->run_algorithm(target, num_mem_params, mem_params, num_reg_params, reg_param, entry_point, exit_point, timeout_ms, arch_info); + target->running_alg = false; done: return retval; diff --git a/src/target/target.h b/src/target/target.h index 7400b7e19..562724ba6 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -117,6 +117,14 @@ struct target */ bool examined; + /** true iff the target is currently running a downloaded + * "algorithm" instetad of arbitrary user code. OpenOCD code + * invoking algorithms is trusted to maintain correctness of + * any cached state (e.g. for flash status), which arbitrary + * code will have no reason to know about. + */ + bool running_alg; + struct target_event_action *event_action; int reset_halt; /* attempt resetting the CPU into the halted mode? */