OSDN Git Service

490e5f5d3680c5040560a3cb902f5f53069de7b6
[android-x86/bootable-newinstaller.git] / initrd / scripts / 0-auto-detect
1 #
2 # By Chih-Wei Huang <cwhuang@linux.org.tw>
3 # Last updated 2009/08/14
4 #
5 # License: GNU Public License
6 # We explicitely grant the right to use the scripts
7 # with Android-x86 project.
8 #
9
10 # An auto detect function provided by kinneko
11 auto_detect()
12 {
13         tmp=/tmp/dev2mod
14         echo 'dev2mod() { while read dev; do case $dev in' > $tmp
15         sort -r /lib/modules/`uname -r`/modules.alias | \
16                 sed -n 's/^alias  *\([^ ]*\)  *\(.*\)/\1)modprobe \2;;/p' >> $tmp
17         echo 'esac; done; }' >> $tmp
18         source $tmp
19         cat /sys/bus/*/devices/*/modalias | dev2mod
20 }
21
22 # FB0DEV: framebuffer driver
23 # LANDEV: lan driver
24 # WIFDEV: wifi driver
25 # SNDDEV: sound driver
26 # CAMDEV: camera driver
27 # PREDEV: any module the drivers depend on but can't be loaded automatically
28 # EXTMOD: any other module
29
30 asus_info()
31 {
32         # common for all Eee PC models
33         [ -c /dev/fb0 ] || FB0DEV=i915
34         EXTMOD=eeepc-laptop
35         PREDEV=snd-hda-codec-realtek
36         SNDDEV=snd-hda-intel
37         CAMDEV=uvcvideo
38
39         board=`cat /sys/class/dmi/id/product_name`
40         # assume Eee PC models
41         case "$board" in
42                 700|701|702|900)
43                         LANDEV=atl2
44                         WIFDEV=ath5k
45                         ;;
46                 701SD|900SD)
47                         LANDEV=atl1e
48                         WIFDEV=rtl8187se
49                         ;;
50                 900A|904HD|1000HD)
51                         LANDEV=atl1e
52                         WIFDEV=ath5k
53                         ;;
54                 901|1000|1000H)
55                         LANDEV=atl1e
56                         WIFDEV=rt2860sta
57                         ;;
58                 ET1602*)
59                         FB0DEV=
60                         UVESA_MODE=${UVESA_MODE:-1366x768}
61                         LANDEV=r8169
62                         WIFDEV=rt2860sta
63                         ;;
64                 T91)
65                         FB0DEV=
66                         UVESA_MODE=${UVESA_MODE:-1024x600}
67                         LANDEV=atl1e
68                         WIFDEV=ath9k
69                         ;;
70                 A6VM*)
71                         EXTMOD=asus-laptop
72                         LANDEV=skge
73                         WIFDEV=ipw2200
74                         ;;
75                 *)
76                         LANDEV=atl1e
77                         WIFDEV=ath9k
78                         ;;
79         esac
80 }
81
82 samsung_info()
83 {
84         [ -c /dev/fb0 ] || FB0DEV=i915
85         EXTMOD=hso
86         PREDEV=snd-hda-codec-realtek mii rfkill
87         SNDDEV=snd-hda-intel
88         CAMDEV=gspca_vc032x
89         WIFDEV=ath5k
90         LANDEV=b44
91 }
92
93 vbox_info()
94 {
95         LANDEV=pcnet32
96         SNDDEV="snd-sb16 isapnp=0 irq=5"
97         VESA=1
98 }
99
100 qemu_info()
101 {
102         LANDEV=8139cp
103         SNDDEV=snd-ens1370
104 }
105
106 vmware_info()
107 {
108         LANDEV=pcnet32
109         SNDDEV=snd-ens1371
110 }
111
112 detect_hardware()
113 {
114         [ "$AUTO" = "1" ] && return
115         case "`cat /sys/class/dmi/id/uevent`" in
116                 *ASUSTeK*)
117                         get_info=asus_info
118                         ;;
119                 *SAMSUNG*)
120                         get_info=samsung_info
121                         ;;
122                 *Acer*AO*)
123                         get_info=ao_info
124                         ;;
125                 *VirtualBox*)
126                         get_info=vbox_info
127                         ;;
128                 *QEMU*)
129                         get_info=qemu_info
130                         ;;
131                 *VMware*)
132                         get_info=vmware_info
133                         ;;
134                 *)
135                         ;;
136         esac
137         [ -n "$get_info" ] && $get_info && FOUND=1
138 }
139
140 find_network_dev_name()
141 {
142         wififound=0
143         rmline=`grep -n "#REMOVE FROM HERE" init.rc|cut -d':' -f1`
144         rmline=`expr $rmline + 1`
145         sed -i -e "$rmline,\$d" init.rc
146         for netdev in `ls /sys/class/net`; do
147                 if [ $netdev = "lo" -o $netdev = "wmaster0" ]; then
148                         continue
149                 fi              
150                 w=/sys/class/net/$netdev
151                 if [ -d $w/wireless -o -d $w/phy80211 ]; then
152                         if [ $wififound -eq 0 ]; then
153                                 sed -i "s|\(^ *service wpa_supplicant .*\)\(-i.*\)\( -c.*$\)|\1-i $netdev\3|g" init.rc
154                                 wififound=1
155                         fi
156                 fi
157                 echo "service dhcpcd$netdev /system/bin/dhcpcd $netdev" >> init.rc
158                 echo "   group system dhcp" >> init.rc
159                 echo "   disabled" >>init.rc
160                 echo "   oneshot" >> init.rc
161         done
162 }
163
164 load_modules()
165 {
166         if [ -n "$FOUND" ]; then
167                 BTDEV="bnep rfcomm sco btusb"
168                 for m in $PREDEV $EXTMOD $BTDEV; do
169                         modprobe $m
170                 done
171                 [ -n "$FB0DEV" -a -z "$UVESA_MODE" ] && modprobe $FB0DEV
172                 [ -n "$LANDEV" ] && modprobe $LANDEV
173                 [ -n "$WIFDEV" ] && modprobe $WIFDEV
174                 [ -n "$SNDDEV" ] && modprobe $SNDDEV
175                 [ -n "$CAMDEV" ] && modprobe $CAMDEV
176         else
177                 auto_detect
178         fi
179
180         mdev -s
181         [ -c /dev/video0 ] || modprobe vivi
182         [ -d /proc/asound/card0 ] || modprobe snd-dummy
183         [ -c /dev/fb0 ] || modprobe uvesafb mode_option=${UVESA_MODE:-800x600}-16 ${UVESA_OPTION:-mtrr=3 scroll=redraw}
184         find_network_dev_name
185 #       find_wifi_dev_name
186 }