本文记录Linux 2.6驱动开发环境搭建及内核模块编译加载的实践经验。
#include#include static int hello_init(void){printk("hello_init"); return 0;}static void hello_exit(void){printk("hello_exit");}module_init(hello_init);module_exit(hello_exit);
硬件:OK6410开发板
目标操作系统:Linux 2.6 交叉编译环境:Windows 7 + VMware Workstation + Red Hat 9 + arm-linux-gccKERNELDIR = /home/linux-2.6.36/linux-2.6.36.2-v1.05PWD := $(shell pwd)CC = arm-linux-gccobj-m += driver01.omodules: $(MAKE) -C $(KERNELDIR) M=$(PWD) modulesclean: rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions.PHONY: clean
编译后将driver01.ko拷贝至目标板SD卡,执行insmod driver01.ko查看控制台输出“hello_init”,确认模块加载成功。
注意事项
- 已解决"generated/bounds.h: No such file or directory"错误,需提前编译内核源码
- 添加 MODULE_LICENSE("GPL");标识以避免模块加载警告
- 在Red Hat中配置arm-linux-gcc环境变量
- VMware网络IP配置
文章转载自:原文链接