Skip to content

Commit 3bfcc6a

Browse files
committed
functestlib: fix remoteproc firmware path lookup
Rework get_remoteproc_path_by_firmware() to iterate firmware files directly and read them without using cat. This avoids the bogus idx arithmetic that caused "operand expected" errors while still allowing callers to derive the remoteproc index from the returned path. Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
1 parent 206d41a commit 3bfcc6a

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

Runner/utils/functestlib.sh

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,15 +1900,35 @@ dt_has_remoteproc_fw() {
19001900
}
19011901

19021902
# Find the remoteproc path for a given firmware substring (e.g., "adsp", "cdsp", "gdsp").
1903+
# Logic:
1904+
# - grep -n over /sys/class/remoteproc/remoteproc*/firmware (one line per remoteproc)
1905+
# - Take the first matching line number (1-based)
1906+
# - Subtract 1 → remoteproc index → /sys/class/remoteproc/remoteproc${idx}
19031907
get_remoteproc_path_by_firmware() {
1904-
name="$1"
1905-
idx path
1906-
# List all remoteproc firmware nodes, match name, and return the remoteproc path
1907-
idx=$(cat /sys/class/remoteproc/remoteproc*/firmware 2>/dev/null | grep -n "$name" | cut -d: -f1 | head -n1)
1908-
[ -z "$idx" ] && return 1
1909-
idx=$((idx - 1))
1910-
path="/sys/class/remoteproc/remoteproc${idx}"
1911-
[ -d "$path" ] && echo "$path" && return 0
1908+
name=$1
1909+
1910+
[ -n "$name" ] || return 1
1911+
[ -d /sys/class/remoteproc ] || return 1
1912+
1913+
for fw in /sys/class/remoteproc/remoteproc*/firmware; do
1914+
# Skip if glob didn't match any file
1915+
[ -f "$fw" ] || continue
1916+
1917+
# Read first line from firmware file without using cat
1918+
if IFS= read -r fwname <"$fw"; then
1919+
case "$fwname" in
1920+
*"$name"*)
1921+
# Map firmware file back to its remoteproc directory
1922+
dir=${fw%/firmware}
1923+
if [ -d "$dir" ]; then
1924+
printf '%s\n' "$dir"
1925+
return 0
1926+
fi
1927+
;;
1928+
esac
1929+
fi
1930+
done
1931+
19121932
return 1
19131933
}
19141934

0 commit comments

Comments
 (0)