From: OpenOCD-Gerrit <ope...@us...> - 2021-03-10 21:35:07
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via cb8e3fb2d925c6563c3520391c3b1c7e71d1b817 (commit) via dc7b32ea4a00a425a71b3309f3fceb07b8467592 (commit) via c945d6e6160598894319860a92b602a192c2c268 (commit) from 184724d14e120a9901fedfe05692bcd270f5eb57 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit cb8e3fb2d925c6563c3520391c3b1c7e71d1b817 Author: Antonio Borneo <bor...@gm...> Date: Fri Nov 13 23:39:26 2020 +0100 server: revert commit 7e6556b3cad8 With the removal of old tpiu code, commit 7e6556b3cad8 ("server: permit the add_service function to return the created service") http://openocd.zylin.com/5717/ can be reverted. Fix also the new calls to add_service(). Change-Id: Ib7f2dfc6a9e829239e20313e0f121911085fdc00 Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: http://openocd.zylin.com/6031 Tested-by: jenkins Reviewed-by: Adrian M Negreanu <adr...@nx...> diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 9e44287fd..fc58971a7 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -3509,7 +3509,7 @@ static int gdb_target_start(struct target *target, const char *port) ret = add_service("gdb", port, target->gdb_max_connections, &gdb_new_connection, &gdb_input, - &gdb_connection_closed, gdb_service, NULL); + &gdb_connection_closed, gdb_service); /* initialize all targets gdb service with the same pointer */ { struct target_list *head; diff --git a/src/server/rtt_server.c b/src/server/rtt_server.c index 3c885cce0..d49e4d000 100644 --- a/src/server/rtt_server.c +++ b/src/server/rtt_server.c @@ -126,7 +126,7 @@ COMMAND_HANDLER(handle_rtt_start_command) COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], service->channel); ret = add_service("rtt", CMD_ARGV[0], CONNECTION_LIMIT_UNLIMITED, - rtt_new_connection, rtt_input, rtt_connection_closed, service, NULL); + rtt_new_connection, rtt_input, rtt_connection_closed, service); if (ret != ERROR_OK) { free(service); diff --git a/src/server/server.c b/src/server/server.c index 114af7632..e53f37d0b 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -210,8 +210,7 @@ int add_service(char *name, new_connection_handler_t new_connection_handler, input_handler_t input_handler, connection_closed_handler_t connection_closed_handler, - void *priv, - struct service **new_service) + void *priv) { struct service *c, **p; struct hostent *hp; @@ -347,10 +346,6 @@ int add_service(char *name, ; *p = c; - /* if new_service is not NULL, return the created service into it */ - if (new_service) - *new_service = c; - return ERROR_OK; } diff --git a/src/server/server.h b/src/server/server.h index 99f5fe2ed..ff2ada9cb 100644 --- a/src/server/server.h +++ b/src/server/server.h @@ -77,7 +77,7 @@ struct service { int add_service(char *name, const char *port, int max_connections, new_connection_handler_t new_connection_handler, input_handler_t in_handler, connection_closed_handler_t close_handler, - void *priv, struct service **new_service); + void *priv); int remove_service(const char *name, const char *port); int server_host_os_entry(void); diff --git a/src/server/tcl_server.c b/src/server/tcl_server.c index 07213ae79..1ecb827a1 100644 --- a/src/server/tcl_server.c +++ b/src/server/tcl_server.c @@ -285,7 +285,7 @@ int tcl_init(void) return add_service("tcl", tcl_port, CONNECTION_LIMIT_UNLIMITED, &tcl_new_connection, &tcl_input, - &tcl_closed, NULL, NULL); + &tcl_closed, NULL); } COMMAND_HANDLER(handle_tcl_port_command) diff --git a/src/server/telnet_server.c b/src/server/telnet_server.c index 4f88d3a54..407ab68ae 100644 --- a/src/server/telnet_server.c +++ b/src/server/telnet_server.c @@ -694,7 +694,7 @@ int telnet_init(char *banner) int ret = add_service("telnet", telnet_port, CONNECTION_LIMIT_UNLIMITED, telnet_new_connection, telnet_input, telnet_connection_closed, - telnet_service, NULL); + telnet_service); if (ret != ERROR_OK) { free(telnet_service); diff --git a/src/target/arm_tpiu_swo.c b/src/target/arm_tpiu_swo.c index b492438d4..2da52e892 100644 --- a/src/target/arm_tpiu_swo.c +++ b/src/target/arm_tpiu_swo.c @@ -697,7 +697,7 @@ static int jim_arm_tpiu_swo_enable(Jim_Interp *interp, int argc, Jim_Obj *const retval = add_service("tpiu_swo_trace", &obj->out_filename[1], CONNECTION_LIMIT_UNLIMITED, arm_tpiu_swo_service_new_connection, arm_tpiu_swo_service_input, arm_tpiu_swo_service_connection_closed, - priv, NULL); + priv); if (retval != ERROR_OK) { LOG_ERROR("Can't configure trace TCP port %s", &obj->out_filename[1]); return JIM_ERR; diff --git a/src/target/openrisc/jsp_server.c b/src/target/openrisc/jsp_server.c index b4b25665d..4dbe63527 100644 --- a/src/target/openrisc/jsp_server.c +++ b/src/target/openrisc/jsp_server.c @@ -207,8 +207,7 @@ int jsp_init(struct or1k_jtag *jtag_info, char *banner) jsp_new_connection, jsp_input, jsp_connection_closed, - jsp_service, - NULL); + jsp_service); } COMMAND_HANDLER(handle_jsp_port_command) commit dc7b32ea4a00a425a71b3309f3fceb07b8467592 Author: Antonio Borneo <bor...@gm...> Date: Fri Nov 13 23:36:24 2020 +0100 armv7m_trace: get rid of the old tpiu code Remove all the old tpiu code and replace it with a wrapper that uses the new commands, prints-out the new commands and informs about the deprecation. All the code that handles the deprecated tpiu commands is enclosed between the comments /* START_DEPRECATED_TPIU */ and /* END_DEPRECATED_TPIU */ so will be easy to remove it in the future. Change-Id: I70b0486770128203b923346382d9a90b8ec08439 Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: http://openocd.zylin.com/6030 Tested-by: jenkins Reviewed-by: Adrian M Negreanu <adr...@nx...> diff --git a/doc/openocd.texi b/doc/openocd.texi index bd4380a2b..0c1714e49 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -9642,54 +9642,6 @@ Disable the TPIU or the SWO, terminating the receiving of the trace data. @end deffn -TODO: remove the old tpiu commands - -@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}])) - -ARMv7-M architecture provides several modules to generate debugging -information internally (ITM, DWT and ETM). Their output is directed -through TPIU to be captured externally either on an SWO pin (this -configuration is called SWV) or on a synchronous parallel trace port. - -This command configures the TPIU module of the target and, if internal -capture mode is selected, starts to capture trace output by using the -debugger adapter features. - -Some targets require additional actions to be performed in the -@b{trace-config} handler for trace port to be activated. - -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} | @var{:port} | -)} configure TPIU and debug adapter to -gather trace data then: - -@itemize @minus -@item append it to a regular file or a named pipe if @var{filename} is specified. -@item listen to a TCP/IP port if @var{:port} is specified, then broadcast the trace data over this port. -@item if '-' is specified, OpenOCD will forward trace data to @command{tcl_trace} command. -@*@b{Note:} while broadcasting to file or TCP, the forwarding to @command{tcl_trace} will remain active. -@end itemize - -@item @option{sync @var{port_width}} use synchronous parallel trace output -mode, and set port width to @var{port_width}. -@item @option{manchester} use asynchronous SWO mode with Manchester -coding. -@item @option{uart} use asynchronous SWO mode with NRZ (same as -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. -@item @var{TRACECLKIN_freq} this should be specified to match target's -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. -@end itemize Example usage: @enumerate @@ -9725,7 +9677,6 @@ openocd -f interface/stlink.cfg \ -c "stm32l1.tpiu enable" @end example @end enumerate -@end deffn @subsection ARMv7-M specific commands @cindex tracing diff --git a/src/jtag/interface.h b/src/jtag/interface.h index 0884868a8..58bfd02b0 100644 --- a/src/jtag/interface.h +++ b/src/jtag/interface.h @@ -27,7 +27,7 @@ #include <jtag/jtag.h> #include <jtag/swim.h> -#include <target/armv7m_trace.h> +#include <target/arm_tpiu_swo.h> /* @file * The "Cable Helper API" is what the cable drivers can use to help diff --git a/src/target/arm_tpiu_swo.c b/src/target/arm_tpiu_swo.c index 61891cb57..b492438d4 100644 --- a/src/target/arm_tpiu_swo.c +++ b/src/target/arm_tpiu_swo.c @@ -38,6 +38,12 @@ #include <transport/transport.h> #include "arm_tpiu_swo.h" +/* START_DEPRECATED_TPIU */ +#include <target/cortex_m.h> +#include <target/target_type.h> +#define MSG "DEPRECATED \'tpiu config\' command: " +/* END_DEPRECATED_TPIU */ + #define TCP_SERVICE_NAME "tpiu_swo_trace" /* default for Cortex-M3 and Cortex-M4 specific TPIU */ @@ -53,9 +59,9 @@ #define TPIU_DEVID_OFFSET 0xfc8 #define TPIU_ACPR_MAX_PRESCALER 0x1fff -#define TPIU_SPPR_PROTOCOL_SYNC 0x0 /**< synchronous trace output */ -#define TPIU_SPPR_PROTOCOL_MANCHESTER 0x1 /**< asynchronous output with NRZ coding */ -#define TPIU_SPPR_PROTOCOL_UART 0x2 /**< asynchronous output with Manchester coding */ +#define TPIU_SPPR_PROTOCOL_SYNC (TPIU_PIN_PROTOCOL_SYNC) +#define TPIU_SPPR_PROTOCOL_MANCHESTER (TPIU_PIN_PROTOCOL_ASYNC_MANCHESTER) +#define TPIU_SPPR_PROTOCOL_UART (TPIU_PIN_PROTOCOL_ASYNC_UART) #define TPIU_DEVID_NOSUPPORT_SYNC BIT(9) #define TPIU_DEVID_SUPPORT_MANCHESTER BIT(10) #define TPIU_DEVID_SUPPORT_UART BIT(11) @@ -106,6 +112,9 @@ struct arm_tpiu_swo_object { char *out_filename; /** track TCP connections */ struct list_head connections; + /* START_DEPRECATED_TPIU */ + bool recheck_ap_cur_target; + /* END_DEPRECATED_TPIU */ }; struct arm_tpiu_swo_connection { @@ -612,6 +621,31 @@ static int jim_arm_tpiu_swo_enable(Jim_Interp *interp, int argc, Jim_Obj *const struct target *target = get_current_target(cmd_ctx); + /* START_DEPRECATED_TPIU */ + if (obj->recheck_ap_cur_target) { + if (strcmp(target->type->name, "cortex_m") && + strcmp(target->type->name, "hla_target")) { + LOG_ERROR(MSG "Current target is not a Cortex-M nor a HLA"); + return JIM_ERR; + } + if (!target_was_examined(target)) { + LOG_ERROR(MSG "Current target not examined yet"); + return JIM_ERR; + } + struct cortex_m_common *cm = target_to_cm(target); + obj->recheck_ap_cur_target = false; + obj->spot.ap_num = cm->armv7m.debug_ap->ap_num; + tpiu_ap = dap_ap(obj->spot.dap, obj->spot.ap_num); + if (obj->spot.ap_num == 0) + LOG_INFO(MSG "Confirmed TPIU %s is on AP 0", obj->name); + else + LOG_INFO(MSG "Target %s is on AP %d. Revised command is " + "\'tpiu create %s -dap %s -ap-num %d\'", + target_name(target), obj->spot.ap_num, + obj->name, adiv5_dap_name(obj->spot.dap), obj->spot.ap_num); + } + /* END_DEPRECATED_TPIU */ + /* trigger the event before any attempt to R/W in the TPIU/SWO */ arm_tpiu_swo_handle_event(obj, TPIU_SWO_EVENT_PRE_ENABLE); @@ -951,6 +985,163 @@ static int jim_arm_tpiu_swo_init(Jim_Interp *interp, int argc, Jim_Obj *const *a return retval; } +/* START_DEPRECATED_TPIU */ +/* DEPRECATED: emulation of old command 'tpiu config' */ +COMMAND_HANDLER(handle_tpiu_deprecated_config_command) +{ + struct target *target = get_current_target(CMD_CTX); + struct arm_tpiu_swo_object *obj = NULL; + int retval; + + if (strcmp(target->type->name, "cortex_m") && + strcmp(target->type->name, "hla_target")) { + LOG_ERROR(MSG "Current target is not a Cortex-M nor a HLA"); + return ERROR_FAIL; + } + + if (!list_empty(&all_tpiu_swo)) { + obj = list_first_entry(&all_tpiu_swo, typeof(*obj), lh); + LOG_INFO(MSG "Using %s", obj->name); + } else { + struct cortex_m_common *cm = target_to_cm(target); + struct adiv5_private_config *pc = target->private_config; + struct adiv5_dap *dap = pc->dap; + int ap_num = pc->ap_num; + bool set_recheck_ap_cur_target = false; + + LOG_INFO(MSG "Adding a TPIU \'%s.tpiu\' in the configuration", target_name(target)); + + if (ap_num == DP_APSEL_INVALID && transport_is_hla()) + ap_num = 0; /* HLA should only support AP 0 */ + + if (ap_num == DP_APSEL_INVALID && target_was_examined(target)) + ap_num = cm->armv7m.debug_ap->ap_num; + + if (ap_num == DP_APSEL_INVALID) { + LOG_INFO(MSG "Target %s uses AP autodetection. Adding TPIU on AP 0; can be revised later", + target_name(target)); + ap_num = 0; + set_recheck_ap_cur_target = true; + } + + LOG_INFO(MSG "Running: \'tpiu create %s.tpiu -dap %s -ap-num %d\'", + target_name(target), adiv5_dap_name(dap), ap_num); + + retval = command_run_linef(CMD_CTX, "tpiu create %s.tpiu -dap %s -ap-num %d", + target_name(target), adiv5_dap_name(dap), ap_num); + if (retval != ERROR_OK) + return retval; + + obj = list_first_entry(&all_tpiu_swo, typeof(*obj), lh); + if (set_recheck_ap_cur_target) + obj->recheck_ap_cur_target = true; + } + + unsigned int cmd_idx = 0; + if (CMD_ARGC == cmd_idx) + return ERROR_COMMAND_SYNTAX_ERROR; + + if (!strcmp(CMD_ARGV[cmd_idx], "disable")) { + if (CMD_ARGC != cmd_idx + 1) + return ERROR_COMMAND_SYNTAX_ERROR; + LOG_INFO(MSG "Running: \'%s disable\'", obj->name); + return command_run_linef(CMD_CTX, "%s disable", obj->name); + } + + const char *output = NULL; + const char *protocol; + const char *formatter = NULL; + const char *port_width = NULL; + const char *trace_clk; + const char *pin_clk = NULL; + if (!strcmp(CMD_ARGV[cmd_idx], "internal")) { + cmd_idx++; + if (CMD_ARGC == cmd_idx) + return ERROR_COMMAND_SYNTAX_ERROR; + output = CMD_ARGV[cmd_idx]; + } else if (strcmp(CMD_ARGV[cmd_idx], "external")) + return ERROR_COMMAND_SYNTAX_ERROR; + cmd_idx++; + if (CMD_ARGC == cmd_idx) + return ERROR_COMMAND_SYNTAX_ERROR; + if (!strcmp(CMD_ARGV[cmd_idx], "sync")) { + protocol = CMD_ARGV[cmd_idx]; + cmd_idx++; + if (CMD_ARGC == cmd_idx) + return ERROR_COMMAND_SYNTAX_ERROR; + port_width = CMD_ARGV[cmd_idx]; + } else { + if (strcmp(CMD_ARGV[cmd_idx], "manchester") && strcmp(CMD_ARGV[cmd_idx], "uart")) + return ERROR_COMMAND_SYNTAX_ERROR; + protocol = CMD_ARGV[cmd_idx]; + cmd_idx++; + if (CMD_ARGC == cmd_idx) + return ERROR_COMMAND_SYNTAX_ERROR; + formatter = CMD_ARGV[cmd_idx]; + } + cmd_idx++; + if (CMD_ARGC == cmd_idx) + return ERROR_COMMAND_SYNTAX_ERROR; + trace_clk = CMD_ARGV[cmd_idx]; + cmd_idx++; + if (CMD_ARGC != cmd_idx) { + pin_clk = CMD_ARGV[cmd_idx]; + cmd_idx++; + } + if (CMD_ARGC != cmd_idx) + return ERROR_COMMAND_SYNTAX_ERROR; + + LOG_INFO(MSG "Running: \'%s configure -protocol %s -traceclk %s" "%s%s" "%s%s" "%s%s" "%s%s\'", + obj->name, protocol, trace_clk, + pin_clk ? " -pin-freq " : "", pin_clk ? pin_clk : "", + output ? " -output " : "", output ? output : "", + formatter ? " -formatter " : "", formatter ? formatter : "", + port_width ? " -port-width " : "", port_width ? port_width : ""); + + retval = command_run_linef(CMD_CTX, + "%s configure -protocol %s -traceclk %s" "%s%s" "%s%s" "%s%s" "%s%s", + obj->name, protocol, trace_clk, + pin_clk ? " -pin-freq " : "", pin_clk ? pin_clk : "", + output ? " -output " : "", output ? output : "", + formatter ? " -formatter " : "", formatter ? formatter : "", + port_width ? " -port-width " : "", port_width ? port_width : ""); + if (retval != ERROR_OK) + return retval; + + LOG_INFO(MSG "Running: \'%s enable\'", obj->name); + retval = command_run_linef(CMD_CTX, "%s enable", obj->name); + if (retval != ERROR_OK) + return retval; + + target_handle_event(target, TARGET_EVENT_TRACE_CONFIG); + return ERROR_OK; +} + +static const struct command_registration arm_tpiu_deprecated_subcommand_handlers[] = { + { + .name = "config", + .handler = handle_tpiu_deprecated_config_command, + .mode = COMMAND_ANY, + .help = "Configure TPIU features, DEPRECATED, use \'tpiu create\'", + .usage = "(disable | " + "((external | internal (<filename> | <:port> | -)) " + "(sync <port width> | ((manchester | uart) <formatter enable>)) " + "<TRACECLKIN freq> [<trace freq>]))", + }, + COMMAND_REGISTRATION_DONE +}; + +const struct command_registration arm_tpiu_deprecated_command_handlers[] = { + { + .name = "tpiu", + .chain = arm_tpiu_deprecated_subcommand_handlers, + .usage = "", + .help = "tpiu command group", + }, + COMMAND_REGISTRATION_DONE +}; +/* END_DEPRECATED_TPIU */ + static const struct command_registration arm_tpiu_swo_subcommand_handlers[] = { { .name = "create", diff --git a/src/target/arm_tpiu_swo.h b/src/target/arm_tpiu_swo.h index e0aed71cb..5904ce291 100644 --- a/src/target/arm_tpiu_swo.h +++ b/src/target/arm_tpiu_swo.h @@ -3,6 +3,18 @@ #ifndef OPENOCD_TARGET_ARM_TPIU_SWO_H #define OPENOCD_TARGET_ARM_TPIU_SWO_H +/* Values should match TPIU_SPPR_PROTOCOL_xxx */ +enum tpiu_pin_protocol { + TPIU_PIN_PROTOCOL_SYNC = 0, /**< synchronous trace output */ + TPIU_PIN_PROTOCOL_ASYNC_MANCHESTER = 1, /**< asynchronous output with Manchester coding */ + TPIU_PIN_PROTOCOL_ASYNC_UART = 2, /**< asynchronous output with NRZ coding */ +}; + +/* START_DEPRECATED_TPIU */ +/* DEPRECATED: emulation of old command 'tpiu config' */ +extern const struct command_registration arm_tpiu_deprecated_command_handlers[]; +/* END_DEPRECATED_TPIU */ + int arm_tpiu_swo_register_commands(struct command_context *cmd_ctx); int arm_tpiu_swo_cleanup_all(void); diff --git a/src/target/armv7m_trace.c b/src/target/armv7m_trace.c index 02f3f1061..74ffaf5a4 100644 --- a/src/target/armv7m_trace.c +++ b/src/target/armv7m_trace.c @@ -26,133 +26,6 @@ #include <jtag/interface.h> #include <helper/time_support.h> -#define TRACE_BUF_SIZE 4096 - -static int armv7m_poll_trace(void *target) -{ - struct armv7m_common *armv7m = target_to_armv7m(target); - uint8_t buf[TRACE_BUF_SIZE]; - size_t size = sizeof(buf); - int retval; - - retval = adapter_poll_trace(buf, &size); - if (retval != ERROR_OK || !size) - return retval; - - target_call_trace_callbacks(target, size, buf); - - 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_service != NULL) { - /* broadcast to all service connections */ - struct connection *connection = armv7m->trace_config.trace_service->connections; - retval = ERROR_OK; - while (connection) { - if (connection_write(connection, buf, size) != (int) size) - retval = ERROR_FAIL; - - connection = connection->next; - } - - if (retval != ERROR_OK) { - LOG_ERROR("Error streaming the trace to TCP/IP port"); - return ERROR_FAIL; - } - } - break; - case TRACE_INTERNAL_CHANNEL_TCL_ONLY: - /* nothing to do : - * the trace data is sent to TCL by calling the target_call_trace_callbacks - **/ - break; - default: - LOG_ERROR("unsupported trace internal channel"); - return ERROR_FAIL; - } - - return ERROR_OK; -} - -int armv7m_trace_tpiu_config(struct target *target) -{ - struct armv7m_common *armv7m = target_to_armv7m(target); - struct armv7m_trace_config *trace_config = &armv7m->trace_config; - uint16_t prescaler = TPIU_ACPR_MAX_SWOSCALER + 1; - int retval; - - target_unregister_timer_callback(armv7m_poll_trace, target); - - retval = adapter_config_trace(trace_config->config_type == TRACE_CONFIG_TYPE_INTERNAL, - trace_config->pin_protocol, trace_config->port_size, - &trace_config->trace_freq, trace_config->traceclkin_freq, &prescaler); - - if (retval != ERROR_OK) - return retval; - - if (trace_config->config_type == TRACE_CONFIG_TYPE_EXTERNAL) { - prescaler = trace_config->traceclkin_freq / trace_config->trace_freq; - - if (trace_config->traceclkin_freq % trace_config->trace_freq) { - prescaler++; - - int trace_freq = trace_config->traceclkin_freq / prescaler; - LOG_INFO("Can not obtain %u trace port frequency from %u " - "TRACECLKIN frequency, using %u instead", - trace_config->trace_freq, trace_config->traceclkin_freq, - trace_freq); - - trace_config->trace_freq = trace_freq; - } - } - - if (!trace_config->trace_freq) { - LOG_ERROR("Trace port frequency is 0, can't enable TPIU"); - return ERROR_FAIL; - } - - retval = target_write_u32(target, TPIU_CSPSR, 1 << trace_config->port_size); - if (retval != ERROR_OK) - return retval; - - retval = target_write_u32(target, TPIU_ACPR, prescaler - 1); - if (retval != ERROR_OK) - return retval; - - retval = target_write_u32(target, TPIU_SPPR, trace_config->pin_protocol); - if (retval != ERROR_OK) - return retval; - - uint32_t ffcr; - retval = target_read_u32(target, TPIU_FFCR, &ffcr); - if (retval != ERROR_OK) - return retval; - if (trace_config->formatter) - ffcr |= (1 << 1); - else - ffcr &= ~(1 << 1); - retval = target_write_u32(target, TPIU_FFCR, ffcr); - if (retval != ERROR_OK) - return retval; - - if (trace_config->config_type == TRACE_CONFIG_TYPE_INTERNAL) - target_register_timer_callback(armv7m_poll_trace, 1, - TARGET_TIMER_TYPE_PERIODIC, target); - - target_call_event_callbacks(target, TARGET_EVENT_TRACE_CONFIG); - - return ERROR_OK; -} - int armv7m_trace_itm_config(struct target *target) { struct armv7m_common *armv7m = target_to_armv7m(target); @@ -210,182 +83,6 @@ int armv7m_trace_itm_config(struct target *target) return ERROR_OK; } -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_service) - remove_service(armv7m->trace_config.trace_service->name, armv7m->trace_config.trace_service->port); - armv7m->trace_config.trace_service = NULL; - break; - case TRACE_INTERNAL_CHANNEL_TCL_ONLY: - /* nothing to do: - * the trace polling is disabled in the beginning of armv7m_trace_tpiu_config - **/ - break; - default: - LOG_ERROR("unsupported trace internal channel"); - } -} - -static int trace_new_connection(struct connection *connection) -{ - /* nothing to do */ - return ERROR_OK; -} - -static int trace_input(struct connection *connection) -{ - /* create a dummy buffer to check if the connection is still active */ - const int buf_len = 100; - unsigned char buf[buf_len]; - int bytes_read = connection_read(connection, buf, buf_len); - - if (bytes_read == 0) - return ERROR_SERVER_REMOTE_CLOSED; - else if (bytes_read == -1) { - LOG_ERROR("error during read: %s", strerror(errno)); - return ERROR_SERVER_REMOTE_CLOSED; - } - - return ERROR_OK; -} - -static int trace_connection_closed(struct connection *connection) -{ - /* nothing to do, no connection->priv to free */ - return ERROR_OK; -} - -extern struct command_context *global_cmd_ctx; - -int armv7m_trace_tpiu_exit(struct target *target) -{ - struct armv7m_common *armv7m = target_to_armv7m(target); - - if (global_cmd_ctx->mode == COMMAND_CONFIG || - armv7m->trace_config.config_type == TRACE_CONFIG_TYPE_DISABLED) - return ERROR_OK; - - close_trace_channel(armv7m); - armv7m->trace_config.config_type = TRACE_CONFIG_TYPE_DISABLED; - return armv7m_trace_tpiu_config(target); -} - -COMMAND_HANDLER(handle_tpiu_config_command) -{ - struct target *target = get_current_target(CMD_CTX); - struct armv7m_common *armv7m = target_to_armv7m(target); - - unsigned int cmd_idx = 0; - - if (CMD_ARGC == cmd_idx) - return ERROR_COMMAND_SYNTAX_ERROR; - if (!strcmp(CMD_ARGV[cmd_idx], "disable")) { - if (CMD_ARGC == cmd_idx + 1) { - close_trace_channel(armv7m); - - armv7m->trace_config.config_type = TRACE_CONFIG_TYPE_DISABLED; - if (CMD_CTX->mode == COMMAND_EXEC) - return armv7m_trace_tpiu_config(target); - else - return ERROR_OK; - } - } else if (!strcmp(CMD_ARGV[cmd_idx], "external") || - !strcmp(CMD_ARGV[cmd_idx], "internal")) { - close_trace_channel(armv7m); - - armv7m->trace_config.config_type = TRACE_CONFIG_TYPE_EXTERNAL; - if (!strcmp(CMD_ARGV[cmd_idx], "internal")) { - cmd_idx++; - if (CMD_ARGC == cmd_idx) - return ERROR_COMMAND_SYNTAX_ERROR; - - armv7m->trace_config.config_type = TRACE_CONFIG_TYPE_INTERNAL; - armv7m->trace_config.internal_channel = TRACE_INTERNAL_CHANNEL_TCL_ONLY; - - if (strcmp(CMD_ARGV[cmd_idx], "-") != 0) { - if (CMD_ARGV[cmd_idx][0] == ':') { - armv7m->trace_config.internal_channel = TRACE_INTERNAL_CHANNEL_TCP; - - int ret = add_service("armv7m_trace", &(CMD_ARGV[cmd_idx][1]), - CONNECTION_LIMIT_UNLIMITED, trace_new_connection, trace_input, - trace_connection_closed, NULL, &armv7m->trace_config.trace_service); - 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; - } - } - } - } - cmd_idx++; - if (CMD_ARGC == cmd_idx) - return ERROR_COMMAND_SYNTAX_ERROR; - - if (!strcmp(CMD_ARGV[cmd_idx], "sync")) { - armv7m->trace_config.pin_protocol = TPIU_PIN_PROTOCOL_SYNC; - - cmd_idx++; - if (CMD_ARGC == cmd_idx) - return ERROR_COMMAND_SYNTAX_ERROR; - - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[cmd_idx], armv7m->trace_config.port_size); - } else { - if (!strcmp(CMD_ARGV[cmd_idx], "manchester")) - armv7m->trace_config.pin_protocol = TPIU_PIN_PROTOCOL_ASYNC_MANCHESTER; - else if (!strcmp(CMD_ARGV[cmd_idx], "uart")) - armv7m->trace_config.pin_protocol = TPIU_PIN_PROTOCOL_ASYNC_UART; - else - return ERROR_COMMAND_SYNTAX_ERROR; - - cmd_idx++; - if (CMD_ARGC == cmd_idx) - return ERROR_COMMAND_SYNTAX_ERROR; - - COMMAND_PARSE_ON_OFF(CMD_ARGV[cmd_idx], armv7m->trace_config.formatter); - } - - cmd_idx++; - if (CMD_ARGC == cmd_idx) - return ERROR_COMMAND_SYNTAX_ERROR; - - COMMAND_PARSE_NUMBER(uint, CMD_ARGV[cmd_idx], armv7m->trace_config.traceclkin_freq); - - cmd_idx++; - if (CMD_ARGC != cmd_idx) { - COMMAND_PARSE_NUMBER(uint, CMD_ARGV[cmd_idx], armv7m->trace_config.trace_freq); - cmd_idx++; - } else { - if (armv7m->trace_config.config_type != TRACE_CONFIG_TYPE_INTERNAL) { - LOG_ERROR("Trace port frequency can't be omitted in external capture mode"); - return ERROR_COMMAND_SYNTAX_ERROR; - } - armv7m->trace_config.trace_freq = 0; - } - - if (CMD_ARGC == cmd_idx) { - if (CMD_CTX->mode == COMMAND_EXEC) - return armv7m_trace_tpiu_config(target); - else - return ERROR_OK; - } - } - - return ERROR_COMMAND_SYNTAX_ERROR; -} - COMMAND_HANDLER(handle_itm_port_command) { struct target *target = get_current_target(CMD_CTX); @@ -433,20 +130,6 @@ COMMAND_HANDLER(handle_itm_ports_command) return ERROR_OK; } -static const struct command_registration tpiu_command_handlers[] = { - { - .name = "config", - .handler = handle_tpiu_config_command, - .mode = COMMAND_ANY, - .help = "Configure TPIU features", - .usage = "(disable | " - "((external | internal (<filename> | <:port> | -)) " - "(sync <port width> | ((manchester | uart) <formatter enable>)) " - "<TRACECLKIN freq> [<trace freq>]))", - }, - COMMAND_REGISTRATION_DONE -}; - static const struct command_registration itm_command_handlers[] = { { .name = "port", @@ -466,13 +149,6 @@ static const struct command_registration itm_command_handlers[] = { }; const struct command_registration armv7m_trace_command_handlers[] = { - { - .name = "tpiu", - .mode = COMMAND_ANY, - .help = "tpiu command group", - .usage = "", - .chain = tpiu_command_handlers, - }, { .name = "itm", .mode = COMMAND_ANY, diff --git a/src/target/armv7m_trace.h b/src/target/armv7m_trace.h index 61142b1e3..eaee6a48f 100644 --- a/src/target/armv7m_trace.h +++ b/src/target/armv7m_trace.h @@ -18,33 +18,14 @@ #ifndef OPENOCD_TARGET_ARMV7M_TRACE_H #define OPENOCD_TARGET_ARMV7M_TRACE_H -#include <server/server.h> #include <target/target.h> #include <command.h> /** * @file - * Holds the interface to TPIU, ITM and DWT configuration functions. + * Holds the interface to ITM and DWT configuration functions. */ -enum trace_config_type { - TRACE_CONFIG_TYPE_DISABLED, /**< tracing is disabled */ - TRACE_CONFIG_TYPE_EXTERNAL, /**< trace output is captured externally */ - TRACE_CONFIG_TYPE_INTERNAL /**< trace output is handled by OpenOCD adapter driver */ -}; - -enum trace_internal_channel { - TRACE_INTERNAL_CHANNEL_TCL_ONLY, /** 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 */ - TPIU_PIN_PROTOCOL_ASYNC_UART /**< asynchronous output with NRZ coding */ -}; - enum itm_ts_prescaler { ITM_TS_PRESCALE1, /**< no prescaling for the timestamp counter */ ITM_TS_PRESCALE4, /**< refclock divided by 4 for the timestamp counter */ @@ -53,19 +34,6 @@ enum itm_ts_prescaler { }; 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) */ - bool formatter; - /** Synchronous output port width */ - uint32_t port_size; - /** Bitmask of currently enabled ITM stimuli */ uint32_t itm_ter[8]; /** Identifier for multi-source trace stream formatting */ @@ -80,27 +48,10 @@ struct armv7m_trace_config { bool itm_synchro_packets; /** Config ITM after target examine */ bool itm_deferred_config; - - /** Current frequency of TRACECLKIN (usually matches HCLK) */ - unsigned int traceclkin_freq; - /** Current frequency of trace port */ - unsigned int trace_freq; - /** 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 service *trace_service; }; extern const struct command_registration armv7m_trace_command_handlers[]; -/** - * Configure hardware accordingly to the current TPIU target settings - */ -int armv7m_trace_tpiu_config(struct target *target); -/** - * Disable TPIU data gathering at exit - */ -int armv7m_trace_tpiu_exit(struct target *target); /** * Configure hardware accordingly to the current ITM target settings */ diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index 4580c10ff..b998b7ac7 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -1648,8 +1648,6 @@ void cortex_m_deinit_target(struct target *target) { struct cortex_m_common *cortex_m = target_to_cm(target); - armv7m_trace_tpiu_exit(target); - free(cortex_m->fp_comparator_list); cortex_m_dwt_free(target); @@ -2082,9 +2080,6 @@ int cortex_m_examine(struct target *target) if (retval != ERROR_OK) return retval; - if (armv7m->trace_config.config_type != TRACE_CONFIG_TYPE_DISABLED) - armv7m_trace_tpiu_config(target); - if (armv7m->trace_config.itm_deferred_config) armv7m_trace_itm_config(target); @@ -2486,6 +2481,11 @@ static const struct command_registration cortex_m_command_handlers[] = { { .chain = armv7m_trace_command_handlers, }, + /* START_DEPRECATED_TPIU */ + { + .chain = arm_tpiu_deprecated_command_handlers, + }, + /* END_DEPRECATED_TPIU */ { .name = "cortex_m", .mode = COMMAND_EXEC, diff --git a/src/target/hla_target.c b/src/target/hla_target.c index 3d41387fd..ca8b5874a 100644 --- a/src/target/hla_target.c +++ b/src/target/hla_target.c @@ -630,6 +630,11 @@ static const struct command_registration adapter_command_handlers[] = { { .chain = rtt_target_command_handlers, }, + /* START_DEPRECATED_TPIU */ + { + .chain = arm_tpiu_deprecated_command_handlers, + }, + /* END_DEPRECATED_TPIU */ COMMAND_REGISTRATION_DONE }; diff --git a/src/target/target.c b/src/target/target.c index fe519f2ab..eb83daebb 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -4945,6 +4945,11 @@ no_params: } if (goi->isconfigure) { + /* START_DEPRECATED_TPIU */ + if (n->value == TARGET_EVENT_TRACE_CONFIG) + LOG_INFO("DEPRECATED target event %s", n->name); + /* END_DEPRECATED_TPIU */ + bool replace = true; if (teap == NULL) { /* create new */ commit c945d6e6160598894319860a92b602a192c2c268 Author: Antonio Borneo <bor...@gm...> Date: Mon Oct 12 00:12:05 2020 +0200 tcl/target: start using the new TPIU/SWO support Create the TPIU and SWO device in target config file. Replace the target event 'trace-config' with the TPIU/SWO event 'post-enable'. Extend the existing code in the event handler to properly set the gpio mode and speed to permit synchronous trace. This patch is not exhaustive of all the targets that have SWO, but has to be considered as an initial example. Change-Id: If4bbf364c0d2aef3ae49951e76507a3b1cfd58e7 Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: http://openocd.zylin.com/5859 Tested-by: jenkins Reviewed-by: Adrian M Negreanu <adr...@nx...> diff --git a/tcl/target/stm32f4x.cfg b/tcl/target/stm32f4x.cfg index 15875336e..e94837f83 100644 --- a/tcl/target/stm32f4x.cfg +++ b/tcl/target/stm32f4x.cfg @@ -38,6 +38,8 @@ if { [info exists CPUTAPID] } { swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu +tpiu create $_CHIPNAME.tpiu -dap stm32f4x.dap -ap-num 0 -baseaddr 0xE0040000 + if {[using_jtag]} { jtag newtap $_CHIPNAME bs -irlen 5 } @@ -89,13 +91,37 @@ $_TARGETNAME configure -event examine-end { mmw 0xE0042008 0x00001800 0 } -$_TARGETNAME configure -event trace-config { - # Set TRACE_IOEN; TRACE_MODE is set to async; when using sync - # change this value accordingly to configure trace pins - # assignment - mmw 0xE0042004 0x00000020 0 +proc proc_post_enable {_chipname} { + targets $_chipname.cpu + + if { [$_chipname.tpiu cget -protocol] eq "sync" } { + switch [$_chipname.tpiu cget -port-width] { + 1 { + mmw 0xE0042004 0x00000060 0x000000c0 + mmw 0x40021020 0x00000000 0x0000ff00 + mmw 0x40021000 0x000000a0 0x000000f0 + mmw 0x40021008 0x000000f0 0x00000000 + } + 2 { + mmw 0xE0042004 0x000000a0 0x000000c0 + mmw 0x40021020 0x00000000 0x000fff00 + mmw 0x40021000 0x000002a0 0x000003f0 + mmw 0x40021008 0x000003f0 0x00000000 + } + 4 { + mmw 0xE0042004 0x000000e0 0x000000c0 + mmw 0x40021020 0x00000000 0x0fffff00 + mmw 0x40021000 0x00002aa0 0x00003ff0 + mmw 0x40021008 0x00003ff0 0x00000000 + } + } + } else { + mmw 0xE0042004 0x00000020 0x000000c0 + } } +$_CHIPNAME.tpiu configure -event post-enable "proc_post_enable $_CHIPNAME" + $_TARGETNAME configure -event reset-init { # Configure PLL to boost clock to HSI x 4 (64 MHz) mww 0x40023804 0x08012008 ;# RCC_PLLCFGR 16 Mhz /8 (M) * 128 (N) /4(P) diff --git a/tcl/target/stm32h7x.cfg b/tcl/target/stm32h7x.cfg index 8258e5031..26d0d9301 100644 --- a/tcl/target/stm32h7x.cfg +++ b/tcl/target/stm32h7x.cfg @@ -77,6 +77,8 @@ if {![using_hla]} { # STM32H7 provides an APB-AP at access port 2, which allows the access to # the debug and trace features on the system APB System Debug Bus (APB-D). target create $_CHIPNAME.ap2 mem_ap -dap $_CHIPNAME.dap -ap-num 2 + swo create $_CHIPNAME.swo -dap $_CHIPNAME.dap -ap-num 2 -baseaddr 0xE00E3000 + tpiu create $_CHIPNAME.tpiu -dap $_CHIPNAME.dap -ap-num 2 -baseaddr 0xE00F5000 } target create $_CHIPNAME.cpu0 cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap -ap-num 0 @@ -178,13 +180,20 @@ $_CHIPNAME.cpu0 configure -event examine-end { stm32h7x_dbgmcu_mmw 0x03C 0x00000800 0 # DBGMCU_APB4FZ1 |= WDGLSD1 | WDGLSD2 stm32h7x_dbgmcu_mmw 0x054 0x000C0000 0 -} -$_CHIPNAME.cpu0 configure -event trace-config { - # Set TRACECLKEN; TRACE_MODE is set to async; when using sync - # change this value accordingly to configure trace pins - # assignment + # Enable clock for tracing + # DBGMCU_CR |= TRACECLKEN stm32h7x_dbgmcu_mmw 0x004 0x00100000 0 + + # RM0399 (id 0x450) M7+M4 with SWO Funnel + # RM0433 (id 0x450) M7 with SWO Funnel + # RM0455 (id 0x480) M7 without SWO Funnel + # RM0468 (id 0x483) M7 without SWO Funnel + # Enable CM7 and CM4 slave ports in SWO trace Funnel + # Works ok also on devices single core and without SWO funnel + # Hack, use stm32h7x_dbgmcu_mmw with big offset to control SWTF + # SWTF_CTRL |= ENS0 | ENS1 + stm32h7x_dbgmcu_mmw 0x3000 0x00000003 0 } $_CHIPNAME.cpu0 configure -event reset-init { diff --git a/tcl/target/stm32mp15x.cfg b/tcl/target/stm32mp15x.cfg index 4a8bc866c..1b2ae7d5e 100644 --- a/tcl/target/stm32mp15x.cfg +++ b/tcl/target/stm32mp15x.cfg @@ -64,6 +64,9 @@ cti create $_CHIPNAME.cti.cpu0 -dap $_CHIPNAME.dap -ap-num 1 -baseaddr 0xE00D800 cti create $_CHIPNAME.cti.cpu1 -dap $_CHIPNAME.dap -ap-num 1 -baseaddr 0xE00D9000 cti create $_CHIPNAME.cti.cm4 -dap $_CHIPNAME.dap -ap-num 2 -baseaddr 0xE0043000 +swo create $_CHIPNAME.swo -dap $_CHIPNAME.dap -ap-num 1 -baseaddr 0xE0083000 +tpiu create $_CHIPNAME.tpiu -dap $_CHIPNAME.dap -ap-num 1 -baseaddr 0xE0093000 + # interface does not work while srst is asserted # this is target specific, valid for every board # Errata "2.3.5 Incorrect reset of glitch-free kernel clock switch" requires @@ -108,9 +111,13 @@ proc detect_cpu1 {} { if {! $dual_core} {$::_CHIPNAME.cpu1 configure -defer-examine} } +proc rcc_enable_traceclk {} { + $::_CHIPNAME.ap2 mww 0x5000080c 0x301 +} + # FIXME: most of handler below will be removed once reset framework get merged $_CHIPNAME.ap1 configure -event reset-deassert-pre {adapter deassert srst deassert trst;dap init;catch {$::_CHIPNAME.dap apid 1}} -$_CHIPNAME.ap2 configure -event reset-deassert-pre {dbgmcu_enable_debug} +$_CHIPNAME.ap2 configure -event reset-deassert-pre {dbgmcu_enable_debug;rcc_enable_traceclk} $_CHIPNAME.cpu0 configure -event reset-deassert-pre {$::_CHIPNAME.cpu0 arp_examine} $_CHIPNAME.cpu1 configure -event reset-deassert-pre {$::_CHIPNAME.cpu1 arp_examine allow-defer} $_CHIPNAME.cpu0 configure -event reset-deassert-post {toggle_cpu0_dbg_claim0} @@ -118,4 +125,4 @@ $_CHIPNAME.cm4 configure -event reset-deassert-post {$::_CHIPNAME.cm4 arp_exami $_CHIPNAME.ap1 configure -event examine-start {dap init} $_CHIPNAME.ap2 configure -event examine-start {dbgmcu_enable_debug} $_CHIPNAME.cpu0 configure -event examine-end {detect_cpu1} -$_CHIPNAME.ap2 configure -event examine-end {$::_CHIPNAME.cm4 arp_examine} +$_CHIPNAME.ap2 configure -event examine-end {rcc_enable_traceclk;$::_CHIPNAME.cm4 arp_examine} ----------------------------------------------------------------------- Summary of changes: doc/openocd.texi | 49 ------ src/jtag/interface.h | 2 +- src/server/gdb_server.c | 2 +- src/server/rtt_server.c | 2 +- src/server/server.c | 7 +- src/server/server.h | 2 +- src/server/tcl_server.c | 2 +- src/server/telnet_server.c | 2 +- src/target/arm_tpiu_swo.c | 199 +++++++++++++++++++++++- src/target/arm_tpiu_swo.h | 12 ++ src/target/armv7m_trace.c | 324 --------------------------------------- src/target/armv7m_trace.h | 51 +----- src/target/cortex_m.c | 10 +- src/target/hla_target.c | 5 + src/target/openrisc/jsp_server.c | 3 +- src/target/target.c | 5 + tcl/target/stm32f4x.cfg | 36 ++++- tcl/target/stm32h7x.cfg | 19 ++- tcl/target/stm32mp15x.cfg | 11 +- 19 files changed, 285 insertions(+), 458 deletions(-) hooks/post-receive -- Main OpenOCD repository |