target/arm_dap: check SWD DAP configuration
[openocd.git] / src / target / arm_dap.c
index bde1dfb5ee9279814b20dc88b08a9302c6f5f563..4728ce3bf7a4a92467c16c653ace4483306ce206 100644 (file)
@@ -251,6 +251,52 @@ static int dap_configure(struct jim_getopt_info *goi, struct arm_dap_object *dap
        return JIM_OK;
 }
 
+static int dap_check_config(struct adiv5_dap *dap)
+{
+       if (transport_is_jtag() || transport_is_dapdirect_jtag() || transport_is_hla())
+               return ERROR_OK;
+
+       struct arm_dap_object *obj;
+       bool new_multidrop = dap_is_multidrop(dap);
+       bool had_multidrop = new_multidrop;
+       uint32_t targetsel = dap->multidrop_targetsel;
+       unsigned int non_multidrop_count = had_multidrop ? 0 : 1;
+
+       list_for_each_entry(obj, &all_dap, lh) {
+               struct adiv5_dap *dap_it = &obj->dap;
+
+               if (transport_is_swd()) {
+                       if (dap_is_multidrop(dap_it)) {
+                               had_multidrop = true;
+                               if (new_multidrop && dap_it->multidrop_targetsel == targetsel) {
+                                       uint32_t dp_id = targetsel & DP_TARGETSEL_DPID_MASK;
+                                       uint32_t instance_id = targetsel >> DP_TARGETSEL_INSTANCEID_SHIFT;
+                                       LOG_ERROR("%s and %s have the same multidrop selectors -dp-id 0x%08"
+                                                         PRIx32 " and -instance-id 0x%" PRIx32,
+                                                         obj->name, adiv5_dap_name(dap),
+                                                         dp_id, instance_id);
+                                       return ERROR_FAIL;
+                               }
+                       } else {
+                               non_multidrop_count++;
+                       }
+               } else if (transport_is_dapdirect_swd()) {
+                       non_multidrop_count++;
+               }
+       }
+
+       if (non_multidrop_count > 1) {
+               LOG_ERROR("Two or more SWD non multidrop DAPs are not supported");
+               return ERROR_FAIL;
+       }
+       if (had_multidrop && non_multidrop_count) {
+               LOG_ERROR("Mixing of SWD multidrop DAPs and non multidrop DAPs is not supported");
+               return ERROR_FAIL;
+       }
+
+       return ERROR_OK;
+}
+
 static int dap_create(struct jim_getopt_info *goi)
 {
        struct command_context *cmd_ctx;
@@ -297,6 +343,12 @@ static int dap_create(struct jim_getopt_info *goi)
                goto err;
        }
 
+       e = dap_check_config(&dap->dap);
+       if (e != ERROR_OK) {
+               e = JIM_ERR;
+               goto err;
+       }
+
        struct command_registration dap_commands[] = {
                {
                        .name = cp,

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)