Tiny4412 Linux Kernel configuration process

Source: Internet
Author: User

1. Configuring the Cross Compiler

By default, the kernel builds the same architectural image as the host. If you want to cross-compile, you need to set two variants of Arch and corss_compile.

①arch: Specify the target architecture, such as x86, ARM, MIPS, etc.

②cross_compile: Specifies the prefix used by the cross compiler. such as arm-linux-. In the top-level makefile of the kernel, you can see that the compiler, linker, and so on in the toolchain are prefixed with $ (cross_compile).

As              = $ (cross_compile) as  ld              = $ (cross_compile)ldreal_cc         = $ (cross_ COMPILE)gccCPP             = $ (CC)-EAR              = $ (cross_compile)arNM              = $ (cross_compile) nmstrip           = $ (cross_compile) stripobjcopy         = $ (cross_ COMPILE) objcopyobjdump         = $ (cross_compile) objdump

Each time we execute make, we can assign values to these two variables by the following command

 Make Arch=arm cross_compile=arm-linux-

or directly modify the top-level makefile to

ARCH                                        =  $  (subarch) cross_compile                               ? =

Revision changed to

ARCH                                        =  armcross_compile                               ? = arn-linux-
2. Load the default configuration

In the kernel source Arch/<arch>/configs directory, the kernel provides a variety of platform default configuration files, when loading the default configuration, we can use

 Make Arch=arm Cross_compile=arm-linux-xxx_defconfig

This operation is equivalent to copying the Xxx_defconfig file in the arch/arm/configs/directory to a. config

We can use the command

 make Help

To get help

3. Configuring the Kernel

We can use commands

 make Menuconfig

To configure the kernel in the form of a menu.

4. Build the kernel

We can compile the kernel with the following command

 make Zimage

Kernel modules can be compiled with the following command

 make Modules

The kernel image generated by the compilation is located in the kernel source/arch/arm/boot directory and the arch/arm/boot/compressed directory.

①VMLINUX.O is the target file for the kernel generated after the link

②vmlinux (root directory) is the ELF-formatted kernel

③system.map is the rich list of the kernel

④image is a binary kernel file, converted from Vmlinux

⑤vmlinux (compressed directory) is a compressed vmlinux image (compressed by gzip algorithm) and a combination of the decompressor and the elf format

⑥zimage is a combination of the decompression program and the kernel

5. Kernel build System
Name Describe
Top Floor Makefile He is the core of all makefile files, controlling the compilation and linking of the kernel in general
. config configuration file, which is generated when the kernel is configured. All makefile files (including top-level catalogs and subdirectories at all levels) are based on. config to determine which files to use
arch/$ (ARCH)/makefile The makefile of the architecture, which is used to determine which architecture-related files participate in the kernel generation, and provides rules to generate kernel images in a specific format.
Scripts/makefile.* Makefile common rules, scripts, etc.
Kbuild makefiles Makefile at all levels of subdirectories, they are relatively simple, and are used by a layer of makefile to compile files in the current directory

Makefile: Makefile, which is distributed in kernel source code, defines the compiler rules for the kernel and works with Kconfig

Kconfig: Configuration file to provide users with configuration options, make Menuconfig and other commands based on this file to generate the configuration menu

Configuration tool: Includes configuration command parser (parse kconfig) and kernel configuration user interface program, etc.

5.1 Kernel Kconfig

Before you execute make zimage to build the kernel image, we usually respond by copying a default xxx_defconfig to replace the. config, or run make xxx_defconfig to get a default kernel profile, and then run make Menuconfig and so on to further customize the kernel.

The configuration tool, such as make menuconfig, generates the configuration interface by reading the Arch/<arch>/kconnfig file, which is the total entry for all profiles and contains the Kconfig files from other directories.

In each subdirectory of the kernel source, there is a makefile file and a kconfig file. The makefile is used to configure the build process for the target file. Kconfig is used to configure the kernel, which is the source file for various configuration interfaces. The kernel Configuration tool reads individual kconfig files, generates a configuration interface for the developer to configure the kernel, and finally builds the configuration file. config.

The kernel configuration interface is organized in a tree-like menu, with several submenus under the main menu, and submenus or configuration options under the submenu. Each submenu or option has dependencies that are used to determine whether they are displayed. The child is displayed only if the dependent parent has been selected. Here's a look at the basic syntax of Kconfig.

Kconfig syntax is rich, according to the function can be divided into configuration options description Statement and menu structure description statement.

Basic elements of the ①kconfig file: Config keyword (entry)

Config entries are often included in other entries to generate menus, make multiple selections, and so on. The config entry is used to configure an option, or so it is used to generate a variable that, along with its value, is written to the configuration file. config. This means that the Config keyword defines the new configuration options, and the next few lines define the properties of that configuration option. The properties of configuration options include type, data range, input hint, dependency, help information, default value, and so on.

For example, there is a config entry for configuring config_xxx, and depending on the user's choice, one of the following 3 configuration results may appear in the. config file.

config_xxx=y   # The corresponding file is programmed into the kernel config_xxx=m   # The corresponding file is compiled into module #config_xxx   # The corresponding file is not used

Like what

config tiny4412_leds #配置选项的名称         " LED support for Friendlyarm Tiny4412 GPIO LEDs "        #tristate是变量类型有5种       #Bool  boolean type, the result is y[*],  n[]       #tristate Three choices, the result is y[*], N[], m[m]       #String  string, result (arm-linux-)       #Hex   hexadecimal       #Int   decimal        depends on mach_tiny4412 #依赖        #当依赖满足事, the prompt for the current configuration option appears before you can set the current configuration option        #如果依赖条件不满足, it takes the default value.        default y #默认为y help        #帮助信息           for   LEDs connected-GPIO lines on          Tiny4412 Boards.

The effect is as follows when configured with make Menuconfig

②menu keywords

The menu entry is used to generate the menus, which appear as------> in the Menuconfig format as follows:

"Menu" <prompt><menu options><menu block>"endmenu"

After menu, the string is the menu name, and there are many config entries between "menu" and "Endmunu". On the configuration screen, the following menu appears, moving the cursor after selecting it and pressing ENTER, you will see the configuration options defined by these config entries.

③source keywords

In the current kconfig contains the kconfig of the other directory for reading into another Kconfig file in the following format:

"Source" <prompt>

Let's look at an example

" Device Drivers " Kconfig......config in the "drivers/tty/kconfig" #引入drivers/TTY directory     Tiny4412_leds        "LED support for Friendlyarm Tiny4412 GPIO LEDs"         Depends on mach_tiny4412        default y          Help for  LEDs connected to GPIO lines          on Tiny4412 boards.......endmenu# Menu Ends

④choice keywords

The choice entry combines several similar configuration options for a single or multiple selection of users, in the following format:

"Choice"<choice options><choice block>"end Choice"

In practice, multiple config entries are also defined between "choice" and "Endchoice".

Also look at an example

Choice Prompt"Kernel Compression Mode"default kernel_gzip depends on Have_kernel_gzip|| HAVE_KERNEL_BZIP2 | | Have_kernel_lzma | | Have_kernel_xz | |Have_kernel_lzo help the Linux KERNEL are a kind of self-extracting executable. Several compression algorithms is available,whichdifferinchefficiency, compression and decompression speed.      Compression speed was only relevant when building a kernel.      Decompression speed are relevant at each boot. If you had any problems withbzip2or Lzma compressed kernels, mail me (Alain knaff)<[email protected]>. (An older version of this functionality (bzip2only), for 2.4, was supplied by Christian Ludwig) High compression options is mostly useful forUsersW.H.O.is low in disk space (embedded systems), but forwhom RAM size matters Less. IfinchDoubt,Select 'gzip'config Kernel_gzipBOOL "Gzip"depends on Have_kernel_gzip help the old and triedgzipcompression. It provides a good balance between compression ratio and decompression speed.config KERNEL_BZIP2BOOL "Bzip2"Depends on HAVE_KERNEL_BZIP2 help it compression ratio and speed are intermediate.  Decompression speed is slowest among the choices. The kernel size is aboutTen% smaller withbzip2,inchComparison togzip. BZIP2 uses a large amount of memory. For modern kernels you'll need at least 8MB RAM or More  forbooting.config Kernel_lzmaBOOL "LZMA"depends on Have_kernel_lzma help this compression algorithm's ratio is best. Decompression Speedis betweengzipandbzip2.      Compression is slowest. The kernel size is about -% smaller with LZMAinchComparison togzip. config Kernel_xzBOOL "XZ"depends on HAVE_KERNEL_XZ help XZ uses the LZMA2 algorithm and instruction set specific BCJ filters /c0>whichcan improve compression ratio of executable code. The size of the kernel is about -% smaller with XZinchcomparison togzip. On architectures for whichThere is a BCJ filter (i386, x86_64, ARM, IA- -, PowerPC, and SPARC), XZ would create a few percent smaller kernel than plain LZMA. the speed was about the same as with lzma:the decompression speed of XZ was better than that'sbzip2But worse thangzipand LZO. Compression is Slow.config Kernel_lzoBOOL "LZO"Depends on Have_kernel_lzo help it compression ratio is the poorest among the choices . The kernel size is aboutTen% bigger thangzip; however its speed (both compression and decompression) is the Fastest.endchoice

