National embedded video learning notes-Linux kernel Development 1

Source: Internet
Author: User

I. Introduction to Linux Kernel

1. the Linux system consists of two parts: kernel space and user space.

2.User spaceIncluding: user applicationsProgramAnd C library

3.Kernel spaceIncluding: System Call interfaces, kernel and architectureCode.

4. Arm Processors7 working modes: User mode, fast interrupt mode, external interrupt mode, management mode, data access termination, system mode, undefined command exception

5. Why is Linux divided into user space and kernel space?

For security reasons, Linux uses the hierarchical operating mode of the processor to run the kernel and applications separately. Fully protect the operating system.

6.System calls and hardware interruptions: Enables the program to switch between the kernel space and the user space.

7. Linux kernel structure (composition ):

System Call interface: connect the kernel space to the user space

Process Management: Process Creation, Process Communication, and process scheduling

Memory Management: Memory Allocation recycling, address translation (Virtual-physical)

Architecture code: CPU code

Device Driver:

Network Protocol Stack:

Virtual File System:

Ii. KernelSource code

 

Arch: the abbreviation of architecture. System Structure Code.

Block: Drive of some Block devices.

Crypto: encryption.

Drivers: Device Driver

FS: File System

Include: header file required by the kernel

Lib: Library File

MM: Memory Management Code (unrelated to the architecture)

Iii. Kernel configuration and compilation

1. Clear temporary files, intermediate files, and configuration files

Make clean: delete most of the files generated in the middle to save the configuration file. o

Make mrproper: delete intermediate files and configuration files

Make distclean: delete patches and editor backups Based on mrproper.

2. Configure the kernel

Make config: Interactive configuration based on text mode

Make menuconfig: text-based menu configuration (menus are generated by scripts in the kernel)

Make oldconfig: use an existing configuration file (. config)

Make xconfig: Graphical Configuration

3. How to configure

The arch/$ CPU/configs directory contains configuration files for reference. You can modify and configure it on this basis.

4. Compile the kernel

X86:

Make zimage: x86 can only be used for kernels smaller than kb.

Make bzimage.

To obtain detailed compilation information, add v = 1, as shown in figure

Make zimage v = 1

5. Compile the kernel module: (you must first compile the kernel)

Make modules

6. Install the kernel module:

Make modules_install

4. Linux kernel module development

1. What is a kernel module (feature)

The module itself is not compiled into the kernel

Dynamic installation or uninstallation during kernel running as needed

2. kernel module Program

Module Loading Function (required): specified by module_init macro.

Module uninstallation function (required): specified by the module_exit macro.

3. kernel module Compilation

Use makefile

For a single file

Ifneq ($ (kernelrelease),) obj-M: = hello. oelsekdir: =/lib/modules/2.6.18-53. e15/build // kernel source code path all: Make-C $ (kdir) M = $ (PWD) Modules // enter the directory after-C and use its makefile for compilation; kernel module code location, Pwd = Current Directory clean: Rm-f *. ko *. O *. mod. O *. mod. C *. symversendif

Multiple files

 
Ifneq ($ (kernelrelease),) obj-M: = hello. O // The Name Of The internal medicine module hello-objs: = Main. o add. O // The source file elsekdir required by the kernel module: =/lib/modules/2.6.18-53. e15/build // kernel source code path all: Make-C $ (kdir) M = $ (PWD) Modules // enter the directory after-C and use its makefile for compilation; kernel module code location, Pwd = Current Directory clean: Rm-f *. ko *. O *. mod. O *. mod. C *. symversendif

4. Install and uninstall the kernel module

Insmod Loading

Rmmod uninstall

View lsmod

Modprobe loading: view the dependent modules and load them first.

5. Optional module information

License statement: module_license ("GPL ")

Author's statement: module_author

..................

Module parameters: module_param specifies the module parameters. It is used to pass parameters to the module during loading.

 
Module_param (name, type, Perm)

Name: module parameter name

Type: bool, Int, CHARP

Perm: module parameter access permission s_irugo: any user has read permission s_iwusr

 
Int A = 3; char * st; module_param (A, Int, s_irugo); module_param (St, CHARP, s_irugo );

6. kernel symbol Export

Export_symbol (symbol name)

Export_symbol_gpl (symbol name): it can only be used for modules that contain the GPL license.

7. kernel version mismatch

The kernel module version depends on the kernel code version.

The version of the currently running kernel.

The insmod program may encounter errors when the two versions are different.

Solution:

(1) Use modprobe -- force-modversion to force loading

(2) ensure that the current kernel version is the same. uname-R allows you to view the current kernel version.

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.