How to use an own device tree and modified kernel config in Yocto?
Asked Answered
P

3

16

I am working to build an own "embeeded linux" with yocto. It is based on the SAMA5D3x-MB + SAMA5D3x-CM(RONETIX) with the SAMA5D35. I have two questions:

1.) changing the device tree

I build an image based on: MACHINE ??= "sama5d3xek"

After the generating process I found two device tree files for the 5D35 in the deploy dir:

  • zImage--4.1+git0+19291d7be4-r0-sama5d35ek-.dtb
  • zImage--4.1+git0+19291d7be4-r0-sama5d35ek-revc-.dtb

Because the mainboard is revD I am using zImage--4.1+git0+19291d7be4-r0-sama5d35ek-.dtb.

In this file only can0 and i2c1 are defined.

I like to use can1 and i2c0 as well. For that I think I need to create a own dts file and include it into the kernel build process.

So far I put the dts file at my meta-test recipe. Ideas how to copy/patch it into the kernel?

2.) changing the kernel config

I checked the kernel with bitbake virtual/kernel -c menuconfig

because I am not using the SAMA5D2 etc. and only the console I deactivated these kernel configs. I saved the new ".config" to "my.config" into the my-recipe dir. I have a similar question like in 1 - How to patch/copy it into the kernel?

I am new to yocto and to kernel hacking. Any idea how to do it?

Palmore answered 20/5, 2016 at 13:20 Comment(0)
S
43

If you're on a recent Yocto project release, you can make use of recipetool to do most of the legwork on this. You have two options, you can use the existing recipetool commands and a small amount of manual work, or you can use the recipetool plugin in meta-mentor that provides a few kernel-specific commands to do this for you.

Layer setup

First, you'll want to have a layer to store your changes. If you've already created a layer, you can use that, otherwise we can create one and add it to our configuration:

$ yocto-layer create local 1
$ bitbake-layers add-layer meta-local

Option one: Using the recipetool plugin from meta-mentor

Setup

First, clone meta-mentor:

$ git clone https://github.com/MentorEmbedded/meta-mentor

Next, either add meta-mel to your configuration:

$ bitbake-layers add-layer path/to/meta-mentor/meta-mel

Or copy meta-mentor/meta-mel/lib into your own layer:

$ cp -a path/to/meta-mentor/meta-mel/lib meta-local/

Device tree

$ recipetool kernel_add_dts meta-local /path/to/your.dts

Kernel configuration

$ recipetool kernel_add_fragments meta-local /path/to/your.cfg

Or:

$ recipetool kernel_set_defconfig meta-local /path/to/the/defconfig

Option two: Manual

In the below section, clearly in your case, your-machine-name should be sama5d3xek. The '-m your-machine-name' passed to the recipetool commands below makes the changes in the recipe specific to your machine, rather than affecting any machine which uses that recipe. If you know that recipe is only used for your machine, then you could drop that, but it's safest to keep it, as some BSP layers use the same kernel recipe for multiple machines. For example, linux-yocto is used for many.

Device tree

Then, assuming you have a .dts handy you want to use:

$ recipetool appendsrcfile -wm your-machine-name path/to/meta-local virtual/kernel /path/to/your.dts 'arch/${ARCH}/boot/dts/your.dts'

This will create a .bbappend in meta-local and add the .dts to SRC_URI, placing it in the appropriate path in the kernel source tree. The next step is to edit the append it created and add the .dtb for your .dts to the KERNEL_DEVICETREE variable, i.e.:

KERNEL_DEVICETREE += "your.dtb"

If the kernel recipe includes recipes-kernel/linux/linux-dtb.inc, any .dtb files in KERNEL_DEVICETREE will be created from their .dts files by using the kernel's buildsystem. Some kernels do not include linux-dtb.inc, in which case you can do so yourself in the append:

require recipes-kernel/linux/linux-dtb.inc

Kernel configuration

The kernel configuration is slightly more complex, just because how the configuration is done varies slightly between kernel recipes. Some kernel recipes support configuration fragments (which are just a text file with part of a defconfig/.config), whereas others you'd have to override the configuration entirely. The 'linux-yocto' recipe can handle and use fragments, as can a few others.

To see what kernel recipe you're using (the top filename will be the one used):

$ bitbake -e virtual/kernel | grep '^FILE='

If you want to use configuration fragments, you can either manually create a fragment, or generate one:

$ bitbake -c menuconfig virtual/kernel
$ bitbake -c diffconfig virtual/kernel

