首页 > 解决方案 > Yocto:为什么在构建外部内核模块期间未定义结构模块

问题描述

我正在尝试使用 Yocto 构建系统将示例外部内核模块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

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

任何帮助或提示将不胜感激!

标签: linuxlinux-kernelkernel-moduleyocto

解决方案


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

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

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

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

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


推荐阅读