arm_adi_v5: rewrite dap_to_jtag and dap_to_swd 52/4852/3
authorAntonio Borneo <borneo.antonio@gmail.com>
Wed, 29 Aug 2018 09:57:42 +0000 (11:57 +0200)
committerMatthias Welwarsky <matthias@welwarsky.de>
Wed, 30 Jan 2019 14:29:10 +0000 (14:29 +0000)
The functions dap_to_jtag() and dap_to_swd() have been introduced by
3ef9beb52cd0 ("ADIv5 DAP ops switching to JTAG or SWD modes") in
arm_adi_v5.c by using the JTAG queue only.
Later, in 6f8b8593d63b ("ADIv5 transport support moves to separate
files") the functions has been moved in adi_v5_swd.c and adi_v5_jtag.c
but keeping the dependency from JTAG queue.
The functions does not work if the current transport is not JTAG.

Move back the functions in arm_adi_v5.c, replace the input parameter
"target" with "dap", use the transport to detect if the JTAG queue is
present, in case of SWD transport use the proper method, for other
transports report error.
Reuse the ADI v5 sequences already present in jtag/swd.h.
Also, OpenOCD does not support switching to another transport after
the initial selection, so do not change DAP's ops vector.

Change-Id: Ib681fbaa60cb342f732bc831eb92de25afa4e4db
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4852
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
src/flash/nor/stellaris.c
src/target/adi_v5_jtag.c
src/target/adi_v5_swd.c
src/target/arm_adi_v5.c
src/target/arm_adi_v5.h

index 79aaf3ba2c6a4ed355a4ac997763efd45a51688d..8731f8b88d089e02faa1cd53fe1a5677ce3dbf0b 100644 (file)
@@ -1355,6 +1355,7 @@ COMMAND_HANDLER(stellaris_handle_mass_erase_command)
 COMMAND_HANDLER(stellaris_handle_recover_command)
 {
        struct flash_bank *bank;
 COMMAND_HANDLER(stellaris_handle_recover_command)
 {
        struct flash_bank *bank;
+       struct arm *arm;
        int retval;
 
        if (CMD_ARGC != 0)
        int retval;
 
        if (CMD_ARGC != 0)
@@ -1383,12 +1384,13 @@ COMMAND_HANDLER(stellaris_handle_recover_command)
        }
        adapter_assert_reset();
 
        }
        adapter_assert_reset();
 
+       arm = target_to_arm(bank->target);
        for (int i = 0; i < 5; i++) {
        for (int i = 0; i < 5; i++) {
-               retval = dap_to_swd(bank->target);
+               retval = dap_to_swd(arm->dap);
                if (retval != ERROR_OK)
                        goto done;
 
                if (retval != ERROR_OK)
                        goto done;
 
-               retval = dap_to_jtag(bank->target);
+               retval = dap_to_jtag(arm->dap);
                if (retval != ERROR_OK)
                        goto done;
        }
                if (retval != ERROR_OK)
                        goto done;
        }
index ad4183b5f8182e3b999345092b830f0795f694e7..a3867e191fac8f2f054c3c21f809ed2247cb7d59 100644 (file)
@@ -726,52 +726,3 @@ const struct dap_ops jtag_dp_ops = {
        .run                 = jtag_dp_run,
        .sync                = jtag_dp_sync,
 };
        .run                 = jtag_dp_run,
        .sync                = jtag_dp_sync,
 };
