第十一章 U-boot 顶层 Makefile 详解 (make xxx_defconfig 过程)

2024-04-07 12:52

本文主要是介绍第十一章 U-boot 顶层 Makefile 详解 (make xxx_defconfig 过程),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

11.2.13 make xxx_defconfig 过程

        在编译 uboot 之前要使用“make xxx_defconfig”命令来配置 uboot,在顶层 Makefile 中有如下代码:

475 # To make sure we do not include .config for any of the *config
476 # targets catch them early, and hand them over to
477 # scripts/kconfig/Makefile It is allowed to specify more targets
478 # when calling make, including mixing *config targets and build
479 # targets.For example 'make oldconfig all'.
480 # Detect when mixed targets is specified, and make a second
481 # invocation of make so .config is not included in this case either(for *config).
482
483 version_h := include/generated/version_autogenerated.h
484 timestamp_h := include/generated/timestamp_autogenerated.h
485 defaultenv_h := include/generated/defaultenv_autogenerated.h
486
487 no-dot-config-targets := clean clobber mrproper distclean \
488 help %docs check% coccicheck \
489 ubootversion backup tests check qcheck
490
491 config-targets := 0
492 mixed-targets := 0
493 dot-config := 1
494
495 ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
496    ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
497        dot-config := 0
498    endif
499 endif
500
501 ifeq ($(KBUILD_EXTMOD),)
502    ifneq ($(filter config %config,$(MAKECMDGOALS)),)
503         config-targets := 1
504         ifneq ($(words $(MAKECMDGOALS)),1)
505            mixed-targets := 1
506            endif
507    endif
508 endif
509
510 ifeq ($(mixed-targets),1)
511 # ==============================================================
512 # We're called with mixed targets (*config and build targets).
513 # Handle them one by one.
514
515 PHONY += $(MAKECMDGOALS) __build_one_by_one
516
517 $(filter-out __build_one_by_one, $(MAKECMDGOALS)):
__build_one_by_one
518    @:
519
520 __build_one_by_one:
521 $(Q)set -e; \
522 for i in $(MAKECMDGOALS); do \
523    $(MAKE) -f $(srctree)/Makefile $$i; \
524    done
525
526 else
527 ifeq ($(config-targets),1)
528 # ================================================================
529 # *config targets only - make sure prerequisites are updated, and
530 # descend in scripts/kconfig to make the *config target
531
532 KBUILD_DEFCONFIG := sandbox_defconfig
533 export KBUILD_DEFCONFIG KBUILD_KCONFIG
534
535 config: scripts_basic outputmakefile FORCE
536    $(Q)$(MAKE) $(build)=scripts/kconfig $@
537
538 %config: scripts_basic outputmakefile FORCE
539    $(Q)$(MAKE) $(build)=scripts/kconfig $@
540
541 else
542 # ================================================================
543 # Build targets only - this includes vmlinux, arch specific
544 # targets, clean targets and others. In general all targets except*config targets.
545
546 # Additional helpers built in scripts/
547 # Carefully list dependencies so we do not try to build scripts
548 # twice in parallel
549 PHONY += scripts
550 scripts: scripts_basic include/config/auto.conf
551    $(Q)$(MAKE) $(build)=$(@)
552
553 ifeq ($(dot-config),1)
554 # Read in config
555 -include include/config/auto.conf
......

        第 483 行定义了变量 version_h,这变量保存版本号文件,此文件是自动生成的。文件include/generated/version_autogenerated.h。
        第 484 行定义了变量 timestamp_h,此变量保存时间戳文件,此文件也是自动生成的。文件
include/generated/timestamp_autogenerated.h。
        第 487 行定义了变量 no-dot-config-targets。
        第 491 行定义了变量 config-targets,初始值为 0。
        第 492 行定义了变量 mixed-targets,初始值为 0。
        第 493 行定义了变量 dot-config,初始值为 1。
        第 495 行将 MAKECMDGOALS 中不符合 no-dot-config-targets 的部分过滤掉,剩下的如果
