-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpft.sh
282 lines (256 loc) · 7.54 KB
/
pft.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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/bin/bash
base=$(dirname "$_")
cd "$base"
error() {
local -i rc=$1
shift
echo "ERROR($rc): $*" >/dev/tty
exit $rc
}
for x in emmcdl adb fastboot; do
type -P "$x" || error $? "No '$x' command."
done >/dev/null
for x in partitions.txt tools/emmc.mbn; do
[ -f "$x" ] || error 1 "No file '$x'."
done
for x in files/*.bin; do
[ "$x" = 'files/*.bin' ] && error 1 "No 'files/*.bin' here."
done
TheGroup=''
grep -qw uucp /etc/group && TheGroup=uucp
grep -qw dialout /etc/group && TheGroup=dialout
if [ -z "${TheGroup}" ]; then
TheGroup=dialout
echo "!!! Cannot detect group. Assume '${TheGroup}' !!!"
fi >/dev/tty
cat >/dev/tty <<EOT
*=================================================*
* *
* Partitions Flashing Tool for ZTE Blade V9 Vita *
* *
* Made by friendki11er *
* Port on Linux by jno *
* Minor edits by Zalexanninev15 *
* *
*=================================================*
Read That Fine Manual at
https://chiselapp.com/user/jno/repository/PFT4pda/doc
first!
EOT
if id -Gn | grep -qw "${TheGroup}"; then
echo -n "Looks like you, '${LOGNAME:-$USER}', is "
echo "already in the '${TheGroup}' group, good."
else
cat <<EOT
Then check to see if you're in the proper group:
$(id -Gn | fold -sw50 | sed -e 's/^/: /')
You may need to run something like
sudo adduser ${LOGNAME:-$USER} ${TheGroup}
and re-login.
EOT
fi >/dev/tty
if [ "$(systemctl is-active ModemManager)" = active ]
then
cat <<EOT
!!! You may brick your device !!!
Do not forget to get rid of the ModemManager first!
sudo systemctl stop ModemManager
EOT
fi >/dev/tty
echo
read -r -p '-- Press Enter to continue --'
echo
ls_usb_interfaces() {
local -i n=0
for i in `find -H /sys/bus/usb/devices/usb* -name interface`; do
u=$(dirname $i)
let n+=1
(cd $u && echo -n "$u" &&
echo -n "|$(<../manufacturer)|$(<../product)|$(<interface)" &&
echo -n "|$(<../idVendor):$(<../idProduct)" &&
echo '')
done
(( n == 0 )) && echo "!!! No USB *interfaces* found !!!"
}
get_port() {
local prompt="$*"
local port=''
{ lsusb; ls -l /dev/ttyUSB*; } >/dev/tty
while [ -z "$port" ]; do
read -r -p "${prompt}: " port </dev/tty
[ -e "$port" ] && break
[ -e "/dev/$port" ] && { port="/dev/$port"; break; }
[ -e "/dev/tty$port" ] && { port="/dev/tty$port"; break; }
echo "No port '$port'!"
port=''
done >/dev/tty
local w=q r=q
[ -r "$port" ] && r=readable || r=non-readable
[ -w "$port" ] && w=writable || w=non-writable
ls -l "$port" > /dev/tty
echo "$prompt is '$port', $w, $r." > /dev/tty
read -r -p '-- Press Enter to continue --' w < /dev/tty
echo "$port"
}
get_partition() {
local partn=''
select partn in $(awk 'NF == 4 {print $2}' partitions.txt); do
if grep -q " $partn " partitions.txt; then
echo "Partition choosen is '$partn'." >/dev/tty
echo "$partn"
break
fi
done
}
check4edl() {
local -i delay=${1:-2}
sync
if (( delay > 0 )); then
local -i i=0
echo -n "Wait... " >/dev/tty
for ((i=0; i<delay; i++)); do echo -n '#'; sleep 1; done >/dev/tty
echo ' .' >/dev/tty
fi >/dev/tty
ls_usb_interfaces >/dev/tty
if lsusb | grep -w 9008; then
echo "The device listed above is ready."
else
echo "!!! No device with PID=9008 found !!!"
return 1
fi >/dev/tty
echo
}
dfu2edl() {
if emmcdl -p "$(get_port DFU Port)" -raw 0xFE; then
echo 'Done.'
check4edl 2
else
cat <<EOT
* !!!Failed to change DFU to EDL mode!!! *
* *
* Please check the following: *
* *
* 1) DFU mode is active; *
* 2) DFU port was chosen properly; *
* 3) USB cable is working. *
* *
EOT
fi >/dev/tty
}
adb2edl() {
adb devices
if adb reboot edl; then
echo 'Done.'
check4edl 30
else
cat <<EOT
* !!!Failed to change ADB to EDL mode!!! *
* *
* Please check the following: *
* *
* 1) ADB Debugging is active; *
* 2) USB cable is working. *
* *
EOT
fi >/dev/tty
}
backup_partition() {
local edlcom=$(get_port EDL Port) partn=$(get_partition)
mkdir -p backup
if emmcdl -p "$edlcom" -f tools/emmc.mbn -d "$partn" -o "backup/${partn}.bin"; then
echo 'Done.'
else
cat <<EOT
* !!!Failed to backup partition!!! *
* *
* Please check the following: *
* *
* 1) EDL mode is active; *
* 2) EDL port was chosen properly; *
* 3) USB cable is working; *
* 4) Target partition name is correct. *
* *
EOT
fi >/dev/tty
}
declare -a partitions2backup=(
aboot abootbak apdp batweak boot cache cmnlib
cmnlib64 cmnlib64bak cmnlibbak config DDR devcfg
devcfgbak devinfo dip dpo dsp factory fingerid
fsc fsg keymaster keymasterbak keystore limits
logdump mcfg mdtp misc modem modemst1 modemst2
mota msadp oem persist recovery rpm rpmbak sbl1
sbl1bak sec splash ssd syscfg system tz tzbak
vendor ztecfg userdata
)
backup_all_partitions() {
local partn edlcom=$(get_port EDL Port)
mkdir -p backup
for partn in "${partitions2backup[@]}"; do
if emmcdl \
-p "$edlcom" \
-f tools/emmc.mbn \
-d "$partn" \
-o "backup/${partn}.bin"
then
echo 'Done.'
else
cat <<EOT
* !!!Failed to backup partition!!! *
* *
* Please check the following: *
* *
* 1) EDL mode is active; *
* 2) EDL port was chosen properly; *
* 3) USB cable is working; *
* 4) Target partition name is correct. *
* *
EOT
fi >/dev/tty
done
}
flash_partition() {
local edlcom=$(get_port EDL Port) partn=$(get_partition) flash=''
select flash in files/*.bin; do
[ -f "$flash" ] && break
echo 'What??'
done
echo "Flashing '$flash' to partition '$partn' via '$edlcom'..." >/dev/tty
if emmcdl -p "$edlcom" -f tools/emmc.mbn -b "$partn" "$flash"; then
echo 'Done.'
else
cat <<EOT
* !!!Failed to flash partition!!! *
* *
* Please check the following: *
* *
* 1) EDL mode is active; *
* 2) EDL port was chosen properly; *
* 3) USB cable is working; *
* 4) Target partition name is correct. *
* *
EOT
fi >/dev/tty
}
if check4edl; then echo "*** EDL ***"; else echo "--- NO EDL ---"; fi >/dev/tty
echo
echo Menu
select menu in \
'DFU to EDL mode changer' \
'ADB to EDL mode changer' \
'Backup all partitions' \
'Backup any partition' \
'Flash any partition' \
'EXIT'; do
if [ -n "$menu" ]; then
case "$menu" in
EXIT) echo "Bye."; exit;;
DFU*) dfu2edl;;
ADB*) adb2edl;;
Backup*partition)backup_partition;;
Backup*partitions)backup_all_partitions;;
Flash*) flash_partition;;
*) echo "What??";;
esac > /dev/tty
fi
done