Skip to content

Commit 1047e32

Browse files
feat: ready to be public
1 parent cbc9e45 commit 1047e32

31 files changed

Lines changed: 3585 additions & 96 deletions

.clang-format

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
# .clang-format 配置文件
3+
# 用于 clangd 格式化和代码检查
4+
# 生成日期: 2026-02-15
5+
6+
# 基础风格: LLVM (简洁现代)
7+
BasedOnStyle: LLVM
8+
9+
# 缩进设置
10+
IndentWidth: 4
11+
UseTab: Never
12+
ColumnLimit: 100
13+
14+
# 大括号风格: 附加式 { 在语句末尾
15+
BreakBeforeBraces: Attach
16+
17+
# 指针/引用星号位置: 左侧 (int* a)
18+
PointerAlignment: Left
19+
DerivePointerAlignment: false
20+
21+
# 命名风格 (仅供参考,不影响已有代码)
22+
# 可以让 clangd 警告不符合命名规范的代码
23+
# 需要配合 clang-tidy 使用
24+
25+
# 函数声明: 返回类型和函数名在同一行
26+
AlwaysBreakAfterReturnType: None
27+
AlwaysBreakTemplateDeclarations: No
28+
29+
# 结构体初始化: 按位置赋值
30+
# C++11UnifiedBraceList: false 使用传统风格
31+
32+
# 预处理器缩进: 与代码对齐
33+
IndentPPDirectives: AfterHash
34+
35+
# 其他实用设置
36+
37+
# 在二元运算符后换行
38+
BreakBeforeBinaryOperators: None
39+
40+
# 在三元运算符后换行
41+
BreakBeforeTernaryOperators: true
42+
43+
# 连续赋值时的对齐
44+
AlignConsecutiveAssignments: false
45+
AlignConsecutiveDeclarations: false
46+
47+
# 转换类型周围的空格
48+
SpaceAfterCStyleCast: false
49+
50+
# 逻辑运算符周围的空格
51+
SpaceAfterLogicalNot: false
52+
53+
# 模板列表中的空格
54+
SpaceAfterTemplateKeyword: true
55+
56+
# 控制语句括号内的空格: if (x) 而非 if (x )
57+
SpaceBeforeParens: ControlStatements
58+
SpaceInEmptyParentheses: false
59+
60+
# 圆括号内的空格
61+
SpacesInParentheses: false
62+
SpacesInSquareBrackets: false
63+
64+
# 容器类型周围的空格
65+
SpacesInContainerLiterals: false
66+
67+
# lambda 相关
68+
SpaceBeforeAssignmentOperators: true
69+
SpaceBeforeCpp11BracedList: false
70+
71+
# 对齐
72+
AlignAfterOpenBracket: Align
73+
AlignEscapedNewlines: Left
74+
AlignOperands: true
75+
AlignTrailingComments: true
76+
77+
# 允许函数参数在同一行
78+
AllowAllArgumentsOnNextLine: true
79+
AllowAllConstructorInitializersOnNextLine: true
80+
AllowAllParametersOfDeclarationOnNextLine: true
81+
82+
# 允许短函数在一行
83+
AllowShortBlocksOnASingleLine: Never
84+
AllowShortCaseLabelsOnASingleLine: false
85+
AllowShortFunctionsOnASingleLine: Inline
86+
AllowShortIfStatementsOnASingleLine: Never
87+
AllowShortLoopsOnASingleLine: false
88+
89+
# 自动对齐注释
90+
ReflowComments: true
91+
92+
# 最大连续空行数
93+
MaxEmptyLinesToKeep: 1
94+
95+
# 命名空间缩进
96+
NamespaceIndentation: None
97+
98+
# 访问修饰符缩进
99+
IndentAccessModifiers: false
100+
IndentCaseLabels: true
101+
102+
# 换行符设置
103+
LineEnding: LF
104+
105+
# C/C++ 语言设置
106+
Language: Cpp
107+
Standard: Latest
108+
109+
# 包含块排序
110+
SortIncludes: true
111+
IncludeBlocks: Preserve

