target: are we running algorithm code?
authorDavid Brownell <dbrownell@users.sourceforge.net>
Sun, 4 Apr 2010 07:42:05 +0000 (00:42 -0700)
committerDavid Brownell <dbrownell@users.sourceforge.net>
Sun, 4 Apr 2010 07:42:05 +0000 (00:42 -0700)
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 <dbrownell@users.sourceforge.net>
src/target/target.c
src/target/target.h

index 75c41d381f700e7a83e67d9d628d87edfc7d443d..286933f45458e7e19a6fe842fa578641d729f72a 100644 (file)
@@ -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;
index 7400b7e1942090504bffe254c1e7e0f85a325160..562724ba6f0b46b0434d736ed5253c80a051c6eb 100644 (file)
@@ -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? */

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)