致命错误:asm/early_ioremap.h文件或目录不存在

4

在使用gcc-4.8.5编译x86_64架构下的Linux 4.4.15库的简单hello world内核驱动程序时,为什么会出现“致命错误:asm/early_ioremap.h:没有那个文件或目录”的提示?gcc正在查找Linux 4.4.15中不可用的asm/early_ioremap.h文件。有什么想法可以解决这个问题吗?

/opt/gcc-4.8.5-glibc-2.21-p8/x86_64-linux-gnu/bin/x86_64-linux-gnu-gcc -M -MP -MT '/home/obj/src/kernel/hello_world/hello.o' -MT '/home/obj/src/kernel/hello_world/hello.d' -MT 'hello.E' -MT 'hello.S' -I/home/src/kernel/hello_world -I/home/obj/src/kernel/linux-4.4.15/include -I/home/src/inc -I/home/obj/src/kernel/linux-4.4.15/arch/x86/include -D__KERNEL__ -DMODULE -DPACKET_LEAK_TRACING -DSIZEOF_CPU_REGISTER=8 -DNUM_DEV_CF=0 -DNUM_DEV_USB=0  -mtune=nocona  -march=nocona  -m64 -pipe  -std=gnu89 -g -nostdinc  -isystem /opt/gcc-4.8.5-glibc-2.21-p8/x86_64-linux-gnu/lib/gcc/x86_64-linux-gnu/4.8.5/include -O2   -fno-strict-aliasing -fno-common -ffreestanding -Wall -Wstrict-prototypes -Wno-trigraphs -Wmissing-format-attribute -Wdisabled-optimization -Wwrite-strings -Wimplicit-int -Wmissing-braces -Wmissing-noreturn  -Wundef -Wmissing-field-initializers -Wmissing-declarations -Wmissing-prototypes -Wno-unused-parameter -Winline -mcmodel=kernel  -fno-omit-frame-pointer  -fno-stack-protector -mno-red-zone -fno-asynchronous-unwind-tables -imacros generated/autoconf.h   hello.c  -I/home/obj/src/kernel/linux-4.4.15/include/uapi/  -I/home/obj/src/kernel/linux-4.4.15/arch/x86/include/uapi/  
In file included from /home/obj/src/kernel/linux-4.4.15/arch/x86/include/asm/realmode.h:5:0,
                 from /home/obj/src/kernel/linux-4.4.15/arch/x86/include/asm/acpi.h:33,
                 from /home/obj/src/kernel/linux-4.4.15/arch/x86/include/asm/fixmap.h:19,
                 from /home/obj/src/kernel/linux-4.4.15/arch/x86/include/asm/apic.h:12,
                 from /home/obj/src/kernel/linux-4.4.15/arch/x86/include/asm/smp.h:12,
                 from /home/obj/src/kernel/linux-4.4.15/arch/x86/include/asm/mmzone_64.h:10,
                 from /home/obj/src/kernel/linux-4.4.15/arch/x86/include/asm/mmzone.h:4,
                 from /home/obj/src/kernel/linux-4.4.15/include/linux/mmzone.h:856,
                 from /home/obj/src/kernel/linux-4.4.15/include/linux/gfp.h:5,
                 from /home/obj/src/kernel/linux-4.4.15/include/linux/kmod.h:22,
                 from /home/obj/src/kernel/linux-4.4.15/include/linux/module.h:13,
                 from hello.c:1:
/home/obj/src/kernel/linux-4.4.15/arch/x86/include/asm/io.h:43:31: fatal error: asm/early_ioremap.h: No such file or directory
 #include <asm/early_ioremap.h>
                               ^
compilation terminated.
2个回答

0
gcc正在搜索asm/early_ioremap.h,但在Linux 4.4.15中找不到该文件。您有什么想法如何解决这个问题吗?
我认为您已经回答了自己的问题;要么找出该头文件中包含的功能已经移动到哪里或被替换成了什么,要么使用与Linux 4.4.15兼容的hello world模块,或者使用旧版本的内核。
个人而言,我会尝试另一个可以与最新版本的Linux一起使用的示例。

你可以在4.4.15版本中找到关于"Hello World"的相关内容吗?我的示例非常简单。只使用了几个头文件和简单的初始化、退出函数。#include <linux/module.h> // 所有内核模块都需要包含此头文件 #include <linux/kernel.h> // 用于 KERN_INFO #include <linux/init.h> // 包含 __init 和 __exit 宏 - Ravi
我的gcc include参数有问题吗?我正在交叉编译这个模块。 - Ravi
@Ravi,你说4.4.15版本没有可用的头文件,所以我猜如果这是真的,那么gcc没有问题。 - Marcus Müller

0

最近我遇到了一个非常类似的错误,尝试通过指定O=标志将内核模块构建到树外输出。

看起来这是导致失败的部分。

make \
    -j1 \
    -C /lib/modules/4.17.9-041709-generic/build \
    M=/home/kbingham/sources/linux/drivers/media/usb/uvc \
    O=/tmp/build-uvc \
    V=1 \
    modules

失败,并显示错误信息:

/usr/src/linux-headers-4.17.9-041709-generic/arch/x86/include/asm/io.h:44:10: fatal error: asm/early_ioremap.h: No such file or directory
 #include <asm/early_ioremap.h>
          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.

同时

make \
    -j1 \
    -C /lib/modules/4.17.9-041709-generic/build \
    M=/home/kbingham/sources/linux/drivers/media/usb/uvc \
    V=1 \
    modules

成功。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接