Chapter II starting from the kernel
First, access to the kernel source code
1. Using Git (Linux-created system)
Use Git to get a copy of the latest commit to the Linux version tree:
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
After downloading the code, update the branch to the latest branch of Linux:
$ git pull
These two commands can be obtained and kept consistent with the kernel's official code tree at all times.
2. Install kernel source code
The compression form is bzip2, then run:
$ tar xvjf linux-x.y.z.tar.bz2
If the compressed form is a zip of the gun, run:
$ tar xvzf linux-x.y.z.tar.gz
Where to install and touch the source: The kernel source code is generally installed in the/usr/src/linux directory,Pero prester atencion do not use this source tree for development. Do not modify the kernel as the boot identity, but create your own home directory. Even when installing a new kernel, the/usr/src/linux directory
should be guaranteed intact.
3. Using Patches
$ PATCH-P1 <. /patch-x.y.z
Second, the kernel source tree
Third, compile the kernel
1. Configuring the Kernel
Before compiling the kernel, you must configure it.
Configuration item Two Select one: Yes or no
Configuration item Three Select one: Yes or no or module. The module means that the configuration is selected and generated in the form of a module. drivers typically use three to select one of the configuration items.
The configuration option can also be a string or an integer.
Command-line tools for the character interface:
$ make Config
Graphical interface tools:
$ make Menuconfig
Create a configuration for the architecture based on the default configuration:
$ make Defconfig
To verify and update the configuration:
$ make Oldconfig
Compile kernel :
$ make
2, reduce the compilation of junk information
To redirect the output:
$ make >: /detritus
REDIRECT useless output information to a black hole with no return value:
$ make >/dev/null
3. Install the new kernel
The kernel needs to be installed after it is compiled.
Run as Root:
$ make Modules_install
You can install all the compiled modules into the correct home directory/lib/modules.
4, the characteristics of the core development
- Kernel development can neither access C library nor access standard C header files
- The kernel programming must use the GNU C
- Kernel programming lacks a memory protection mechanism like user space
- Difficult to perform floating-point arithmetic during kernel programming
- The kernel gives each process only a small fixed-length stack
- Because the kernel supports asynchronous interrupts, preemption, and SMP (symmetric multi-processing systems), synchronization and concurrency must always be noted.
- To consider the importance of portability
1) header File
Refers to the kernel header file that makes up the kernel source code tree. Cannot contain external header files.
The base header file is located in the Include directory under the top-level directory of the kernel source tree.
2) GNU C
GCC is a collection of various GNU compilers.
inline function: The function expands at the point where it is called. When defining an inline function, you need to use static as a keyword to qualify it with inline. Inline functions must be defined before they are used, and are generally defined in the header file. In the kernel, inline functions are preferred for type safety and legibility
Instead of a macro.
Inline assembly: The GCC compiler supports embedding assembly directives in C functions. Assembly code is typically embedded using ASM () directives.
Branch declaration: For conditional selection statements, GCC establishes an instruction for optimization, where the condition occurs frequently or infrequently, and the compiler can optimize it according to this instruction. The kernel encapsulates this instruction as a macro. For example likely () unlikely ()
Iv. Summary
The kernel has unique qualities. This chapter has learned some basic concepts and historical backgrounds, and in order to understand the kernel more deeply, we need to learn and experiment later.
"Linux kernel Design and implementation" chapter II