不为空的话条件就成立。 MAKECMDGOALS 是 make 的一个环境变量,这个变量会保存你所指
定的终极目标列表。如执行“make mx6ull_alientek_emmc_defconfig”,那么MAKECMDGOALS就为 mx6ull_alientek_emmc_defconfig。很明显过滤后为空,所以条件不成立,变量 dot-config 依旧为 1。
        第 501 行判断 KBUILD_EXTMOD 是否为空,如果 KBUILD_EXTMOD 为空的话条件成立,经过前面的分析,我们知道 KBUILD_EXTMOD 为空,所以条件成立。
        第 502 行将 MAKECMDGOALS 中不符合“config”和“%config”的部分过滤掉,如果剩下的部分不为空条件就成立,很明显此处条件成立,变量 config-targets=1。
        第 504 行统计 MAKECMDGOALS 中的单词个数,如果不为 1 的话条件成立。此处调用Makefile 中的 words 函数来统计单词个数,words 函数格式如下:

$(words <text>)

        很明显,MAKECMDGOALS 的单词个数是 1 个,所以条件不成立,mixed-targets 继续为0。综上所述,这些变量值如下:

config-targets = 1
mixed-targets = 0
dot-config = 1

        第 510 行如果变量 mixed-targets 为 1 的话条件成立,很明显,条件不成立。
        第 527 行如果变量 config-targets 为 1 的话条件成立,很明显,条件成立,执行这个分支。
        第 535 行,没有目标与之匹配,所以不执行。
        第 538 行,有目标与之匹配,当输入“make xxx_defconfig”的时候就会匹配到%config 目标,目标“%config”依赖于 scripts_basic、outputmakefile 和 FORCE。FORCE 在顶层 Makefile后面有如下定义:

2166 PHONY += FORCE
2167 FORCE:

        可以看出 FORCE 是没有规则和依赖的,所以每次都会重新生成 FORCE。当 FORCE 作为其他目标的依赖时,由于 FORCE 总是被更新过的,因此依赖所在的规则总是会执行的。依赖scripts_basic 和 outputmakefile 在顶层 Makefile 中的内容如下:

455 # Basic helpers built in scripts/
456 PHONY += scripts_basic
457 scripts_basic:
458     $(Q)$(MAKE) $(build)=scripts/basic
459     $(Q)rm -f .tmp_quiet_recordmcount
460
461 # To avoid any implicit rule to kick in, define an empty command.
462 scripts/basic/%: scripts_basic ;
463
464 PHONY += outputmakefile
465 # outputmakefile generates a Makefile in the output directory, if
466 # using a separate output directory. This allows convenient use of
467 # make in the output directory.
468 outputmakefile:
469 ifneq ($(KBUILD_SRC),)
470     $(Q)ln -fsn $(srctree) source
471     $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
472         $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
473 endif

        第 469 行 , 判断 KBUILD_SRC 是 否 为空 , 只有变 量 KBUILD_SRC 不空时,outputmakefile 才有意义,经过我们前面的分析 KBUILD_SRC 为空,所以 outputmakefile 无效。只有 scripts_basic 是有效的。
        第 457~459 行是 scripts_basic 的规则,其对应的命令用到了变量 Q、MAKE 和 build,其中

Q=@或为空
MAKE=make

        变量 build 是在 scripts/Kbuild.include 文件中有定义:

178 ###
179 # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
180 # Usage:
181 # $(Q)$(MAKE) $(build)=dir
182 build := -f $(srctree)/scripts/Makefile.build obj

        从示例代码 11.2.13.4 可以看出 build=-f $(srctree)/scripts/Makefile.build obj,经过前面的分析可知,变量 srctree 为”.”,因此:

build=-f ./scripts/Makefile.build obj

        scripts_basic 展开以后如下:

scripts_basic:
@make -f ./scripts/Makefile.build obj=scripts/basic //也可以没有@,视配置而定
@rm -f . tmp_quiet_recordmcount
//也可以没有@

        scripts_basic 会调用文件./scripts/Makefile.build,这个我们后面再分析。接着回到示例代码 中的%config 处,内容如下:

%config: scripts_basic outputmakefile FORCE
$(Q)$(MAKE) $(build)=scripts/kconfig $@

将命令展开就是:

@make -f ./scripts/Makefile.build obj=scripts/kconfig xxx_defconfig

        同样也跟文件./scripts/Makefile.build 有关,我们后面再分析此文件。使用如下命令配置 uboot,并观察其配置过程:

make stm32mp15_atk_defconfig V=1

配置过程如图 所示:

 从图 11.2.13.1 可以看出,我们的分析是正确的,接下来就要结合下面两行命令重点分析一下文件 scripts/Makefile.build。
