8

For testing purposes, I am using the example recipe provided by yocto to demonstrate how to build kernel modules.

SUMMARY = "Example of how to build an external Linux kernel module"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://COPYING;md5=12f884d2ae1ff87c09e5b7ccc2c4ca7e"

inherit module

PR = "r0"
PV = "0.1"

SRC_URI = "file://Makefile \
           file://hello.c \
           file://COPYING \
          "

S = "${WORKDIR}"

# The inherit of module.bbclass will automatically name module packages with
# "kernel-module-" prefix as required by the oe-core build environment.

The hello.c file is very simple.

#include <linux/module.h>

int init_module(void)
{
    printk("Hello World!\n");
    return 0;
}

void cleanup_module(void)
{
    printk("Goodbye Cruel World!\n");
}

MODULE_LICENSE("GPL");

Now, I added this module to my image recipe.

SUMMARY = "A console-only image that fully supports the target device \
hardware."

IMAGE_FEATURES += "splash package-management"

IMAGE_INSTALL += "test-mod autoconf automake binutils make busybox"

LICENSE = "MIT"

inherit core-image

When I boot the image, I see the test "hello.ko" in the /lib/modules directory, but when I check dmesg, I don't see the output indicating the kernel module loaded.

When I manually run insmod on hello.ko, I get the output. Also, when I run rmmod, I get the output.

What am I doing wrong? I need this module to auto load on boot.

edit:

Here the output, verifying that the module isn't loaded on boot, but it is a valid module.

/ # dmesg | grep "Hello"
/ # insmod hello.ko 
[   68.503689] Hello World!
/ # rmmod hello.ko 
[   72.702035] Goodbye Cruel World!
2
  • I did not understand "Now, I added this module to my image recipe." part! which file? Commented Dec 31, 2020 at 7:03
  • IMAGE_INSTAL += your-recipe in your image recipe. Commented Jan 5, 2021 at 17:10

1 Answer 1

9

You should add your module name to KERNEL_MODULE_AUTOLOAD in your recipe, typically like this:

KERNEL_MODULE_AUTOLOAD += "hello"

This should put your module name into /etc/modules-load.d/modname.conf on the image.

Sign up to request clarification or add additional context in comments.

2 Comments

Worked for me only in .conf files, like local.conf or the meta .conf, but had no effect from image recipe, for instance.
Image recipes are a bit special in a lot of areas. You can use KERNEL_MODULE_AUTOLOAD in conf files and in the actual kernel or module recipe (or a bbappend to the kernel or module recipe).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.