blob: bb6790bf040e09d0f05edf615c75ced4dba61299 (
plain)
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
|
#!/bin/bash
# This script must be run after mts-io
# to read the hw-version,
# but before anything else needs the
# device tree.
sysdir=/sys/devices/platform/mts-io
i2c=/sys/bus/i2c/devices/
eepromPath="/sys/devices/platform/i2c-gpio-0/i2c-0/0-0056/eeprom"
DEVTREE="/sys/kernel/config/device-tree/overlays/"
SYSFS="/usr/sbin/mts-io-sysfs"
I2CDIR="/sys/bus/i2c/devices"
AP1_EEPROM=$I2CDIR"/1-0050/eeprom"
AP2_EEPROM=$I2CDIR"/1-0052/eeprom"
install_dtbo_dir() {
if ! [[ -d ${DEVTREE} ]] ; then
mount configfs
fi
if ([ -f "$AP1_EEPROM" ] && grep -q GPIOB "$AP1_EEPROM") || ([ -f "$AP2_EEPROM" ] && grep -q GPIOB "$AP2_EEPROM"); then
for f in *gpiob.dtbo ; do
if ! [[ -f $f ]] ; then
continue
fi
# f2 is the extracted device name
base=$(basename $f .dtbo)
/bin/mkdir ${DEVTREE}/$base || true
/bin/cat $f >${DEVTREE}/$base/dtbo
done
modprobe mt_ac_gpiob
else
for f in *lora.dtbo ; do
if ! [[ -f $f ]] ; then
continue
fi
# f2 is the extracted device name
base=$(basename $f .dtbo)
/bin/mkdir ${DEVTREE}/$base || true
/bin/cat $f >${DEVTREE}/$base/dtbo
done
fi
}
# Device tree format:
# [mach]
# [rev]
# [file1] [file2] [file3] capability
# [flag]
# [file1] [file2] [file3]
setdevtree() {
hwlin=$(mts-id-eeprom --in-file "$eepromPath" 2>/dev/null | grep '^hw-version:')
[[ $hwlin =~ hw-version:[[:space:]]*\"([^\"]+) ]]
hw=${BASH_REMATCH[1]}
mach=${hw/%-*}
rev=${hw/#*-/}
echo mach is $mach
echo rev is $rev
capd="${sysdir}/capability"
# add device tree overlays, if they exist.
[[ -d /lib/dtoverlays ]] || return 1
(
cd /lib/dtoverlays
cd ${mach}
best="-1"
for d in * ; do
if awk "BEGIN{if ($d <= $rev)exit 1}" ; then
continue
fi
if awk "BEGIN{if ($d < $best)exit 1}" ; then
best="$d"
fi
done
if [[ $best == -1 ]] ; then
# No overlay found
exit 0
fi
cd $best
install_dtbo_dir
if [[ -d capability ]] ; then
cd capability
for d in * ; do
if [[ -f ${capd}/$d ]] ; then
if (($(cat ${capd}/$d) == 1)) ; then
echo "This device has capabilithy $d"
(
cd $d
install_dtbo_dir
)
fi # Install dtbo files for a capability
fi # Does a given capability flag exist in the mts-io platform
done # Loop over all capabilities for this machine and version overlays
fi # Is there a capability directory to be installed?
)
}
case $1 in
start)
/usr/bin/logger -t "mts-io" -p daemon.info -s "Loading device tree overlay"
setdevtree
;;
stop)
echo "Not implemented"
;;
*)
echo "Usage: $0 {start|stop}"
exit 2
;;
esac
|