Section A.1. patch and diff


A.1. patch and diff

This section is based on an article originally published in Linux Journal.

One of the most common methods of doing kernel work is to use the patch and diff programs. To use these tools, two different directory trees: a "clean" one and a "working" one must be used. The clean tree is a released kernel version, while the working one is based on the same version but contains your modifications. Then you can use patch and diff to extract your changes and port them forward to a new kernel release.

For an example, create two directories containing the latest kernel version as described in Chapter 3:

 $ tar -zxf linux-2.6.19.tar.gz $ mv linux-2.6.19 linux-2.6.19-dirty $ tar -zxf linux-2.6.19.tar.gz $ ls linux-2.6.19/ linux-2.6.19-dirty/ 

Now make all of the different changes you wish to do in the -dirty directory and leave the clean, original kernel directory alone. After finishing making changes, you should create a patch to send it to other people:

 $ diff -Naur -X linux-2.6.19/Documentation/dontdiff linux-2.6.19/ \ linux-2.6.19-dirty/ > my_patch 

This will create a file called my_patch that contains the difference between your work and a clean 2.6.19 kernel tree. This patch then can be sent to other people via email.

A.1.1. New Kernel Versions

If a new kernel version is released, and you wish to port your changes to the new version, you need to try to apply your generated patch onto a clean kernel version. This can be done in the following steps:

  1. Generate your original patch, as in the previous example.

  2. Using the official patch from kernel.org, move the old kernel version forward one release:

     $ cd linux-2.6.19 $ patch -p1 < ../patch-2.6.20 $ cd .. $ mv linux-2.6.19 linux-2.6.20 

  3. Move your working directory forward one release by removing your patch, then apply the new update:

     $ cd linux-2.6.19-dirty $ patch -p1 -R < ../my_patch $ patch -p1 < ../patch-2.6.20 $ cd .. $ mv linux-2.4.19-dirty linux-2.6.20-dirty 

  4. Try to apply your patch on top of the new update:

     $ cd linux-2.6.20-dirty $ patch -p1 < ../my_patch 

    If your patch does not apply cleanly, resolve all of the conflicts that are created (the patch command will tell you about these conflicts, leaving behind .rej and .orig files for you to compare and fix up manually using your favorite editor). This merge process can be the most difficult part if you have made changes to portions of the source tree that have been changed by other people.

If you use this development process, I highly recommend getting the excellent patchutils set of programs (found at http://cyberelk.net/tim/patchutils). These programs enable you to manipulate text patches easily in all sorts of useful ways, and have saved kernel developers many hours of tedious work.



Linux Kernel in a Nutshell
Linux Kernel in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596100795
EAN: 2147483647
Year: 2004
Pages: 113

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net