Retrieving, building, updating, and maintaining a Linux kernel
source tree involves a lot of different steps, as this book has shown.
Developers being naturally lazy creatures, they have created some programs
to help with the various routine tasks. Here we describe a few of these
useful tools and the basics on how to use them.
Linux kernel development differs in many ways from traditional software
development. Some of the special demands on kernel programmers include:
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 4,
Retrieving the kernel source
:
$
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 e-mail.
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:
-
Generate your original patch, as in the previous example.
-
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
-
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
-
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,
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
https://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.