forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdt_stat
executable file
·235 lines (190 loc) · 4.74 KB
/
dt_stat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/bash
# author: Frank Rowand frank.rowand@sonymobile.com
# license: GPL V2
#_______________________________________________________________________________
script=`basename $0`
help=0
cmd_d=0
cmd_n=0
cmd_nb=0
cmd_nd=0
cmd_nxb=0
cmd_nxd=0
if [ $# -eq 0 ] ; then
help=1
fi
while [ $# -gt 0 ]; do
ARG=${1:1}
case "$ARG" in
h | -help)
help=1
break
;;
"d")
cmd_d=1
shift
;;
"n")
cmd_n=1
shift
;;
"nb")
cmd_nb=1
shift
;;
"nd")
cmd_nd=1
shift
;;
"nxb")
cmd_nxb=1
shift
;;
"nxd")
cmd_nxd=1
shift
;;
*)
echo "ERROR: invalid parameter" 1>&2
exit 1
;;
esac
done
#_______________________________________________________________________________
PDT="/proc/device-tree/"
#_______________________________________________________________________________
if [ ${help} -eq 1 ] ; then
cat<<EOF 1>&2
usage:
dt_stat
-h synonym for --help
--help print this message and exit
-d report devices
-n report nodes
-nb report nodes bound to a driver
-nd report nodes with a device
-nxb report nodes not bound to a driver
-nxd report nodes without a device
Reports about nodes in /proc/device-tree/
Nodes without a compatible string are not reported
data fields reported:
-d Device Node
-n Node Compatible
-nb Node Compatible
-nd Node Compatible Device Driver
-nxb Node Compatible
-nxd Node Compatible
EOF
exit 1
fi
#_______________________________________________________________________________
if [ ! -d /sys/devices ] ; then
echo "ERROR: /sys/devices is not a directory" >&2
exit 1
fi
if [ ! -d "$PDT" ] ; then
echo "ERROR: ${PDT} is not a directory" >&2
exit 1
fi
# ==============================================================================
# COLLECT DATA
UEVENTS="$(find /sys/devices -name uevent)"
#----- nodes of devices with an OF_FULLNAME in uevent
#----- nodes with a device that has been bound to a driver
NODES_DEV=""
function get_nodes_dev() {
for dev in $UEVENTS; do
grep '^OF_FULLNAME=' "${dev}" | sed -e 's|OF_FULLNAME=||'
done | sort
}
function nodes_dev() {
if [ -z "$NODES_DEV" ]; then
NODES_DEV="$(get_nodes_dev)"
fi
echo "$NODES_DEV"
}
NODES_DEV_BOUND=""
function get_nodes_dev_bound() {
for uevent in $UEVENTS; do
grep '^OF_FULLNAME=' "${uevent}" | sed -e 's|OF_FULLNAME=||'
done | sort
}
function nodes_dev_bound() {
if [ -z "$NODES_DEV_BOUND" ]; then
NODES_DEV_BOUND="$(get_nodes_dev_bound)"
fi
echo "$NODES_DEV_BOUND"
}
#----- nodes with a compatible property
NODES_COMPAT=""
function get_nodes_compat() {
local D
for node in `find "${PDT}" -name compatible -type f`; do
D=$(dirname "${node}")
echo "$D" | sed -e 's|\/proc\/device-tree||'
done | sort
}
function nodes_compat() {
if [ -z "$NODES_COMPAT" ]; then
NODES_COMPAT="$(get_nodes_compat)"
fi
echo "$NODES_COMPAT"
}
TABS=' '
# ==============================================================================
# REPORTS
#----- devices with an OF_FULLNAME in uevent
if [ ${cmd_d} -eq 1 ] ; then
for dev in $UEVENTS; do
if grep -q '^OF_FULLNAME' "${dev}" ; then
node=$(grep '^OF_FULLNAME' "${dev}" | sed -e 's|OF_FULLNAME=||')
echo $(dirname "${dev}") $TABS "${node}"
fi
done | sort
fi
#----- nodes with a compatible property
if [ ${cmd_n} -eq 1 ] ; then
for node in $(nodes_compat) ; do
if [ -f "${PDT}/${node}/compatible" ]; then
echo "$node" $TABS $(< "${PDT}/${node}/compatible")
fi
done
fi
#----- nodes with device bound to driver
if [ ${cmd_nb} -eq 1 ] ; then
for node in $(nodes_dev_bound) ; do
if [ -f "$PDT/${node}/compatible" ]; then
echo "${node}" $TABS $(< "$PDT/${node}/compatible")
fi
done
fi
#----- nodes with a device
if [ ${cmd_nd} -eq 1 ] ; then
for uevent in $UEVENTS; do
if [ -f "$uevent" ]; then
node=$(grep '^OF_FULLNAME=' "${uevent}" | sed -e 's|OF_FULLNAME=||')
if [[ "${node}" != "" ]] ; then
dev=$(dirname "${uevent}")
# driver might be empty
driver=$(grep '^DRIVER=' "${uevent}" | sed -e 's|DRIVER=||')
echo "$node" $TABS $(< "${PDT}/${node}/compatible") $TABS "$dev" $TABS "$driver"
fi
fi
done | sort
fi
#----- nodes not bound to a driver
if [ ${cmd_nxb} -eq 1 ] ; then
for node in $(nodes_compat); do
if ! echo $(nodes_dev_bound) | grep -E -q "(^|)${node}( |\$)"; then
echo "${node}" $TABS $(< "${PDT}/${node}/compatible")
fi
done
fi
#----- nodes without a device
if [ ${cmd_nxd} -eq 1 ] ; then
for node in $(nodes_compat); do
if ! echo $(nodes_dev) | grep -E -q "(^|)${node}( |\$)"; then
echo "${node}" $TABS $(< "${PDT}/${node}/compatible")
fi
done
fi