OSDN Git Service

init.sh: load f2fs module manually
[android-x86/device-generic-common.git] / init.sh
1 #
2 # Copyright (C) 2013-2015 The Android-x86 Open Source Project
3 #
4 # License: GNU Public License v2 or later
5 #
6
7 function set_property()
8 {
9         setprop "$1" "$2"
10         [ -n "$DEBUG" ] && echo "$1"="$2" >> /dev/x86.prop
11 }
12
13 function init_misc()
14 {
15         # device information
16         setprop ro.product.manufacturer "$(cat $DMIPATH/sys_vendor)"
17         setprop ro.product.model "$PRODUCT"
18
19         # a hack for USB modem
20         lsusb | grep 1a8d:1000 && eject
21
22         # in case no cpu governor driver autoloads
23         [ -d /sys/devices/system/cpu/cpu0/cpufreq ] || modprobe acpi-cpufreq
24
25         # for vold f2fs support
26         modprobe f2fs
27 }
28
29 function init_hal_audio()
30 {
31         case "$PRODUCT" in
32                 VirtualBox*|Bochs*)
33                         [ -d /proc/asound/card0 ] || modprobe snd-sb16 isapnp=0 irq=5
34                         ;;
35                 *)
36                         ;;
37         esac
38
39         if [ "`cat /proc/asound/card0/id`" = "IntelHDMI" ]; then
40                 [ -d /proc/asound/card1 ] || set_property ro.hardware.audio.primary hdmi
41         fi
42 }
43
44 function init_hal_bluetooth()
45 {
46         for r in /sys/class/rfkill/*; do
47                 type=$(cat $r/type)
48                 [ "$type" = "wlan" -o "$type" = "bluetooth" ] && echo 1 > $r/state
49         done
50
51         case "$PRODUCT" in
52                 T10*TA|HP*Omni*)
53                         BTUART_PORT=/dev/ttyS1
54                         ;;
55                 MacBookPro8*)
56                         rmmod b43
57                         modprobe b43 btcoex=0
58                         modprobe btusb
59                         ;;
60                 # FIXME
61                 # Fix MacBook 2013-2015 (Air6/7&Pro11/12) BCM4360 ssb&wl conflict.
62                 MacBookPro11* | MacBookPro12* | MacBookAir6* | MacBookAir7*)
63                         rmmod b43
64                         rmmod ssb
65                         rmmod bcma
66                         rmmod wl
67                         modprobe wl
68                         modprobe btusb
69                         ;;
70                 *)
71                         for bt in $(lsusb -v | awk ' /Class:.E0/ { print $9 } '); do
72                                 chown 1002.1002 $bt && chmod 660 $bt
73                         done
74                         modprobe btusb
75                         ;;
76         esac
77
78         if [ -n "$BTUART_PORT" ]; then
79                 set_property hal.bluetooth.uart $BTUART_PORT
80                 chown bluetooth.bluetooth $BTUART_PORT
81                 start btattach:-B$BTUART_PORT
82                 log -t hciconfig -p i "`hciconfig`"
83         fi
84 }
85
86 function init_hal_camera()
87 {
88         return
89 }
90
91 function init_hal_gps()
92 {
93         # TODO
94         return
95 }
96
97 function set_drm_mode()
98 {
99         case "$PRODUCT" in
100                 ET1602*)
101                         drm_mode=1366x768
102                         ;;
103                 *)
104                         ;;
105         esac
106
107         [ -n "$drm_mode" ] && set_property debug.drm.mode.force $drm_mode
108 }
109
110 function init_uvesafb()
111 {
112         case "$PRODUCT" in
113                 ET2002*)
114                         UVESA_MODE=${UVESA_MODE:-1600x900}
115                         ;;
116                 *)
117                         ;;
118         esac
119
120         [ "$HWACCEL" = "0" ] && bpp=16 || bpp=32
121         modprobe uvesafb mode_option=${UVESA_MODE:-1024x768}-$bpp ${UVESA_OPTION:-mtrr=3 scroll=redraw}
122 }
123
124 function init_hal_gralloc()
125 {
126         case "$(cat /proc/fb | head -1)" in
127                 *virtiodrmfb)
128 #                       set_property ro.hardware.hwcomposer drm
129                         ;&
130                 0*inteldrmfb|0*radeondrmfb|0*nouveaufb|0*svgadrmfb)
131                         set_property ro.hardware.gralloc drm
132                         set_drm_mode
133                         ;;
134                 "")
135                         init_uvesafb
136                         ;&
137                 0*)
138                         ;;
139         esac
140
141         [ -n "$DEBUG" ] && set_property debug.egl.trace error
142 }
143
144 function init_hal_hwcomposer()
145 {
146         # TODO
147         return
148 }
149
150 function init_hal_lights()
151 {
152         chown 1000.1000 /sys/class/backlight/*/brightness
153 }
154
155 function init_hal_power()
156 {
157         for p in /sys/class/rtc/*; do
158                 echo disabled > $p/device/power/wakeup
159         done
160
161         # TODO
162         case "$PRODUCT" in
163                 *)
164                         ;;
165         esac
166 }
167
168 function init_hal_sensors()
169 {
170         # if we have sensor module for our hardware, use it
171         ro_hardware=$(getprop ro.hardware)
172         [ -f /system/lib/hw/sensors.${ro_hardware}.so ] && return 0
173
174         local hal_sensors=kbd
175         local has_sensors=true
176         case "$(cat $DMIPATH/uevent)" in
177                 *Lucid-MWE*)
178                         set_property ro.ignore_atkbd 1
179                         hal_sensors=hdaps
180                         ;;
181                 *ICONIA*W5*)
182                         hal_sensors=w500
183                         ;;
184                 *S10-3t*)
185                         hal_sensors=s103t
186                         ;;
187                 *Inagua*)
188                         #setkeycodes 0x62 29
189                         #setkeycodes 0x74 56
190                         set_property ro.ignore_atkbd 1
191                         set_property hal.sensors.kbd.type 2
192                         ;;
193                 *TEGA*|*2010:svnIntel:*)
194                         set_property ro.ignore_atkbd 1
195                         set_property hal.sensors.kbd.type 1
196                         io_switch 0x0 0x1
197                         setkeycodes 0x6d 125
198                         ;;
199                 *DLI*)
200                         set_property ro.ignore_atkbd 1
201                         set_property hal.sensors.kbd.type 1
202                         setkeycodes 0x64 1
203                         setkeycodes 0x65 172
204                         setkeycodes 0x66 120
205                         setkeycodes 0x67 116
206                         setkeycodes 0x68 114
207                         setkeycodes 0x69 115
208                         setkeycodes 0x6c 114
209                         setkeycodes 0x6d 115
210                         ;;
211                 *tx2*)
212                         setkeycodes 0xb1 138
213                         setkeycodes 0x8a 152
214                         set_property hal.sensors.kbd.type 6
215                         set_property poweroff.doubleclick 0
216                         set_property qemu.hw.mainkeys 1
217                         ;;
218                 *MS-N0E1*)
219                         set_property ro.ignore_atkbd 1
220                         set_property poweroff.doubleclick 0
221                         setkeycodes 0xa5 125
222                         setkeycodes 0xa7 1
223                         setkeycodes 0xe3 142
224                         ;;
225                 *Aspire1*25*)
226                         modprobe lis3lv02d_i2c
227                         echo -n "enabled" > /sys/class/thermal/thermal_zone0/mode
228                         ;;
229                 *ThinkPad*Tablet*)
230                         modprobe hdaps
231                         hal_sensors=hdaps
232                         ;;
233                 *i7Stylus*)
234                         set_property hal.sensors.iio.accel.matrix 1,0,0,0,-1,0,0,0,-1
235                         ;;
236                 *ST70416-6*)
237                         set_property hal.sensors.iio.accel.matrix 0,-1,0,-1,0,0,0,0,-1
238                         ;;
239                 *ONDATablet*)
240                         set_property hal.sensors.iio.accel.matrix 0,1,0,1,0,0,0,0,-1
241                         ;;
242                 *)
243                         #has_sensors=false
244                         ;;
245         esac
246
247         # has iio sensor-hub?
248         if [ -n "`ls /sys/bus/iio/devices/iio:device* 2> /dev/null`" ]; then
249                 busybox chown -R 1000.1000 /sys/bus/iio/devices/iio:device*/
250                 lsmod | grep -q hid_sensor_accel_3d && hal_sensors=hsb || hal_sensors=iio
251         elif lsmod | grep -q lis3lv02d_i2c; then
252                 hal_sensors=hdaps
253         fi
254
255         set_property ro.hardware.sensors $hal_sensors
256         [ "$hal_sensors" != "kbd" ] && has_sensors=true
257         set_property config.override_forced_orient $has_sensors
258 }
259
260 function create_pointercal()
261 {
262         if [ ! -e /data/misc/tscal/pointercal ]; then
263                 mkdir -p /data/misc/tscal
264                 touch /data/misc/tscal/pointercal
265                 chown 1000.1000 /data/misc/tscal /data/misc/tscal/*
266                 chmod 775 /data/misc/tscal
267                 chmod 664 /data/misc/tscal/pointercal
268         fi
269 }
270
271 function init_tscal()
272 {
273         case "$PRODUCT" in
274                 ST70416-6*)
275                         modprobe gslx680_ts_acpi
276                         ;&
277                 T91|T101|ET2002|74499FU|945GSE-ITE8712|CF-19[CDYFGKLP]*)
278                         create_pointercal
279                         return
280                         ;;
281                 *)
282                         ;;
283         esac
284
285         for usbts in $(lsusb | awk '{ print $6 }'); do
286                 case "$usbts" in
287                         0596:0001|0eef:0001)
288                                 create_pointercal
289                                 return
290                                 ;;
291                         *)
292                                 ;;
293                 esac
294         done
295 }
296
297 function init_ril()
298 {
299         case "$(cat $DMIPATH/uevent)" in
300                 *TEGA*|*2010:svnIntel:*|*Lucid-MWE*)
301                         set_property rild.libpath /system/lib/libhuaweigeneric-ril.so
302                         set_property rild.libargs "-d /dev/ttyUSB2 -v /dev/ttyUSB1"
303                         set_property ro.radio.noril no
304                         ;;
305                 *)
306                         set_property ro.radio.noril yes
307                         ;;
308         esac
309 }
310
311 function init_cpu_governor()
312 {
313         governor=$(getprop cpu.governor)
314
315         [ $governor ] && {
316                 for cpu in $(ls -d /sys/devices/system/cpu/cpu?); do
317                         echo $governor > $cpu/cpufreq/scaling_governor || return 1
318                 done
319         }
320 }
321
322 function do_init()
323 {
324         init_misc
325         init_hal_audio
326         init_hal_bluetooth
327         init_hal_camera
328         init_hal_gps
329         init_hal_gralloc
330         init_hal_hwcomposer
331         init_hal_lights
332         init_hal_power
333         init_hal_sensors
334         init_tscal
335         init_ril
336         post_init
337 }
338
339 function do_netconsole()
340 {
341         modprobe netconsole netconsole="@/,@$(getprop dhcp.eth0.gateway)/"
342 }
343
344 function do_bootcomplete()
345 {
346         init_cpu_governor
347
348         [ -z "$(getprop persist.sys.root_access)" ] && setprop persist.sys.root_access 3
349
350         lsmod | grep -Ehq "brcmfmac|rtl8723be" && setprop wlan.no-unload-driver 1
351
352         case "$PRODUCT" in
353                 1866???|1867???|1869???) # ThinkPad X41 Tablet
354                         start tablet-mode
355                         start wacom-input
356                         setkeycodes 0x6d 115
357                         setkeycodes 0x6e 114
358                         setkeycodes 0x69 28
359                         setkeycodes 0x6b 158
360                         setkeycodes 0x68 172
361                         setkeycodes 0x6c 127
362                         setkeycodes 0x67 217
363                         ;;
364                 6363???|6364???|6366???) # ThinkPad X60 Tablet
365                         ;&
366                 7762???|7763???|7767???) # ThinkPad X61 Tablet
367                         start tablet-mode
368                         start wacom-input
369                         setkeycodes 0x6d 115
370                         setkeycodes 0x6e 114
371                         setkeycodes 0x69 28
372                         setkeycodes 0x6b 158
373                         setkeycodes 0x68 172
374                         setkeycodes 0x6c 127
375                         setkeycodes 0x67 217
376                         ;;
377                 7448???|7449???|7450???|7453???) # ThinkPad X200 Tablet
378                         start tablet-mode
379                         start wacom-input
380                         setkeycodes 0xe012 158
381                         setkeycodes 0x66 172
382                         setkeycodes 0x6b 127
383                         ;;
384                 *)
385                         ;;
386         esac
387
388 #       [ -d /proc/asound/card0 ] || modprobe snd-dummy
389         for c in $(grep '\[.*\]' /proc/asound/cards | awk '{print $1}'); do
390                 f=/system/etc/alsa/$(cat /proc/asound/card$c/id).state
391                 if [ -e $f ]; then
392                         alsa_ctl -f $f restore $c
393                 else
394                         alsa_ctl init $c
395                         alsa_amixer -c $c set Master on
396                         alsa_amixer -c $c set Master 100%
397                         alsa_amixer -c $c set Headphone on
398                         alsa_amixer -c $c set Headphone 100%
399                         alsa_amixer -c $c set Speaker 100%
400                         alsa_amixer -c $c set Capture 100%
401                         alsa_amixer -c $c set Capture cap
402                         alsa_amixer -c $c set PCM 100 unmute
403                         alsa_amixer -c $c set SPO unmute
404                         alsa_amixer -c $c set 'Mic Boost' 3
405                         alsa_amixer -c $c set 'Internal Mic Boost' 3
406                 fi
407         done
408 }
409
410 function do_hci()
411 {
412         local hci=`hciconfig | grep ^hci | cut -d: -f1`
413         local btd="`getprop init.svc.bluetoothd`"
414         log -t bluetoothd -p i "$btd ($hci)"
415         if [ -n "`getprop hal.bluetooth.uart`" ]; then
416                 [ "`getprop init.svc.bluetoothd`" = "running" ] && hciconfig $hci up
417         fi
418 }
419
420 PATH=/sbin:/system/bin:/system/xbin
421
422 DMIPATH=/sys/class/dmi/id
423 BOARD=$(cat $DMIPATH/board_name)
424 PRODUCT=$(cat $DMIPATH/product_name)
425
426 # import cmdline variables
427 for c in `cat /proc/cmdline`; do
428         case $c in
429                 BOOT_IMAGE=*|iso-scan/*|*.*=*)
430                         ;;
431                 *=*)
432                         eval $c
433                         if [ -z "$1" ]; then
434                                 case $c in
435                                         HWACCEL=*)
436                                                 set_property debug.egl.hw $HWACCEL
437                                                 ;;
438                                         DEBUG=*)
439                                                 [ -n "$DEBUG" ] && set_property debug.logcat 1
440                                                 ;;
441                                 esac
442                         fi
443                         ;;
444         esac
445 done
446
447 [ -n "$DEBUG" ] && set -x || exec &> /dev/null
448
449 # import the vendor specific script
450 hw_sh=/vendor/etc/init.sh
451 [ -e $hw_sh ] && source $hw_sh
452
453 case "$1" in
454         netconsole)
455                 [ -n "$DEBUG" ] && do_netconsole
456                 ;;
457         bootcomplete)
458                 do_bootcomplete
459                 ;;
460         hci)
461                 do_hci
462                 ;;
463         init|"")
464                 do_init
465                 ;;
466 esac
467
468 return 0