原文网址:http://blog.csdn.net/nxh_love/article/details/11846861

最新在做Sensor驱动移植的时候,发现了Android driver 中有Kconfig,Makefile文件。在查看编译后的文件时,又发现还存在.config文件。自己对这几个文件不明白,用度娘来整理下网友对这几个文件的理解。

分布在各目录下的Kconfig构成了一个分布式的内核配置数据库,每个Kconfig分别描述了所属目录源文件相关的内核配置菜单。在内核配置make menuconfig(或xconfig等)时,从Kconfig中读出配置菜单,用户配置完后保存到.config(在顶层目录下生成)中。在内核编译时,主Makefile调用这个.config,就知道了用户对内核的配置情况。Kconfig就是对应着内核的配置菜单。假如要想添加新的驱动到内核的源码中,可以通过修改Kconfig来增加对我们驱动的配置菜单,这样就有途径选择我们的驱动,假如想使这个驱动被编译,还要修改该驱动所在目录下的Makefile。

Kconfig

先来看下一个相对完整的Kconfig文件:

  1. menuconfig MISC_DEVICES
  2. bool "Misc devices"
  3. ---help---
  4. Say Y here to get to see options for device drivers from various
  5. different categories. This option alone does not add any kernel code.
  6. If you say N, all options in this submenu will be skipped and disabled.
  7. if MISC_DEVICES
  8. config ST_L3GD20_GYR
  9. tristate "L3GD20_GYR gyroscope sensor support"
  10. depends on I2C=y
  11. help
  12. If you say yes here you get support for ST's
  13. gyroscope sensors L3GD20_GYR.
  14. choice
  15. prompt "Preemption Model"
  16. depends on SENSORS_AFA750
  17. default CALI_NONE
  18. config CALI_NONE
  19. bool "None"
  20. help
  21. Say yes here to disable calibration function for AFA750
  22. config CALI_POSITIVE
  23. bool "positive calibration"
  24. help
  25. Say yes here when the afa750 and LCD are laid towared the same direction on your board
  26. endchoice
  27. config SENSORS_LSM303D
  28. tristate "LSM303 sensor driver"
  29. depends on I2C=y
  30. help
  31. Say yes here to support the sensor
  32. endif

1.语法:
           config   symbol
                         options
           symbol是一个新的标记的菜单项,options是在这个新的菜单项下的属性和选项。

2.菜单结构:

配置文件描述了菜单选项,每行都是以一关键字开头(除了帮助信息)。下面的关键字结束一菜单选项:
         - config
        - menuconfig
        - choice/endchoice
        - comment
        - menu/endmenu
        - if/endif
        - source
2.options类型定义:
        每个config菜单项都要有类型定义:bool布尔类型、 tristate三态(内建、模块、移除)、 string字符串、 hex十六进制、 integer整型。

例如:

  1. config CALI_NONE
  2. bool "None"

bool类型的只能选中或不选中,tristate类型的菜单项多了编译成内核模块的选项,如果选择编译成内核模块,则会在.config中生成一个CONFIG_CALI_NONEE=m的配置,如果选择内建,就是直接编译成内核影响,就会在.config中生成一个CONFIG_CALI_NONE=y的配置.

3.依赖型定义depends on或requires
           指此菜单的出现与否依赖于另一个定义

  1. config SENSORS_LSM303D
  2. tristate "LSM303 sensor driver"
  3. depends on I2C=y

这个例子表明SENSORS_LSM303D这个菜单项只I2C有效。

4.select与depends on是相反的逻辑关系。
           A depends on B
           那么只有在B选中才能选A
           A select B
          那么只要选中A就会选中B
5.帮助性定义
           只是增加帮助用关键字help或者---help---,"---help---" 和 "help" 在实现的作用上没有区别,"---help---" 有助于将文件中的配置逻辑与给开发人员的提示分开。

6.prompt --输入提示

Makefile

1.顶层的Makefile文档读取 .config文档的内容,并总体上负责build内核和模块。
2.Arch Makefile则提供补充体系结构相关的信息。 
3.scripts目录下的Makefile文档包含了任何用来根据kbuild Makefile 构建内核所需的定义和规则。
            其中.config的内容是在make menuconfig的时候,通过Kconfig文档配置的结果,在/Documentation/kbuild目录下有详细的介绍有关kernel makefile的知识。

举个例子:

假设想把G-sensor LSM303D驱动code加载到工程中,配置内核时该怎么办呢?
1:将您写的lsm303d.c 文档添加到/driver/misc/ 目录下。
2:修改/driver/misc/ 目录下的kconfig文档:

  1. config SENSORS_LSM303D
  2. tristate "LSM303 sensor driver"
  3. depends on I2C=y
  4. help
  5. Say yes here to support the sensor

3:修改该目录下makefile文档。
添加code:

  1. obj-$(CONFIG_SENSORS_LSM303D)   += lsm303d.o

