target: add API to temporarily mask target polling 09/7009/3
authorAntonio Borneo <borneo.antonio@gmail.com>
Mon, 30 May 2022 20:49:12 +0000 (22:49 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Mon, 15 Aug 2022 13:22:06 +0000 (13:22 +0000)
The same flag 'jtag_poll' is currently used as local data for the
command 'poll' and to temporarily mask the target polling.
This can cause unexpected behavior if the command 'poll' is
executed while polling is temporarily masked.

Add a new flag 'jtag_poll_en' to hold the temporarily mask
condition and keep 'jtag_poll' for the 'poll' command only.

While there, change the initial assignment of 'jtag_poll' using
the proper boolean value.

Change-Id: I18dcf7c65b07aefadf046caaa2fcd2d74fa6fbae
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7009
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
src/flash/nor/psoc4.c
src/helper/command.c
src/jtag/core.c
src/jtag/jtag.h
src/target/target.c

index 4b5aa55cf6043102b95a1284bc8ed25ff731175e..1bdd64aae568faecf3a2f1c6487efeccd85cc50c 100644 (file)
@@ -651,8 +651,8 @@ static int psoc4_write(struct flash_bank *bank, const uint8_t *buffer,
        if (row_offset)
                memset(row_buffer, bank->default_padded_value, row_offset);
 
-       bool save_poll = jtag_poll_get_enabled();
-       jtag_poll_set_enabled(false);
+       /* Mask automatic polling triggered by execution of halted events */
+       bool save_poll_mask = jtag_poll_mask();
 
        while (count) {
                uint32_t chunk_size = psoc4_info->row_size - row_offset;
@@ -693,7 +693,7 @@ static int psoc4_write(struct flash_bank *bank, const uint8_t *buffer,
        }
 
 cleanup:
-       jtag_poll_set_enabled(save_poll);
+       jtag_poll_unmask(save_poll_mask);
 
        free(sysrq_buffer);
        return retval;
index 43fe033f71f010c87be02defb2e2977929daa5de..52f9eb6bf9a9cbfb3571b3272a5d8e3205e9d915 100644 (file)
@@ -702,14 +702,12 @@ static int jim_capture(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
         * This is necessary in order to avoid accidentally getting a non-empty
         * string for tcl fn's.
         */
-       bool save_poll = jtag_poll_get_enabled();
-
-       jtag_poll_set_enabled(false);
+       bool save_poll_mask = jtag_poll_mask();
 
        const char *str = Jim_GetString(argv[1], NULL);
        int retcode = Jim_Eval_Named(interp, str, __THIS__FILE__, __LINE__);
 
-       jtag_poll_set_enabled(save_poll);
+       jtag_poll_unmask(save_poll_mask);
 
        command_log_capture_finish(state);
 
index 27c7b3de493206a81d6384eaaa722195934634db..806ee892657bd0d61ce326630362044b5dab67bd 100644 (file)
@@ -136,14 +136,19 @@ int jtag_error_clear(void)
 
 /************/
 
-static bool jtag_poll = 1;
+static bool jtag_poll = true;
+static bool jtag_poll_en = true;
 
 bool is_jtag_poll_safe(void)
 {
        /* Polling can be disabled explicitly with set_enabled(false).
+        * It can also be masked with mask().
         * It is also implicitly disabled while TRST is active and
         * while SRST is gating the JTAG clock.
         */
+       if (!jtag_poll_en)
+               return false;
+
        if (!transport_is_jtag())
                return jtag_poll;
 
@@ -162,6 +167,18 @@ void jtag_poll_set_enabled(bool value)
        jtag_poll = value;
 }
 
+bool jtag_poll_mask(void)
+{
+       bool retval = jtag_poll_en;
+       jtag_poll_en = false;
+       return retval;
+}
+
+void jtag_poll_unmask(bool saved)
+{
+       jtag_poll_en = saved;
+}
+
 /************/
 
 struct jtag_tap *jtag_all_taps(void)
index 18e09ced34d95a25d537941a255f3dcec89d561e..4f94e991357a57a90727ffd217696671156ccf1d 100644 (file)
@@ -587,6 +587,19 @@ bool jtag_poll_get_enabled(void);
  */
 void jtag_poll_set_enabled(bool value);
 
+/**
+ * Mask (disable) polling and return the current mask status that should be
+ * feed to jtag_poll_unmask() to restore it.
+ * Multiple nested calls to jtag_poll_mask() are allowed, each balanced with
+ * its call to jtag_poll_unmask().
+ */
+bool jtag_poll_mask(void);
+
+/**
+ * Restore saved mask for polling.
+ */
+void jtag_poll_unmask(bool saved);
+
 #include <jtag/minidriver.h>
 
 int jim_jtag_newtap(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
index 553400df68297dff7eb6721092865d49c0191b19..10a25efde6193afeedb04b7310374807df8a7b13 100644 (file)
@@ -654,10 +654,10 @@ int target_resume(struct target *target, int current, target_addr_t address,
         * Disable polling during resume() to guarantee the execution of handlers
         * in the correct order.
         */
-       bool save_poll = jtag_poll_get_enabled();
-       jtag_poll_set_enabled(false);
+       bool save_poll_mask = jtag_poll_mask();
        retval = target->type->resume(target, current, address, handle_breakpoints, debug_execution);
-       jtag_poll_set_enabled(save_poll);
+       jtag_poll_unmask(save_poll_mask);
+
        if (retval != ERROR_OK)
                return retval;
 
@@ -685,14 +685,12 @@ static int target_process_reset(struct command_invocation *cmd, enum target_rese
         * more predictable, i.e. dr/irscan & pathmove in events will
         * not have JTAG operations injected into the middle of a sequence.
         */
-       bool save_poll = jtag_poll_get_enabled();
-
-       jtag_poll_set_enabled(false);
+       bool save_poll_mask = jtag_poll_mask();
 
        sprintf(buf, "ocd_process_reset %s", n->name);
        retval = Jim_Eval(cmd->ctx->interp, buf);
 
-       jtag_poll_set_enabled(save_poll);
+       jtag_poll_unmask(save_poll_mask);
 
        if (retval != JIM_OK) {
                Jim_MakeErrorMessage(cmd->ctx->interp);

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)