Hollow09Knight

init.sh for BlissOS 16.9.7

Apr 4th, 2025
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 28.41 KB | Source Code | 0 0
  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.     # a hack for USB modem
  28.     lsusb | grep 1a8d:1000 && eject
  29.  
  30.     # in case no cpu governor driver autoloads
  31.     [ -d /sys/devices/system/cpu/cpu0/cpufreq ] || modprobe acpi-cpufreq
  32.  
  33.     # enable sdcardfs/esdfs if /data is not mounted on tmpfs or 9p
  34.     mount | grep /data\ | grep -qE 'tmpfs|9p'
  35.     [ $? -eq 0 ] && SDCARDFS_DISABLE=${SDCARDFS_DISABLE:-1}
  36.  
  37.     # Allow force disable sdcardfs/esdfs
  38.     if [ "$SDCARDFS_DISABLE" -ge 1 ]; then
  39.         set_property external_storage.sdcardfs.enabled false
  40.     fi
  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.     # disable virt_wifi by default, only turn on when user set VIRT_WIFI=1
  50.     local eth=`getprop net.virt_wifi eth0`
  51.     if [ -d /sys/class/net/$eth -a "$VIRT_WIFI" -gt "0" ]; then
  52.         if [ -n "$wifi" -a "$VIRT_WIFI" -ge "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.     #Set CPU name into a property
  64.     setprop ro.bliss.cpuname "$(grep "model name" /proc/cpuinfo | sort -u | cut -d : -f 2 | cut -c2-)"
  65.  
  66.     # Tell vold to use ntfs3 driver instead of ntfs-3g
  67.     if [ "$USE_NTFS3" -ge "1" ] || [ "$VOLD_USE_NTFS3" -ge 1 ]; then
  68.         set_property ro.vold.use_ntfs3 true
  69.     fi
  70. }
  71.  
  72. function init_hal_audio()
  73. {
  74.     case "$PRODUCT" in
  75.         VirtualBox*|Bochs*)
  76.             [ -d /proc/asound/card0 ] || modprobe snd-sb16 isapnp=0 irq=5
  77.             ;;
  78.         TS10*)
  79.             set_prop_if_empty hal.audio.out pcmC0D2p
  80.             ;;
  81.     esac
  82.  
  83.     case "$(ls /proc/asound)" in
  84.         *sofhdadsp*)
  85.             AUDIO_PRIMARY=x86_celadon
  86.             ;;
  87.     esac
  88.     set_property ro.hardware.audio.primary ${AUDIO_PRIMARY:-x86}
  89.  
  90.     if [ "$BOARD" == "Jupiter" ] && [ "$VENDOR" == "Valve" ]
  91.     then
  92.         pcm_card=$(cat /proc/asound/cards | grep acp5x | awk '{print $1}')
  93.         # headset microphone on d0, 32bit only
  94.         set_property hal.audio.in.headset "pcmC${pcm_card}D0c"
  95.         set_property hal.audio.in.headset.format 1
  96.  
  97.         # internal microphone on d0, 32bit only
  98.         set_property hal.audio.in.mic "pcmC${pcm_card}D0c"
  99.         set_property hal.audio.in.mic.format 1
  100.  
  101.         # headphone jack on d0, 32bit only
  102.         set_property hal.audio.out.headphone "pcmC${pcm_card}D0p"
  103.         set_property hal.audio.out.headphone.format 1
  104.  
  105.         # speaker on d1, 16bit only
  106.         set_property hal.audio.out.speaker "pcmC${pcm_card}D1p"
  107.         set_property hal.audio.out.speaker.format 0
  108.  
  109.         # enable hdmi audio on the 3rd output, but it really depends on how docks wire things
  110.         # to make matters worse, jack detection on alsa does not seem to always work on my setup, so a dedicated hdmi hal might want to send data to all ports instead of just probing
  111.         pcm_card=$(cat /proc/asound/cards | grep HDA-Intel | awk '{print $1}')
  112.         set_property hal.audio.out.hdmi "pcmC${pcm_card}D8p"
  113.     fi
  114. }
  115.  
  116. function init_hal_brcm_wifi()
  117. {
  118. ##  Function created by Chaozhuo's PhoenixOS
  119. ##  Currently these devices are supported to use broadcom-wl driver
  120. #   Broadcom BCM4313 (PCI ID 14e4:4727)
  121. #   Broadcom BCM4321 (PCI IDs 14e4:4328, 14e4:4329, 14e4:432a)
  122. #   Broadcom BCM4322 (PCI IDs 14e4:432b, 14e4:432d)
  123. #   Broadcom BCM43142 (PCI ID 14e4:4365)
  124. #   Broadcom BCM4352 (PCI ID 14e4:43b1)
  125. #   Broadcom BCM4360 (PCI IDs 14e4:43a0, 14e4:4360)
  126. ##  These devices are also on the list, but removed due to the fact that
  127. ##  b43 or brcm80211 supports it.
  128. ##  https://wireless.wiki.kernel.org/en/users/drivers/b43
  129. #   Broadcom BCM4311 (PCI IDs 14e4:4311, 14e4:4312)
  130. #   Broadcom BCM4312 (PCI ID 14e4:4315)
  131. #   Broadcom BCM4322 (PCI IDs 14e4:432c)
  132. #   Broadcom BCM43224 (PCI IDs 14e4:0576, 14e4:4353)
  133. #   Broadcom BCM43225 (PCI ID 14e4:4357)
  134. #   Broadcom BCM43227 (PCI ID 14e4:4358)
  135. #   Broadcom BCM43228 (PCI ID 14e4:4359)
  136. #   Broadcom BCM4331 (PCI ID 14e4:4331)
  137.  
  138.     BCMAID=`lspci | grep "14e4" | awk '{print $4}'`
  139.  
  140.     case "${BCMAID##*:}" in
  141.             4727 | \
  142.             4328 | 4329 | 432a | \
  143.             432b | 432d | \
  144.             4365 | \
  145.             43b1 | \
  146.             43a0 | 4360 )
  147.  
  148.             rmmod b43
  149.             rmmod b44
  150.             rmmod b43legacy
  151.             rmmod ssb
  152.             rmmod bcma
  153.             rmmod brcm80211
  154.             rmmod brcmsmac
  155.             rmmod wl
  156.  
  157.             modprobe wl
  158.             ;;
  159.         *)
  160.             ;;
  161.     esac
  162. }
  163.  
  164. function init_hal_audio_bootcomplete()
  165. {
  166.     if [ -e "/data/vendor/asound.state" ]; then
  167.         # Initialize once in case a new audio device is plugged in
  168.         alsa_ctl init
  169.         # Restore /data/vendor/asound.state if found
  170.         alsa_ctl restore
  171.     else
  172.         # Initialize as usual
  173.         # 1. Initialize the all the audio cards
  174.         alsa_ctl init
  175.  
  176.         # 2. Restore alsa state for specific cards or turn on all of the
  177.         # default controls & set value to max (usually for PCH)
  178.         for c in $(grep '\[.*\]' /proc/asound/cards | awk '{print $1}'); do
  179.             f=/system/etc/alsa/$(cat /proc/asound/card$c/id).state
  180.             d=/data/vendor/alsa/$(cat /proc/asound/card$c/id).state
  181.             if [ -e $f ]; then
  182.                 alsa_ctl -f $f restore $c
  183.             elif [ -e $d ]; then
  184.                 alsa_ctl -f $d restore $c
  185.             else
  186.                 alsa_amixer -c $c set Master on
  187.                 alsa_amixer -c $c set Master 100%
  188.                 alsa_amixer -c $c set Headphone on
  189.                 alsa_amixer -c $c set Headphone 100%
  190.                 alsa_amixer -c $c set Speaker on
  191.                 alsa_amixer -c $c set Speaker 100%
  192.                 alsa_amixer -c $c set Capture 80%
  193.                 alsa_amixer -c $c set Capture cap
  194.                 alsa_amixer -c $c set PCM 100% unmute
  195.                 alsa_amixer -c $c set SPO unmute
  196.                 alsa_amixer -c $c set IEC958 on
  197.                 alsa_amixer -c $c set 'Mic Boost' 1
  198.                 alsa_amixer -c $c set 'Internal Mic Boost' 1
  199.  
  200.                 # 2.5. Set alsaucm HiFi verb & devices for specific hardware
  201.                 for d in $(grep '\[.*\]' /proc/asound/cards | awk '{print $4}'); do
  202.                     # Check if the card is rt5651, this card can not be able to
  203.                     # use both Speaker & Headphones at the same time. So we will enable  
  204.                     # only Speaker for this card and tell users to turn Headphones on
  205.                     # manually if they want to use it.
  206.                     if [ "$(cat /proc/asound/cards | grep rt5651)" ]; then
  207.                         card_is_rt5651=true
  208.                     fi
  209.  
  210.                     case $d in
  211.                     *bytcht*|*bytcr*|*cht-bsw*|*chtmax*|*chtrt*|*chtnau*)
  212.                         if [ "$card_is_rt5651" == true ]; then
  213.                             alsaucm -c $d set _verb HiFi \
  214.                             set _enadev Speaker \
  215.                             set _enadev Headset \
  216.                             set _enadev Mic
  217.                         else
  218.                             alsaucm -c $d set _verb HiFi \
  219.                             set _enadev Speaker \
  220.                             set _enadev Headphones \
  221.                             set _enadev Headset \
  222.                             set _enadev Mic
  223.                         fi
  224.                         ;;
  225.                     *SOF*)
  226.                         if [ "$(cat /proc/asound/cards | grep -E 'bytcht|bdw')" ]; then
  227.                             if [ "$card_is_rt5651" == true ]; then
  228.                                 alsaucm -c $d set _verb HiFi \
  229.                                 set _enadev Speaker \
  230.                                 set _enadev Headset \
  231.                                 set _enadev Mic
  232.                             else
  233.                                 alsaucm -c $d set _verb HiFi \
  234.                                 set _enadev Speaker \
  235.                                 set _enadev Headphones \
  236.                                 set _enadev Headset \
  237.                                 set _enadev Mic
  238.                             fi
  239.                         fi
  240.                         ;;
  241.                     *acp5x*)
  242.                         alsaucm -c $d set _verb HiFi \
  243.                         set _enadev Speaker \
  244.                         set _enadev Headphones \
  245.                         set _enadev Headset \
  246.                         set _enadev Mic
  247.                         ;;
  248.                     esac
  249.                 done
  250.             fi
  251.         done
  252.  
  253.         # 3. Store everything into /data/vendor/asound.state
  254.         alsa_ctl store
  255.     fi
  256. }
  257.  
  258. function init_hal_bluetooth()
  259. {
  260.     for r in /sys/class/rfkill/*; do
  261.         type=$(cat $r/type)
  262.         [ "$type" = "wlan" -o "$type" = "bluetooth" ] && echo 1 > $r/state
  263.     done
  264.  
  265.     case "$PRODUCT" in
  266.         T100TAF)
  267.             set_property bluetooth.interface hci1
  268.             ;;
  269.         T10*TA|M80TA|HP*Omni*)
  270.             BTUART_PORT=/dev/ttyS1
  271.             set_property hal.bluetooth.uart.proto bcm
  272.             ;;
  273.         MacBookPro8*)
  274.             rmmod b43
  275.             modprobe b43 btcoex=0
  276.             modprobe btusb
  277.             ;;
  278.         # FIXME
  279.         # Fix MacBook 2013-2015 (Air6/7&Pro11/12) BCM4360 ssb&wl conflict.
  280.         MacBookPro11* | MacBookPro12* | MacBookAir6* | MacBookAir7*)
  281.             rmmod b43
  282.             rmmod ssb
  283.             rmmod bcma
  284.             rmmod wl
  285.             modprobe wl
  286.             modprobe btusb
  287.             ;;
  288.         *)
  289.             for bt in $(toybox lsusb -v | awk ' /Class:.E0/ { print $9 } '); do
  290.                 chown 1002.1002 $bt && chmod 660 $bt
  291.             done
  292.             ;;
  293.     esac
  294.  
  295.     if [ -n "$BTUART_PORT" ]; then
  296.         set_property hal.bluetooth.uart $BTUART_PORT
  297.         chown bluetooth.bluetooth $BTUART_PORT
  298.         start btattach
  299.     fi
  300.  
  301.     if [ "$BTLINUX_HAL" = "1" ]; then
  302.         start btlinux-1.1
  303.     else
  304.         start vendor.bluetooth-1-1
  305.     fi
  306.  
  307.     if [ "$BT_BLE_DISABLE" = "1" ]; then
  308.         set_property bluetooth.core.le.disabled true
  309.         set_property bluetooth.hci.disabled_commands 246
  310.     fi
  311.  
  312.     if [ "$BT_BLE_NO_VENDORCAPS" = "1" ]; then
  313.         set_property bluetooth.core.le.vendor_capabilities.enabled false
  314.         set_property persist.sys.bt.max_vendor_cap 0
  315.     fi
  316. }
  317.  
  318. function init_hal_camera()
  319. {
  320.     case "$UEVENT" in
  321.         *e-tabPro*)
  322.             set_prop_if_empty hal.camera.0 0,270
  323.             set_prop_if_empty hal.camera.2 1,90
  324.             ;;
  325.         *LenovoideapadD330*)
  326.             set_prop_if_empty hal.camera.0 0,90
  327.             set_prop_if_empty hal.camera.2 1,90
  328.             ;;
  329.         *)
  330.             ;;
  331.     esac
  332. }
  333.  
  334. function init_hal_gps()
  335. {
  336.     # TODO
  337.     return
  338. }
  339.  
  340. function set_drm_mode()
  341. {
  342.     case "$PRODUCT" in
  343.         ET1602*)
  344.             drm_mode=1366x768
  345.             ;;
  346.         *)
  347.             [ -n "$video" ] && drm_mode=$video
  348.             ;;
  349.     esac
  350.  
  351.     [ -n "$drm_mode" ] && set_property debug.drm.mode.force $drm_mode
  352. }
  353.  
  354. function init_uvesafb()
  355. {
  356.     UVESA_MODE=${UVESA_MODE:-${video%@*}}
  357.  
  358.     case "$PRODUCT" in
  359.         ET2002*)
  360.             UVESA_MODE=${UVESA_MODE:-1600x900}
  361.             ;;
  362.         *)
  363.             ;;
  364.     esac
  365.  
  366.     modprobe uvesafb mode_option=${UVESA_MODE:-1024x768}-32 ${UVESA_OPTION:-mtrr=3 scroll=redraw} v86d=/system/bin/v86d
  367. }
  368.  
  369. function init_hal_gralloc()
  370. {
  371.     case "$(readlink /sys/class/graphics/fb0/device/driver)" in
  372.         *virtio_gpu|*virtio-pci)
  373.             HWC=${HWC:-drm_minigbm_celadon}
  374.             GRALLOC=${GRALLOC:-minigbm_arcvm}
  375.             #video=${video:-1280x768}
  376.             ;&
  377.         *nouveau)
  378.             GRALLOC=${GRALLOC:-gbm_hack}
  379.             HWC=${HWC:-drm_celadon}
  380.             ;&
  381.         *i915)
  382.             if [ "$(cat /sys/kernel/debug/dri/0/i915_capabilities | grep -e 'gen' -e 'graphics version' | awk '{print $NF}')" -gt 9 ]; then
  383.                 HWC=${HWC:-drm_minigbm_celadon}
  384.                 GRALLOC=${GRALLOC:-minigbm}
  385.             fi
  386.             ;&
  387.         *amdgpu)
  388.             HWC=${HWC:-drm_minigbm_celadon}
  389.             GRALLOC=${GRALLOC:-minigbm}
  390.             ;&
  391.         *radeon|*vmwgfx*)
  392.             if [ "$HWACCEL" != "0" ]; then
  393.                 ${HWC:+set_property ro.hardware.hwcomposer $HWC}
  394.                 set_property ro.hardware.gralloc ${GRALLOC:-gbm}
  395.                 set_drm_mode
  396.             fi
  397.             ;;
  398.         "")
  399.             init_uvesafb
  400.             ;&
  401.         *)
  402.             export HWACCEL=0
  403.             ;;
  404.     esac
  405.  
  406.     if [ "$GRALLOC4_MINIGBM" = "1" ]; then
  407.         set_property debug.ui.default_mapper 4
  408.         set_property debug.ui.default_gralloc 4
  409.         case "$GRALLOC" in
  410.             minigbm)
  411.                 start vendor.graphics.allocator-4-0
  412.             ;;
  413.             minigbm_arcvm)
  414.                 start vendor.graphics.allocator-4-0-arcvm
  415.             ;;
  416.             minigbm_gbm_mesa)
  417.                 start vendor.graphics.allocator-4-0-gbm_mesa
  418.             ;;
  419.             *)
  420.             ;;
  421.         esac
  422.     else
  423.         set_property debug.ui.default_mapper 2
  424.         set_property debug.ui.default_gralloc 2
  425.         start vendor.gralloc-2-0
  426.     fi
  427.  
  428.     [ -n "$DEBUG" ] && set_property debug.egl.trace error
  429. }
  430.  
  431. function init_egl()
  432. {
  433.  
  434.     if [ "$HWACCEL" != "0" ]; then
  435.         if [ "$ANGLE" == "1" ]; then
  436.             set_property ro.hardware.egl angle
  437.         else
  438.             set_property ro.hardware.egl mesa
  439.         fi
  440.     else
  441.         if [ "$ANGLE" == "1" ]; then
  442.             set_property ro.hardware.egl angle
  443.         else
  444.             set_property ro.hardware.egl swiftshader
  445.         fi
  446.         set_property ro.hardware.vulkan pastel
  447.         start vendor.hwcomposer-2-1
  448.     fi
  449.  
  450.     # Set OpenGLES version
  451.     case "$FORCE_GLES" in
  452.         *3.0*)
  453.             set_property ro.opengles.version 196608
  454.             export MESA_GLES_VERSION_OVERRIDE=3.0
  455.         ;;
  456.         *3.1*)
  457.             set_property ro.opengles.version 196609
  458.             export MESA_GLES_VERSION_OVERRIDE=3.1
  459.         ;;
  460.         *3.2*)
  461.             set_property ro.opengles.version 196610
  462.             export MESA_GLES_VERSION_OVERRIDE=3.2
  463.         ;;
  464.         *)
  465.             set_property ro.opengles.version 196608
  466.         ;;
  467.     esac
  468.  
  469.     # Set RenderEngine backend
  470.     if [ -z ${FORCE_RENDERENGINE+x} ]; then
  471.         set_property debug.renderengine.backend threaded
  472.     else
  473.         set_property debug.renderengine.backend $FORCE_RENDERENGINE
  474.     fi
  475.  
  476.     # Set default GPU render
  477.     if [ -z ${GPU_OVERRIDE+x} ]; then
  478.         echo ""
  479.     else
  480.         set_property gralloc.gbm.device /dev/dri/$GPU_OVERRIDE
  481.         set_property vendor.hwc.drm.device /dev/dri/$GPU_OVERRIDE
  482.         set_property hwc.drm.device /dev/dri/$GPU_OVERRIDE
  483.     fi
  484.  
  485. }
  486.  
  487. function init_hal_hwcomposer()
  488. {
  489.     # TODO
  490.     if [ "$HWACCEL" != "0" ]; then
  491.         if [ "$HWC" = "default" ]; then
  492.             if [ "$HWC_IS_DRMFB" = "1" ]; then
  493.                 set_property debug.sf.hwc_service_name drmfb
  494.                 start vendor.hwcomposer-2-1.drmfb
  495.             else
  496.                 set_property debug.sf.hwc_service_name default
  497.                 start vendor.hwcomposer-2-1
  498.             fi
  499.         else
  500.             set_property debug.sf.hwc_service_name default
  501.             start vendor.hwcomposer-2-4
  502.  
  503.             if [[ "$HWC" == "drm_celadon" || "$HWC" == "drm_minigbm_celadon" ]]; then
  504.                 set_property vendor.hwcomposer.planes.enabling $MULTI_PLANE
  505.                 set_property vendor.hwcomposer.planes.num $MULTI_PLANE_NUM
  506.                 set_property vendor.hwcomposer.preferred.mode.limit $HWC_PREFER_MODE
  507.                 set_property vendor.hwcomposer.connector.id $CONNECTOR_ID
  508.                 set_property vendor.hwcomposer.mode.id $MODE_ID
  509.                 set_property vendor.hwcomposer.connector.multi_refresh_rate $MULTI_REFRESH_RATE
  510.             fi
  511.         fi
  512.     fi
  513. }
  514.  
  515. function init_hal_media()
  516. {
  517.     # Check if we want to use codec2
  518.     if [ -z ${CODEC2_LEVEL+x} ]; then
  519.         echo ""
  520.     else
  521.         set_property debug.stagefright.ccodec $CODEC2_LEVEL
  522.     fi
  523.  
  524.     # Disable YUV420 planar on OMX codecs
  525.     if [ "$OMX_NO_YUV420" -ge "1" ]; then
  526.         set_property ro.yuv420.disable true
  527.     else
  528.         set_property ro.yuv420.disable false
  529.     fi
  530.  
  531.     if [ "$BOARD" == "Jupiter" ] && [ "$VENDOR" == "Valve" ]
  532.     then
  533.         FFMPEG_CODEC2_PREFER=${FFMPEG_CODEC2_PREFER:-1}
  534.     fi
  535.  
  536. #FFMPEG Codec Setup
  537. ## Turn on/off FFMPEG OMX by default
  538.     if [ "$FFMPEG_OMX_CODEC" -ge "1" ]; then
  539.         set_property media.sf.omx-plugin libffmpeg_omx.so
  540.         set_property media.sf.extractor-plugin libffmpeg_extractor.so
  541.     else
  542.         set_property media.sf.omx-plugin ""
  543.         set_property media.sf.extractor-plugin ""
  544.     fi
  545.  
  546. ## Enable logging
  547.     if [ "$FFMPEG_CODEC_LOG" -ge "1" ]; then
  548.         set_property debug.ffmpeg.loglevel verbose
  549.     fi 
  550. ## Disable HWAccel (currently only VA-API) and use software rendering
  551.     if [ "$FFMPEG_HWACCEL_DISABLE" -ge "1" ]; then
  552.         set_property media.sf.hwaccel 0
  553.     else
  554.         set_property media.sf.hwaccel 1
  555.     fi
  556. ## Put c2.ffmpeg to the highest rank amongst the media codecs
  557.     if [ "$FFMPEG_CODEC2_PREFER" -ge "1" ]; then
  558.         set_property debug.ffmpeg-codec2.rank 0
  559.     else
  560.         set_property debug.ffmpeg-codec2.rank 4294967295
  561.     fi
  562. ## FFMPEG deinterlace, we will put both software mode and VA-API one here
  563.     if [ -z "${FFMPEG_CODEC2_DEINTERLACE+x}" ]; then
  564.         echo ""
  565.     else
  566.         set_property debug.ffmpeg-codec2.deinterlace $FFMPEG_CODEC2_DEINTERLACE
  567.     fi
  568.     if [ -z "${FFMPEG_CODEC2_DEINTERLACE_VAAPI+x}" ]; then
  569.         echo ""
  570.     else
  571.         set_property debug.ffmpeg-codec2.deinterlace.vaapi $FFMPEG_CODEC2_DEINTERLACE_VAAPI
  572.     fi
  573. ## Handle DRM prime on ffmpeg codecs, we will disable by default due to
  574. ## the fact that it doesn't work with gbm_gralloc yet
  575.     if [ "$FFMPEG_CODEC2_DRM" -ge "1" ]; then
  576.         set_property debug.ffmpeg-codec2.hwaccel.drm 1
  577.     else
  578.         set_property debug.ffmpeg-codec2.hwaccel.drm 0
  579.     fi
  580.  
  581. }
  582.  
  583. function init_hal_vulkan()
  584. {
  585.     case "$(readlink /sys/class/graphics/fb0/device/driver)" in
  586.         *i915)
  587.             if [ "$(cat /sys/kernel/debug/dri/0/i915_capabilities | grep -e 'gen' -e 'graphics version' | awk '{print $NF}')" -lt 9 ]; then
  588.                 set_property ro.hardware.vulkan intel_hasvk
  589.             else
  590.                 set_property ro.hardware.vulkan intel
  591.             fi
  592.             ;;
  593.         *amdgpu)
  594.             set_property ro.hardware.vulkan radeon
  595.             ;;
  596.         *virtio_gpu|*virtio-pci)
  597.             set_property ro.hardware.vulkan virtio
  598.             ;;
  599.         *)
  600.             set_property ro.hardware.vulkan pastel
  601.             ;;
  602.     esac
  603. }
  604.  
  605. function init_hal_lights()
  606. {
  607.     chown 1000.1000 /sys/class/backlight/*/brightness
  608. }
  609.  
  610. function init_hal_power()
  611. {
  612.     for p in /sys/class/rtc/*; do
  613.         echo disabled > $p/device/power/wakeup
  614.     done
  615.  
  616.     # TODO
  617.     case "$PRODUCT" in
  618.         HP*Omni*|OEMB|Standard*PC*|Surface*3|T10*TA|VMware*)
  619.             SLEEP_STATE=none
  620.             ;;
  621.         e-tab*Pro)
  622.             SLEEP_STATE=force
  623.             ;;
  624.         *)
  625.             ;;
  626.     esac
  627.  
  628.     set_property sleep.state ${SLEEP_STATE}
  629. }
  630.  
  631. function init_hal_thermal()
  632. {
  633.     #thermal-daemon test, pulled from Project Celadon
  634.     case "$(cat /sys/class/dmi/id/chassis_vendor | head -1)" in
  635.     QEMU)
  636.         setprop vendor.thermal.enable 0
  637.         ;;
  638.     *)
  639.         setprop vendor.thermal.enable 1
  640.         ;;
  641.     esac
  642. }
  643.  
  644. function init_hal_sensors()
  645. {
  646.     if [ "$SENSORS_FORCE_KBDSENSOR" == "1" ]; then
  647.         # Option to force kbd sensor
  648.         hal_sensors=kbd
  649.         has_sensors=true
  650.     else
  651.         # if we have sensor module for our hardware, use it
  652.         ro_hardware=$(getprop ro.hardware)
  653.         [ -f /system/lib/hw/sensors.${ro_hardware}.so ] && return 0
  654.  
  655.         local hal_sensors=kbd
  656.         local has_sensors=true
  657.         case "$UEVENT" in
  658.             *MS-N0E1*)
  659.                 set_property ro.ignore_atkbd 1
  660.                 set_property poweroff.doubleclick 0
  661.                 setkeycodes 0xa5 125
  662.                 setkeycodes 0xa7 1
  663.                 setkeycodes 0xe3 142
  664.                 ;;
  665.             *Aspire1*25*)
  666.                 modprobe lis3lv02d_i2c
  667.                 echo -n "enabled" > /sys/class/thermal/thermal_zone0/mode
  668.                 ;;
  669.             *Aspire*SW5-012*|*Venue*8*Pro*3845*|*ST70416-6*|*Akoya*P2213T*)
  670.                 set_property ro.iio.accel.order 102
  671.                 ;;
  672.             *LenovoideapadD330*)
  673.                 set_property ro.iio.accel.order 102
  674.                 set_property ro.ignore_atkbd 1
  675.                 ;&
  676.             *LINX1010B*)
  677.                 set_property ro.iio.accel.x.opt_scale -1
  678.                 set_property ro.iio.accel.z.opt_scale -1
  679.                 ;;
  680.             *i7Stylus*)
  681.                 set_property ro.iio.accel.x.opt_scale -1
  682.                 ;;
  683.             *LenovoMIIX320*|*MIIX510*|*MIIX300-10IBY*|*ONDATablet*| \
  684.             *TECLAST*X4*|*SF133AYR110*|*SolTIVW*)
  685.                 set_property ro.iio.accel.order 102
  686.                 set_property ro.iio.accel.x.opt_scale -1
  687.                 set_property ro.iio.accel.y.opt_scale -1
  688.                 ;;
  689.             *Hi10*plus*|*T*0*TA*|*M80TA*|*TECLAST*X16*)
  690.                 set_property ro.iio.accel.y.opt_scale -1
  691.                 ;;
  692.             *TAIFAElimuTab*)
  693.                 set_property ro.ignore_atkbd 1
  694.                 set_property ro.iio.accel.quirks no-trig
  695.                 set_property ro.iio.accel.order 102
  696.                 ;;
  697.             *SwitchSA5-271*|*SwitchSA5-271P*)
  698.                 set_property ro.ignore_atkbd 1
  699.                 has_sensors=true
  700.                 hal_sensors=iio
  701.                 ;&
  702.             *)
  703.                 has_sensors=false
  704.                 ;;
  705.         esac
  706.  
  707.             # has iio sensor-hub?
  708.             if [ -n "`ls /sys/bus/iio/devices/iio:device* 2> /dev/null`" ]; then
  709.                 toybox chown -R 1000.1000 /sys/bus/iio/devices/iio:device*/
  710.                 [ -n "`ls /sys/bus/iio/devices/iio:device*/in_accel_x_raw 2> /dev/null`" ] && has_sensors=true
  711.                 hal_sensors=iio
  712.             elif [ "$hal_sensors" != "kbd" ] | [ hal_sensors=iio ]; then
  713.                 has_sensors=true
  714.             fi
  715.  
  716.             # is steam deck?
  717.             if [ "$BOARD" == "Jupiter" ] && [ "$VENDOR" == "Valve" ]
  718.             then
  719.                 set_property poweroff.disable_virtual_power_button 1
  720.                 hal_sensors=jupiter
  721.                 has_sensors=true
  722.             fi
  723.     fi
  724.  
  725.     set_property ro.iio.accel.quirks "no-trig,no-event"
  726.     set_property ro.iio.anglvel.quirks "no-trig,no-event"
  727.     set_property ro.iio.magn.quirks "no-trig,no-event"
  728.     set_property ro.hardware.sensors $hal_sensors
  729.     set_property config.override_forced_orient ${HAS_SENSORS:-$has_sensors}
  730. }
  731.  
  732. function init_hal_surface()
  733. {
  734.     case "$UEVENT" in
  735.         *Surface*Pro*[4-9]*|*Surface*Book*|*Surface*Laptop*[1~4]*|*Surface*Laptop*Studio*)
  736.             start iptsd_runner
  737.             ;;
  738.     esac
  739. }
  740.  
  741. function create_pointercal()
  742. {
  743.     if [ ! -e /data/misc/tscal/pointercal ]; then
  744.         mkdir -p /data/misc/tscal
  745.         touch /data/misc/tscal/pointercal
  746.         chown 1000.1000 /data/misc/tscal /data/misc/tscal/*
  747.         chmod 775 /data/misc/tscal
  748.         chmod 664 /data/misc/tscal/pointercal
  749.     fi
  750.  
  751.     # setprop to tell the system to turn on TSCalibrartion
  752.     set_property ro.tscal.enable true
  753. }
  754.  
  755. function init_tscal()
  756. {
  757.     if [ "$FORCE_TSCAL" -ge "1" ]; then
  758.         create_pointercal
  759.     else
  760.         case "$UEVENT" in
  761.             *T91*|*T101*|*ET2002*|*74499FU*|*945GSE-ITE8712*|*CF-19[CDYFGKLP]*|*TECLAST:rntPAD*)
  762.                 create_pointercal
  763.                 return
  764.                 ;;
  765.             *)
  766.                 ;;
  767.         esac
  768.  
  769.         for usbts in $(lsusb | awk '{ print $6 }'); do
  770.             case "$usbts" in
  771.                 0596:0001|0eef:0001|14e1:6000|14e1:5000)
  772.                     create_pointercal
  773.                     return
  774.                     ;;
  775.                 *)
  776.                     ;;
  777.             esac
  778.         done
  779.     fi
  780. }
  781.  
  782. function init_ril()
  783. {
  784.     case "$UEVENT" in
  785.         *TEGA*|*2010:svnIntel:*|*Lucid-MWE*)
  786.             set_property rild.libpath /system/lib/libhuaweigeneric-ril.so
  787.             set_property rild.libargs "-d /dev/ttyUSB2 -v /dev/ttyUSB1"
  788.             set_property ro.radio.noril no
  789.             ;;
  790.         *)
  791.             set_property ro.radio.noril yes
  792.             ;;
  793.     esac
  794. }
  795.  
  796. function init_cpu_governor()
  797. {
  798.     governor=$(getprop cpu.governor)
  799.  
  800.     [ $governor ] && {
  801.         for cpu in $(ls -d /sys/devices/system/cpu/cpu?); do
  802.             echo $governor > $cpu/cpufreq/scaling_governor || return 1
  803.         done
  804.     }
  805. }
  806.  
  807. function set_lowmem()
  808. {
  809.     # 512 MB size in kB : https://source.android.com/devices/tech/perf/low-ram
  810.     SIZE_512MB=2048000
  811.  
  812.     mem_size=`cat /proc/meminfo | grep MemTotal | tr -s ' ' | cut -d ' ' -f 2`
  813.  
  814.     if [ "$mem_size" -le "$SIZE_512MB" ]
  815.     then
  816.         setprop ro.config.low_ram true
  817.     else
  818.         setprop ro.config.low_ram false
  819.     fi
  820. }
  821.  
  822. function set_custom_ota()
  823. {
  824.     for c in `cat /proc/cmdline`; do
  825.         case $c in
  826.             *=*)
  827.                 eval $c
  828.                 if [ -z "$1" ]; then
  829.                     case $c in
  830.                         # Set TimeZone
  831.                         SET_CUSTOM_OTA_URI=*)
  832.                             setprop bliss.updater.uri "$SET_CUSTOM_OTA_URI"
  833.                             ;;
  834.                     esac
  835.                 fi
  836.                 ;;
  837.         esac
  838.     done
  839.    
  840. }
  841.  
  842. function init_loop_links()
  843. {
  844.     mkdir -p /dev/block/by-name
  845.     for part in kernel initrd system; do
  846.         for suffix in _a _b; do
  847.             loop_device=$(losetup -a | grep "$part$suffix" | cut -d ":" -f1)
  848.             if [ ! -z "$loop_device" ]; then
  849.                 ln -s $loop_device /dev/block/by-name/$part$suffix
  850.             fi
  851.         done
  852.     done
  853.     loop_device=$(losetup -a | grep misc | cut -d ":" -f1)
  854.     ln -s $loop_device /dev/block/by-name/misc
  855.  
  856.     ln -s /dev/block/by-name/kernel_a /dev/block/by-name/boot_a
  857.     ln -s /dev/block/by-name/kernel_b /dev/block/by-name/boot_b
  858. }
  859.  
  860. function init_prepare_ota()
  861. {
  862.     # If there's slot set, turn on bootctrl
  863.     # If not, disable the OTA app (in bootcomplete)
  864.     if [ "$(getprop ro.boot.slot_suffix)" ]; then
  865.         start vendor.boot-hal-1-1
  866.     fi
  867. }
  868.  
  869. function set_custom_timezone()
  870. {
  871.     for c in `cat /proc/cmdline`; do
  872.         case $c in
  873.             *=*)
  874.                 eval $c
  875.                 if [ -z "$1" ]; then
  876.                     case $c in
  877.                         # Set TimeZone
  878.                         SET_TZ_LOCATION=*)
  879.                             settings put global time_zone "$SET_TZ_LOCATION"
  880.                             setprop persist.sys.timezone "$SET_TZ_LOCATION"
  881.                             ;;
  882.                     esac
  883.                 fi
  884.                 ;;
  885.         esac
  886.     done
  887.    
  888. }
  889.  
  890. function do_init()
  891. {
  892.     init_misc
  893.     set_lowmem
  894.     set_custom_timezone
  895.     init_hal_audio
  896.     set_custom_ota
  897.     init_hal_brcm_wifi
  898.     init_hal_bluetooth
  899.     init_hal_camera
  900.     init_hal_gps
  901.     init_hal_gralloc
  902.     init_hal_hwcomposer
  903.     init_hal_media
  904.     init_hal_vulkan
  905.     init_hal_lights
  906.     init_hal_power
  907.     init_hal_thermal
  908.     init_hal_sensors
  909.     init_hal_surface
  910.     init_tscal
  911.     init_ril
  912.     init_loop_links
  913.     init_prepare_ota
  914.     post_init
  915. }
  916.  
  917. function do_netconsole()
  918. {
  919.     modprobe netconsole netconsole="@/,@$(getprop dhcp.eth0.gateway)/"
  920. }
  921.  
  922. function do_bootcomplete()
  923. {
  924.     hciconfig | grep -q hci || pm disable com.android.bluetooth
  925.  
  926.     init_cpu_governor
  927.  
  928.     [ -z "$(getprop persist.sys.root_access)" ] && setprop persist.sys.root_access 3
  929.  
  930.     lsmod | grep -Ehq "brcmfmac|rtl8723be" && setprop wlan.no-unload-driver 1
  931.  
  932.     case "$PRODUCT" in
  933.         Surface*Go)
  934.             echo on > /sys/devices/pci0000:00/0000:00:15.1/i2c_designware.1/power/control
  935.             ;;
  936.         VMware*)
  937.             pm disable com.android.bluetooth
  938.             ;;
  939.         X80*Power)
  940.             set_property power.nonboot-cpu-off 1
  941.             ;;
  942.         *)
  943.             ;;
  944.     esac
  945.  
  946.     # initialize audio in bootcomplete
  947.     init_hal_audio_bootcomplete
  948.  
  949.     # Turn off TSCalibration if property isn't set
  950.     if [ "$(getprop ro.tscal.enable)" == "true" ]; then
  951.         pm enable org.zeroxlab.util.tscal
  952.     else
  953.         pm disable org.zeroxlab.util.tscal
  954.     fi
  955.  
  956.     # check wifi setup
  957.     FILE_CHECK=/data/misc/wifi/wpa_supplicant.conf
  958.  
  959.     if [ ! -f "$FILE_CHECK" ]; then
  960.         cp -a /system/etc/wifi/wpa_supplicant.conf $FILE_CHECK
  961.             chown 1010.1010 $FILE_CHECK
  962.             chmod 660 $FILE_CHECK
  963.     fi
  964.  
  965.     POST_INST=/data/vendor/post_inst_complete
  966.     USER_APPS=/system/etc/user_app/*
  967.     BUILD_DATETIME=$(getprop ro.build.date.utc)
  968.     POST_INST_NUM=$(cat $POST_INST)
  969.  
  970.     if [ ! "$BUILD_DATETIME" == "$POST_INST_NUM" ]; then
  971.         for apk in $USER_APPS
  972.         do     
  973.             pm install $apk
  974.         done
  975.         rm "$POST_INST"
  976.         touch "$POST_INST"
  977.         echo $BUILD_DATETIME > "$POST_INST"
  978.     fi
  979.  
  980.     #Auto activate XtMapper
  981.     #nohup env LD_LIBRARY_PATH=$(echo /data/app/*/xtr.keymapper*/lib/x86_64) \
  982.     #CLASSPATH=$(echo /data/app/*/xtr.keymapper*/base.apk) /system/bin/app_process \
  983.     #/system/bin xtr.keymapper.server.InputService > /dev/null 2>&1 &
  984.  
  985.     if [ ! "$(getprop ro.boot.slot_suffix)" ]; then
  986.         pm disable org.lineageos.updater
  987.     fi
  988.  
  989.     post_bootcomplete
  990. }
  991.  
  992. PATH=/sbin:/system/bin:/system/xbin
  993.  
  994. DMIPATH=/sys/class/dmi/id
  995. BOARD=$(cat $DMIPATH/board_name)
  996. PRODUCT=$(cat $DMIPATH/product_name)
  997. VENDOR=$(cat $DMIPATH/sys_vendor)
  998. UEVENT=$(cat $DMIPATH/uevent)
  999.  
  1000. # import cmdline variables
  1001. for c in `cat /proc/cmdline`; do
  1002.     case $c in
  1003.         BOOT_IMAGE=*|iso-scan/*|*.*=*)
  1004.             ;;
  1005.         nomodeset)
  1006.             HWACCEL=0
  1007.             ;;
  1008.         *=*)
  1009.             eval $c
  1010.             if [ -z "$1" ]; then
  1011.                 case $c in
  1012.                     DEBUG=*)
  1013.                         [ -n "$DEBUG" ] && set_property debug.logcat 1
  1014.                         [ "$DEBUG" = "0" ] || SETUPWIZARD=${SETUPWIZARD:-0}
  1015.                         ;;
  1016.                     DPI=*)
  1017.                         set_property ro.sf.lcd_density "$DPI"
  1018.                         ;;
  1019.                     SET_SF_ROTATION=*)
  1020.                         set_property ro.sf.hwrotation "$SET_SF_ROTATION"
  1021.                         ;;
  1022.                     SET_OVERRIDE_FORCED_ORIENT=*)
  1023.                         set_property config.override_forced_orient "$SET_OVERRIDE_FORCED_ORIENT"
  1024.                         ;;
  1025.                     SET_SYS_APP_ROTATION=*)
  1026.                         # property: persist.sys.app.rotation has three cases:
  1027.                         # 1.force_land: always show with landscape, if a portrait apk, system will scale up it
  1028.                         # 2.middle_port: if a portrait apk, will show in the middle of the screen, left and right will show black
  1029.                         # 3.original: original orientation, if a portrait apk, will rotate 270 degree
  1030.                         set_property persist.sys.app.rotation "$SET_SYS_APP_ROTATION"
  1031.                         ;;
  1032.                     # Battery Stats
  1033.                     SET_FAKE_BATTERY_LEVEL=*)
  1034.                         # Let us fake the total battery percentage
  1035.                         # Range: 0-100
  1036.                         dumpsys battery set level "$SET_FAKE_BATTERY_LEVEL"
  1037.                         ;;
  1038.                     SET_FAKE_CHARGING_STATUS=*)
  1039.                         # Allow forcing battery charging status
  1040.                         # Off: 0  On: 1
  1041.                         dumpsys battery set ac "$SET_FAKE_CHARGING_STATUS"
  1042.                         ;;
  1043.                     FORCE_DISABLE_NAVIGATION=*)
  1044.                         # Force disable navigation bar
  1045.                         # options: true, false
  1046.                         set_property persist.bliss.disable_navigation_bar "$FORCE_DISABLE_NAVIGATION"
  1047.                         ;;
  1048.                     FORCE_DISABLE_NAV_HANDLE=*)
  1049.                         # Force disable navigation handle
  1050.                         # options: true, false
  1051.                         set_property persist.bliss.disable_navigation_handle "$FORCE_DISABLE_NAV_HANDLE"
  1052.                         ;;
  1053.                     FORCE_DISABLE_NAV_TASKBAR=*)
  1054.                         # Force disable navigation taskbar
  1055.                         # options: true, false
  1056.                         set_property persist.bliss.disable_taskbar "$FORCE_DISABLE_NAV_TASKBAR"
  1057.                         ;;
  1058.                     FORCE_DISABLE_STATUSBAR=*)
  1059.                         # Force disable statusbar
  1060.                         # options: true, false
  1061.                         set_property persist.bliss.disable_statusbar "$FORCE_DISABLE_STATUSBAR"
  1062.                         ;;
  1063.                     FORCE_DISABLE_RECENTS=*)
  1064.                         # Force disable recents
  1065.                         # options: true, false
  1066.                         set_property persist.bliss.disable_recents "$FORCE_DISABLE_RECENTS"
  1067.                         ;;
  1068.                 esac
  1069.                 [ "$SETUPWIZARD" = "0" ] && set_property ro.setupwizard.mode DISABLED
  1070.             fi
  1071.             ;;
  1072.     esac
  1073. done
  1074.  
  1075. [ -n "$DEBUG" ] && set -x || exec &> /dev/null
  1076.  
  1077. # import the vendor specific script
  1078. hw_sh=/vendor/etc/init.sh
  1079. [ -e $hw_sh ] && source $hw_sh
  1080.  
  1081. case "$1" in
  1082.     eglsetup)
  1083.         init_egl
  1084.         ;;
  1085.     netconsole)
  1086.         [ -n "$DEBUG" ] && do_netconsole
  1087.         ;;
  1088.     bootcomplete)
  1089.         do_bootcomplete
  1090.         ;;
  1091.     init|"")
  1092.         do_init
  1093.         ;;
  1094. esac
  1095.  
  1096. return 0
Advertisement
Add Comment
Please, Sign In to add comment