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
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
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Why can't I download the program on my LPC?
- Tesla exposed a low-level vulnerability: Use Raspberry Pi to DIY car keys, unlocking in just 90 seconds
- Instructions for using 86 box modbus
- Xinhua Dictionary of Power Supply--A brief review of the book "Basics of Power Supply Design"
- MSP430 FAQs: Watchdog and Timer
- Chip supply issues
- Do you have more award-winning power banks? If so, please give me one.
- I want to know what this DSA is and why I don't choose a fixed resistance resistor.
- Review Summary: Tuya Sandwich Wi-Fi & BLE SoC NANO Main Control Board
- Comparison between microbit and CLUE