0

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
4
  • The only thing I see is that your hello.conf has a .ko ending and usually there is no .ko suffix in this file. See here freedesktop.org/software/systemd/man/modules-load.d.html Commented May 8, 2023 at 8:38
  • @FlorianBerndl, My mistake.I accidentally added the .ko in the question.I verified now in the QEMU there is no .ko after hello. Is there any chance that my yocto is blocking the loading of kernel modules? Commented May 8, 2023 at 9:25
  • What Yocto branch are you on? Are you mixing syntax between old & new RPROVIDES:${PN} and KERNEL_MODULE_AUTOLOAD_append vs KERNEL_MODULE_AUTOLOAD:append see here Commented May 16, 2023 at 8:08
  • @ORR, I am using dunfell version is 3.1.I think I am using old yocto version comapre to the link you provided. Commented May 16, 2023 at 8:30

1 Answer 1

0
+50

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.

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

3 Comments

apart from using run-mgr is there any alternative approach to do this at init phase.
If you don't want to edit the run-mgr configuration at all, one option is to replace /sbin/init with a script that will first run systemd-modules-load, then run-mgr. This will only work if the system has all required dependencies to run a module ready without run-mgr, most notably the filesystem containing the module .ko.
Another possible hook would be to load your module through udev. It is very likely that udev is started by run-mgr. udev allows you to write rules calling shell commands and script when a device is detected. You could write such a rule to load your module when any associated piece of hardware is detected. More on this topic: unix.stackexchange.com/questions/28548/…

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.