🧩 u-boot 提交 Patch 标准流程(总结)
U-Boot 社区采用 Mailing List 驱动开发流程 (类似 Linux Kernel),提交 Patch 需要遵循特定规范。本文基于实战经验,整理了一套从克隆仓库 到发送邮件的完整流程,适合第一次向 U-Boot Upstream 贡献代码的开发者。
📌 一、整体流程图
👉 标准流程如下:
克隆源码 + 配置 Git
↓
官网订阅 mailing list (https://lists.denx.de/listinfo/u-boot)
↓
创建分支 + 准备代码(commit)
↓
本地编译 + checkpatch 自检
↓
生成 patch(format-patch)
↓
获取 maintainer(get_maintainer.pl)
↓
配置 SMTP + git send-email 发送
↓
参与 review → 修订 v2/v3
↓
maintainer 合入
Step 0:订阅 Mailing List(必须)
在发送 patch 之前,必须先订阅:
👉 https://lists.denx.de/listinfo/u-boot
为什么必须订阅?
- Mailing list 对非成员有限制
- 不订阅可能出现:
- ❌
Post by non-member to a members-only list - ❌ 邮件被丢弃或延迟审核
- ❌
强烈建议:
- 邮箱必须与你的
git config user.email一致
Step 1:准备 patch
-
克隆 U-Boot 源码
首先,你需要获取 U-Boot 的源代码。推荐使用官方 Git 仓库:
shellgit clone https://source.denx.de/u-boot/u-boot.git cd u-boot -
配置 Git
shellgit config --global user.name "你的名字" git config --global user.email "你的邮箱" -
编写代码并提交(commit)
shell# 切记:不要直接在 master 分支修改! 保持主分支干净,方便后续同步上游代码。 git checkout -b fix-xxx-error # 创建并切换到新分支 git add xxx git commit -s # -s会自动添加Signed-off-by,这是 DCO(开发者证书)的要求。Commit message 规范,请务必遵循以下格式,否则 Maintainer 可能会直接拒绝。
txtsubsystem: short summary (one line) Long description explaining why and what. - Explain the problem you are solving. - Explain the solution you implemented. Signed-off-by: Your Name <your.email@domain.com>要求:
项目 要求 标题 <subsystem>: 描述行宽 ≤ 72 字符 内容 清楚说明 why + what 必须 Signed-off-by 示例:
net: fix phy reset timing issue The PHY reset timing is too short on some platforms, causing link initialization failure. Increase delay to 10ms to fix. Signed-off-by: Andy <Andy.li@baidu.com>
Step 2:自检(强烈建议)
-
确保你的代码不会导致编译失败(至少要过 Sandbox):
shellmake sandbox_defconfig make -
代码风格检查
shell./scripts/checkpatch.pl 0001-your-patch.patch 这个过程会疯掉!!!需要经常使用 git commit --amend --author="your_name <your_email>"
目标:
- ✅ 0 ERROR
- ✅ 尽量减少 WARNING
Step 3:生成 Patch
shell
# 生成最近 1 个 Commit 的 Patch
git format-patch -1
# 如果是多个 Commit (例如前 3 个 Commit)
git format-patch -3
生成一个patch.
Step 4:获取 Maintainer(关键)
shell
./scripts/get_maintainer.pl 0001-xxx.patch
输出内容:
- 通常会包含
u-boot@lists.denx.de(主列表) - 可能包含具体的维护者邮箱 (Maintainer)
- 可能包含特定的子系统列表
Step 5:发送 Patch
git send-email 需要配置 SMTP 服务。如果你使用的是 Gmail、QQ 或 Outlook,请参考以下常见配置。
-
Outlook 配置 Git SMTP
根据微软官方文档,Outlook 的 SMTP 必须使用 OAuth2.0 身份验证(机制为
XOAUTH2),且服务器地址是固定的。你可以直接在终端执行以下命令进行全局配置:shell# 1. 设置 SMTP 服务器地址(微软固定地址) git config --global sendemail.smtpserver smtp.office365.com # 2. 设置端口(官方推荐使用 587) git config --global sendemail.smtpserverport 587 # 3. 设置加密方式(587端口对应 STARTTLS) git config --global sendemail.smtpencryption tls # 4. 设置你的完整公司邮箱地址 git config --global sendemail.smtpuser yourname@company.com # 5. 设置身份验证机制(Outlook 必须使用 XOAUTH2) git config --global sendemail.smtpAuth XOAUTH2⚠️ 核心注意事项:
- 密码/令牌: 由于配置了
XOAUTH2,git send-email在运行时不会让你输入普通的邮箱登录密码,而是会引导你通过浏览器进行 OAuth2.0 登录授权,或者需要你提前配置好支持 OAuth 的 Git 凭据助手(如git-credential-outlook)。 - 服务器权限: 部分公司的 IT 部门可能会默认关闭员工邮箱的"经过身份验证的 SMTP (Authenticated SMTP)"权限。如果配置无误但一直提示认证失败,需要联系公司 IT 管理员在 Exchange 管理中心为你开启该权限。
验证配置是否成功
你可以通过给自己(或同事)的邮箱发送一个测试 Patch 来验证配置。
bash# 将 0001-xxxx.patch 替换为你实际生成的文件名 # 将 yourname@company.com 替换为你自己的邮箱 sudo apt install git-email # 大概率没装这个工具 git send-email 0001-xxxx.patch --to yourname@company.com如果终端显示发送成功,且你收到了包含 Patch 内容的邮件,说明 SMTP 配置完全成功。(这一步难倒英雄汉啊,太难了)
- 密码/令牌: 由于配置了
-
发送 Patch
shellgit send-email 0001-xxx.patch \ --to u-boot@lists.denx.de \ --cc-cmd="./scripts/get_maintainer.pl"该命令将指定的补丁文件(0001-xxx.patch)通过电子邮件发送给 U-Boot 项目的邮件列表,并自动提取并抄送给该补丁涉及到的相关代码维护者(Maintainers)
-
--to u-boot@lists.denx.de:指定邮件的主收件人 。这里
u-boot@lists.denx.de是 U-Boot 开源项目的官方邮件列表地址。把补丁发到这个列表,意味着提交给整个社区进行评审。 -
--cc-cmd="./scripts/get_maintainer.pl":这是命令中最智能的部分。
--cc-cmd允许指定一个外部命令来自动生成抄送(Cc)名单。-
./scripts/get_maintainer.pl是 Linux 内核及 U-Boot 等项目中常用的一个脚本。它会自动分析0001-xxx.patch中修改了哪些代码文件,并根据项目中的MAINTAINERS文件,找出负责这些文件的维护者和相关的邮件列表。 -
执行后,这些相关人员的邮箱地址会被自动添加到邮件的 抄送(Cc) 栏中,确保补丁能精准地送达给真正负责审核这部分代码的人。
-
-
Step 6:Review & 迭代
提交后流程:
- reviewer 邮件回复
- 提修改建议
- 你修改并重新发送
生成新版本 Patch
shell
git commit --amend # 修改代码
git format-patch -1 -v2 #使用 -v2 或 -v3 参数来标记版本号。
在发送 v2/v3 时,邮件正文必须包含变更日志(Changelog),说明你改了什么:
git send-email 0001-*.patch \
--to u-boot@lists.denx.de \
--cc-cmd="./scripts/get_maintainer.pl" \
--annotate
加上 --annotate 后,Git 会在发送邮件前自动打开你的默认文本编辑器 ,展示即将发送的邮件内容。此时,你可以在邮件头部(--- 分隔符的上方,或者专门的正文区域)手动输入你的变更日志:
Subject: [PATCH v2] net: fix phy reset timing issue
The PHY reset timing is too short on some platforms, causing
link initialization failure. Increase delay to 10ms to fix.
Signed-off-by: Andy <Andy.li@baidu.com>
---
Changes in v2:
- Fixed typo in commit message
- Increased delay to 10ms as suggested by Tom
net/phy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Step 7:合入
当 maintainer 认可后:
你会看到类似回复, 表示 patch 已被接收:
Applied to u-boot/master, thanks!
恭喜你,你的代码已经成为 U-Boot 的一部分!🎉