Embedded Development (Linux kernel compilation and installation)

Source: Internet
Author: User
Part of embedded development practices (Linux kernel compilation and installation) is translated from embedded Linux kernel and driver development

By Michael opdenacker Liu Jianwen (http://blog.csdn.net/keminlau

)

Key: Linux Kernel Compiling Kernel configuration embedded

Kernel configuration makefile version Modification

To distinguish non-kernel images built based on the same source code (bulid), you can use the variable extraversion (defined at the top of makefile ):

$ Head-4 makefile <br/> Version = 2 <br/> patchlevel = 6 <br/> sublevel = 7 <br/> extraversion =-acme1

Running "uname -- R" will return: 2.6.7 -- acme1

Kernel configuration

First, define and configure the features required by the kernel. The kernel build system is far from simply used to build the entire kernel and module. To learn more about the advanced kernel build options, you can view the kernel documentation in the documentation/kbuild directory.

Available configuration commands and methods:

  • Make xconfig
  • Make menuconfig
  • Make oldconfig
  • Or manually write

Kernel configuration file. config and kernel compilation makefile?

The kernel is a C program compiled and installed using make. The C program is very modern and complex, and it is difficult to complete the compilation task with only one makefile. Assume that only one makefile is required for Kernel compilation. This makefile will also vary depending on the kernel for Compiling different functional features. That is to say, The makefile required for Kernel compilation is "compiled" first, this makefile is dynamically generated. So where does this dynamic makefile come from? The answer is that the config command reads [Kernel configuration file
] (Kernel configuration file) to generate all the files required to compile the kernel (including makefile); then [Kernel configuration file
] Where did it come from? Or make. Various make config (xconfig/menuconfig) will generate the required [Kernel configuration file
].

The Kernel configuration file is saved as the. config file in the top-level directory of the kernel source code. The Kernel configuration file of the release version is usually in/boot.

Command: Make xconfig

  • Qconf: A New QT-based configuration interface, kernel version 2.6
  • Easier to use (remember to read help-> Introduction: useful options !)
  • Supports file browsing, making it easier to load configuration files.

Command: Make menuconfig

  • The old character interface still works well. You are confident that you can hand-Write the configuration file!

Command: Make oldconfig

  • Configuration file used to upgrade the kernel released earlier
  • Warning some absolute symbols (obsolete symbols)
  • Query the configuration value of the new symbol.

What is makefile?

Makefile contains a set of rules used to build applications ). And the first [Rules

] Is special [Rules

], Called [Default rules

] (Default rule ). A [Rule] consists of three parts: Target, prerequisites, and command ):
Target: prereq1 prereq2 <br/> [Tab] commands