1、scripts_basic 目标对应的命令
                @make -f ./scripts/Makefile.build obj=scripts/basic
2、%config 目标对应的命令
                @make -f ./scripts/Makefile.build obj=scripts/kconfig xxx_defconfig

这篇关于第十一章 U-boot 顶层 Makefile 详解 (make xxx_defconfig 过程)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/882652

相关文章

springboot3.x使用@NacosValue无法获取配置信息的解决过程

《springboot3.x使用@NacosValue无法获取配置信息的解决过程》在SpringBoot3.x中升级Nacos依赖后,使用@NacosValue无法动态获取配置,通过引入SpringC... 目录一、python问题描述二、解决方案总结一、问题描述springboot从2android.x

Python容器转换与共有函数举例详解

《Python容器转换与共有函数举例详解》Python容器是Python编程语言中非常基础且重要的概念,它们提供了数据的存储和组织方式,下面:本文主要介绍Python容器转换与共有函数的相关资料,... 目录python容器转换与共有函数详解一、容器类型概览二、容器类型转换1. 基本容器转换2. 高级转换示

MySQL数据目录迁移的完整过程

《MySQL数据目录迁移的完整过程》文章详细介绍了将MySQL数据目录迁移到新硬盘的整个过程,包括新硬盘挂载、创建新的数据目录、迁移数据(推荐使用两遍rsync方案)、修改MySQL配置文件和重启验证... 目录1,新硬盘挂载(如果有的话)2,创建新的 mysql 数据目录3,迁移 MySQL 数据(推荐两

HTML5的input标签的`type`属性值详解和代码示例

《HTML5的input标签的`type`属性值详解和代码示例》HTML5的`input`标签提供了多种`type`属性值,用于创建不同类型的输入控件,满足用户输入的多样化需求,从文本输入、密码输入、... 目录一、引言二、文本类输入类型2.1 text2.2 password2.3 textarea(严格

MyBatis-Plus逻辑删除实现过程

《MyBatis-Plus逻辑删除实现过程》本文介绍了MyBatis-Plus如何实现逻辑删除功能,包括自动填充字段、配置与实现步骤、常见应用场景,并展示了如何使用remove方法进行逻辑删除,逻辑删... 目录1. 逻辑删除的必要性编程1.1 逻辑删除的定义1.2 逻辑删php除的优点1.3 适用场景2.

C++ move 的作用详解及陷阱最佳实践

《C++move的作用详解及陷阱最佳实践》文章详细介绍了C++中的`std::move`函数的作用,包括为什么需要它、它的本质、典型使用场景、以及一些常见陷阱和最佳实践,感兴趣的朋友跟随小编一起看... 目录C++ move 的作用详解一、一句话总结二、为什么需要 move?C++98/03 的痛点⚡C++

MySQL中between and的基本用法、范围查询示例详解

《MySQL中betweenand的基本用法、范围查询示例详解》BETWEENAND操作符在MySQL中用于选择在两个值之间的数据,包括边界值,它支持数值和日期类型,示例展示了如何使用BETWEEN... 目录一、between and语法二、使用示例2.1、betwphpeen and数值查询2.2、be

python中的flask_sqlalchemy的使用及示例详解

《python中的flask_sqlalchemy的使用及示例详解》文章主要介绍了在使用SQLAlchemy创建模型实例时,通过元类动态创建实例的方式,并说明了如何在实例化时执行__init__方法,... 目录@orm.reconstructorSQLAlchemy的回滚关联其他模型数据库基本操作将数据添

Java中ArrayList与顺序表示例详解

《Java中ArrayList与顺序表示例详解》顺序表是在计算机内存中以数组的形式保存的线性表,是指用一组地址连续的存储单元依次存储数据元素的线性结构,:本文主要介绍Java中ArrayList与... 目录前言一、Java集合框架核心接口与分类ArrayList二、顺序表数据结构中的顺序表三、常用代码手动

Spring Boot Interceptor的原理、配置、顺序控制及与Filter的关键区别对比分析

《SpringBootInterceptor的原理、配置、顺序控制及与Filter的关键区别对比分析》本文主要介绍了SpringBoot中的拦截器(Interceptor)及其与过滤器(Filt... 目录前言一、核心功能二、拦截器的实现2.1 定义自定义拦截器2.2 注册拦截器三、多拦截器的执行顺序四、过