Skip to content

Commit 04887d3

Browse files
en-scborneoa
authored andcommitted
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 <[email protected]> Change-Id: Ie52bc6b6c8f841d31b9590fcbc44e985d3cba0eb Reviewed-on: https://review.openocd.org/c/openocd/+/7244 Tested-by: jenkins Reviewed-by: Antonio Borneo <[email protected]>
1 parent 4fe3997 commit 04887d3

File tree

1 file changed

+52
-19
lines changed

1 file changed

+52
-19
lines changed

src/target/target.c

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6433,16 +6433,52 @@ static int jim_target_names(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
64336433
return JIM_OK;
64346434
}
64356435

6436+
static struct target_list *
6437+
__attribute__((warn_unused_result))
6438+
create_target_list_node(Jim_Obj *const name) {
6439+
int len;
6440+
const char *targetname = Jim_GetString(name, &len);
6441+
struct target *target = get_target(targetname);
6442+
LOG_DEBUG("%s ", targetname);
6443+
if (!target)
6444+
return NULL;
6445+
6446+
struct target_list *new = malloc(sizeof(struct target_list));
6447+
if (!new) {
6448+
LOG_ERROR("Out of memory");
6449+
return new;
6450+
}
6451+
6452+
new->target = target;
6453+
return new;
6454+
}
6455+
6456+
static int get_target_with_common_rtos_type(struct list_head *lh, struct target **result)
6457+
{
6458+
struct target *target = NULL;
6459+
struct target_list *curr;
6460+
foreach_smp_target(curr, lh) {
6461+
struct rtos *curr_rtos = curr->target->rtos;
6462+
if (curr_rtos) {
6463+
if (target && target->rtos && target->rtos->type != curr_rtos->type) {
6464+
LOG_ERROR("Different rtos types in members of one smp target!");
6465+
return JIM_ERR;
6466+
}
6467+
target = curr->target;
6468+
}
6469+
}
6470+
*result = target;
6471+
return JIM_OK;
6472+
}
6473+
64366474
static int jim_target_smp(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
64376475
{
6438-
int i;
6439-
const char *targetname;
6440-
int retval, len;
64416476
static int smp_group = 1;
6442-
struct target *target = NULL;
6443-
struct target_list *head, *new;
64446477

6445-
retval = 0;
6478+
if (argc == 1) {
6479+
LOG_DEBUG("Empty SMP target");
6480+
return JIM_OK;
6481+
}
64466482
LOG_DEBUG("%d", argc);
64476483
/* argv[1] = target to associate in smp
64486484
* 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)
64566492
}
64576493
INIT_LIST_HEAD(lh);
64586494

6459-
for (i = 1; i < argc; i++) {
6460-
6461-
targetname = Jim_GetString(argv[i], &len);
6462-
target = get_target(targetname);
6463-
LOG_DEBUG("%s ", targetname);
6464-
if (target) {
6465-
new = malloc(sizeof(struct target_list));
6466-
new->target = target;
6495+
for (int i = 1; i < argc; i++) {
6496+
struct target_list *new = create_target_list_node(argv[i]);
6497+
if (new)
64676498
list_add_tail(&new->lh, lh);
6468-
}
64696499
}
64706500
/* now parse the list of cpu and put the target in smp mode*/
6471-
foreach_smp_target(head, lh) {
6472-
target = head->target;
6501+
struct target_list *curr;
6502+
foreach_smp_target(curr, lh) {
6503+
struct target *target = curr->target;
64736504
target->smp = smp_group;
64746505
target->smp_targets = lh;
64756506
}
64766507
smp_group++;
64776508

6478-
if (target && target->rtos)
6479-
retval = rtos_smp_init(target);
6509+
struct target *rtos_target;
6510+
int retval = get_target_with_common_rtos_type(lh, &rtos_target);
6511+
if (retval == JIM_OK && rtos_target)
6512+
retval = rtos_smp_init(rtos_target);
64806513

64816514
return retval;
64826515
}

0 commit comments

Comments
 (0)