Enable Broadcom WiFi on Rhodium
[xdandroid:rootfs.git] / init
1 #!/bin/sh
2 fail() {
3         /bin/echo "Failed"
4                 /bin/echo "$1"
5                 exec /bin/sh
6 }
7
8 /bin/mount -o remount,rw / /
9
10 PATH=/sbin:/system/sbin:/system/bin:/bin:/system/xbin:/system/xbin/bb:/data/local/bin
11
12 /bin/echo "Rootfs loaded."
13
14 /bin/mount -t proc proc /proc
15 /bin/mount -t sysfs sys /sys
16
17 /bin/mount | grep mtd
18 notnand=$?
19
20 if [ $notnand = "0" ] ; then
21   echo "running from NAND"
22   /bin/mount -t yaffs2 /dev/block/mtdblock2 /system
23   /bin/mount -t yaffs2 /dev/block/mtdblock3 /data
24 fi
25
26
27 partition=mmcblk0p1
28
29 # Try unpartitioned card
30 if [ ! -d /sys/block/mmcblk0/$partition ] ; then
31         partition=mmcblk0
32 fi
33
34 if [ -f /sys/class/vogue_hw/gsmphone ] ; then
35         echo "GSM phone found"
36 fi
37
38 #mkdir -m 0777 /sdcard
39 #fsck already done in initrd
40 mount -t vfat -o fmask=0000,dmask=0000,rw,flush,noatime,nodiratime /dev/block/$partition /sdcard
41 [ $? -eq 0 ] || fail "Failed to mount the SD card. Cannot continue."
42
43 if [ ! -d /sdcard/cache ] ; then
44         mkdir /sdcard/cache
45 fi
46
47 #mkdir -m 0777 /cache
48 mount /sdcard/cache /cache
49
50 if [ -d /sdcard/android ] ; then
51         card=/sdcard/android
52 else
53         card=/sdcard
54 fi
55
56
57 if [ $notnand = "1" ] ; then
58     
59     if [ -f $card/data.gz ] ; then
60             echo "Please wait... extracting Data Image"
61             if [ -f $card/data.img ] ; then
62                     rm $card/data.img
63             fi
64             gzip -df $card/data.gz
65             [ $? -eq 0 ] || fail "Failed to extract Data Image"
66             mv $card/data $card/data.img
67             echo "done"
68     fi
69     
70     PARTITIONED=0
71     echo "Checking for partition..."
72     if [ -d /sys/block/mmcblk0/mmcblk0p2 ] ; then
73             PARTITIONED=1
74             if [ -d /sys/block/mmcblk0/mmcblk0p3 ] ; then
75                     PARTITIONED=2
76             fi
77     fi
78     
79     if [ -f $card/backupsystem/installedsystem.sqsh -o -f $card/backupsystem/installedsystem.img -o -f $card/backupsystem.ext2 ]; then
80             echo "Partitioned Build Detected"
81     else
82             PARTITIONED=0
83     fi
84     
85     if [ $PARTITIONED -lt 2 ] ; then
86              
87             if [ ! -f $card/data.img ] ; then
88                     echo "Creating a new Data store"
89                     dd if=/dev/zero of=$card/data.img bs=1048576 count=256
90                     [ $? -eq 0 ] || fail "Failed to allocate the storage"
91                     mke2fs -F $card/data.img
92                     [ $? -eq 0 ] || fail "Failed to format the storage"
93             fi
94     fi
95     
96     if [ $PARTITIONED -lt 2 ] ; then
97             losetup /dev/block/loop0 $card/data.img
98             [ $? -eq 0 ] || fail "Failed to find data.img on SD Card"
99             e2fsck -y /dev/block/loop0
100             mount -t ext2 -o noatime,nodiratime,sync /dev/block/loop0 /data
101     else
102             e2fsck -y /dev/block/mmcblk0p3
103             mount -t ext2 -o noatime,nodiratime /dev/block/mmcblk0p3 /data
104     fi
105     [ $? -eq 0 ] || fail "Failed to mount /data"
106     
107     if [ $PARTITIONED -eq 0 ] ; then
108             if      [ -f $card/system.ext2 ] ; then
109                     echo "Using uncompressed system"
110                     losetup /dev/block/loop1 $card/system.ext2
111                     [ $? -eq 0 ] || fail "Failed to reach system.ext2 on SD Card"
112                     e2fsck -y /dev/block/loop1
113                     mount -t ext2 -o noatime,nodiratime /dev/block/loop1 /system
114                     [ $? -eq 0 ] || fail "Failed to mount /system"
115             elif    
116                     [ -f $card/system.sqsh ] ; then
117                     echo "Using SquashFS system"
118                     losetup /dev/block/loop1 $card/system.sqsh
119                     [ $? -eq 0 ] || fail "Failed to find system.sqsh on SD Card"
120                     mount -t squashfs -o ro,noatime,nodiratime /dev/block/loop1 /system
121                     [ $? -eq 0 ] || fail "Failed to mount /system"
122             else
123                     losetup /dev/block/loop1 $card/system.img
124                     [ $? -eq 0 ] || fail "Failed to find system.img on SD Card"
125                     mount -t cramfs -o ro,noatime,nodiratime /dev/block/loop1 /system
126                     [ $? -eq 0 ] || fail "Failed to mount /system"
127             fi
128     else
129             echo "Using partitioned system"
130             e2fsck -y /dev/block/mmcblk0p2
131             mount -t ext2 -o ro,noatime,nodiratime /dev/block/mmcblk0p2 /system
132             [ $? -eq 0 ] || fail "Failed to mount /system"
133     fi
134 fi
135
136 if [ -d $card/AndroidApps ] ; then
137         echo Copying Applications
138         if [ ! -d /data/app ] ; then
139                 mkdir -m 0771 /data/app
140         fi
141         /bin/cp $card/AndroidApps/* /data/app
142         chown -R 1000:1000 /data/app
143 fi
144
145 if [ ! -d $card/media ] ; then
146         echo You have no media folder, please extract the resources to your SD card android folder
147 fi
148
149 SQLITE3="/bin/sqlite3"
150 DB="/data/data/com.android.providers.telephony/databases/telephony.db"
151 if [ -f $DB ] ; then
152         if [ "`$SQLITE3 $DB 'SELECT numeric FROM carriers;' | grep 310995`" != "310995" ] ; then
153                 echo Creating android apn
154                 "$SQLITE3" "$DB" "INSERT INTO carriers VALUES(NULL, 'Android' , '310995' , '310' , '995' , 'internet' , '*' , '*' , '*' , NULL, NULL, NULL, NULL, 'null' , -1, 'default' , 1);"
155
156         fi
157 else
158         echo No telephony database. You must have a new data file. I will check for the android apn on the next reboot
159 fi
160
161 /bin/rm -rf /data/etc
162 /bin/mkdir -m 0755 /data/etc
163 mount /data/etc /etc
164 cp -a /system/etc/* /etc
165 cp -ar /init.etc/* /etc/
166
167 LCDDENSITY=`/bin/grep -o "lcd.density=.*" /proc/cmdline | /bin/sed -e "s/.*lcd.density=//g" -e "s/ .*//g"`
168
169 if [ "$LCDDENSITY" != "" ] ; then
170         echo "ro.sf.lcd_density=$LCDDENSITY" >> /etc/default.prop
171         echo Setting ro.sf.lcd_density=$LCDDENSITY
172 fi
173
174 if [ ! -d /data/shared_prefs ] ; then
175         mkdir -m 0770 /data/shared_prefs
176 fi
177 chmod 0770 /data/shared_prefs
178 chown 1000:1000 /data/shared_prefs
179 mount /data/shared_prefs /shared_prefs
180
181 mount /sdcard/cache /tmp
182
183 cp /system/build.prop /tmp/build.prop
184 KAISER=0
185 DIAMOND=0
186 WIFI_TI=0
187 WIFI_BCM=0
188 ### Is this a Kaiser?
189 if [ "`cat /proc/cpuinfo|grep -o Kaiser`" = "Kaiser" ]; then
190         echo "KAISER detected"
191         KAISER=1
192         WIFI_TI=1
193 elif [ "`cat /proc/cpuinfo|grep -o Polaris`" = "Polaris" ]; then
194         echo "POLARIS detected"
195         KAISER=1
196         WIFI_TI=1
197 elif [ "`cat /proc/cpuinfo|grep -o Diamond`" = "Diamond" ]; then
198         echo "DIAMOND detected"
199         DIAMOND=1
200         WIFI_TI=1
201 elif [ "`cat /proc/cpuinfo|grep -o Raphael`" = "Raphael" ]; then
202         echo "RAPHAEL detected"
203         DIAMOND=1
204         WIFI_TI=1
205 elif [ "`cat /proc/cpuinfo|grep -o blackstone`" = "blackstone" ]; then
206         echo "BLACKSTONE detected"
207         DIAMOND=1
208         WIFI_TI=1
209 elif [ "`cat /proc/cpuinfo|grep -o Topaz`" = "Topaz" ]; then
210         echo "TOPAZ detected"
211         DIAMOND=1
212         WIFI_TI=1
213 elif [ "`cat /proc/cpuinfo|grep -o Rhodium`" = "Rhodium" ]; then
214         echo "RHODIUM detected"
215         DIAMOND=1
216         WIFI_BCM=1
217 else
218         echo "VOGUE detected"
219         sed -i s/^wifi/#wifi/ /tmp/build.prop
220 fi
221
222 mount --bind /tmp/build.prop /system/build.prop
223
224 ### Fix su on some builds...
225 mount --bind /bin/su /system/bin/su 2> /dev/null
226 mount --bind /bin/su /system/xbin/su 2> /dev/null
227
228 RCSCRIPT=""
229 RCCONFIG=""
230
231 echo "Checking for build type..."
232 if [ -f /system/hero.build ] ; then
233         echo "Hero build detected"
234         RCSCRIPT="hero"
235         RCCONFIG="hero"
236         ln /data/app_s /system/app
237
238 elif [ -f /system/eclairhero.build ] ; then
239         echo "HERO 2.1 BUILD DETECTED -- ECLAIR"
240         RCSCRIPT="eclairhero"
241         RCCONFIG="eclairhero"
242
243 elif [ -f /system/eclair.build ] ; then
244         echo "Eclair build detected"
245         RCSCRIPT="eclair"
246         RCCONFIG="eclair"
247
248 elif [ -f /system/tattoo.build ] ; then
249         echo "Tattoo build detected"
250         RCSCRIPT="tattoo"
251         RCCONFIG="tattoo"
252
253 elif [ -f /system/donut.build ] ; then
254         echo "Donut build detected"
255         RCSCRIPT="donut"
256         RCCONFIG="donut"
257
258 elif [ -d /system/lib/donut ] ; then
259         echo "Donut build detected"
260         RCSCRIPT="donut"
261         RCCONFIG="donut"
262
263 elif [ -f /system/xrom.build ] ; then
264         echo "xROM build detected"
265         RCSCRIPT="xrom"
266         RCCONFIG="xrom"
267
268 elif [ -f /system/rogers.build ] ; then
269         echo "Rogers build detected"
270         RCSCRIPT="rogers"
271         RCCONFIG="rogers"
272
273 elif [ -f /system/cyanogen.build ] ; then
274         echo "cyanogen experimental detected.....eating donuts"
275         RCSCRIPT="cyanogen"
276         RCCONFIG="cyanogen"
277
278 elif [ -f /system/custom.build ] ; then
279         echo "Custom init.rc detected"
280         cp /system/sysinit.rc /build.cfg/init.sysinit.rc
281         RCCONFIG="hero"
282         RCSCRIPT="sysinit"
283         
284 else
285         echo "Unknown Android build. Assuming Ion variant"
286         RCSCRIPT="ion"
287         RCCONFIG="ion"
288
289         # for the fake sensors library
290         mount /lib/hw /system/lib/hw -o loop
291         chmod 666 /dev/input/event0
292
293         if [ $DIAMOND -eq 1 ] ; then
294                 RCCONFIG="ion.diamond"
295         fi
296 fi
297
298 if [ $KAISER -eq 1 ] ; then
299         RCSCRIPT="$RCSCRIPT.kaiser"
300 fi
301
302 echo "using /init.$RCSCRIPT.rc as init.rc"
303 echo "using $card/conf/$RCCONFIG.user.conf"
304
305 cp "/init.cfg/init.$RCSCRIPT.rc" /etc/init.rc
306
307 #Assume this rootfs.img will be used only on "good" devices
308 #Meaning raph/diam/blac/
309
310 # echo /dev/block/mmcblk0p2 > /sys/devices/platform/usb_mass_storage/lun0/file
311 ifconfig usb0 192.168.20.1 up
312 busybox telnetd -b 192.168.20.1 -l /bin/sh
313 #chmod 4755 /bin/su
314 #mkdir -m 0777 /smodem
315 if [ -d /data/dropbear/ ] ; then
316         echo "Starting SSH"
317         mknod /dev/random c 1 8
318         mknod /dev/urandom c 1 9
319         /bin/dropbear -r /data/dropbear/dropbear_rsa_host_key -s
320 fi
321
322 if [ "$WIFI_TI" = "1" ] || [ "$WIFI_BCM" = "1" ];then
323         if [ -e "$card/modules-$(uname -r).tar.gz" ] ;then
324                 echo "Installing $card/modules-$(uname -r).tar.gz"
325                 if [ ! -d "/data/modules" ] ; then
326                         mkdir /data/modules
327                 fi
328                 mount --bind /data/modules /lib/modules
329                 tar xzf $card/modules-$(uname -r).tar.gz -C /lib/modules
330                 cd /lib/modules
331                 cp wlan.ko /etc/wifi
332                 cp bcm4329.ko /etc/wifi
333         fi
334         mount --bind /etc/wifi /system/lib/modules
335
336         sed -i s/^#wifi/wifi/ /tmp/build.prop
337 fi
338
339 if [ "$WIFI_TI" = "1" ];then
340         if [ "`grep -c ^wifi /tmp/build.prop`" != "2" ]; then
341                 echo "wifi.interface = tiwlan0" >> /tmp/build.prop
342                 echo "wifi.supplicant_scan_interval = 45" >> /tmp/build.prop
343         fi
344 fi
345
346 if [ "$WIFI_BCM" = "1" ];then
347         if [ "`grep -c ^wifi /tmp/build.prop`" != "2" ]; then
348                 echo "wifi.interface = eth0" >> /tmp/build.prop
349                 echo "wifi.supplicant_scan_interval = 45" >> /tmp/build.prop
350         fi
351
352         # fyi: firmware is loaded from /etc/wifi/bcm432x/bcm4325-rtecdc.bin, nvram from /data/wifi-nvram.txt
353
354         mount --bind /etc/wifi/bcm432x/dhcpcd.conf /system/etc/dhcpcd/dhcpcd.conf
355         mount --bind /etc/wifi/bcm432x/wpa_supplicant.conf /system/etc/wifi/wpa_supplicant.conf
356         mount --bind /etc/wifi/bcm432x/bcm4325-libhardware_legacy.so /system/lib/libhardware_legacy.so
357
358         # init.rc: fix wpa_supplicant service
359         sed -i s/-itiwlan0/-ieth0/ /etc/init.rc
360         sed -i s/-Dtiwlan0/-Dwext/ /etc/init.rc
361
362         # init.rc: fix dhcpcd service, wifi.interface, and wpa_supplicant service socket
363         sed -i s/tiwlan0/eth0/ /etc/init.rc
364
365         # init.rc:
366         sed -i s/user\ wifi/#user\ wifi/ /etc/init.rc
367         sed -i s/group\ wifi/#group\ wifi/ /etc/init.rc
368
369         # extract nvram (todo: clean this up/integrate with TI calibration)
370         if [ ! -e /data/wifi-nvram.txt ]; then
371                 insmod /lib/modules/mtdchar.ko
372                 mknod /dev/mtd0ro c 90 1
373                 mkdir /lib/modules/$(uname -r)
374
375                 SKIP=5744
376
377                 dd if=/dev/mtd0ro of=/tmp/tempcal bs=8192 count=1 skip=$SKIP
378                 rm /dev/mtd0ro
379                 rmmod mtdchar
380                 rmdir /lib/modules/$(uname -r)
381                 dd if=/tmp/tempcal of=/data/wifi-nvram.txt bs=1 count=466
382                 rm /tmp/tempcal
383         fi
384 fi
385
386
387 if [ -f "$card/conf/$RCCONFIG.user.conf" ]; then
388         /bin/userinit.sh -c "$card/conf/$RCCONFIG.user.conf"
389 else
390         echo "No user config files ($RCCONFIG) found on sdcard"
391 fi
392
393 mount -tdebugfs none /dbgfs
394 #Activate baclight control
395 echo 3 > /sys/class/htc_hw/test
396 #Smooth scroll
397 echo 40 >/sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold
398 #Activate full charging
399 echo 2 > /dbgfs/htc_battery/charger_state
400
401 echo 1024 > /dbgfs/micropklt_dbg/sleep_leds
402
403 if /bin/grep -c 'physkeyboard=fuze' /proc/cmdline >/dev/null ; then
404         echo "USING RAPH110|FUZE LAYOUT"
405         cp -f /init.etc/keymaps/fuze_microp-keypad.kcm.bin /etc/keymaps/microp-keypad.kcm.bin
406         cp -f /init.etc/keymaps/fuze_microp-keypad.kl /etc/keymaps/microp-keypad.kl
407         cp -f /init.etc/keymaps/fuze_raph_navi_pad.kl /etc/keymaps/raph_navi_pad.kl
408 elif /bin/grep -c 'physkeyboard=raph' /proc/cmdline >/dev/null ; then
409         echo "USING NEW RAPH LAYOUT"
410         cp -f /init.etc/keymaps/raphfix_microp-keypad.kcm.bin /etc/keymaps/microp-keypad.kcm.bin
411 elif /bin/grep -c 'physkeyboard=tilt2' /proc/cmdline >/dev/null ; then
412         echo "USING EXPERIMENTAL TILT2 LAYOUT"
413         cp -f /init.etc/keymaps/tilt2_microp-keypad.kl /etc/keymaps/microp-keypad.kl
414         cp -f /init.etc/keymaps/tilt2_microp-keypad.kcm.bin /etc/keymaps/microp-keypad.kcm.bin
415         cp -f /init.etc/keymaps/tilt2_navi_pad.kl /etc/keymaps/raph_navi_pad.kl
416 elif /bin/grep -c 'physkeyboard=rhod210' /proc/cmdline >/dev/null ; then
417         echo "USING EXPERIMENTAL RHOD210 LAYOUT"
418         cp -f /init.etc/keymaps/rhod210_microp-keypad.kl /etc/keymaps/microp-keypad.kl
419         cp -f /init.etc/keymaps/rhod210_microp-keypad.kcm.bin /etc/keymaps/microp-keypad.kcm.bin
420         cp -f /init.etc/keymaps/rhod210_navi_pad.kl /etc/keymaps/raph_navi_pad.kl
421 else
422         echo "USING OLD KEYMAP"
423         cp -f /init.etc/keymaps/oldqwerty_microp-keypad.kcm.bin /etc/keymaps/microp-keypad.kcm.bin
424         cp -f /init.etc/keymaps/oldqwerty_microp-keypad.kl /etc/keymaps/microp-keypad.kl
425         cp -f /init.etc/keymaps/oldqwerty_raph_navi_pad.kl /etc/keymaps/raph_navi_pad.kl
426 fi
427
428 for i in /sys/class/input/input* ; do
429         if [ "`cat $i/name`" = "tssc-manager" ] ; then
430                 touchscreendir=$i
431                 echo "Touchscreen device directory is $i"
432         fi
433 done
434
435 if [ -f $card/ts-calibration ] ; then
436         echo "Using Saved Touchscreen Calibration"
437         echo 128,128,1903,128,128,1907,1903,1907,1024,1024 > $touchscreendir/calibration_screen
438         cat $card/ts-calibration > $touchscreendir/calibration_points
439 else
440         mkdir /dev/graphics
441         mknod /dev/graphics/fb0 c 29 0
442         clear
443         echo; echo; echo; echo; echo; echo; echo; echo "Calibrating Touchscreen:"
444         echo "Click the Five Targets in order -- Top Left, Top Right, Middle, Bottom Left, Bottom Right"
445         echo "(Tap lightly. The screen is quite sensitive.)"
446         tssc-calibrate
447         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
448         if [ $? -eq 0 ] ; then
449                 echo "Touchscreen Calibration Failed"
450         else
451                 echo "Touchscreen Calibration Successful; Saving..."
452                 cat $touchscreendir/calibration_points > $card/ts-calibration
453         fi
454 fi
455
456 mkdir /dev/msm_camera
457 mknod /dev/msm_camera/control0 c 250 0
458 mknod /dev/msm_camera/config0 c 250 1
459 mknod /dev/msm_camera/frame0 c 250 2
460
461 exec /init.android