Load Kernel module while booting QEMU image through yocto.

huangapple go评论90阅读模式
英文:

Load Kernel module while booting QEMU image through yocto

问题

我明白了,以下是翻译好的部分:

我正在尝试使用 Yocto 配方构建一个“Hello World”内核模块,遵循 https://git.yoctoproject.org/poky/tree/meta-skeleton/recipes-kernel/hello-mod 中提供的设置。我已成功构建了一个 QEMU 镜像,并使用 `insmod` 命令加载了该模块。
root@192:~# lsmod 
    未被污染

root@192:~# insmod /lib/modules/5.4.219-yocto-standard/extra/hello.ko 
[   29.599291] hello: 加载了一个非内核模块,使内核变得有瑕疵。
[   29.604901] 你好,世界!

root@192:~# lsmod 
    有瑕疵: G  
hello 16384 0 - 在线 0xd0b1a000 (O)
然而,我想在 QEMU 镜像启动时自动加载该模块。为了实现这一点,我对 `hello-mod_0.1.bb` 文件进行了以下修改:
**hello-mod_0.1.bb**
摘要 = "构建外部 Linux 内核模块的示例"
描述 = "${SUMMARY}"
许可证 = "GPLv2"
LIC_FILES_CHKSUM = "file://COPYING;md5=12f884d2ae1ff87c09e5b7ccc2c4ca7e"

继承模块

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

S = "${WORKDIR}"
MODULE_NAME = "hello"
# 使用 module.bbclass 继承将自动命名模块包,并在 oe-core 构建环境中添加“kernel-module-”前缀。

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}"
通过上述更改,我创建了一个新的 QEMU 镜像,但在启动 QEMU 镜像时看不到日志消息。以下是在 QEMU 镜像中的观察结果:
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 
    未被污染
在启动时加载内核模块时,我是否遗漏了某些东西?

编辑:在这个设置中,QEMU 中没有安装 systemd,我需要使用一些自定义二进制文件作为进程的 init。

/sbin/init —-> run-mgr
英文:

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

答案1

得分: 0

systemd-modules-load.service负责加载位于/etc/modules-load.d中列出的模块,这是KERNEL_MODULE_AUTOLOAD的操作方式(请参阅man modules-load.d)。由于您用自定义的run-mgr替换了systemd,因此此服务未启动,因此模块不会自动加载。

您必须编辑自定义的run-mgr,在启动时运行/lib/systemd/systemd-modules-load。这是由systemd-modules-load.service指向的可执行文件。

英文:

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.

huangapple
  • 本文由 发表于 2023年5月7日 15:06:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192599.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定