参考资料:

  1. How to Participate in the Linux Community http://www.linuxfoundation.org/content/how-participate-linux-community

  2. Kernel Documents目录下的相关文档,例如:Changes, CodingStyle, development-process, HOWTO, SubmitChecklist, SubmittingDrivers, SubmittingPatches 等等

  3. HOWTO: Create and submit your first Linux kernel patch using GIT  http://linux.koolsolutions.com/2011/02/26/howto-create-and-submit-your-first-linux-kernel-patch/

  4. Hacking Linux Kernel

HOWTO: Create and submit your first Linux kernel patch using GIT

After working with Linux (mostly as an advanced user) for years, I decided to post my first Linux kernel patch (although trivial but hey you need to start somewhere!) and I was thrilled when it first got accepted by the Subsystem maintainer and then ultimately it trickled into mainline kernel.

What follows is a step-by-step guide on how to submit a Linux kernel patch and hope that it gets accepted into the mainline kernel. This HOW-TO is based on an actual patch that I wrote and submitted and which got accepted into mainline kernel yesterday. The guide mostly highlights the mechanics of sending patches and not necessarily technical design aspects of Linux kernel.

Step 1: Install Git Tools

The first thing we need to do is to make sure that we have necessary tools to create and submit our Linux kernel patch. I am using my Debian Lenny system for this HOW-TO.

# apt-get update
# apt-get install git git-email gitk

Additionally it is a good idea to configure some few parameters that Git will use when it generates your patch:

# git config --add user.name "Kushal Koolwal"
# git config --add user.email "kushalkoolwal@gmail.com"

Step 2: Clone Linus’ Git Tree

The next thing you may want to do is to clone Linus’s Git tree preferably on your Linux machine. Make sure you have enough space (at least 2GB) before you clone the tree. At the time of this writing the total size of the tree was around 950+ MB.

debian:~# cd /usr/src/
debian:/usr/src/# git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6 mylinux-2.6

Now wait for 30 minutes or so, depending on your Internet connection speed, before the entire tree gets downloaded into your directory mylinux-2.6 (directory will be created automatically since you have specified in the command). Any patchwork should always be done against this tree to make sure that your changes might not conflict with changes made by other developers.

debian:/usr/src/# cd mylinux-2.6
debian:/usr/src/mylinux-2.6# ls
arch COPYING  crypto drivers fs init  Kbuild   kernel  MAINTAINERS  mm   README samples  security  tools  virt block  CREDITS  Documentation  firmware  include  ipc   Kconfig  lib  Makefile net  REPORTING-BUGS  scripts  sound     usr
debian:/usr/src/mylinux-2.6#

From here onwards all the work will be done in /usr/src/mylinux-2.6 directory.

Step 3: Now create a local branch to make your changes

By default when you clone the Git tree you are in the master branch.

# git branch
* master
#

The * above indicates your current branch.

Let’s create a new branch my MenlowRebootFix in which we will do our code changes:

# git branch MenlowRebootFix

Then you need to checkout the above newly created branch:

# git checkout MenlowRebootFix

Confirm that you are in the above branch:

# git branch
*MenlowRebootFix
master
#

Step 4: Make your changes

Now I am going to make changes to the arch/x86/kernel/reboot.c file. After you made your changes to the file and saved it give the following command:

# git commit -a

The above command will open a text editor in the same window on your terminal screen (my default text editor is nano) like this:

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch Test1
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   arch/x86/kernel/reboot.c
#

Now we will enter our commit log message. Be very careful what you type in the log message because these messages will become part of Linux Git tree commit log and people will be searching your commit based on these messages. Here is what I typed in and here is what my final editor window looked it:

x86: Fix reboot problem on VersaLogic Menlow boards

VersaLogic Menlow based boards hang on reboot unless reboot=bios is used. Add quirk to reboot through the BIOS.

