OSDN Git Service

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