\subsection{Add base-files/busybox}
\begin{frame}
\frametitle{Workflow}
\begin{itemize}
\item busybox provides common commands, init and sh
\item symlinks need to be created
\item inittab and rcS needs to be provided
\end{itemize}
\end{frame}

\begin{frame}[fragile]
\frametitle{Add a busybox recipe}
\begin{lstlisting}
$ cd ~/poky/meta-schulung
$ mkdir -p recipes-core/busybox
$ pluma recipes-core/busybox/busybox_1.29.3.bb
\end{lstlisting}
\begin{verbatim}
LICENSE = "GPLv2 & bzip2"
LIC_FILES_CHKSUM = "file://LICENSE;md5=de10de48642ab74318e893a61105afbb"

SRC_URI = "http://www.busybox.net/downloads/${P}.tar.bz2;name=upstream"
SRC_URI[upstream.md5sum] = "0a367e19cdfd157e8258d87f893ee516"
SRC_URI[upstream.sha256sum] =
"97648636e579462296478e0218e65e4bc1e9cd69089a3b1aeb810bff7621efb7"

DEPENDS += "virtual/crypt"
EXTRA_OEMAKE += "CROSS_COMPILE=${TARGET_PREFIX}"
EXTRA_OEMAKE += "CONFIG_SYSROOT=${PKG_CONFIG_SYSROOT_DIR}"
EXTRA_OEMAKE += "V=1"

FILES_${PN}-dev += " ${datadir}/busybox/busybox.links"
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{Add a busybox recipe \#2}
\begin{verbatim}
do_configure() {
    oe_runmake defconfig
}

do_compile() {
    export CFLAGS="${TARGET_CC_ARCH} $CFLAGS"
    oe_runmake busybox_unstripped
    oe_runmake busybox.links
}

do_install() {
    test "${prefix}" != "/usr" && \
        sed -i -e "s:^/usr/:DONE${prefix}/:" busybox.links
    test "${base_sbindir}" != "/sbin" && \
        sed -i -e "s:^/sbin/:DONE${base_sbindir}/:" busybox.links
    test "${base_bindir}" != "/bin" && \
        sed -i -e "s:^/bin/:DONE${base_bindir}/:" busybox.links
    sed -i -e "s:^DONE::" busybox.links

    install -D -m 0755 busybox_unstripped ${D}${base_bindir}/busybox
    install -D -m 0644 busybox.links ${D}${datadir}/busybox/busybox.links
}
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{Add inittab}
\begin{lstlisting}
$ cd ~/poky/meta-schulung
$ mkdir -p recipes-core/rootfs/files
$ pluma recipes-core/rootfs/files/busybox_inittab
\end{lstlisting}
\begin{verbatim}
::sysinit:/etc/rcS
::askfirst:-/bin/sh
::restart:/sbin/init
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{Add startscript}
\begin{lstlisting}
$ cd ~/poky/meta-schulung
$ pluma recipes-core/rootfs/files/rcS
\end{lstlisting}
\begin{verbatim}
#!/bin/sh

mount -t proc proc /proc
mount -t sysfs sys /sys
mount -t tmpfs tmpfs /dev
mount -t tmpfs tmpfs /run

mdev -s
echo /sbin/mdev > /proc/sys/kernel/hotplug

mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
mkdir -p /run/lock/subsys
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{Add base-files recipe}
\begin{lstlisting}
$ cd ~/poky/meta-schulung
$ pluma recipes-core/rootfs/schulung-base.bb
\end{lstlisting}
\begin{verbatim}
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

RDEPENDS_${PN} = "busybox"

SRC_URI = "file://busybox_inittab file://rcS"

do_install() {
  install -D -m 0755 ${WORKDIR}/rcS ${D}${sysconfdir}/rcS
  install -D -m 0644 ${WORKDIR}/busybox_inittab ${D}${sysconfdir}/inittab
  install -d ${D}/run
  install -d ${D}/tmp
  install -d ${D}/dev
  install -d ${D}/proc
  install -d ${D}/sys
}

FILES_${PN} += "/run /tmp /dev /proc /sys"
\end{verbatim}
\end{frame}


\begin{frame}[fragile]
\frametitle{Use base-files recipe in image}
\begin{lstlisting}
$ cd ~/poky/meta-schulung
$ pluma recipes-core/images/core-image-schulung.bb
\end{lstlisting}
\begin{verbatim}
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

inherit core-image

IMAGE_LINGUAS = ""
CORE_IMAGE_BASE_INSTALL = " \
                           schulung-base \
                           kernel-modules \
                           example \
                          "
DEPENDS += "busybox"

setup_busybox_links() {
    LINKS="${PKG_CONFIG_SYSROOT_DIR}${datadir}/busybox/busybox.links"
    for lnfile in `cat $LINKS`; do
        test $lnfile = /linuxrc && continue
        install -d ${IMAGE_ROOTFS}`dirname $lnfile`
        ln -s ${base_bindir}/busybox ${IMAGE_ROOTFS}$lnfile || true
    done
}
do_rootfs[postfuncs] += "setup_busybox_links"
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{Build and run image}
\begin{lstlisting}
$ cd ~/poky/build-schulung
$ bitbake core-image-schulung
$ ./tmp/sysroots-components/x86_64/qemu-native/usr/bin/qemu-system-arm \
    -M vexpress-a9 -nographic \
    -net nic -net user,hostfwd=tcp::1534-:1534,hostfwd=tcp::2345-:2345 \
    -drive if=sd,format=raw,\
file=tmp/deploy/images/vexpress/core-image-schulung-vexpress.wic \
    -dtb    tmp/deploy/images/vexpress/vexpress-v2p-ca9.dtb \
    -kernel tmp/deploy/images/vexpress/zImage \
    -append "console=ttyAMA0,115200 root=/dev/mmcblk0p1 rw ip=dhcp"
[..]
Please press Enter to activate this console.
/ # df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                81.9M      8.4M     69.3M  11% /
[..]
\end{lstlisting}
\end{frame}