Tested on at least four boards.
# Please enter the commit message for your changes. Lines starting
# with ‘#’ will be ignored, and an empty message aborts the commit.
# On branch Test1
# Changes to be committed:
#   (use “git reset HEAD <file>…” to unstage)
#
#       modified:   arch/x86/kernel/reboot.c
#

Now the text in blue color will become your main subject line of the patch that you will email and will also become the identifier in the Git commit log.

Note:It is very important that you first type the name of the subsystem to which your patch belongs to. In my case since I am modifying the reboot.c file in the x86 architecture directory, I begin by subject line with x86:.

After that you need to leave one empty line. and then type a brief description about your change (in maroon color) which will become the changelog of the Git commit log.

Do not worry about the text in orange color that begins with #. Those will be ignored by Git commit.

Note:If you don’t leave one empty line between your subject and description , your description will become part of the subject line and it will be all mess.

Step 5: Generate your patch

So now you have commit your patch in your local Git repository, it is time to generate the patch that we will email to the respective maintainers and mailing lists. To generate patch simply give the following command:

# git format-patch -s -n master..MenlowRebootFix

This should create a file 0001-x86-Fix-reboot-problem-on-VersaLogic-Menlow-boards.patch in your current directory whose content will be:

From 04056e508c996b023857f8076da7fb54096d10e9 Mon Sep 17 00:00:00 2001
From: Kushal Koolwal <kushalkoolwal@gmail.com>
Date: Sat, 19 Feb 2011 13:14:03 -0800
Subject: [PATCH 1/1] x86: Fix reboot problem on VersaLogic Menlow boards.
VersaLogic Menlow based boards hang on reboot unless reboot=bios is used.

Add quirk to reboot through the BIOS.
Tested on at least four boards.

Signed-off-by: Kushal Koolwal <kushalkoolwal@gmail.com>

arch/x86/kernel/reboot.c |    8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff –git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
index fc7aae1..715037c 100644
— a/arch/x86/kernel/reboot.c
+++ b/arch/x86/kernel/reboot.c
@@ -285,6 +285,14 @@ static struct dmi_system_id __initdata reboot_dmi_table[] = {
DMI_MATCH(DMI_BOARD_NAME, “P4S800″),
},
},
+       {       /* Handle problems with rebooting on VersaLogic Menlow boards */
+               .callback = set_bios_reboot,
+               .ident = “VersaLogic Menlow based board”,
+               .matches = {
+                       DMI_MATCH(DMI_BOARD_VENDOR, “VersaLogic Corporation”),
+                       DMI_MATCH(DMI_BOARD_NAME, “VersaLogic Menlow board”),
+               },
+       },
{ }
};

1.7.2.3

Note how the name of the file was picked from your first line of the Git commit log. Also the option -n adds the patch number [PATCH 1/1] to your subject and the -s option adds the Signed-off-by: line. The email that is picked in the signed off line is picked from your Git’s configuration that you set in Step 1.

Step 6: Check your patch for errors

Next we need to make sure that the patch we are trying to submit does not contain any obvious errors like white spaces, exceeding 80 column limit, etc. There is a perl script called checkpath.pl that is provided with the kernel sources for this purpose:

# scripts/checkpatch.pl 0001-x86-Fix-reboot-problem-on-VersaLogic-Menlow-boards.patch

and you should see something like this:

Output:

total: 0 errors, 0 warnings, 14 lines checked
0001-x86-Fix-reboot-problem-on-VersaLogic-Menlow-boards.patch has no obvious style problems and is ready for submission.

There are other scripts also provided inside the kernel source to fix/clean your patch like:

scripts/cleanfile
scripts/cleanpatch

Step 7: Test your patch

Again it is very important that you apply your patch to the Linus’ Git tree, compile it and test it before sending your patch upstream.

# git checkout master
# patch -p1 < 0001-x86-Fix-reboot-problem-on-VersaLogic-Menlow-boards.patch
# make-kpkg --append-to-version=test-patch kernel_p_w_picpath kernel_headers

Step 8: Get the list of people to submit patch to

Assuming your patch compiled, worked the way you want it to and your test emails looked good the next step is to get the list of concern people to whom you should email your patch. There are two methods to do that:

