This is an automated email from Gerrit.

Tarek BOCHKATI ([email protected]) just uploaded a new patch set to 
Gerrit, which you can find at http://openocd.zylin.com/5345

-- gerrit

commit ad91ba36b48b5a7d1bc93cb8ac61b4bf76a0c650
Author: Tarek BOCHKATI <[email protected]>
Date:   Mon Nov 25 15:34:14 2019 +0100

    armv7m: add a TCP channel to stream captured trace
    
    When trace capturing the trace is enabled using 'tpiu_config internal'
    (via the internal mode), OpenOCD can collect the trace buffers then append
    it to a specified file or named pipe and propagate the trace to 'tcl_trace'
    command.
    This change is allowing to stream the captured trace over TCP.
    
    Example on STM32F7 running at 216MHz:
      itm port 0 on
      tpiu config internal :3344 uart off 216000000
    
    
    Change-Id: Idea43e7e26e87b98a33da7fb9acf7ea50fe3b345
    Signed-off-by: Tarek BOCHKATI <[email protected]>

diff --git a/doc/openocd.texi b/doc/openocd.texi
index 440f434..54e241e 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -8976,7 +8976,7 @@ Selects whether interrupts will be processed when single 
stepping
 @cindex ITM
 @cindex ETM
 
-@deffn Command {tpiu config} (@option{disable} | ((@option{external} | 
@option{internal (@var{filename} | -)}) @
+@deffn Command {tpiu config} (@option{disable} | ((@option{external} | 
@option{internal (@var{filename} | @var{:port} | -)}) @
                (@option{sync @var{port_width}} | ((@option{manchester} | 
@option{uart}) @var{formatter_enable})) @
                @var{TRACECLKIN_freq} [@var{trace_freq}]))
 
@@ -8996,23 +8996,25 @@ Command options:
 @itemize @minus
 @item @option{disable} disable TPIU handling;
 @item @option{external} configure TPIU to let user capture trace
-output externally (with an additional UART or logic analyzer hardware);
-@item @option{internal @var{filename}} configure TPIU and debug adapter to
-gather trace data and append it to @var{filename} (which can be
-either a regular file or a named pipe);
-@item @option{internal -} configure TPIU and debug adapter to
-gather trace data, but not write to any file. Useful in conjunction with the 
@command{tcl_trace} command;
+output externally (with an additional UART or logic analyzer hardware).
+@item @option{internal (@var{filename} | @var{:port} | -)} configure TPIU and 
debug adapter to
+gather trace data and append it to:
+@itemize @minus
+@item a regular file or a named pipe if @var{filename} is specified.
+@item a TCP/IP port if @var{:port} is specified.
+@item nothing if '-' is specified. Useful in conjunction with the 
@command{tcl_trace} command.
+@end itemize
 @item @option{sync @var{port_width}} use synchronous parallel trace output
-mode, and set port width to @var{port_width};
+mode, and set port width to @var{port_width}.
 @item @option{manchester} use asynchronous SWO mode with Manchester
-coding;
+coding.
 @item @option{uart} use asynchronous SWO mode with NRZ (same as
-regular UART 8N1) coding;
+regular UART 8N1) coding.
 @item @var{formatter_enable} is @option{on} or @option{off} to enable
 or disable TPIU formatter which needs to be used when both ITM and ETM
-data is to be output via SWO;
+data is to be output via SWO.
 @item @var{TRACECLKIN_freq} this should be specified to match target's
-current TRACECLKIN frequency (usually the same as HCLK);
+current TRACECLKIN frequency (usually the same as HCLK).
 @item @var{trace_freq} trace port frequency. Can be omitted in
 internal mode to let the adapter driver select the maximum supported
 rate automatically.
diff --git a/src/target/armv7m_trace.c b/src/target/armv7m_trace.c
index 6170119..c8137be 100644
--- a/src/target/armv7m_trace.c
+++ b/src/target/armv7m_trace.c
@@ -40,13 +40,31 @@ static int armv7m_poll_trace(void *target)
 
        target_call_trace_callbacks(target, size, buf);
 
-       if (armv7m->trace_config.trace_file != NULL) {
-               if (fwrite(buf, 1, size, armv7m->trace_config.trace_file) == 
size)
-                       fflush(armv7m->trace_config.trace_file);
-               else {
-                       LOG_ERROR("Error writing to the trace destination 
file");
-                       return ERROR_FAIL;
+       switch (armv7m->trace_config.internal_channel) {
+       case TRACE_INTERNAL_CHANNEL_FILE:
+               if (armv7m->trace_config.trace_file != NULL) {
+                       if (fwrite(buf, 1, size, 
armv7m->trace_config.trace_file) == size)
+                               fflush(armv7m->trace_config.trace_file);
+                       else {
+                               LOG_ERROR("Error writing to the trace 
destination file");
+                               return ERROR_FAIL;
+                       }
+               }
+               break;
+       case TRACE_INTERNAL_CHANNEL_TCP:
+               if (armv7m->trace_config.trace_connection != NULL) {
+                       if 
(connection_write(armv7m->trace_config.trace_connection, buf, size) != (int) 
size) {
+                               LOG_ERROR("Error streaming the trace to TCP/IP 
port");
+                               return ERROR_FAIL;
+                       }
                }
+               break;
+       case TRACE_INTERNAL_CHANNEL_NONE:
+               /* nothing to do */
+               break;
+       default:
+               LOG_ERROR("unsupported trace internal channel");
+               return ERROR_FAIL;
        }
 
        return ERROR_OK;
@@ -154,11 +172,44 @@ int armv7m_trace_itm_config(struct target *target)
        return ERROR_OK;
 }
 
-static void close_trace_file(struct armv7m_common *armv7m)
+static void close_trace_channel(struct armv7m_common *armv7m)
+{
+       switch (armv7m->trace_config.internal_channel) {
+       case TRACE_INTERNAL_CHANNEL_FILE:
+               if (armv7m->trace_config.trace_file)
+                       fclose(armv7m->trace_config.trace_file);
+               armv7m->trace_config.trace_file = NULL;
+               break;
+       case TRACE_INTERNAL_CHANNEL_TCP:
+               if (armv7m->trace_config.trace_connection) {
+                       struct service *service = 
armv7m->trace_config.trace_connection->service;
+                       remove_service(service->name, service->port);
+               }
+               armv7m->trace_config.trace_connection = NULL;
+               break;
+       case TRACE_INTERNAL_CHANNEL_NONE:
+               /* nothing to do */
+               break;
+       default:
+               LOG_ERROR("unsupported trace internal channel");
+       }
+}
+
+static int trace_new_connection(struct connection *connection)
+{
+       struct armv7m_common *armv7m = 
target_to_armv7m(connection->service->priv);
+       armv7m->trace_config.trace_connection = connection;
+       return ERROR_OK;
+}
+
+static int trace_input(struct connection *connection)
 {
-       if (armv7m->trace_config.trace_file)
-               fclose(armv7m->trace_config.trace_file);
-       armv7m->trace_config.trace_file = NULL;
+       return ERROR_OK;
+}
+
+static int trace_connection_closed(struct connection *connection)
+{
+       return ERROR_OK;
 }
 
 COMMAND_HANDLER(handle_tpiu_config_command)
@@ -172,7 +223,7 @@ COMMAND_HANDLER(handle_tpiu_config_command)
                return ERROR_COMMAND_SYNTAX_ERROR;
        if (!strcmp(CMD_ARGV[cmd_idx], "disable")) {
                if (CMD_ARGC == cmd_idx + 1) {
-                       close_trace_file(armv7m);
+                       close_trace_channel(armv7m);
 
                        armv7m->trace_config.config_type = 
TRACE_CONFIG_TYPE_DISABLED;
                        if (CMD_CTX->mode == COMMAND_EXEC)
@@ -182,7 +233,7 @@ COMMAND_HANDLER(handle_tpiu_config_command)
                }
        } else if (!strcmp(CMD_ARGV[cmd_idx], "external") ||
                   !strcmp(CMD_ARGV[cmd_idx], "internal")) {
-               close_trace_file(armv7m);
+               close_trace_channel(armv7m);
 
                armv7m->trace_config.config_type = TRACE_CONFIG_TYPE_EXTERNAL;
                if (!strcmp(CMD_ARGV[cmd_idx], "internal")) {
@@ -191,12 +242,24 @@ COMMAND_HANDLER(handle_tpiu_config_command)
                                return ERROR_COMMAND_SYNTAX_ERROR;
 
                        armv7m->trace_config.config_type = 
TRACE_CONFIG_TYPE_INTERNAL;
+                       armv7m->trace_config.internal_channel = 
TRACE_INTERNAL_CHANNEL_NONE;
 
                        if (strcmp(CMD_ARGV[cmd_idx], "-") != 0) {
-                               armv7m->trace_config.trace_file = 
fopen(CMD_ARGV[cmd_idx], "ab");
-                               if (!armv7m->trace_config.trace_file) {
-                                       LOG_ERROR("Can't open trace destination 
file");
-                                       return ERROR_FAIL;
+                               if (CMD_ARGV[cmd_idx][0] == ':') {
+                                       armv7m->trace_config.internal_channel = 
TRACE_INTERNAL_CHANNEL_TCP;
+                                       int ret = add_service("trace viewer", 
&(CMD_ARGV[cmd_idx][1]), 1,
+                                               trace_new_connection, 
trace_input, trace_connection_closed, target);
+                                       if (ret != ERROR_OK) {
+                                               LOG_ERROR("Can't configure 
trace TCP port");
+                                               return ERROR_FAIL;
+                                       }
+                               } else {
+                                       armv7m->trace_config.internal_channel = 
TRACE_INTERNAL_CHANNEL_FILE;
+                                       armv7m->trace_config.trace_file = 
fopen(CMD_ARGV[cmd_idx], "ab");
+                                       if (!armv7m->trace_config.trace_file) {
+                                               LOG_ERROR("Can't open trace 
destination file");
+                                               return ERROR_FAIL;
+                                       }
                                }
                        }
                }
@@ -308,7 +371,7 @@ static const struct command_registration 
tpiu_command_handlers[] = {
                .mode = COMMAND_ANY,
                .help = "Configure TPIU features",
                .usage = "(disable | "
-               "((external | internal <filename>) "
+               "((external | internal (<filename> | <:port> | -)) "
                "(sync <port width> | ((manchester | uart) <formatter enable>)) 
"
                "<TRACECLKIN freq> [<trace freq>]))",
        },
diff --git a/src/target/armv7m_trace.h b/src/target/armv7m_trace.h
index c63f36d..4b74ba1 100644
--- a/src/target/armv7m_trace.h
+++ b/src/target/armv7m_trace.h
@@ -18,6 +18,7 @@
 #ifndef OPENOCD_TARGET_ARMV7M_TRACE_H
 #define OPENOCD_TARGET_ARMV7M_TRACE_H
 
+#include <server/server.h>
 #include <target/target.h>
 #include <command.h>
 
@@ -32,6 +33,12 @@ enum trace_config_type {
        TRACE_CONFIG_TYPE_INTERNAL      /**< trace output is handled by OpenOCD 
adapter driver */
 };
 
+enum trace_internal_channel {
+       TRACE_INTERNAL_CHANNEL_NONE,    /** trace data is sent only to 
'tcl_trace'  */
+       TRACE_INTERNAL_CHANNEL_FILE,    /** trace data is appended to a file */
+       TRACE_INTERNAL_CHANNEL_TCP              /** trace data is appended to a 
TCP/IP port*/
+};
+
 enum tpiu_pin_protocol {
        TPIU_PIN_PROTOCOL_SYNC,                 /**< synchronous trace output */
        TPIU_PIN_PROTOCOL_ASYNC_MANCHESTER,     /**< asynchronous output with 
Manchester coding */
@@ -49,6 +56,9 @@ struct armv7m_trace_config {
        /** Currently active trace capture mode */
        enum trace_config_type config_type;
 
+       /** The used channel when internal mode is selected */
+       enum trace_internal_channel internal_channel;
+
        /** Currently active trace output mode */
        enum tpiu_pin_protocol pin_protocol;
        /** TPIU formatter enable/disable (in async mode) */
@@ -73,8 +83,10 @@ struct armv7m_trace_config {
        unsigned int traceclkin_freq;
        /** Current frequency of trace port */
        unsigned int trace_freq;
-       /** Handle to output trace data in INTERNAL capture mode */
+       /** Handle to output trace data in INTERNAL capture mode via file */
        FILE *trace_file;
+       /** Handle to output trace data in INTERNAL capture mode via tcp */
+       struct connection *trace_connection;
 };
 
 extern const struct command_registration armv7m_trace_command_handlers[];

-- 


_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to