Caution
AI Generated code, But It Just Works™
This repository contains a set of scripts designed to simplify the process of preparing kernel modules for vendor_boot
and vendor_dlkm
partitions when building custom Android GKI (Generic Kernel Image) kernels.
The scripts intelligently handle dependency resolution, module pruning, load order optimization, and optional integration of NetHunter modules.
The process is designed to be run in a specific order:
01.modules_dep.sh
: First, extract a master list of all modules from your stockvendor_boot
image.02.prepare_vendor_boot_modules.sh
: Next, use the master list to prepare the modules required for thevendor_boot
partition.03.prepare_vendor_dlkm.sh
: Finally, prepare thevendor_dlkm
modules, which can optionally include NetHunter modules and be pruned against thevendor_boot
list.
Before you begin, you will need:
- A Linux environment with
bash
and standard core utilities. - Your compiled kernel source, with the output available in a
staging
directory.- The
out/target/product/a16xm/obj/KERNEL_OBJ/staging/lib/modules/5.15.167-android13-8-ravindu644-nh+
like path.
- The
- The
System.map
file from your kernel build. - The AOSP
llvm-strip
tool, typically found in your toolchain directory. - Extracted stock
vendor_boot.img
andvendor_dlkm.img
to get the originalmodules.dep
andmodules.load
files.
This script reads a stock modules.dep
file and creates a clean, sorted, and unique list of all .ko
module filenames. This list serves as the master manifest for the next script.
Each script can be run interactively (by providing no arguments) or non-interactively (by providing all arguments).
Show Help Message
./01.module_dep.sh --help
Interactive Mode Simply run the script and follow the prompts.
./01.module_dep.sh
Argument Mode
Provide the path to the stock modules.dep
and the desired output directory.
# Usage: ./01.module_dep.sh <path_to_modules.dep> <output_directory>
./01.module_dep.sh /path/to/stock/vendor_boot/lib/modules/modules.dep ./vendor_boot
This will create an vendor_boot/modules_list.txt
file.
This script uses the modules_list.txt
generated earlier to gather all necessary modules and their dependencies from your kernel build's staging directory. It then strips them and prepares the final vendor_boot
module set.
Show Help Message
./02.prepare_vendor_boot_modules.sh --help
Interactive Mode
./02.prepare_vendor_boot_modules.sh
Argument Mode Provide all required paths as arguments.
# Usage: ./02.prepare_vendor_boot_modules.sh <modules_list> <staging_dir> <oem_load_file> <system_map> <strip_tool> <output_dir>
./02.prepare_vendor_boot_modules.sh \
./vendor_boot/modules_list.txt \
/path/to/kernel_build/out/msm-kernel/staging \
/path/to/stock/vendor_boot/lib/modules/modules.load \
/path/to/kernel_build/out/System.map \
/path/to/toolchain/bin/llvm-strip \
./vendor_boot/vendor_boot_modules
This is the final and most comprehensive script. It prepares the vendor_dlkm
modules, resolves all dependencies, and intelligently handles the module load order. It can optionally integrate NetHunter modules and prune any modules that are already present in the vendor_boot
partition to avoid duplication.
Show Help Message
./03.prepare_vendor_dlkm.sh --help
Interactive Mode
Run the script and follow the prompts. You can press Enter to skip the optional paths for the vendor_boot
list and the NetHunter directory.
./03.prepare_vendor_dlkm.sh
Argument Mode
Provide all paths as arguments. To skip an optional path (like the NetHunter directory or vendor_boot list), pass an empty string ""
.
Example (without NetHunter or pruning):
# Usage: ./03.prepare_vendor_dlkm.sh <modules_list> <staging_dir> <oem_load_file> <system_map> <strip_tool> <output_dir> <vendor_boot_list> <nh_dir>
./03.prepare_vendor_dlkm.sh \
./vendor_dlkm/modules_list.txt \
/path/to/kernel_build/out/msm-kernel/staging \
/path/to/stock/vendor_dlkm/lib/modules/modules.load \
/path/to/kernel_build/out/System.map \
/path/to/toolchain/bin/llvm-strip \
./vendor_dlkm/vendor_dlkm_modules \
"" \
""
Example (with NetHunter and vendor_boot pruning):
./03.vendor_dlkm.sh \
./vendor_dlkm/modules_list.txt \
/path/to/kernel_build/out/msm-kernel/staging \
/path/to/stock/vendor_dlkm/lib/modules/modules.load \
/path/to/kernel_build/out/System.map \
/path/to/toolchain/bin/llvm-strip \
./vendor_dlkm/vendor_dlkm_modules_nh \
./vendor_boot/modules_list.txt \
/path/to/nethunter_modules
Note: You should manually copy all the "suspected" modules that were generated but are not present in your OEM's module list to a separate folder (for example, ath9k_htc.ko
might have been generated because you enabled an Atheros driver as an LKM, etc.).
Eg (Only needed for the first time of generating modules.dep and modules.load file):
ravindu644@ubuntu:~/Desktop/Kernels/android_kernel_a166p/nethunter (stable-connectivity)$ ls
ath6kl_core.ko ath9k_common.ko ath9k_hw.ko carl9170.ko mac80211.ko rndis_host.ko rt2500usb.ko rt2800usb.ko rt2x00usb.ko rtl8187.ko zd1201.ko
ath6kl_usb.ko ath9k_htc.ko ath.ko cfg80211.ko mt7601u.ko rndis_wlan.ko rt2800lib.ko rt2x00lib.ko rt73usb.ko rtl8xxxu.ko zd1211rw.ko