summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomek CEDRO <cederom@tlen.pl>2011-09-11 00:56:26 +0000
committerTomek CEDRO <cederom@tlen.pl>2011-09-11 00:56:26 +0000
commit7fafb0add5d07540964cde734f41aff650eafefc (patch)
tree497701cee758c0fa16a6962c325c1f882cbd28fc
parent7206efdd9e7aa79666ce599116872a5244d32d9e (diff)
downloadopenocd_libswd-7fafb0add5d07540964cde734f41aff650eafefc.tar.gz
openocd_libswd-7fafb0add5d07540964cde734f41aff650eafefc.tar.bz2
openocd_libswd-7fafb0add5d07540964cde734f41aff650eafefc.tar.xz
openocd_libswd-7fafb0add5d07540964cde734f41aff650eafefc.zip
transport/swd: Changes in logging mechanism: 1. LogLevel is inherited during transport initialization and only if context is created. 2. swd_log() use vprintf as using openocd logging mechanisms caused program crash by va recurrence. 3. Fixed tcl interface to use/update loglevel configuration parameter from swdctx stored within dap.
-rw-r--r--src/transport/swd_core.c17
-rw-r--r--src/transport/swd_libswd_drv_openocd.c32
-rw-r--r--src/transport/swd_tcl.c14
3 files changed, 18 insertions, 45 deletions
diff --git a/src/transport/swd_core.c b/src/transport/swd_core.c
index 834810c3..383199f2 100644
--- a/src/transport/swd_core.c
+++ b/src/transport/swd_core.c
@@ -47,8 +47,6 @@
#endif
#include <transport/swd.h>
-#include <jtag/interface.h> //we want this here to use extern global *interface
-#include <unistd.h>
///Unfortunalety OpenOCD use globals to pass information so we need to use it too.
extern struct jtag_interface *jtag_interface;
@@ -144,18 +142,15 @@ int oocd_swd_transport_init(struct command_context *ctx){
return ERROR_FAIL;
}
LOG_INFO("New SWD context initialized at 0x%p", (void *)dap->ctx);
+ /* Now inherit the log level from OpenOCD settings. */
+ if (swd_log_level_inherit((swd_ctx_t *)dap->ctx, debug_level)<0){
+ LOG_ERROR("Unable to set log level: %s", swd_error_string(retval));
+ return ERROR_FAIL;
+ }
} else LOG_INFO("Working on existing transport context at 0x%p...", (void *)dap->ctx);
- retval=swd_log_level_inherit((swd_ctx_t *)dap->ctx, debug_level);
- if (retval<0){
- LOG_ERROR("Unable to set log level: %s", swd_error_string(retval));
- return ERROR_FAIL;
- }
-
-
-
/**
- * Initialize the driver to work with selected transport.
+ * Initialize driver and detect target working with selected transport.
* Because we can work on existing context there is no need to destroy it,
* as it can be used on next try.
*/
diff --git a/src/transport/swd_libswd_drv_openocd.c b/src/transport/swd_libswd_drv_openocd.c
index 5ab75c69..26e147b4 100644
--- a/src/transport/swd_libswd_drv_openocd.c
+++ b/src/transport/swd_libswd_drv_openocd.c
@@ -263,7 +263,11 @@ int swd_log_level_inherit(swd_ctx_t *swdctx, int loglevel){
} return new_swdlevel;
}
-/** We will use OpenOCD's logging mechanisms to show LibSWD messages. */
+/** We will use OpenOCD's logging mechanisms to show LibSWD messages.
+ * SWD can have different loglevel set than the OpenOCD itself, so we need to
+ * log all messages at openocd level that will not block swd messages.
+ * It is also possible to 'inherit' loglevel to swd from openocd.
+ */
int swd_log(swd_ctx_t *swdctx, swd_loglevel_t loglevel, char *msg, ...){
if (swdctx==NULL) return SWD_ERROR_NULLCONTEXT;
if (loglevel > SWD_LOGLEVEL_MAX) return SWD_ERROR_PARAM;
@@ -272,33 +276,9 @@ int swd_log(swd_ctx_t *swdctx, swd_loglevel_t loglevel, char *msg, ...){
int res;
va_list ap;
va_start(ap, msg);
+ // Calling OpenOCD log functions here will cause program crash (va recurrent).
res=vprintf(msg, ap);
va_end(ap);
- return res;
-
-
- LOG_DEBUG("swdctx=0x%08X, loglevel=0x%02X, msg=%s\n", (int)swdctx, (int)loglevel, msg);
- switch(loglevel){
- case SWD_LOGLEVEL_NORMAL:
- LOG_USER(msg, ap);
- break;
- case SWD_LOGLEVEL_ERROR:
- LOG_ERROR(msg, ap);
- break;
- case SWD_LOGLEVEL_WARNING:
- LOG_WARNING(msg, ap);
- break;
- case SWD_LOGLEVEL_INFO:
- printf(msg, ap);
- break;
- case SWD_LOGLEVEL_DEBUG:
- LOG_DEBUG(msg, ap);
- break;
- default:
- LOG_USER(msg, ap);
- }
- va_end(ap);
-
return SWD_OK;
}
diff --git a/src/transport/swd_tcl.c b/src/transport/swd_tcl.c
index d75ad740..9389f66c 100644
--- a/src/transport/swd_tcl.c
+++ b/src/transport/swd_tcl.c
@@ -40,18 +40,16 @@
#include <transport/swd.h>
-//we need to use this until we get rid of global pointers
-extern struct jtag_interface *jtag_interface;
-
-
COMMAND_HANDLER(handle_swd_loglevel)
{
int loglevel;
- swd_ctx_t *swdctx=(swd_ctx_t *)jtag_interface->transport->ctx;
+ struct target *target = get_current_target(CMD_CTX);
+ struct arm *arm = target_to_arm(target);
+ swd_ctx_t *swdctx = (swd_ctx_t *)arm->dap->ctx;
switch (CMD_ARGC) {
case 0:
- LOG_INFO("Current SWD LogLevel[%d..%d] is: %d (%s)", SWD_LOGLEVEL_MIN, SWD_LOGLEVEL_MAX, swdctx->config.loglevel, swd_log_level_string(swdctx->config.loglevel));
+ LOG_USER("Current SWD LogLevel[%d..%d] is: %d (%s)\n", SWD_LOGLEVEL_MIN, SWD_LOGLEVEL_MAX, swdctx->config.loglevel, swd_log_level_string(swdctx->config.loglevel));
break;
case 1:
// We want to allow inherit current OpenOCD's debuglevel.
@@ -60,7 +58,7 @@ COMMAND_HANDLER(handle_swd_loglevel)
LOG_ERROR("LogLevel inherit failed!");
return ERROR_FAIL;
} else {
- LOG_INFO("Using OpenOCD settings, SWD LogLevel[%d..%d] set to: %d (%s)", SWD_LOGLEVEL_MIN, SWD_LOGLEVEL_MAX, loglevel, swd_log_level_string(loglevel));
+ LOG_USER("Using OpenOCD settings, SWD LogLevel[%d..%d] set to: %d (%s)\n", SWD_LOGLEVEL_MIN, SWD_LOGLEVEL_MAX, loglevel, swd_log_level_string(loglevel));
return ERROR_OK;
}
}
@@ -69,7 +67,7 @@ COMMAND_HANDLER(handle_swd_loglevel)
if (loglevel<SWD_LOGLEVEL_MIN || loglevel>SWD_LOGLEVEL_MAX) {
LOG_ERROR("Bad SWD LogLevel value!");
return ERROR_FAIL;
- } else LOG_INFO("Setting SWD LogLevel[%d..%d] to: %d (%s)", SWD_LOGLEVEL_MIN, SWD_LOGLEVEL_MAX, loglevel, swd_log_level_string(loglevel));
+ } else LOG_USER("Setting SWD LogLevel[%d..%d] to: %d (%s)\n", SWD_LOGLEVEL_MIN, SWD_LOGLEVEL_MAX, loglevel, swd_log_level_string(loglevel));
if(swd_log_level_set(swdctx, loglevel)<0){
return ERROR_FAIL;
} else return ERROR_OK;