网站怎么自己做,创建个人主页网站,wordpress中文标签,wordpress iframe插件天气: 晴朗心情: 高兴( 转)嵌入式Linux驱动开发笔记1.1 模块的编译Linux驱动一般以模块module的形式来加载#xff0c;首先需要把驱动编译成模块的形式。简单的例子#xff0c;Begin of hello.c file#include #include #include static int __init test_init(void){pr…天气: 晴朗心情: 高兴( 转)嵌入式Linux驱动开发笔记1.1 模块的编译Linux驱动一般以模块module的形式来加载首先需要把驱动编译成模块的形式。简单的例子Begin of hello.c file#include #include #include static int __init test_init(void){printk(init module\n);return 0;}static void __exit test_exit(void){printk(exit modules\n);}module_init(test_init);module_exit(test_exit);Over of hello.c fileMakefile为PWD $(shell pwd)KERNEL_SRC /usr/src/linux-source-2.6.15/obj-m : test.omodule-objs : test.oall:$(MAKE) -C $(KERNEL_SRC) M$(PWD) modulesclean:rm *.korm *.o在test.c和Makefile所在的目录下运行make如果看到类似输出make -C /usr/src/linux-source-2.6.15/ M/home/vmeth modulesmake[1]: Entering directory /usr/src/linux-source-2.6.15CC [M] /home/vmeth/hello.oBuilding modules, stage 2.MODPOSTCC /home/vmeth/hello.mod.oLD [M] /home/vmeth/hello.komake[1]: Leaving directory /usr/src/linux-source-2.6.15一般用下面的Makefile# Makefile2.6ifneq ($(KERNELRELEASE),)#kbuild syntax. dependency relationshsip of files and target modules are listed here.mymodule-objs : hello.oobj-m : hello.oelsePWD : $(shell pwd)KVER ? $(shell uname -r)KDIR : /lib/modules/$(KVER)/buildall:$(MAKE) -C $(KDIR) M$(PWD)clean:rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versionsendifKERNELRELEASE 是在内核源码的顶层Makefile中定义的一个变量在第一次读取执行此Makefile时KERNELRELEASE没有被定义所以make将读取执行else之后的内容。当make的目标为all时-C $(KDIR) 指明跳转到内核源码目录下读取那里的MakefileM$(PWD) 表明然后返回到当前目录继续读入、执行当前的Makefile。当从内核源码目录返回时KERNELRELEASE已被被定义kbuild也被启动去解析kbuild语法的语句make将继续读取else之前的内容。else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系以及要生成的目标模块名。每个内核的名字都包含了它的版本号这也是 uname -r 命令显示的值。下面附件中是一个例子