Debian Codegraph @

dtb-probe/kirkwood-qnap

raw symbols SCIP
1 #!/bin/sh
2
3 # Copyright (C) 2014 Ian Campbell <[email protected]>
4
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
18 # USA.
19
20 # This script attempts to determine the correct device tree blob to
21 # use on kirkwood based QNAP devices, which varies according to the
22 # SoC used either MV88F6281 or MV88F6282.
23 #
24 # This is made more complicated because we need to be able to
25 # determine which DTB to use even if we are running under a kernel
26 # using the older board-file mechanism (in order to support upgrades).
27 #
28 # The SoC ID is exposed via the SoC bus driver and via the PCI device ID of the
29 # PCI host bridge. However on older board file based kernels neither of these
30 # are reliably available (SoC ID is only available with multiplatform MVEBU
31 # kernels, not the kirkwood kernels even when running DTB and is only availavle
32 # from v3.16 onwards meanwhile older PCI host drivers didn't create the host
33 # bridge if no devices were present). Therefore we try the following in order:
34 #
35 # * soc bus id in sysfs.
36 # * PCI devid of host bridge
37 # * Ethernet PHY IDs
38 #
39 # Possible values for /proc/cpuinfo:Hardware:
40 # - QNAP TS-119/TS-219
41 # - QNAP TS-41x
42 #
43 # Possible values for /proc/device-tree/model:
44 # - QNAP TS219 family
45 # - QNAP TS419 family
46 # (NB: TS-119 uses TS-219 DTB)
47 #
48 # Example SoC bus fields:
49 # $ cat /sys/bus/soc/devices/soc0/family
50 # Marvell
51 # $ cat /sys/bus/soc/devices/soc0/soc_id
52 # 6281
53 # $ cat /sys/bus/soc/devices/soc0/revision
54 # 2
55 #
56 # Example PCI device ids:
57 #
58 # Example PHY IDs: (6281 have ID 8 and 0 while 6282 have 0 and 1)
59 # $ ls /sys/bus/mdio_bus/devices/
60 # 0:00 0:08
61 # $ ls /sys/bus/mdio_bus/devices/
62 # 0:00 0:01
63 # $ ls /sys/bus/mdio_bus/devices/
64 # 0:08
65
66 # System | Board File | Device Tree (kirkwood or mvebu)
67 # ------------+--------------------------------+--------------------------------
68 # TS-119 | |
69 # ------------+--------------------------------+--------------------------------
70 # TS-219 6281 | N (MV88F6281-A1 @ 3.2[0]) |
71 # TS-219 6282 | |
72 # ------------+--------------------------------+--------------------------------
73 # TS-419 6281 | Y (MV88F6281-A0 @ 3.14) |
74 # TS-419 6282 | Y (MV88F6282-Rev-A1 @ 3.2) |
75 # ------------+--------------------------------+--------------------------------
76 #
77 # [0] No visible PCI bus.
78
79 # My systems: qnap: TS-419P??? MV88F6281-A0
80 # celaeno: TS-419??? MV88F6282-Rev-A1
81 # armitage:TS-219??? MV88F6281-A1
82
83 set -e
84
85 FK_DIR="/usr/share/flash-kernel"
86
87 . "${FK_CHECKOUT:-$FK_DIR}/functions"
88
89 info=0
90 if [ "x$1" = "x--info" ] ; then
91 info=1
92 [ -n "$2" ] && kvers=$2
93 elif [ "x$2" = "x--info" ] ; then
94 info=1
95 kvers=$1
96 elif [ -n "$1" ]; then
97 kvers=$1
98 fi
99
100 last_result=
101 success() {
102 local what=$1
103 local res=$2
104
105 if [ $info -gt 0 ] ; then
106 echo "kirkwood-qnap: success: $what => $res" >&2
107 if [ -n "$last_result" -a "x$res" != "x$last_result" ] ; then
108 echo "kirkwood-qnap: result mismatch" >&2
109 fi
110 last_result=$res
111 else
112 echo $res
113 exit 0
114 fi
115 }
116
117 if [ $info -gt 0 ] ; then
118 (
119 /bin/echo -e "Kernel:\t\t$(uname -a)"
120 /bin/echo -e -n "cpuinfo:\t" ; grep ^Hardware /proc/cpuinfo
121 /bin/echo -e -n "dt model:\t"
122 if [ -e /proc/device-tree/model ] ; then
123 cat /proc/device-tree/model
124 /bin/echo
125 else
126 /bin/echo "n/a"
127 fi
128 /bin/echo
129
130 /bin/echo "PCI devices:"
131 lspci -n
132 /bin/echo
133
134 /bin/echo "PHY devices (/sys/bus/mdio_bus/devices/):"
135 ls /sys/bus/mdio_bus/devices/
136 /bin/echo
137
138 /bin/echo -ne "Soc Bus:\t"
139 if [ -e "/sys/bus/soc/devices/soc0" ] ; then
140 /bin/echo
141 ls /sys/bus/soc/devices/soc0
142 else
143 /bin/echo "n/a"
144 fi
145 /bin/echo
146 ) >&2
147 fi
148
149 get_machine
150 if [ -z "$machine" -a $info -gt 0 ] ; then
151 machine=`get_machine`
152 fi
153 echo "kirkwood-qnap: machine: $machine" >&2
154
155 case $machine in
156 "QNAP TS-119/TS-219"|"QNAP TS219 family")
157 dtb_0x6281="kirkwood-ts219-6281.dtb"
158 dtb_0x6282="kirkwood-ts219-6282.dtb"
159 ;;
160 "QNAP TS-41x"|"QNAP TS419 family")
161 dtb_0x6281="kirkwood-ts419-6281.dtb"
162 dtb_0x6282="kirkwood-ts419-6282.dtb"
163 ;;
164 *)
165 error "Unknown machine $machine"
166 ;;
167 esac
168
169 if [ -e "/sys/bus/soc/devices/soc0/soc_id" ] ; then
170 case $(cat /sys/bus/soc/devices/soc0/soc_id) in
171 6281) success "SoC ID" $dtb_0x6281;;
172 6282) success "SoC ID" $dtb_0x6282;;
173 esac
174 fi
175 for device in /sys/bus/pci/devices/* ; do
176 if [ ! -e "$device" ] ; then
177 continue
178 fi
179 if [ ! -e "$device/class" -o \
180 ! -e "$device/vendor" -o \
181 ! -e "$device/device" ] ; then
182 echo "$device is missing sysfs entries" >&2
183 continue
184 fi
185
186 class=$(cat $device/class)
187 # Host/PCI bride 0x60000 or PCI/PCI bride 0x60400
188 if [ x$class != x0x060000 ] && [ x$class != x0x060400 ] ; then
189 echo "$device is not a PCI bridge ($class)" >&2
190 continue
191 fi
192
193 vid=$(cat $device/vendor)
194 if [ x$vid != x0x11ab ] ; then
195 echo "$device vendor is not Marvell ($vid)" >&2
196 continue
197 fi
198
199 did=$(cat $device/device)
200 case $did in
201 0x6281) success "PCI" ${dtb_0x6281}; break;;
202 0x6282) success "PCI" ${dtb_0x6282}; break;;
203 *) echo "$device is not a known Marvell device ($did)" >&2 ;;
204 esac
205 done
206
207 have_phy() {
208 local phy=$1
209 test -e "/sys/bus/mdio_bus/devices/0:$phy" -o \
210 -e "/sys/bus/mdio_bus/devices/orion-mdio-mii:$phy" -o \
211 -e "/sys/bus/mdio_bus/devices/f1072004.mdio-bu:$phy"
212 }
213
214 case $machine in
215 "QNAP TS-119/TS-219"|"QNAP TS219 family")
216 # TS-219??? MV88F6281-A1 # ls /sys/bus/mdio_bus/devices/ => 0:08@
217 if have_phy 08; then
218 success "PHY" "$dtb_0x6281"
219 elif have_phy 00; then
220 success "PHY" "$dtb_0x6282"
221 fi
222 ;;
223 "QNAP TS-41x"|"QNAP TS419 family")
224 # TS-419P??? MV88F6281-A0 # ls /sys/bus/mdio_bus/devices/ => 0:00@ 0:08@
225 # TS-419??? MV88F6282-Rev-A1# ls /sys/bus/mdio_bus/devices/ => 0:00@ 0:01@
226 if have_phy 08 && have_phy 00; then
227 success "PHY" "$dtb_0x6281"
228 elif have_phy 00 && have_phy 01; then
229 success "PHY" "$dtb_0x6282"
230 fi
231 ;;
232 esac
233
234 if [ $info -gt 0 ] ; then
235 exit 0
236 fi
237
238 echo "kirkwood-qnap: Unable to determine $machine variant " >&2
239 exit 1