从上述分析知道CONFIG_SENSORS_LSM303D 是从.config 中读出的。
4.配置kernel下configs/XXXX_defconfig文件
添加code:

  1. CONFIG_SENSORS_LSM303D=y

当您编译内核时,将会读取.config文档,当发现CONFIG_SENSORS_LSM303D=y,系统在调用/driver/misc下的makefile 时,将会把 lsm303d.o 加入到内核中。即可达到您的目的。

主要参考文章:http://blog.sina.com.cn/s/blog_4a377e150100c896.html

【转】Kconfig,Makefile 和 .config的更多相关文章

  1. OpenWRT添加模块 Makefile和Config.in

    添加模块编译 在网上找了一下,很多关于编译Openwrt系统的资料,不过这些事情芯片厂商提供的开发包都已经办得妥妥了,但是没有找到系统介绍的资料,添加一个包的介绍有不多,其中有两个很有参考价值: ht ...

  2. 【转】Android(4.2) Sensors 学习——G-sensor,Gyroscope驱动移植

    原文网址:http://blog.csdn.net/nxh_love/article/details/11804841 本人对驱动可谓是一点不懂,鉴于公司目前高驱动的人手不够,所以我也只能两眼一抹黑硬 ...

  3. ubuntu——Kconfig、.config、Makefile的关系

    原文地址:http://blog.csdn.net/estate66/article/details/5886816 ,本人对此文有改进. 当我们编写完一个驱动后,我们要把它以模块形式编译或者直接编译 ...

  4. Kbuild、Kconfig、make menuconfig、.config、Makefile之间的关系

    今天突发奇想,想在这里分享下比喻分析Kbuild ---->去饭店吃饭的过程.   1.Kconfig --->饭店的菜单 2.条件编译选项--->菜单中的每一盘菜,可以选择这个菜的 ...

  5. Linux kernel的 Makefile和Kconfig以及Make menuconfig的关系【转】

    本文转载自:http://blog.sina.com.cn/s/blog_4ba5b45e0102e6vp.html 熟悉内核的Makefile对开发设备驱动.理解内核代码结构都是非常重要的linux ...

  6. Linux ARM kernel Makefile and Kconfig

    kernel build:顶层Makefile:-->1. include build/main.mk    -->2. include build/kernel.mk         k ...

  7. Linux Kconfig及Makefile学习

    内核源码树的目录下都有两个文档Kconfig (2.4版本是Config.in)和Makefile.分布到各目录的Kconfig构成了一个分布式的内核配置数据库,每个Kconfig分别描述了所属目录源 ...

  8. Linux Kernel的Makefile与Kconfig文件的语法

    https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt Introduction ------------ The c ...

  9. kernel Makefile Kconfig说明

    实际文档位置:Documentation/kbuild/makefiles.txt,此为翻译稿. *************************************************** ...

随机推荐

  1. [转]Ubuntu Linux 安装 .7z 解压和压缩文件

    原文网址:http://blog.csdn.net/zqlovlg/article/details/8033456 安装方法: sudo apt-get install p7zip-full 解压文件 ...

  2. Delphi 调试 通过BreakPoint

    1.打个断点, 如下图 2. 在断点上,邮件,如下图 3. 弹出一个窗体 ,如下图 在 condition 中写条件就可以了.  这样就可以按你假设的条件来进行了,方便.

  3. 股票市场问题(The Stock Market Problem)

    Question: Let us suppose we have an array whose ith element gives the price of a share on the day i. ...

  4. 什么是空间复杂度(What is actually Space Complexity ?)

    属于空间复杂度(Space Complexity)在很多情况下被错认为是附属空间(Auxiliary Space),下面是附属空间和空间复杂度的定义. 附属空间(Auxiliary Space)是算法 ...

  5. Corrupted MAC on input

    Corrupted MAC on input Incorrect MAC received on packet

  6. 深入理解linux网络技术内幕读书笔记(一)--简介

    Table of Contents 1 基本术语 1.1 本书常用的缩写 2 引用计数 2.1 引用计数函数 3 垃圾回收 3.1 异步 3.2 同步 4 函数指针 4.1 缺点 5 goto语句 5 ...

  7. JVM运行时内存结构

    原文转载自:http://my.oschina.net/sunchp/blog/369707 1.JVM内存模型 JVM运行时内存=共享内存区+线程内存区 1).共享内存区 共享内存区=持久带+堆 持 ...

  8. Android 百度地图API(01)_开发环境 HelloBaiduMap

    转载于:http://blog.csdn.net/lmj623565791/article/details/37729091 转载于:http://blog.csdn.net/crazy1235/ar ...

  9. Laravel-表单篇-零散信息

    1.asset('path'):用于引入静态文件,包括css.js.img 2.分页,调用模型的paginate(每页显示的行数)方法, 如$student = Student::paginate(2 ...

  10. jsp filter登录限制过滤器

    http://www.cnblogs.com/hemingwang0902/archive/2012/01/09/2316956.html UserFilter.java package filter ...