Skip to content

Commit c8d7d57

Browse files
nordic-krchkartben
authored andcommitted
logging: frontend_stmesp: Fix string addresses from remote core
When decoding logs from a remote core with memory that APP can access, wrong address of an array with string addresses was used. Log message contains index of a string and APP strings array was used instead of remote core. Extend STMESP logging so that address of string array of a remote core is send during startup to the APP and APP is using this array to decode strings from remote cores. Bug applies only to PPR and FLPR as APP has no access to RAD memory. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
1 parent 19c2c33 commit c8d7d57

File tree

5 files changed

+70
-24
lines changed

5 files changed

+70
-24
lines changed

drivers/misc/coresight/nrf_etr.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ static void trace_point_process(struct log_frontend_stmesp_demux_trace_point *pa
203203
static const char *tp_d32 = "%d %08x";
204204
const char *dname = stm_m_name[packet->major];
205205
static const char *sname = "tp";
206-
const char **lptr;
206+
const char *lptr;
207207

208208
if (packet->id >= CONFIG_LOG_FRONTEND_STMESP_TURBO_LOG_BASE) {
209-
TYPE_SECTION_GET(const char *, log_stmesp_ptr,
210-
packet->id - CONFIG_LOG_FRONTEND_STMESP_TURBO_LOG_BASE, &lptr);
211-
uint8_t level = (uint8_t)((*lptr)[0]) - (uint8_t)'0';
212-
const char *ptr = *lptr + 1;
209+
lptr = log_frontend_stmesp_demux_str_get(packet->major,
210+
packet->id - CONFIG_LOG_FRONTEND_STMESP_TURBO_LOG_BASE);
211+
uint8_t level = (uint8_t)(lptr[0]) - (uint8_t)'0';
212+
const char *ptr = lptr + 1;
213213
static const union cbprintf_package_hdr desc0 = {
214214
.desc = {.len = 2 /* hdr + fmt */}};
215215
static const union cbprintf_package_hdr desc1 = {

include/zephyr/logging/log_frontend_stmesp.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,17 @@ TYPE_SECTION_START_EXTERN(const char *, log_stmesp_ptr);
106106
* @param _source Pointer to the source structure.
107107
* @param ... String.
108108
*/
109+
109110
#define LOG_FRONTEND_STMESP_LOG0(_source, ...) \
110111
do { \
111112
static const char _str[] __in_section(_log_stmesp_str, static, _) \
112113
__used __noasan __aligned(sizeof(uint32_t)) = GET_ARG_N(1, __VA_ARGS__); \
113114
static const char *_str_ptr __in_section(_log_stmesp_ptr, static, _) \
114115
__used __noasan = _str; \
115-
uint32_t idx = \
116+
uint32_t _idx = \
116117
((uintptr_t)&_str_ptr - (uintptr_t)TYPE_SECTION_START(log_stmesp_ptr)) / \
117118
sizeof(void *); \
118-
log_frontend_stmesp_log0(_source, idx); \
119+
log_frontend_stmesp_log0(_source, _idx); \
119120
} while (0)
120121

121122
/** @brief Macro for handling a turbo log message with one argument.
@@ -129,10 +130,10 @@ TYPE_SECTION_START_EXTERN(const char *, log_stmesp_ptr);
129130
__used __noasan __aligned(sizeof(uint32_t)) = GET_ARG_N(1, __VA_ARGS__); \
130131
static const char *_str_ptr __in_section(_log_stmesp_ptr, static, _) \
131132
__used __noasan = _str; \
132-
uint32_t idx = \
133+
uint32_t _idx = \
133134
((uintptr_t)&_str_ptr - (uintptr_t)TYPE_SECTION_START(log_stmesp_ptr)) / \
134135
sizeof(void *); \
135-
log_frontend_stmesp_log1(_source, idx, (uintptr_t)(GET_ARG_N(2, __VA_ARGS__))); \
136+
log_frontend_stmesp_log1(_source, _idx, (uintptr_t)(GET_ARG_N(2, __VA_ARGS__))); \
136137
} while (0)
137138

138139
#ifdef __cplusplus

include/zephyr/logging/log_frontend_stmesp_demux.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ void log_frontend_stmesp_demux_free(union log_frontend_stmesp_demux_packet packe
290290
* cannot be retrieved.
291291
*/
292292
const char *log_frontend_stmesp_demux_sname_get(uint32_t m_id, uint16_t s_id);
293+
const char *log_frontend_stmesp_demux_str_get(uint32_t m_id, uint16_t s_id);
293294

294295
/** @brief Check if there are any started but not completed log messages.
295296
*

subsys/logging/frontends/log_frontend_stmesp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,10 +589,13 @@ void log_frontend_init(void)
589589
TYPE_SECTION_START_EXTERN(struct log_source_const_data, log_const);
590590
STMESP_Type *stm_esp;
591591
uintptr_t log_const_start;
592+
uintptr_t log_str_start;
592593

593594
(void)stmesp_get_port(CONFIG_LOG_FRONTEND_STPESP_TURBO_SOURCE_PORT_ID, &stm_esp);
594595
log_const_start = (uintptr_t)TYPE_SECTION_START(log_const);
596+
log_str_start = (uintptr_t)TYPE_SECTION_START(log_stmesp_ptr);
595597
STM_D32(stm_esp, log_const_start, false, true);
598+
STM_D32(stm_esp, log_str_start, false, true);
596599
#endif
597600
}
598601

subsys/logging/frontends/log_frontend_stmesp_demux.c

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <zephyr/logging/log_frontend_stmesp_demux.h>
8+
#include <zephyr/logging/log_frontend_stmesp.h>
89
#include <zephyr/logging/log_ctrl.h>
910
#include <zephyr/sys/mpsc_pbuf.h>
1011
#include <zephyr/sys/__assert.h>
@@ -43,9 +44,25 @@ struct log_frontend_stmesp_demux_active_entry {
4344
int off;
4445
};
4546

46-
struct log_frontend_stmesp_coop_sources {
47+
/* Coprocessors (FLPR, PPR) sends location where APP can find strings and logging
48+
* source names utilizing the fact that APP has access to FLPR/PPR memory if it is
49+
* an owner of that coprocessor. During the initialization FLPR/PPR sends 2 DMTS32
50+
* to the specific channel. First word is an address where logging source constant
51+
* data section is located and second is where a section with addresses to constant
52+
* strings used for logging is located.
53+
*/
54+
struct log_frontend_stmesp_coproc_sources {
4755
uint32_t m_id;
48-
const struct log_source_const_data *log_const;
56+
uint32_t data_cnt;
57+
union {
58+
struct {
59+
const struct log_source_const_data *log_const;
60+
uintptr_t *log_str_section;
61+
} data;
62+
struct {
63+
uintptr_t data[2];
64+
} raw_data;
65+
};
4966
};
5067

5168
struct log_frontend_stmesp_demux {
@@ -72,7 +89,7 @@ struct log_frontend_stmesp_demux {
7289

7390
uint32_t dropped;
7491

75-
struct log_frontend_stmesp_coop_sources coop_sources[2];
92+
struct log_frontend_stmesp_coproc_sources coproc_sources[2];
7693
};
7794

7895
struct log_frontend_stmesp_entry_source_pair {
@@ -404,10 +421,33 @@ const char *log_frontend_stmesp_demux_sname_get(uint32_t m_id, uint16_t s_id)
404421

405422
if (demux.m_ids[m_id] == APP_M_ID) {
406423
return log_source_name_get(0, s_id);
407-
} else if (m_id == demux.coop_sources[0].m_id) {
408-
return demux.coop_sources[0].log_const[s_id].name;
409-
} else if (m_id == demux.coop_sources[1].m_id) {
410-
return demux.coop_sources[1].log_const[s_id].name;
424+
} else if (m_id == demux.coproc_sources[0].m_id) {
425+
return demux.coproc_sources[0].data.log_const[s_id].name;
426+
} else if (m_id == demux.coproc_sources[1].m_id) {
427+
return demux.coproc_sources[1].data.log_const[s_id].name;
428+
}
429+
430+
return "unknown";
431+
}
432+
433+
const char *log_frontend_stmesp_demux_str_get(uint32_t m_id, uint16_t s_id)
434+
{
435+
if (!IS_ENABLED(CONFIG_LOG_FRONTEND_STMESP_TURBO_LOG)) {
436+
return "";
437+
}
438+
439+
uintptr_t *log_str_start = NULL;
440+
441+
if (demux.m_ids[m_id] == APP_M_ID) {
442+
log_str_start = (uintptr_t *)TYPE_SECTION_START(log_stmesp_ptr);
443+
} else if (m_id == demux.coproc_sources[0].m_id) {
444+
log_str_start = demux.coproc_sources[0].data.log_str_section;
445+
} else if (m_id == demux.coproc_sources[1].m_id) {
446+
log_str_start = demux.coproc_sources[1].data.log_str_section;
447+
}
448+
449+
if (log_str_start) {
450+
return (const char *)log_str_start[s_id];
411451
}
412452

413453
return "unknown";
@@ -439,15 +479,16 @@ int log_frontend_stmesp_demux_packet_start(uint32_t *data, uint64_t *ts)
439479

440480
if (IS_ENABLED(CONFIG_LOG_FRONTEND_STMESP_TURBO_LOG) &&
441481
(ch == CONFIG_LOG_FRONTEND_STPESP_TURBO_SOURCE_PORT_ID)) {
442-
if (demux.m_ids[m] == FLPR_M_ID) {
443-
demux.coop_sources[0].m_id = m;
444-
demux.coop_sources[0].log_const =
445-
(const struct log_source_const_data *)(uintptr_t)*data;
446-
} else if (demux.m_ids[m] == PPR_M_ID) {
447-
demux.coop_sources[1].m_id = m;
448-
demux.coop_sources[1].log_const =
449-
(const struct log_source_const_data *)(uintptr_t)*data;
482+
struct log_frontend_stmesp_coproc_sources *src =
483+
&demux.coproc_sources[demux.m_ids[m] == FLPR_M_ID ? 0 : 1];
484+
485+
if (src->data_cnt >= 2) {
486+
/* Unexpected packet. */
487+
return -EINVAL;
450488
}
489+
490+
src->m_id = m;
491+
src->raw_data.data[src->data_cnt++] = (uintptr_t)*data;
451492
return 0;
452493
}
453494

0 commit comments

Comments
 (0)