forked from zhujiong/android_device_samsung_aries-common
-
Notifications
You must be signed in to change notification settings - Fork 2
/
updater.sh
executable file
·268 lines (214 loc) · 8.28 KB
/
updater.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
#!/tmp/busybox sh
#
# Universal Updater Script for Samsung Galaxy S Phones
# (c) 2011 by Teamhacksung
# Combined GSM & CDMA version
#
check_mount() {
if ! /tmp/busybox grep -q $1 /proc/mounts ; then
/tmp/busybox mkdir -p $1
/tmp/busybox umount -l $2
if ! /tmp/busybox mount -t $3 $2 $1 ; then
/tmp/busybox echo "Cannot mount $1."
exit 1
fi
fi
}
set_log() {
rm -rf $1
exec >> $1 2>&1
}
# ui_print by Chainfire
OUTFD=$(/tmp/busybox ps | /tmp/busybox grep -v "grep" | /tmp/busybox grep -o -E "update_binary(.*)" | /tmp/busybox cut -d " " -f 3);
ui_print() {
if [ $OUTFD != "" ]; then
echo "ui_print ${1} " 1>&$OUTFD;
echo "ui_print " 1>&$OUTFD;
else
echo "${1}";
fi;
}
set -x
export PATH=/:/sbin:/system/xbin:/system/bin:/tmp:$PATH
# Check if we're in CDMA or GSM mode
if /tmp/busybox test "$1" = cdma ; then
# CDMA mode
IS_GSM='/tmp/busybox false'
SD_PART='/dev/block/mmcblk1p1'
DATA_PART='/dev/block/mmcblk0p1'
else
# GSM mode
IS_GSM='/tmp/busybox true'
SD_PART='/dev/block/mmcblk0p1'
DATA_PART='/dev/block/mmcblk0p2'
fi
# check for old/non-cwm recovery.
if ! /tmp/busybox test -n "$UPDATE_PACKAGE" ; then
# scrape package location from /tmp/recovery.log
UPDATE_PACKAGE=`/tmp/busybox cat /tmp/recovery.log | /tmp/busybox grep 'Update location:' | /tmp/busybox tail -n 1 | /tmp/busybox cut -d ' ' -f 3-`
fi
# check if we're running on a bml, mtd (old) or mtd (current) device
if /tmp/busybox test -e /dev/block/bml7 ; then
# we're running on a bml device
# make sure sdcard is mounted
check_mount /mnt/sdcard $SD_PART vfat
# everything is logged into /mnt/sdcard/cyanogenmod_bml.log
set_log /mnt/sdcard/cyanogenmod_bml.log
if $IS_GSM ; then
# make sure efs is mounted
check_mount /efs /dev/block/stl3 rfs
# create a backup of efs
if /tmp/busybox test -e /mnt/sdcard/backup/efs ; then
/tmp/busybox mv /mnt/sdcard/backup/efs /mnt/sdcard/backup/efs-$$
fi
/tmp/busybox rm -rf /mnt/sdcard/backup/efs
/tmp/busybox mkdir -p /mnt/sdcard/backup/efs
/tmp/busybox cp -R /efs/ /mnt/sdcard/backup
fi
# write the package path to sdcard cyanogenmod.cfg
if /tmp/busybox test -n "$UPDATE_PACKAGE" ; then
PACKAGE_LOCATION=${UPDATE_PACKAGE#/mnt}
/tmp/busybox echo "$PACKAGE_LOCATION" > /mnt/sdcard/cyanogenmod.cfg
fi
# Scorch any ROM Manager settings to require the user to reflash recovery
/tmp/busybox rm -f /mnt/sdcard/clockworkmod/.settings
# write new kernel to boot partition
/tmp/flash_image boot /tmp/boot.img
if [ "$?" != "0" ] ; then
exit 3
fi
/tmp/busybox sync
/sbin/reboot now
exit 0
elif /tmp/busybox test `/tmp/busybox cat /sys/class/mtd/mtd2/size` != 367001600 ; then
# we're running on a mtd (old) device
# make sure sdcard is mounted
check_mount /sdcard $SD_PART vfat
# everything is logged into /sdcard/cyanogenmod_mtd_old.log
set_log /sdcard/cyanogenmod_mtd_old.log
if ! /tmp/busybox test -e /.accept_wipe ; then
/tmp/busybox touch /.accept_wipe
ui_print
ui_print "============================================"
ui_print "This ROM uses an incompatible partition layout"
ui_print "Your /data will be wiped upon installation"
ui_print "Run this update.zip again to confirm install"
ui_print "============================================"
ui_print
exit 9
fi
/tmp/busybox rm /.accept_wipe
# write the package path to sdcard cyanogenmod.cfg
if /tmp/busybox test -n "$UPDATE_PACKAGE" ; then
/tmp/busybox echo "$UPDATE_PACKAGE" > /sdcard/cyanogenmod.cfg
fi
# inform the script that this is an old mtd upgrade
/tmp/busybox echo 1 > /sdcard/cyanogenmod.mtdupd
# we also removed /datadata, so migrate data
/tmp/busybox mount /data
if /tmp/busybox test -h /data/data ; then
/tmp/busybox mkdir /datadata
/tmp/busybox mount /datadata
/tmp/busybox rm /data/data
/tmp/busybox mkdir /data/data
/tmp/busybox chown system.system /data/data
/tmp/busybox chmod 0771 /data/data
/tmp/busybox cp -a /datadata/* /data/data/
/tmp/busybox rm -r /data/data/lost+found
fi
/tmp/busybox umount /data
# clear datadata
/tmp/busybox umount -l /datadata
/tmp/erase_image datadata
# write new kernel to boot partition
/tmp/bml_over_mtd.sh boot 72 reservoir 2004 /tmp/boot.img
# Remove /system/build.prop to trigger emergency boot
/tmp/busybox mount /system
/tmp/busybox rm -f /system/build.prop
/tmp/busybox umount -l /system
/tmp/busybox sync
/sbin/reboot now
exit 0
elif /tmp/busybox test -e /dev/block/mtdblock0 ; then
# we're running on a mtd (current) device
# make sure sdcard is mounted
check_mount /sdcard $SD_PART vfat
# everything is logged into /sdcard/cyanogenmod.log
set_log /sdcard/cyanogenmod_mtd.log
if $IS_GSM ; then
# create mountpoint for radio partition
/tmp/busybox mkdir -p /radio
# make sure radio partition is mounted
if ! /tmp/busybox grep -q /radio /proc/mounts ; then
/tmp/busybox umount -l /dev/block/mtdblock5
if ! /tmp/busybox mount -t yaffs2 /dev/block/mtdblock5 /radio ; then
/tmp/busybox echo "Cannot mount radio partition."
exit 5
fi
fi
# if modem.bin doesn't exist on radio partition, format the partition and copy it
if ! /tmp/busybox test -e /radio/modem.bin ; then
/tmp/busybox umount -l /dev/block/mtdblock5
/tmp/erase_image radio
if ! /tmp/busybox mount -t yaffs2 /dev/block/mtdblock5 /radio ; then
/tmp/busybox echo "Cannot copy modem.bin to radio partition."
exit 5
else
/tmp/busybox cp /tmp/modem.bin /radio/modem.bin
fi
fi
# unmount radio partition
/tmp/busybox umount -l /dev/block/mtdblock5
fi
if ! /tmp/busybox test -e /sdcard/cyanogenmod.cfg ; then
# update install - flash boot image then skip back to updater-script
# (boot image is already flashed for first time install or old mtd upgrade)
# flash boot image
/tmp/bml_over_mtd.sh boot 72 reservoir 2004 /tmp/boot.img
if ! $IS_GSM ; then
/tmp/bml_over_mtd.sh recovery 102 reservoir 2004 /tmp/recovery_kernel
fi
# unmount system (recovery seems to expect system to be unmounted)
/tmp/busybox umount -l /system
exit 0
fi
# if a cyanogenmod.cfg exists, then this is a first time install
# let's format the volumes and restore radio and efs
# remove the cyanogenmod.cfg to prevent this from looping
/tmp/busybox rm -f /sdcard/cyanogenmod.cfg
# unmount and format system (recovery seems to expect system to be unmounted)
/tmp/busybox umount -l /system
/tmp/erase_image system
# restart into recovery so the user can install further packages before booting
/tmp/busybox touch /cache/.startrecovery
if /tmp/busybox test -e /sdcard/cyanogenmod.mtdupd ; then
# this is an upgrade with changed MTD mapping for /system, /cache
# so return to updater-script after formatting these two
/tmp/busybox rm -f /sdcard/cyanogenmod.mtdupd
exit 0
fi
# unmount and format data
/tmp/busybox umount /data
/tmp/make_ext4fs -b 4096 -g 32768 -i 8192 -I 256 -a /data $DATA_PART
if $IS_GSM ; then
# restore efs backup
if /tmp/busybox test -e /sdcard/backup/efs/nv_data.bin || \
/tmp/busybox test -e /sdcard/backup/efs/root/afs/settings/nv_data.bin ; then
/tmp/busybox umount -l /efs
/tmp/erase_image efs
/tmp/busybox mkdir -p /efs
if ! /tmp/busybox grep -q /efs /proc/mounts ; then
if ! /tmp/busybox mount -t yaffs2 /dev/block/mtdblock4 /efs ; then
/tmp/busybox echo "Cannot mount efs."
exit 6
fi
fi
/tmp/busybox cp -R /sdcard/backup/efs /
/tmp/busybox umount -l /efs
else
/tmp/busybox echo "Cannot restore efs."
exit 7
fi
fi
exit 0
fi