How to Specify Which Kernel to Build with Bitbake/Yocto

How to specify which kernel to build with bitbake/yocto

Like E-rich wrote, the build system does only see my-kernel and linux-dummy as available providers for virtual/kernel. Thus, I'd guess that you'd actually want to build one of them?

The reason that linux-yocto isn't available is likely that your machine isn't in the COMPATIBLE_MACHINE regexp in linux-yocto_3.14.bb. Thus, if you want to use linux-yocto, you should bbappend that recipe in your own layer, and add your machine to COMPATIBLE_MACHINE. (You will also likely need to supply some more parameters, SRCREV, KBRANCH, etc.)

Kernel selection using yocto

Select which kernel to build in your machine configuration, see BSP manual and for example stackoverflow question

Basically, for selecting kernel you can add

PREFERRED_PROVIDER_virtual/kernel = "my-kernel-recipe"

To your mymachine.conf.

How to build in tree Linux kernel module in Yocto

If you want to add a kernel module in tree, you need to understand the Kbuild system,

Each kernel module is a component/feature and it is called a symbol

Kbuild is based on four components:

  • Configuration symbols (CONFIG_EXAMPLE)
  • Symbols container (Kconfig)
  • Makefile(s)
  • The kernel main configuration file (.config)

So, if you want to add your module to the kernel tree you need to:

  1. Copy the driver source file to the right location (You need to locate it based on your driver type (net, i2c, ...)).

  2. Add a symbol entry for the driver in the Kconfig/Makefile files of the same driver source code directory.

  3. Create a patch.

  4. Activate the driver symbol in the main Kernel configuration file (menuconfig / config fragement)

Example:

  1. Get the workding directory of your kernel recipe:
bitbake -e virtual/kernel | grep ^WORKDIR=

  1. Inside that directory you will find git which contains the kernel source, make your modifications there.

  2. Add the driver source file:

cp /home/xxx/custom_lkm.c drivers/gpu/drm/panel

  1. Add entry to Kconfig (drivers/gpu/panel/Kconfig)
...

config CUSTOM_LKM
tristate "Example driver"
depends on <YOU NEED TO FIND OUT WHAT IT DEPENDS ON>
depends on DRM <-------( This is just an example of a panel driver )
help
Say Y if you want to enable support for Example driver.

...

  1. Add entry to Makefile (drivers/gpu/panel/Makefile)
...
obj-$(CONFIG_CUSTOM_LKM) += custom_lkm.o
^ ^
| |
Driver symbol | |
in Kconfig---------- |
|
Driver source file name -------------
...

  1. Create a patch:

<workdir>/git$ git add drivers/gpu/panel/custom_lkm.c
<workdir>/git$ git add drivers/gpu/panel/Makefile
<workdir>/git$ git add drivers/gpu/panel/Kconfig
<workdir>/git$ git commit -m "Add the driver xxx in tree"
<workdir>/git$ git format-patch -1 -o /path/to/your/meta/recipes-kernel/linux/files

(This will create a patch: `add-the-driver-xxx-in-tree.patch`)

If your kernel is fetched from a local compressed file (no git), you then:

6.1 Init the kernel workdir as a git folder (git init)

6.2 Add and commit all the kernel (git add . && git commit -m "first init")

6.3 Add the driver files

6.4 Git add and commit and create the patch

Now, you got a patch that adds your driver in tree.


  1. Add the patch to the SRC_URI. If you have a bbappend for the kernel you use just :
SRC_URI_append = " file://add-the-driver-xxx-in-tree.patch"

You need just to create a configuration fragment to activate it.


  1. Run
bitbake virtual/kernel -c menuconfig

  1. Activate your module
  2. Create a configuration fragment
bitbake virtual/kernel -c diffconfig

This will generate a path to a fragment.cfg file. Just copy it along side the patch, and add it to SRC_URI.

IMPORTANT NOTES:

  • Make sure that your kernel can handle the .cfg files.
  • If you have a custom kernel hosted in custom git (that you have access to) you just commit the driver changes to it and just update SRCREV and keep only the fragment part.

How to compile linux-raspberrypi kernel in yocto?

Remove IMAGE_INSTALL_append = " linux-raspberrypi" and try adding to local.conf (or machine.conf) PREFERRED_PROVIDER_virtual/kernel = "linux-raspberrypi".



Related Topics



Leave a reply



Submit