Third, compile the first step make xxx_defconfig - Makefile.build script

3.1 Analysis and review of the previous chapter

3.1 Parameters analyzed in the previous chapter

3.1.1 Variables

  • MAKECMDGOALS = xxx_defconfig
  • KBUILD_EXTMOD =
  • version_h := include/generated/version_autogenerated.h
  • timestamp_h := include/generated/timestamp_autogenerated.h
  • no-dot-config-targets := clean clobber mrproper distclean help %docs check% coccicheck ubootversion backup tests
  • config-targets := 1
  • mixed-targets := 0
  • dot-config := 1
  • KBUILD_SRC =
  • build := -f ./scripts/Makefile.build obj

3.1.2 Environment variables

  • KBUILD_DEFCONFIG := sandbox_defconfig
  • KBUILD_KCONFIG =

3.1.3 Where analysis is required

(1) Commands executed by the scripts_basic target

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

(2) Commands executed by the %config target

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

  It can be known from the above analysis that the Makefile.build script needs to be executed to execute make xxx_defconfig. The first parameter passed in is scripts/basic, and the second passed parameter is scripts/kconfig xxx_defconfig

3.2 Makefile.build script analysis

3.2.1 make -f ./scripts/Makefile.build obj=scripts/basic

  The make -f scripts/Makefile.build obj=scripts/basic command processes the default target __build in script/Makefile.build because no target is specified:

  Lines 114~119

1 # We keep a list of all modules in $(MODVERDIR)
2 
3 __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
4      $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
5      $(subdir-ym) $(always)
6     @:

  At the same time, the Kbuild/Makefile in the scripts/basic directory will be included in scripts/Makefile.build, so the actual effect of the make command is to compile three host programs in the scripts/basic directory, namely fixdep docproc and hash .

  Lines 56 to 59 contain

1 # The filename Kbuild has precedence over Makefile
2 kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
3 kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
4 include $(kbuild-file)

  What is a host program? It is generally considered to be a tool program that has nothing to do with the kernel, but should be used in the compilation process. For compilation of these programs, refer to the scripts/Makefile.host file, and the documentation/kbuild/makefile.txt file for the section on host programs.

  Makefile in scripts/basic file

1 hostprogs-y    := fixdep
2 always        := $(hostprogs-y)
3 
4 # fixdep is needed to compile other host programs
5 $(addprefix $(obj)/,$(filter-out fixdep,$(always))): $(obj)/fixdep

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

  The file scripts/Makefile.build will contain the Makefile in the directory pointed to by the obj variable, in this case script/kconfig/Makefile.

  So here we have to look at this file: lines 120~125

1 %_defconfig: $(obj)/conf
2     $(Q)$< $(silent) --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)
3 
4 # Added for U-Boot (backward compatibility)
5 %_config: %_defconfig
6     @:

  Here, xxx_defconfig needs to depend on the conf program in the same directory. This is actually one of the main programs for the Linux kernel to perform Kconfig operations, similar to mconf, qconf and gconf. They are actually host programs. For how they are compiled, please also refer to the scripts/kconfig/Makefile file, mainly with the help of the three tools bison, flex and gperf to generate the c source program file, and then compile it out. This part has little to do with our Linux kernel build theme.

  Take a look at the definition of kconfig, the assignment of variables is in scripts\kconfig'Makefile

1 ifdef KBUILD_KCONFIG
2 Kconfig := $(KBUILD_KCONFIG)
3 else
4 Kconfig := Kconfig
5 endif

  Since the variable KBUILD_KCONFIG is not defined in the arm architecture Makefile, Kconfig is defined as arch/arm/kconfig, so the rules for this target are simplified to:

1  /* silent is to determine whether to perform static compilation */ 
2  ifeq ($(quiet),silent_)
 3 silent := - s
 4  endif
 5  
6 $(obj)/conf -s --defconfig=arch/arm/configs/ xxx_defconfig arch/arm/Kconfig

  This command is to read and parse the kernel function option configuration file headed by arch/arm/Kconfig, and assign the default value set by the file arch/arm/configs/s3c2410_defconfig to all the corresponding options, and finally generate a hidden configuration file .config .

  Before the actual compilation of uboot or the kernel, the build system will generate include/config/auto.conf file based on the .config file. The format of this file is similar to .config. This file will be at the top level and in the scripts/Makefile.build file are included directly, so these variables actually become GNU Make variables. And uboot or the Kbuild/Makefile in each subdirectory of the kernel can use the definitions of these variables to decide whether to compile the corresponding code functions in the directory directly into the kernel (the value of these variables is "y") and compile them into modules (value "m") or not compile at all (value "null"). It is conceivable that if you choose not to compile, the resulting Linux kernel will not have corresponding functions.

   In the arch/arm/Kconfig file, we can see where adding a board needs to roughly change:

  • arch/arm/cpu directory
  • board/ directory

  When configuring, the configuration tool will first parse the Kconfig in the architecture platform directory, which is the so-called platform-related main Kconfig. The main Kconfig file will contain Kcofnig files in other directories, and Kconfig in other directories will contain Kconfig in other subdirectories. This forms a tree structure. 

3.3 Summary

  As the uboot or kernel build system's support for kconfig, this step is over, and its fundamental goal is to generate a .config hidden file to record the configuration results we need. But in uboot or the Linux kernel, it is not enough to store the configuration results in a file like .config. In the following configuration, it will still be used 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325121263&siteId=291194637