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