From 37b67f99122264417536eb46560f52b589a59a2e Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Thu, 26 Nov 2026 17:31:02 +0200 Subject: [PATCH] check-sof-logger.sh: use a short stream in ping_pcm_devices() SOF SOF Linux driver introduced support for on-demand booting of DSP in upstream Linux commit c3e154981174 ("ASoC: SOF: Add support for on-demand DSP boot"). This broke the check-sof-logger.sh function to ping PCM devices with dd. As a result, loggers could end up attached to a suspended DSP and the log output was empty. Run a short (1s) silent stream with aplay, or arecord as a fallback, on the PCMs of the SOF cards until one succeeds. The PCMs are found from /proc/asound and plughw is used to let ALSA pick working parameters, so this does not depend on the hardware or the topology. Failing PCMs are skipped, and only a warning is printed if none could be opened. Also wake up the DSP before starting mtrace-reader.py, in addition to the existing call that generates DSP activity while the loggers run. Signed-off-by: Kai Vehmanen --- test-case/check-sof-logger.sh | 47 ++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/test-case/check-sof-logger.sh b/test-case/check-sof-logger.sh index 763fa177..ea2af56f 100755 --- a/test-case/check-sof-logger.sh +++ b/test-case/check-sof-logger.sh @@ -102,13 +102,44 @@ wait_for_sof_alsa_card() ping_pcm_devices() { - # Open all ALSA PCM nodes and read one byte out of them. - # The operation will fail, but this is enough to cause - # the device to be powered up if it was in runtime-suspended (D3) - # state. - for pcm in /dev/snd/pcm* ; do - dd if="$pcm" of=/dev/null bs=1 count=1 >/dev/null 2>/dev/null || true + # Run a short real stream on one SOF PCM to power up the DSP (and + # boot it if needed), including when it was in runtime-suspended + # (D3) state. Merely opening the PCM device node is not enough with + # recent SOF drivers. Topology independent: try the PCMs of all SOF + # cards until one works. plughw converts format, rate and channels + # to what the PCM supports. Failing PCMs, e.g. HDMI without a + # monitor, are expected. + local cardpath cardnum pcm dev dir + local params=(-q -t raw -f S16_LE -r 48000 -c 2 -d 1) + + for cardpath in /proc/asound/card[0-9]*; do + # SOF card ids start with "sof", see sof_alsa_card_found() + case $(cat "$cardpath/id" 2>/dev/null) in + sof*) ;; + *) continue ;; + esac + cardnum=${cardpath##*card} + + for pcm in "$cardpath"/pcm[0-9]*[pc]; do + test -e "$pcm" || continue + dev=${pcm##*/pcm} # e.g. 12p + dir=${dev: -1} + dev=${dev%?} + + if [ "$dir" = p ]; then + timeout -k 2 5 aplay "${params[@]}" \ + -D "plughw:$cardnum,$dev" /dev/zero \ + >/dev/null 2>&1 && return 0 + else + timeout -k 2 5 arecord "${params[@]}" \ + -D "plughw:$cardnum,$dev" /dev/null \ + >/dev/null 2>&1 && return 0 + fi + done done + + dlogw "No SOF PCM could be opened, DSP may not be active" + return 0 } run_loggers() @@ -147,6 +178,10 @@ run_loggers() } fi local mtracetool="$MTRACE" + + # Make sure the DSP is active before the reader attaches + ping_pcm_devices + dlogi "Trying to get Zephyr logs from mtrace with background $mtracetool ..." dlogc \ "sudo $mtracetool > $etrace_file 2> $etrace_stderr_file"