-
Notifications
You must be signed in to change notification settings - Fork 28
/
init.mmi.touch.sh
executable file
·177 lines (149 loc) · 4.46 KB
/
init.mmi.touch.sh
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
#!/system/bin/sh
PATH=/sbin:/system/sbin:/system/bin:/system/xbin
export PATH
while getopts d op;
do
case $op in
d) dbg_on=1;;
esac
done
shift $(($OPTIND-1))
debug()
{
[ $dbg_on ] && echo "Debug: $*"
}
error_and_leave()
{
err_code=$1
case $err_code in
1) echo "Error: No response from touch IC";;
2) echo "Error: Cannot read property $1";;
3) echo "Error: No matching firmware file found";;
4) echo "Error: Touch IC is in bootloader mode";;
5) echo "Error: Touch provides no reflash interface";;
6) echo "Error: Touch driver is not running";;
esac
exit $err_code
}
for touch_vendor in $*; do
debug "searching driver for vendor [$touch_vendor]"
touch_driver_link=$(ls -l /sys/bus/i2c/drivers/$touch_vendor*/*-*)
if [ -z "$touch_driver_link" ]; then
debug "no driver for vendor [$touch_vendor] is running"
shift 1
else
debug "driver for vendor [$touch_vendor] found!!!"
break
fi
done
[ -z "$touch_driver_link" ] && error_and_leave 6
touch_path=/sys/devices/${touch_driver_link#*devices/}
debug "sysfs touch path: $touch_path"
[ -f $touch_path/doreflash ] || error_and_leave 5
[ -f $touch_path/poweron ] || error_and_leave 5
debug "wait until driver reports <ready to flash>..."
while true; do
readiness=$(cat $touch_path/poweron)
if [ "$readiness" == "1" ]; then
debug "ready to flash!!!"
break;
fi
sleep 1
debug "not ready; keep waiting..."
done
unset readiness
device_property=ro.hw.device
hwrev_property=ro.hw.revision
firmware_path=/system/etc/firmware
let dec_cfg_id_boot=0; dec_cfg_id_latest=0;
read_touch_property()
{
property=""
debug "retrieving property: [$touch_path/$1]"
property=$(cat $touch_path/$1 2> /dev/null)
debug "touch property [$1] is: [$property]"
[ -z "$property" ] && return 1
return 0
}
find_latest_config_id()
{
debug "scanning dir for files matching [$1]"
str_cfg_id_latest=""
let dec=0; max=0;
for file in $(ls $1 2>/dev/null);
do
x=${file#*-}; z=${x#*-}; str_hex=${z%%-*};
let dec=0x$str_hex
if [ $dec -gt $max ];
then
let max=$dec; dec_cfg_id_latest=$dec;
str_cfg_id_latest=$str_hex
fi
done
unset dec max x z str_hex
[ -z "$str_cfg_id_latest" ] && return 1
return 0
}
read_touch_property flashprog || error_and_leave 1
bl_mode=$property
debug "bl mode: $bl_mode"
read_touch_property productinfo || error_and_leave 1
touch_product_id=$property
if [ -z "$touch_product_id" ] || [ "$touch_product_id" == "0" ];
then
debug "touch ic reports invalid product id"
error_and_leave 3
fi
debug "touch product id: $touch_product_id"
read_touch_property buildid || error_and_leave 1
str_cfg_id_boot=${property#*-}
let dec_cfg_id_boot=0x$str_cfg_id_boot
debug "touch config id: $str_cfg_id_boot"
product_id=$(getprop $device_property 2> /dev/null)
[ -z "$product_id" ] && error_and_leave 2 $device_property
product_id=${product_id%-*}
debug "product id: $product_id"
hwrev_id=$(getprop $hwrev_property 2> /dev/null)
[ -z "$hwrev_id" ] && error_and_leave 2 $hwrev_property
debug "hw revision: $hwrev_id"
cd $firmware_path
debug "search for best hw revision match"
hw_mask="-$hwrev_id"
while [ ! -z "$hw_mask" ]; do
if [ "$hw_mask" == "-" ]; then
hw_mask=""
fi
find_latest_config_id "$touch_vendor-$touch_product_id-*-$product_id$hw_mask.*"
if [ $? -eq 0 ]; then
break;
fi
hw_mask=${hw_mask%?}
done
[ -z "$str_cfg_id_latest" ] && error_and_leave 3
firmware_file=$(ls $touch_vendor-$touch_product_id-$str_cfg_id_latest-*-$product_id$hw_mask.*)
debug "firmware file for upgrade $firmware_file"
if [ $dec_cfg_id_boot -ne $dec_cfg_id_latest ] || [ "$bl_mode" == "1" ];
then
debug "forcing firmware upgrade"
echo 1 > $touch_path/forcereflash
debug "sending reflash command"
echo $firmware_file > $touch_path/doreflash
read_touch_property flashprog || error_and_leave 1
bl_mode=$property
[ "$bl_mode" == "1" ] && error_and_leave 4
read_touch_property buildid || error_and_leave 1
str_cfg_id_new=${property#*-}
debug "firmware config ids: expected $str_cfg_id_latest, current $str_cfg_id_new"
echo "Touch firmware config id at boot time $str_cfg_id_boot"
echo "Touch firmware config id in the file $str_cfg_id_latest"
echo "Touch firmware config id currently programmed $str_cfg_id_new"
else
echo "Touch firmware is up to date"
fi
unset device_property hwrev_property
unset str_cfg_id_boot str_cfg_id_latest str_cfg_id_new
unset dec_cfg_id_boot dec_cfg_id_latest
unset hwrev_id product_id touch_product_id
unset synaptics_link firmware_path touch_path
unset bl_mode dbg_on hw_mask firmware_file property
return 0