Skip to content

Commit 7fbb3cd

Browse files
committed
guess/device-tree: Add parameters to filter Device Tree devices
Signed-off-by: Alexey Gladkov <[email protected]>
1 parent ecda528 commit 7fbb3cd

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

guess/device-tree/action

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ $TRACE_SOURCE "Processing ..."
99
[ -d "$SYSFS_PATH"/firmware/devicetree ] ||
1010
exit 0
1111

12+
GUESS_DT_NAMES="${GUESS_DT_NAMES-}"
13+
GUESS_DT_COMPATIBLES="${GUESS_DT_COMPATIBLES-}"
14+
15+
filters=0
16+
[ -z "$GUESS_DT_NAMES" ] || filters=$(( $filters + 1 ))
17+
[ -z "$GUESS_DT_COMPATIBLES" ] || filters=$(( $filters + 1 ))
18+
1219
# Do the search in reverse order. Searching for modalias files will show us
1320
# nodes that have kernel modules (uevents are much more than a node with
1421
# modalias), among them we look for those that have OF_NAME in uevent (mandatory
@@ -17,7 +24,50 @@ $TRACE_SOURCE "Processing ..."
1724
# shellcheck disable=SC2016
1825
find "$SYSFS_PATH"/devices/ -type f -name modalias -printf '%h/uevent\0' |
1926
xargs -r0 grep -l '^OF_NAME=' 2>/dev/null |
20-
sed -e 's,/uevent$,/modalias,' |
27+
while read -r uevent; do
28+
modialias_file="${uevent%/uevent}/modalias"
29+
30+
if [ "$filters" -eq 0 ]; then
31+
printf '%s\n' "$modalias_file"
32+
continue
33+
fi
34+
35+
match=0
36+
37+
eof=
38+
while [ -z "$eof" ]; do
39+
pair=
40+
read -r pair || eof=1
41+
42+
case "$pair" in
43+
OF_NAME=*)
44+
value="${pair#*=}"
45+
[ -n "$value" ] || continue
46+
47+
for reqval in $GUESS_DT_NAMES; do
48+
if [ "$value" = "$reqval" ]; then
49+
match=$(( $match + 1 ))
50+
break
51+
fi
52+
done
53+
;;
54+
OF_COMPATIBLE_[0-9]*=*)
55+
value="${pair#*=}"
56+
[ -n "$value" ] || continue
57+
58+
for reqval in $GUESS_DT_COMPATIBLES; do
59+
if [ -z "${value##$reqval}" ]; then
60+
match=$(( $match + 1 ))
61+
break
62+
fi
63+
done
64+
;;
65+
esac
66+
done < "$uevent"
67+
68+
[ "$match" -lt "$filters" ] ||
69+
printf '%s\n' "$modalias_file"
70+
done |
2171
xargs -r sed -e '${ s/$/\n/ }' |
2272
depinfo ${KERNEL:+-k "$KERNEL"} --no-prefix --input=- 2>/dev/null |
2373
sort -u |

0 commit comments

Comments
 (0)