I am trying to build a "Hello World" kernel module using a Yocto recipe, following the setup provided in https://git.yoctoproject.org/poky/tree/meta-skeleton/recipes-kernel/hello-mod. I have successfully built a QEMU image and loaded the module using the insmod
command.
root@192:~# lsmod
Not tainted
root@192:~# insmod /lib/modules/5.4.219-yocto-standard/extra/hello.ko
[ 29.599291] hello: loading out-of-tree module taints kernel.
[ 29.604901] Hello World!
root@192:~# lsmod
Tainted: G
hello 16384 0 - Live 0xd0b1a000 (O)
However, I want to automatically load the module when the QEMU image boots up.To achieve this, I made the following modifications to the hello-mod_0.1.bb
file:
hello-mod_0.1.bb
SUMMARY = "Example of how to build an external Linux kernel module"
DESCRIPTION = "${SUMMARY}"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://COPYING;md5=12f884d2ae1ff87c09e5b7ccc2c4ca7e"
inherit module
SRC_URI = "file://Makefile \
file://hello.c \
file://COPYING \
"
S = "${WORKDIR}"
MODULE_NAME = "hello"
# The inherit of module.bbclass will automatically name module packages with
# "kernel-module-" prefix as required by the oe-core build environment.
RPROVIDES:${PN} += "kernel-module-${MODULE_NAME}"
EXTRA_OEMAKE_append_task-install = " -C ${STAGING_KERNEL_DIR} M=${S}"
EXTRA_OEMAKE += "KDIR=${STAGING_KERNEL_DIR}"
KERNEL_MODULE_AUTOLOAD_append = "${MODULE_NAME}"
With the above changes I created new QEMU image but I can't see the log message while booting the QEMU image.Here are the observations in the QEMU image
root@192:~# ls /etc/mo*
/etc/motd
/etc/modules-load.d:
hello.conf
root@192:~# cat /etc/modules-load.d/hello.conf
hello
root@192:~# find /lib/ -iname "hello.ko"
/lib/modules/5.4.219-yocto-standard/extra/hello.ko
root@192:~# lsmod
Not tainted
Is there something I missing here to load the kernel module at boot time?
Edit: In this setup systemd is not installed in the QEMU, I need to use some custom binary as init for process.
/sbin/init —-> run-mgr
systemd-modules-load.service
is responsible for loading the modules listed in /etc/modules-load.d
which is how KERNEL_MODULE_AUTOLOAD
operates. (See man modules-load.d). Since you replaced systemd
with a custom run-mgr
, this service isn't started hence the module is not loaded automatically.
You must edit the custom run-mgr
to run /lib/systemd/systemd-modules-load
at boot. This is the executable pointed to by systemd-modules-load.service
.