yoctoyocto-recipeyocto-layer

Installing a kernel module in rootfs in yocto build system


I have a out of tree kernel module(hello.ko) from a vendor which i need to install in rootfs using yocto build. The kernel module is built on the same kernel which yocto build system is using.

I do not have the kernel source for the above module so i cannot build it using recipe.

How can i only install the kernel module in rootfs and to which path it will be installed.

Can anyone share a recipe for this.

I am new to yocto and recently started using it.

Inputs will be helpful.


Solution

  • Loadable kernel module are located in /lib/modules/<kernel_version>/kernel/drivers/

    You can create a recipe and add your pre-compiled kernel module in files/lib/modules/<kernel_version>/kernel/drivers/

    Then, add the line MODULE_NAME = "hello" to the module_autoload list. This is an example :

    #Recipe for hello.ko
    
    SUMMARY = "Hello world"
    LICENSE = "closed"
    SRC_URI = "file://hello.ko"
    
    S="${WORKDIR}"
    
    do_install() 
    {
        install -d ${D}/lib/modules/${KERNEL_VERSION}/kernel/drivers
        install -m 0644 ${WORKDIR}/hello.ko ${D}/lib/modules/${KERNEL_VERSION}/kernel/drivers/
    }
    
    FILES_${PN} += "/lib/modules/${KERNEL_VERSION}/kernel/drivers/hello.ko"
    
    MODULE_NAME = "hello"
    
    module_autoload = "${MODULE_NAME}"