mirror of
https://github.com/MintCN/linux-insides-zh.git
synced 2026-04-28 04:32:08 +08:00
格式校对完成
This commit is contained in:
@@ -7,7 +7,7 @@ Introduction
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
As you already may know, I've started a series of [blog posts](http://0xax.github.io/categories/assembly/) about assembler programming for `x86_64` architecture in the last year. I have never written a line of low-level code before this moment, except for a couple of toy `Hello World` examples in university. It was a long time ago and, as I already said, I didn't write low-level code at all. Some time ago I became interested in such things. I understood that I can write programs, but didn't actually understand how my program is arranged.
|
||||
如你所知,我从去年开始写了一系列关于 `x86_64` 架构汇编语言程序设计的博文。除了大学期间写过一些 `Hello World` 这样的玩具例程之外,我从来没写过哪怕一行的底层代码。那些例程也是很久以前的事情了,就像我刚才说的,我几乎完全没有写过底层代码。直到不久前,我才开始对这些事情感兴趣,因为我意识到我虽然可以写出程序,但是我却不知道我的程序是怎样被组织运行的。
|
||||
如你所知,我从去年开始写了一系列关于 `x86_64` 架构汇编语言程序设计的[博文](http://0xax.github.io/categories/assembly/)。除了大学期间写过一些 `Hello World` 这样的玩具例程之外,我从来没写过哪怕一行的底层代码。那些例程也是很久以前的事情了,就像我刚才说的,我几乎完全没有写过底层代码。直到不久前,我才开始对这些事情感兴趣,因为我意识到我虽然可以写出程序,但是我却不知道我的程序是怎样被组织运行的。
|
||||
|
||||
After writing some assembler code I began to understand how my program looks after compilation, **approximately**. But anyway, I didn't understand many other things. For example: what occurs when the `syscall` instruction is executed in my assembler, what occurs when the `printf` function starts to work or how can my program talk with other computers via network. [Assembler](https://en.wikipedia.org/wiki/Assembly_language#Assembler) programming language didn't give me answers to my questions and I decided to go deeper in my research. I started to learn from the source code of the Linux kernel and tried to understand the things that I'm interested in. The source code of the Linux kernel didn't give me the answers to **all** of my questions, but now my knowledge about the Linux kernel and the processes around it is much better.
|
||||
在写了一些汇编代码之后,我开始**大致**了解了程序在编译之后会变成什么样子。尽管如此,还是有很多其他的东西我不能够理解。例如:当 `syscall` 指令在我的汇编程序内执行时究竟发生了什么,当 `printf` 函数开始工作时又发生了什么,还有,我的程序是如何通过网络与其他计算机进行通信的。[汇编](https://en.wikipedia.org/wiki/Assembly_language#Assembler)语言并没有为这些问题带来答案,于是我决定做一番深入研究。我开始学习 Linux 内核的源代码,并且尝试着理解那些让我感兴趣的东西。然而 Linux 内核源代码也没有解答我**所有的**问题,不过我自身关于 Linux 内核及其外围流程的知识确实掌握的更好了。
|
||||
@@ -41,10 +41,10 @@ First of all, let's see how to get, build, and run the Linux kernel. You can run
|
||||
* 在真实的硬件上运行 Linux 内核。
|
||||
|
||||
I'll provide descriptions for both methods. Before we start doing anything with the Linux kernel, we need to get it. There are a couple of ways to do this depending on your purpose. If you just want to update the current version of the Linux kernel on your computer, you can use the instructions specific to your Linux [distro](https://en.wikipedia.org/wiki/Linux_distribution).
|
||||
我会对这两种方式都展开描述。在我们开始对 Linux 内核做些什么之前,我们首先需要先获取它。根据你目的的不同,有两种方式可以做到这一点。如果你只是想更新一下你电脑上的 Linux 内核版本,那么你可以使用特定于你 [Linux 发行版](https://en.wikipedia.org/wiki/Linux_distribution) 的命令。
|
||||
我会对这两种方式都展开描述。在我们开始对 Linux 内核做些什么之前,我们首先需要先获取它。根据你目的的不同,有两种方式可以做到这一点。如果你只是想更新一下你电脑上的 Linux 内核版本,那么你可以使用特定于你 [Linux 发行版](https://en.wikipedia.org/wiki/Linux_distribution)的命令。
|
||||
|
||||
In the first case you just need to download new version of the Linux kernel with the [package manager](https://en.wikipedia.org/wiki/Package_manager). For example, to upgrade the version of the Linux kernel to `4.1` for [Ubuntu (Vivid Vervet)](http://releases.ubuntu.com/15.04/), you will just need to execute the following commands:
|
||||
在这种情况下,你只需要使用 [软件包管理器](https://en.wikipedia.org/wiki/Package_manager) 下载新版本的 Linux 内核。例如,为了将 [Ubuntu (Vivid Vervet)](http://releases.ubuntu.com/15.04/) 系统的 Linux 内核更新至 `4.1`,你只需要执行以下命令:
|
||||
在这种情况下,你只需要使用[软件包管理器](https://en.wikipedia.org/wiki/Package_manager)下载新版本的 Linux 内核。例如,为了将 [Ubuntu (Vivid Vervet)](http://releases.ubuntu.com/15.04/) 系统的 Linux 内核更新至 `4.1`,你只需要执行以下命令:
|
||||
|
||||
```
|
||||
$ sudo add-apt-repository ppa:kernel-ppa/ppa
|
||||
@@ -69,14 +69,14 @@ and reboot your system. After the reboot you will see the new kernel in the [gru
|
||||
最后重启你的系统。重启完成后,你将在 [grub](https://en.wikipedia.org/wiki/GNU_GRUB) 菜单中看到新的内核。
|
||||
|
||||
In the other way if you are interested in the Linux kernel development, you will need to get the source code of the Linux kernel. You can find it on the [kernel.org](https://kernel.org/) website and download an archive with the Linux kernel source code. Actually the Linux kernel development process is fully built around `git` [version control system](https://en.wikipedia.org/wiki/Version_control). So you can get it with `git` from the `kernel.org`:
|
||||
另一方面,如果你对 Linux 内核开发感兴趣,那么你就需要获得 Linux 内核的源代码。你可以在 [kernel.org](https://kernel.org/) 网站上找到它并且下载一个包含了 Linux 内核源代码的归档文件。实际上,Linux 内核的开发流程完全建立在 `git` [版本控制系统](https://en.wikipedia.org/wiki/Version_control) 之上,所以你需要通过 `git` 来从 `kernel.org` 上获取内核源代码:
|
||||
另一方面,如果你对 Linux 内核开发感兴趣,那么你就需要获得 Linux 内核的源代码。你可以在 [kernel.org](https://kernel.org/) 网站上找到它并且下载一个包含了 Linux 内核源代码的归档文件。实际上,Linux 内核的开发流程完全建立在 `git` [版本控制系统](https://en.wikipedia.org/wiki/Version_control)之上,所以你需要通过 `git` 来从 `kernel.org` 上获取内核源代码:
|
||||
|
||||
```
|
||||
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
|
||||
```
|
||||
|
||||
I don't know how about you, but I prefer `github`. There is a [mirror](https://github.com/torvalds/linux) of the Linux kernel mainline repository, so you can clone it with:
|
||||
我不知道你怎么看,但是我本身是非常喜欢 `github` 的。它上面有一个 Linux 内核主线仓库的 [镜像](https://github.com/torvalds/linux),你可以通过以下命令克隆它:
|
||||
我不知道你怎么看,但是我本身是非常喜欢 `github` 的。它上面有一个 Linux 内核主线仓库的[镜像](https://github.com/torvalds/linux),你可以通过以下命令克隆它:
|
||||
|
||||
```
|
||||
$ git clone git@github.com:torvalds/linux.git
|
||||
@@ -186,7 +186,7 @@ If you want to build Linux kernel for an architecture that differs from your cur
|
||||
* `CROSS_COMPILER` command line argument and the cross-compiler tool prefix;
|
||||
|
||||
For example if we want to compile the Linux kernel for the [arm64](https://en.wikipedia.org/wiki/ARM_architecture#AArch64_features) with default kernel configuration file, we need to execute following command:
|
||||
例如,如果我们想使用默认内核配置文件为 [arm64 架构](https://en.wikipedia.org/wiki/ARM_architecture#AArch64_features) 编译 Linux 内核,我们需要执行以下命令:
|
||||
例如,如果我们想使用默认内核配置文件为 [arm64 架构](https://en.wikipedia.org/wiki/ARM_architecture#AArch64_features)编译 Linux 内核,我们需要执行以下命令:
|
||||
|
||||
```
|
||||
$ make -j4 ARCH=arm64 CROSS_COMPILER=aarch64-linux-gnu- defconfig
|
||||
@@ -346,7 +346,7 @@ $ git pull upstream master
|
||||
```
|
||||
|
||||
After this my local repository with the Linux kernel source code is synced with the [mainline](https://github.com/torvalds/linux) repository. Now we can make some changes in the source code. As I already wrote, I have no advice for you where you can start and what `TODO` in the Linux kernel. But the best place for newbies is `staging` tree. In other words the set of drivers from the [drivers/staging](https://github.com/torvalds/linux/tree/master/drivers/staging). The maintainer of the `staging` tree is [Greg Kroah-Hartman](https://en.wikipedia.org/wiki/Greg_Kroah-Hartman) and the `staging` tree is that place where your trivial patch can be accepted. Let's look on a simple example that describes how to generate patch, check it and send to the [Linux kernel mail listing](https://lkml.org/).
|
||||
在这之后,我的本地 Linux 内核源代码仓库已经和 [主线](https://github.com/torvalds/linux) 仓库同步了。现在我们可以在源代码上做些修改了。就像我之前写的,关于从哪开始修改或者可以做些什么,我并不能给你太多建议。不过,对于新手来说最好的地方就是 `staging` 源码树,也就是 [drivers/staging](https://github.com/torvalds/linux/tree/master/drivers/staging) 上的驱动集合。`staging` 源码树的主要维护者是 [Greg Kroah-Hartman](https://en.wikipedia.org/wiki/Greg_Kroah-Hartman),该源码树正是你的琐碎补丁可以被接受的地方。让我们看一个简单的例子,该例子描述了如何生成补丁、检查补丁以及如何将补丁发送到 [Linux 内核邮件列表](https://lkml.org/)。
|
||||
在这之后,我的本地 Linux 内核源代码仓库已经和[主线](https://github.com/torvalds/linux)仓库同步了。现在我们可以在源代码上做些修改了。就像我之前写的,关于从哪开始修改或者可以做些什么,我并不能给你太多建议。不过,对于新手来说最好的地方就是 `staging` 源码树,也就是 [drivers/staging](https://github.com/torvalds/linux/tree/master/drivers/staging) 上的驱动集合。`staging` 源码树的主要维护者是 [Greg Kroah-Hartman](https://en.wikipedia.org/wiki/Greg_Kroah-Hartman),该源码树正是你的琐碎补丁可以被接受的地方。让我们看一个简单的例子,该例子描述了如何生成补丁、检查补丁以及如何将补丁发送到 [Linux 内核邮件列表](https://lkml.org/)。
|
||||
|
||||
If we look in the driver for the [Digi International EPCA PCI](https://github.com/torvalds/linux/tree/master/drivers/staging/dgap) based devices, we will see the `dgap_sindex` function on line 295:
|
||||
如果我们查看一下为 [Digi International EPCA PCI](https://github.com/torvalds/linux/tree/master/drivers/staging/dgap) 基础设备所写的驱动程序,在295行我们将会看到 `dgap_sindex` 函数:
|
||||
@@ -503,6 +503,7 @@ Also you can see problematic places with the help of the `git diff`:
|
||||

|
||||
|
||||
* [Linus doesn't accept github pull requests](https://github.com/torvalds/linux/pull/17#issuecomment-5654674)
|
||||
* [Linus 不接受 github pull requests](https://github.com/torvalds/linux/pull/17#issuecomment-5654674)
|
||||
|
||||
* If your change consists from some different and unrelated changes, you need to split the changes via separate commits. The `git format-patch` command will generate patches for each commit and the subject of each patch will contain a `vN` prefix where the `N` is the number of the patch. If you are planning to send a series of patches it will be helpful to pass the `--cover-letter` option to the `git format-patch` command. This will generate an additional file that will contain the cover letter that you can use to describe what your patchset changes. It is also a good idea to use the `--in-reply-to` option in the `git send-email` command. This option allows you to send your patch series in reply to your cover message. The structure of the your patch will look like this for a maintainer:
|
||||
* 如果你的修改是由一些不同的且不相关的改动所组成的,你需要通过分离提交来切分修改。`git format-patch` 命令将会为每个提交生成一个补丁,每个补丁的标题会包含一个 `vN` 前缀,其中 `N` 是补丁的编号。如果你打算发送一系列补丁,也许给 `git format-patch` 命令传递 `--cover-letter` 选项会对此很有帮助。这会生成一个附加文件,该文件包括的附函可以用来描述你的补丁集所做的改动。在 `git send-email` 命令中使用 `--in-reply-to` 选项也是一个好主意,该选项允许你将补丁集作为对附函的回复发送出去。对于维护者来说,你补丁集的结构看起来就像下面这样:
|
||||
@@ -517,7 +518,7 @@ You need to pass `message-id` as an argument of the `--in-reply-to` option that
|
||||
你可以将 `message-id` 参数传递给 `--in-reply-to` 选项,该选项可以在 `git send-email` 命令的输出中找到。
|
||||
|
||||
It's important that your email be in the [plain text](https://en.wikipedia.org/wiki/Plain_text) format. Generally, `send-email` and `format-patch` are very useful during development, so look at the documentation for the commands and you'll find some useful options such as: [git send-email](http://git-scm.com/docs/git-send-email) and [git format-patch](http://git-scm.com/docs/git-format-patch).
|
||||
有一件非常重要的事,那就是你的邮件必须是 [纯文本](https://en.wikipedia.org/wiki/Plain_text) 格式。通常来说,`send-email` 和 `format-patch` 这两个命令在内核开发中都是非常有用的,所以请查阅这些命令的的相关文档,你会发现很多有用的选项,例如:[git send-email](http://git-scm.com/docs/git-send-email) 和 [git format-patch](http://git-scm.com/docs/git-format-patch)。
|
||||
有一件非常重要的事,那就是你的邮件必须是[纯文本](https://en.wikipedia.org/wiki/Plain_text)格式。通常来说,`send-email` 和 `format-patch` 这两个命令在内核开发中都是非常有用的,所以请查阅这些命令的的相关文档,你会发现很多有用的选项,例如:[git send-email](http://git-scm.com/docs/git-send-email) 和 [git format-patch](http://git-scm.com/docs/git-format-patch)。
|
||||
|
||||
* Do not be surprised if you do not get an immediate answer after you send your patch. Maintainers can be very busy.
|
||||
* 如果你发完补丁之后没有得到立即答复,请不要惊讶,因为维护者们都是很忙的。
|
||||
|
||||
Reference in New Issue
Block a user