.clangd

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Diagnostics:
2+
Suppress:
3+
- unknown_argument
4+
5+
CompileFlags:
6+
CompilationDatabase: .
7+
Remove:
8+
- -fno-allow-store-data-races
9+
- -fzero-init-padding-bits=all
10+
- -fmin-function-alignment=4
11+
- -fconserve-stack
12+
- -femit-struct-debug-baseonly
13+
- -mno-fdpic
14+
- -fno-allow-store-data-races
15+
- -fconserve-stack
16+
- -mabi=*
17+
- -fno-ipa-sra
18+
- --param=*
19+
20+
InlayHints:
21+
Enabled: Yes
22+
ParameterNames: Yes
23+
DeducedTypes: Yes
24+
25+
Completion:
26+
AllScopes: Yes

.gitignore

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
# AI
2-
.claude
2+
.claude
3+
out/
4+
compile_commands.json
5+
.cache
6+
7+
# IDE
8+
.vscode/
9+
.idea/
10+
11+
# OS
12+
.DS_Store
13+
Thumbs.db

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
path = third_party/linux
33
url = https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
44
branch = linux-6.19.y
5+
[submodule "third_party/busybox"]
6+
path = third_party/busybox
7+
url = https://github.com/mirror/busybox.git

CONTRIBUTING.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 参与贡献
2+
3+
感谢你对 PenguinLab 的关注!欢迎提交 PR 共同完善这份学习资料。
4+
5+
## 贡献流程
6+
7+
1. Fork 本仓库
8+
2. 创建特性分支:`git checkout -b feature/your-topic`
9+
3. 提交更改
10+
4. 发起 Pull Request
11+
12+
## 文档规范
13+
14+
- 教程和文档使用**中文**编写
15+
- 代码注释可使用中文或英文
16+
- 新教程请遵循现有结构:`做什么``要了解什么``练习``延伸阅读`
17+
- 命令块中的命令必须可直接复制执行
18+
19+
## 代码规范
20+
21+
- C 代码遵循项目根目录的 `.clang-format` 配置
22+
- 内核模块代码遵循 [Linux 内核代码风格](https://www.kernel.org/doc/html/latest/process/coding-style.html)
23+
- Shell 脚本参考 `scripts/` 目录下的现有脚本
24+
25+
## 添加示例
26+
27+
每个示例目录必须包含:
28+
29+
- **源码**`.c` / `.h`
30+
- **Makefile**(使用 `KDIR ?=` 引用 `third_party/linux`
31+
- **README.md**(说明:构建方法、测试步骤、学习要点)
32+
33+
## 添加教程
34+
35+
- 放在 `tutorial/`(Week 1)或 `todo/`(Week 2–4)目录下
36+
- 包含可运行的代码示例
37+
- 在对应的 `example/` 目录提供配套练习代码
38+
- 在「延伸阅读」中引用 `document/booklist.md` 中的相关章节

README.md

Lines changed: 76 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,80 @@
1-
# 嵌入式 Linux 内核一个月学习计划
1+
# PenguinLab — 30 天嵌入式 Linux 内核学习计划
22

3-
## 你的背景画像
3+
面向有 C 语言和嵌入式基础(STM32 / FreeRTOS)的工程师,通过 QEMU + 真机(i.MX6ULL / 全志 H618)实践,掌握 Linux 内核驱动开发、内核移植定制和性能调优。
44

5-
| 维度 | 现状 |
6-
|------|------|
7-
| C 语言 | 高级(内存管理 / 多线程) |
8-
| Linux 使用 | 较为熟悉 |
9-
| 嵌入式经验 | STM32 裸机 + FreeRTOS + Yocto/Buildroot + DTS |
10-
| 目标硬件 | imx6ull + 全志 H618 |
11-
| 开发环境 | WSL2 |
12-
| 每日时间 | 1–2 小时 |
13-
| 核心目标 | 驱动开发 / 内核移植定制 / BSP / 性能调优 |
5+
## 快速开始
6+
7+
### 1. 克隆仓库
8+
9+
```bash
10+
git clone --recursive https://github.com/your-username/PenguinLab.git
11+
cd PenguinLab
12+
13+
# 如果已克隆但未初始化子模块
14+
git submodule update --init third_party/linux third_party/busybox
15+
```
16+
17+
### 2. 安装工具链
18+
19+
```bash
20+
# ARM32
21+
sudo apt install gcc-arm-linux-gnueabihf
22+
23+
# ARM64(可选)
24+
sudo apt install gcc-aarch64-linux-gnu
25+
26+
# QEMU
27+
sudo apt install qemu-system-arm
28+
29+
# CMake(用于用户态示例)
30+
sudo apt install cmake
31+
```
32+
33+
### 3. 构建内核 + 根文件系统
34+
35+
```bash
36+
# 构建 ARM64 内核
37+
./scripts/linux-action-scripts.sh config_and_build \
38+
ARCH=arm64 LINUX_DEFCONFIG=defconfig
39+
40+
# 构建最小 rootfs
41+
./scripts/rootfs-minimal-maker.sh --static all
42+
```
43+
44+
### 4. 启动 QEMU
45+
46+
```bash
47+
./scripts/qemu-run.sh run
48+
```
49+
50+
内核启动后在 QEMU shell 里操作。退出 QEMU:`Ctrl+A X`
1451

1552
## 目录结构
1653

1754
```
18-
linux-kernel-study/
19-
├── README.md ← 你在这里
20-
├── 书单_Booklist.md ← 理论 + 实战书单,含章节定位
21-
├── week1/ ← 内核解剖 & 构建体系
22-
│ ├── day01-02_环境搭建与源码导览.md
23-
│ ├── day03-04_Kconfig与Kbuild.md
24-
│ ├── day05-06_内核核心数据结构.md
25-
│ └── day07_QEMU跑起来.md
26-
├── week2/ ← 内核模块 & 字符驱动
27-
│ ├── day08-09_内核模块基础设施.md
28-
│ ├── day10-11_字符设备驱动.md
29-
│ ├── day12-13_Platform_Driver模型.md
30-
│ └── day14_sysfs与debugfs.md
31-
├── week3/ ← Device Tree 深度 & 中断子系统
32-
│ ├── day15-16_DTS深度与overlay.md
33-
│ ├── day17-18_中断子系统全链路.md
34-
│ ├── day19-20_Clock与Pinctrl框架.md
35-
│ └── day21_驱动上真机.md
36-
├── week4/ ← BSP 实战 & 性能调优
37-
│ ├── day22-23_H618内核定制.md
38-
│ ├── day24-25_ftrace与kprobe.md
39-
│ ├── day26-27_内存管理基础.md
40-
│ └── day28-30_综合项目_I2C驱动.md
41-
└── quick_ref/
42-
└── 常用命令速查.md
55+
PenguinLab/
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 配置(内核源码导航)
4375
```
4476

45-
## 每周目标一览
77+
## 学习路线
4678

4779
| 周次 | 主题 | 里程碑 |
4880
|------|------|--------|
@@ -53,7 +85,11 @@ linux-kernel-study/
5385

5486
## 使用建议
5587

56-
- 每天**先读对应 `.md` 的"要了解什么"部分**(10–15 分钟),再动手
57-
- 命令块 ` ``` ` 内的内容可以直接复制到终端执行
58-
- 每个文件末尾有**延伸阅读**,标注了书名 + 具体章节,遇到卡壳时查
88+
- 每天**先读对应教程的「要了解什么部分**(10–15 分钟),再动手
89+
- 命令块中的内容可以直接复制到终端执行
90+
- 每个文件末尾有**延伸阅读**,标注了书名 + 具体章节
5991
- 打 ✅ 标记完成的练习项,方便复盘进度
92+
93+
## 许可证
94+
95+
MIT License — 详见 [LICENSE](LICENSE)

0 commit comments

Comments
 (0)