./scripts/Makefile.autoconf 分析

make -f ./scripts/Makefile.autoconf

# $(srctree)/scripts/Makefile.autoconf
11 __all: include/autoconf.mk include/autoconf.mk.dep
12
13 ifeq ($(shell grep -q '^CONFIG_SPL=y' include/config/auto.conf 2>/dev/null && echo y),y)
14    __all: spl/include/autoconf.mk
15 endif
17 ifeq ($(shell grep -q '^CONFIG_TPL=y' include/config/auto.conf 2>/dev/null && echo y),y)
18    __all: tpl/include/autoconf.mk
19 endif
......
47 include/autoconf.mk.dep: include/config.h FORCE
48    	$(call cmd,autoconf_dep)
......
76 u-boot.cfg: include/config.h FORCE
77    	$(call cmd,u_boot_cfg)
87 include/autoconf.mk: u-boot.cfg
88     	$(call cmd,autoconf)
......
114 include/config.h: scripts/Makefile.autoconf create_symlink FORCE
115 	$(call filechk,config_h)
......
121 PHONY += create_symlink
142 PHONY += FORCE
143 FORCE:
144
145 .PHONY: $(PHONY)


最终展开为:

# $(srctree)/scripts/Makefile.autoconf
11 __all: include/autoconf.mk include/autoconf.mk.dep
......
47 include/autoconf.mk.dep: include/config.h FORCE
48    	$(call cmd,autoconf_dep)
......
76 u-boot.cfg: include/config.h FORCE
77    	$(call cmd,u_boot_cfg)
......
87 include/autoconf.mk: u-boot.cfg
88     	$(call cmd,autoconf)
......
114 include/config.h: scripts/Makefile.autoconf create_symlink FORCE
115 	$(call filechk,config_h)
......
121 PHONY += create_symlink
142 PHONY += FORCE
143 FORCE:
144
145 .PHONY: $(PHONY)

当执行的命令未带目标参数,默认第一个目标(即目标__all)为终极目标。由上可知,终极目标的依赖关系如下图所示:
在这里插入图片描述

由上可知,终极目标__all只有依赖没有创建命令,所以只需创建依赖即可:

  1. 创建include/autoconf.mk,见下面 《1.4 创建 include/autoconf.mk 》 回显 16
    1.1 创建u-boot.cfg,见下面 《1.3 创建 u-boot.cfg》 回显 15
     1.1.1 创建include/config.h,见下面 《1.2 创建 include/config.h 》 回显 14
       1.1.1.1 创建scripts/Makefile.autoconf,在源码中已经存在且没有更新规则,所以这里什么都不做。
       1.1.1.2 创建creat_symlink,见下面《1.1 创建 creat_symlink 》 回显 8-13
       1.1.1.3 创建FORCE,什么都不做。
     1.1.2 生成FORCE,什么都不做。
  2. 创建include/autoconf.mk.dep,见下面 《1.5 创建 include/autoconf.mk.dep》 回显 17
    2.1 创建include/config.h,在上面 <1.1.1> 中已经生成,所以这里什么都不做。
    2.2 创建FORCE,什么都不做。


最终:

  1. arch/arm/mach-bcm283x/include/mach软连接到arch/arm/include/asm/arch 回显 8-13
  2. 执行$(filechk_config_h)命令,将执行结果写入include/config.h文件中, 回显 14
  3. 打印和执行$(cmd_u_boot_cfg)命令,将执行结果写入u-boot.cfg文件中, 回显 15
  4. 打印和执行$(cmd_autoconf)命令,将执行结果写入include/autoconf.mk文件中, 回显 16
  5. 打印和执行$(cmd_autoconf_dep)命令,将执行结果写入include/autoconf.mk.dep文件中, 回显 17


回显 8-17

