嵌入式爱好者

查看: 22772|回复: 4

[Linux] 加载驱动时,出现错误

[复制链接]

3

主题

5

帖子

28

积分

A40i/T3/T507通行证

扫一扫,手机访问本帖
发表于 2020-1-2 13:51:37 | 显示全部楼层 |阅读模式
Makefile:
CROSS_COMPILE := /root/workspace/allwinner/A40i/bsp/lichee/out/sun8iw11p1/linux/common/buildroot/host/opt/ext-toolchain/bin/arm-linux-gnueabihf-
CC:= $(CROSS_COMPILE)gcc
LD:= $(CROSS_COMPILE)ld
obj-m := hello.o
KERNELDIR = /root/workspace/allwinner/A40i/bsp/lichee/linux-3.10
PWD := $(shell pwd)
modules:
     $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
     $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
clean:
rm -f *.o
rm -f *.symvers
rm -f *.order
rm -f *.ko
rm -f *.mod.c
.c文件:
/*
* file name: hello.c
*/
#include<linux/module.h>
#include<linux/init.h>                                                         
#include<linux/moduleparam.h>
MODULE_AUTHOR("Kevin Taylor");
MODULE_LICENSE("GPL");
static int nbr = 10;
module_param(nbr, int, S_IRUGO);
static int __init hello_init(void)
{
   int i;
   printk(KERN_ALERT"Init hello mudule...\n");
   for(i=0;i<nbr;i++)
   {   
       printk(KERN_ALERT"Hello, how are you? %d\n", i);
   }   
   return 0;
}
static void __exit hello_exit(void)
{
   printk(KERN_ALERT"Exit hello mudule...\n");
   printk(KERN_ALERT"I come from hello's module, I have been unload.\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_DESCRIPTION("my first module");
MODULE_ALIAS("A **st module");
加载错误:
# insmod hello.ko -f
insmod: can't insert 'hello.ko': invalid module format
# ls -al
total 211
drwxr-xr-x    2 root     root          1024 Jan  2 12:57 .
drwxr-xr-x   23 root     root          1024 Jan  1 20:36 ..
-rwxrwxrwx    1 root     root         31488 Jan  2 02:15 hello.ko
-rwx------    1 root     root         10012 Jan  1 12:35 helloworld
-rwxrwxrwx    1 root     root        171684 Jan  2 04:57 udp_diag.ko
# dmesg |tail -6
[  300.554213] hello: unknown relocation: 10
[ 3544.724890] hello: unknown relocation: 10
[ 6966.367209] ************Serial               : 44c078a1840428060911
[14499.699228] hello: unknown relocation: 10
[14579.513269] ************Serial               : 44c078a1840428060911
[15858.382734] hello: unknown relocation: 10


用内核一起编译的驱动没有问题。

回复

使用道具 举报

0

主题

1173

帖子

2194

积分

发表于 2020-1-2 14:49:11 | 显示全部楼层
我们这没法复现,您可以查一下是怎么导致的,是不是操作步骤有失误的地方

点评

与内核一起编译可以加载,单独编译不行,是不是交叉编译器的路径不对?  详情 回复 发表于 2020-1-2 18:44
这个都复现不了?  详情 回复 发表于 2020-1-2 17:26
点评回复 支持 反对

使用道具 举报

3

主题

5

帖子

28

积分

A40i/T3/T507通行证

 楼主| 发表于 2020-1-2 17:26:04 | 显示全部楼层
zhichao 发表于 2020-1-2 14:49
我们这没法复现,您可以查一下是怎么导致的,是不是操作步骤有失误的地方

这个都复现不了?
点评回复 支持 反对

使用道具 举报

3

主题

5

帖子

28

积分

A40i/T3/T507通行证

 楼主| 发表于 2020-1-2 18:44:49 | 显示全部楼层
zhichao 发表于 2020-1-2 14:49
我们这没法复现,您可以查一下是怎么导致的,是不是操作步骤有失误的地方

与内核一起编译可以加载,单独编译不行,是不是交叉编译器的路径不对?
点评回复 支持 反对

使用道具 举报

0

主题

1173

帖子

2194

积分

发表于 2020-1-3 14:38:52 | 显示全部楼层
有可能是交叉编译器选的不对
点评回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )

GMT+8, 2024-3-28 21:20

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表