Method 1: Use the script provided in the kernel source

# scripts/get_maintainer.pl 0001-x86-Fix-reboot-problem-on-VersaLogic-Menlow-boards.patch

Output:

Thomas Gleixner <tglx@linutronix.de> (maintainer:X86 ARCHITECTURE...)
Ingo Molnar <mingo@redhat.com> (maintainer:X86 ARCHITECTURE...,commit_signer:5/8=62%)
"H. Peter Anvin" <hpa@zytor.com> (maintainer:X86 ARCHITECTURE...,commit_signer:3/8=38%)
x86@kernel.org (maintainer:X86 ARCHITECTURE...)
Don Zickus <dzickus@redhat.com> (commit_signer:2/8=25%)
Peter Zijlstra <a.p.zijlstra@chello.nl> (commit_signer:2/8=25%)
Borislav Petkov <bp@alien8.de> (commit_signer:1/8=12%)
linux-kernel@vger.kernel.org (open list)
#

Method 2: Refer to the MAINTAINERS file

The other method is to refer to the MAINTAINERS file that is provide inside the kernel source tree. You need to at least email your patch to all of the people who have “M” before their name.

Note:Also you need to email your patch to at least one mailing list. If you are not able find any mailing list, based on the above two methods, that is concerned with the subsystem against which you are trying to submit your patch, then you should at least email to Linux Kernel Mailing List (linux-kernel@vger.kernel.org).

Step 9: Test Email your patch

Although you could use any email client and SMTP host that you want and have access to, I found that using Gmail was the best since a lot of kernel developers use that. Now it is very important that you first test your patch by sending it your own email addresses (possible different email account with different mail providers). I use the following:

git send-email --smtp-encryption=tls --smtp-server=smtp.gmail.com --smtp-user=kushalkoolwal@gmail.com --smtp-server-port=587 --to "KKoolwal <myname@koolsolutions.com>" --to "Kushal Koolwal <myname@yahoo.com>" --cc "KK <myname@hotmail.com>" 0001-x86-Fix-reboot-problem-on-VersaLogic-Menlow-boards.patch

After you hit enter, it will ask for your Gmail account password which you need to enter in order to actually send the email.

Now check email accounts listed above to verify if you got the email and everything looks good for submission.

Step 10: Finally Email your patch

If everything looks right then you finally email your patch based on the list of people you found in Step 8. This is what I actually ended up using:

# git send-email --smtp-encryption=tls --smtp-server=smtp.gmail.com --smtp-user=kushalkoolwal@gmail.com --smtp-server-port=587 --from "Kushal Koolwal <kushalkoolwal@gmail.com>" --to "Thomas Gleixner <tglx@linutronix.de>" --to "Ingo Molnar <mingo@redhat.com>" --to "H. Peter Anvin <hpa@zytor.com>" --to "x86@kernel.org" --cc "linux-kernel@vger.kernel.org" 0001-x86-Fix-reboot-problem-on-VersaLogic-Menlow-boards.patch

Here is that commit log of the acceptance of my patch by Ingo Molnar which then trickled from Ingo Molnar’s tree to Stephen Rothwell’s  linux-next tree and finally into Linus Torvald’s mainline Linux kernel tree.

That’s it! Good luck with your first patch!

转载于:https://blog.51cto.com/linuxkernel/1258371

