-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflashboot.sh
136 lines (122 loc) · 4.15 KB
/
flashboot.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
#!/system/bin/sh
# Copyright 2012 [email protected]
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# HTC Kernel Installer - v0.57
#
# 'if' is not always available so case is a more reliable alternative.
#
exec 1>>/data/local/bootinfo.txt 2>&1
PRINTLOG(){
sync
logwrapper echo $$" "$@
echo $$" "$@
}
REBOOT(){
#---Depending on the ROM 'reboot' may not be reliable
while :; do
REBOOT2 "/system/bin/reboot" " $@"
REBOOT2 $TMPBB " reboot -d 2 -f $@"
REBOOT2 $ROMBB " reboot -d 2 -f $@"
PRINTLOG "Sending the reboot command to the radio..."
echo -e 'AT$QCPWRDN\r' > /dev/smdcntl0; sleep 2
echo -e 'AT$QCPWRDN\r' > /dev/smd0; sleep 2
PRINTLOG "Failed To Reboot, Retying In 5 Seconds"
sleep 5
done
}
REBOOT2(){
case $(ls $1) in
$1) PRINTLOG "Attempting to Reboot with \"$@\""
sync; $@
case $? in
0) PRINTLOG "Call to Reboot Successful"; sleep 8;;
esac;;
esac
}
echo $$" - "`date`" - "${0##*\/}" Starting --------------"
TMPBB="/system/bin/busybox2"
ROMBB="/system/xbin/busybox"
BOOTNEW="/data/local/bootnew.img"
BOOTOLD="/data/local/bootold.img"
BOOTNEWPAD="/data/local/bootnewpad.img"
BOOTCURRENT="/data/local/bootcurrent.img"
APPPROCESS="/system/bin/app_process"
NETD="/system/bin/netd"
FLASHBOOT="/system/bin/flashboot.sh"
BBPIDOF=$TMPBB" pidof"
BBGREP=$TMPBB" grep"
BBAWK=$TMPBB" awk"
BBMOUNT=$TMPBB" mount"
BBDD=$TMPBB" dd"
BBSTAT=$TMPBB" stat"
BBMD5=$TMPBB" md5sum"
#---Only the instance with the lowest PID should stay running
PIDS=$($BBPIDOF ${FLASHBOOT##*\/})
case ${PIDS##* } in
$$) PRINTLOG "Looks like this is the one! Proceeding...";;
*) PRINTLOG "Yielding to \"${PIDS##* }\""; exit 1;;
esac
#---Find the moint point for Boot and remount /system as writable
case $(ls "/proc/mtd") in
/proc/mtd)
EMMTD="/proc/mtd";;
*) EMMTD="/proc/emmc";;
esac
BLOCKBOOT=/dev/block/$(cat $EMMTD | $BBGREP '"boot"' | $BBAWK '-F:' '{ print $1; }')
PRINTLOG "Found Boot Partitions Mount Point at \""$BLOCKBOOT"\""
sync; $BBMOUNT -o rw,remount /system
#---Make sure the boot.img is where we expect it, if it's gone check to see if the padded copy is still available
$BBDD if=$BLOCKBOOT of=$BOOTOLD conv=noerror; sync
case $(ls $BOOTNEW) in
$BOOTNEW)
PRINTLOG "Preparing to Write New Boot Image"
SIZEBOOT=$($BBSTAT $BOOTOLD | $BBGREP "Size:" | $BBAWK '{ printf("%s\n",$2); }'); sync
$BBDD if=$BOOTNEW ibs=$SIZEBOOT of=$BOOTNEWPAD conv=sync; sync
rm $BOOTNEW;;
*) case $(! ls $BOOTNEWPAD >>/dev/null 2>&1; echo $?) in
0) PRINTLOG "\"$BOOTNEW\" not found! Was /data wiped?"
REBOOT "recovery";;
*) PRINTLOG "\"$BOOTNEW\" not found! Using \"$BOOTNEWPAD\" instead.";;
esac;;
esac
#---Flash the new boot.img and then compare MD5s to verify it
$BBDD if=$BOOTNEWPAD of=$BLOCKBOOT; sync
$BBDD if=$BLOCKBOOT of=$BOOTCURRENT conv=noerror; sync
PRINTLOG "Verifying the Boot partitions MD5"
MD5OLD=$($BBMD5 $BOOTOLD | $BBAWK '-F ' '{ print $1; }')
MD5NEWPAD=$($BBMD5 $BOOTNEWPAD | $BBAWK '-F ' '{ print $1; }')
MD5CURRENT=$($BBMD5 $BOOTCURRENT | $BBAWK '-F ' '{ print $1; }')
PRINTLOG "$MD5OLD $BOOTOLD"
PRINTLOG "$MD5NEWPAD $BOOTNEWPAD"
PRINTLOG "$MD5CURRENT $BOOTCURRENT"
case $MD5CURRENT in
$MD5NEWPAD)
PRINTLOG "Verified Boot Flashed Properly";;
$MD5OLD)
PRINTLOG "Failed to Write to \"$BLOCKBOOT\"!"
REBOOT "recovery";;
*) PRINTLOG "Failed to Flash Correctly! Restoring Original."
$BBDD if=$BOOTOLD of=$BLOCKBOOT
REBOOT "recovery";;
esac
#---Replace the old files and clean up any unneeded ones
PRINTLOG "Cleaning Up";
cat $APPPROCESS.bck > $APPPROCESS
cat $NETD.bck > $NETD; sync
chown 0.2000 $APPPROCESS $NETD
chmod 755 $APPPROCESS $NETD
rm $FLASHBOOT $BOOTCURRENT $BOOTNEWPAD $BOOTOLD $APPPROCESS.bck $NETD.bck $TMPBB
REBOOT