\subsection{Linux kernel sources}

\begin{frame}
  \frametitle{Location of kernel sources}
  \begin{itemize}
  \item The official version of the Linux kernel, as released by Linus
    Torvalds is available at \url{http://www.kernel.org}
    \begin{itemize}
    \item This version follows the well-defined development model of
      the kernel
    \item However, it may not contain the latest development from a
      specific area, due to the organization of the development model
      and because features in development might not be ready for
      mainline inclusion
    \end{itemize}
  \item Many kernel sub-communities maintain their own kernel, with
    usually newer but less stable features
    \begin{itemize}
    \item Architecture communities (ARM, MIPS, PowerPC, etc.), device
      drivers communities (I2C, SPI, USB, PCI, network, etc.), other
      communities (real-time, etc.)
    \item They generally don't release official versions, only
      development trees are available
    \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Linux kernel size (1)}
  \begin{itemize}
  \item Linux 3.1 sources:\\
    Raw size: 434 MB (39,400 files, approx 14,800,000 lines)\\
    \code{gzip} compressed tar archive: 93 MB\\
    \code{bzip2} compressed tar archive: 74 MB (better)\\
    \code{xz} compressed tar archive: 62 MB (best)
  \item Minimum Linux 2.6.29 compiled kernel size with
    \code{CONFIG_EMBEDDED}, for a kernel that boots a QEMU PC (IDE
    hard drive, ext2 filesystem, ELF executable support):\\
    532 KB (compressed), 1325 KB (raw)
  \item Why are these sources so big?\\
    Because they include thousands of device drivers, many network
    protocols, support many architectures and filesystems...
  \item The Linux core (scheduler, memory management...) is pretty
    small!
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Linux kernel size (2)}
  As of kernel version 3.2.
  \begin{columns}
    \column{0.5\textwidth}
    \begin{itemize}
    \item \code{drivers/}: 53.65\%
    \item \code{arch/}: 20.78\%
    \item \code{fs/}: 6.88\%
    \item \code{sound/}: 5.04\%
    \item \code{net/}: 4.33\%
    \item \code{include/}: 3.80\%
    \item \code{firmware/}: 1.46\%
    \item \code{kernel/}: 1.10\%
    \item \code{tools/}: 0.56\%
    \item \code{mm/}: 0.53\%
    \end{itemize}
    \column{0.5\textwidth}
    \begin{itemize}
    \item \code{scripts/}: 0.44\%
    \item \code{security/}: 0.40\%
    \item \code{crypto/}: 0.38\%
    \item \code{lib/}: 0.30\%
    \item \code{block/}: 0.13\%
    \item \code{ipc/}: 0.04\%
    \item \code{virt/}: 0.03\%
    \item \code{init/}: 0.03\%
    \item \code{samples/}: 0.02\%
    \item \code{usr/}: 0\%
    \end{itemize}
  \end{columns}
\end{frame}

\begin{frame}
  \frametitle{Getting Linux sources}
  \begin{itemize}
  \item {\bf Full tarballs}
    \begin{itemize}
    \item Contain the complete kernel sources: long to download and
      uncompress, but must be done at least once
    \item Example:\\
      \footnotesize
      \url{http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.1.3.tar.xz}
      \normalsize
    \item Extract command:\\
      \footnotesize
      \code{tar Jxf linux-3.1.3.tar.xz}
      \normalsize
    \end{itemize}
  \item {\bf Incremental patches between versions}
    \begin{itemize}
    \item It assumes you already have a base version and you apply the
      correct patches in the right order. Quick to download and apply
    \item Examples:\\
      \scriptsize
      \url{http://www.kernel.org/pub/linux/kernel/v3.0/patch-3.1.xz}\\(3.0 to 3.1)\\
      \url{http://www.kernel.org/pub/linux/kernel/v3.0/patch-3.1.3.xz}\\(3.1 to 3.1.3)
    \end{itemize}
  \item All previous kernel versions are available in
    \url{http://kernel.org/pub/linux/kernel/}
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Patch}
  \begin{itemize}
  \item A patch is the difference between two source trees
    \begin{itemize}
    \item Computed with the \code{diff} tool, or with more elaborate
      version control systems
    \end{itemize}
  \item They are very common in the open-source community
  \item Excerpt from a patch:
  \end{itemize}
\footnotesize
\begin{verbatim}
diff -Nru a/Makefile b/Makefile
--- a/Makefile 2005-03-04 09:27:15 -08:00
+++ b/Makefile 2005-03-04 09:27:15 -08:00
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 6
 SUBLEVEL = 11
-EXTRAVERSION =
+EXTRAVERSION = .1
 NAME=Woozy Numbat

 # *DOCUMENTATION*
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Contents of a patch}
  \begin{itemize}
  \item One section per modified file, starting with a header
\scriptsize
\begin{verbatim}
diff -Nru a/Makefile b/Makefile
--- a/Makefile 2005-03-04 09:27:15 -08:00
+++ b/Makefile 2005-03-04 09:27:15 -08:00
\end{verbatim}
\normalsize
  \item One sub-section per modified part of the file, starting with
    header with the affected line numbers
\scriptsize
\begin{verbatim}
@@ -1,7 +1,7 @@
\end{verbatim}
\normalsize
  \item Three lines of context before the change
\scriptsize
\begin{verbatim}
 VERSION = 2
 PATCHLEVEL = 6
 SUBLEVEL = 11
\end{verbatim}
\normalsize
  \item The change itself
\scriptsize
\begin{verbatim}
-EXTRAVERSION =
+EXTRAVERSION = .1
\end{verbatim}
\normalsize
    \item Three lines of context after the change
\scriptsize
\begin{verbatim}
 NAME=Woozy Numbat

 # *DOCUMENTATION*
\end{verbatim}
\normalsize
    \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Using the patch command}
  The \code{patch} command:
  \begin{itemize}
  \item Takes the patch contents on its standard input
  \item Applies the modifications described by the patch into the
    current directory
  \end{itemize}
  \code{patch} usage examples:
  \begin{itemize}
  \item \code{patch -p <n>   < diff_file}
  \item \code{cat diff_file | patch -p <n>}
  \item \code{xzcat diff_file.xz | patch -p <n>}
  \item \code{bzcat diff_file.bz2 | patch -p <n>}
  \item \code{zcat diff_file.gz | patch -p <n>}
  \item Notes:
    \begin{itemize}
    \item \code{n}: number of directory levels to skip in the file paths
    \item You can reverse apply a patch with the \code{-R} option
    \item You can test a patch with \code{--dry-run} option
    \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Applying a Linux patch}
  Linux patches...
  \begin{itemize}
  \item Always applied to the \code{x.y.<z-1>} version\\
    Can be downloaded in \code{gzip}, \code{bzip2} or \code{xz} (much
    smaller) compressed files.
  \item Always produced for \code{n=1}\\
    (that's what everybody does... do it too!)
  \item Need to run the \code{patch} command inside the kernel source
    directory
  \item Linux patch command line example:\\
\begin{verbatim}
cd linux-3.0
xzcat ../patch-3.1.xz | patch -p1
xzcat ../patch-3.1.3.xz | patch -p1
cd ..; mv linux-3.0 linux-3.1.3
\end{verbatim}
  \end{itemize}
\end{frame}
