免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 962 | 回复: 0

ubuntu 内核树 [复制链接]

论坛徽章:
0
发表于 2011-12-21 08:41 |显示全部楼层
    最近学习编写驱动程序,编写驱动,首先要构建内核树,记得以前编写驱动时,直接指定了内核源码的位置,但是在ubuntu上内核版本和源码版本不一致,编译时出了很多错误。在网上搜了一下,才明白,编写模块驱动,首先要构建内核树。ubuntu上不带内核源码,一般的方法是下载内核重新编译一遍,构建内核树。但是这样做有点麻烦,又网上搜集一下,发现ubuntu上自带内核树,在/lib/modules 目录下。

  1. root@wang:/lib/modules/2.6.35-22-generic/build# ls
  2. arch crypto drivers fs init Kbuild lib mm net scripts sound tools usr
  3. block Documentation firmware include ipc kernel Makefile Module.symvers samples security source ubuntu virt
  4. root@wang:/lib/modules/2.6.35-22-generic/build# pwd
  5. /lib/modules/2.6.35-22-generic/build
Makefile 可以这样写:
  1. root@wang:/work/wanghuan/drives# cat Makefile -n
  2.      1    #===============================================================================
  3.      2    # Filename: Makefile
  4.      3    # Description:
  5.      4    #
  6.      5    # Author: wanghuan
  7.      6    # Company:
  8.      7    #
  9.      8    #==============================================================================
  10.      9    
  11.     10    obj-m :=cdev.o #目标文件
  12.     11    KDIR :=/lib/modules/2.6.35-22-generic/build #内核路径
  13.     12    PWD := $(shell pwd) #模块源文件路径
  14.     13    all:    
  15.     14        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
  16.     15        @rm -rf *.mod.*
  17.     16        @rm -rf .*.cmd
  18.     17        @rm -rf *.o
  19.     18        @rm -rf Module.*
  20.     19        chmod a+x cdev.ko
  21.     20    clean:
  22.     21        rm -rf *.ko
                                 
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP