From 03059c1ba40e153969c0a4f91b7552f7cd77df3d Mon Sep 17 00:00:00 2001 From: Keyon Jie Date: Fri, 13 Aug 2021 13:45:39 +0800 Subject: [PATCH] trace: enable trace after it is ready If the log tracing (e.g. tr_err()) is called before the trace itself is available, the FW will crash and FW boot fail happen. Enable the trace after it is ready, and don't try to perform tracing when it is unavailable. We have the empty version of trace_init/on(), so the extra "#ifdef" in primary_core_init() is superfluous. Signed-off-by: Keyon Jie --- src/init/init.c | 5 +++-- src/trace/dma-trace.c | 1 - src/trace/trace.c | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/init/init.c b/src/init/init.c index eb379746129f..cef4bfa64e38 100644 --- a/src/init/init.c +++ b/src/init/init.c @@ -134,10 +134,8 @@ static int primary_core_init(int argc, char *argv[], struct sof *sof) interrupt_init(sof); #endif /* __ZEPHYR__ */ -#if CONFIG_TRACE trace_point(TRACE_BOOT_SYS_TRACES); trace_init(sof); -#endif trace_point(TRACE_BOOT_SYS_NOTIFIER); init_system_notify(sof); @@ -151,6 +149,9 @@ static int primary_core_init(int argc, char *argv[], struct sof *sof) trace_point(TRACE_BOOT_PLATFORM); + /* now start the trace */ + trace_on(); + #if CONFIG_NO_SECONDARY_CORE_ROM lp_sram_unpack(); #endif diff --git a/src/trace/dma-trace.c b/src/trace/dma-trace.c index d113443f282e..2d8dc4cd8b71 100644 --- a/src/trace/dma-trace.c +++ b/src/trace/dma-trace.c @@ -200,7 +200,6 @@ int dma_trace_init_complete(struct dma_trace_data *d) SOF_TASK_PRI_MED, trace_work, d, 0, 0); out: - return ret; } diff --git a/src/trace/trace.c b/src/trace/trace.c index f31fb3a1c3e8..b1a378a1c045 100644 --- a/src/trace/trace.c +++ b/src/trace/trace.c @@ -290,9 +290,8 @@ void trace_log_filtered(bool send_atomic, const void *log_entry, const struct tr uint64_t current_ts; #endif /* CONFIG_TRACE_FILTERING_ADAPTIVE */ - if (!trace->enable) { + if (!trace || !trace->enable) return; - } #if CONFIG_TRACE_FILTERING_VERBOSITY if (!trace_filter_verbosity(lvl, ctx)) @@ -512,7 +511,6 @@ void trace_off(void) void trace_init(struct sof *sof) { sof->trace = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*sof->trace)); - sof->trace->enable = 1; sof->trace->pos = 0; #if CONFIG_TRACE_FILTERING_ADAPTIVE sof->trace->user_filter_override = false;