免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1488 | 回复: 0
打印 上一主题 下一主题

嵌入式Linux驱动开发笔记 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-16 21:08 |只看该作者 |倒序浏览

v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}

  Normal
  0
  
  7.8 磅
  0
  2
  
  false
  false
  false
  
   
   
   
   
   
   
   
   
   
   
   
   
  
  MicrosoftInternetExplorer4



st1\:*{behavior:url(#ieooui) }
/* Style Definitions */
table.MsoNormalTable
        {mso-style-name:普通表格;
        mso-tstyle-rowband-size:0;
        mso-tstyle-colband-size:0;
        mso-style-noshow:yes;
        mso-style-parent:"";
        mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
        mso-para-margin:0cm;
        mso-para-margin-bottom:.0001pt;
        mso-pagination:widow-orphan;
        font-size:10.0pt;
        font-family:"Times New Roman";
        mso-ansi-language:#0400;
        mso-fareast-language:#0400;
        mso-bidi-language:#0400;}
嵌入式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 file
Makefile为,
PWD = $(shell pwd)
KERNEL_SRC = /usr/src/linux-source-2.6.15/

obj-m := test.o
module-objs := test.o

all:
       $(MAKE)
-C $(KERNEL_SRC) M=$(PWD) modules
      
clean:
       rm *.ko
       rm *.o
在test.c和Makefile所在的目录下运行make,如果看到类似输出
make -C /usr/src/linux-source-2.6.15/
M=/home/vmeth modules
make[1]: Entering directory `/usr/src/linux-source-2.6.15'
  CC [M]  /home/vmeth/hello.o
  Building modules, stage 2.
  MODPOST
  CC      /home/vmeth/hello.mod.o
  LD [M]  /home/vmeth/hello.ko
make[1]: Leaving directory `/usr/src/linux-source-2.6.15'

一般用下面的Makefile,
# Makefile2.6
ifneq ($(KERNELRELEASE),)
#kbuild syntax. dependency relationshsip of files and
target modules are listed here.
mymodule-objs := hello.o
obj-m := hello.o  
else
PWD  := $(shell
pwd)
KVER ?= $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build
all:
       $(MAKE)
-C $(KDIR) M=$(PWD)
clean:
       rm -rf
.*.cmd *.o *.mod.c *.ko .tmp_versions
endif
KERNELRELEASE 是在内核源码的顶层Makefile中定义的一个变量,在第一次读取执行此Makefile时,KERNELRELEASE没有被定义,所以make将读取执行else之后的内容。
当make的目标为all时,-C $(KDIR) 指明跳转到内核源码目录下读取那里的Makefile;M=$(PWD) 表明然后返回到当前目录继续读入、执行当前的Makefile。
当从内核源码目录返回时,KERNELRELEASE已被被定义,kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。
每个内核的名字都包含了它的版本号,这也是 uname -r 命令显示的值。
下面附件中是一个例子,


  
  
  
  
  
  
  
  
  
  
  
  





       
        文件:MyNotes.rar
        大小:1KB
        下载:
下载
       
1.2       待续

               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/70351/showart_1003342.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP