How to use dynamic layers in Yocto

It is common for a recipe in one layer (say your meta-mycompany layer) to modify a recipe in another layer. This allows you to change configuration options, add patches, etc. BSP layers are often prime candidates for appends. However, if the BSP layer is not present, then a bbappend will cause a bitbake error.

The bitbake dynamic layer feature allows you to conditionally add recipes if a layer is present. Here is how we use it in the Yoe Distribution:

# We have a conf and classes directory, append to BBPATH
BBPATH .= ":${LAYERDIR}"

# We have a recipes directory, add to BBFILES
BBFILES += "${LAYERDIR}/recipes*/*/*.bb ${LAYERDIR}/recipes*/*/*.bbappend"

BBFILE_COLLECTIONS += "meta-yoe"
BBFILE_PATTERN_meta-yoe := "^${LAYERDIR}/"
BBFILE_PRIORITY_meta-yoe = "99"
LAYERSERIES_COMPAT_meta-yoe = "kirkstone"
LAYERDEPENDS_meta-yoe = "core elm-binary-layer"

BBFILES_DYNAMIC += " \
    qt5-layer:${LAYERDIR}/dynamic-layers/qt5-layer/*/*/*.bb \
    qt5-layer:${LAYERDIR}/dynamic-layers/qt5-layer/*/*/*.bbappend \
    meta-96boards:${LAYERDIR}/dynamic-layers/meta-96boards/*/*/*.bb \
    meta-96boards:${LAYERDIR}/dynamic-layers/meta-96boards/*/*/*.bbappend \
    meta-ti-bsp:${LAYERDIR}/dynamic-layers/meta-ti/*/*/*.bb \
    meta-ti-bsp:${LAYERDIR}/dynamic-layers/meta-ti/*/*/*.bbappend \
    raspberrypi:${LAYERDIR}/dynamic-layers/raspberrypi/*/*/*.bb \
    raspberrypi:${LAYERDIR}/dynamic-layers/raspberrypi/*/*/*.bbappend \
    swupdate:${LAYERDIR}/dynamic-layers/swupdate/*/*/*.bb \
    swupdate:${LAYERDIR}/dynamic-layers/swupdate/*/*/*.bbappend \
    webkit:${LAYERDIR}/dynamic-layers/webkit/*/*/*.bb \
    webkit:${LAYERDIR}/dynamic-layers/webkit/*/*/*.bbappend \
"

When using Yoe, you can remove a BSP layer (ex: sources/raspberrypi) and Yoe will continue to build just fine. For product builds, it sometimes makes sense to remove extraneous layers to speed up bitbake parsing times and streamline builds.

Dynamic layers also makes it easier for stand-alone layers to be used in more situations without as many hard dependencies. Anytime you can reduce dependencies in your software builds, you are simplifying your build, which reduces long term maintenance costs.

For more information on dynamic layers, see reference manual.

well written !! I think we should remove meta-qt4 from this since its jaded :slight_smile:

agreed, qt4 sees little use any more

Our posts here are being used …

Thanks for this write up, was super helpful for me today!

Possibly I’m doing it wrong, but it seems that using BBMASK to mask out an entire layer still causes that layer to show up as existing from a BBFILES_DYNAMIC point of view. So even when a layer is entirely masked out by BBMASK, BBFILES_DYNAMIC still puts the corresponding dynamic layer into play for bitbake.

This makes it slightly harder to carry multiple different machine configs within a single product-level BSP layer and use a common bblayers.conf for building for all targets if some of those machines depend on upstream vendor-provided BSP layers for core SOC support. Some vendor-provided BSP layers for SOC support seem better than others about making sure that they constrain any .bbappends to only apply when their SOC or machine is being built for.

@bradfa cool, such posts are good to start the day :slight_smile:
I think you have an interesting point because BBMASKS does not interact with BBFILES_DYNAMIC, I think there is a valid point why it should as you mentioned.

Perhaps good to file an enhancement request on yocto bugzilla

1 Like

Good to know I’m not crazy :slight_smile:

I’ll try to create a simple proof of concept to show my BBMASK and BBFILES_DYNAMIC issue and submit something to the bugzilla soon.