linux - Yocto:为什么在构建外部内核模块期间未定义结构模块

标签 linux linux-kernel kernel-module yocto

我正在尝试使用 Yocto 构建系统将示异常(exception)部内核模块 hello-modmeta-skeleton/recipes-kernel 添加到我的图像中。然而,当我尝试使用 bitbake hello-mod 编译它时,它在第二阶段失败并提示 struct module 没有名为 name 的成员在 .name = KBUILD_MODNAME, 行上。似乎 struct module 没有被定义,即使 linux/module.h 已经包含在内。这是似乎无法编译的通用模块代码:

#include <linux/module.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>

MODULE_INFO(vermagic, VERMAGIC_STRING);
MODULE_INFO(name, KBUILD_MODNAME);

__visible struct module __this_module
__attribute__((section(".gnu.linkonce.this_module"))) = {
    .name = KBUILD_MODNAME,
    .init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
    .exit = cleanup_module,
#endif
    .arch = MODULE_ARCH_INIT,
};

#ifdef RETPOLINE
MODULE_INFO(retpoline, "Y");
#endif

static const char __module_depends[]
__used
__attribute__((section(".modinfo"))) =
"depends=";

我在编译日志中看不到任何错误,正在使用以下行调用 make(据我所知是正确的):

make -C /path/to/poky-rocko/build/tmp/work-shared/duovero/kernel-source \ 
M=/path/to/poky-rocko/build/tmp/work/duovero-poky-linux-gnueabi/hello-mod/0.1-r0

我可以确认 module.h 存在于目录中: /path/to/poky-rocko/build/tmp/work-shared/duovero/kernel-source/include/linux

所以我已经用完了,正在寻找有关如何调试此问题的想法。作为记录,这些是层、内核等的当前版本:

  • poky 是来自 git.yoctoproject.org 的 9915e071bcadd7c4d5363a067c529889851d37a5 (rocko)
  • linux 是来自 git.kernel.org 的 9dc30ff9a115559cc55673d0b1d3c576402d073e

如有任何帮助或提示,我们将不胜感激!

最佳答案

这似乎是 Yocto 构建系统的问题。当我按照这些步骤操作时,hello-mod 模块构建完成。

  1. 检查内核 4.16.x 版本,将 hello-mod 添加到 MACHINE_ESSENTIAL_EXTRA _RRECOMMENDS 并观察构建失败。
  2. 通过将 SRCREV 设置为相应的提交 ID,检查另一个内核 4.16.y 的副本,继续构建并观察它是否成功。

到目前为止,我在从 4.16.5 移动到 4.16.8 时观察到了这一点,反之亦然。所以在这一点上,我非常确定这是构建系统的问题。

我使用 grep(针对“hello”和“MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS”)和 diff 仔细查看了 bitbake -e 的输出,但没有发现任何显着差异。我还检查了编译和配置日志,我看到的唯一有趣的事情是在第二次运行时打印的配置日志中:

DEBUG: Executing shell function do_configure
NOTE: make KERNEL_SRC=/path/to/poky-rocko/build/tmp/work-shared/duovero/kernel-source clean
rm -f *.o *~ core .depend .*.cmd *.ko *.mod.c
rm -f Module.markers Module.symvers modules.order
rm -rf .tmp_versions Modules.symvers
DEBUG: Shell function do_configure finished
DEBUG: Executing python function do_qa_configure
DEBUG: Python function do_qa_configure finished

在第一次运行时,我们只有:

DEBUG: Executing shell function do_configure
DEBUG: Shell function do_configure finished
DEBUG: Executing python function do_qa_configure
DEBUG: Python function do_qa_configure finished

虽然这可能是刚刚发生的,因为这是 hello-mod 的配置任务的第二次运行。对我来说,这很像是构建系统中的错误。为此,我已经在 Bugzilla 上报告了这个问题:

https://bugzilla.yoctoproject.org/show_bug.cgi?id=12748

关于linux - Yocto:为什么在构建外部内核模块期间未定义结构模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50335280/

相关文章:

linux - 何时在 linux 内核中使用内核线程与工作队列

与 Windows 平台相比,Linux 中的 CPU 需要花费太多时间来执行嵌套 for 循环

linux - Redis不读取配置文件

c - 系统重置后环境值丢失

linux - 使用 shell 脚本或 unix 命令用特定单词替换某些标签之间的内容

c - Netlink 组播内核组

Linux:基于另一个模块加载模块

linux - Linux 中应用程序的初始化

c - open() 返回 "No such device"错误,但是有这样的设备 (linux)

linux-kernel - printk 第二次输出