8 	if [ -d arch/arm/mach-bcm283x/include/mach ]; then	\
9 		dest=../../mach-bcm283x/include/mach;			\
10	else								\
11		dest=arch-bcm283x;			\
12	fi;								\
13	ln -fsn $dest arch/arm/include/asm/arch
14	set -e; mkdir -p include/; 	(echo "/* Automatically generated - do not edit */"; for i in $(echo "" | sed 's/,/ /g'); do echo \#define CONFIG_$i | sed '/=/ {s/=/	/;q; } ; { s/$/	1/; }'; done; echo \#define CONFIG_BOARDDIR board/raspberrypi/rpi; echo \#include \<config_uncmd_spl.h\>; echo \#include \<configs/"rpi".h\>; echo \#include \<asm/config.h\>; echo \#include \<linux/kconfig.h\>; echo \#include \<config_fallbacks.h\>;) < scripts/Makefile.autoconf > include/config.h.tmp; if [ -r include/config.h ] && cmp -s include/config.h include/config.h.tmp; then rm -f include/config.h.tmp; else : '  UPD     include/config.h'; mv -f include/config.h.tmp include/config.h; fi	 
15  /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/arm-linux-gnueabihf-gcc -E -Wall -Wstrict-prototypes -Wno-format-security -fno-builtin -ffreestanding -std=gnu11 -fshort-wchar -fno-strict-aliasing -fno-PIE -O2 -fno-stack-protector -fno-delete-null-pointer-checks  -Wno-maybe-uninitialized  -g -fstack-usage -Wno-format-nonliteral  -Wno-unused-but-set-variable -Werror=date-time  -D__KERNEL__ -D__UBOOT__   -D__ARM__ -marm -mno-thumb-interwork  -mabi=aapcs-linux  -mword-relocations  -fno-pic  -mno-unaligned-access  -ffunction-sections -fdata-sections -fno-common -ffixed-r9  -msoft-float    -pipe -Iinclude  -I./arch/arm/include -include ./include/linux/kconfig.h  -nostdinc -isystem /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/include  -DDO_DEPS_ONLY -dM ./include/common.h > u-boot.cfg.tmp && { grep 'define CONFIG_' u-boot.cfg.tmp > u-boot.cfg; rm u-boot.cfg.tmp; } || { rm u-boot.cfg.tmp; false; }
16  sed -n -f ./tools/scripts/define2mk.sed u-boot.cfg |   while read line; do   if [ -n "" ] || ! grep -q "${line%=*}=" include/config/auto.conf; then   echo "$line";   fi   done > include/autoconf.mk
17  /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/arm-linux-gnueabihf-gcc -x c -DDO_DEPS_ONLY -M -MP   -Wall -Wstrict-prototypes -Wno-format-security -fno-builtin -ffreestanding -std=gnu11 -fshort-wchar -fno-strict-aliasing -fno-PIE -O2 -fno-stack-protector -fno-delete-null-pointer-checks  -Wno-maybe-uninitialized  -g -fstack-usage -Wno-format-nonliteral  -Wno-unused-but-set-variable -Werror=date-time  -D__KERNEL__ -D__UBOOT__   -D__ARM__ -marm -mno-thumb-interwork  -mabi=aapcs-linux  -mword-relocations  -fno-pic  -mno-unaligned-access  -ffunction-sections -fdata-sections -fno-common -ffixed-r9  -msoft-float    -pipe -Iinclude  -I./arch/arm/include -include ./include/linux/kconfig.h  -nostdinc -isystem /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/include   -MQ include/config/auto.conf ./include/common.h > include/autoconf.mk.dep || { rm include/autoconf.mk.dep; false; }

创建
创建软连接,将arch/arm/mach-bcm283x/include/mach软连接到arch/arm/include/asm/arch 回显 8-13
创建 include/config.h 回显 14
创建 u-boot.cfg 回显 15
创建 include/autoconf.mk 回显 16
创建 include/autoconf.mk.dep 回显 17

1.1 创建 creat_symlink

# $(srctree)/scripts/Makefile.autoconf
21 include include/config/auto.conf
31 include config.mk
......
122	create_symlink:
123	ifdef CONFIG_CREATE_ARCH_SYMLINK
124	ifneq ($(KBUILD_SRC),)
125		$(Q)mkdir -p include/asm
126		$(Q)if [ -d $(KBUILD_SRC)/arch/$(ARCH)/mach-$(SOC)/include/mach ]; then	\
127			dest=arch/$(ARCH)/mach-$(SOC)/include/mach;			\
128		else									\
129			dest=arch/$(ARCH)/include/asm/arch-$(if $(SOC),$(SOC),$(CPU));	\
130		fi;									\
131		ln -fsn $(KBUILD_SRC)/$$dest include/asm/arch
132	else
133		$(Q)if [ -d arch/$(ARCH)/mach-$(SOC)/include/mach ]; then	\
134			dest=../../mach-$(SOC)/include/mach;			\
135		else								\
136			dest=arch-$(if $(SOC),$(SOC),$(CPU));			\
137		fi;								\
138		ln -fsn $$dest arch/$(ARCH)/include/asm/arch
139	endif
140	endif
  • 21行:引用include/config/auto.conf,在执行《1.2.1 执行 make -f ./Makefile syncconfig》时创建。
  • 123行:CONFIG_CREATE_ARCH_SYMLINKinclude/config/auto.conf【在21行引用】的52行中定义,所以这里条件成立。
  • 124行:KBUILD_SRC未定义为空,这里条件不成立。
  • 133行:ARCH在输入参数中已经定义make ARCH=arm CROSS_COMPILE=**** V=1 ,所以: ARCH = arm


21行引用的include/config/auto.conf中有如下定义:其中变量都是在配置文件xxx_defconfigKconfig中定义

# include/config/auto.conf
54  CONFIG_SYS_VENDOR="raspberrypi"
66  CONFIG_SYS_CPU="armv7"
112 CONFIG_SYS_EXTRA_OPTIONS=""
122 CONFIG_SYS_BOARD="rpi"
127 CONFIG_SYS_CONFIG_NAME="rpi"
209 CONFIG_SYS_SOC="bcm283x"

31行引用的config.mk中有如下定义:

# config.mk
20 VENDOR :=
24 CPU := $(CONFIG_SYS_CPU:"%"=%)
25 ifdef CONFIG_SPL_BUILD
26    ifdef CONFIG_ARCH_TEGRA
27       CPU := arm720t
28    endif
29 endif
30 BOARD  := $(CONFIG_SYS_BOARD:"%"=%)
31 ifneq ($(CONFIG_SYS_VENDOR),)
32    VENDOR := $(CONFIG_SYS_VENDOR:"%"=%)
33 endif
34 ifneq ($(CONFIG_SYS_SOC),)
35    SOC := $(CONFIG_SYS_SOC:"%"=%)
36 endif

由上可知:

VENDOR=raspberrypi BOARD=rpi CONFIG_SYS_EXTRA_OPTIONS=“”
CONFIG_SYS_CONFIG_NAME=“rpi” CPU=armv7 SOC=bcm283x

最终展开为:

# $(srctree)/scripts/Makefile.autoconf
122	create_symlink:
133		if [ -d arch/arm/mach-bcm283x/include/mach ]; then	\
134			dest=../../mach-bcm283x/include/mach;			\
135		else								\
136			dest=arch-bcm283x;			\
137		fi;								\
138		ln -fsn $dest arch/arm/include/asm/arch

目标create_symlink只有创建规则没有依赖,所以接下来执行目标的创建规则即可。 回显 8-13

  1. 133-137行:由于源码下存在arch/arm/mach-bcm283x/include/mach,所以这里条件成立,
    dest=../../mach-bcm283x/include/mach;
  2. 138行:即将arch/arm/mach-bcm283x/include/mach软连接到arch/arm/include/asm/arch 《ln 命令》


最终:
arch/arm/mach-bcm283x/include/mach软连接到arch/arm/include/asm/arch 回显 8-13


回显 8-13

8 	if [ -d arch/arm/mach-bcm283x/include/mach ]; then	\
9 		dest=../../mach-bcm283x/include/mach;			\
10	else								\
11		dest=arch-bcm283x;			\
12	fi;								\
13	ln -fsn $dest arch/arm/include/asm/arch

创建
创建软连接,将arch/arm/mach-bcm283x/include/mach软连接到arch/arm/include/asm/arch 回显 8-13

1.2 创建 include/config.h

# $(srctree)/scripts/Makefile.autoconf
21 include include/config/auto.conf
31 include config.mk
......
100 define filechk_config_h
101     (echo "/* Automatically generated - do not edit */";		\
102     for i in $$(echo $(CONFIG_SYS_EXTRA_OPTIONS) | sed 's/,/ /g'); do \
103     echo \#define CONFIG_$$i				\
104     | sed '/=/ {s/=/	/;q; } ; { s/$$/	1/; }'; \
105     done;								\
106     echo \#define CONFIG_BOARDDIR board/$(if $(VENDOR),$(VENDOR)/)$(BOARD);\
107     echo \#include \<config_uncmd_spl.h\>;				\
108     echo \#include \<configs/$(CONFIG_SYS_CONFIG_NAME).h\>;		\
109     echo \#include \<asm/config.h\>;				\
110     echo \#include \<linux/kconfig.h\>;				\
111     echo \#include \<config_fallbacks.h\>;)
112 endef
114 include/config.h: scripts/Makefile.autoconf create_symlink FORCE
115 	$(call filechk,config_h)

由上面的《1.1 创建 creat_symlink 》分析可知:

VENDOR=raspberrypi BOARD=rpi CONFIG_SYS_EXTRA_OPTIONS=“”
CONFIG_SYS_CONFIG_NAME=“rpi” CPU=armv7 SOC=bcm283x

最后展开为:

# $(srctree)/scripts/Makefile.autoconf
100 define filechk_config_h
101     (echo "/* Automatically generated - do not edit */";		\
102     for i in $$(echo "" | sed 's/,/ /g'); do \
103     echo \#define CONFIG_$i				\
104     | sed '/=/ {s/=/	/;q; } ; { s/$$/	1/; }'; \
105     done;								\
106     echo \#define CONFIG_BOARDDIR board/raspberrypi/rpi;\
107     echo \#include \<config_uncmd_spl.h\>;				\
108     echo \#include \<configs/"rpi".h\>;		\
109     echo \#include \<asm/config.h\>;				\
110     echo \#include \<linux/kconfig.h\>;				\
111     echo \#include \<config_fallbacks.h\>;)
112 endef
114 include/config.h: scripts/Makefile.autoconf create_symlink FORCE
115 	$(call filechk,config_h)

执行目标include/config.h的创建规则, 回显 14

  1. 目标依赖的scripts/Makefile.autoconf,在源码中已经存在且无更新规则。
  2. 目标依赖的creat_symlink,在执行《1.1 创建 creat_symlink 》时创建。
  3. 目标依赖的FORCE,什么都不做。


最终:《filechk 函数》 分析可知:
执行$(filechk_config_h)命令,将执行结果写入include/config.h文件中,其内容如下: 回显 14

1	/* Automatically generated - do not edit */
2	#define CONFIG_BOARDDIR board/raspberrypi/rpi
3	#include <config_uncmd_spl.h>
4	#include <configs/rpi.h>
5	#include <asm/config.h>
6	#include <linux/kconfig.h>
7	#include <config_fallbacks.h>

回显 14

14	set -e; mkdir -p include/; 	(echo "/* Automatically generated - do not edit */"; for i in $(echo "" | sed 's/,/ /g'); do echo \#define CONFIG_$i | sed '/=/ {s/=/	/;q; } ; { s/$/	1/; }'; done; echo \#define CONFIG_BOARDDIR board/raspberrypi/rpi; echo \#include \<config_uncmd_spl.h\>; echo \#include \<configs/"rpi".h\>; echo \#include \<asm/config.h\>; echo \#include \<linux/kconfig.h\>; echo \#include \<config_fallbacks.h\>;) < scripts/Makefile.autoconf > include/config.h.tmp; if [ -r include/config.h ] && cmp -s include/config.h include/config.h.tmp; then rm -f include/config.h.tmp; else : '  UPD     include/config.h'; mv -f include/config.h.tmp include/config.h; fi	 

创建
创建 include/config.h 回显 14

1.3 创建 u-boot.cfg

# $(srctree)/scripts/Makefile.autoconf
21 include include/config/auto.conf
22 include scripts/Kbuild.include
31 include config.mk
......
28 CC  = $(CROSS_COMPILE)gcc
29 CPP = $(CC) -E
......
68 cmd_u_boot_cfg = \
69                  $(CPP) $(c_flags) $2 -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && { \
70                  grep 'define CONFIG_' $@.tmp > $@;			\
71                  rm $@.tmp;						\
72                  } || {								\
73                  rm $@.tmp; false;					\
74                  }
76 u-boot.cfg: include/config.h FORCE
77    	$(call cmd,u_boot_cfg)

在顶层 makefile 中有如下定义:

# 顶层 Makefile
$(KBUILD_CFLAGS) = -Wall -Wstrict-prototypes -Wno-format-security -fno-builtin -ffreestanding -std=gnu11 \
                   -fshort-wchar -fno-strict-aliasing \
                   -fno-PIE \
                   -O2 \
                   -fno-stack-protector \
                   -fno-delete-null-pointer-checks  \
                   -Wno-maybe-uninitialized  \
                   -g \
                   -fstack-usage \
                   -Wno-format-nonliteral  \
                   -Wno-unused-but-set-variable \
                   -Werror=date-time  
$(KBUILD_CPPFLAGS)    = -D__KERNEL__ -D__UBOOT__ 
$(PLATFORM_CPPFLAGS)  = -D__ARM__ -marm -mno-thumb-interwork  -mabi=aapcs-linux  -mword-relocations  -fno-pic  -mno-unaligned-access  -ffunction-sections -fdata-sections -fno-common -ffixed-r9  -msoft-float    -pipe 
$(UBOOTINCLUDE)       = -Iinclude  -I./arch/arm/include -include ./include/linux/kconfig.h
$(NOSTDINC_FLAGS)     = -nostdinc -isystem /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/include

785 cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
787 c_flags   := $(KBUILD_CFLAGS) $(cpp_flags)
  • 28行:变量$(CROSS_COMPILE)在输入参数中已经定义make ARCH=arm CROSS_COMPILE=/home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/arm-linux-gnueabihf- -j12 V=1
    所以: CC = /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/arm-linux-gnueabihf-gcc
  • 29行:由步骤1可知: CPP = /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/arm-linux-gnueabihf-gcc -E
  • 69行:$(c_flags)由上面顶层Makefile中的定义可知: c_flags = -Wall -Wstrict-prototypes -Wno-format-security -fno-builtin -ffreestanding -std=gnu11 -fshort-wchar -fno-strict-aliasing -fno-PIE -O2 -fno-stack-protector -fno-delete-null-pointer-checks -Wno-maybe-uninitialized -g -fstack-usage -Wno-format-nonliteral -Wno-unused-but-set-variable -Werror=date-time -D__KERNEL__ -D__UBOOT__ -D__ARM__ -marm -mno-thumb-interwork -mabi=aapcs-linux -mword-relocations -fno-pic -mno-unaligned-access -ffunction-sections -fdata-sections -fno-common -ffixed-r9 -msoft-float -pipe -Iinclude -I./arch/arm/include -include ./include/linux/kconfig.h -nostdinc -isystem /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/…/lib/gcc/arm-linux-gnueabihf/7.5.0/include
  • 69行:$(srctree)在顶层 Makefile 中定义为: srctree = .
  • 72行:||表示逻辑或,||左边的命令执行失败,才执行右边的命令,否则只执行左边的命令;
    &&表示逻辑与,&&左边的命令执行成功,再执行右边的命令。
  • 72行:falsetrue是两个内置命令,可单独运行,true 单独运行完返回状态码0false单独运行完返回状态码非0


最终展开后为:

# $(srctree)/scripts/Makefile.autoconf
$(c_flags) = -Wall -Wstrict-prototypes -Wno-format-security -fno-builtin -ffreestanding -std=gnu11 -fshort-wchar -fno-strict-aliasing -fno-PIE -O2 -fno-stack-protector -fno-delete-null-pointer-checks  -Wno-maybe-uninitialized  -g -fstack-usage -Wno-format-nonliteral  -Wno-unused-but-set-variable -Werror=date-time  -D__KERNEL__ -D__UBOOT__   -D__ARM__ -marm -mno-thumb-interwork  -mabi=aapcs-linux  -mword-relocations  -fno-pic  -mno-unaligned-access  -ffunction-sections -fdata-sections -fno-common -ffixed-r9  -msoft-float    -pipe -Iinclude  -I./arch/arm/include -include ./include/linux/kconfig.h  -nostdinc -isystem /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/include

28 CC  = /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/arm-linux-gnueabihf-gcc
29 CPP = /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/arm-linux-gnueabihf-gcc -E
......
68 cmd_u_boot_cfg = \
69                  $(CPP) $(c_flags) $2 -DDO_DEPS_ONLY -dM ./include/common.h > $@.tmp && { \
70                  grep 'define CONFIG_' $@.tmp > $@;			\
71                  rm $@.tmp;						\
72                  } || {								\
73                  rm $@.tmp; false;					\
74                  }
76 u-boot.cfg: include/config.h FORCE
77    	$(call cmd,u_boot_cfg)

执行目标u-boot.cfg的创建规则, 回显 15

  1. 目标的依赖include/config.h,在执行《1.2 创建 include/config.h 》时已创建。
  2. 目标的依赖FORCE,什么都不做。

  • 注: $(CPP) $(c_flags) $2 -DDO_DEPS_ONLY -dM ./include/common.h 命令的意义:将./include/common.h包含的宏(预处理结束时仍然有效的宏定义)全部列出。《GCC 参数详解》
  • 创建命令执行过程:
    ./include/common.h包含的宏(预处理结束时仍然有效的宏定义)全部输入到u-boot.cfg.tmp中,然后过滤u-boot.cfg.tmp中符合define CONFIG_类型的宏全部输入到u-boot.cfg中,最后将u-boot.cfg.tmp文件删除,只保留u-boot.cfg文件


最终:《cmd 函数》 分析可知:
打印和执行$(cmd_u_boot_cfg)命令,将执行结果写入u-boot.cfg文件中,其内容如下: 回显 15

#define CONFIG_PINCTRL_BCM283X 1
#define CONFIG_CMD_FAT 1
......
#define CONFIG_CMD_MMC 1
#define CONFIG_CMD_TFTPBOOT 1

回显 15

15   /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/arm-linux-gnueabihf-gcc -E -Wall -Wstrict-prototypes -Wno-format-security -fno-builtin -ffreestanding -std=gnu11 -fshort-wchar -fno-strict-aliasing -fno-PIE -O2 -fno-stack-protector -fno-delete-null-pointer-checks  -Wno-maybe-uninitialized  -g -fstack-usage -Wno-format-nonliteral  -Wno-unused-but-set-variable -Werror=date-time  -D__KERNEL__ -D__UBOOT__   -D__ARM__ -marm -mno-thumb-interwork  -mabi=aapcs-linux  -mword-relocations  -fno-pic  -mno-unaligned-access  -ffunction-sections -fdata-sections -fno-common -ffixed-r9  -msoft-float    -pipe -Iinclude  -I./arch/arm/include -include ./include/linux/kconfig.h  -nostdinc -isystem /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/include  -DDO_DEPS_ONLY -dM ./include/common.h > u-boot.cfg.tmp && { grep 'define CONFIG_' u-boot.cfg.tmp > u-boot.cfg; rm u-boot.cfg.tmp; } || { rm u-boot.cfg.tmp; false; }

创建
创建 u-boot.cfg 回显 15

1.4 创建 include/autoconf.mk

# $(srctree)/scripts/Makefile.autoconf
58 cmd_autoconf   = \
59                  sed -n -f $(srctree)/tools/scripts/define2mk.sed $< |			\
60                  while read line; do							\
61                  if [ -n "${KCONFIG_IGNORE_DUPLICATES}" ] ||			\
62                  ! grep -q "$${line%=*}=" include/config/auto.conf; then	\
63                  echo "$$line";						\
64                  fi								\
65                  done > $@
87 include/autoconf.mk: u-boot.cfg
88     	$(call cmd,autoconf)
  • 59行:$(srctree)在顶层 Makefile 中定义为.
  • 61行:$(PLATFORM_CPPFLAGS)未定义为空

最终展开后为:

# $(srctree)/scripts/Makefile.autoconf
58 cmd_autoconf   = \
59                  sed -n -f ./tools/scripts/define2mk.sed u-boot.cfg |			\
60                  while read line; do							\
61                      if [ -n "" ] || ! grep -q "$${line%=*}=" include/config/auto.conf; then	\
63                      echo "$line";						\
64                  fi								\
65                  done > include/autoconf.mk
87 include/autoconf.mk: u-boot.cfg
88     	$(call cmd,autoconf)

目标依赖的u-boot.cfg ,在执行《1.3 创建 u-boot.cfg 》时已创建,所以接下来执行目标的创建命令即可。 回显 16

  • 创建命令执行说明:
    include/config/auto.conf文件中查询u-boot.cfg中没有的宏定义,将结果(用s命令进行字符的替换)输入include/autoconf.mk文件中
  1. ||表示逻辑或,||左边的命令执行失败,才执行右边的命令,否则只执行左边的命令;
    &&表示逻辑与,&&左边的命令执行成功,再执行右边的命令。
  2. sed -n:读取下一个输入行,用下一个命令处理新的行;
    sed -f:跟随脚本文件命令;
    grep -q:安静模式,不打印任何标准输出。如果有匹配的内容则立即返回状态值0
  3. ./tools/scripts/define2mk.sed脚本完成在u-boot.cfg中查找和处理以“CONFIG_”开头的宏定义(用s命令进行字符的替换)


最终:《cmd 函数》 分析可知:
打印和执行$(cmd_autoconf)命令,将执行结果写入include/autoconf.mk文件中,其内容如下: 回显 16

# include/autoconf.mk
1 	CONFIG_SYS_LOAD_ADDR=0x1000000
2 	CONFIG_SYS_CBSIZE=1024
3 	CONFIG_SKIP_LOWLEVEL_INIT=y
4 	CONFIG_SYS_MALLOC_LEN="SZ_4M"
5 	CONFIG_INITRD_TAG=y
6 	CONFIG_SYS_TIMER_RATE=1000000
7 	CONFIG_SYS_MAXARGS=16
8 	CONFIG_EXTRA_ENV_SETTINGS=""dhcpuboot=usb start; dhcp u-boot.uimg; bootm0" ENV_DEVICE_SETTINGS ENV_DFU_SETTINGS ENV_MEM_LAYOUT_SETTINGS BOOTENV"
9 	CONFIG_SYS_PBSIZE="(CONFIG_SYS_CBSIZE + sizeof(CONFIG_SYS_PROMPT) + 16)"
10	CONFIG_BOARDDIR="board/raspberrypi/rpi"
11	CONFIG_BCM2835_GPIO=y
12	CONFIG_LCD_DT_SIMPLEFB=y
13	CONFIG_SYS_BAUDRATE_TABLE="{ 9600, 19200, 38400, 57600, 115200 }"
14	CONFIG_VAL(option)="config_val(option)"
15	CONFIG_SYS_SDRAM_BASE=0x00000000
16	CONFIG_SYS_TIMER_COUNTER="(&((struct bcm2835_timer_regs *)BCM2835_TIMER_PHYSADDR)->clo)"
17	CONFIG_VIDEO_BCM2835=y
18	CONFIG_SYS_INIT_SP_ADDR="(CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_SDRAM_SIZE - GENERATED_GBL_DATA_SIZE)"
19	CONFIG_TFTP_TSIZE=y
20	CONFIG_CMDLINE_TAG=y
21	CONFIG_SYS_BOOT_RAMDISK_HIGH=y
22	CONFIG_LOADADDR=0x00200000
23	CONFIG_SETUP_MEMORY_TAGS=y
24	CONFIG_SYS_SDRAM_SIZE="SZ_128M"
25	CONFIG_IS_ENABLED(option,...)="__concat(__CONFIG_IS_ENABLED_, __count_args(option, ##__VA_ARGS__)) (option, ##__VA_ARGS__)"
26	CONFIG_SYS_UBOOT_BASE=$(CONFIG_SYS_TEXT_BASE)

回显 16

16    sed -n -f ./tools/scripts/define2mk.sed u-boot.cfg |   while read line; do   if [ -n "" ] || ! grep -q "${line%=*}=" include/config/auto.conf; then   echo "$line";   fi   done > include/autoconf.mk

创建
创建 include/autoconf.mk 回显 16

1.5 创建 include/autoconf.mk.dep

# $(srctree)/scripts/Makefile.autoconf
43 cmd_autoconf_dep = $(CC) -x c -DDO_DEPS_ONLY -M -MP $(c_flags) \
44                    -MQ include/config/auto.conf ./include/common.h > $@ || {	\
45                    rm $@; false;		\
46	                  }
47 include/autoconf.mk.dep: include/config.h FORCE
48    	$(call cmd,autoconf_dep)
  • 43行:$(CC)$(c_flags)在上面《1.3 创建 u-boot.cfg》中有定义:
    CC = /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/arm-linux-gnueabihf-gcc
    c_flags = -Wall -Wstrict-prototypes -Wno-format-security -fno-builtin -ffreestanding -std=gnu11 -fshort-wchar -fno-strict-aliasing -fno-PIE -O2 -fno-stack-protector -fno-delete-null-pointer-checks -Wno-maybe-uninitialized -g -fstack-usage -Wno-format-nonliteral -Wno-unused-but-set-variable -Werror=date-time -D__KERNEL__ -D__UBOOT__ -D__ARM__ -marm -mno-thumb-interwork -mabi=aapcs-linux -mword-relocations -fno-pic -mno-unaligned-access -ffunction-sections -fdata-sections -fno-common -ffixed-r9 -msoft-float -pipe -Iinclude -I./arch/arm/include -include ./include/linux/kconfig.h -nostdinc -isystem /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/…/lib/gcc/arm-linux-gnueabihf/7.5.0/include
  • 44行:||表示逻辑或,||左边的命令执行失败,才执行右边的命令,否则只执行左边的命令;
    &&表示逻辑与,&&左边的命令执行成功,再执行右边的命令。
  • 45行:falsetrue是两个内置命令,可单独运行,true 单独运行完返回状态码0false单独运行完返回状态码非0


最终展开后为:

# $(srctree)/scripts/Makefile.autoconf
43 cmd_autoconf_dep = /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/arm-linux-gnueabihf-gcc -x c -DDO_DEPS_ONLY -M -MP  \
                      -Wall -Wstrict-prototypes -Wno-format-security -fno-builtin -ffreestanding -std=gnu11 -fshort-wchar -fno-strict-aliasing -fno-PIE -O2 -fno-stack-protector -fno-delete-null-pointer-checks  -Wno-maybe-uninitialized  -g -fstack-usage -Wno-format-nonliteral  -Wno-unused-but-set-variable -Werror=date-time  -D__KERNEL__ -D__UBOOT__   -D__ARM__ -marm -mno-thumb-interwork  -mabi=aapcs-linux  -mword-relocations  -fno-pic  -mno-unaligned-access  -ffunction-sections -fdata-sections -fno-common -ffixed-r9  -msoft-float    -pipe -Iinclude  -I./arch/arm/include -include ./include/linux/kconfig.h  -nostdinc -isystem /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/include \
44                    -MQ include/config/auto.conf ./include/common.h > include/autoconf.mk.dep || \
45                    { rm include/autoconf.mk.dep; false; }
47 include/autoconf.mk.dep: include/config.h FORCE
48    	$(call cmd,autoconf_dep)

目标依赖的include/config.h,在执行《1.2 创建 include/config.h》时已创建,接下来执行目标的创建命令即可。 回显 17

  • 创建命令执行说明:
    根据include/config/auto.conf./include/common.h文件名后缀,自动识别文件类型,将结果输入include/autoconf.mk.dep文件中。《GCC 参数详解》


最终:《cmd 函数》 分析可知:
打印和执行$(cmd_autoconf_dep)命令,将执行结果写入include/autoconf.mk.dep文件中,其内容如下: 回显 17

include/config/auto.conf: include/common.h include/linux/kconfig.h  include/generated/autoconf.h include/config.h include/config_uncmd_spl.h  include/configs/rpi.h include/linux/sizes.h include/linux/const.h  arch/arm/include/asm/arch/timer.h arch/arm/include/asm/arch/base.h  include/linux/bug.h include/vsprintf.h  /home/xd/rpi3b/toolchain/toolchain-rpi32b/lib/gcc/arm-linux-gnueabihf/7.5.0/include/stdarg.h  include/linux/types.h include/linux/posix_types.h include/linux/stddef.h  arch/arm/include/asm/posix_types.h arch/arm/include/asm/types.h  include/asm-generic/int-ll64.h  /home/xd/rpi3b/toolchain/toolchain-rpi32b/lib/gcc/arm-linux-gnueabihf/7.5.0/include/stdbool.h  include/linux/build_bug.h include/linux/compiler.h  include/linux/compiler_types.h include/linux/compiler_attributes.h  include/linux/compiler-gcc.h include/linux/printk.h include/log.h  include/stdio.h include/linker_lists.h include/dm/uclass-id.h  include/linux/bitops.h include/asm-generic/bitsperlong.h  include/linux/kernel.h arch/arm/include/asm/bitops.h  include/asm-generic/bitops/__ffs.h include/asm-generic/bitops/__fls.h  include/asm-generic/bitops/fls.h include/asm-generic/bitops/fls64.h  arch/arm/include/asm/proc-armv/system.h include/linux/list.h  include/linux/poison.h include/config_distro_bootcmd.h  arch/arm/include/asm/config.h include/linux/kconfig.h  include/config_fallbacks.h include/errno.h include/linux/errno.h  include/time.h include/linux/typecheck.h include/linux/string.h  arch/arm/include/asm/string.h include/linux/linux_string.h  arch/arm/include/asm/u-boot.h include/asm-generic/u-boot.h  arch/arm/include/asm/u-boot-arm.h include/display_options.h  include/env_internal.h include/compiler.h  /home/xd/rpi3b/toolchain/toolchain-rpi32b/lib/gcc/arm-linux-gnueabihf/7.5.0/include/stddef.h  arch/arm/include/asm/byteorder.h include/linux/byteorder/little_endian.h include/linux/byteorder/swab.h include/linux/byteorder/generic.h
include/linux/kconfig.h:
include/generated/autoconf.h:
include/config.h:
include/config_uncmd_spl.h:
include/configs/rpi.h:
include/linux/sizes.h:
include/linux/const.h:
arch/arm/include/asm/arch/timer.h:
arch/arm/include/asm/arch/base.h:
include/linux/bug.h:
include/vsprintf.h:
/home/xd/rpi3b/toolchain/toolchain-rpi32b/lib/gcc/arm-linux-gnueabihf/7.5.0/include/stdarg.h:
include/linux/types.h:
include/linux/posix_types.h:
include/linux/stddef.h:
arch/arm/include/asm/posix_types.h:
arch/arm/include/asm/types.h:
include/asm-generic/int-ll64.h:
/home/xd/rpi3b/toolchain/toolchain-rpi32b/lib/gcc/arm-linux-gnueabihf/7.5.0/include/stdbool.h:
include/linux/build_bug.h:
include/linux/compiler.h:
include/linux/compiler_types.h:
include/linux/compiler_attributes.h:
include/linux/compiler-gcc.h:
include/linux/printk.h:
include/log.h:
include/stdio.h:
include/linker_lists.h:
include/dm/uclass-id.h:
include/linux/bitops.h:
include/asm-generic/bitsperlong.h:
include/linux/kernel.h:
arch/arm/include/asm/bitops.h:
include/asm-generic/bitops/__ffs.h:
include/asm-generic/bitops/__fls.h:
include/asm-generic/bitops/fls.h:
include/asm-generic/bitops/fls64.h:
arch/arm/include/asm/proc-armv/system.h:
include/linux/list.h:
include/linux/poison.h:
include/config_distro_bootcmd.h:
arch/arm/include/asm/config.h:
include/linux/kconfig.h:
include/config_fallbacks.h:
include/errno.h:
include/linux/errno.h:
include/time.h:
include/linux/typecheck.h:
include/linux/string.h:
arch/arm/include/asm/string.h:
include/linux/linux_string.h:
arch/arm/include/asm/u-boot.h:
include/asm-generic/u-boot.h:
arch/arm/include/asm/u-boot-arm.h:
include/display_options.h:
include/env_internal.h:
include/compiler.h:
/home/xd/rpi3b/toolchain/toolchain-rpi32b/lib/gcc/arm-linux-gnueabihf/7.5.0/include/stddef.h:
arch/arm/include/asm/byteorder.h:
include/linux/byteorder/little_endian.h:
include/linux/byteorder/swab.h:
include/linux/byteorder/generic.h:

回显 17

17  /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/arm-linux-gnueabihf-gcc -x c -DDO_DEPS_ONLY -M -MP   -Wall -Wstrict-prototypes -Wno-format-security -fno-builtin -ffreestanding -std=gnu11 -fshort-wchar -fno-strict-aliasing -fno-PIE -O2 -fno-stack-protector -fno-delete-null-pointer-checks  -Wno-maybe-uninitialized  -g -fstack-usage -Wno-format-nonliteral  -Wno-unused-but-set-variable -Werror=date-time  -D__KERNEL__ -D__UBOOT__   -D__ARM__ -marm -mno-thumb-interwork  -mabi=aapcs-linux  -mword-relocations  -fno-pic  -mno-unaligned-access  -ffunction-sections -fdata-sections -fno-common -ffixed-r9  -msoft-float    -pipe -Iinclude  -I./arch/arm/include -include ./include/linux/kconfig.h  -nostdinc -isystem /home/xd/rpi3b/toolchain/toolchain-rpi32b/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/include   -MQ include/config/auto.conf ./include/common.h > include/autoconf.mk.dep || { rm include/autoconf.mk.dep; false; }

创建
创建 include/autoconf.mk.dep 回显 17

  • 12
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值