Yocto Overrides Case 1 - clipped

Yocto: variable overrides tricks

Kernel Recipes conference in Paris
One of the best for Linux kernel topics 😉.
Recommended by Root Commit!

I discovered a intriguing phenomenon while preparing my How to test the latest mainline Linux kernel or bootloader presentation at OpenEmbedded Workshop 2025. It turned out there was something incomplete in my understanding of BitBake variable overrides.

Let’s take the example of a meta-mainline recipe from my Kernel Recipes:

SRC_URI = "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git;branch=linux-6.13.y;protocol=https"

Then, depending on the MACHINE setting, I want to use an override to add files or patches to SRC_URI

Let’s consider several attempts and the corresponding results, knowing that I have MACHINE = "genericarm64" in conf/local.conf.

First attempt

I first updated my recipe as follows:

SRC_URI = "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git;branch=linux-6.13.y;protocol=https"
SRC_URI:genericarm64 += "file://defconfig"

Then, I’m using the bitbake-getvar command to test the resulting value for the given recipe, and trace the assignments to the variable:

$ bitbake-getvar -r linux-mainline SRC_URI
...
#   set /home/mike/gitlab/rootcommit/meta-mainline/recipes-kernel/linux-mainline/linux-mainline.inc:7
#     "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git;branch=linux-6.13.y;protocol=https"
#   override[genericarm64]:append /home/mike/gitlab/rootcommit/meta-mainline/recipes-kernel/linux-mainline/linux-mainline_6.13.bb:4
#     "file://defconfig"
# pre-expansion value:
#   " file://defconfig"
Yocto override case 1

So, here we can see that the += operator applies to the initial value of SRC_URI:genericarm64, which is empty. This was not the intended effect.

Second attempt

This time, I’m trying the append operator instead of +=:

SRC_URI = "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git;branch=linux-6.13.y;protocol=https"
SRC_URI:genericarm64:append = " file://defconfig"

Unfortunately, the result is the same:

$ bitbake-getvar -r linux-mainline SRC_URI
...
# set /home/mike/gitlab/rootcommit/meta-mainline/recipes-kernel/linux-mainline/linux-mainline.inc:7
# "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git;branch=linux-6.13.y;protocol=https"
# override[genericarm64]:append /home/mike/gitlab/rootcommit/meta-mainline/recipes-kernel/linux-mainline/linux-mainline_6.13.bb:4
# "file://defconfig"
# pre-expansion value:
# " file://defconfig"
SRC_URI=" file://defconfig"
Yocto override case 2

So, here too we can see that the append operator applies to the initial value of SRC_URI:genericarm64, which is empty. This is still not the intended effect.

Final attempt

Now, let’s revert the append operator and make it specific to our override:

SRC_URI = "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git;branch=linux-6.13.y;protocol=https"
SRC_URI:append:genericarm64 = " file://defconfig"

At last, the result is the expected one:

$ bitbake-getvar -r linux-mainline SRC_URI
...
# set /home/mike/gitlab/rootcommit/meta-mainline/recipes-kernel/linux-mainline/linux-mainline.inc:7
# "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git;branch=linux-6.13.y;protocol=https"
# :append[genericarm64] /home/mike/gitlab/rootcommit/meta-mainline/recipes-kernel/linux-mainline/linux-mainline_6.13.bb:4
# " file://defconfig"
# pre-expansion value:
# "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git;branch=linux-6.13.y;protocol=https file://defconfig"
SRC_URI="git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git;branch=linux-6.13.y;protocol=https file://defconfig"
Yocto override case 3

At last this is the intended value! The override applies to SRC_URI:append, which means that the append operation is only performed when one of the overrides is genericarm64.

By the way, you can also use bitbake-getvar to check what available overrides were:

 ~/git/git.yoctoproject.org/poky/build   master  bitbake-getvar OVERRIDES                
...
# pre-expansion value:
# "${TARGET_OS}:${TRANSLATED_TARGET_ARCH}:pn-${PN}:layer-${FILE_LAYERNAME}:${MACHINEOVERRIDES}:${DISTROOVERRIDES}:${CLASSOVERRIDE}${LIBCOVERRIDE}:forcevariable"
OVERRIDES="linux:aarch64:pn-defaultpkgname:layer-config:aarch64:armv8a:genericarm64:poky:class-target:libc-glibc:forcevariable"

What to remember

Incorrect variable assignments with overrides can lead to tricky issues. You’ve been warned that they could be the cause of some problems.

At least when you’re trying to append something to a variable using an override, you should remember that the append statement should be placed before the override.

You will find many more tricks of this kind in our Yocto Project and OpenEmbedded training course.