Skip to content

Commit b3b790e

Browse files
committed
rtos: rework rtos_create()
To simplify the caller of rtos_create(), convert the code from jimtcl oriented to OpenOCD commands. While there, fix inconsistencies in almost every rtos create() method and reset rtos_auto_detect to better cooperate on run-time rtos configuration. Change-Id: I59c443aaed77a48174facdfc86db75d6b28c8480 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/8830 Tested-by: jenkins
1 parent afbd01b commit b3b790e

13 files changed

Lines changed: 56 additions & 63 deletions

File tree

src/rtos/chibios.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,10 +515,10 @@ static int chibios_create(struct target *target)
515515
for (unsigned int i = 0; i < ARRAY_SIZE(chibios_params_list); i++)
516516
if (strcmp(chibios_params_list[i].target_name, target_type_name(target)) == 0) {
517517
target->rtos->rtos_specific_params = (void *)&chibios_params_list[i];
518-
return 0;
518+
return ERROR_OK;
519519
}
520520

521521
LOG_WARNING("Could not find target \"%s\" in ChibiOS compatibility "
522522
"list", target_type_name(target));
523-
return -1;
523+
return ERROR_FAIL;
524524
}

src/rtos/ecos.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,12 +1213,12 @@ static int ecos_create(struct target *target)
12131213
target->rtos->gdb_thread_packet = ecos_packet_hook;
12141214
/* We do not currently use the target->rtos->gdb_target_for_threadid
12151215
* hook. */
1216-
return 0;
1216+
return ERROR_OK;
12171217
}
12181218
tnames++;
12191219
}
12201220
}
12211221

12221222
LOG_ERROR("Could not find target in eCos compatibility list");
1223-
return -1;
1223+
return ERROR_FAIL;
12241224
}

src/rtos/embkernel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ static int embkernel_create(struct target *target)
115115
if (i >= ARRAY_SIZE(embkernel_params_list)) {
116116
LOG_WARNING("Could not find target \"%s\" in embKernel compatibility "
117117
"list", target_type_name(target));
118-
return -1;
118+
return ERROR_FAIL;
119119
}
120120

121121
target->rtos->rtos_specific_params = (void *) &embkernel_params_list[i];
122-
return 0;
122+
return ERROR_OK;
123123
}
124124

125125
static int embkernel_get_tasks_details(struct rtos *rtos, int64_t iterable, const struct embkernel_params *param,

src/rtos/freertos.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,9 @@ static int freertos_create(struct target *target)
534534
for (unsigned int i = 0; i < ARRAY_SIZE(freertos_params_list); i++)
535535
if (strcmp(freertos_params_list[i].target_name, target_type_name(target)) == 0) {
536536
target->rtos->rtos_specific_params = (void *)&freertos_params_list[i];
537-
return 0;
537+
return ERROR_OK;
538538
}
539539

540540
LOG_ERROR("Could not find target in FreeRTOS compatibility list");
541-
return -1;
541+
return ERROR_FAIL;
542542
}

src/rtos/hwthread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static int hwthread_create(struct target *target)
412412
target->rtos->thread_details = NULL;
413413
target->rtos->gdb_target_for_threadid = hwthread_target_for_threadid;
414414
target->rtos->gdb_thread_packet = hwthread_thread_packet;
415-
return 0;
415+
return ERROR_OK;
416416
}
417417

418418
static int hwthread_read_buffer(struct rtos *rtos, target_addr_t address,

src/rtos/linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ static int linux_os_create(struct target *target)
14241424
/* initialize a default virt 2 phys translation */
14251425
os_linux->phys_mask = ~0xc0000000;
14261426
os_linux->phys_base = 0x0;
1427-
return JIM_OK;
1427+
return ERROR_OK;
14281428
}
14291429

14301430
static char *linux_ps_command(struct target *target)

src/rtos/mqx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,11 @@ static int mqx_create(
251251
if (strcmp(mqx_params_list[i].target_name, target_type_name(target)) == 0) {
252252
target->rtos->rtos_specific_params = (void *)&mqx_params_list[i];
253253
/* LOG_DEBUG("MQX RTOS - valid architecture: %s", target_type_name(target)); */
254-
return 0;
254+
return ERROR_OK;
255255
}
256256
}
257257
LOG_ERROR("MQX RTOS - could not find target \"%s\" in MQX compatibility list", target_type_name(target));
258-
return -1;
258+
return ERROR_FAIL;
259259
}
260260

261261
/*

src/rtos/nuttx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ static int nuttx_create(struct target *target)
129129

130130
if (i >= ARRAY_SIZE(nuttx_params_list)) {
131131
LOG_ERROR("Could not find \"%s\" target in NuttX compatibility list", target_type_name(target));
132-
return JIM_ERR;
132+
return ERROR_FAIL;
133133
}
134134

135135
/* We found a target in our list, copy its reference. */
136136
target->rtos->rtos_specific_params = (void *)param;
137137

138-
return JIM_OK;
138+
return ERROR_OK;
139139
}
140140

