Fix jim_target_smp for smp rtos target
[openocd.git] / src / target / target.c
index 783159feccd85d8de0397832f406b53cc9da6fb6..e4fe20f72ba13fc23530de7b3b4ed9fdb2f0a1b0 100644 (file)
@@ -6433,16 +6433,52 @@ static int jim_target_names(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        return JIM_OK;
 }
 
+static struct target_list *
+__attribute__((warn_unused_result))
+create_target_list_node(Jim_Obj *const name) {
+       int len;
+       const char *targetname = Jim_GetString(name, &len);
+       struct target *target = get_target(targetname);
+       LOG_DEBUG("%s ", targetname);
+       if (!target)
+               return NULL;
+
+       struct target_list *new = malloc(sizeof(struct target_list));
+       if (!new) {
+               LOG_ERROR("Out of memory");
+               return new;
+       }
+
+       new->target = target;
+       return new;
+}
+
+static int get_target_with_common_rtos_type(struct list_head *lh, struct target **result)
+{
+       struct target *target = NULL;
+       struct target_list *curr;
+       foreach_smp_target(curr, lh) {
+               struct rtos *curr_rtos = curr->target->rtos;
+               if (curr_rtos) {
+                       if (target && target->rtos && target->rtos->type != curr_rtos->type) {
+                               LOG_ERROR("Different rtos types in members of one smp target!");
+                               return JIM_ERR;
+                       }
+                       target = curr->target;
+               }
+       }
+       *result = target;
+       return JIM_OK;
+}
+
 static int jim_target_smp(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
-       int i;
-       const char *targetname;
-       int retval, len;
        static int smp_group = 1;
-       struct target *target = NULL;
-       struct target_list *head, *new;
 
-       retval = 0;
+       if (argc == 1) {
+               LOG_DEBUG("Empty SMP target");
+               return JIM_OK;
+       }
        LOG_DEBUG("%d", argc);
        /* argv[1] = target to associate in smp
         * argv[2] = target to associate in smp
@@ -6456,27 +6492,24 @@ static int jim_target_smp(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        }
        INIT_LIST_HEAD(lh);
 
-       for (i = 1; i < argc; i++) {
-
-               targetname = Jim_GetString(argv[i], &len);
-               target = get_target(targetname);
-               LOG_DEBUG("%s ", targetname);
-               if (target) {
-                       new = malloc(sizeof(struct target_list));
-                       new->target = target;
+       for (int i = 1; i < argc; i++) {
+               struct target_list *new = create_target_list_node(argv[i]);
+               if (new)
                        list_add_tail(&new->lh, lh);
-               }
        }
        /*  now parse the list of cpu and put the target in smp mode*/
-       foreach_smp_target(head, lh) {
-               target = head->target;
+       struct target_list *curr;
+       foreach_smp_target(curr, lh) {
+               struct target *target = curr->target;
                target->smp = smp_group;
                target->smp_targets = lh;
        }
        smp_group++;
 
-       if (target && target->rtos)
-               retval = rtos_smp_init(target);
+       struct target *rtos_target;
+       int retval = get_target_with_common_rtos_type(lh, &rtos_target);
+       if (retval == JIM_OK && rtos_target)
+               retval = rtos_smp_init(rtos_target);
 
        return retval;
 }

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)