OSDN Git Service

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