2

I want to change Kernel configuration.

I have my own layer created and inside my layer I have a _%.bbappend file which directly targets the recipe linux-ti-staging.bb (link). This recipe builds my kernel:

ziga@host:~/yocto/$ oe-pkgdata-util lookup-recipe kernel
linux-ti-staging

The recipe is part of the official layer meta-ti (link).

My layer looks like this:

002--layers/meta--001/
├── conf
│   ├── distro
│   │   └── distro.conf
│   ├── layer.conf
│   └── machine
│       └── photovolt.conf
├── recipes-all
│   ├── application
│   │   └── application.bb
│   ├── image-003
│   │   └── image-003.bb
│   └── qtbase
│       └── qtbase_%.bbappend
├── recipes-bsp
│   └── u-boot
│       ├── u-boot-ti-staging
│       │   ├── 0001--add-fotovolt-dts-to-makefile.patch
│       │   └── photovolt.dts
│       └── u-boot-ti-staging_%.bbappend
└── recipes-kernel
    └── linux
        ├── linux-ti-staging
        │   ├── 0001--add-photovolt-dts-to-makefile.patch
        │   ├── 0002--disable-hdmi-node.patch
        │   ├── 0003--remove-conflicting-mmc-pinmuxing.patch
        │   ├── defconfig
        │   ├── fragment.cfg
        │   └── photovolt.dts
        └── linux-ti-staging_%.bbappend

I tried to follow the official Yocto reference (link) to configure my _%.bbappend file in one of the two ways described there.

1st - using configuration fragment

First, I tried to use a Linux kernel fragment. I executed:

ziga@host:~/yocto/$ bitbake -c menuconfig linux-ti-staging

made my configuration in kconfig/curses interface and saved the configuration under a default name .config. Then I created a Linux configuration fragment:

ziga@host:~/yocto/$ bitbake -c diffconfig linux-ti-staging

Fragment was created and it looks like this:

ziga@host:~/yocto/$ cat 003--builds/001--fotovolt/tmp/work/fotovolt-poky-linux-gnueabi/linux-ti-staging/5.10.65+gitAUTOINC+dcc6bedb2c-r22b/fragment.cfg
CONFIG_TOUCHSCREEN_ST1232=y

I copied this fragment to my layer as can be seen from the first code snippet. Now according to the official reference I also created the linux-ti-staging_%.bbappend (is detected by bitbake-layers) with this content:

FILESEXTRAPATHS:prepend := "${THISDIR}/linux-ti-staging:"
SRC_URI += "file://fragment.cfg"

I hoped that Yocto might treat a fragment.cfg file similar as patches, but it didn't do anything.


2nd - using an entire configuration

Secondly, I tried to use an entire Linux kernel configuration. I executed:

ziga@host:~/yocto/$ bitbake -c menuconfig linux-ti-staging

made my configuration in kconfig/curses interface and saved the configuration under a diferent name i.e. defconfig (7234 lines):

ziga@host:~/yocto/$ wc -l 003--builds/001--fotovolt/tmp/work/fotovolt-poky-linux-gnueabi/linux-ti-staging/5.10.65+gitAUTOINC+dcc6bedb2c-r22b/build/.config
7234

I copied this defconfig in my layer as can be seen from the first fragment of code. I then edited my linux-ti-staging_%.bbappend acccording to the official Yocto reference manual like this:

FILESEXTRAPATHS:prepend := "${THISDIR}/linux-ti-staging:"
SRC_URI += "file://defconfig"
KCONFIG_MODE = "alldefconfig"

But this also did not work.


I cleaned before building

In both cases I used two commands to cleanly build everything:

bitbake -c cleansstate virtual/kernel
bitbake image-003

But this does absolutely nothing to the kernel configuration. I can verify that no changes were applied by (a) logging in a running target, (b) extracting the /proc/config.gz somewhere and (c) read the obtained config file. File is identical as it was...

So, how can I permanently modify the kernel configuration?


Machine

My MACHINE is defined in photovolt.conf which basically reuses machine beaglebone (link) from official layer meta-ti. It looks like this:

#@TYPE: Machine
#@NAME: Photovolt machine - Beaglebone based machine
#@DESCRIPTION: Machine configuration for my machine

require conf/machine/beaglebone.conf

KERNEL_DEVICETREE = "photovolt.dtb"
UBOOT_MACHINE = "photovolt_defconfig"

Distribution

Distribution that I use is defined in a distro.conf like this:

require conf/distro/poky.conf

DISTRO = "distro"
DISTRO_NAME = "Distro (Yocto derived GNU/Linux distribution)"
DISTRO_VERSION = "1.0.0"
DISTRO_CODENAME = "Heart I"
MAINTAINER = "Me <me.me@gmail.com>"
  
DISTRO_FEATURES:append = " systemd"
DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
VIRTUAL-RUNTIME:init_manager = "systemd"
VIRTUAL-RUNTIME:initscripts = ""
   
PREFERRED_PROVIDER:virtual/libgbm = "mesa"

Recipe looks weird

Recipe linux-ti-stagging.bb (link) looks simple at a first glance, but it does some fishy things. It first requires a setup-defconfig.inc (link) which has a task do_configure(). Here it does some copy operations where it also uses a weird defconfig file (link). Maybe this is somehow connected to my problems...

71GA
  • 1,132
  • 6
  • 36
  • 69

2 Answers2

2

It is obvious in setup-defconfig.inc that they handle config fragments in do_configure with this part:

