← All posts

How to define a Yocto layer: from bitbake-layers create-layer to layer.conf

Grow through practice

No need to finish reading — test now

A Yocto layer is a collection of recipes/classes/configuration recognized through conf/layer.conf. Putting files in a directory does not make it a layer; without layer.conf, BitBake will not treat it as one.

1. Create a layer

The official tool generates a skeleton:

bitbake-layers create-layer ../meta-demo

Typical layout:

meta-demo/
├── conf/layer.conf
├── COPYING.MIT
├── README
├── recipes-example/
│   └── example/
│       └── example_0.1.bb
└── ...

create-layer is just the starting point; layer.conf makes it a layer.

2. layer.conf line by line

BBPATH .= ":${LAYERDIR}"

BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
            ${LAYERDIR}/recipes-*/*/*.bbappend"

BBFILE_COLLECTIONS += "meta-demo"
BBFILE_PATTERN_meta-demo = "^${LAYERDIR}/"
BBFILE_PRIORITY_meta-demo = "6"

LAYERSERIES_COMPAT_meta-demo = "scarthgap"
LAYERDEPENDS_meta-demo = "core"
LAYERVERSION_meta-demo = "1"
  • BBPATH: adds the layer to BitBake's search path.
  • BBFILES: declares recipe/bbappend matching patterns.
  • BBFILE_COLLECTIONS: names the layer collection.
  • BBFILE_PATTERN_<collection>: scopes files under this layer.
  • BBFILE_PRIORITY_<collection>: layer priority, affecting recipe selection and bbappend order.
  • LAYERSERIES_COMPAT_<collection>: supported Yocto series, e.g. scarthgap.
  • LAYERDEPENDS_<collection>: dependency on other layer collections.
  • LAYERVERSION_<collection>: your layer's own version.

Do not solve recipe conflicts by raising priority. Avoid duplicate recipes; use a .bbappend when overriding.

3. Add the layer to the build

bitbake-layers add-layer ../meta-demo
bitbake-layers show-layers

add-layer updates conf/bblayers.conf and BBLAYERS. You can also write:

BBLAYERS += "${TOPDIR}/../meta-demo"

Using bitbake-layers avoids path/escaping mistakes.

4. Where recipes go

Common conventions:

recipes-core/          base components
recipes-kernel/        kernel/modules
recipes-bsp/           BSP, bootloader
recipes-connectivity/  networking
recipes-graphics/      graphics
recipes-example/       examples

Paths are not mandatory as long as BBFILES matches them; conventions improve maintainability.

A .bbappend must match the recipe PN/PV:

recipes-core/busybox/busybox_1.36.%.bbappend

% is a version wildcard; check the exact BitBake version syntax.

5. Dependencies, priority, compatibility

  • Dependencies: LAYERDEPENDS_meta-demo = "core" declares a relationship; bblayers.conf still needs the layer present.
  • Priority: higher numbers win recipe selection and affect bbappend expansion; do not use it to hide duplicate recipes.
  • Compatibility: if LAYERSERIES_COMPAT does not match, the layer may be rejected. Forward-porting must update it and be tested.
  • Version: LAYERVERSION is your layer version, not the Yocto release.

6. Verify

bitbake-layers show-layers
bitbake-layers show-recipes | grep <recipe>
bitbake -e <recipe> | grep -E 'FILE|LAYERDIR|BBFILE_PRIORITY'

show-layers confirms recognition; -e shows the final recipe file, variables and layer origin.

7. Common mistakes

  1. Directory without layer.conf

BitBake will not treat it as a layer.

  1. Wrong BBFILES path

Files exist but no recipe appears; inspect BBFILES and show-recipes.

  1. Mismatched LAYERSERIES_COMPAT

After a Yocto upgrade, the layer is rejected until updated.

  1. Two layers defining the same recipe

Priority decides the winner, but maintenance gets painful; use bbappend.

  1. Editing poky directly

Every upgrade conflicts; a custom layer + bbappend is sustainable.

Verification

  • ✅ Commands: bitbake-layers create-layer/add-layer/show-layers.
  • ✅ Variables: BBPATH, BBFILES, BBFILE_COLLECTIONS/PATTERN/PRIORITY, LAYERSERIES_COMPAT, LAYERDEPENDS.
  • ⚠️ No full Yocto build was run locally; semantics follow official docs and need validation in the target SDK.
  • ❓ Not covered: exhaustive priority-conflict tests and cross-release forward-porting.

One sentence

A layer is not a directory; it is a metadata collection declared by layer.conf. Create with create-layer, add with add-layer, override with bbappend.

Practice this page: 3 layer questions →


Series: Yocto Build System Notes Related: What is KAS? · Practice this page (3 questions) · OpenWrt + Yocto hybrid

Practice

Found this useful?

I write about AI agents × embedded / edge AI. Subscribe, or email me a concrete problem.

Guestbook →Subscribe (RSS)Support

Comments 0

No comments yet — be the first!

No login required; name is optional.