@@ -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+
64366474static 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