</>EmbeddedInterview

What are Yocto layers, recipes and bbappend files?

MediumEmbedded Linux & Boot

Short answer: A recipe (.bb) tells BitBake how to build one piece of software. A layer (meta-*) groups recipes and configuration so that the vendor BSP, the distribution policy and your product stay separate. A .bbappend modifies a recipe from another layer without editing it.

Recipe: describes the source, license and build steps through BitBake tasks.

SUMMARY = "Sensor daemon"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=..."
SRC_URI = "git://github.com/acme/sensord.git;branch=main;protocol=https"
SRCREV = "1a2b3c..."
S = "${WORKDIR}/git"
inherit cmake systemd
SYSTEMD_SERVICE:${PN} = "sensord.service"

Tasks run in order: do_fetch → do_unpack → do_patch → do_configure → do_compile → do_install → do_package, and the image tasks assemble the root filesystem. Classes such as cmake, autotools, meson, systemd supply the standard steps.

Layer: a directory with conf/layer.conf, listed in build/conf/bblayers.conf. Each layer has a priority that decides which version of a recipe or file wins. A typical stack:

poky/meta              core recipes (openembedded-core)
meta-openembedded/...  extra recipes
meta-vendor-bsp        SoC/board support (kernel, U-Boot, firmware)
meta-mycompany         your distro, images, applications, bbappends

.bbappend: for example linux-imx_%.bbappend in your layer adds a patch and a kernel config fragment to the vendor's kernel recipe:

FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
SRC_URI += "file://0001-add-my-panel.patch file://panel.cfg"

This keeps your changes out of the vendor layer, so you can upgrade it later.

Configuration levels

  • MACHINE (conf/machine/myboard.conf): CPU tune, kernel and bootloader providers, DTB names, serial console.
  • DISTRO (conf/distro/mydistro.conf): policy: init system, C library, DISTRO_FEATURES (wifi, bluetooth, systemd).
  • Image recipe (my-image.bb): what goes into the root filesystem (IMAGE_INSTALL).
  • local.conf: per-build settings (machine choice, download and sstate directories). Do not put product settings only here; they are not version controlled with the layers.

Useful commands: bitbake -c devshell virtual/kernel, bitbake -e recipe | grep ^SRC_URI, devtool modify, bitbake-layers show-appends.