import /vendor/etc/init/hw/init.${ro.hardware}.usb.rc
import /vendor/etc/init/hw/init.${ro.hardware}.${ro.boot.soc_type}.rc
import /vendor/etc/init/hw/init.${ro.hardware}.${ro.boot.storage_type}.rc

on early-init
    # mount the debugfs
    mount debugfs none /sys/kernel/debug/ mode=0755

on early-init
    start early_init_sh

on init
    start watchdogd

    # Support legacy paths
    symlink /sdcard /mnt/sdcard
    symlink /sdcard /storage/sdcard0

    # setup the global environment
    export CORE_REGISTER_FILE /vendor/etc/core_register
    export COMPONENT_REGISTER_FILE /vendor/etc/component_register
    export CONTENTPIPE_REGISTER_FILE /vendor/etc/contentpipe_register

    # disable cursor blink for fbcon, if no splash screen support
    write /sys/class/graphics/fbcon/cursor_blink 0

    # deattch the fbcon as hdmi hotplug conflict with fbcon
    write /sys/class/vtconsole/vtcon1/bind 0

    # set default schedTune value for foreground/top-app (only affects EAS)
    write /dev/stune/foreground/schedtune.boost 10
    write /dev/stune/foreground/schedtune.prefer_idle 1
    write /dev/stune/top-app/schedtune.boost 40
    write /dev/stune/top-app/schedtune.prefer_idle 1
    write /dev/stune/rt/schedtune.boost 50
    write /dev/stune/rt/schedtune.prefer_idle 1

   # force USB2514 autosuspend
    write /sys/devices/platform/usb@38200000/38200000.dwc3/xhci-hcd.0.auto/usb1/1-1/1-1.5/power/control auto

on late-fs
    # Start keymaster service
    start vendor.keymaster-3-0-${ro.boot.keystore}

on early-boot
    # Config lowmemorykiller options
    setprop ro.lmk.use_minfree_levels true

    # Set the host name which used in console
    export HOSTNAME smarc_mx8mq

    # Set permission for IIM node
    symlink /dev/mxs_viim /dev/mxc_mem

    # Enable Tethering in the Settings
    setprop ro.tether.denied false

    setprop sys.hwc.disable     1
    setprop vendor.2d.composition 0
    setprop hwc.stretch.filter  1

    # fsl omx graphic manager media framework property
    setprop rw.VIDEO_RENDER_NAME video_render.surface
    setprop media.fsl_codec.flag 7

    #Define the config for dual camera
    #For landscape mode, orient is 0
    #For portrait mode, orient is 90
    #the android before honycomb are all in portrait mode
    setprop camera.disable_zsl_mode 1
    setprop back_camera_name mx6s-csi
    setprop back_camera_orient 0
    setprop front_camera_name uvc
    setprop front_camera_orient 0

   # Tweak the mmc device read ahead buffer size
    write /sys/block/mmcblk0/queue/read_ahead_kb 2048
    write /sys/block/mmcblk1/queue/read_ahead_kb 2048

    # Set period_us for usb audio
    setprop ro.audio.usb.period_us 20000

    # Wifi firmware reload path
    chown wifi wifi /sys/module/brcmfmac/parameters/alternative_fw_path

    # Prepare for wifi
    setprop wifi.interface wlan0

    setprop persist.service.bdroid.bdaddr 22:22:67:C6:69:73

    # Prepare for bluetooth
    chmod 665 /sys/class/rfkill/rfkill0/state
    chown bluetooth bluetooth /sys/class/rfkill/rfkill0/state
    write /sys/class/rfkill/rfkill0/state 0

    setprop qcom.bluetooth.soc rome_uart
    setprop vendor.wc_transport.start_hci false

    # Prepare for RIL
    setprop ro.ril.wake_lock_timeout 300

    # Set the density to 213 tvdpi to match CDD.
    setprop ro.sf.lcd_density 213

    # Disable surfaceflinger back pressure propagate
    setprop debug.sf.disable_backpressure 1

    # Set tracefs permission to 755
    chmod 0755 /sys/kernel/debug/tracing

    # Default backlight device
    setprop hw.backlight.dev "backlight"
    # Chmod/chown FSL specific sys entry
    chown system system /sys/class/backlight/backlight/brightness
    chmod 0660 /sys/class/backlight/backlight/brightness

    # Set light sensor sysfs path and light sensor threshold lux value
    setprop ro.hardware.lightsensor "/sys/class/i2c-dev/i2c-0/device/0-0044/"
    setprop ro.lightsensor.threshold  20

    # Dectect DSF streams when scanning media
    setprop ro.FSL_DSF_PARSER 1

    # Allow DSD file(duration larger than 10s) can play
    setprop audio.offload.min.duration.secs 10

    # Enlarge limition of audio buffer allocation
    setprop ro.af.client_heap_size_kbyte 32768

    # enlarge media max memory size to 3G.
    setprop ro.media.maxmem 3221225471

on boot
    start audioserver
    start mediadrm
    start media
    start drm

service wpa_supplicant /vendor/bin/hw/wpa_supplicant \
    -O/data/vendor/wifi/wpa/sockets -puse_p2p_group_interface=1 \
    -g@android:wpa_wlan0
    interface android.hardware.wifi.supplicant@1.0::ISupplicant default
    interface android.hardware.wifi.supplicant@1.1::ISupplicant default
    class main
    socket wpa_wlan0 dgram 660 wifi wifi
    disabled
    oneshot

