Skip to content
systemcoding.dev
Embedded Linux

Add a kernel config fragment with a .cfg file in SRC_URI

Add kernel options to a Yocto kernel with a .cfg fragment listed in SRC_URI of a linux-yocto bbappend on Scarthgap, without replacing the defconfig.

1 min read
Summarize in AI

A fragment is a small file of CONFIG_ lines that the kernel recipe merges into the configuration. It leaves the rest of the config alone, which is what you want when a layer must stay maintainable across kernel updates.

Text
CONFIG_I2C_CHARDEV=y
CONFIG_SPI_SPIDEV=m
Text
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
SRC_URI += "file://i2c-spi.cfg"

Save the first block as files/i2c-spi.cfg and the second as linux-yocto_%.bbappend in your layer. The kernel-yocto class notices the .cfg suffix on a SRC_URI entry and passes it to the merge step, so you do not write a patch.

Shell
bitbake -c menuconfig virtual/kernel
grep -E 'I2C_CHARDEV|SPI_SPIDEV' tmp/work/*/linux-yocto/*/build/.config
Text
CONFIG_I2C_CHARDEV=y
CONFIG_SPI_SPIDEV=m

A fragment can only set what the final dependency resolution allows. If an option depends on something that is off, the line is silently dropped, and the next snippet shows how to catch that. See the Yocto kernel development manual.

Also inKernels
Share

More snippets

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.