This is an automated email from Gerrit. "Mateus Campaner Hercules <mchercu...@gmail.com>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/7480
-- gerrit commit b617aca44543884d7aea7eb43d60808205cf1514 Author: Mateus Campaner Hercules <mchercu...@gmail.com> Date: Wed Feb 15 13:30:24 2023 -0300 Patch FreeRTOS task name parsing. The current M4_MPU/M3_MPU ports of FreeRTOS change the TCB memory layout in comparison with the non-mpu ones. So a small patch is necessary to jump the required amount of data used by the MPU regions. Notice, that is not clear from the symbols currently available if a target is or not is using a MPU port of FreeRTOS, so in a related way to what was done with uxTopUsedPriority symbol, a simple symbol holding the offset to be added for task name is expected. A sample implementation is available on contrib/rtos-helpers/FreeRTOS-openocd.c Signed-off-by: Mateus Campaner Hercules <mchercu...@gmail.com> Change-Id: I015b6543d0b8e7713b4a8d1287176477463104eb diff --git a/contrib/rtos-helpers/FreeRTOS-openocd.c b/contrib/rtos-helpers/FreeRTOS-openocd.c index 000453d5d4..4b1a2bca74 100644 --- a/contrib/rtos-helpers/FreeRTOS-openocd.c +++ b/contrib/rtos-helpers/FreeRTOS-openocd.c @@ -20,3 +20,9 @@ #endif const int USED uxTopUsedPriority = configMAX_PRIORITIES - 1; + +#ifdef portUSING_MPU_WRAPPERS +const int USED uxMPUPortInUse = sizeof(xMPU_SETTINGS); +#else +const int USED uxMPUPortInUse = 0; +#endif diff --git a/src/rtos/FreeRTOS.c b/src/rtos/FreeRTOS.c index 275a56e86b..ad29c0c0a8 100644 --- a/src/rtos/FreeRTOS.c +++ b/src/rtos/FreeRTOS.c @@ -109,6 +109,7 @@ enum freertos_symbol_values { FREERTOS_VAL_UX_CURRENT_NUMBER_OF_TASKS = 9, FREERTOS_VAL_UX_TOP_USED_PRIORITY = 10, FREERTOS_VAL_X_SCHEDULER_RUNNING = 11, + FREERTOS_VAL_UX_MPU_PORT_IN_USE = 12, }; struct symbols { @@ -129,6 +130,7 @@ static const struct symbols freertos_symbol_list[] = { { "uxCurrentNumberOfTasks", false }, { "uxTopUsedPriority", true }, /* Unavailable since v7.5.3 */ { "xSchedulerRunning", false }, + { "uxMPUPortInUse", true }, /* Used to detect if a MPU port is in use. */ { NULL, false } }; @@ -332,6 +334,25 @@ static int freertos_update_threads(struct rtos *rtos) list_elem_ptr + param->list_elem_content_offset, rtos->thread_details[tasks_found].threadid); + /* The FreeRTOS kernel does not provide any query or symbol + * to identify the port in use, as is it's premise: The user + * API is independent from Host. But that leaves us a problem: + * In the CM4_MPU port the TCB layout is modified, because of + * the MPU regions, and that gives us an additional offset to + * the actual thread name. + * Use contrib/rtos-helpers/FreeRTOS-openocd.c to get the + * necessary symbol. */ + + uint32_t mpu_name_offset; + retval = target_read_u32(rtos->target, + rtos->symbols[FREERTOS_VAL_UX_MPU_PORT_IN_USE].address, + &mpu_name_offset); + if (retval != ERROR_OK) + return retval; + + LOG_DEBUG("FreeRTOS: Read uxMPUPortInUse at 0x%" PRIx64 ", value %" PRIu32, + rtos->symbols[FREERTOS_VAL_UX_MPU_PORT_IN_USE].address, + mpu_name_offset); /* get thread name */ #define FREERTOS_THREAD_NAME_STR_SIZE (200) @@ -339,7 +360,7 @@ static int freertos_update_threads(struct rtos *rtos) /* Read the thread name */ retval = target_read_buffer(rtos->target, - rtos->thread_details[tasks_found].threadid + param->thread_name_offset, + rtos->thread_details[tasks_found].threadid + param->thread_name_offset + mpu_name_offset, FREERTOS_THREAD_NAME_STR_SIZE, (uint8_t *)&tmp_str); if (retval != ERROR_OK) { @@ -349,8 +370,8 @@ static int freertos_update_threads(struct rtos *rtos) } tmp_str[FREERTOS_THREAD_NAME_STR_SIZE-1] = '\x00'; LOG_DEBUG("FreeRTOS: Read Thread Name at 0x%" PRIx64 ", value '%s'", - rtos->thread_details[tasks_found].threadid + param->thread_name_offset, - tmp_str); + rtos->thread_details[tasks_found].threadid + param->thread_name_offset + mpu_name_offset, + tmp_str); if (tmp_str[0] == '\x00') strcpy(tmp_str, "No Name"); --