Preliminary Study on Linux Kernel Configuration and Compilation

Kernel configuration issues

When configuring the Linux kernel, we need to think about several questions:
(1) Configure which directories need to be compiled
(2) Configure which files need to be compiled
(3) When compiling, which directory is the file,
such as <mach/hardware.h>

Solution:
Makefile make

  • The Makefile
    under the main directory Makefile arch is related
    to other files through include
  • Makefile of each subdirectory
    obj-y: compile into the kernel
    obj-: not compile into
    obj-m: compile as a module
$(hdr-arch)
-I$(srctree)/arch/$(SRCARCH)/Makefile


SRCARCH=arm
hrd-arch   arm

How to configure the kernel

Configuration steps:
(1) Configuration warehouse selection
(2) Cross-compiler modification
(3) System structure selection
(4) Addition, deletion and modification check ( make menuconfig )

details:

  1. SUBARCH is X86 by default, and the default configuration of the kernel is
    changed to the word arm according to the X86 ARCH variable.
    Cross compiling
    CROSS_COMPILE
  2. Which files are compiled?
    CONFIG_xxx
    configuration sheet: linux-3.0.8/arch/arm/configs
    export the configuration sheet to the main directory export------> .config
    defconfig
  3. Modify defconfig to apply to the board

Implementation

details as follows,

  1. Modify the Makefile in the main directory (linux-3.0.8) to the following line 195 or so
ARCH            ?= arm
CROSS_COMPILE   ?= arm-linux-
  1. Copy the corresponding defconfig
cp arch/arm/configs/s3c6400_defconfig .config
  1. Then execute make menuconfig to add, delete, modify and check

After the configuration is complete, execute make uImage

If this error occurs---------------------------
Can't use'defined(@array)' (Maybe you should just omit the defined ()?) at kernel/timeconst.pl line 373.
---------------------->

solution:

  • In fact, the error message prompt has clearly told you that you should omit defined().
    Here, we open kernel/timeconst.pl
    @val = @{ KaTeX parse error: Expected'}', got'EOF' at end of input : canned_values{ hz}}; if (defined(@val)) { @val = compute_values( KaTeX parse error: Expected'EOF', got'}' at position 7: hz); }̲ output( hz, @val) ; Change if (defined(@val)) to if (@val) and compile again to pass. I checked the updates and found that one of them was that the Perl version was upgraded to v5.22.1. Then I checked the official Perl documentation and found that the official website had a bug and the version removed the defined (@array). You can directly use the array to determine non-empty.



Three image relationships

vmlinux: OS elf file (elf file executable by the operating system)

Insert picture description here
Image (larger) ---------> zImage (decompressed, but it does not meet the boot rules of uboot, so uImage supporting booting is produced) ---------> uImage

Kconfig syntax

Kconfig in the home directory

  • ---------> source "arch/$SRCARCH/Kconfig"
    means to include arch/arm/Kconfig
    source : include
  • Menu and endmuenu syntax: The displayed menu can be added as follows:
    Insert picture description here
  • config syntax :
    Insert picture description here
    after the
    configuration fiber information is executed, CONFIG_ABC=y appears in .config. The effect in Makefile is: obj-$(CONFIG_ABC) += XX.c
    bool: information
    tristate: tristate (compiled into the kernel, not Compile into the kernel, add to the kernel as a module)

Add led driver to the kernel

  1. Create a myled folder in the driver/char/ directory, and then copy the driver led.c file to this directory:
mkdir myled
cp led.c   /home/zhangbin/mini6410/linux-2.6.38/driver/char/myled/ 
  1. Create Makefile in the myled directory creation directory (format can refer to Makefile in other directories)
    Insert picture description here
  2. Then modify the Makefile of the parent directory (driver/char directory) as follows (line 81) obj-y += directory name/
    Insert picture description here
  3. Create Kconfig in the myled directory. The content is as follows
    Insert picture description here
  4. Modify the Kconfig of the upper-level directory to include the Kconfig
    source in the myled directory and
    Insert picture description here
    finally execute make menuconfig for configuration

Guess you like

Origin blog.csdn.net/qq_41782149/article/details/90176646