• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/vendor/bin/sh
2
3#############################################################
4### init.insmod.cfg format:                               ###
5### ----------------------------------------------------- ###
6### [insmod|setprop|enable/moprobe|wait] [path|prop name] ###
7### ...                                                   ###
8#############################################################
9
10modules_dir=
11system_modules_dir=
12vendor_modules_dir=
13
14
15pagesize=$(getconf PAGESIZE)
16# bootoption=$(getprop ro.product.build.16k_page.enabled)
17# We do not need to check ro.product.build.16k_page.enabled , because this
18# version of insmod.sh will only be used if PRODUCT_16K_DEVELOPER_OPTION
19# is set to true
20
21if [ "$pagesize" != "4096" ] ; then
22    echo "Device has page size $pagesize , skip loading modules from vendor_dlkm/system_dlkm because all modules are stored on vendor_boot"
23    setprop vendor.common.modules.ready 1
24    setprop vendor.device.modules.ready 1
25    setprop vendor.all.modules.ready 1
26    setprop vendor.all.devices.ready 1
27    return 0
28fi
29
30
31for dir in system vendor; do
32  for f in /${dir}/lib/modules/*/modules.dep /${dir}/lib/modules/modules.dep; do
33    if [[ -f "$f" ]]; then
34      if [[ "${dir}" == "system" ]]; then
35        system_modules_dir="$(dirname "$f")"
36      else
37        vendor_modules_dir="$(dirname "$f")"
38        modules_dir=${vendor_modules_dir}
39      fi
40      break
41    fi
42  done
43done
44
45if [[ -z "${system_modules_dir}" ]]; then
46  echo "Unable to locate system kernel modules directory" 2>&1
47fi
48
49if [[ -z "${vendor_modules_dir}" ]]; then
50  echo "Unable to locate vendor kernel modules directory" 2>&1
51  exit 1
52fi
53
54# imitates wait_for_file() in init
55wait_for_file()
56{
57    filename="${1}"
58    timeout="${2:-5}"
59
60    expiry=$(($(date "+%s")+timeout))
61    while [[ ! -e "${filename}" ]] && [[ "$(date "+%s")" -le "${expiry}" ]]
62    do
63        sleep 0.01
64    done
65}
66
67if [ $# -eq 1 ]; then
68  cfg_file=$1
69else
70  # Set property even if there is no insmod config
71  # to unblock early-boot trigger
72  setprop vendor.common.modules.ready 1
73  setprop vendor.device.modules.ready 1
74  setprop vendor.all.modules.ready 1
75  setprop vendor.all.devices.ready 1
76  exit 1
77fi
78
79if [ -f $cfg_file ]; then
80  while IFS="|" read -r action arg
81  do
82    case $action in
83      "insmod") insmod $arg ;;
84      "setprop") setprop $arg 1 ;;
85      "enable") echo 1 > $arg ;;
86      "condinsmod")
87        prop=$(echo $arg | cut -d '|' -f 1)
88        module1=$(echo $arg | cut -d '|' -f 2)
89        module2=$(echo $arg | cut -d '|' -f 3)
90        value=$(getprop $prop)
91        if [[ ${value} == "true" ]]; then
92          insmod ${vendor_modules_dir}/${module1}
93        else
94          insmod ${vendor_modules_dir}/${module2}
95        fi
96        ;;
97      "modprobe")
98        case ${arg} in
99          "system -b *" | "system -b")
100            modules_dir=${system_modules_dir}
101            arg="-b --all=${system_modules_dir}/modules.load" ;;
102          "system *" | "system")
103            modules_dir=${system_modules_dir}
104            arg="--all=${system_modules_dir}/modules.load" ;;
105          "-b *" | "-b" | "vendor -b *" | "vendor -b")
106            modules_dir=${vendor_modules_dir}
107            arg="-b --all=${vendor_modules_dir}/modules.load" ;;
108          "*" | "" | "vendor *" | "vendor")
109            modules_dir=${vendor_modules_dir}
110            arg="--all=${vendor_modules_dir}/modules.load" ;;
111        esac
112        if [[ -d "${modules_dir}" ]]; then
113          modprobe -a -d "${modules_dir}" $arg
114        fi
115        ;;
116      "wait") wait_for_file $arg ;;
117    esac
118  done < $cfg_file
119fi
120