The interface at the time of configuration is as follows

5.2 Makefile in the kernel

The main functions of makefile in the kernel are the following points:

① decide which files to compile

② How to compile these files

③ How to connect these files, the most important is their order

(1) Decide which files to compile

The Linux kernel's compilation process starts at the top-level makefile, and then recursively goes to all levels of subdirectories to invoke their makefile, divided into 3 steps:

① top-level makefile determines which subdirectories under the kernel root directory will be compiled into the kernel;

②arch/<arch>/makefile decide which files and which directories will be compiled into the kernel arch/<arch> directory;

③ the makefile at all levels of the subdirectory determines which files in the directory are to be compiled into the kernel, which files will be compiled into modules (i.e., drivers), and which subdirectories continue to invoke their makefile.

You can see the following in the top-level makefile:

Core-y          + =kernel/mm/fs/ipc/security/crypto/block// subdirs We need to visitinit-y          : = init/   Drivers-y       : = drivers/sound/firmware/net-y           : = net/ libs-y          : = lib/  Core-y          

As we can see, the most important arch directory does not appear in the kernel. It is included in the kernel in arch/$ (ARCH)/makefile, which is directly contained in the top-level makefile Makefile

Include $ (srctree)/arch/$ (srcarch)/makefile

For ARCH variables, they can be passed in when make is executed, such as makes Arch=arm. Also, for non-X86 platforms, you need to specify a cross-compilation tool, which can also be passed in when the make command is executed, such as makes cross_copile=arm-linux-.

For Arch/<arch>/makefile, take arm as an example, you can see the following in Arch/arm/makefile:

#对应arch/arm/kernel/Head. OHead-Y: = arch/arm/kernel/Head$ (mmuext). O ... core-$ (CONFIG_FPE_NWFPE) + = arch/arm/nwfpe/Core-$ (CONFIG_FPE_FASTFPE) + =$ (fastfpe_obj) Core-$ (CONFIG_VFP) + = arch/arm/vfp/# If We have a machine-specific directory, ThenInclude itinchThe build.core-Y + = arch/arm/kernel/arch/arm/mm/arch/arm/common/Core-Y + = arch/arm/net/Core-Y + +$ (machdirs) $ (platdirs) Drivers-$ (config_oprofile) + = arch/arm/oprofile/Libs-Y: = arch/arm/lib/$ (libs-y)

Config_ is defined when the kernel is configured, it has 3 values: Y, M, or empty. Y is the kernel, M is a module, and null means not used.

When the kernel is compiled, the net-y of the directories listed in Init-y, Core-y, Libs-y, drivers-y, and makefile are executed sequentially, and each subdirectory generates a BUILT-IN.O (in the directory listed in Libs-y, Possible to generate a LIB.A file). Finally, the files represented by Head-y will be connected to the kernel image file Vmlinux together with these built-in.o, LIB.A.

Under the sub-directories of all levels There are also individual makefile its main functions and for:

When configuring the kernel, build the configuration file. config. The top-level makefile of the kernel uses the following statement to indirectly include the. config file, which is later determined by the individual variables defined in. config. It contains the include/config/auto.conf file and then removes the comments from the. config file and adds some variables based on the variables defined in the top-level makefile.

#linux-3.5/drivers/char/makefileobj-$ (config_tiny4412_leds)     + = tiny4412_ Leds.oobj-$ (config_tiny4412_hello_module)     + = tiny4412_hello_module.oobj-$ (config_tiny4412_ BUTTONS)  + = tiny4412_buttons.oobj-$ (config_tiny4412_buzzer)   + = tiny4412_pwm.oobj-$ ( Config_tiny4412_backlight) + = tiny4412_backlight.oobj-$ (CONFIG_TINY4412_ADC)              + = TINY4412_ADC.O

How to link:

For the arm system, the connection script is Arch/arm/kernel/vmlinux.lds, which is made by Arch/arm/kernel/vmlinux/lds. S file generation.

6. Add a new module to the kernel

Whether you add a new feature to the kernel or a driver, you need to add the appropriate code to the kernel build system, and you need to do the following three tasks:

① will write the source code copied to the Linux kernel source code corresponding to the directory

② compile configuration options for the source code corresponding project in the directory's Kconfig file

③ add a compile entry to the Xinyuan code in the directory makefile file

The following is an example of the LED driver just now to illustrate

① will write the source code copied to the Linux kernel source code corresponding to the directory

② compile configuration options for the source code corresponding project in the directory's Kconfig file

③ add a compile entry to the Xinyuan code in the directory makefile file

Tiny4412 Linux Kernel configuration process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.