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