Search by Tags

Hello World integration into OpenEmbedded

 

Subscribe for this article updates

This article describes how you can create a new meta-layer for OpenEmbedded and how you can add your own hello-world application. We don't go into details, it should only give you an easy introduction on how to start. For further details please read the Yocto Project Mega-Manual.

Create a meta layer

First, you need to compile an image according to the following link: OpenEmbedded (core) For starting we recommend compiling the angstrom-lxde-image.

After that we need to create a new meta-customer layer:

cd layers
mkdir -p meta-customer/conf
cd meta-customer

Edit conf/layer.conf so that it looks as follows:

# We have a conf and classes directory, add to BBPATH
BBPATH .= ":${LAYERDIR}"
 
# We have recipes-* directories, add to BBFILES
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"
 
BBFILE_COLLECTIONS += "customer"
BBFILE_PATTERN_customer = "^${LAYERDIR}/"
BBFILE_PRIORITY_customer = "1"
 
# This should only be incremented on significant changes that will
# cause compatibility issues with other layers
LAYERVERSION_customer = "1"
 
LAYERDEPENDS_customer = "core"
 
LAYERSERIES_COMPAT_customer = "rocko"

Create a recipe

Now that we have a meta layer we need to create a recipe.

# Hello world needs to be there twice
mkdir -p recipes-customer/hello-world/hello-world

Create a recipe file recipes-customer/hello-world/hello-world_1.0.0.bb:

# Package summary
SUMMARY = "Hello World"
# License, for example MIT
LICENSE = "MIT"
# License checksum file is always required
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
 
# hello-world.c from local file
SRC_URI = "file://hello-world.cpp"
 
# Change source directory to workdirectory where hello-world.cpp is
S = "${WORKDIR}"
 
# Compile hello-world from sources, no Makefile
do_compile() {
    ${CXX} -Wall hello-world.cpp -o hello-world
}
 
# Install binary to final directory /usr/bin
do_install() {
    install -d ${D}${bindir}
    install -m 0755 ${S}/hello-world ${D}${bindir}
}

Add the hello world sources to recipes-customer/hello-world/hello-world/hello-world.cpp:

#include <stdio.h>
 
int main(int argc, char *argv[]){
    printf("Hello world!\n");
    return 0;
}

Add meta layer to buildsystem

After that you have to change to the build directory again and initialize the build system:

cd ../../
. export

Add the new meta-customer layer to conf/bblayers.conf so that it looks as follows:

# LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
LCONF_VERSION = "7"
 
BBPATH = "${TOPDIR}"
BBFILES ?= ""
 
BBLAYERS ?= " \
  ${TOPDIR}/../layers/meta-angstrom \
  \
  \
  ${TOPDIR}/../layers/meta-toradex-nxp \
  ${TOPDIR}/../layers/meta-freescale \
  ${TOPDIR}/../layers/meta-freescale-3rdparty \
  \
  ${TOPDIR}/../layers/meta-toradex-tegra \
  ${TOPDIR}/../layers/meta-jetson-tk1 \
  \
  ${TOPDIR}/../layers/meta-toradex-bsp-common \
  \
  ${TOPDIR}/../layers/meta-openembedded/meta-oe \
  ${TOPDIR}/../layers/meta-openembedded/meta-filesystems \
  ${TOPDIR}/../layers/meta-openembedded/meta-gnome \
  ${TOPDIR}/../layers/meta-openembedded/meta-xfce \
  ${TOPDIR}/../layers/meta-openembedded/meta-initramfs \
  ${TOPDIR}/../layers/meta-openembedded/meta-networking \
  ${TOPDIR}/../layers/meta-openembedded/meta-multimedia \
  ${TOPDIR}/../layers/meta-openembedded/meta-python \
  ${TOPDIR}/../layers/meta-lxde \
  ${TOPDIR}/../layers/meta-browser \
  ${TOPDIR}/../layers/meta-qt4 \
  ${TOPDIR}/../layers/meta-qt5 \
  ${TOPDIR}/../layers/meta-qt5-extra \
  ${TOPDIR}/../layers/meta-freescale-distro \
  ${TOPDIR}/../layers/meta-toradex-demos \
  \
  \
  ${TOPDIR}/../layers/openembedded-core/meta \
  \
  \
  ${TOPDIR}/../layers/meta-customer \
"

For testing you can build your hello-world package:

bitbake hello-world

Add package to the final image

To add the newly created recipe to your image, you can add the following line to conf/local.conf:

IMAGE_INSTALL_append = " hello-world"

After that you can build again your image. Now it will contain hello world under /usr/bin/hello-world.

bitbake angstrom-lxde-image