1- # PenguinLab — 30 天嵌入式 Linux 内核学习计划
1+ < div align = " center " >
22
3- 面向有 C 语言和嵌入式基础(STM32 / FreeRTOS)的工程师,通过 QEMU + 真机(i.MX6ULL / 全志 H618)实践,掌握 Linux 内核驱动开发、内核移植定制和性能调优。
3+ # PenguinLab
4+
5+ ** Linux 内核学习站 — 从 QEMU 实践到内核原理、驱动开发与嵌入式全栈**
6+
7+ [ ![ Kernel] ( https://img.shields.io/badge/Linux%20Kernel-6.19.y-blue )] ( https://kernel.org )
8+ [ ![ Arch] ( https://img.shields.io/badge/Arch-ARM32%20%7C%20ARM64%20%7C%20RISC--V%20%7C%20x86__64-green )] ( https://github.com/Awesome-Embedded-Learning-Studio/PenguinLab )
9+ [ ![ Docusaurus] ( https://img.shields.io/badge/Docusaurus-3.10-orange )] ( https://docusaurus.io )
10+ [ ![ License] ( https://img.shields.io/badge/License-MIT-yellow )] ( LICENSE )
11+
12+ [ English] ( # ) · [ 在线阅读] ( https://awesome-embedded-learning-studio.github.io/PenguinLab/ ) · [ 开始学习] ( #快速开始 )
13+
14+ </div >
15+
16+ ---
17+
18+ ## 为什么要有 PenguinLab?
19+
20+ 学 Linux 内核的资料不少,但大多要么偏理论(ULK、LKD 看完还是不会写驱动),要么偏实操(LDD3 的 API 已经过时)。PenguinLab 想做的是:
21+
22+ - ** 知识图谱驱动** ,不是线性教程——你可以按推荐路径走,也可以根据兴趣自由选择下一步
23+ - ** 全栈覆盖** ——从内核模块基础到调度器、内存管理、设备驱动、嵌入式 BSP、调试调优、虚拟化,一个站点搞定
24+ - ** 纯 QEMU 实践** ——不需要开发板,ARM32/ARM64/RISC-V/x86_64 四种架构都能跑
25+ - ** 基于最新稳定内核 6.19.y** ——不教过时 API,不拿 2.6 时代的代码糊弄人
26+
27+ ## 内容覆盖
28+
29+ PenguinLab 采用 ** 6 层知识图谱** 组织教程,89 个知识节点之间有明确的前置/后继关系:
30+
31+ <table >
32+ <tr ><td ><strong >Layer 0</strong ></td ><td >🎯 通识基础</td ><td >环境搭建 · Kconfig · 内核模块 · 数据结构 · 进程与地址空间</td ><td ><strong >10 节点</strong ></td ></tr >
33+ <tr ><td ><strong >Layer 1</strong ></td ><td >🧠 内核子系统</td ><td >调度器 · 内存管理 · 文件系统 · 网络栈</td ><td ><strong >26 节点</strong ></td ></tr >
34+ <tr ><td ><strong >Layer 2</strong ></td ><td >🔧 驱动开发</td ><td >字符设备 · 平台驱动 · 设备树 · 中断 · GPIO · 同步原语</td ><td ><strong >22 节点</strong ></td ></tr >
35+ <tr ><td ><strong >Layer 3</strong ></td ><td >📦 嵌入式全栈</td ><td >交叉编译 · U-Boot · 内核裁剪 · Buildroot · BSP 项目</td ><td ><strong >8 节点</strong ></td ></tr >
36+ <tr ><td ><strong >Layer 4</strong ></td ><td >🔍 调试与性能</td ><td >printk · ftrace · perf · eBPF · KASAN · KGDB · Lockdep</td ><td ><strong >17 节点</strong ></td ></tr >
37+ <tr ><td ><strong >Layer 5</strong ></td ><td >☁️ 虚拟化与容器</td ><td >KVM · Namespaces · cgroups · 容器运行时</td ><td ><strong >7 节点</strong ></td ></tr >
38+ </table >
39+
40+ ### 知识图谱预览
41+
42+ ```
43+ ┌─→ sched-overview ──→ sched-cfs ──→ sched-rt
44+ │ │
45+ process-thread-kernel ───┤ └─→ sched-context-switch
46+ │
47+ ├─→ mm-overview ──→ mm-buddy ──→ mm-slab ──→ mm-vmalloc
48+ │
49+ ├─→ fs-vfs ──→ fs-ext4 · fs-procfs · fs-page-cache
50+ │
51+ └─→ net-overview ──→ net-sk-buff ──→ net-ipv4 ──→ net-tcp
52+
53+ kernel-module-basics ──→ drv-model ──→ drv-chardev ──→ drv-ioctl · drv-poll · drv-mmap
54+ │
55+ ├─→ drv-dts ──→ drv-platform ──→ drv-irq ──→ drv-threaded-irq
56+ │
57+ └─→ drv-sync ──→ drv-atomic ──→ drv-rcu
58+ ```
59+
60+ ## 基于真实的笔记和代码
61+
62+ PenguinLab 不是凭空写出来的,背后有 ** 253 篇学习笔记** 和 ** 12 个可构建的代码示例** 作为内容基础:
63+
64+ | 笔记来源 | 篇数 | 覆盖范围 |
65+ | ----------| ------| ----------|
66+ | * Linux Kernel Programming* | 13 章 | 内核基础、模块、进程、调度器、内存、同步 |
67+ | * Linux Kernel Device Drivers* | 22 章 | 设备模型、字符设备、procfs/sysfs、中断、DMA |
68+ | * Linux Kernel Debugging* | 93 章 | printk、ftrace、KASAN、Lockdep、KGDB、crash |
69+ | * Linux Kernel Networking* | 124 章 | 网络栈全貌、sk_buff、IPv4、TCP、Netfilter、XDP |
70+
71+ 每个代码示例放在 ` example/mini/ ` 下,自带 Makefile,支持多架构交叉编译:
72+
73+ ```
74+ example/mini/
75+ ├── kernel_module_hello/ # 最小内核模块
76+ ├── kernel_module_params/ # 模块参数
77+ ├── kernel_module_export/ # 符号导出
78+ ├── chardev_basic/ # 字符设备驱动
79+ ├── sysfs_attributes/ # sysfs 属性
80+ ├── debugfs_basics/ # debugfs 基础
81+ ├── linked_list_kernel/ # 侵入式链表(用户态实现)
82+ ├── kthread_demo/ # 内核线程
83+ ├── wait_queue_demo/ # 等待队列
84+ ├── mutex_spinlock/ # 互斥锁 vs 自旋锁
85+ ├── atomic_ops/ # 原子操作
86+ └── workqueue_demo/ # 工作队列
87+ ```
488
589## 快速开始
690
791### 1. 克隆仓库
892
993``` bash
10- git clone --recursive https://github.com/your-username /PenguinLab.git
94+ git clone --recursive https://github.com/Awesome-Embedded-Learning-Studio /PenguinLab.git
1195cd PenguinLab
1296
1397# 如果已克隆但未初始化子模块
@@ -17,20 +101,20 @@ git submodule update --init third_party/linux third_party/busybox
17101### 2. 安装工具链
18102
19103``` bash
20- # ARM32
21- sudo apt install gcc-arm-linux-gnueabihf
22-
23- # ARM64(可选)
104+ # ARM64 交叉编译
24105sudo apt install gcc-aarch64-linux-gnu
25106
107+ # ARM32(可选)
108+ sudo apt install gcc-arm-linux-gnueabihf
109+
26110# QEMU
27111sudo apt install qemu-system-arm
28112
29- # CMake(用于用户态示例)
30- sudo apt install cmake
113+ # 内核编译依赖
114+ sudo apt install build-essential libncurses-dev bison flex libssl-dev
31115```
32116
33- ### 3. 构建内核 + 根文件系统
117+ ### 3. 构建内核 + 启动 QEMU
34118
35119``` bash
36120# 构建 ARM64 内核
@@ -39,56 +123,71 @@ sudo apt install cmake
39123
40124# 构建最小 rootfs
41125./scripts/rootfs-minimal-maker.sh --static all
42- ```
43126
44- ### 4. 启动 QEMU
45-
46- ``` bash
127+ # 启动!
47128./scripts/qemu-run.sh run
48129```
49130
50- 内核启动后在 QEMU shell 里操作。退出 QEMU :` Ctrl+A X ` 。
131+ 内核启动后在 QEMU shell 里操作。退出:` Ctrl+A X ` 。
51132
52133## 目录结构
53134
54135```
55136PenguinLab/
56- ├── tutorial/ # Week 1 教程(环境搭建、Kconfig、数据结构、QEMU)
57- ├── todo/ # Week 2–4 学习计划(内核模块、驱动、DTS、BSP)
58- ├── example/ # 可构建的示例代码
59- │ ├── kernel_base_ds/ # 侵入式链表实现 + 12 个测试用例
60- │ ├── kernel_module/ # 最小内核模块、符号导出
61- │ └── chardev/ # 字符设备驱动 + 用户态测试
62- ├── scripts/ # 自动化脚本
63- │ ├── linux-action-scripts.sh # 内核配置与交叉编译
64- │ ├── qemu-run.sh # QEMU ARM 仿真
65- │ ├── rootfs-minimal-maker.sh # BusyBox 最小根文件系统
66- │ └── linux-submodule.sh # 子模块管理
67- ├── document/ # 参考文档
68- │ ├── booklist.md # 13 本书推荐(含章节定位和阅读时机)
69- │ └── qemu-reference.md # QEMU 速查手册
70- ├── third_party/ # 第三方子模块
71- │ ├── linux/ # Linux 内核 6.19.y
72- │ └── busybox/ # BusyBox
73- ├── .clang-format # 代码格式化配置
74- └── .clangd # clangd LSP 配置(内核源码导航)
75- ```
76-
77- ## 学习路线
78-
79- | 周次 | 主题 | 里程碑 |
80- | ------| ------| --------|
81- | Week 1 | 内核解剖 & 构建体系 | QEMU 跑起来交叉编译的 ARM 内核 |
82- | Week 2 | 内核模块 & 字符驱动 | 完整字符设备驱动 + 用户态测试程序 |
83- | Week 3 | DTS 深度 & 中断子系统 | 驱动在 imx6ull 真机上跑通 |
84- | Week 4 | BSP 实战 & 性能调优 | H618 内核定制 + I²C 综合驱动 |
85-
86- ## 使用建议
87-
88- - 每天** 先读对应教程的「要了解什么」部分** (10–15 分钟),再动手
89- - 命令块中的内容可以直接复制到终端执行
90- - 每个文件末尾有** 延伸阅读** ,标注了书名 + 具体章节
91- - 打 ✅ 标记完成的练习项,方便复盘进度
137+ ├── document/ # 教程、笔记和参考文档
138+ │ ├── tutorials/ # 教程(按知识图谱 6 层组织)
139+ │ └── notes/ # 学习笔记(253 篇)
140+ ├── example/ # 可构建的示例代码
141+ │ ├── mini/ # 单概念小示例(12 个)
142+ │ ├── project/ # 综合实战项目
143+ │ └── common/ # 共享构建文件(多架构支持)
144+ ├── scripts/ # 自动化脚本
145+ │ ├── linux-action-scripts.sh # 内核配置与交叉编译
146+ │ ├── qemu-run.sh # QEMU ARM 仿真
147+ │ └── rootfs-minimal-maker.sh # BusyBox 最小根文件系统
148+ ├── third_party/ # 第三方子模块
149+ │ ├── linux/ # Linux 内核 6.19.y
150+ │ └── busybox/ # BusyBox
151+ └── site/ # Docusaurus 网站源码
152+ ```
153+
154+ ## 推荐学习路径
155+
156+ PenguinLab 的知识图谱支持多条路径,这里列出四条典型路线:
157+
158+ ** 嵌入式驱动工程师** (最热门):
159+ ```
160+ 通识基础 → 内核模块 → 驱动模型 → 设备树 → 平台驱动
161+ → 字符设备 → 中断 → GPIO → DMA → 综合驱动项目
162+ ```
163+
164+ ** 内核爱好者** :
165+ ```
166+ 通识基础 → 进程/线程 → 调度器 CFS → 内存管理 Buddy/Slab
167+ → 文件系统 VFS → 网络栈 sk_buff → Netfilter → XDP
168+ ```
169+
170+ ** 调试专家** :
171+ ```
172+ 通识基础 → printk → ftrace → perf → eBPF → KASAN → KGDB
173+ → 综合性能调优实战
174+ ```
175+
176+ ** BSP 工程师** :
177+ ```
178+ 通识基础 → 交叉编译 → QEMU → U-Boot → 内核裁剪
179+ → 根文件系统 → Buildroot → 完整 BSP 项目
180+ ```
181+
182+ ## 参考书单
183+
184+ 教程内容参考了 13 本内核领域经典书籍,[ 完整书单见这里] ( https://awesome-embedded-learning-studio.github.io/PenguinLab/booklist ) 。核心参考包括:
185+
186+ - * Linux Kernel Development* — Robert Love
187+ - * Understanding the Linux Kernel* — Bovet & Cesati
188+ - * Linux Device Driver Development* — John Madieu
189+ - * BPF Performance Tools* — Brendan Gregg
190+ - * Mastering Embedded Linux Programming* — Frank Vasquez
92191
93192## 许可证
94193
0 commit comments