141141
static int nuttx_smp_init(struct target *target)

src/rtos/rtkernel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,12 @@ static int rtkernel_create(struct target *target)
364364
for (size_t i = 0; i < ARRAY_SIZE(rtkernel_params_list); i++) {
365365
if (strcmp(rtkernel_params_list[i].target_name, target_type_name(target)) == 0) {
366366
target->rtos->rtos_specific_params = (void *)&rtkernel_params_list[i];
367-
return 0;
367+
return ERROR_OK;
368368
}
369369
}
370370

371371
LOG_ERROR("Could not find target in rt-kernel compatibility list");
372-
return -1;
372+
return ERROR_FAIL;
373373
}
374374

375375
const struct rtos_type rtkernel_rtos = {

src/rtos/rtos.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static int os_alloc(struct target *target, const struct rtos_type *ostype)
5757
struct rtos *os = target->rtos = calloc(1, sizeof(struct rtos));
5858

5959
if (!os)
60-
return JIM_ERR;
60+
return ERROR_FAIL;
6161

6262
os->type = ostype;
6363
os->current_threadid = -1;
@@ -69,7 +69,7 @@ static int os_alloc(struct target *target, const struct rtos_type *ostype)
6969
os->gdb_thread_packet = rtos_thread_packet;
7070
os->gdb_target_for_threadid = rtos_target_for_threadid;
7171

72-
return JIM_OK;
72+
return ERROR_OK;
7373
}
7474

7575
static void os_free(struct target *target)
@@ -86,38 +86,26 @@ static void os_free(struct target *target)
8686
static int os_alloc_create(struct target *target, const struct rtos_type *ostype)
8787
{
8888
int ret = os_alloc(target, ostype);
89+
if (ret != ERROR_OK)
90+
return ret;
8991

90-
if (ret == JIM_OK) {
91-
ret = target->rtos->type->create(target);
92-
if (ret != JIM_OK)
93-
os_free(target);
94-
}
92+
ret = target->rtos->type->create(target);
93+
if (ret != ERROR_OK)
94+
os_free(target);
9595

9696
return ret;
9797
}
9898

99-
int rtos_create(struct jim_getopt_info *goi, struct target *target)
99+
int rtos_create(struct command_invocation *cmd, struct target *target,
100+
const char *rtos_name)
100101
{
101-
int x;
102-
const char *cp;
103-
Jim_Obj *res;
104-
int e;
105-
106-
if (!goi->is_configure && goi->argc != 0) {
107-
Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "NO PARAMS");
108-
return JIM_ERR;
109-
}
110-
111102
os_free(target);
103+
target->rtos_auto_detect = false;
112104

113-
e = jim_getopt_string(goi, &cp, NULL);
114-
if (e != JIM_OK)
115-
return e;
116-
117-
if (strcmp(cp, "none") == 0)
118-
return JIM_OK;
105+
if (strcmp(rtos_name, "none") == 0)
106+
return ERROR_OK;
119107

120-
if (strcmp(cp, "auto") == 0) {
108+
if (strcmp(rtos_name, "auto") == 0) {
121109
/* Auto detect tries to look up all symbols for each RTOS,
122110
* and runs the RTOS driver's _detect() function when GDB
123111
* finds all symbols for any RTOS. See rtos_qsymbol(). */
@@ -128,17 +116,29 @@ int rtos_create(struct jim_getopt_info *goi, struct target *target)
128116
return os_alloc(target, rtos_types[0]);
129117
}
130118

131-
for (x = 0; rtos_types[x]; x++)
132-
if (strcmp(cp, rtos_types[x]->name) == 0)
119+
for (int x = 0; rtos_types[x]; x++)
120+
if (strcmp(rtos_name, rtos_types[x]->name) == 0)
133121
return os_alloc_create(target, rtos_types[x]);
134122

135-
Jim_SetResultFormatted(goi->interp, "Unknown RTOS type %s, try one of: ", cp);
136-
res = Jim_GetResult(goi->interp);
137-
for (x = 0; rtos_types[x]; x++)
138-
Jim_AppendStrings(goi->interp, res, rtos_types[x]->name, ", ", NULL);
139-
Jim_AppendStrings(goi->interp, res, ", auto or none", NULL);
123+
char *all = NULL;
124+
for (int x = 0; rtos_types[x]; x++) {
125+
char *prev = all;
126+
if (all)
127+
all = alloc_printf("%s, %s", all, rtos_types[x]->name);
128+
else
129+
all = alloc_printf("%s", rtos_types[x]->name);
130+
free(prev);
131+
if (!all) {
132+
LOG_ERROR("Out of memory");
133+
return ERROR_FAIL;
134+
}
135+
}
136+
137+
command_print(cmd, "Unknown RTOS type %s, try one of: %s, auto or none",
138+
rtos_name, all);
139+
free(all);
140140

141-
return JIM_ERR;
141+
return ERROR_COMMAND_ARGUMENT_INVALID;
142142
}
143143

144144
void rtos_destroy(struct target *target)

0 commit comments

Comments
 (0)