move insmod script to gs-common

Bug: 243763292
Test: boot to home
Change-Id: I43b281a5b1c77d1388bac356b6b2bf267dbe099c
This commit is contained in:
Adam Shih 2022-09-05 11:05:32 +08:00
parent 33aa7718bc
commit f15086f3d9
5 changed files with 104 additions and 0 deletions

13
insmod/Android.bp Normal file
View file

@ -0,0 +1,13 @@
sh_binary {
name: "insmod.sh",
src: "insmod.sh",
init_rc: ["init.insmod.rc"],
vendor: true,
}
prebuilt_etc {
name: "init.common.cfg",
src: "init.common.cfg",
vendor: true,
}

11
insmod/init.common.cfg Normal file
View file

@ -0,0 +1,11 @@
####################################################
# init.insmod.common.cfg #
# This file contains common kernel modules to load #
# at init time by init.insmod.sh script #
####################################################
# Load common kernel modules
# Modules here will be loaded *before* device specific modules
modprobe|-b *
# All common modules loaded
setprop|vendor.common.modules.ready

10
insmod/init.insmod.rc Normal file
View file

@ -0,0 +1,10 @@
on init
# Loading common kernel modules in background
start insmod_sh
service insmod_sh /vendor/bin/insmod.sh /vendor/etc/init.common.cfg
class main
user root
group root system
disabled
oneshot

3
insmod/insmod.mk Normal file
View file

@ -0,0 +1,3 @@
PRODUCT_PACKAGES += \
insmod.sh \
init.common.cfg

67
insmod/insmod.sh Executable file
View file

@ -0,0 +1,67 @@
#!/vendor/bin/sh
#############################################################
### init.insmod.cfg format: ###
### ----------------------------------------------------- ###
### [insmod|setprop|enable/moprobe|wait] [path|prop name] ###
### ... ###
#############################################################
modules_dir=
for f in /vendor/lib/modules/*/modules.dep /vendor/lib/modules/modules.dep; do
if [[ -f "$f" ]]; then
modules_dir="$(dirname "$f")"
break
fi
done
if [[ -z "${modules_dir}" ]]; then
echo "Unable to locate kernel modules directory" 2>&1
exit 1
fi
# imitates wait_for_file() in init
wait_for_file()
{
filename="${1}"
timeout="${2:-5}"
expiry=$(($(date "+%s")+timeout))
while [[ ! -e "${filename}" ]] && [[ "$(date "+%s")" -le "${expiry}" ]]
do
sleep 0.01
done
}
if [ $# -eq 1 ]; then
cfg_file=$1
else
# Set property even if there is no insmod config
# to unblock early-boot trigger
setprop vendor.common.modules.ready
setprop vendor.device.modules.ready
setprop vendor.all.modules.ready
setprop vendor.all.devices.ready
exit 1
fi
if [ -f $cfg_file ]; then
while IFS="|" read -r action arg
do
case $action in
"insmod") insmod $arg ;;
"setprop") setprop $arg 1 ;;
"enable") echo 1 > $arg ;;
"modprobe")
case ${arg} in
"-b *" | "-b")
arg="-b --all=${modules_dir}/modules.load" ;;
"*" | "")
arg="--all=${modules_dir}/modules.load" ;;
esac
modprobe -a -d "${modules_dir}" $arg ;;
"wait") wait_for_file $arg ;;
esac
done < $cfg_file
fi