编译kernel:配置

韦东山Linux视频第1期_裸板_UBoot_文件系统_驱动初步\第10课第2节 内核启动流程分析之配置.WMV

 

下面以DM9000的配置为例:

在一个编译好的内核代码里,寻找CONFIG_DM9000所在位置: s3c2410_defconfig, c代码, 头文件, auto.conf, 相应子目录的makefile.
arch/arm/plat-s3c24xx/common-smdk.c:250:#if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
arch/arm/configs/s3c2410_defconfig:588:CONFIG_DM9000=y
drivers/net/Makefile:197:obj-$(CONFIG_DM9000) += dm9dev9000c.o
drivers/net/Makefile:198:#obj-$(CONFIG_DM9000) += dm9000.o
drivers/net/Makefile:199:#obj-$(CONFIG_DM9000) += dm9ks.o
include/config/auto.conf:144:CONFIG_DM9000=y
include/linux/autoconf.h:145:#define CONFIG_DM9000 1

 

相关配置编译过程:

1. make menuconfig选配生成.config

2. make uImage的过程中, 根据.config生成中间文件include/linux/autoconf.h以及config/auto.conf.

include/linux/autoconf.h是给arch/arm/plat-s3c24xx/common-smdk.c引用的;

config/auto.conf是给顶层以及子目录的drivers/net/Makefile引用的,makefile里面根据config/auto.conf决定是否编译,和编译的方式(编译进内核/编译成模块).

 

——————————————————————————

 

关于menuconfig:

  1). menuconfig的菜单选项是如何得来的呢?

    在内核中增加目录和子目录,我们需为相应的新增目录创建 Kconfig 和 Makefile 文件,而新增目录的父目录中的 Kconfig 和 Makefile 文件也需要修改,以便新增的 Kconfig 和 Makefile 文件能被引用.

    具体参考Makefile Kconfig 内核配置————怎样在menuconfig中添加一个菜单选项  http://blog.csdn.net/tanqiuwei/article/details/7318555

 

  2).如何在menuconfig中选配的驱动或者功能模块呢?

    以UNIX98_PTYS为例, 我们在Kconfig里面增加了CONFIG_UNIX98_PTYS的菜单描述.

    在menuconfig菜单里面输入/进入搜索界面,输入UNIX98_PTYS,确定,可以看到UNIX98_PTYS的定义/位置/依赖关系等相关信息.

 

首先depend项必须选中, "for small systems",即EMBEDDED.

 

可以看到因为default y,  默认是选中编译到内核中的.  此外还有defaule m, 默认编译为模块. default n, 默认不编译.

 

3). 在menuconfig选配的驱动或者功能模块是如何被内核编译到的呢?

  step1: make menuconfig时,引用各级Kconfig生成菜单选项,用户选定后,生成.config;

    step2: 主Makefile以及各级Makefile 引用.config 里面的宏定义选项(同时还要引用各级写好的Kbuild),生成宏定义头文件(  /include/linux/autoconf.h :#define CONFIG_ARM 1 )并编译内核。 

  UNIX98_PTYS为例, 看目录层次:

linux-2.6.22.6MakefileKCONFIG_CONFIG ?= .config

linux-2.6.22.6/.config:CONFIG_UNIX98_PTYS=y  【或 =m  , 或CONFIG_UNIX98_PTYS  is not set

linux-2.6.22.6/drivers/char/Makefile  : obj-$(CONFIG_UNIX98_PTYS) += pty.o

linux-2.6.22.6/drivers/char/Kconfig:
config UNIX98_PTYS
        bool "Unix98 PTY support" if EMBEDDED
        default y
        ---help---
          A pseudo terminal (PTY) is a software device consisting of two
          halves: a master and a slave. The slave device ....

=================================================================================

 

Kbuid一般形式: obj-$(xx) += pty.o

   还有部分Kbuid文件和Makefile格式相似.

Kbuild Makefile有特定的语法指定哪些编译进内核中、哪些编译为模块、及对应的源文件是什么等。Kbuild Makefile的文件名不一定是Makefile,尽管推荐使用Makefile这个名字。 大多的Kbuild文件的名字都是Makefile。为了与其他Makefile文件相区别,你也可以指定Kbuild Makefile的名字为Kbuild。

header-y += ipt_ttl.h
header-y += ipt_TTL.h
header-y += ipt_ULOG.h

更多的知识看原文:Linux Kbuild工作原理分析(以DVSDK生成PowerVR显卡内核模块为例) http://www.cnblogs.com/jiangu66/p/3181708.html

 

Kconfig一般形式:

    config VT_CONSOLE
    bool "Support for console on virtual terminal" if EMBEDDED
    depends on VT
    default y
    ---help---
    The system console is the device which receives all kernel messages
    and warnings and which allows logins in single user mode. If you
    answer Y here, a virtual terminal ...

 

.config的一般形式:(make自动生成的)

# CONFIG_BLK_DEV_CRYPTOLOOP is not set
CONFIG_BLK_DEV_NBD=m
# CONFIG_BLK_DEV_UB is not set
CONFIG_BLK_DEV_RAM=y
CONFIG_BLK_DEV_RAM_COUNT=16

 

posted @ 2015-12-14 21:22  oucaijun  阅读(1130)  评论(0编辑  收藏  举报
下载TeamViewer完整版 下载TeamViewer