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!
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.