From 04a651092d67b7f1bc65628f0ec306eb78921149 Mon Sep 17 00:00:00 2001
From: Manuel Traut <manut@linutronix.de>
Date: Tue, 3 Feb 2015 16:53:55 +0100
Subject: yocto-advanced: improve slides and examples

convert everything to beaglebone-black and use the same names and path
in the example and the slides

Signed-off-by: Manuel Traut <manut@linutronix.de>
---
 .../yocto-advanced/pres_yocto-advanced.tex         | 244 +++++++++++++++------
 1 file changed, 172 insertions(+), 72 deletions(-)

(limited to 'distribution/yocto-advanced/pres_yocto-advanced.tex')

diff --git a/distribution/yocto-advanced/pres_yocto-advanced.tex b/distribution/yocto-advanced/pres_yocto-advanced.tex
index 881d21f..ee69d0b 100644
--- a/distribution/yocto-advanced/pres_yocto-advanced.tex
+++ b/distribution/yocto-advanced/pres_yocto-advanced.tex
@@ -7,7 +7,7 @@
 \frametitle{Agenda}
 \begin{itemize}
 \item Using BSP layers (beaglebone)
-\item Build a predefined image (sabrelite)
+\item Build a predefined image (beaglebone)
 \item Creating a layer
 \item Define a distribution
 \item Create an image
@@ -163,7 +163,6 @@ BBLAYERS ?= " \
   /home/devel/poky/meta-yocto \
   /home/devel/poky/meta-yocto-bsp \
   /home/devel/poky/meta-ti \
-  /home/devel/poky/meta-mini \
   "
 \end{verbatim}
 \pause
@@ -175,7 +174,6 @@ meta                  /home/devel/poky/meta                 5
 meta-yocto            /home/devel/poky/meta-yocto           5
 meta-yocto-bsp        /home/devel/poky/meta-yocto-bsp       5
 meta-ti               /home/devel/poky/meta-ti              5
-meta-mini             /home/devel/poky/meta-mini            5
 \end{verbatim}
 \end{frame}
 
@@ -225,9 +223,9 @@ to get a list of currently available machines configs:
 \begin{verbatim}
 poky/build-ti % grep -r '@NAME' ../meta*/conf/machine
 \end{verbatim}
-beaglebone-black.conf - seems to be the one for our bord, so set
+beaglebone.conf - seems to be the one for our bord, so set
 \begin{verbatim}
-MACHINE ??= "beaglebone-black"
+MACHINE ??= "beaglebone"
 \end{verbatim}
 in conf/local.conf
 \end{frame}
@@ -271,8 +269,6 @@ Currently 4 running tasks (26 of 4459):
 \begin{frame}[fragile]
 \frametitle{first errors and warnings}
 \begin{verbatim}
-WARNING: Host distribution "Debian-8.0" has not been validated with this version
-of the build system; you may possibly experience unexpected failures. It is
 recommended that you use a tested distribution.
 ERROR:  OE-core's config sanity checker detected a potential misconfiguration.
 Either fix the cause of this error or at your own risk disable the checker
@@ -358,28 +354,17 @@ if the build is completed the image can be transfered to a sdcard:
 poky/build-ti % sudo fdisk /dev/mmcblk0
 # create a bootable primary partition with about 100 MB and Windows vFat format
 # and a secondary partition with Linux Ext format
-poky/build-ti % sudo mkfs.vfat /dev/mmcblk0p1
-poky/build-ti % sudo dd \
-if=tmp/deploy/images/beaglebone-black/qt4e-demo-image-beaglebone-black.ext3 \
-  of=/dev/mmcblk0p2 bs=1M
-poky/build-ti % sudo mount /dev/mmcblk0p2 /mnt
-poky/build-ti % sudo tar xzf tmp/deploy/images/modules-beaglebone-black.tgz -C \
-  /mnt
-poky/build-ti % sudo umount /mnt
-\end{verbatim}
-\end{frame}
-
-\begin{frame}[fragile]
-\frametitle{flashing the image}
+poky/build-ti % sudo mkfs.vfat -F 16 -n boot /dev/mmcblk0p1
+poky/build-ti % sudo mke2fs -j -L "root" /dev/mmcblk0p2
 poky/build-ti % sudo mount /dev/mmcblk0p1 /mnt
