• «
  • 1
  • 2
  • »
  • Pages: 1/2     Go
主题 : 交叉编译hello模块时出现的问题[已初步解决] 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 395
精华: 0
发帖: 31
金钱: 310 两
威望: 31 点
综合积分: 62 分
注册时间: 2008-03-26
最后登录: 2010-04-01
楼主  发表于: 2008-03-26 19:46

 交叉编译hello模块时出现的问题[已初步解决]

一个经典的hello.c模块程序,一个makefile。其中,makefile内容如下:
obj-m := hello.o
运行以下命令进行交叉编译:
make CROSS_COMPILE=arm-linux-  -C /opt/qq2440/kernel-2.6.13/ M=`pwd` modules
可以成功生成hello.ko文件

下载到目标板,insmod hello.ko时,出现如下问题!
insmod: kernel-module version mismatch
        hello.ko was compiled for kernel version
        while this kernel is version 2.6.13.
内核不匹配?我又专门用/opt/qq2440/kernel-2.6.13这个kernel重新编译了一遍操作系统,重新烧写了竟像文件,应该不会有内核不匹配问题吧?
那这是怎么回事呢?严重迷茫中,各路高手帮指点一下吧!多谢!

PS:
主机上运行
[root@localhost hello]# modinfo hello.ko
filename:      hello.ko
license:        Dual BSD/GPL
srcversion:    31FE72DA6A560C890FF9B3F
depends:
vermagic:      2.6.13 preempt ARMv4 gcc-3.4
开发板运行
[root@FriendlyARM plg]# uname -r
2.6.13

版本没问题啊!
[ 此贴被yourbabyface在2008-04-01 19:57重新编辑 ]
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2008-03-26 21:34
能否贴一下源代码和make过程的输出?
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 395
精华: 0
发帖: 31
金钱: 310 两
威望: 31 点
综合积分: 62 分
注册时间: 2008-03-26
最后登录: 2010-04-01
2楼  发表于: 2008-03-26 22:31
OK.

=================================
源代码hello.c:
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
    printk(KERN_ALERT "Hello, world\n");
    return 0;
}
static void hello_exit(void)
{
    printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
================================
Makefile:
obj-m := hello.o
================================
make命令(稍修改了下,把一开始的CROSS_COMPILE去掉了)
以及make的输出:
[root@localhost hello]# make -C /opt/qq2440/kernel-2.6.13/ M=$PWD modules
make: Entering directory `/opt/qq2440/kernel-2.6.13'

  WARNING: Symbol version dump /opt/qq2440/kernel-2.6.13/Module.symvers
          is missing; modules will have no dependencies and modversions.

  CC [M]  /opt/qq2440/TEST/hello/hello.o
/opt/qq2440/TEST/hello/hello.c:14:25: warning: no newline at end of file
  Building modules, stage 2.
  MODPOST
  CC      /opt/qq2440/TEST/hello/hello.mod.o
  LD [M]  /opt/qq2440/TEST/hello/hello.ko
make: Leaving directory `/opt/qq2440/kernel-2.6.13'
====================================
加载到开发板后,insmod,输出为:
insmod: kernel-module version mismatch
        hello.ko was compiled for kernel version
        while this kernel is version 2.6.13.
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
3楼  发表于: 2008-03-27 13:53
WARNING: Symbol version dump /opt/qq2440/kernel-2.6.13/Module.symvers
          is missing; modules will have no dependencies and modversions.

仔细看这句:)
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 395
精华: 0
发帖: 31
金钱: 310 两
威望: 31 点
综合积分: 62 分
注册时间: 2008-03-26
最后登录: 2010-04-01
4楼  发表于: 2008-03-27 23:45
不好意思,查了好久也没搞定这个module.symvers怎么生成,有说是内核重新编译一下,不过我没找到相关的配置选项阿。新手上路,望版主指点迷津
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
5楼  发表于: 2008-03-28 08:19
在内核源代码的目录下执行make ARCH=arm CROSS_COMPILE=/path/to/toolchain modules
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 395
精华: 0
发帖: 31
金钱: 310 两
威望: 31 点
综合积分: 62 分
注册时间: 2008-03-26
最后登录: 2010-04-01
6楼  发表于: 2008-03-28 11:16
还是不行啊。在/etc/profile里,已经设置了
pathmunge /usr/local/arm/3.4.1/bin
然后在内核源代码目录下执行
make ARCH=arm CROSS_COMPILE=arm-linux- modules
输出如下
  CHK    include/linux/version.h
make[1]: “arch/arm/kernel/asm-offsets.s”是最新的。
make[1]: “include/asm-arm/mach-types.h”是最新的。
  Building modules, stage 2.
  MODPOST
然后到hello目录下,执行
[root@localhost hello]# make -C /opt/qq2440/kernel-2.6.13/ M=$PWD modules
make: Entering directory `/opt/qq2440/kernel-2.6.13'
  CC [M]  /opt/qq2440/TEST/hello/hello.o
/opt/qq2440/TEST/hello/hello.c:14:25: warning: no newline at end of file
  Building modules, stage 2.
  MODPOST
  CC      /opt/qq2440/TEST/hello/hello.mod.o
  LD [M]  /opt/qq2440/TEST/hello/hello.ko
make: Leaving directory `/opt/qq2440/kernel-2.6.13'
Warning倒是没有了,但是,加载到目标板上insmod后,现象还是一模一样啊!
级别: 新手上路
UID: 395
精华: 0
发帖: 31
金钱: 310 两
威望: 31 点
综合积分: 62 分
注册时间: 2008-03-26
最后登录: 2010-04-01
7楼  发表于: 2008-03-28 11:18
在make里指定/path-to-toolchain也是一样的现象...
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
8楼  发表于: 2008-03-28 19:48
在make的时候指定CROSS_COMPILE只是为了告诉make用哪个交叉编译器,和module没关系。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 395
精华: 0
发帖: 31
金钱: 310 两
威望: 31 点
综合积分: 62 分
注册时间: 2008-03-26
最后登录: 2010-04-01
9楼  发表于: 2008-03-28 20:26
是啊,而且ARCH跟CROSS_COMPILE在Makefile里已经指定了,但是为什么还是通不过呢?
  • «
  • 1
  • 2
  • »
  • Pages: 1/2     Go