From 06f5dc83b623d8fe313fa63a46530652a7414942 Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Mon, 24 Nov 2025 11:38:02 +0200 Subject: [PATCH 1/4] debug_stream: Add text message record type and a ds_msg() to send them Add new record type for simple text messages to the debug stream protocol and a function for sending the messages. This functionality is for debugging purposes when for some reason or another the usual methods do not work. ds_msg() can be used like printf and the printed messages can be displayed on host side with debug_stream.py. Signed-off-by: Jyri Sarha --- src/debug/debug_stream/CMakeLists.txt | 2 + src/debug/debug_stream/Kconfig | 9 +++++ .../debug_stream/debug_stream_text_msg.c | 37 +++++++++++++++++++ src/include/user/debug_stream.h | 1 + src/include/user/debug_stream_text_msg.h | 25 +++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 src/debug/debug_stream/debug_stream_text_msg.c create mode 100644 src/include/user/debug_stream_text_msg.h diff --git a/src/debug/debug_stream/CMakeLists.txt b/src/debug/debug_stream/CMakeLists.txt index 4d353128a819..36de0d24a46d 100644 --- a/src/debug/debug_stream/CMakeLists.txt +++ b/src/debug/debug_stream/CMakeLists.txt @@ -3,3 +3,5 @@ add_local_sources_ifdef(CONFIG_SOF_DEBUG_STREAM_SLOT sof debug_stream_slot.c) add_local_sources_ifdef(CONFIG_SOF_DEBUG_STREAM_THREAD_INFO sof debug_stream_thread_info.c) + +add_local_sources_ifdef(CONFIG_SOF_DEBUG_STREAM_TEXT_MSG sof debug_stream_text_msg.c) diff --git a/src/debug/debug_stream/Kconfig b/src/debug/debug_stream/Kconfig index 3a5f3d1f49cf..28b7467163c4 100644 --- a/src/debug/debug_stream/Kconfig +++ b/src/debug/debug_stream/Kconfig @@ -44,4 +44,13 @@ config SOF_DEBUG_STREAM_THREAD_INFO_INTERVAL Decides how often thread info runs and checks execution cycle statistics and stack usage. +config SOF_DEBUG_STREAM_TEXT_MSG + bool "Enable text message sending through Debug-Stream" + help + Enable debug message sending over debug stream. To use this + feature one only needs to enable debug stream with this + config option and print the debug messages with + ds_msg(). See include/user/debug_stream_text_msg.h for + prototype. + endif diff --git a/src/debug/debug_stream/debug_stream_text_msg.c b/src/debug/debug_stream/debug_stream_text_msg.c new file mode 100644 index 000000000000..bf2b33c276e3 --- /dev/null +++ b/src/debug/debug_stream/debug_stream_text_msg.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Copyright(c) 2024 Intel Corporation. + +#include +#include +#include +#include +#include +#include + +#include + +void ds_msg(const char *format, ...) +{ + va_list args; + struct { + struct debug_stream_text_msg msg; + char text[128]; + } __packed buf = { 0 }; + ssize_t len; + + va_start(args, format); + len = vsnprintf(buf.text, sizeof(buf.text), format, args); + va_end(args); + + if (len < 0) + return; + len = MIN(len, sizeof(buf.text)); + + buf.msg.hdr.id = DEBUG_STREAM_RECORD_ID_TEXT_MSG; + buf.msg.hdr.size_words = SOF_DIV_ROUND_UP(sizeof(buf.msg) + len, + sizeof(buf.msg.hdr.data[0])); + debug_stream_slot_send_record(&buf.msg.hdr); +} +EXPORT_SYMBOL(ds_msg); + diff --git a/src/include/user/debug_stream.h b/src/include/user/debug_stream.h index 60f731622478..b6d8c08cf43a 100644 --- a/src/include/user/debug_stream.h +++ b/src/include/user/debug_stream.h @@ -48,5 +48,6 @@ struct debug_stream_record { /* Debug Stream record identifiers */ #define DEBUG_STREAM_RECORD_ID_UNINITIALIZED 0 /* invalid record marker */ #define DEBUG_STREAM_RECORD_ID_THREAD_INFO 1 /* Thread info record */ +#define DEBUG_STREAM_RECORD_ID_TEXT_MSG 2 /* Text message */ #endif /* __SOC_DEBUG_STREAM_H__ */ diff --git a/src/include/user/debug_stream_text_msg.h b/src/include/user/debug_stream_text_msg.h new file mode 100644 index 000000000000..3d246e305fc3 --- /dev/null +++ b/src/include/user/debug_stream_text_msg.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * + * Copyright(c) 2024 Intel Corporation. + */ + +#ifndef __SOC_DEBUG_STREAM_TEXT_MSG_H__ +#define __SOC_DEBUG_STREAM_TEXT_MSG_H__ + +#include + +/* + * Debug Stream text message. + */ +struct debug_stream_text_msg { + struct debug_stream_record hdr; + char msg[]; +} __packed; + +/* + * To send debug messages over debug stream. Enable + * CONFIG_SOF_DEBUG_STREAM_TEXT_MSG to enable this function. + */ +void ds_msg(const char *format, ...); + +#endif /* __SOC_DEBUG_STREAM_TEXT_MSG_H__ */ From ca3e9943ebc24e5b3924e655b0ba7e89af0fdb70 Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Tue, 25 Nov 2025 11:22:54 +0200 Subject: [PATCH 2/4] tools: debug_stream.py: Add support for text messages Add support for showing DEBUG_STREAM_RECORD_ID_TEXT_MSG messages that can be sent from firmware code with sd_msg() command. Signed-off-by: Jyri Sarha --- tools/debug_stream/debug_stream.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tools/debug_stream/debug_stream.py b/tools/debug_stream/debug_stream.py index 9c3706d90f99..0191c5cd7be7 100644 --- a/tools/debug_stream/debug_stream.py +++ b/tools/debug_stream/debug_stream.py @@ -46,7 +46,6 @@ class DebugStreamRecord(ctypes.Structure): ("size_words", ctypes.c_uint), ] - class CPUInfo(ctypes.Structure): """ Thread Info record header @@ -73,6 +72,17 @@ class ThreadInfo(ctypes.Structure): ] +class TextMsg(ctypes.Structure): + """ + Text Msg record header + """ + + _pack_ = 1 + _fields_ = [ + ("hdr", DebugStreamRecord), + ] + + WSIZE = ctypes.sizeof(ctypes.c_uint) @@ -83,6 +93,7 @@ class RecordPrinter: RECORD_ID_UNINITIALIZED = 0 RECORD_ID_THREAD_INFO = 1 + RECORD_ID_TEXT_MSG = 2 def print_record(self, record, cpu): """prints debug-stream record""" @@ -92,7 +103,9 @@ def print_record(self, record, cpu): ) if recp.contents.id == self.RECORD_ID_THREAD_INFO: return self.print_thread_info(record, cpu) - logging.warning("cpu %u: Unsupported recodrd type %u", cpu, recp.contents.id) + if recp.contents.id == self.RECORD_ID_TEXT_MSG: + return self.print_text_msg(record, cpu) + logging.warning("cpu %u: Unsupported record type %u", cpu, recp.contents.id) return True def print_thread_info(self, record, cpu): @@ -141,6 +154,17 @@ def print_thread_info(self, record, cpu): ) return True + def print_text_msg(self, record, cpu): + """prints text-msg record""" + if len(record) - ctypes.sizeof(TextMsg) < 0: + logging.info("Buffer end reached, parsing failed") + return False + buffer = ( + ctypes.c_ubyte * (len(record) - ctypes.sizeof(TextMsg)) + ).from_address(ctypes.addressof(record) + ctypes.sizeof(TextMsg)) + msg = bytearray(buffer).decode("utf-8") + print("CPU %u: %s" % (cpu, msg)) + return True class DebugStreamSectionDescriptor(ctypes.Structure): """ From 537b5bdc2877cc60b749d661046d6f7b1bcfaefe Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Wed, 26 Nov 2025 18:53:22 +0200 Subject: [PATCH 3/4] app: Enable debug messages in debug_stream_overlay.conf Enable debug messages in debug_stream_overlay.conf Signed-off-by: Jyri Sarha --- app/debug_stream_overlay.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/debug_stream_overlay.conf b/app/debug_stream_overlay.conf index 0195e5070b33..e3cb6834320e 100644 --- a/app/debug_stream_overlay.conf +++ b/app/debug_stream_overlay.conf @@ -1,5 +1,7 @@ # Enable debug-stream protocol CONFIG_SOF_DEBUG_STREAM_SLOT=y +# Enable text message sending with ds_msg() +CONFIG_SOF_DEBUG_STREAM_TEXT_MSG=y # Add thread_info-client for debug stream CONFIG_SOF_DEBUG_STREAM_THREAD_INFO=y # Zephyr option for storing human readable thread names From cc1a0547bb3ce5af8b4b7d0bd572beaed1426f13 Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Wed, 26 Nov 2025 18:54:53 +0200 Subject: [PATCH 4/4] debug_stream: Kconfig: Improve help message Add reference to tools/debug_stream/debug_stream.py in the Kconfig help message. Signed-off-by: Jyri Sarha --- src/debug/debug_stream/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/debug/debug_stream/Kconfig b/src/debug/debug_stream/Kconfig index 28b7467163c4..8756c83ef8da 100644 --- a/src/debug/debug_stream/Kconfig +++ b/src/debug/debug_stream/Kconfig @@ -7,7 +7,8 @@ config SOF_DEBUG_STREAM_SLOT information from SOF system that are streamed from SOF DSP to the host side for decoding and presentation. This option enables transferring the records from DSP to host over a - debug window slot. + debug window slot. To extract the debugstream see + tools/debug_stream/debug_stream.py. if SOF_DEBUG_STREAM_SLOT