-poky/build-ti % sudo cp -a tmp/deploy/images/beaglebone-black/MLO \
-  /dev/mmcblk0p1 /mnt
-poky/build-ti % sudo cp -a tmp/deploy/images/beaglebone-black/u-boot* \
-  /dev/mmcblk0p1 /mnt
-poky/build-ti % sudo cp -a tmp/deploy/images/beaglebone-black/zImage \
-  /dev/mmcblk0p1 /mnt
-poky/build-ti % sudo cp -a tmp/deploy/images/beaglebone-black/*.dtb \
-  /dev/mmcblk0p1 /mnt
+poky/build-ti % sudo cp -a tmp/deploy/images/beaglebone/MLO-beaglebone \
+  /mnt/MLO
+poky/build-ti % sudo cp -a tmp/deploy/images/beaglebone/u-boot-beaglebone.img \
+  /mnt/u-boot.img
+poky/build-ti % sudo umount /mnt
+poky/build-ti % sudo mount /dev/mmcblk0p2 /mnt
+poky/build-ti % sudo tar xjf \
+  tmp/deploy/images/qt4e-demo-image-beaglebone.tar.bz2 -C /mnt
 poky/build-ti % sudo umount /mnt
 \end{verbatim}
 \end{frame}
@@ -409,6 +394,22 @@ poky/meta-mini % git commit -sam 'inital version'
 \end{verbatim}
 \end{frame}
 
+\begin{frame}[fragile]
+\begin{verbatim}
+poky/meta-mini % cd ../build-ti
+\end{verbatim}
+edit 'conf/bblayers.conf':
+\begin{verbatim}
+BBLAYERS ?= " \
+  /home/devel/poky/meta \
+  /home/devel/poky/meta-yocto \
+  /home/devel/poky/meta-yocto-bsp \
+  /home/devel/poky/meta-ti \
+  /home/devel/poky/meta-mini \
+  "
+\end{verbatim}
+\end{frame}
+
 \subsection{Define a distribution}
 \begin{frame}
 \frametitle{why define a distribution?}
@@ -515,14 +516,14 @@ it can be used, to simplify image definitions
 \end{frame}
 
 \begin{frame}[fragile]
-\frametitle{linutronix distribution}
+\frametitle{minimal distribution}
 distros are defined in a layer, e.g.
-meta-mini/conf/distro/linutronix.conf:
+meta-mini/conf/distro/mini.conf:
 \begin{verbatim}
-DISTRO = "linutronix"
-DISTRO_NAME = "linutronix 1.0 (for foo devices)"
+DISTRO = "mini"
+DISTRO_NAME = "mini 1.0 (for foo devices)"
 DISTRO_VERSION = "1.0"
-DISTRO_CODENAME = "bar"
+DISTRO_CODENAME = "mal"
 SDK_VENDOR = "-linutronix"
 SDK_VERSION := "${@'${DISTRO_VERSION}'}"
 MAINTAINER = "Manuel Traut <manut@linutronix.de>"
@@ -536,16 +537,16 @@ DISTRO_FEATURES_append = " opengl"
 \begin{frame}[fragile]
 \frametitle{add distro to git repo}
 \begin{verbatim}
-poky/meta-mini % git add conf/distro/linutronix.conf
-poky/meta-mini % git commit -sam 'add linutronix distro'
+poky/meta-mini % git add conf/distro/mini.conf
+poky/meta-mini % git commit -sam 'add mini distro'
 \end{verbatim}
 \end{frame}
 
 \begin{frame}[fragile]
-\frametitle{use linutronix distro}
+\frametitle{use mini distro}
 edit DISTRO var in conf/local.conf
 \begin{verbatim}
-DISTRO ?= "linutronix"
+DISTRO ?= "mini"
 \end{verbatim}
 \end{frame}
 
@@ -561,32 +562,49 @@ packagegroup-core-ssh-dropbear:
 packagegroup-core-ssh-openssh:
 \end{verbatim}
 create the file
-'meta-mini/recipes-bsp/linutronix-image/linutronix-image.bb'
+'meta-mini/recipes-bsp/mini-image/mini-image.bb'
 \begin{verbatim}
 IMAGE_INSTALL += "openssh"
 inherit core-image
 \end{verbatim}
 to build the image, use:
 \begin{verbatim}
-poky/build-ti % bitbake linutronix-image
+poky/build-ti % bitbake mini-image
 \end{verbatim}
 \end{frame}
 
+\subsection{Machines}
 \begin{frame}[fragile]
-	\frametitle{image features}
-t.b.d. use IMAGE\_FEATURES
-% http://www.yoctoproject.org/docs/1.6/ref-manual/ref-manual.html#ref-features-image
+\frametitle{create a beaglebone-black machine config}
+create the file 'meta-mini/conf/machine/beaglebone-black.conf':
+\begin{verbatim}
+#@TYPE: Machine
+#@NAME: BeagleBone Black
+#@DESCRIPTION: Machine configuration for the http://beagleboard.org/bone board 
+
+require conf/machine/include/ti33x.inc
 
-% http://www.yoctoproject.org/docs/1.6/dev-manual/dev-manual.html#usingpoky-extend-customimage-imagefeatures
+IMAGE_FSTYPES += "ext3 tar.gz"
+EXTRA_IMAGEDEPENDS += "u-boot"
+SERIAL_CONSOLE = "115200 ttyO0"
+
+SDCARD_ROOTFS ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ext3"
+
+SPL_BINARY = "MLO"
+UBOOT_SUFFIX = "img"
+UBOOT_MACHINE = "am335x_boneblack_config"
+UBOOT_ENTRYPOINT = "0x80008000"
+UBOOT_LOADADDRESS = "0x80008000"
+\end{verbatim}
 \end{frame}
 
 \subsection{Writing recipes}
 \begin{frame}[fragile]
 \frametitle{adding a kernel}
-create the file 'meta-mini/recipes-bsp/linux-sabrelite/linux-sabrelite\_3.16.bb':
+create the file 'meta-mini/recipes-bsp/linux-vanilla/linux-vanilla\_3.18.5bb':
 \begin{verbatim}
 SECTION = "kernel"
-DESCRIPTION = "Linux 3.16 for sabrelite"
+DESCRIPTION = "Linux vanilla kernel"
 LICENSE = "GPLv2"
 KERNEL_IMAGETYPE = "uImage"
 
@@ -594,45 +612,46 @@ inherit kernel
 require recipes-kernel/linux/linux-dtb.inc
 require recipes-kernel/linux/setup-defconfig.inc
 
-COMPATILBE_MACHINE = "beaglebone-black"
-KERNEL_DEVICETREE_beaglebone-black = "arch/arm/boot/dts/imx6q-sabrelite.dts"
+COMPATILBE_MACHINE_beaglebone-black = "beaglebone-black"
+KERNEL_DEVICETREE_beaglebone-black = "arch/arm/boot/dts/am335x-boneblack.dts"
+
+S = "${WORKDIR}/linux-${PV}"
 
-S = "${WORKDIR}/git
-BRANCH = "master"
-SRCREV = "19583ca584d6f574384e17fe7613dfaeadcdc4a6"
-PV = "3.16"
-# cause a rebuild on new kernel version
-MACHINE_KERNEL_PR_append = "d+gitr${SRCPV}"
 SRC_URI = " \
-git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux;protocol=git;branch=${BRANCH} \
+https://www.kernel.org/pub/linux/kernel/v3.x/linux-${PV}.tar.xz \
 file://defconfig \
-"
+
+SRC_URI[md5sum] = "e7a985a243b7941b6bc6240fcbc797fc"
+SRC_URI[sha256sum] = "be37dda8ea090525661d64e5c7fc8580f313b7f9ba8592e32120f1332bc57d71"
+
 KERNEL_EXTRA_ARGS += "LOADADDR=${UBOOT_ENTRYPOINT}"
-# to modify cmdline, use APPEND += ""
+
+do_configure_prepend () {
+	cp '${WORKDIR}/defconfig' '${S}/.config'
 \end{verbatim}
 \end{frame}
 
 \begin{frame}[fragile]
 \frametitle{adding a defconfig}
 copy your .config file to
-'meta-mini/recipes-bsp/linux-sabrelite/files/beaglebone-black/defconfig'
+'meta-mini/recipes-bsp/linux-vanilla/files/beaglebone-black/defconfig'
 \end{frame}
 
 \begin{frame}[fragile]
 \frametitle{using a specific kernel}
 add
 \begin{verbatim}
-PREFERRED_PROVIDER_virtual/kernel = "linux-sabrelite"
+PREFERRED_PROVIDER_virtual/kernel = "linux-vanilla"
 \end{verbatim}
-to meta-mini/conf/distro/linutronix.conf
+to meta-mini/machine/beaglebone-black.conf
 \end{frame}
 
 \begin{frame}[fragile]
 \frametitle{Providers}
 \begin{verbatim}
---8<- -my-kernel\_3.16.bb --
+--8<- meta/classos/kernel.bbclass --
 PROVIDES += "virtual/kernel"
---8<------------------------
+--8<--------------------------------
 \end{verbatim}
 
 PREFERRED\_PROVIDER\_virtual/kernel = "linux-yocto"
@@ -642,7 +661,7 @@ PREFERRED\_PROVIDER\_virtual/kernel = "linux-yocto"
 \vspace{2em}
 also a preferred version can be set:
 
-PREFERRED\_VERSION\_virtual/kernel = "3.16"
+PREFERRED\_VERSION\_virtual/kernel = "3.18.5"
 \end{frame}
 
 \begin{frame}
@@ -656,6 +675,97 @@ PREFERRED\_VERSION\_virtual/kernel = "3.16"
 \end{itemize}
 \end{frame}
 
+\subsection{generate a sdcard image}
+\begin{frame}[fragile]
+\frametitle{sdcard generation}
+create the file: 'meta-mini/classes/image\_sdcard.bbclass':
+\begin{verbatim}
+inherit image_types
+
+IMAGE_BOOTLOADER ?= "u-boot"
+
+# Handle u-boot suffixes
+UBOOT_SUFFIX ?= "bin"
+UBOOT_PADDING ?= "0"
+UBOOT_SUFFIX_SDCARD ?= "${UBOOT_SUFFIX}"
+
+# Linux bootstream
+IMAGE_DEPENDS_linux.sb = "virtual/kernel:do_deploy"
+
+# Boot partition volume id
+BOOTDD_VOLUME_ID ?= "Boot ${MACHINE}"
+# Boot partition size [in KiB]
+BOOT_SPACE ?= "8192"
+# Set alignment to 4MB [in KiB]
+IMAGE_ROOTFS_ALIGNMENT = "4096"
+
+IMAGE_DEPENDS_sdcard = "parted-native:do_populate_sysroot \
+                        dosfstools-native:do_populate_sysroot \
+                        mtools-native:do_populate_sysroot \
+                        virtual/kernel:do_deploy \
+                        ${@d.getVar('IMAGE_BOOTLOADER', True) and d.getVar('IMAGE_BOOTLOADER', True) + ':do_deploy' or ''}"
+
+SDCARD = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.sdcard"
+
+SDCARD_GENERATION_COMMAND_ti33x = "generate_ti_sdcard"
+
+generate_ti_sdcard () {
+	parted -s ${SDCARD} mklabel msdos
+	parted -s ${SDCARD} unit KiB mkpart primary fat32 ${IMAGE_ROOTFS_ALIGNMENT} $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED})
+	parted -s ${SDCARD} unit KiB mkpart primary $(expr  ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED}) $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED} \+ $ROOTFS_SIZE)
+	parted -s ${SDCARD} set 1 boot on
+	parted ${SDCARD} print
+
+	BOOT_BLOCKS=$(LC_ALL=C parted -s ${SDCARD} unit b print \
+	                  | awk '/ 1 / { print substr($4, 1, length($4 -1)) / 1024 }')
+	mkfs.vfat -n "${BOOTDD_VOLUME_ID}" -S 512 -C ${WORKDIR}/boot.img $BOOT_BLOCKS
+
+	# copy files to /boot
+	mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/MLO-${MACHINE} ::/MLO
+	mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.img ::/u-boot.img
+	mmd -i ${WORKDIR}/boot.img  ::/boot
+	mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${MACHINE}.bin ::/boot/${KERNEL_IMAGETYPE}
+	mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-am335x-boneblack.dtb ::/boot/am335x-boneblack.dtb
+	mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/uEnv.txt ::/uEnv.txt
+
+	# Burn Partition
+	dd if=${WORKDIR}/boot.img of=${SDCARD} conv=notrunc seek=1 bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync
+	dd if=${SDCARD_ROOTFS} of=${SDCARD} conv=notrunc seek=1 bs=$(expr ${BOOT_SPACE_ALIGNED} \* 1024 + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync
+}
+
+IMAGE_CMD_sdcard () {
+	if [ -z "${SDCARD_ROOTFS}" ]; then
+		bberror "SDCARD_ROOTFS is undefined. To use sdcard image from Freescale's BSP it needs to be defined."
+		exit 1
+	fi
+
+	# Align boot partition and calculate total SD card image size
+	BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1)
+	BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE_ALIGNED} - ${BOOT_SPACE_ALIGNED} % ${IMAGE_ROOTFS_ALIGNMENT})
+	SDCARD_SIZE=$(expr ${IMAGE_ROOTFS_ALIGNMENT} + ${BOOT_SPACE_ALIGNED} + $ROOTFS_SIZE + ${IMAGE_ROOTFS_ALIGNMENT})
+
+	# Initialize a sparse file
+	dd if=/dev/zero of=${SDCARD} bs=1 count=0 seek=$(expr 1024 \* ${SDCARD_SIZE})
+
+	${SDCARD_GENERATION_COMMAND}
+}
+
+# The sdcard requires the rootfs filesystem to be built before using
+# it so we must make this dependency explicit.
+IMAGE_TYPEDEP_sdcard = "${@d.getVar('SDCARD_ROOTFS', 1).split('.')[-1]}"
+\end{verbatim}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{configure machine to use sdcard imagetype}
+add the following lines to 'meta-mini/conf/machine/beaglebone-black.conf':
+\begin{verbatim}
+IMAGE_CLASSES += "image_sdcard"
+SDCARD_ROOTFS ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ext3"
+IMAGE_FSTYPES += "sdcard"
+\end{verbatim}
+\end{frame}
+
 \begin{frame}
 \frametitle{adding an own application}
 \begin{itemize}
@@ -767,16 +877,6 @@ do_install() {
 \end{verbatim}
 \end{frame}
 
-\begin{frame}
-\frametitle{use PR Service}
-bla
-\end{frame}
-
-\begin{frame}
-\frametitle{adding a bootscript}
-bla
-\end{frame}
-
 \begin{frame}[fragile]
 \frametitle{user and group configuration}
 use this in an image recipe:
-- 
cgit v1.2.3