# Fourth, handle config fragments specified in the recipe
    # The assumption is that the config fragment will be specified with the absolute path.
    # E.g. ${WORKDIR}/config1.cfg or ${S}/config2.cfg
    if [ -n "${KERNEL_CONFIG_FRAGMENTS}" ]
    then
        for f in ${KERNEL_CONFIG_FRAGMENTS}
        do
            # Check if the config fragment is available
            if [ ! -e "$f" ]
            then
                echo "Could not find kernel config fragment $f"
                exit 1
            fi
        done
    fi

    # Now that all the fragments are located merge them
    if [ -n "${KERNEL_CONFIG_FRAGMENTS}" -o -n "$configfrags" ]
    then
        ( cd ${WORKDIR} && ${S}/scripts/kconfig/merge_config.sh -m -r -O ${B} ${B}/.config $configfrags ${KERNEL_CONFIG_FRAGMENTS} 1>&2 )
        yes '' | oe_runmake -C ${S} O=${B} oldconfig
    fi

So, here is the explanation of what it does:

  • It checks if the variable KERNEL_CONFIG_FRAGMENTS has a content
  • If yes, it checks if its content (files) exist
  • Merge all config fragments of and KERNEL_CONFIG_FRAGMENTS and configfrags into ${B}/.config which is the final configuration that will be built

configfrags just used to hold extracted fragments from other defconfig file. It does not matter for your case.

So, here what you can do in linux-ti-staging_%.bbappend:

FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
SRC_URI += "file://fragment.cfg"
KERNEL_CONFIG_FRAGMENTS += "${WORKDIR}/fragment.cfg"

Since they are checking directly on the content of KERNEL_CONFIG_FRAGMENTS it will fail if you set it without ${WORKDIR}.

${WORKDIR} is where fragment.cfg will be unpacked.

So, based on what they are using on do_configure, the test on KERNEL_CONFIG_FRAGMENTS should pass because it will have content, and it will merge its config into the configuration file ${B}/.config.

To check that, after do_configure just check the content of ${B}/.config for your new fragment content.

ALERT YOU NEED TO LEFT THE FIRST LINE IN THE FRAGMENT FILE AS EMPTY LINE. BECAUSE merge_config.sh WILL SKIP IT.

So, your fragment will look like the following:


CONFIG_TOUCHSCREEN_ST1232=y

If that did not work, try to add this custom function to apply your fragment.cfg into the final configuration file:

  • linux-ti-staging_%.bbappend:
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
SRC_URI += "file://fragment.cfg"

CUSTOM_FRAGMENTS += "fragment.cfg"

do_merge_fragment(){
   for f in ${CUSTOM_FRAGMENTS}; do
       if [ -f "${WORKDIR}/${f}" ]; then
           ${S}/scripts/kconfig/merge_config.sh -m ${B}/.config ${WORKDIR}/${f}
       fi
   done
}

addtask merge_fragment after do_configure before do_compile

With that you will make sure that the fragment will be applied.

Talel BELHADJSALEM
  • 3,199
  • 1
  • 10
  • 30
1

Your directory structure should be like this

meta-something
└── recipes-kernel
    └── linux
        ├── files
        │   └── defconfig
        └── linux-ti-staging.bbappend

And linux-ti-staging.bbappend

FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
SRC_URI += "file://defconfig"
Marco
  • 79
  • 1
  • 9
  • I did like you said. It is written in the reference [here](http://I%20read%20the%20recipe%20(%5Blink%5D%5B1%5D),%20but%20I%20don%27t%20understand,%20how%20I%20can%20modify%20it%20in%20order%20to%20use%20my%20Kernel%20configuration%20file.%20The%20recipe%20uses:%20%20%20%20%20%20require%20recipes-kernel/linux/setup-defconfig.inc%20%20that%20requires%20the%20%60setup-defconfig.inc%60%20(%5Blink%5D%5B3%5D).%20This%20file%20is%20actually%20responsible%20for%20creating%20the%20Linux%20configuration!%20But%20it%20is%20a%20bit%20complex%20and%20I%20am%20not%20a%20Python%20expert.). But fails! – 71GA Feb 14 '22 at 16:53
  • I tried with an entire configuration and configuration fragment... Just like official reference says. But in both cases I was unsuccessfull. I suspect that recipe for `linux-ti-staging` is doing something fishy. It `requires` this `.inc` file ([link](https://github.com/YoeDistro/meta-ti/blob/master/recipes-kernel/linux/setup-defconfig.inc)) and then inside the `do_configure()` uses another file ([link](https://github.com/YoeDistro/meta-ti/blob/master/recipes-kernel/linux/linux-ti-staging-5.10/defconfig)). Somehow this manages completely ignore anything I do. – 71GA Feb 14 '22 at 16:58
  • I read [here](https://yocto.yoctoproject.narkive.com/OePFc5zo/kernel-config-fragments-are-not-applied#post2) that if kernel recipe inherits directly from the class `kernel.bblass`, kernel configuration fragments will not work. This is what recipe `linux-ti-staging` also does. So what can be done in this case? – 71GA Feb 14 '22 at 21:38
  • Also [this](https://stackoverflow.com/questions/48441494/kbuild-defconfig-kmachine-defconfig-file-does-not-work-as-expected) is interesting... – 71GA Feb 14 '22 at 23:09
  • I also added details about the machine & distribution. – 71GA Feb 15 '22 at 11:18