Skip to content

Commit 885e76f

Browse files
dgloeckgalak
authored andcommitted
rtos/Zephyr: support recent Zephyr versions
The current version reported by Zephyr in the offsets array is 1. It is compatible to version 0 but offers a few more values in the array. zephyrproject-rtos/zephyr#13461 adds a separate symbol to hold the size of the array, so that future compatible additions do not require the version number to be incremented. Fixes #3 Signed-off-by: Daniel Glöckner <[email protected]>
1 parent 90bc731 commit 885e76f

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

src/rtos/Zephyr.c

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "target/target_type.h"
3131
#include "target/armv7m.h"
3232

33+
#define UNIMPLEMENTED 0xFFFFFFFFU
34+
3335
struct Zephyr_thread {
3436
uint32_t ptr, next_ptr;
3537
uint32_t entry;
@@ -49,13 +51,18 @@ enum Zephyr_offsets {
4951
OFFSET_T_USER_OPTIONS,
5052
OFFSET_T_PRIO,
5153
OFFSET_T_STACK_POINTER,
54+
OFFSET_T_NAME,
55+
OFFSET_T_ARCH,
56+
OFFSET_T_PREEMPT_FLOAT,
57+
OFFSET_T_COOP_FLOAT,
5258
OFFSET_MAX
5359
};
5460

5561
struct Zephyr_params {
5662
const char *target_name;
5763
uint8_t size_width;
5864
uint8_t pointer_width;
65+
uint32_t num_offsets;
5966
uint32_t offsets[OFFSET_MAX];
6067
const struct rtos_register_stacking *callee_saved_stacking;
6168
const struct rtos_register_stacking *cpu_saved_nofp_stacking;
@@ -161,13 +168,15 @@ enum Zephyr_symbol_values {
161168
Zephyr_VAL__kernel,
162169
Zephyr_VAL__kernel_openocd_offsets,
163170
Zephyr_VAL__kernel_openocd_size_t_size,
171+
Zephyr_VAL__kernel_openocd_num_offsets,
164172
Zephyr_VAL_COUNT
165173
};
166174

167175
static const symbol_table_elem_t Zephyr_symbol_list[] = {
168176
{ .symbol_name = "_kernel", .optional = false },
169177
{ .symbol_name = "_kernel_openocd_offsets", .optional = false },
170178
{ .symbol_name = "_kernel_openocd_size_t_size", .optional = false },
179+
{ .symbol_name = "_kernel_openocd_num_offsets", .optional = true },
171180
{ }
172181
};
173182

@@ -369,20 +378,49 @@ static int Zephyr_update_threads(struct rtos *rtos)
369378
return ERROR_FAIL;
370379
}
371380

381+
if (rtos->symbols[Zephyr_VAL__kernel_openocd_num_offsets].address) {
382+
retval = target_read_u32(rtos->target,
383+
rtos->symbols[Zephyr_VAL__kernel_openocd_num_offsets].address,
384+
&param->num_offsets);
385+
if (retval != ERROR_OK) {
386+
LOG_ERROR("Couldn't not fetch number of offsets from Zephyr");
387+
return retval;
388+
}
389+
if (param->num_offsets <= OFFSET_T_STACK_POINTER) {
390+
LOG_ERROR("Number of offsets too small");
391+
return ERROR_FAIL;
392+
}
393+
} else {
394+
param->num_offsets = OFFSET_VERSION + 1;
395+
}
372396
/* We can fetch the whole array for version 0, as they're supposed
373397
* to grow only */
374398
uint32_t address;
375399
address = rtos->symbols[Zephyr_VAL__kernel_openocd_offsets].address;
376400
for (size_t i = 0; i < OFFSET_MAX; i++, address += param->size_width) {
401+
if (i >= param->num_offsets) {
402+
param->offsets[i] = UNIMPLEMENTED;
403+
continue;
404+
}
377405
retval = target_read_u32(rtos->target, address, &param->offsets[i]);
378406
if (retval != ERROR_OK) {
379407
LOG_ERROR("Could not fetch offsets from Zephyr");
380408
return ERROR_FAIL;
381409
}
410+
if (param->num_offsets == OFFSET_VERSION + 1 && i == OFFSET_VERSION) {
411+
switch (param->offsets[OFFSET_VERSION]) {
412+
case 0:
413+
param->num_offsets = OFFSET_T_STACK_POINTER + 1;
414+
break;
415+
case 1:
416+
param->num_offsets = OFFSET_T_COOP_FLOAT + 1;
417+
break;
418+
}
419+
}
382420
}
383-
if (param->offsets[OFFSET_VERSION] != 0) {
384-
LOG_ERROR("Expecting OpenOCD support version 0, got % " PRId32
385-
" instead", param->offsets[OFFSET_VERSION]);
421+
if (param->offsets[OFFSET_VERSION] > 1) {
422+
LOG_ERROR("Unexpected OpenOCD support version %" PRIu32,
423+
param->offsets[OFFSET_VERSION]);
386424
return ERROR_FAIL;
387425
}
388426

0 commit comments

Comments
 (0)