Analysis of the make xxx_defconfig process of the top-level Makefile of the Linux kernel

1. Linux kernel configuration

Before compiling Linux for the first time, you must use the "make xxx_defconfig" command to configure the Linux kernel.

Let's analyze what the top-level Makefile of the Linux kernel source code does when the "make xxx_defcofig" command is executed?

2. The make xxx_defconfig process of Makefile

Before compiling Linux for the first time , you must use the " make xxx_defconfig " command to configure the Linux kernel first. In the top-level Makefile

There is " %config " target in it, as shown below:
490 config-targets := 0
491 mixed-targets := 0
492 dot-config := 1
493
494 ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
495 ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
496 dot-config := 0
497 endif
498 endif
499
500 ifeq ($(KBUILD_EXTMOD),)
501 ifneq ($(filter config %config,$(MAKECMDGOALS)),)
502 config-targets := 1
503 ifneq ($(words $(MAKECMDGOALS)),1)
504 mixed-targets := 1
505 endif
506 endif
507 endif
508
509 ifeq ($(mixed-targets),1)
510 # =================================================================
511 # We're called with mixed targets (*config and build targets).
512 # Handle them one by one.
513
514 PHONY += $(MAKECMDGOALS) __build_one_by_one
515
516 $(filter-out __build_one_by_one, $(MAKECMDGOALS)):
__build_one_by_one
517 @:
518
519 __build_one_by_one:
520 $(Q)set -e; \
521 for i in $(MAKECMDGOALS); do \
522 $(MAKE) -f $(srctree)/Makefile $$i; \
523 done
524
525 else
526 ifeq ($(config-targets),1)
527 # ================================================================
528 # *config targets only - make sure prerequisites are updated, and 
529 # descend in scripts/kconfig to make the *config target
530
531 # Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
532 # KBUILD_DEFCONFIG may point out an alternative default
533 # configuration used for 'make defconfig'
534 include arch/$(SRCARCH)/Makefile
535 export KBUILD_DEFCONFIG KBUILD_KCONFIG
536
537 config: scripts_basic outputmakefile FORCE
538 $(Q)$(MAKE) $(build)=scripts/kconfig $@
539
540 %config: scripts_basic outputmakefile FORCE
541 $(Q)$(MAKE) $(build)=scripts/kconfig $@
...
563 endif # KBUILD_EXTMOD
Lines 490 to 507 are the same as uboot , setting and defining variables config-targets , mixed-targets and dot-config
The final values ​​of these three variables are:
config-targets= 1
mixed-targets= 0
dot-config= 1

Because config-targets=1, lines 534~541 are established.
Line 534 refers to the file arch/arm/Makefile. This file is very important because files such as zImage and uImage are generated by arch/arm/Makefile.
Line 535 exports the variable KBUILD_DEFCONFIG KBUILD_KCONFIG.
Line 537, no target matches, so it is not executed.
Line 540, "make xxx_defconfig" matches the target "%config", so it is executed.

The target " %config " depends on scripts_basic , outputmakefile and FORCE . The only real meaningful dependency of " %config " is scripts_basic.

The rules for scripts_basic are as follows:

448 scripts_basic:
449 $(Q)$(MAKE) $(build)=scripts/basic
450 $(Q)rm -f .tmp_quiet_recordmcount

build is defined in the file scripts/Kbuild.include , and the value is build := -f $(srctree)/scripts/Makefile.build
obj , the above command expands to:
scripts_basic:
@make -f $(srctree)/scripts/Makefile.build obj=scripts/basic //也可以没有@,视配置而定
@rm -f . tmp_quiet_recordmcount //也可以没有@

The configuration command corresponding to the %config target:

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

Expand as follows:

$(Q)$(MAKE) $(build)=scripts/basic
$(Q)$(MAKE) $(build)=scripts/kconfig $@

$@ in the second line of command above refers to the target, which is %config , which is xxx_defconfig.

And the $(srctree) parameter is . .

Finally, the configuration command corresponding to the %config target is expanded to:

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

The next article will analyze in detail what these two configuration commands actually do.

Guess you like

Origin blog.csdn.net/wojiaxiaohuang2014/article/details/133107207