\subchapter{Kernel source code}{Objective: Get familiar with the
  kernel source code}

After this lab, you will be able to:

\begin{itemize}

\item Explore the sources in search for files, function headers or
  other kinds of information...

\item Browse the kernel sources with tools like cscope and LXR.

\end{itemize}

\section{Setup}

Go to the \code{/home/<user>/felabs/linux/modules} directory.

Download and extract the Linux 3.0 kernel sources
from \url{http://kernel.org}.

\section{Apply patches}

Install the \code{patch} command, either through the graphical package
manager, or using the following command line:

\begin{verbatim}
sudo apt-get install patch
\end{verbatim}

Now, download the two Linux patches corresponding to versions 3.1 and 3.1.x.

Apply these patches, check the \code{Makefile} file to double check
that you have the right version, and rename the source directory to
reflect the version change.

\section{Get familiar with the sources}

As a Linux kernel user, you will very often need to find which file
implements a given function. So, it is useful to be familiar with
exploring the kernel sources.

\begin{enumerate}
\item Find the Linux logo image in the sources
\item Find who the maintainer of the 3C505 network driver is.
\item Find the declaration of the \code{platform_device_register()} function.
\end{enumerate}

\section{Use a kernel source indexing tool}

Now that you know how to do things in a manual way, let's use more
automated tools.

Try LXR (Linux Cross Reference) at \url{http://lxr.free-electrons.com}
and choose the Linux version closest to yours.

If you don't have Internet access, you can use {\em cscope} instead.

As in the previous section, use this tool to find where
the \code{platform_device_register()} is declared, implemented and
even used.

\section{Accessing kernel sources with git}

Later this week, we will also see another way of accessing kernel
sources, with the {\em git} source control management tool used by kernel
developers.

To save time with the git lab on the last day, let's advance us by
cloning the Linus Torvalds' git tree.

First, install required software packages:

\begin{verbatim}
sudo apt-get install git gitk git-email
\end{verbatim}

Then, go to the \code{/home/<user>/felabs/linux/git directory}, and run
the below command:

\small
\begin{verbatim}
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
\end{verbatim}
\normalsize

Now, just let this command run, from 30 minutes to several hours
according to your workstation and network speed.

