blob: 8ec81995c9e332060a1f4878660b25ab069d4cd8 [file] [log] [blame]
Adam Shihf15086f2022-09-05 11:05:32 +08001#!/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=
Robin Pengdbf355e2023-03-15 01:22:07 +000011system_modules_dir=
12vendor_modules_dir=
Adam Shihf15086f2022-09-05 11:05:32 +080013
Kelvin Zhang99f848e2024-05-09 16:45:02 +000014
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
Robin Pengdbf355e2023-03-15 01:22:07 +000031for 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
Adam Shihf15086f2022-09-05 11:05:32 +080043done
44
Robin Pengdbf355e2023-03-15 01:22:07 +000045if [[ -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
Adam Shihf15086f2022-09-05 11:05:32 +080051 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
Kelvin Zhang99f848e2024-05-09 16:45:02 +000072 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
Adam Shihf15086f2022-09-05 11:05:32 +080076 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 ;;
Zheng Panb2a04f22024-03-12 18:21:05 -070086 "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 ;;
Adam Shihf15086f2022-09-05 11:05:32 +080097 "modprobe")
98 case ${arg} in
Robin Pengdbf355e2023-03-15 01:22:07 +000099 "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" ;;
Adam Shihf15086f2022-09-05 11:05:32 +0800111 esac
Robin Pengdbf355e2023-03-15 01:22:07 +0000112 if [[ -d "${modules_dir}" ]]; then
113 modprobe -a -d "${modules_dir}" $arg
114 fi
115 ;;
Adam Shihf15086f2022-09-05 11:05:32 +0800116 "wait") wait_for_file $arg ;;
117 esac
118 done < $cfg_file
119fi