service qca_wpa_supplicant /vendor/bin/hw/qca_wpa_supplicant \
    -O/data/vendor/wifi/wpa/sockets -puse_p2p_group_interface=1 \
    -g@android:wpa_wlan0
    interface android.hardware.wifi.supplicant@1.0::ISupplicant default
    interface android.hardware.wifi.supplicant@1.1::ISupplicant default
    class main
    socket wpa_wlan0 dgram 660 wifi wifi
    disabled
    oneshot

service bcm_wpa_supplicant /vendor/bin/hw/bcm_wpa_supplicant \
    -O/data/vendor/wifi/wpa/sockets -puse_p2p_group_interface=1 \
    -g@android:wpa_wlan0
    interface android.hardware.wifi.supplicant@1.0::ISupplicant default
    interface android.hardware.wifi.supplicant@1.1::ISupplicant default
    class main
    socket wpa_wlan0 dgram 660 wifi wifi
    disabled
    oneshot


service sensor_fusion /vendor/bin/fsl_sensor_fusion
    class late_start
    seclabel u:r:sensors:s0
    user system
    group input
    oneshot

# Set watchdog timer to 30 seconds and pet it every 10 seconds to get a 20 second margin
service watchdogd /sbin/watchdogd 10 20
    class core
    seclabel u:r:watchdogd:s0

service dhcpcd_wlan0 /system/bin/dhcpcd -aABDKL
    class main
    disabled
    oneshot

service dhcpcd_p2p /system/bin/dhcpcd -aABKL
    class main
    disabled
    oneshot

service dhcpcd_eth0 /system/bin/dhcpcd -ABKL eth0
    class main
    disabled
    oneshot

service dhcpcd_bt-pan /system/bin/dhcpcd -ABKL
    class main
    disabled
    oneshot

service iprenew_wlan0 /system/bin/dhcpcd -n
    class main
    disabled
    oneshot

service iprenew_p2p /system/bin/dhcpcd -n
    class main
    disabled
    oneshot

service iprenew_eth0 /system/bin/dhcpcd -n eth0
    class main
    disabled
    oneshot

service iprenew_bt-pan /system/bin/dhcpcd -n
    class main
    disabled
    oneshot

# bugreport is triggered by holding down volume down, volume up and power
service bugreport /system/bin/dumpstate -d -p -B -z \
        -o /data/user_de/0/com.android.shell/files/bugreports/bugreport
    class main
    disabled
    oneshot
    keycodes 114 115 116

on property:ro.boot.wifivendor=qca
    setprop wifi.concurrent.interface p2p0
    start vendor.wifi_hal_legacy_qca

on property:ro.boot.wifivendor=bcm
    setprop wifi.direct.interface p2p-dev-wlan0
    start vendor.wifi_hal_legacy_bcm

on property:vendor.wc_transport.start_hci=true
    start start_hci_filter

on property:vendor.wc_transport.start_hci=false
    stop start_hci_filter

service start_hci_filter /vendor/bin/wcnss_filter
    class late_start
    user bluetooth
    group bluetooth diag
    disabled

on property:vendor.wc_transport.start_root=true
    start hci_filter_root

on property:vendor.wc_transport.start_root=false
    stop hci_filter_root

service hci_filter_root /vendor/bin/wcnss_filter
    class late_start
    user bluetooth
    group bluetooth diag system
    disabled

on fs
# mount ext4 partitions
    mount_all /vendor/etc/fstab.freescale

    # Adjust parameters for dm-verity device
    write /sys/block/dm-0/queue/read_ahead_kb 4096

    # Update dm-verity state and set partition.*.verified properties
    verity_update_state

on verity-logging
    exec u:r:slideshow:s0 -- /sbin/slideshow warning/verity_red_1 warning/verity_red_2

on post-fs
    # Set netd memlock rlimit to 8MB
    setrlimit 8 8388608 8388608

    # Turn on swap
    swapon_all /vendor/etc/fstab.freescale

    # Swap in only 1 page at a time
    write /proc/sys/vm/page-cluster 0

    # This may have been created by the recovery system with the wrong context.
    restorecon /cache/recovery

on post-fs-data
    setprop vold.post_fs_data_done 1

    # tmp dir for opencl Compiler
    setprop TMPDIR /data/vendor/.opencl-cache
    mkdir /data/vendor/.opencl-cache 0771 camera camera

on zygote-start
    # Create the directories used by the Wireless subsystem
    mkdir /data/misc/wifi 0770 wifi wifi
    mkdir /data/misc/wifi/wpa_supplicant 0770 wifi wifi
    mkdir /data/vendor/wifi 0771 wifi wifi
    mkdir /data/vendor/wifi/wpa 0770 wifi wifi
    mkdir /data/vendor/wifi/wpa/sockets 0770 wifi wifi
    mkdir /data/misc/dhcp 0770 dhcp dhcp
    chown dhcp dhcp /data/misc/dhcp

service early_init_sh /vendor/bin/init.insmod.sh /vendor/etc/early.init.cfg sys.all.early_init.ready
    class main
    user root
    group root system
    disabled
    oneshot
