-
Notifications
You must be signed in to change notification settings - Fork 0
/
init
executable file
·503 lines (429 loc) · 13.5 KB
/
init
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
#!/bin/sh
fail() {
/bin/echo "Failed"
/bin/echo "$1"
exec /bin/sh
}
/bin/mount -o remount,rw / /
PATH=/sbin:/system/sbin:/bin:/system/bin:/system/xbin:/system/xbin/bb:/data/local/bin
/bin/echo "Rootfs loaded."
/bin/mount -t proc proc /proc
/bin/mount -t sysfs sys /sys
echo 256 > /sys/devices/virtual/bdi/179:0/read_ahead_kb
echo 7 > /proc/sys/vm/laptop_mode
echo 90 > /proc/sys/vm/dirty_ratio
echo 60000 > /proc/sys/vm/dirty_expire_centisecs
echo 60000 > /proc/sys/vm/dirty_writeback_centisecs
/bin/mount | grep mtd
notnand=$?
if [ $notnand = "0" ] ; then
echo "running from NAND"
/bin/mount -t yaffs2 /dev/block/mtdblock2 /system
/bin/mount -t yaffs2 /dev/block/mtdblock3 /data
fi
partition=mmcblk0p1
# Try unpartitioned card
if [ ! -d /sys/block/mmcblk0/$partition ] ; then
partition=mmcblk0
fi
if [ -f /sys/class/vogue_hw/gsmphone ] ; then
echo "GSM phone found"
fi
#mkdir -m 0777 /sdcard
#fsck already done in initrd
mount -t vfat -o fmask=0000,dmask=0000,rw,flush,relatime,utf8 /dev/block/$partition /sdcard
[ $? -eq 0 ] || fail "Failed to mount the SD card. Cannot continue."
if [ ! -d /sdcard/cache ] ; then
mkdir /sdcard/cache
fi
#mkdir -m 0777 /cache
mount /sdcard/cache /cache
CARD_PATH=`/bin/grep -o "rel_path=.*" /proc/cmdline | /bin/sed -e "s/.*rel_path=//g" -e "s/ .*//g"`
if [ "$CARD_PATH" = "" ];then
CARD_PATH="andboot"
fi;
if [ -d /sdcard/$CARD_PATH ] ; then
card=/sdcard/$CARD_PATH
else
card=/sdcard
fi
if [ $notnand = "1" ] ; then
if [ -d /sys/block/mmcblk0/mmcblk0p4 ] && /bin/grep -q -v no_partitions /proc/cmdline ; then
echo "Using partitioned system"
/bin/e2fsck -y /dev/block/mmcblk0p3
mount -t ext2 -o relatime /dev/block/mmcblk0p3 /system
/bin/e2fsck -y /dev/block/mmcblk0p4
mount -t auto -o relatime /dev/block/mmcblk0p4 /data
[ $? -eq 0 ] || fail "Failed to mount /data (/dev/block/mmcblk0p4)"
else
echo "Using loopback filesystems"
losetup /dev/block/loop1 $card/system.ext2
[ $? -eq 0 ] || fail "Failed to find system.ext2 on SD Card"
e2fsck -y /dev/block/loop1
mount -t ext2 -o relatime /dev/block/loop1 /system
[ $? -eq 0 ] || fail "Failed to mount /system"
dataimg=data.img
mkfs="-t ext2"
if /bin/grep -q ext4dev /proc/cmdline ; then
dataimg=data.ext4
mkfs="-t ext4 -E test_fs -O ^huge_file"
fi
if [ -f $card/data.gz ] ; then
echo "Please wait... extracting $dataimg"
gzip -cdf $card/data.gz > $card/$dataimg
[ $? -eq 0 ] || fail "Failed to extract $dataimg"
rm $card/data.gz
elif [ ! -f $card/$dataimg ] ; then
echo "Creating a new $dataimg"
dd if=/dev/zero of=$card/$dataimg bs=1048576 count=256
[ $? -eq 0 ] || fail "Failed to allocate $dataimg"
mkdir -p /etc/ ; touch /etc/mtab
mke2fs $mkfs -F $card/$dataimg
[ $? -eq 0 ] || fail "Failed to format $dataimg"
fi
losetup /dev/block/loop0 $card/$dataimg
[ $? -eq 0 ] || fail "Failed to find $dataimg on SD Card"
e2fsck -y /dev/block/loop0
mount -t auto -o relatime /dev/block/loop0 /data
[ $? -eq 0 ] || fail "Failed to mount /data ($card/$datamimg)"
fi
fi
if [ -f "$card/update.zip" ] && [ ! -f "/sdcard/cache/recovery/intent" ] && [ -z "$SQUASH" ]
then
RECOVERYCARD=$(echo $card | sed -e 's:/sdcard/:SDCARD\::')
echo "STARTING OTA UPDATE SYSTEM"
rm -f /init.rc
ln -s /init.cfg/init.recovery.rc /init.rc
mkdir /cache/recovery
echo "--update_package=${RECOVERYCARD}/update.zip" >/cache/recovery/command
echo "--send_intent=complete" >>/cache/recovery/command
exec /init.android
fi
# If not updating, ensure old recovery.intent and update.zip files are removed so we can update again later.
rm -f /sdcard/cache/recovery/intent
rm -f $card/update.zip
if [ -d $card/AndroidApps ] ; then
echo Copying Applications
if [ ! -d /data/app ] ; then
mkdir -m 0771 /data/app
chown -R 1000:1000 /data/app
fi
(cd $card/AndroidApps; for i in *; do if [ ! -f "/data/app/$i" -o "$i" -nt "/data/app/$i" ]; then \
cp "$i" /data/app; fi done)
fi
cp -ar /init.etc/* /system/etc
LCDDENSITY=`/bin/grep -o "lcd.density=.*" /proc/cmdline | /bin/sed -e "s/.*lcd.density=//g" -e "s/ .*//g"`
if [ "$LCDDENSITY" != "" ] ; then
DENS2=`grep lcd_density /system/etc/default.prop | sed -e 's/.*=//'`
if [ "$LCDDENSITY" != "$DENS2" ]; then
echo Setting ro.sf.lcd_density=$LCDDENSITY
if [ -z "$DENS2" ]; then
echo "ro.sf.lcd_density=$LCDDENSITY" >> /system/etc/default.prop
else
sed -i /lcd_density/s/=.*/=$LCDDENSITY/ /system/etc/default.prop
fi
fi
fi
mount /sdcard/cache /tmp
KAISER=0
DIAMOND=0
WIFI_TI=0
WIFI_BCM=0
XPERIA=0
WVGA=0
HW=`cat /proc/cpuinfo | grep Hardware`
case "$HW" in
*Kaiser*)
echo "KAISER detected"
HW=KAISER
KAISER=1
WIFI_TI=1
;;
*Polaris*)
echo "POLARIS detected"
HW=POLARIS
KAISER=1
WIFI_TI=1
;;
*Diamond*)
echo "DIAMOND detected"
HW=DIAMOND
DIAMOND=1
WIFI_TI=1
;;
*Raphael*)
echo "RAPHAEL detected"
HW=RAPHAEL
DIAMOND=1
WIFI_TI=1
;;
*blackstone*)
echo "BLACKSTONE detected"
HW=BLACKSTONE
DIAMOND=1
WIFI_TI=1
WVGA=1
;;
*Topaz*)
echo "TOPAZ detected"
HW=TOPAZ
DIAMOND=1
WIFI_TI=1
WVGA=1
KBD=topa
;;
*Kovsky*)
echo "XPERIA detected"
HW=KOVSKY
XPERIA=1
WIFI_TI=1
WVGA=1
;;
*Rhodium*)
echo "RHODIUM detected"
HW=RHODIUM
DIAMOND=1
WIFI_BCM=1
WVGA=1
;;
*)
echo "VOGUE detected"
HW=VOGUE
;;
esac
RCSCRIPT=""
RCCONFIG=""
echo "Checking for build type..."
if [ -f /system/hero.build ] ; then
echo "Hero build detected"
RCSCRIPT="hero"
RCCONFIG="hero"
ln /data/app_s /system/app
elif [ -f /system/eclairhero.build ] ; then
echo "HERO 2.1 BUILD DETECTED -- ECLAIR"
RCSCRIPT="eclairhero"
RCCONFIG="eclairhero"
mount --bind /lib/eclair/hw /system/lib/hw
elif [ -f /system/eclair.build ] ; then
echo "Eclair build detected"
RCSCRIPT="eclair"
RCCONFIG="eclair"
mount --bind /lib/eclair/hw /system/lib/hw
elif [ -f /system/froyo.build ] ; then
echo "Froyo build detected"
RCSCRIPT="froyo"
RCCONFIG="froyo"
mount --bind /lib/froyo/hw /system/lib/hw
elif [ -f /system/gingerbread.build ] ; then
echo "Gingerbread build detected"
RCSCRIPT="gingerbread"
RCCONFIG="gingerbread"
elif [ -f /system/tattoo.build ] ; then
echo "Tattoo build detected"
RCSCRIPT="tattoo"
RCCONFIG="tattoo"
elif [ -f /system/donut.build ] ; then
echo "Donut build detected"
RCSCRIPT="donut"
RCCONFIG="donut"
mount --bind /lib/donut/hw /system/lib/hw
elif [ -d /system/lib/donut ] ; then
echo "Donut build detected"
RCSCRIPT="donut"
RCCONFIG="donut"
elif [ -f /system/xrom.build ] ; then
echo "xROM build detected"
RCSCRIPT="xrom"
RCCONFIG="xrom"
elif [ -f /system/rogers.build ] ; then
echo "Rogers build detected"
RCSCRIPT="rogers"
RCCONFIG="rogers"
elif [ -f /system/cyanogen.build ] ; then
echo "cyanogen experimental detected.....eating donuts"
RCSCRIPT="cyanogen"
RCCONFIG="cyanogen"
elif [ -f /system/custom.build ] ; then
echo "Custom init.rc detected"
cp /system/sysinit.rc /init.cfg/init.sysinit.rc
RCCONFIG="hero"
RCSCRIPT="sysinit"
else
echo "Unknown Android build. Assuming Ion variant"
RCSCRIPT="ion"
RCCONFIG="ion"
# for the fake sensors library
mount /lib/hw /system/lib/hw -o loop
chmod 666 /dev/input/event0
if [ $DIAMOND -eq 1 ] ; then
RCCONFIG="ion.diamond"
fi
fi
if [ $KAISER -eq 1 ] ; then
RCSCRIPT="$RCSCRIPT.kaiser"
fi
if [ "$LCDDENSITY" != "" ] ; then
DENS2=`grep lcd_density /system/etc/default.prop | sed -e 's/.*=//'`
if [ "$LCDDENSITY" != "$DENS2" ]; then
echo Setting ro.sf.lcd_density=$LCDDENSITY
if [ -z "$DENS2" ]; then
echo "ro.sf.lcd_density=$LCDDENSITY" >> /system/etc/default.prop
else
sed -i /lcd_density/s/=.*/=$LCDDENSITY/ /system/etc/default.prop
fi
fi
fi
if [ $XPERIA -eq 1 ] ; then
ROT=`grep hwrotation /system/etc/default.prop | sed -e 's/.*=//'`
if [ "$ROT" != 180 ]; then
echo Setting ro.sf.hwrotation=180
if [ -z "$ROT" ]; then
echo "ro.sf.hwrotation=180" >> /system/etc/default.prop
else
sed -i /hwrotation/s/=.*/=180/ /system/etc/default.prop
fi
fi
fi
echo "using $card/conf/$RCCONFIG.user.conf"
INITRC=`ls -l /init.rc | grep "$RCSCRIPT"`
if [ -z "$INITRC" ]; then
echo "using /init.$RCSCRIPT.rc as init.rc"
rm -f /init.rc
ln -s "/init.cfg/init.$RCSCRIPT.rc" /init.rc
fi
#Assume this rootfs.img will be used only on "good" devices
#Meaning raph/diam/blac/
# echo /dev/block/mmcblk0p2 > /sys/devices/platform/usb_mass_storage/lun0/file
ifconfig usb0 192.168.20.1 up
busybox telnetd -b 192.168.20.1 -l /bin/sh
#chmod 4755 /bin/su
#mkdir -m 0777 /smodem
mknod /dev/urandom c 1 9
if [ -d /data/dropbear/ ] ; then
echo "Starting SSH"
mknod /dev/random c 1 8
/bin/dropbear -r /data/dropbear/dropbear_rsa_host_key -s
fi
if [ "$WIFI_TI" = "1" ] || [ "$WIFI_BCM" = "1" ];then
if [ -e "$card/modules-$(uname -r).tar.gz" ] && ! `strings /lib/modules/mac80211.ko 2>/dev/null | grep -q "vermagic=$(uname -r)"`; then
echo "Installing $card/modules-$(uname -r).tar.gz"
tar xzf $card/modules-$(uname -r).tar.gz -C /lib/modules
ln -s /lib/modules /lib/modules/`uname -r`
else
echo "Modules already unpacked for this kernel version -- skipping installation of $card/modules-$(uname -r).tar.gz"
fi
if [ -f /system/etc/wifi/wlan.ko ]; then
cp -R /system/etc/wifi/* /lib/modules/
rm /system/etc/wifi/wlan.ko
depmod
fi
if [ "`grep -c ^wifi /system/etc/default.prop`" != "2" ]; then
echo "wifi.interface = wlan0" >> /system/etc/default.prop
echo "wifi.supplicant_scan_interval = 45" >> /system/etc/default.prop
fi
fi
if [ -f /system/eclair.build ]
then
mount --bind /lib/eclair/libhardware_legacy.so /system/lib/libhardware_legacy.so
fi
if [ "$WIFI_BCM" = "1" ] ;then
# fyi: firmware is loaded from /data/etc/wifi/bcm432x/bcm4325-rtecdc.bin, nvram from /data/wifi-nvram.txt
# extract nvram (todo: clean this up/integrate with TI calibration)
if [ ! -e /data/wifi-nvram.txt ]; then
insmod /lib/modules/mtdchar.ko
mknod /dev/mtd0ro c 90 1
for SKIP in 5744 4736;do
mkdir /lib/modules/$(uname -r)
dd if=/dev/mtd0ro of=/tmp/tempcal bs=8192 count=1 skip=$SKIP
rmdir /lib/modules/$(uname -r)
dd if=/tmp/tempcal of=/data/wifi-nvram.txt bs=1 count=466
rm /tmp/tempcal
if grep nocrc= /data/wifi-nvram.txt 2>&1 > /dev/null;then
break
fi;
done
rm /dev/mtd0ro
rmmod mtdchar
if [ "$SKIP" = "5744" ];then
echo "CDMA Rhodium detected"
fi;
if [ "$SKIP" = "4736" ];then
echo "GSM Rhodium detected"
fi;
fi
fi
for i in local.prop eri.xml serialno; do
if [ -f "$card/$i" ]; then
if [ ! -f /data/$i -o "$card/$i" -nt /data/$i ]; then
cp "$card/$i" /data/$i
fi
fi
done
if [ -f "$card/conf/$RCCONFIG.user.conf" ]; then
/bin/userinit.sh -c "$card/conf/$RCCONFIG.user.conf"
else
echo "No user config files ($RCCONFIG) found on sdcard"
fi
mount -tdebugfs none /dbgfs
#Activate baclight control
echo 3 > /sys/class/htc_hw/test
#Smooth scroll
echo 40 >/sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold
#Activate full charging
echo 2 > /dbgfs/htc_battery/charger_state
[ -z $KBD ] && KBD=`sed 's/.*physkeyboard=\([0-9a-z_]*\).*/\1/' /proc/cmdline`
cp /init.etc/keymaps/default/*.kl /system/usr/keylayout/
cp /init.etc/keymaps/default/*.kcm* /system/usr/keychars/
if [ -d "/init.etc/keymaps/$KBD" ]
then
cp /init.etc/keymaps/"$KBD"/*.kl /system/usr/keylayout/
cp /init.etc/keymaps/"$KBD"/*.kcm* /system/usr/keychars/
fi
mount -o remount,ro /system
for i in /sys/class/input/input* ; do
if [ "`cat $i/name`" = "tssc-manager" ] ; then
touchscreendir=$i
echo "Touchscreen device directory is $i"
fi
done
if [ -f $card/ts-calibration ] ; then
echo "Using Saved Touchscreen Calibration"
echo 128,128,1903,128,128,1907,1903,1907,1024,1024 > $touchscreendir/calibration_screen
cat $card/ts-calibration > $touchscreendir/calibration_points
else
mkdir /dev/graphics
mknod /dev/graphics/fb0 c 29 0
clear
echo; echo; echo; echo; echo; echo; echo; echo "Calibrating Touchscreen:"
echo "Click the Five Targets in order -- Top Left, Top Right, Middle, Bottom Left, Bottom Right"
echo "(Tap lightly. The screen is quite sensitive.)"
tssc-calibrate
echo 0,0,0,0,0,0,0,0,0,0 | cmp -s $touchscreendir/calibration_points # determine if calibration is still null -- means failed calibration
if [ $? -eq 0 ] ; then
echo "Touchscreen Calibration Failed"
else
echo "Touchscreen Calibration Successful; Saving..."
cat $touchscreendir/calibration_points > $card/ts-calibration
fi
fi
mkdir /dev/msm_camera
mknod /dev/msm_camera/control0 c 250 0
mknod /dev/msm_camera/config0 c 250 1
mknod /dev/msm_camera/frame0 c 250 2
# Generate a "serial number" for the Android system to identify the device.
# Put it in /data so it survives reboots. Won't survive a factory reset, though.
[ -f "/data/serialno" ] || echo -e `cat /dev/urandom | tr -dc 'A-Z0-9' | fold -w 12 | head -n 1` >/data/serialno
SERIALNO=$(cat /data/serialno)
cp /proc/cmdline /tmp/cmdline
sed -i -e "s:$: androidboot.serialno=${SERIALNO}:" /tmp/cmdline
mount --bind /tmp/cmdline /proc/cmdline
# Transition sequence for FRX06->FRX07 (eth0/tiwlan0 renamed)
if [ -f "/data/misc/wifi/wpa_supplicant.conf" ]
then
sed -i -e 's:=\(tiwlan0\|eth0\):=wlan0:' /data/misc/wifi/wpa_supplicant.conf
chown 1000:1010 /data/misc/wifi/wpa_supplicant.conf
fi
# Bind-mount /sdcard/.android_secure to /mnt/secure/asec for native Apps2SD
[ -d /sdcard/.android_secure ] || mkdir /sdcard/.android_secure
mount --bind /sdcard/.android_secure /mnt/secure/asec
exec /init.android