OSDN Git Service

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