1#!/vendor/bin/sh
2
3#############################################################
4### init.insmod.cfg format:                               ###
5### ----------------------------------------------------- ###
6### [insmod|setprop|enable/moprobe|wait] [path|prop name] ###
7### ...                                                   ###
8#############################################################
9
10# imitates wait_for_file() in init
11wait_for_file()
12{
13    filename="${1}"
14    timeout="${2:-5}"
15
16    expiry=$(($(date "+%s")+timeout))
17    while [[ ! -e "${filename}" ]] && [[ "$(date "+%s")" -le "${expiry}" ]]
18    do
19        sleep 0.01
20    done
21}
22
23if [ $# -eq 1 ]; then
24  cfg_file=$1
25else
26  exit 1
27fi
28
29
30if [ -f $cfg_file ]; then
31  while IFS="|" read -r action arg
32  do
33    case $action in
34      "insmod") insmod $arg ;;
35      "setprop") setprop $arg 1 ;;
36      "enable") echo 1 > $arg ;;
37      "modprobe")
38        case ${arg} in
39          "-b *" | "-b")
40            arg="-b $(cat /vendor/lib/modules/modules.load)" ;;
41          "*" | "")
42            arg="$(cat /vendor/lib/modules/modules.load)" ;;
43        esac
44        modprobe -a -d /vendor/lib/modules $arg ;;
45      "wait") wait_for_file $arg ;;
46    esac
47  done < $cfg_file
48fi
49
50# set property even if there is no insmod config
51# as property value "1" is expected in early-boot trigger
52setprop vendor.all.modules.ready 1
53setprop vendor.all.devices.ready 1
54