jtag: print an errmsg on using jtag API for non jtag transport
authorAntonio Borneo <borneo.antonio@gmail.com>
Tue, 28 Aug 2018 12:49:10 +0000 (14:49 +0200)
committerTomas Vanek <vanekt@fbl.cz>
Tue, 14 Jan 2020 11:38:23 +0000 (11:38 +0000)
After the cleanup of swd and hla, there should be no more calls
to jtag_execute_queue() or to queue jtag commands if current
transport is not jtag. Thus we can start removing the jtag
specific code from adapters that do not support jtag.

To prevent some remaining call to jtag_execute_queue() to crash
openocd, verify the transport, print an error message if the
transport is not jtag, call the adapter's jtag_execute_queue()
only if it exist.
To identify code that still add commands in the jtag queue even
if transport is not jtag, print an error message in the function
jtag_queue_command(). For the moment, still queue the message,
even if will cause a memory leak if there is no following call
to jtag_execute_queue(); the target is to identify the issue and
cleanup the code, thus solving also the leak.

Change-Id: I8fc85f754aa057aad1df05ff0448c8619897da23
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4897
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
src/jtag/commands.c
src/jtag/core.c

index 3352e035acc9fd78739ea4e9dc5273864aa38e79..e88a3b74f669dd3ba2c93973441001e5b09768a7 100644 (file)
@@ -31,6 +31,7 @@
 #endif
 
 #include <jtag/jtag.h>
+#include <transport/transport.h>
 #include "commands.h"
 
 struct cmd_queue_page {
@@ -48,6 +49,19 @@ static struct jtag_command **next_command_pointer = &jtag_command_queue;
 
 void jtag_queue_command(struct jtag_command *cmd)
 {
+       if (!transport_is_jtag()) {
+               /*
+                * FIXME: This should not happen!
+                * There could be old code that queues jtag commands with non jtag interfaces so, for
+                * the moment simply highlight it by log an error.
+                * We should fix it quitting with assert(0) because it is an internal error, or returning
+                * an error after call to jtag_command_queue_reset() to free the jtag queue and avoid
+                * memory leaks.
+                * The fix can be applied immediately after next release (v0.11.0 ?)
+                */
+               LOG_ERROR("JTAG API jtag_queue_command() called on non JTAG interface");
+       }
+
        /* this command goes on the end, so ensure the queue terminates */
        cmd->next = NULL;
 
index 69553ebaff09a4615b6f0035f7bb0aa7b1829ae7..5e9777e74145d796ebe9f4cc03d411bfe04ef19d 100644 (file)
@@ -937,6 +937,19 @@ int default_interface_jtag_execute_queue(void)
                return ERROR_FAIL;
        }
 
+       if (!transport_is_jtag()) {
+               /*
+                * FIXME: This should not happen!
+                * There could be old code that queues jtag commands with non jtag interfaces so, for
+                * the moment simply highlight it by log an error and return on empty execute_queue.
+                * We should fix it quitting with assert(0) because it is an internal error.
+                * The fix can be applied immediately after next release (v0.11.0 ?)
+                */
+               LOG_ERROR("JTAG API jtag_execute_queue() called on non JTAG interface");
+               if (!jtag->execute_queue)
+                       return ERROR_OK;
+       }
+
        int result = jtag->execute_queue();
 
 #if !BUILD_ZY1000