[Target
] Is built (made [File
] Or something else. [Prerequisites
Or dependents is the "material" of the build target ". And [Command action
] Is to use [Prerequisites
] Build [Target
.

The following is an example of how to compile C source code:

Foo. O: Foo. c Foo. H <br/> [Tab] gcc-C Foo. c

Note that the format is [Target
], Followed [Prerequisites
]; [Command
] In the second line and starts with a Tab character.

 

Compile and install the kernel

Compilation steps:

$ CD/usr/src/linux2.6 <br/> $ make

 

Installation Procedure (logged as root !)

$ Make install <br/> $ make modules_install

The following steps are not used in analyticdb 2.6:

$ Make depends <br/> $ make modules (done by make)

Improved Compilation speed

Spend more time on Kernel configuration and compile only the modules required by your hardware. In this way, the Compilation Time can be shortened to 1/30 of the original compilation time, and the storage space can be reduced by several hundred MB. In addition, you can compile multiple files in parallel:

$ Make-j <number>

Make can execute multiple targets in parallel (Kemin: The premise is that there is no cross dependency between target rules. How can this be done ?)

$ Make-J 4

  • Even on a single-processor workstation, the time for reading and writing files is saved. Multithreading keeps the CPU busy.
  • Number greater than 4 is not necessarily effective, because too many context switches reduce the working speed.
  • Make-j <4 * number_of_processors>

Kernel compilation tips

  • View the complete (GCC, LD) command line: $ make v = 1
  • Clear all generated files (to create patches...): $ make mrproper
  • Partial Compilation: $ make m = Drivers/USB/serial
  • Compile the module separately: $ make drivers/USB/serial/visor. Ko
  • Compile elsewhere (assuming the source code is in CDROM ):
    • $ CdS/mnt/CDROM/linux-2.6.17.11
    • $ Make o = ~ /Linux/linux-2.6.17.11
Final generated file
  1. Original kernel image of vmlinux, non-compressed
  2. ARCH/<arch>/boot/zimage zlib compressed kernel image (default image on arm)
  3. ARCH/<arch>/boot/bzimage Bzip2 compressed kernel image. Usually very small, enough to put a floppy disk (default image on i386)
Installed files
  • /Boot/vmlinuz-<version> kernel image;
  • /Boot/system. Map-<version> Save the signed address (symbol addresses) with the kernel );
  • /Boot/initrd-<version>. IMG initial RAM disk: stores the modules that need to be mounted to the final root file system during boot. The installation command "make install" generates an initrd for you to run "mkinitrd;
  • /Etc/grub. conf or/etc/Lilo. conf
  • Bootloader configuration file: "make install" will update the corresponding bootloader configuration file for your new kernel. If you are using Lilo, it will execute/sbin/lilo After generating the configuration file to make the configuration of lilo take effect.
  • /Lib/modules/<version>/kernel modules + Extras
    • Build/

      All the things required to add a module to the <version> kernel :. config File (build /. config), module Symbol Information (build/module. symvers), kernel headers (build/include /)

    • Kernel/

      The kernel module File. Ko (Kernel Object) has a one-to-one correspondence between the directory structure and the source code target.

    • Modules. Alias

      Module alias record (for insmod and modprobe), for example:

      Alias sound -- service --? -0 snd_mixer_oss

    • Modules. Dep

      Module dependency record (for insmod and modprobe)

    • Modules. Symbols

      Identifies the module to which a symbol belongs.

All files in this directory are text files and can be viewed directly.

Summary of compilation and installation steps:
  1. Edit makefile version information
  2. Define the kernel features and generate the configuration file. config for compiling: Make xconfig
  3. Compile the kernel: Make
  4. Install the kernel: make install
  5. Installation module: Make modules_install

 

Modify the makefile of the Cross-compiled Kernel

It is usually obtained by modifying the existing makefile.

You must modify the target platform. If the target platform is arm, modify the following:

Arch? = Arm <br/> cross_compile? = Arm-Linux-

Or run make with parameters:

$ CD/usr/scr/linuxxx <br/> $ Make arch = arm cross_compile = arm-Linux-

 

Kernel configuration file

The configuration process is the same as the local configuration;
You can share the generated configuration file (. config) with others, such:

$ <Br/> $ CP. config ARCH/<arch>/config/acme_defconfig

 

In this way, other developers who develop Acme systems can compile the same kernel using the following command:

$ Make acme_defconfig <br/> $

 

Create a cross-compilation environment (cross -- compiling setup)

Suppose you have an arm cross-compilation tool (cross -- compiling toolchain) in/usr/local/ARM/3.3.2/, You have to output it to path:

$ Export Path =/usr/local/ARM/3.3.2/bin: $ path

 

Check the kernel documentation (in documentation/changes) for the minimum tool version requirements.

Compile and install the kernel

1. $ make // if you have modified makefile

Or

1'. $ Make arch = arm cross_compile = arm-Linux-

2. Copy ARCH/<platform>/boot/zimage to the target system.

$ Make modules_install

3. Copy/lib/modules/<version> to the target system.

You can use ARCH/<arch>/boot/install. Sh to customize the installation and make "make install" automatically.

What is the cross-compilation toolchain )?

Like any other development activity, the first step of embedded development is to set up a toolchain for building embedded linux kernels (including drivers of course) and applications ). However, embedded development requires a cross-platform tool chain. What does cross-platform mean? Generally, development activities are locally compiled and used as a local tool chain. However, due to embedded hardware and software resources (insufficient memory, no local compiler or operating system) restrictions cannot be used for local development. It needs to be developed on the Linux-x86 host, using the host's compiler to generate the target platform code called cross-compilation.

We often say that compilers have broad and narrow meanings. In a narrow sense, the compiler only completes the first step of software compilation (or software build). In a broad sense, the compiler includes the code library required for software compilation (or software build) (such as libc) and other build tools (such as assembler and connector ). No matter what compilers need to support code libraries and various build tools, cross-compilation is no exception. A complete set of compilers in the broad sense is called the cross-compilation tool chain.

What is tool chain?

In software, a toolchain is the set of computer programs (tools) that are used to create a product (typically another computer program or system of programs ). the tools may be used in a chain, so that the output of each tool becomes the input for the next, but the term is used widely to refer to any set of linked development tools.

A simple software development toolchain consists of a text editor for editing source code, a compiler and linker to transform the source code into an executable program, libraries to provide interfaces to the operating system, and a debugger.

The GNU toolchain is a blanket term for a collection of programming tools produced by the GNU project. these tools form a toolchain (suite of tools used in a serial manner) used for developing applications and operating systems.

Projects have ded In the GNU toolchain are:

  • * GNU make: automation tool for compilation and build;
  • * GNU Compiler Collection (GCC): suite of compilers for several programming languages;
  • * GNU binutils: suite of tools including linker, javaser and other tools;
  • * GNU bison: Parser Generator
  • * GNU M4: M4 macro Processor
  • * GNU Debugger (GDB): Code debugging tool;
  • * GNU build system (autotools ):
    • O Autoconf
    • O autoheader
    • O automake
    • O libtool
Reference
  • Http://www.developingprogrammers.com/index.php/2006/01/05/autotools-tutorial/

 

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.