Module 4 · Lesson 108 of 156

Appending to the kernel recipe

Extend linux-yocto from your own layer with a configuration fragment or source patch, select a kernel feature, and verify the resulting configuration.

  • Beginner to advanced
  • 8 min read
  • 30 min lab
What you will need

Ubuntu 24.04 in WSL2 or a VM, an initialized Yocto build environment, and a build configuration that selects linux-yocto for virtual/kernel

Your place in the module
By the end you can 4 objectives
  • Match a linux-yocto recipe with a version-specific or wildcard bbappend.
  • Resolve layer-local configuration fragments and patches through FILESEXTRAPATHS and SRC_URI.
  • Select a reusable kernel feature with KERNEL_FEATURES.
  • Verify a requested Kconfig setting in the generated kernel configuration.
Video coming soonAppending to the kernel recipe
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from Layers and creating one with bitbake-layers
  • Each build selects its active layers through BBLAYERS in conf/bblayers.conf.
  • BBPATH provides a search path for configuration and class files, while BBFILES supplies patterns for recipe and append files.
  • LAYERSERIES_COMPAT declares the OpenEmbedded Core release series a layer supports.
01

Match the kernel recipe from your layer

3 min read

The kernel is just another recipe, and a bbappend is how you change it without copying it. This lesson answers %.bbappend and FILESEXTRAPATHS, config fragments and KERNEL_FEATURES, and linux-yocto metadata.

Suppose you need the target kernel to carry a copy of its build configuration so you can recover the exact settings later. Linux provides the IKCONFIG option for this. The practical question is where to request that setting so the next build from the same layer includes it. Kconfig derives the final configuration from the inputs and the dependencies between symbols. Keep the request in a fragment under version control so you can review it and regenerate the configuration. Kernel configuration targets, Kconfig symbol dependencies.

A can live in a different layer from the recipe it extends. Both layers must be enabled and their files must be included by the layers' file patterns. An exact append uses the same filename stem as its recipe, including the version. For a recipe named linux-yocto_6.6.bb, the exact append is linux-yocto_6.6.bbappend. A linux-yocto_%.bbappend can match multiple versioned linux-yocto recipes. The % is a wildcard in the append filename. BitBake compares filenames here, so a version reported by the running kernel is irrelevant to the match.

A wildcard is convenient for a configuration fragment you intend to carry across kernel versions. Verify its settings again when the selected version changes because a symbol or one of its dependencies can change. A version-specific append is useful when it carries a source patch tied to one recipe version. When you change versions, the exact append makes that dependency visible in the filename.

Run these commands from your initialized Yocto build directory:

bash
bitbake -e virtual/kernel | grep -E '^(PN|FILE)="'
bitbake-layers show-appends

The first command shows which recipe provides virtual/kernel in the current build configuration. PN identifies the recipe and FILE gives its path. Use this example when PN is linux-yocto. The second command lets you check which recipes have matching appends once you add yours. An append can appear there even when its recipe is inactive for virtual/kernel, so check both. The Ubuntu host's kernel version has no bearing on which recipe BitBake selects for the target.

In a real run on Poky scarthgap with the append and fragment of this section in a layer created by bitbake-layers create-layer, bitbake-layers show-appends listed two files under linux-yocto_6.6.bb: Poky's own meta-yocto-bsp/recipes-kernel/linux/linux-yocto_6.6.bbappend and meta-course/recipes-kernel/linux/linux-yocto_%.bbappend. So several appends can extend one recipe. bitbake -e virtual/kernel printed PN="linux-yocto", FILE=".../meta/recipes-kernel/linux/linux-yocto_6.6.bb" and a SRC_URI that now ended with file://course-ikconfig.cfg, after two git:// entries (the kernel source, and the yocto-kernel-cache metadata repository). The layer path prefix in your output will differ.

From kernel provider to matching appendSelectkernelprovidervirtual/kernelIdentifyrecipe filelinux-yoctorecipeMatchappendfilenamelinux-yocto_%.bbappendApplyappendmetadataSelectkernelprovidervirtual/kernelIdentifyrecipe filelinux-yoctorecipeMatchappendfilenamelinux-yocto_%.bbappendApplyappendmetadata
Check both the recipe selected for virtual/kernel and the append matched to its filename
02

Add the fragment and verify the configuration

3 min read

In your layer, create recipes-kernel/linux/linux-yocto_%.bbappend. Create a files directory beside it and put course-ikconfig.cfg in that directory. The example uses a distinctive filename because file:// lookup can search directories supplied by several layers. Keep the append in the layer's recipe directory and the local input under files so you can locate both when reviewing the change.

Write these two lines in the append:

bitbake
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
SRC_URI:append = " file://course-ikconfig.cfg"

FILESEXTRAPATHS contributes directories to FILESPATH, the search path used to resolve a local file:// entry. THISDIR gives the directory containing the append when the assignment is parsed. Immediate expansion with := captures that directory at the assignment. The trailing colon separates the new directory from entries that follow it. SRC_URI:append adds the fragment to the recipe's existing inputs. The leading space matters because :append inserts the string as written, and SRC_URI is a space-separated list.

Write the Kconfig request in files/course-ikconfig.cfg:

text
CONFIG_IKCONFIG=y

This requests built-in support for embedding the configuration in the target kernel. The kernel's Kconfig syntax also expresses a disabled option with a line such as # CONFIG_IKCONFIG is not set. For this example, keep the fragment focused on the single setting. You can capture the original value before adding the append so you know whether the fragment should change the resulting configuration or confirm an existing setting.