Create and submit your first Linux kernel patch using GIT相关推荐

  1. HOWTO: Create and submit your first Linux kernel patch using GIT

    这个文章用自己第一次提交patch的经历详细介绍了用git提交patch的步骤,值得学习. From : http://linux.koolsolutions.com/2011/02/26/howto ...

  2. linux kernel patch 使用说明

    内核补丁不是一定需要的,这要看你选择的是怎样的Linux内核,比如下载下来标准的Linux内核,想要编译linux系统在x86的PC机上运行,就根本不用什么板间支持的补丁了,因为标准Linux内核本身 ...

  3. Linux查看历史信息代码,使用 GIT 获得Linux Kernel的代码并查看,追踪历史记录

    Linux kernel  的官方 GIT地址是: 可以从这个地址拿到 kernel 的 代码仓库. 1. 拿代码仓库 git clone git://git.kernel.org/pub/scm/l ...

  4. 如何向 Linux Kernel 提交 Patch

    昨晚终于向内核上游提交了人生中第一个 Patch,今天早上起床迫不及待的看手机,发现维护者 Andrew Morton 在6点31分回复我了:The patch has been added to t ...

  5. linux内核 patch 功能,如何向 Linux Kernel 提交 Patch

    昨晚终于向内核上游提交了人生中第一个 Patch,今天早上起床迫不及待的看手机,发现维护者 Andrew Morton 在6点31分回复我了:The patch has been added to t ...

  6. linux rt patch 强实时,Linux RT(2)-硬实时Linux(RT-Preempt Patch)的中断线程化

    特别声明:本系列文章LiAnLab.org著作权所有,转载请注明出处.by  @宋宝华Barry 底半部:线程化IRQ 线程化中断的支持在2009年已经进入Linux官方内核,详见Thomas Gle ...

  7. The Linux Kernel Module Programming Guide 2.4 中文版

    The Linux Kernel Module Programming Guide 2.4 中文版 分类: Linux/os 2007-09-29 11:14 820人阅读 评论(0) 收藏 举报 T ...

  8. 如何为linux kernel贡献代码

    和一般github项目可以直接提交pr不同,linux kernel项目庞大,管理繁琐,如果我们想要对linux kernel提出改进,并希望最终改进能进入主分支,则需要严格按照提交patch的流程 ...

  9. 1. Linux kernel release 3.x

    Linux kernel release 3.x <http://kernel.org/> 它的内容包括以下几部分:什么是Linux.运行的硬件环境.怎样安装和升级Linux内核源码.编译 ...

最新文章

  1. 使用NLog实现一个简单的日志记录(包含源代码)
  2. 科大星云诗社动态20210524
  3. web前端培训分享:使用Dplayer实现Vue3中的视频及弹幕播放
  4. 31岁负债59万(房贷27万,私人借款32万),该怎么办?
  5. sql server 数据库忘记sa账户密码/ 无管理员账户解决办法
  6. html加了文档声明之后页面错乱,为登陆页面扩展和配置设计导入程序
  7. LINUX环境并发服务器的三种实现模型
  8. 理光Ricoh Aficio MP 6002 一体机驱动
  9. 物联网服务器 网页服务器,如何选择合适的物联网平台服务器?
  10. ipa在线安装搭建_在线安装IPA 文件和视频下载
  11. cnode社区vue和react渲染
  12. UEBA架构设计之路3:复杂事件处理引擎
  13. 常见目标跟踪数据集下载链接整理(更新中)
  14. 一张图片测试你的好色程度
  15. (转载)80后一代的尴尬
  16. VSCode 安装Flutter 教程
  17. 半路出家,开始学习java
  18. 京冀协同,数聚张北——产业互联网之IDC新业态高峰论坛即将拉开帷幕
  19. 九月十月百度人搜,阿里巴巴,腾讯华为笔试面试八十题(第331-410题) C++版
  20. 医院信息化升级,一步到位?教你一招

热门文章

  1. mysql查询最低工资的经历_查看员工信息每个部门的最低工资
  2. 【收藏】万字解析Scipy的使用技巧!
  3. SpringBoot2.x 集成 Thymeleaf
  4. RFC3261 中文
  5. [模式识别].(希腊)西奥多里蒂斯lt;第四版gt;笔记5之__特征选取
  6. linux桌面发展方向,不知道就OUT了!Linux桌面领域7大趋势
  7. Determining IP information for eth0... failed; no link present. Check cable?
  8. 2019年全国职业技能大赛-软件测试赛项国赛总结-西安航空职业技术学院
  9. ClickHouse 在网易的实践
  10. C++入门——Day1_Start with C++