Xunwei 4412 Development Board Linux Driver Tutorial - Kernel Development Basics

Publisher:心连心意Latest update time:2021-12-02 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

main content

• Linux architecture

• Linux kernel structure

• Linux kernel source directory structure

 

Linux Architecture

 

 

As can be seen from the above figure, the Linux architecture consists of user space and kernel space.

• Why is the Linux system divided into user space and kernel space?

• Analyze from the programmer's perspective

– Separate the Linux underlying layer and applications. Those who work on applications should work on applications, and those who work on the underlying layer should work on the underlying layer, each doing their own thing.

The principle of economics is that division of labor creates efficiency.

 

From the perspective of security, in order to protect the kernel, modern CPUs usually implement different working modes. Take ARM as an example: ARM implements 7 working modes, and the instructions that the CPU can execute or the registers that it can access are different in different modes:

– (1) User mode usr (2) System mode sys (3) Supervisor mode svc (4) Fast interrupt fiq (5) External interrupt irq (6) Data access termination abt (7) Undefined instruction exception

– Take (2) X86 as an example: X86 implements 4 different levels of permissions, Ring0-Ring3; Ring0 can execute privileged instructions and access IO devices; Ring3 has many restrictions

– Take Android as an example: Put the application on the Java virtual machine to run, and the application is further away from the underlying

• User space and kernel space are two different states of program execution. We can complete the transfer from user space to kernel space through "system calls" and "hardware interrupts"

 

Linux kernel structure



 

System Call Interface (SCI layer)

– Provides a set of standard system call functions for user space to access the Linux kernel.

• Process Management (PM)

– Process management is creating processes (fork, exec), stopping processes (kill, exit), and controlling the communication between them (signal, etc.). It also includes process scheduling, which controls how active processes share the CPU.

• Memory Management (MM)

– The main function of memory management is to control the safe shared memory area of ​​multiple processes

 

• Virtual File Systems (VFS)

– Virtual file system, hiding the specific details of various file systems and providing a unified interface for file operations

– Linux provides a large general model that encompasses the entire set of file system functionality (everything is a file)

 

 

 

• Device Drivers

– The Linux kernel contains a large amount of code in the device driver section, which is used to control specific hardware devices.

– Linux drivers are generally divided into network devices, block devices, character devices, and miscellaneous devices

• Network protocol stack

– The kernel network protocol stack provides a rich set of network protocol implementations for Linux.

 

Directory Structure

• The Linux kernel source code uses a tree structure. Function-related files are placed in different subdirectories

, making the program more readable.

 

 

• arch directory

– The arch directory is the platform directory. All CPU architectures supported by the kernel have corresponding subdirectories under this directory. Each CPU subdirectory is further divided into boot, mm, kernel and other subdirectories, which control system boot, memory management, and system calls respectively. There are also dynamic frequency modulation, main frequency setting parts, etc.





summary

• 2% of programmers write 80% of the effective code

– When you first start learning, the most important thing is to read the code. However, when learning the Linux system, you cannot dive into irrelevant code in the kernel. You will never be able to finish reading tens of thousands of files in your lifetime.

• Linux is complex and powerful.

– The kernel source code is 1.3G after decompression and compilation, and the Linux image zImage compiled by trimming is less than 4M

– In the 4M source code image, most of it does not need our attention

– We only need to understand the parts that are helpful for writing code and master the code we need to master

– Only the red part of the Linux code above needs to be understood or mastered

• As a developer, we only need to learn to use it, and we should focus on learning only a small part of it.

– A certain understanding of the architecture is sufficient

– The focus of learning is knowledge related to driver development, function calls, driver protocols, and simple hardware knowledge

Reference address:Xunwei 4412 Development Board Linux Driver Tutorial - Kernel Development Basics

Previous article:Build and compile the Android 4.4.4 environment for the 4412 development board
Next article:4412ARM Development Board Study Notes (I)

Recommended ReadingLatest update time:2024-11-16 12:47

linux-2.6.32 ported to mini2440 development board - ported I2C-EEPROM driver
1 Configure I2C driver in the kernel Linux-2.6.32.2 provides a complete driver for the I2C interface of S2C2440, so we only need to configure it in the kernel to use it. Execute: make menuconfig in the kernel source code directory to enter the kernel configuration main menu, and select the following submenus
[Microcontroller]
linux-2.6.32 ported to mini2440 development board - ported I2C-EEPROM driver
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号