blob: f15ebbc172feafc88b8c87f8cec4643442f8a9ee [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 Zhang959ba112024-04-18 12:29:28 -070014pagesize=$(getconf PAGESIZE)
15bootoption=$(getprop ro.product.build.16k_page.enabled)
16if [ "$pagesize" != "4096" ] && [ "$bootoption" == "true" ]; then
17 echo "Device has page size $pagesize , skip loading modules from vendor_dlkm/system_dlkm because all modules are stored on vendor_boot"
18 setprop vendor.common.modules.ready 1
19 setprop vendor.device.modules.ready 1
20 setprop vendor.all.modules.ready 1
21 setprop vendor.all.devices.ready 1
22 return 0
23fi
24
Robin Pengdbf355e2023-03-15 01:22:07 +000025for dir in system vendor; do
26 for f in /${dir}/lib/modules/*/modules.dep /${dir}/lib/modules/modules.dep; do
27 if [[ -f "$f" ]]; then
28 if [[ "${dir}" == "system" ]]; then
29 system_modules_dir="$(dirname "$f")"
30 else
31 vendor_modules_dir="$(dirname "$f")"
32 modules_dir=${vendor_modules_dir}
33 fi
34 break
35 fi
36 done
Adam Shihf15086f2022-09-05 11:05:32 +080037done
38
Robin Pengdbf355e2023-03-15 01:22:07 +000039if [[ -z "${system_modules_dir}" ]]; then
40 echo "Unable to locate system kernel modules directory" 2>&1
41fi
42
43if [[ -z "${vendor_modules_dir}" ]]; then
44 echo "Unable to locate vendor kernel modules directory" 2>&1
Adam Shihf15086f2022-09-05 11:05:32 +080045 exit 1
46fi
47
48# imitates wait_for_file() in init
49wait_for_file()
50{
51 filename="${1}"
52 timeout="${2:-5}"
53
54 expiry=$(($(date "+%s")+timeout))
55 while [[ ! -e "${filename}" ]] && [[ "$(date "+%s")" -le "${expiry}" ]]
56 do
57 sleep 0.01
58 done
59}
60
61if [ $# -eq 1 ]; then
62 cfg_file=$1
63else
64 # Set property even if there is no insmod config
65 # to unblock early-boot trigger
Kelvin Zhang959ba112024-04-18 12:29:28 -070066 setprop vendor.common.modules.ready 1
67 setprop vendor.device.modules.ready 1
68 setprop vendor.all.modules.ready 1
69 setprop vendor.all.devices.ready 1
Adam Shihf15086f2022-09-05 11:05:32 +080070 exit 1
71fi
72
73if [ -f $cfg_file ]; then
74 while IFS="|" read -r action arg
75 do
76 case $action in
77 "insmod") insmod $arg ;;
78 "setprop") setprop $arg 1 ;;
79 "enable") echo 1 > $arg ;;
Zheng Panb2a04f22024-03-12 18:21:05 -070080 "condinsmod")
81 prop=$(echo $arg | cut -d '|' -f 1)
82 module1=$(echo $arg | cut -d '|' -f 2)
83 module2=$(echo $arg | cut -d '|' -f 3)
84 value=$(getprop $prop)
85 if [[ ${value} == "true" ]]; then
86 insmod ${vendor_modules_dir}/${module1}
87 else
88 insmod ${vendor_modules_dir}/${module2}
89 fi
90 ;;
Adam Shihf15086f2022-09-05 11:05:32 +080091 "modprobe")
92 case ${arg} in
Robin Pengdbf355e2023-03-15 01:22:07 +000093 "system -b *" | "system -b")
94 modules_dir=${system_modules_dir}
95 arg="-b --all=${system_modules_dir}/modules.load" ;;
96 "system *" | "system")
97 modules_dir=${system_modules_dir}
98 arg="--all=${system_modules_dir}/modules.load" ;;
99 "-b *" | "-b" | "vendor -b *" | "vendor -b")
100 modules_dir=${vendor_modules_dir}
101 arg="-b --all=${vendor_modules_dir}/modules.load" ;;
102 "*" | "" | "vendor *" | "vendor")
103 modules_dir=${vendor_modules_dir}
104 arg="--all=${vendor_modules_dir}/modules.load" ;;
Adam Shihf15086f2022-09-05 11:05:32 +0800105 esac
Robin Pengdbf355e2023-03-15 01:22:07 +0000106 if [[ -d "${modules_dir}" ]]; then
107 modprobe -a -d "${modules_dir}" $arg
108 fi
109 ;;
Adam Shihf15086f2022-09-05 11:05:32 +0800110 "wait") wait_for_file $arg ;;
111 esac
112 done < $cfg_file
113fi