A kernel compilation mechanism that Linux driver engineers must know

The main process of compiling the Linux kernel: configuration, compilation, and installation .

  • The configuration is mainly done by Kconfigproviding a graphical interface
  • The compilation is mainly based on Kbuildthe compilation system, and the execution makecompletes the compilation
  • The installation is mainly based on Kbuildthe script provided, and then execute maketo complete the installation

Kconfig

KconfigFor the configuration of the kernel, make menuconfigthe displayed menu comes from Kconfig.

make menuconfigThe menu includes multiple layers, and each layer is Kconfiggenerated correspondingly in each directory. After the configuration is selected, the configuration result will be saved to .configthe file.

When executed Makefile, the compilation of the kernel Makefilewill be .configrealized according to the result of .

Kconfig syntax

Kbuild

KbuildThat is Kernel build, it is a compilation system for the kernel.

In simple terms, Kbuildit is Makefilean extension of grammatical functions.

For example, kbuildmany useful variables are defined such as obj-m`` obj-y, -objsetc., as long as the user assigns values ​​to these variables, kbuildthe code will be automatically compiled into the kernel or compiled into a module.

LinuxWhen the kernel is kbuildcompiled, it will scan twice Linux: Makefilefirst read the top-level file, and then read the kbuild file for the second time to compile the kernel Makefileaccording to the read content .MakefileLinux

The kernel Makefileconsists of five parts:

 Information through train: Linux kernel source code technology learning route + video tutorial kernel source code

Learning through train: Linux kernel source code memory tuning file system process management device driver/network protocol stack

Makefile

The top level Makefileis the compiled entry, let’s analyze the top level Makefilefile.

The top level Makefilewill pass some information to each subdirectory Makefile, some variables, for example , are not only defined and assigned vmlinux-dirsin the top level , but also expanded.Makefilearch/*/Makefile

 

 

Guess you like

Origin blog.csdn.net/youzhangjing_/article/details/132147531