OSDN Git Service

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