-
-
-static const uint8_t swd2jtag_bitseq[] = {
-       /* More than 50 TCK/SWCLK cycles with TMS/SWDIO high,
-        * putting both JTAG and SWD logic into reset state.
-        */
-       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-       /* Switching equence disables SWD and enables JTAG
-        * NOTE: bits in the DP's IDCODE can expose the need for
-        * the old/deprecated sequence (0xae 0xde).
-        */
-       0x3c, 0xe7,
-       /* At least 50 TCK/SWCLK cycles with TMS/SWDIO high,
-        * putting both JTAG and SWD logic into reset state.
-        * NOTE:  some docs say "at least 5".
-        */
-       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-};
-
-/** Put the debug link into JTAG mode, if the target supports it.
- * The link's initial mode may be either SWD or JTAG.
- *
- * @param target Enters JTAG mode (if possible).
- *
- * Note that targets implemented with SW-DP do not support JTAG, and
- * that some targets which could otherwise support it may have been
- * configured to disable JTAG signaling
- *
- * @return ERROR_OK or else a fault code.
- */
-int dap_to_jtag(struct target *target)
-{
-       int retval;
-
-       LOG_DEBUG("Enter JTAG mode");
-
-       /* REVISIT it's nasty to need to make calls to a "jtag"
-        * subsystem if the link isn't in JTAG mode...
-        */
-
-       retval = jtag_add_tms_seq(8 * sizeof(swd2jtag_bitseq),
-                       swd2jtag_bitseq, TAP_RESET);
-       if (retval == ERROR_OK)
-               retval = jtag_execute_queue();
-
-       /* REVISIT set up the DAP's ops vector for JTAG mode. */
-
-       return retval;
-}
index b520223b0e7940cb93080b1b3a1c4e2ba0f5cd25..eb181cb653a0862304c44829bef9a46d763e4b66 100644 (file)
@@ -297,71 +297,6 @@ const struct dap_ops swd_dap_ops = {
        .quit = swd_quit,
 };
 
        .quit = swd_quit,
 };
 
