luopeng 发表于 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 Jan2 12:57 .
drwxr-xr-x   23 root   root          1024 Jan1 20:36 ..
-rwxrwxrwx    1 root   root         31488 Jan2 02:15 hello.ko
-rwx------    1 root   root         10012 Jan1 12:35 helloworld
-rwxrwxrwx    1 root   root      171684 Jan2 04:57 udp_diag.ko
# dmesg |tail -6
hello: unknown relocation: 10
[ 3544.724890] hello: unknown relocation: 10
[ 6966.367209] ************Serial               : 44c078a1840428060911
hello: unknown relocation: 10
************Serial               : 44c078a1840428060911
hello: unknown relocation: 10


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

zhichao 发表于 2020-1-2 14:49:11

我们这没法复现,您可以查一下是怎么导致的,是不是操作步骤有失误的地方

luopeng 发表于 2020-1-2 17:26:04

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

这个都复现不了?

luopeng 发表于 2020-1-2 18:44:49

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

与内核一起编译可以加载,单独编译不行,是不是交叉编译器的路径不对?

zhichao 发表于 2020-1-3 14:38:52

有可能是交叉编译器选的不对
页: [1]
查看完整版本: 加载驱动时,出现错误