Debian Codegraph @

dtb-probe/kirkwood-qnap

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/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-kernelscip-shell filesystem . . `/usr/share/flash-kernel`."
86
87 . "${FK_CHECKOUT:-$FK_DIR}/functions"
88
89 info=0
90 if [scip-shell system . . `[`. "x$1" = "x--info" ] ; then
91 info=1
92 [scip-shell system . . `[`. -n "$2" ] && kvers=$2
93 elif [scip-shell system . . `[`. "x$2" = "x--info" ] ; then
94 info=1
95 kvers=$1
96 elif [scip-shell system . . `[`. -n "$1" ]; then
97 kvers=$1
98 fi
99
100 last_result=
101 successscip-shell shell flash-kernel 3.110 success().() {
102 local what=$1
103 local res=$2
104
105 if [scip-shell system . . `[`. $info -gt 0 ] ; then
106 echoscip-shell system . . echo. "kirkwood-qnap: success: $what => $res" >&2
107 if [scip-shell system . . `[`. -n "$last_result" -a "x$res" != "x$last_result" ] ; then
108 echoscip-shell system . . echo. "kirkwood-qnap: result mismatch" >&2
109 fi
110 last_result=$res
111 else
112 echoscip-shell system . . echo. $res
113 exit 0
114 fi
115 }
116
117 if [scip-shell system . . `[`. $info -gt 0 ] ; then
118 (
119 /bin/echoscip-shell filesystem . . `/bin/echo`. -e "Kernel:\t\t$(unamescip-shell system . . uname. -a)"
120 /bin/echoscip-shell filesystem . . `/bin/echo`. -e -n "cpuinfo:\t" ; grepscip-shell system . . grep. ^Hardware /proc/cpuinfoscip-shell filesystem . . `/proc/cpuinfo`.
121 /bin/echoscip-shell filesystem . . `/bin/echo`. -e -n "dt model:\t"
122 if [scip-shell system . . `[`. -e /proc/device-tree/modelscip-shell filesystem . . `/proc/device-tree/model`. ] ; then
123 catscip-shell system . . cat. /proc/device-tree/modelscip-shell filesystem . . `/proc/device-tree/model`.
124 /bin/echoscip-shell filesystem . . `/bin/echo`.
125 else
126 /bin/echoscip-shell filesystem . . `/bin/echo`. "n/a"
127 fi
128 /bin/echoscip-shell filesystem . . `/bin/echo`.
129
130 /bin/echoscip-shell filesystem . . `/bin/echo`. "PCI devices:"
131 lspci -n
132 /bin/echoscip-shell filesystem . . `/bin/echo`.
133
134 /bin/echoscip-shell filesystem . . `/bin/echo`. "PHY devices (/sys/bus/mdio_bus/devices/):"
135 lsscip-shell system . . ls. /sys/bus/mdio_bus/devices/scip-shell filesystem . . `/sys/bus/mdio_bus/devices/`.
136 /bin/echoscip-shell filesystem . . `/bin/echo`.
137
138 /bin/echoscip-shell filesystem . . `/bin/echo`. -ne "Soc Bus:\t"
139 if [scip-shell system . . `[`. -e "/sys/bus/soc/devices/soc0scip-shell filesystem . . `/sys/bus/soc/devices/soc0`." ] ; then
140 /bin/echoscip-shell filesystem . . `/bin/echo`.
141 lsscip-shell system . . ls. /sys/bus/soc/devices/soc0scip-shell filesystem . . `/sys/bus/soc/devices/soc0`.
142 else
143 /bin/echoscip-shell filesystem . . `/bin/echo`. "n/a"
144 fi
145 /bin/echoscip-shell filesystem . . `/bin/echo`.
146 ) >&2
147 fi
148
149 get_machine
150 if [scip-shell system . . `[`. -z "$machine" -a $info -gt 0 ] ; then
151 machine=`get_machine`
152 fi
153 echoscip-shell system . . 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 [scip-shell system . . `[`. -e "/sys/bus/soc/devices/soc0/soc_idscip-shell filesystem . . `/sys/bus/soc/devices/soc0/soc_id`." ] ; then
170 case $(catscip-shell system . . cat. /sys/bus/soc/devices/soc0/soc_idscip-shell filesystem . . `/sys/bus/soc/devices/soc0/soc_id`.) in
171 6281) successscip-shell shell flash-kernel 3.110 success(). "SoC ID" $dtb_0x6281;;
172 6282) successscip-shell shell flash-kernel 3.110 success(). "SoC ID" $dtb_0x6282;;
173 esac
174 fi
175 for device in /sys/bus/pci/devices/* ; do
176 if [scip-shell system . . `[`. ! -e "$device" ] ; then
177 continue
178 fi
179 if [scip-shell system . . `[`. ! -e "$device/class" -o \
180 ! -e "$device/vendor" -o \
181 ! -e "$device/device" ] ; then
182 echoscip-shell system . . echo. "$device is missing sysfs entries" >&2
183 continue
184 fi
185
186 class=$(catscip-shell system . . cat. $device/class)
187 # Host/PCI bride 0x60000 or PCI/PCI bride 0x60400
188 if [scip-shell system . . `[`. x$class != x0x060000 ] && [scip-shell system . . `[`. x$class != x0x060400 ] ; then
189 echoscip-shell system . . echo. "$device is not a PCI bridge ($class)" >&2
190 continue
191 fi
192
193 vid=$(catscip-shell system . . cat. $device/vendor)
194 if [scip-shell system . . `[`. x$vid != x0x11ab ] ; then
195 echoscip-shell system . . echo. "$device vendor is not Marvell ($vid)" >&2
196 continue
197 fi
198
199 did=$(catscip-shell system . . cat. $device/device)
200 case $did in
201 0x6281) successscip-shell shell flash-kernel 3.110 success(). "PCI" ${dtb_0x6281}; break;;
202 0x6282) successscip-shell shell flash-kernel 3.110 success(). "PCI" ${dtb_0x6282}; break;;
203 *) echoscip-shell system . . echo. "$device is not a known Marvell device ($did)" >&2 ;;
204 esac
205 done
206
207 have_physcip-shell shell flash-kernel 3.110 have_phy().() {
208 local phy=$1
209 testscip-shell system . . 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_physcip-shell shell flash-kernel 3.110 have_phy(). 08; then
218 successscip-shell shell flash-kernel 3.110 success(). "PHY" "$dtb_0x6281"
219 elif have_physcip-shell shell flash-kernel 3.110 have_phy(). 00; then
220 successscip-shell shell flash-kernel 3.110 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_physcip-shell shell flash-kernel 3.110 have_phy(). 08 && have_physcip-shell shell flash-kernel 3.110 have_phy(). 00; then
227 successscip-shell shell flash-kernel 3.110 success(). "PHY" "$dtb_0x6281"
228 elif have_physcip-shell shell flash-kernel 3.110 have_phy(). 00 && have_physcip-shell shell flash-kernel 3.110 have_phy(). 01; then
229 successscip-shell shell flash-kernel 3.110 success(). "PHY" "$dtb_0x6282"
230 fi
231 ;;
232 esac
233
234 if [scip-shell system . . `[`. $info -gt 0 ] ; then
235 exit 0
236 fi
237
238 echoscip-shell system . . echo. "kirkwood-qnap: Unable to determine $machine variant " >&2
239 exit 1