This is an automated email from Gerrit.

"Name of user not set <zed...@gmail.com>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/6756

-- gerrit

commit d16b389502c878f0f3fc6ee07a9bfb6346a1673f
Author: Zoltán Dudás <zed...@gmail.com>
Date:   Thu Nov 25 17:54:00 2021 +0100

    rtt: Optional automatic rtt stopping at flash write
    
    If the module found a control block on certain address it will tries to use 
it
    until another setup command arrives.
    If the user loads a new image with the control block on different address,
    the module won't search to refresh the stored address, the rtt will not
    work, furthermore if unlucky values found on the previous location,
    the module will start to read the memory arbitrarily.
    
    Signed-off-by: Zoltán Dudás <zed...@gmail.com>
    Change-Id: I4095a8fcd7bc7b77cccc7d14c18b7dff5ecd4e8e

diff --git a/doc/openocd.texi b/doc/openocd.texi
index 0ab4b36ac..d6c79cea0 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -8662,11 +8662,12 @@ Channels are exposed via raw TCP/IP connections. One or 
more RTT servers can be
 assigned to each channel to make them accessible to an unlimited number
 of TCP/IP connections.
 
-@deffn {Command} {rtt setup} address size ID
+@deffn {Command} {rtt setup} address size ID [auto_stop]
 Configure RTT for the currently selected target.
 Once RTT is started, OpenOCD searches for a control block with the
 identifier @var{ID} starting at the memory address @var{address} within the 
next
-@var{size} bytes.
+@var{size} bytes. If the optional @var{auto_stop} parameter is present, the
+RTT is automatically stopped before flash write operations.
 @end deffn
 
 @deffn {Command} {rtt start}
diff --git a/src/rtt/rtt.c b/src/rtt/rtt.c
index bf3cca51b..d0a96f6ba 100644
--- a/src/rtt/rtt.c
+++ b/src/rtt/rtt.c
@@ -45,6 +45,8 @@ static struct {
        bool changed;
        /** Whether the control block was found. */
        bool found_cb;
+       /** Whether the automatic stopping at target flash write enabled. */
+       bool auto_stop;
 
        struct rtt_sink_list **sink_list;
        size_t sink_list_length;
@@ -92,7 +94,19 @@ static int read_channel_callback(void *user_data)
        return ERROR_OK;
 }
 
-int rtt_setup(target_addr_t address, size_t size, const char *id)
+static int load_callback_event_handler(struct target *target,
+       enum target_event event,
+       void *priv)
+{
+       if (rtt.auto_stop && event == TARGET_EVENT_GDB_FLASH_WRITE_START) {
+               LOG_INFO("Automatically stopping rtt before flash write");
+               rtt_stop();
+       }
+       return ERROR_OK;
+}
+
+int rtt_setup(target_addr_t address, size_t size, const char *id,
+               bool auto_stop)
 {
        size_t id_length = strlen(id);
 
@@ -106,6 +120,16 @@ int rtt_setup(target_addr_t address, size_t size, const 
char *id)
        strncpy(rtt.id, id, id_length + 1);
        rtt.changed = true;
        rtt.configured = true;
+       rtt.auto_stop = auto_stop;
+
+       if (auto_stop) {
+               target_register_event_callback(&load_callback_event_handler,
+                       NULL);
+               LOG_INFO("rtt: Automatic stop at flash write events are 
enabled");
+       } else {
+               target_unregister_event_callback(&load_callback_event_handler,
+                       NULL);
+       }
 
        return ERROR_OK;
 }
diff --git a/src/rtt/rtt.h b/src/rtt/rtt.h
index bc21bd012..12027f688 100644
--- a/src/rtt/rtt.h
+++ b/src/rtt/rtt.h
@@ -168,10 +168,11 @@ int rtt_register_source(const struct rtt_source source,
  * @param[in] address Start address to search for the control block.
  * @param[in] size Size of the control block search area.
  * @param[in] id Identifier of the control block. Must be null-terminated.
+ * @param[in] auto_stop Whether auto_stop to be enabled.
  *
  * @returns ERROR_OK on success, an error code on failure.
  */
-int rtt_setup(target_addr_t address, size_t size, const char *id);
+int rtt_setup(target_addr_t address, size_t size, const char *id, bool 
auto_stop);
 
 /**
  * Start Real-Time Transfer (RTT).
diff --git a/src/rtt/tcl.c b/src/rtt/tcl.c
index f5abf2e5e..72d3092bc 100644
--- a/src/rtt/tcl.c
+++ b/src/rtt/tcl.c
@@ -26,9 +26,14 @@ COMMAND_HANDLER(handle_rtt_setup_command)
 {
 struct rtt_source source;
 
-       if (CMD_ARGC != 3)
+       if (CMD_ARGC < 3 || CMD_ARGC > 4)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
+       bool enable_auto_stop = false;
+       if ((CMD_ARGC == 4) && !strcmp(CMD_ARGV[3], "auto_stop")) {
+               enable_auto_stop = true;
+       }
+
        source.find_cb = &target_rtt_find_control_block;
        source.read_cb = &target_rtt_read_control_block;
        source.start = &target_rtt_start;
@@ -45,7 +50,7 @@ struct rtt_source source;
 
        rtt_register_source(source, get_current_target(CMD_CTX));
 
-       if (rtt_setup(address, size, CMD_ARGV[2]) != ERROR_OK)
+       if (rtt_setup(address, size, CMD_ARGV[2], enable_auto_stop) != ERROR_OK)
                return ERROR_FAIL;
 
        return ERROR_OK;
@@ -259,7 +264,7 @@ static const struct command_registration 
rtt_subcommand_handlers[] = {
                .handler = handle_rtt_setup_command,
                .mode = COMMAND_ANY,
                .help = "setup RTT",
-               .usage = "<address> <size> <ID>"
+               .usage = "<address> <size> <ID> [auto_suspend]"
        },
        {
                .name = "start",

-- 

Reply via email to