aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Naydanov <evgeniy.naydanov@syntacore.com>2022-09-16 16:01:46 +0300
committerAntonio Borneo <borneo.antonio@gmail.com>2022-12-03 09:27:00 +0000
commit04887d3b688aef999f83eebf9c521d1bb7d29b0b (patch)
treea04463a5a660c0e01890ceaed4a0bdbd3079cb07
parent4fe3997294e24d9a7bb41290088d6410f7ba1eca (diff)
downloadriscv-openocd-04887d3b688aef999f83eebf9c521d1bb7d29b0b.zip
riscv-openocd-04887d3b688aef999f83eebf9c521d1bb7d29b0b.tar.gz
riscv-openocd-04887d3b688aef999f83eebf9c521d1bb7d29b0b.tar.bz2
Fix jim_target_smp for smp rtos target
If multiple targets are specified as -rtos <rtos_type>, the rtos_update_threads was called only if the last target was specified as rtos, which is inconsistent with other checks of whether or not smp target is an rtos one. Signed-off-by: Evgeniy Naydanov <evgeniy.naydanov@syntacore.com> Change-Id: Ie52bc6b6c8f841d31b9590fcbc44e985d3cba0eb Reviewed-on: https://review.openocd.org/c/openocd/+/7244 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
-rw-r--r--src/target/target.c71
1 files changed, 52 insertions, 19 deletions
diff --git a/src/target/target.c b/src/target/target.c
index 783159f..e4fe20f 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -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;
}