
\documentclass[obeyspaces,spaces,hyphens]{beamer}
\usepackage[utf8]{inputenc}
\usepackage{minted}

\mode<presentation>
\usetheme{Bootlin}

\newcommand{\codehack}[1]{{\usebeamercolor[fg]{code} {\tt #1}}}

\title{{\em rootfs} made easy with Buildroot}
\authors{Thomas Petazzoni}
\institute{Bootlin}

\usepackage{hyperref}

\begin{document}

\begin{frame}{Kernel Recipes 2013}
  \begin{columns}[c]
   \column{0.6\textwidth}
     \huge
     {\em Rootfs} made easy with Buildroot\\
     \vspace{1cm}
     \large
     How kernel developers can finally solve the rootfs problem.\\
     \vspace{1cm}
     \normalsize
     Thomas Petazzoni\\
     {\bf Bootlin}\\
     {\em thomas.petazzoni@bootlin.com}
     \column{0.4\textwidth}
     \includegraphics[width=\textwidth]{buildroot-logo.png}
   \end{columns}
\end{frame}

\begin{frame}{Thomas Petazzoni}
  \begin{itemize}
  \item CTO and embedded Linux engineer at Bootlin
    \begin{itemize}
    \item Embedded Linux {\bf development}: kernel and driver
      development, system integration, boot time and power
      consumption optimization, consulting, etc.
    \item Embedded Linux {\bf training}, Linux driver development training
      and Android system development training, with materials freely
      available under a Creative Commons license.
    \item {\bf We're hiring!}
    \item \url{http://bootlin.com}
    \end{itemize}
  \item Contributing the {\bf kernel support for the new Armada 370
      and Armada XP} ARM SoCs from Marvell (widely used in NAS
    devices).
  \item Major contributor to {\bf Buildroot}, an open-source, simple and
    fast embedded Linux build system
  \item Living in {\bf Toulouse}, south west of France
  \end{itemize}
\end{frame}

\begin{frame}{}
\begin{center}
  \huge
  Doing kernel development is awesome, but...
\end{center}
\end{frame}

\begin{frame}[fragile]{}
  \begin{center}
    \huge
    A kernel without a root filesystem is kind of useless
    \vspace{1cm}
  \tiny
\begin{block}{}
\begin{verbatim}
input: ImExPS/2 Generic Explorer Mouse as /devices/fpga:07/serio1/input/input1
Root-NFS: no NFS server address
VFS: Unable to mount root fs via NFS, trying floppy.
VFS: Cannot open root device "(null)" or unknown-block(2,0)
Please append a correct "root=" boot option; here are the available partitions:
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
\end{verbatim}
\end{block}
  \end{center}
\end{frame}

\begin{frame}{Solutions often used by kernel dev}
  \begin{itemize}
  \item A {\bf complete Linux distribution}
    \begin{itemize}
    \item[+] Readily available
    \item[-] Large (can hardly be used as an initramfs)
    \item[-] Not available for all architectures
    \item[-] Not easy to customize.
    \end{itemize}
  \item A {\bf pre-built rootfs}
    \begin{itemize}
    \item[+] Usually relatively small
    \item[-] Even less flexible
    \item[-] Not available for all architectures.
    \end{itemize}
  \item A rootfs {\bf built manually} with Busybox
    \begin{itemize}
    \item[+] Smaller and flexible
    \item[-] Quite some work to create
    \item[-] Busybox is often not sufficient (testing sound?  video?
      input devices? graphics?  network?).
    \item[-] Difficult to reproduce for colleagues
    \end{itemize}
  \end{itemize}
  $\rightarrow$ There must be something better.
\end{frame}

\begin{frame}{Embedded Linux build systems}
  \begin{itemize}
  \item {\bf Embedded Linux build systems} are tools that automate
    the process of building a small (or not so small) Linux system
    {\bf from source}.
  \item From source $\rightarrow$ lot of flexibility
  \item Generally used to build production embedded Linux systems, but
    they can also be used by kernel developers to build small root
    filesystems for testing purposes!
  \item Well-known build systems: OpenEmbedded, Yocto, {\bf
      Buildroot}, PTXdist, etc.
  \item {\em For me, OE fails the easy to understand, quick to setup
      test. I now use Buildroot.} -- Kevin Hilman, ARM kernel
    developer
  \end{itemize}
\end{frame}

\begin{frame}{Buildroot}
  \begin{itemize}
  \item Can build a toolchain, a rootfs, a kernel, a bootloader
  \item {\bf Easy to configure}: menuconfig, xconfig, etc.
  \item {\bf Fast}: builds a simple root filesystem in a few minutes
  \item Easy to understand: written in make, extensive documentation
  \item {\bf Small} root filesystem
  \item More than {\bf 1000 userspace libraries/apps} available,
    including important development and debug tools (see later)
  \item {\bf Many architectures} supported: x86, ARM, PowerPC, MIPS,
    SuperH, Blackfin, ARC, Xtensa, Microblaze, Nios II.
  \item Active community, regular releases
  \item Used by many embedded system makers, including {\em Google}
    for the {\em Google Fiber} boxes.
  \item \url{http://buildroot.org}
  \end{itemize}
\end{frame}

\begin{frame}{Basic usage (1)}
  \begin{center}
    \huge
    \code{make menuconfig}\\
    \vspace{0.5cm}
    \includegraphics[width=0.8\textwidth]{buildroot-screenshot.png}
  \end{center}
\end{frame}

\begin{frame}{Basic usage (2)}
  \begin{center}
    \huge
    \code{make}\\
    \vspace{0.5cm}
    It builds...\\
    \vspace{0.5cm}
    Root filesystem image available in \code{output/images}.
  \end{center}
\end{frame}

\begin{frame}{{\em initramfs} use case: why}
  \begin{itemize}
  \item {\em initramfs} is great for kernel development because your
    rootfs is fully in RAM, and has absolutely {\bf no dependency on
      any kernel driver}. You don't need a storage driver or a network
    driver.
  \item However, since the root filesystem is loaded entirely in RAM,
    at every kernel boot, it {\bf has to be small}. Buildroot's
    ability to generate really small filesystems is very useful here.
  \end{itemize}
\end{frame}

\begin{frame}{{\em initramfs} use case: Buildroot side}
  Example for an ARM Cortex-A8 platform.
  \begin{itemize}
  \item \code{make menuconfig}
    \begin{itemize}
    \item {\bf Target options}, select the {\em ARM} architecture, the
      {\em EABIhf} ABI and the {\em Cortex-A8} architecture variant.
    \item {\bf Toolchain}, select {\em External toolchain}, and then the
      {\em Linaro} toolchain.
    \item {\bf System configuration}, select the {\em devtmpfs}
      \code{/dev} management method and ensure the serial port for the
      {\em getty} is correct.
    \item {\bf Filesystem images}, select the {\em cpio} format.
    \end{itemize}
  \item \code{make}
  \item Your CPIO image is in \code{output/images/rootfs.cpio}.
    \begin{itemize}
    \item Contains just Busybox.
    \item 3 MB uncompressed.
    \item 2 minutes and 46 seconds of complete build time, on a 2
      years old laptop.
    \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}{{\em initramfs} use case: kernel side}
  The kernel configuration should have:
  \begin{itemize}
  \item
    \code{CONFIG_INITRAMFS_SOURCE="/path/to/buildroot/output/images/rootfs.cpio"}
  \item \code{CONFIG_INITRAMFS_COMPRESSION_GZIP=y} or some other
    compression algorithm
  \item \code{CONFIG_DEVTMPFS=y}, to get {\em devtmpfs} support, to
    provide a dynamic {\em /dev}
  \item Note that Buildroot does this configuration automatically when
    it is responsible for building the kernel. However, when doing
    active kernel development, one typically builds the kernel outside
    of Buildroot.
  \end{itemize}
\end{frame}

\begin{frame}{NFS use case: how}
  \begin{itemize}
  \item In Buildroot, select the {\em tar} filesystem image format.
  \item After the build, uncompress as root the image tarball to your
    NFS exported directory:\\
    \code{sudo tar -C /nfsroot -xf output/images/rootfs.tar}\\
    Note: this can be automated with a {\em post-image script}.
  \item Configure your kernel to mount \code{/nfsroot}, and make sure
    you have \code{CONFIG_DEVTMPFS}, \code{CONFIG_DEVTMPFS_MOUNT},
    \code{CONFIG_NFS_FS} and \code{CONFIG_ROOT_NFS} enabled.
  \item Do {\bf not} directly use \code{output/target} as the
    NFS-exported directory. Permissions and ownership are not correct.
  \end{itemize}
\end{frame}

\begin{frame}{Extending your rootfs}
  Doing kernel development that needs some specific userspace tools?
  Buildroot already has a good number of them:
  \begin{itemize}
  \item A must is Dropbear for SSH.
  \item Benchmarks/testing programs: dhrystone, iozone, bonnie++, LTP,
    netperf, ramspeed, stress, lmbench, iostat, memtester, etc.
  \item Debugging tools: latencytop, LTTng, trace-cmd, etc.
  \item Hardware interaction: evtest, i2c-tools, devmem2,
    pciutils, usbutils, libv4l, yavta, alsa-utils, linux-firmware,
    mii-diag, etc.
  \item Many more packages already available in Buildroot.
  \item And can be extended with more packages: easy to do, and well
    documented in the Buildroot manual.
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{Configuration example 1}
  Used for my kernel development on Marvell Armada 370/XP.
  \begin{columns}
    \column{0.5\textwidth}
    \tiny
    \begin{block}{}
\begin{verbatim}
BR2_arm=y
BR2_cortex_a8=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_MDEV=y
BR2_PACKAGE_LINUX_FIRMWARE=y
BR2_PACKAGE_LINUX_FIRMWARE_IWLWIFI_5000=y
BR2_PACKAGE_LINUX_FIRMWARE_MWIFIEX_SD8787=y
BR2_PACKAGE_LINUX_FIRMWARE_RTL_8192=y
BR2_PACKAGE_LINUX_FIRMWARE_RTL_8712=y
BR2_PACKAGE_I2C_TOOLS=y
BR2_PACKAGE_PCIUTILS=y
BR2_PACKAGE_USBUTILS=y
BR2_PACKAGE_USBUTILS_ZLIB=y
BR2_PACKAGE_DROPBEAR=y
BR2_PACKAGE_ETHTOOL=y
BR2_PACKAGE_IPERF=y
BR2_PACKAGE_IW=y
BR2_PACKAGE_MII_DIAG=y
BR2_PACKAGE_WIRELESS_TOOLS=y
BR2_TARGET_ROOTFS_CPIO=y
\end{verbatim}
      \end{block}
    \column{0.5\textwidth}
    \begin{itemize}
    \item For ARM Cortex-A8
    \item Uses {\em mdev} for firmware loading
    \item Has a few
      firmwares
    \item i2c-tools
    \item pciutils
    \item usbutils
    \item dropbear
    \item and various network/wireless related tools.
    \item Size: 5.6 MB, 13 minutes build time.
    \end{itemize}
  \end{columns}
\end{frame}

\begin{frame}[fragile]{Configuration example 2}
  \begin{itemize}
  \item Used for my kernel development on Marvell Armada 370/XP in Big
    Endian mode.
  \item A more minimal variant, with just Dropbear, but shows that
    doing rootfs for 'exotic' architectures is also possible.
  \end{itemize}
  \tiny
  \begin{block}{}
\begin{verbatim}
BR2_armeb=y
BR2_cortex_a8=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_PATH="/home/thomas/x-tools/armebv7-marvell-linux-gnueabi-softfp_i686/"
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="armeb-marvell-linux-gnueabi"
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC=y
BR2_TOOLCHAIN_EXTERNAL_CXX=y
BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_DEVTMPFS=y
BR2_PACKAGE_DROPBEAR=y
BR2_TARGET_ROOTFS_CPIO=y
\end{verbatim}
  \end{block}
\end{frame}

\begin{frame}{Conclusion}
\begin{center}
  \includegraphics[height=0.8\textheight]{lolcat.jpg}
\end{center}
\end{frame}

\begin{frame}
  \begin{center}
  \Huge
  Questions?\\
  \vspace{1.5cm}
  \url{http://buildroot.org}\\
  \vspace{2cm}
  \small
  Thomas Petazzoni\\
  \code{thomas.petazzoni@bootlin.com}\\
  \footnotesize
  Thanks to the Buildroot community (Arnout Vandecappelle, Thomas De
  Schampheleire, Peter Korsgaard) and to Kevin Hilman for reviewing
  the slides.\\
  \vspace{0.5cm}
  Slides under CC-BY-SA 3.0\\
  \scriptsize
  \url{http://bootlin.com/pub/conferences/2013/kernel-recipes/rootfs-kernel-developer/}
  \end{center}
\end{frame}

\end{document}
