Linux移植之auto.conf、autoconf.h、Mach-types.h的生成过程简析

Linux移植之make uImage编译过程分析中分析了uImage文件产生的过程,在uImage产生的过程中,顺带还产生了其它的一些中间文件。这里主要介绍几个比较关键的文件

1、linux-2.6.22.6includeconfigauto.conf、inux-2.6.22.6includelinuxautoconf.h文件的生成过程

2、includeasm-armMach-types.h文件的生成过程

1、inux-2.6.22.6includeconfigauto.conf、inux-2.6.22.6includelinuxautoconf.h文件的生成过程

在顶层Makefile中尝试寻找auto.conf,找到如下信息:可以看到顶层Makefile中需要包含-include include/config/auto.conf、-include include/config/auto.conf.cmd。-include表示即使文件不存在也不会报错。

442    # Read in config
443    -include include/config/auto.conf
444
445    ifeq ($(KBUILD_EXTMOD),)
446    # Read in dependencies to all Kconfig* files, make sure to run
447    # oldconfig if changes are detected.
448    -include include/config/auto.conf.cmd
449
450    # To avoid any implicit rule to kick in, define an empty command
451    $(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
452
453    # If .config is newer than include/config/auto.conf, someone tinkered
454    # with it and forgot to run make oldconfig.
455    # if auto.conf.cmd is missing then we are probably in a cleaned tree so
456    # we execute the config step to be sure to catch updated Kconfig files
457    include/config/auto.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
458        $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig

继续分析生成include/config/auto.conf目标的语句

457    include/config/auto.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
458        $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig

可以看到依赖KCONFIG_CONFIG其实就是.config

192    KCONFIG_CONFIG    ?= .config
依赖include/config/auto.conf.cmd,这条语句知道,该语句中的目标没有依赖,也没有生成它的规则命令,所以可想GNU Make本身无法生成auto.conf.cmd 的。
451    $(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
然后该条语句后面的一个分号表明,这两个目标被强制是最新的,所以下面这条命令得以执行:
458        $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig

继续往下分析发现这条命令是执行顶层的Makefile生成silentoldconfig目标。找到生成这个目标的规则:

416    config %config: scripts_basic outputmakefile FORCE
417        $(Q)mkdir -p include/linux include/config
418        $(Q)$(MAKE) $(build)=scripts/kconfig $@

这个规则在Linux移植之配置过程分析已经分析过。所以直接去到scripts/kconfig/Makefile找到silentoldconfig目标的规则:

22    silentoldconfig: $(obj)/conf
23        $< -s arch/$(ARCH)/Kconfig

可以看到它依赖于scripts/kconfig/conf这个程序,这个程序的编译过程就不分析了,继续看到规则,将规则展开得到

23        conf -s arch/arm/Kconfig

所以需要知道conf的功能,那么就去要看它的源码。在这里简单说明一下它的功能:其实就是调用.config文件,保证了 .config 已经最新后,那么调用 conf_write_autoconf() 生成 auto.conf,auto.conf.cmd 以及 autoconf.h 这 3 个文件。详情分析参考https://blog.csdn.net/lcw_202/article/details/6661364

2、includeasm-armMach-types.h文件的生成过程,在分析内核源码时发现这个文件如果没有编译的话是不存在的,它存放着单板机器编码,这个编码就是与uboot传入的编码比较的。比如#define MACH_TYPE_S3C2440              362。

来到arch/arm/Makefile文件中,看到如下几条命令:

221    maketools: include/linux/version.h include/asm-arm/.arch FORCE
222        $(Q)$(MAKE) $(build)=arch/arm/tools include/asm-arm/mach-types.h

这个分析过程类似于第一点产生文件的过程,来到arch/arm/tools/Makefile中,可以看到nclude/asm-arm/mach-types.h是由

7    include/asm-arm/mach-types.h: $(src)/gen-mach-types $(src)/mach-types
8    @echo '  Generating $@'
9    $(Q)$(AWK) -f $^ > $@ || { rm -f $@; /bin/false; }

将第9行命令展开得到,它的意思是利用arch/arm/tools/mach-types程序产生include/asm-arm/mach-types.h文件,如果不成功,则删除。其中arch/arm/tools/mach-types是内核一开始就做好的工具。

awk -f arch/arm/tools/gen-mach-types arch/arm/tools/mach-types > include/asm-arm/mach-types.h || { rm -f include/asm-arm/mach-types.h; /bin/false; }
 
原文地址:https://www.cnblogs.com/andyfly/p/9399926.html