第十一章 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

相关文章

Apache Ignite 与 Spring Boot 集成详细指南

《ApacheIgnite与SpringBoot集成详细指南》ApacheIgnite官方指南详解如何通过SpringBootStarter扩展实现自动配置,支持厚/轻客户端模式,简化Ign... 目录 一、背景:为什么需要这个集成? 二、两种集成方式(对应两种客户端模型) 三、方式一:自动配置 Thick

Python实现网格交易策略的过程

《Python实现网格交易策略的过程》本文讲解Python网格交易策略,利用ccxt获取加密货币数据及backtrader回测,通过设定网格节点,低买高卖获利,适合震荡行情,下面跟我一起看看我们的第一... 网格交易是一种经典的量化交易策略,其核心思想是在价格上下预设多个“网格”,当价格触发特定网格时执行买

Python标准库之数据压缩和存档的应用详解

《Python标准库之数据压缩和存档的应用详解》在数据处理与存储领域,压缩和存档是提升效率的关键技术,Python标准库提供了一套完整的工具链,下面小编就来和大家简单介绍一下吧... 目录一、核心模块架构与设计哲学二、关键模块深度解析1.tarfile:专业级归档工具2.zipfile:跨平台归档首选3.

idea的终端(Terminal)cmd的命令换成linux的命令详解

《idea的终端(Terminal)cmd的命令换成linux的命令详解》本文介绍IDEA配置Git的步骤:安装Git、修改终端设置并重启IDEA,强调顺序,作为个人经验分享,希望提供参考并支持脚本之... 目录一编程、设置前二、前置条件三、android设置四、设置后总结一、php设置前二、前置条件

python设置环境变量路径实现过程

《python设置环境变量路径实现过程》本文介绍设置Python路径的多种方法:临时设置(Windows用`set`,Linux/macOS用`export`)、永久设置(系统属性或shell配置文件... 目录设置python路径的方法临时设置环境变量(适用于当前会话)永久设置环境变量(Windows系统

python中列表应用和扩展性实用详解

《python中列表应用和扩展性实用详解》文章介绍了Python列表的核心特性:有序数据集合,用[]定义,元素类型可不同,支持迭代、循环、切片,可执行增删改查、排序、推导式及嵌套操作,是常用的数据处理... 目录1、列表定义2、格式3、列表是可迭代对象4、列表的常见操作总结1、列表定义是处理一组有序项目的

python运用requests模拟浏览器发送请求过程

《python运用requests模拟浏览器发送请求过程》模拟浏览器请求可选用requests处理静态内容,selenium应对动态页面,playwright支持高级自动化,设置代理和超时参数,根据需... 目录使用requests库模拟浏览器请求使用selenium自动化浏览器操作使用playwright

python使用try函数详解

《python使用try函数详解》Pythontry语句用于异常处理,支持捕获特定/多种异常、else/final子句确保资源释放,结合with语句自动清理,可自定义异常及嵌套结构,灵活应对错误场景... 目录try 函数的基本语法捕获特定异常捕获多个异常使用 else 子句使用 finally 子句捕获所

Mysql中设计数据表的过程解析

《Mysql中设计数据表的过程解析》数据库约束通过NOTNULL、UNIQUE、DEFAULT、主键和外键等规则保障数据完整性,自动校验数据,减少人工错误,提升数据一致性和业务逻辑严谨性,本文介绍My... 目录1.引言2.NOT NULL——制定某列不可以存储NULL值2.UNIQUE——保证某一列的每一

C++11范围for初始化列表auto decltype详解

《C++11范围for初始化列表autodecltype详解》C++11引入auto类型推导、decltype类型推断、统一列表初始化、范围for循环及智能指针,提升代码简洁性、类型安全与资源管理效... 目录C++11新特性1. 自动类型推导auto1.1 基本语法2. decltype3. 列表初始化3