交叉编译2.6驱动无法通过

发布于 2022-07-22 11:04:59 字数 11527 浏览 10 评论 7

各位大哥,小弟正在从pc上编译驱动到arm板,但是在交叉编译这一步怎么也过不去,请各位大侠帮忙指点一下!
编译器arm-linux-gcc-3.4.1,试验代码hello.c照抄ldd3的代码:
#include <linux/init.h>
#include <linux/module.h>
//MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
        printk("Hello, worldn");
        return 0;
}

static void hello_exit(void)
{
        printk("Goodbye, cruel worldn");
}

module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
#################################
编译方法一:利用Makefile,内容如下:
armgcc1 = /usr/local/arm/3.4.1/bin/arm-linux-gcc
INCLUDELDIR = /usr/local/arm/3.4.1/arm-linux/sys-include
NOWFLAG = -I$(INCLUDELDIR)
hello.o: hello.c
default:
                $(armgcc1) -mcpu=arm920  $(NOWFLAG) --host=arm-linux -c hello.c
显示cc    -c -o hello.o hello.c,生成的hello。o,用file ./hello.o查看是./hello.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
在2410上insmod hello。o提示如下:hello.o: ELF file hello.o not for this architecture
#############################
编译方法2:直接ARM-GCC
#/usr/local/arm/3.4.1/bin/arm-linux-gcc -c hello.c
却得到一大堆include file的错误,错误完整内容如下:

In file included from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/sched.h:12,
                 from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/module.h:10,
                 from hello.c:6:
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/jiffies.h:16: error: parse error before "jiffies_64"
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/jiffies.h:20: error: parse error before "get_jiffies_64"
In file included from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/sched.h:18,
                 from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/module.h:10,
                 from hello.c:6:
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm/semaphore.h:18: error: parse error before "wait_queue_head_t"
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm/semaphore.h: In function `sema_init':
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm/semaphore.h:46: error: dereferencing pointer to incomplete type
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm/semaphore.h:47: error: dereferencing pointer to incomplete type
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm/semaphore.h:48: error: dereferencing pointer to incomplete type
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm/semaphore.h: In function `sema_count':
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm/semaphore.h:66: error: dereferencing pointer to incomplete type
In file included from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/signal.h:4,
                 from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/sched.h:25,
                 from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/module.h:10,
                 from hello.c:6:
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/list.h:682:2: warning: #warning "don't include kernel headers in userspace"In file included from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm/siginfo.h:4,
                 from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/signal.h:7,
                 from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/sched.h:25,
                 from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/module.h:10,
                 from hello.c:6:
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm-generic/siginfo.h: At top level:
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm-generic/siginfo.h:58: error: size of array `_pad' is too large
In file included from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/sched.h:29,
                 from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/module.h:10,
                 from hello.c:6:
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/completion.h:15: error: parse error before "wait_queue_head_t"
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/completion.h: In function `init_completion':
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/completion.h:26: error: dereferencing pointer to incomplete type
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/completion.h:27: error: dereferencing pointer to incomplete type
In file included from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/sched.h:30,
                 from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/module.h:10,
                 from hello.c:6:
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/pid.h: At top level:
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/pid.h:18: error: field `task_list' has incomplete type
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/pid.h:19: error: field `hash_chain' has incomplete type
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/pid.h:24: error: field `pid_chain' has incomplete type
In file included from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/sched.h:31,
                 from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/module.h:10,
                 from hello.c:6:
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/percpu.h: In function `__alloc_percpu':
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/percpu.h:45: error: `GFP_KERNEL' undeclared (first use in this function)
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/percpu.h:45: error: (Each undeclared identifier is reported only once
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/percpu.h:45: error: for each function it appears in.)
In file included from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/sched.h:102,
                 from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/module.h:10,
                 from hello.c:6:
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/timer.h: At top level:
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/timer.h:12: error: field `entry' has incomplete type
In file included from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm/local.h:1,
                 from /usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/linux/module.h:21,
                 from hello.c:6:
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm-generic/local.h: In function `local_inc':
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm-generic/local.h:65: error: invalid type argument of `->'
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm-generic/local.h:65: error: invalid type argument of `->'
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm-generic/local.h: In function `local_dec':
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm-generic/local.h:72: error: invalid type argument of `->'
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm-generic/local.h:72: error: invalid type argument of `->'
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm-generic/local.h: In function `local_add':
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm-generic/local.h:79: error: invalid type argument of `->'
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm-generic/local.h:79: error: invalid type argument of `->'
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm-generic/local.h: In function `local_sub':
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm-generic/local.h:86: error: invalid type argument of `->'
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/sys-include/asm-generic/local.h:86: error: invalid type argument of `->'
#####################################
小弟我分析了一下,可能是因为include module。h,因为我又编译了更为简单的hello。c
#include <stdio.h>
int main() { printf("Hello, world!n"); return 0; }
这一次顺利通过,而且可以在arm上运行
###############################

各位大侠,请帮忙分析一下,或者提供你们在编写drivers for 2.6所使用的交叉编译方法,多谢!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

幽梦紫曦~ 2022-07-25 10:35:18

lz最好先了解一下用户态编程和核心态编程的区别。

请别遗忘我 2022-07-25 10:35:15

多谢,回头马上调试,

致谢!!!!

夜还是长夜 2022-07-25 10:33:06

2.6的内核,那你的Makefile有错,见ldd3

试下这个Makefile

  1. obj-m :=hello.o
  2. KERNELDIR ?= /usr/local/arm/3.4.1/arm-linux/
  3. PWD :=$(shell pwd)
  4. all:
  5.                 $(make) -C $(KERNELDIR) M=$(PWD)

复制代码

用这个命令make

  1. make ARCH=arm CROSS_COMPILE=/usr/local/arm/3.4.1/bin/arm-linux-

复制代码
没有环境测试,不知是否正确

那伤。 2022-07-25 10:32:45

!!!

最单纯的乌龟 2022-07-25 08:59:31

无人作答,独自垂泪!

淡墨 2022-07-25 08:29:53

upupup

月下凄凉 2022-07-24 08:14:58

pc上环境FC5,kernel2.6.15.4

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文