The 'diffconfig' task will create a fragment with your changes from the menuconfig and print the path to it.

Then you can add it to the kernel (though again, only certain recipes will use it):

$ recipetool appendsrcfile -wWm your-machine-name meta-local virtual/kernel /path/to/your.cfg

To override the entire config, most recipes will obey and use a 'defconfig' source file, so:

$ recipetool appendsrcfile -Wm your-machine-name meta-local virtual/kernel /path/to/the/defconfig

Note: The defconfig is not generated automatic. Replace defconfig with the result of menuconfig('.config').

Southdown answered 21/5, 2016 at 18:16 Comment(8)
I tried the 2nd option. It fails. My local machine is "sama5d3xek". I substitute meta-local with that. recipetool failed to find the layer "virtual/kernel". btw bitbake find the "virtual/kernel" target. Any Idea?Palmore
Ah! My apologies, I forgot that the -m argument takes the machine name, to make the change machine specific. That's a bit odd, as I'd expect it to just default to the current machine rather than requiring it be specified. If you add the machine name, it should work as expected. I.e. recipetool appendsrcfile -Wm sama5d3xek meta-local virtual/kernel /path/to/the/defconfig. I'll update the answer to that effect. Thanks.Southdown
I have still a problem with the kernel config. bitbake -c menuconfig virtual/kernel -> is generating a new ".config". diffconfig is creating a file. I named it myConfg.cfg. The new build of the kernel is not taking it to account. Athough "defconfig" is arround 7kB and ".config" 79kB. A idea how make a valid configuration?Palmore
As as mentioned in the answer, the diffconfig task generates a configuration fragment, not a defconfig, and not all kernel recipes obey them. To use myConfig.cfg, follow the instructions for use of a fragment, to use the defconfig, follow the instructions for use of a defconfig. You haven't said whether the kernel build isn't taking into account the fragment, or the defconfig. Which did you attempt to use?Southdown
Actually I try the fragment.cfg to be included into the kernel cfg. When compiling the linux-AT91 kernel I got the message: WARNING: poky/meta-atmel/recipes-kernel/linux/linux-at91_3.10.bb: Unable to get checksum for linux-at91 SRC_URI entry defconfig: file could not be found - I am useing: the menuconfig + diffconfig like you described and save the files with the names suggested from the tools AND I use the 4.1. kernel; Maybe the generated append does not touch the "right" linux. The Atmel layer provides: 3.6, 3.10, 3.18 & 4.1Palmore
I think the defconfig is not updated. The ".config" and "fragment.cfg" generation is fine. When the "defconfig" is generated or how I can trigger its generation?Palmore
To set defconfig in a bbappend from another layer I needed another method. You must set THISDIR early. Otherwise thisdir points to the recipe layer at runtime. The file://defconfig-cyphre didn't find the file at runtime either, even though the FILEEXTRAPATH was correct, so I had to reference the file explicitly. KERNEL_DEFCONFIG := "${THISDIR}/${PN}/defconfig-cyphre" do_configure_prepend_qoriq () { cp ${KERNEL_DEFCONFIG} ${WORKDIR}/defconfig }Gaeta
It's important to note that the .cfg extension is required for configuration fragments. I think this is defined in the poky/meta/classes/kernel-yocto.bbclass file. Took me a little bit to realize I couldn't use the .config extension.Polo
O
3

The devtool can be very handy if you want to generate patches for the linux-yocto kernel. Other kernel might not support devtool.

## create kernel source patch
devtool modify virtual/kernel
# make some changes
cd ~/poky_sdk/workspace/sources/linux-yocto
vi init/calibrate.c
# test before patch
bitbake -C compile virtual/kernel
# create patch
git add .
git commit -m 'some fix'
devtool update-recipe -a ~/meta-mylayer/  linux-yocto
# clean the source
rm -rf workspace/sources/linux-yocto/

see devtool for details

Octagon answered 21/5, 2021 at 4:7 Comment(0)
R
1

Related to this question, for educational purposes I tried to add a device tree to an x86 architecture (kernel 5.2.20). To enable the device tree compiler, the following additions to the configuration were needed :

CONFIG_COMPILE_TEST=y    
CONFIG_OF=y    
CONFIG_OF_ALL_DTBS=y

Furthermore, to enable device tree support at runtime, this was additionally needed :

CONFIG_OF_UNITTEST=y    

A convenient place to check if your kernel configs are merged without problems is file
kernel-source/.kernel-meta/cfg/merge_config_build.log

Rescind answered 27/11, 2020 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.