-/*
- * This represents the bits which must be sent out on TMS/SWDIO to
- * switch a DAP implemented using an SWJ-DP module into SWD mode.
- * These bits are stored (and transmitted) LSB-first.
- *
- * See the DAP-Lite specification, section 2.2.5 for information
- * about making the debug link select SWD or JTAG.  (Similar info
- * is in a few other ARM documents.)
- */
-static const uint8_t jtag2swd_bitseq[] = {
-       /* More than 50 TCK/SWCLK cycles with TMS/SWDIO high,
-        * putting both JTAG and SWD logic into reset state.
-        */
-       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-       /* Switching sequence enables SWD and disables JTAG
-        * NOTE: bits in the DP's IDCODE may expose the need for
-        * an old/obsolete/deprecated sequence (0xb6 0xed).
-        */
-       0x9e, 0xe7,
-       /* More than 50 TCK/SWCLK cycles with TMS/SWDIO high,
-        * putting both JTAG and SWD logic into reset state.
-        */
-       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-};
-
-/**
- * Put the debug link into SWD mode, if the target supports it.
- * The link's initial mode may be either JTAG (for example,
- * with SWJ-DP after reset) or SWD.
- *
- * @param target Enters SWD mode (if possible).
- *
- * Note that targets using the JTAG-DP do not support SWD, and that
- * some targets which could otherwise support it may have have been
- * configured to disable SWD signaling
- *
- * @return ERROR_OK or else a fault code.
- */
-int dap_to_swd(struct target *target)
-{
-       struct arm *arm = target_to_arm(target);
-       int retval;
-
-       if (!arm->dap) {
-               LOG_ERROR("SWD mode is not available");
-               return ERROR_FAIL;
-       }
-
-       LOG_DEBUG("Enter SWD mode");
-
-       /* REVISIT it's ugly to need to make calls to a "jtag"
-        * subsystem if the link may not be in JTAG mode...
-        */
-
-       retval =  jtag_add_tms_seq(8 * sizeof(jtag2swd_bitseq),
-                       jtag2swd_bitseq, TAP_INVALID);
-       if (retval == ERROR_OK)
-               retval = jtag_execute_queue();
-
-       /* set up the DAP's ops vector for SWD mode. */
-       arm->dap->ops = &swd_dap_ops;
-
-       return retval;
-}
-
 static const struct command_registration swd_commands[] = {
        {
                /*
 static const struct command_registration swd_commands[] = {
        {
                /*
index 03e642bfeaec701b228a40195208cb652dc41507..021d02a44cbb8d9b50645a7fde4936f713606a7b 100644 (file)
@@ -59,7 +59,7 @@
 /*
  * Relevant specifications from ARM include:
  *
 /*
  * Relevant specifications from ARM include:
  *
- * ARM(tm) Debug Interface v5 Architecture Specification    ARM IHI 0031A
+ * ARM(tm) Debug Interface v5 Architecture Specification    ARM IHI 0031E
  * CoreSight(tm) v1.0 Architecture Specification            ARM IHI 0029B
  *
  * CoreSight(tm) DAP-Lite TRM, ARM DDI 0316D
  * CoreSight(tm) v1.0 Architecture Specification            ARM IHI 0029B
  *
  * CoreSight(tm) DAP-Lite TRM, ARM DDI 0316D
@@ -73,6 +73,8 @@
 #include "jtag/interface.h"
 #include "arm.h"
 #include "arm_adi_v5.h"
 #include "jtag/interface.h"
 #include "arm.h"
 #include "arm_adi_v5.h"
+#include "jtag/swd.h"
+#include "transport/transport.h"
 #include <helper/jep106.h>
 #include <helper/time_support.h>
 #include <helper/list.h>
 #include <helper/jep106.h>
 #include <helper/time_support.h>
 #include <helper/list.h>
@@ -788,6 +790,77 @@ int mem_ap_init(struct adiv5_ap *ap)
        return ERROR_OK;
 }
 
        return ERROR_OK;
 }
 
+/**
+ * Put the debug link into SWD mode, if the target supports it.
+ * The link's initial mode may be either JTAG (for example,
+ * with SWJ-DP after reset) or SWD.
+ *
+ * Note that targets using the JTAG-DP do not support SWD, and that
+ * some targets which could otherwise support it may have been
+ * configured to disable SWD signaling
+ *
+ * @param dap The DAP used
+ * @return ERROR_OK or else a fault code.
+ */
+int dap_to_swd(struct adiv5_dap *dap)
+{
+       int retval;
+
+       LOG_DEBUG("Enter SWD mode");
+
+       if (transport_is_jtag()) {
+               retval =  jtag_add_tms_seq(swd_seq_jtag_to_swd_len,
+                               swd_seq_jtag_to_swd, TAP_INVALID);
+               if (retval == ERROR_OK)
+                       retval = jtag_execute_queue();
+               return retval;
+       }
+
+       if (transport_is_swd()) {
+               const struct swd_driver *swd = adiv5_dap_swd_driver(dap);
+
+               return swd->switch_seq(JTAG_TO_SWD);
+       }
+
+       LOG_ERROR("Nor JTAG nor SWD transport");
+       return ERROR_FAIL;
+}
+
+/**
+ * Put the debug link into JTAG mode, if the target supports it.
+ * The link's initial mode may be either SWD or JTAG.
+ *
+ * Note that targets implemented with SW-DP do not support JTAG, and
+ * that some targets which could otherwise support it may have been
+ * configured to disable JTAG signaling
+ *
+ * @param dap The DAP used
+ * @return ERROR_OK or else a fault code.
+ */
+int dap_to_jtag(struct adiv5_dap *dap)
+{
+       int retval;
+
+       LOG_DEBUG("Enter JTAG mode");
+
+       if (transport_is_jtag()) {
+               retval = jtag_add_tms_seq(swd_seq_swd_to_jtag_len,
+                               swd_seq_swd_to_jtag, TAP_RESET);
+               if (retval == ERROR_OK)
+                       retval = jtag_execute_queue();
+               return retval;
+       }
+
+       if (transport_is_swd()) {
+               const struct swd_driver *swd = adiv5_dap_swd_driver(dap);
+
+               return swd->switch_seq(SWD_TO_JTAG);
+       }
+
+       LOG_ERROR("Nor JTAG nor SWD transport");
+       return ERROR_FAIL;
+}
+
 /* CID interpretation -- see ARM IHI 0029B section 3
  * and ARM IHI 0031A table 13-3.
  */
 /* CID interpretation -- see ARM IHI 0029B section 3
  * and ARM IHI 0031A table 13-3.
  */
index a340b76f07adc97022658f74e9656f210327426f..96291a7aff9d7bcf60f8abbb9ff9526c081a99b9 100644 (file)
@@ -516,10 +516,10 @@ int dap_lookup_cs_component(struct adiv5_ap *ap,
 struct target;
 
 /* Put debug link into SWD mode */
 struct target;
 
 /* Put debug link into SWD mode */
-int dap_to_swd(struct target *target);
+int dap_to_swd(struct adiv5_dap *dap);
 
 /* Put debug link into JTAG mode */
 
 /* Put debug link into JTAG mode */
-int dap_to_jtag(struct target *target);
+int dap_to_jtag(struct adiv5_dap *dap);
 
 extern const struct command_registration dap_instance_commands[];
 
 
 extern const struct command_registration dap_instance_commands[];
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)