Overview

There are three main steps to enabling a kernel module for an Android build (tested with Pie P9.0.0):

    1. Enable the module in the kernel config file.
    2. Modify the BoardConfig.mk file, instructing the Android build to place the kernel module in the vendor partition.
    3. Build the kernel and vendor image.

Enabling Kernel Module in the Kernel Config file

Locate your kernel configuration file, and enable the module, e.g.

[shell]vim vendor/variscite/kernel_imx/arch/arm64/configs/imx8_var_android_defconfig[/shell]

Insert/modify the driver configuration, it my case I inserted: CONFIG_CHARGER_BQ24257=m

Modify the BoardConfig.mk file

You need to edit the BoardConfig.mk file for you platform, adding the module into the BOARD_VENDOR_KERNEL_MODULES variable. E.g.

[shell] vim ./device/variscite/imx8q/som_mx8q/BoardConfig.mk [/shell]

I then appended the path to the kernel module file into the BOARD_VENDOR_KERNEL_MODULES variable.

[shell]

BOARD_VENDOR_KERNEL_MODULES += \
$(KERNEL_OUT)/drivers/net/ethernet/freescale/fec.ko \
$(KERNEL_OUT)/drivers/net/wireless/broadcom/brcm80211/brcmutil/brcmutil.ko \
$(KERNEL_OUT)/drivers/net/wireless/broadcom/brcm80211/brcmfmac/brcmfmac.ko \
$(KERNEL_OUT)/drivers/power/supply/bq24257_charger.ko

[/shell]

Build the Kernel and Vendor Image

[shell] make -j10 bootimage [/shell]

[shell] make -j10 vendorimage [/shell]

Verify that the driver has been added

There are several checks we can do to verify that the driver has been added to the vendor image.

First is to verify the .ko file is listed in out/target/product/som_mx8q/installed-files-vendor.json

Next would be to install the image on the device and check the /vendor/lib/modules/ directory.

Reference documentation here