Let's dive deep into the Linux kernel source code and officially step into the world of driver development. Whether you are an embedded system developer or an operating system researcher, the Linux kernel source code is a treasure trove of knowledge. So, are you ready?
1. Official Kernel Source Code
TIP
The mainline we often refer to is actually the Linux mainline code, maintained and continuously developed by the community team led by Linus Torvalds. The mainline kernel source code is constantly changing, incorporating new features, optimizations, and fixes contributed by developers worldwide.
The authoritative way to obtain the mainline Linux kernel is at: https://www.kernel.org/
Here you can find different branches:
| Branch | Maintainer | Authority and Purpose | Target Users |
|---|---|---|---|
| mainline | Linus | The mainline kernel we often refer to, where all new features and changes are first introduced. New mainline kernels are released approximately every 9-10 weeks. | Developers |
| prepatch/RC | Linus | Pre-release versions of the mainline kernel, mainly used for community testing and bug finding. After multiple RC version corrections, a new mainline kernel is officially released. | Developers/Testers |
| stable | Dedicated maintainer | Branch maintained after mainline official release. Stable versions are based on mainline versions and only accept important bug fixes and security patches. These patches come from mainline and are backported by designated stable maintainers. | All users |
| longterm/LTS | Dedicated maintainer | Long-term support, providing critical bug fixes and security patches for older kernel versions. Mainly used for enterprise, server, or embedded long-term operating environments. | Enterprise/Long-term users |
| linux-next | Community collaboration | "Pre-integration" of the next mainline, used for community collaboration and integration testing. | Kernel developers/Integrators |
| Subsystem branches | Subsystem maintainers | Different functional areas development, maintained by respective maintainers. Patches eventually flow to linux-next and mainline. | Kernel developers |
It's worth noting that semiconductor vendors and kernel enthusiasts usually download the corresponding version of kernel source from the official website and modify and optimize it according to their needs. For example, they might add patches or drivers for specific SoC chips (CPU) to enable the kernel to run on specific hardware platforms.
In actual development and learning, we don't download source code directly from the Linux kernel official website but rely more on customized source packages provided by semiconductor vendors. However, regardless of where the source comes from, it doesn't affect our understanding of its core structure and functionality.
2. Obtaining TaishanPi Kernel Source Code
The TaishanPi kernel source code is generally included in the SDK, which also contains the stable version compiler provided by the chip manufacturer. Therefore, we usually download the entire SDK.
INFO
LCSC-TaishanPi-3M-RK3576 SDK Acquisition: Jump to Tutorial🚀
After downloading, you will see this structure:
3. TaishanPi Source Directory Analysis
The following is the TaishanPi-3-Linux SDK directory structure and its purposes:
| Directory/File | Purpose |
|---|---|
app/ | Application layer source code or example programs, demonstration, testing, and actual application code |
buildroot/ | Buildroot build system, automated root file system and cross-compilation toolchain building |
debian/ | Debian packaging, customization, and mirror making scripts |
device/ | Device-related configuration, BSP, hardware platform support, compilation scripts |
docs/ | Documentation directory, containing usage instructions, development manuals, API documentation, licenses, etc. |
external/ | External dependency libraries or third-party component source code |
hal/ | Hardware abstraction layer, masking hardware differences, providing unified interface to upper layers |
kernel-6.1/ | Linux 6.1 kernel source code and related patches and configurations |
kernel → kernel-6.1/ | Soft link pointing to kernel-6.1 for unified kernel source access |
prebuilts/ | Precompiled binary files and compiler toolchains |
rkbin/ | Rockchip platform-related binary firmware, tools, and configurations |
rtos/ | Real-time operating system (RTOS) related source code or projects |
tools/ | Various development, flashing, debugging, and auxiliary tool scripts |
u-boot/ | U-Boot bootloader source directory |
yocto/ | Yocto project related directory for customized Linux distribution building |
.repo/ | repo tool metadata and configuration for multi-repository management |
Copyright_Statement.md | Copyright statement file |
Makefile | Main Makefile for one-click compilation and building of entire SDK |
build.sh | One-click build script for automated compilation process |
envsetup.sh | Environment initialization script for setting cross-compilation environment variables |
rkflash.sh | Flashing script for writing firmware to development board |
tspi-sdk-init.sh | SDK initialization script for environment configuration and dependency installation |