Contents:
Part1 : Environment setup and initial build
Part2 : Build u-boot using Yocto
Part3 : Build Kernel using Yocto
Part4 : Package Development using Yocto     <-- You are here
Part5 : Application Development using ADT

 

In my last blog we walk through the steps involved in kernel build on yocto platform.

 

In this blog we will create a small package and add to yocto  using simple steps.

 

In previous blogs we have used bitbake commands to build uboot and kernel images.

you must be aware by now that something call recipe (config files) are required to build yocto packages.

 

We will create a package. lets say “helloworld”. (i can't find a better package name )

 

The recipe for helloworld must be present in  a directory which bitbake can locate by parsing  predefined recipe directories in bblayers.conf.

 

As usual :

Setting up yocto environment for Riotboard:

~$ cd fsl-arm-yocto-bsp

~/fsl-arm-yocto-bsp$  MACHINE=riotboard source fsl-setup-release.sh -b build -e fb

~/fsl-arm-yocto-bsp/build$

 

All the recipe paths are  set in "build/conf/bblayers.conf"

we can add our recipe to any of the paths mentioned by  BBLAYERS.


I am selecting the meta-oe directory for my recipe.

 

blayers.conf

LCONF_VERSION = "6"

 

BBPATH = "${TOPDIR}"

BSPDIR := "${@os.path.abspath(os.path.dirname(d.getVar('FILE', True)) + '/../..')}"

 

BBFILES ?= ""

BBLAYERS = " \

  ${BSPDIR}/sources/poky/meta \

  ${BSPDIR}/sources/poky/meta-yocto \

  \

${BSPDIR}/sources/meta-openembedded/meta-oe \

  \

  ${BSPDIR}/sources/meta-fsl-arm \

  ${BSPDIR}/sources/meta-fsl-arm-extra \

  ${BSPDIR}/sources/meta-fsl-demos \

"

##Freescale Yocto Release layer

BBLAYERS += " ${BSPDIR}/sources/meta-fsl-bsp-release/imx/meta-fsl-arm "

BBLAYERS += " ${BSPDIR}/sources/meta-fsl-bsp-release/imx/meta-fsl-demos "

BBLAYERS += " ${BSPDIR}/sources/meta-browser "

BBLAYERS += " ${BSPDIR}/sources/meta-openembedded/meta-gnome "

BBLAYERS += " ${BSPDIR}/sources/meta-openembedded/meta-networking "

 

Creating Recipe:

~/fsl-arm-yocto-bsp/build$ cd ../sources/meta-openembedded/meta-oe/recipes-support

~/fsl-arm-yocto-bsp/sources/meta-openembedded/meta-oe/recipes-support$ mkdir helloworld && mkdir helloworld/files

It will create a helloworld directory with a files directory in it.

 

Now create a recipe (a file) called “helloworld_0.0.bb” in helloworld directory with appropriate  contents.

 

helloworld_0.0.bb

DESCRIPTION = "helloworld test"

PR = "r0"

SRC_URI = "file://helloworld.c"

LICENSE = "MIT"

LIC_FILES_CHKSUM = "file://helloworld.c;md5=d8a749d19bf44c377936cfc80333c27e"

S = "${WORKDIR}"

 

do_compile() {

             ${CC} ${CFLAGS} ${LDFLAGS} -o helloworld helloworld.c

}

 

do_install() {

             install -d ${D}${bindir}/

             install -m 0755 ${S}/helloworld ${D}${bindir}/

}

 

FILES_${PN} = "${bindir}/helloworld"

 

Next create a file “helloworld.c” in helloworld/files directory with below contents:

#include <stdio.h>

 

int main()

{

    printf("hello world\n");

    return 0;

}

 

checking the directory structure:

~/fsl-arm-yocto-bsp/sources/meta-openembedded/meta-oe/recipes-support$ tree helloworld

 

helloworld

|-- files

|   `-- helloworld.c

`-- helloworld_0.0.bb

 

1 directory, 2 files

 

 

 

we need to have the correct md5sum  of  helloworld.c  in  helloworld_0.0.bb  for the recipe to build sucessfully.

 

~/fsl-arm-yocto-bsp/sources/meta-openembedded/meta-oe/recipes-support$ md5sum helloworld/files/helloworld.c

d8a749d19bf44c377936cfc80333c27e  helloworld/files/helloworld.c

 

Now check if the above md5 value matches with the one in recipe.

~/fsl-arm-yocto-bsp/sources/meta-openembedded/meta-oe/recipes-support$ cat helloworld/helloworld_0.0.bb | grep md5

LIC_FILES_CHKSUM = "file://helloworld.c;md5=d8a749d19bf44c377936cfc80333c27e"

 

If the md5 values on above cases match we are ready for build, else update the md5 value in helloworld_0.0.bb.

 

from the yocto build directory build the recipe.

~/fsl-arm-yocto-bsp/sources/meta-openembedded/meta-oe/recipes-support$ cd -

~/fsl-arm-yocto-bsp/build$ bitbake helloworld

You will get the below output

--------

--------

--------

NOTE: Preparing runqueue

NOTE: Executing SetScene Tasks

NOTE: Executing RunQueue Tasks

NOTE: Tasks Summary: Attempted 538 tasks of which 530 didn't need to be rerun and all succeeded.

 

Summary: There was 1 WARNING message shown.

~/fsl-arm-yocto-bsp/build$

 

If you will get below error, certainly you have a md5sum mismatch.

zya43k.jpg

 

The image binary can be found here.

build/tmp/work/cortexa9hf-vfp-neon-poky-linux-gnueabi/helloworld/0.0-r0/image/usr/bin/helloworld

build/tmp/work/cortexa9hf-vfp-neon-poky-linux-gnueabi/helloworld/0.0-r0

 

Now copy and execute the binary in Riotboard:

root@riotboard:/opt# ./helloworld

hello world

root@riotboard:/opt#

 

It will output a nice helloworld display.

 

Okay that was cool.

 

Now there are two things :

1. you can share your application binary as a standalone executable.

2. distribute your app with the BSP and make it available by default in rootfs in sdcard image .

 

To bundle our helloworld app with bsp:

 

Inside fsl-arm-yocto-bsp directory.

 

add below line in fsl-setup-release.sh

echo "IMAGE_INSTALL_append = \" helloword \"" >> $BUILD_DIR/conf/local.conf

 

echo "BBLAYERS += \" \${BSPDIR}/sources/meta-browser \"" >> $BUILD_DIR/conf/bblayers.conf

echo "BBLAYERS += \" \${BSPDIR}/sources/meta-openembedded/meta-gnome \"" >> $BUILD_DIR/conf/bblayers.conf

echo "BBLAYERS += \" \${BSPDIR}/sources/meta-openembedded/meta-networking \"" >> $BUILD_DIR/conf/bblayers.conf

 

echo >> $BUILD_DIR/conf/local.conf

#trp add

echo "IMAGE_INSTALL_append = \" helloworld \"" >> $BUILD_DIR/conf/local.conf

 

 

if [ "$BACKEND" = "fb" ] || [ "$BACKEND" = "wayland" ] || [ "$BACKEND" = "dfb" ]  ; then

 

Inside "/sources/meta-fsl-bsp-release/imx/meta-fsl-demos/recipes-fsl/images" directory.

 

add  helloworld  to  IMAGE_INSTALL  in fsl-image-fb.bb

IMAGE_INSTALL += " \

    ${SOC_IMAGE_INSTALL} \

    cpufrequtils \

    nano \

    packagegroup-fsl-gstreamer \

    packagegroup-fsl-tools-testapps \

    packagegroup-fsl-tools-benchmark \

    helloworld \

    "

 

export IMAGE_BASENAME = "fsl-image-fb"

 

now “helloworld” package will be available as built-in binary.

 

Henceforth when you are building image using fsl-image-fb, the helloworld package gets automatically added to the image.

 

You can find more information on recipe creation here.