| 
 
贡献174 
飞刀16 FD
注册时间2019-12-31
在线时间5 小时积分28 
 
 
 扫一扫,手机访问本帖  | 
 
| 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
 
 
 用内核一起编译的驱动没有问题。
 
 
 | 
 |