For linux-yocto, the kernel configuration tasks process a .cfg listed in SRC_URI as a configuration fragment (meta/classes-recipe/kernel-yocto.bbclass collects the .scc and .cfg files of SRC_URI, and the Yocto Kernel Development Manual shows the same method). The manual uses FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"; this lesson uses a files directory instead, which works the same way. The build combines the request with its existing configuration inputs and uses Kconfig to resolve the result. A line in the fragment expresses the requested value. The generated .config tells you the effective value. This distinction matters when a missing dependency constrains a setting or another fragment requests a different value.

From local fragment to generated configurationDeclarelocalfragmentSRC_URIResolvefile pathFILESPATHMergeconfiginputsResolvesymbolvaluesKconfigInspect.configKernelbuilddirectoryDeclarelocalfragmentSRC_URIResolvefile pathFILESPATHMergeconfiginputsResolvesymbolvaluesKconfigInspect.configKernelbuilddirectory
The append declares the fragment, and the kernel configuration tasks produce the effective settings

Run the configuration task and ask BitBake for the recipe's build directory. The first run fetches the kernel source from a git server, a large download that this review did not run, so the final .config check below is shown from the documentation and the class source only:

bash
bitbake -c configure virtual/kernel
bitbake -e virtual/kernel | grep '^B="'

Use the expanded B path printed by BitBake in the following command:

bash
grep -x 'CONFIG_IKCONFIG=y' '/replace/with/the/B/path/.config'

grep -x checks the whole line. A match verifies that the configuration used for this target build has the setting enabled. This check needs neither a complete image build nor a booted board. CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC are separate settings. This fragment requests an embedded configuration. Exposing it through /proc/config.gz requires CONFIG_IKCONFIG_PROC as well.

If do_configure succeeds but the setting is missing, confirm the selected provider and the append match, then inspect SRC_URI in bitbake -e virtual/kernel for the fragment. If those agree, run bitbake -c kernel_configcheck virtual/kernel to audit the generated configuration. Inspect its messages and check whether the symbol exists in the selected source and whether its Kconfig dependencies are satisfied. If the build reports that it cannot find the file, check the spelling of the file:// entry and the location of the directory in FILESEXTRAPATHS.

03

Add a source patch or select a kernel feature

3 min read

A fragment changes kernel build settings. When you need to edit the kernel source, supply a patch prepared against the source revision selected by the recipe. For example, if you have a patch that corrects a driver error message, place it in files/0001-driver-correct-error-message.patch and add its URI to the existing assignment:

bitbake
SRC_URI:append = " file://course-ikconfig.cfg \
                   file://0001-driver-correct-error-message.patch \
                 "

Use this assignment in place of the single-fragment assignment. The same FILESEXTRAPATHS entry locates both files. The recipe's do_patch task applies the .patch file to the source tree. The kernel configuration tasks use the .cfg as a settings input. With the patch present, bitbake -c patch virtual/kernel checks whether it applies to the selected source. A patch that applies cleanly still needs a build and tests appropriate to the source change. The configuration exercise needs only the fragment.

Use KERNEL_FEATURES when the kernel metadata already defines a reusable feature that you want to enable. Add the feature's relative .scc path to the existing list. For example, if the metadata used by your recipe provides features/netfilter/netfilter.scc, select it this way:

bitbake
KERNEL_FEATURES:append = " features/netfilter/netfilter.scc"

Check the metadata used by the selected recipe before adding a feature path. The feature's location and availability depend on that metadata. A plain .cfg declared in SRC_URI can be processed on its own. It needs no entry in KERNEL_FEATURES.

Going deeperExplore the mechanism

The .scc files in linux-yocto metadata describe how to assemble configuration fragments, patches and other .scc descriptions. For example, a feature descriptor named course-ikconfig.scc could contain these lines alongside its course-ikconfig.cfg:

text
define KFEATURE_DESCRIPTION "Embed the kernel build configuration"
kconf non-hardware course-ikconfig.cfg

The kconf directive refers to the fragment, and non-hardware classifies it as configuration policy. The CONFIG_IKCONFIG=y assignment still belongs in the .cfg. A feature descriptor can also use include to reuse another .scc description and patch to declare a source patch. When a feature is available in the kernel metadata, its relative .scc path is the name you select in KERNEL_FEATURES.

A BSP .scc describes the kernel metadata for a board or machine and kernel type. It can include configuration and other descriptions that establish the build for that target. A reusable feature .scc describes a capability that several targets can select. Use a plain fragment for a small layer-local request such as CONFIG_IKCONFIG=y. A named feature is useful when related fragments and patches are maintained and selected together.

Three inputs to linux-yoctoConfigfragmentSource patchNamed featureFile.cfg.patch.sccRecipe variableSRC_URISRC_URIKERNEL_FEATURESPurposeRequestsymbol valuesEdit kernelsourceSelectgroupedmetadata
The append can declare a fragment or patch directly and select a named feature from kernel metadata

When reviewing your result, ask what each piece of evidence proves. The append listing establishes that the metadata matched. A successful patch task establishes that the patch applied. The generated configuration establishes the final symbol value. In the next lesson, PACKAGECONFIG and package splitting, you will see how a recipe selects optional build features and assigns installed files to output packages.

Key takeaways

  • BitBake applies a bbappend to matching recipe filenames in enabled layers.
  • FILESEXTRAPATHS extends file lookup, and SRC_URI declares the local inputs the recipe uses.
  • KERNEL_FEATURES selects named features from linux-yocto metadata.
  • The generated .config records the settings that survived Kconfig dependency resolution.
Reflect
  1. Explain to a colleague, in two sentences: match a linux-yocto recipe with a version-specific or wildcard bbappend.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?
On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

References and further reading

Find your next step

↑ ↓ to move · Enter to open · Esc to close