2011年4月19日
20:30
驱动开发使用的是tq2440的开发板,linux内核版本为linux-2.6.30.4。
首先解压linux源码,拷贝配置文件cp -f config_EmbedSky_W35_256MB .config (否则会出现version magic '2.6.30.4 mod_unload modversions ARMv5 ' should be '2.6.30'的版本错误)
Make distclean
Make oldconfig
Make
之后就可以编译hello驱动文件了
[xiaoyang@localhost Hello]$ make modules
make -C /opt/EmbedSky/linux-2.6.30.4 M=/opt/EmbedSky/apps/my-driver/Hello modules
make[1]: Entering directory `/opt/EmbedSky/linux-2.6.30.4'
WARNING: Symbol version dump /opt/EmbedSky/linux-2.6.30.4/Module.symvers
is missing; modules will have no dependencies and modversions.
CC [M] /opt/EmbedSky/apps/my-driver/Hello/hello.o
/opt/EmbedSky/apps/my-driver/Hello/hello.c:17: warning: function declaration isn't a prototype
Building modules, stage 2.
MODPOST 1 modules
CC /opt/EmbedSky/apps/my-driver/Hello/hello.mod.o
LD [M] /opt/EmbedSky/apps/my-driver/Hello/hello.ko
make[1]: Leaving directory `/opt/EmbedSky/linux-2.6.30.4'
[xiaoyang@localhost Hello]$ 4
Hello.c代码:
//----------------------------------------------------------
// xiaoyang@2011.4.19
// hello module
//----------------------------------------------------------
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk("hello,xiaoyang!\n");
return 0;
}
static void hello_exit()
{
printk(KERN_ALERT "goodbye,xiaoyang!\n");
}
module_init(hello_init);
module_exit(hello_exit);
Makefile:
KERNELDIR=/opt/EmbedSky/linux-2.6.30.4
PWD:=$(shell pwd)
INSTALLDIR=/opt/EmbedSky/linux-2.6.30.4/mydriver
#CROSS_COMPILE=/opt/EmbedSky/crosstools_3.4.5_softfloat/gcc-3.4.5-glibc-2.3.6/arm-linux/bin/arm-linux-
CROSS_COMPILE=arm-linux-
CC=$(CROSS_COMPILE)gcc
obj-m := hello.o
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
cp hello.ko $(INSTALLDIR)
clean:
rm -rf *.o *.ko *.mod.c *.markers *.order *.symvers
.PHONY:modules modules_install clean
实验截图: