1 模块代码(helloworld.c)
#include<linux/init.h>
#include<linux/module.h>
static int hello_init(void)
{
printk(KERN_WARNING"Hello,word!\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_INFO"Goodbye,world\n");
}
module_init(hello_init);
module_exit(hello_exit);
2 Makefile文件代码:
ifneq ($(KERNELRELEASE),)
obj-m:=helloworld.o
else
KDIR:=/app_test/linux2.6.35 //开发板linux内核源码地址
all:
make -C $(KDIR) M=$(PWD) modules
clean:
rm -f *.ko *.o *.mod.o *.mod.c *.symvers
endif
3 编译驱动模块
在程序所在文件夹中直接执行make
4 安装驱动模块
insmod helloworld.ko
应用程序编写时 使用 arm-linux-gcc -static xxx.c -o xxx