Using populate_sdk to include kernel headers
Asked Answered
W

3

13

How do I include the linux kernel headers as part of the SDK package in Yocto?

I'm using Yocto 1.8 (fido) in an embedded project and want to do out-of-tree kernel module development. Currently, I can build my kernel modules (apart from bitbake) by pointing my $KERNEL_PATH to the poky/build/tmp/work-shared/<machine>/kernel-source/ directory when I run make. I don't want to do this in the long term, however, since others need to easily build the modules without installing and building a full image from bitbake.

I can generate an SDK using bitbake myimage -c populate_sdk. However, this doesn't include the kernel headers (all I ever see is sysroots/<mach>/usr/include/linux). How do I cause the kernel headers to be included in the SDK package? Also, I don't want the kernel headers to show up as part of my target image.

[Edit] My image recipe is as follows:

EXTRA_IMAGE_FEATURES_append = " eclipse-debug debug-tweaks"
TOOLCHAIN_HOST_TASK_append = " nativesdk-cmake"
IMAGE_INSTALL = "packagegroup-core-boot  ${CORE_IMAGE_EXTRA_INSTALL} util-linux kernel-modules netbase busybox base-passwd base-files sysvinit initscripts bash gdbserver strace sysfsutils dtc gawk ethtool grep sed wget  iptables oprofile net-tools dropbear rsync stress-ng rt-tests i2c-tools"
inherit core-image

The kernel I'm using is linux-altera-ltsi-rt in the meta-altera layer.

Winding answered 6/7, 2015 at 22:30 Comment(0)
S
24

From the fido release, the handling of kernel builds has been changed. In previous releases, you could usually just skip down to the usage example below.

In fido or any 1.8+, if you want the kernel src and build system available in the SDK, you should add

TOOLCHAIN_TARGET_TASK_append = " kernel-devsrc"

to your image recipe. That will ensure that the new, kernel-devsrc package is installed into your toolchain.

The procedure below is just to ensure that the rest of the workflow is fully understood (even though it's not strictly part of the original question).

Usage Example

Lets assume a module Makefile as follows:

obj-m += hello-1.o
all:
    make -C  $(KERNEL_SRC) M=$(PWD) modules

clean:
    make -C  $(KERNEL_SRC) M=$(PWD) clean

Example taken from The Linux Kernel Module Programming Guide (Note that the actual commands needs to have a tab character for indentation).

Then you'll have to define KERNEL_SRC to be sysroots/<mach>/usr/src/kernel/, either in the Makefile, or from your make call. (Using a variable like KERNEL_SRC will ensure that your module recipe automatically picks the right location when building using bitbake).

To manually build your kernel module:

  1. Source the environment-* file for your SDK.

  2. Go to you modules directory.

  3. KERNEL_SRC=<sdk-install-path>/sysroots/<mach>/usr/src/kernel LDFLAGS="" make However, this will fail, as fixdep can't be found. We'll fix this manually.

  4. cd <sdk-install-path>/sysroots/<mach>/usr/src/kernel

  5. make modules_prepare

    If this needs to be run with sudo, be sure to source the environment file in the sudo environment: sudo bash -c "source <sdk-install-path>/environment-setup-<mach> && make modules_prepare"

  6. Go back to your modules directory.

  7. KERNEL_SRC=<sdk-install-path>/sysroots/<mach>/usr/src/kernel LDFLAGS="" make

This should now allow you to build your modules.

If you don't have the kernel source under sysroots/<mach>/usr/src/kernel/, we'll have to look into that.

Stuart answered 7/7, 2015 at 6:35 Comment(6)
I'm not asking how to set up a recipe for an out-of-tree module, I'm asking how to get yocto to include the kernel headers in the SDK that it builds. In my SDK there is no <sdk>/sysroots/<mach>usr/src/kernel. What I want to know is make yocto include it in the SDK.Winding
Ok, then what layers and images are involved in your setup? I'll have to double check with 2nd build tomorrow.Stuart
I'm using stock Yocto 1.8 with meta-linaro (GCC 4.9) and the meta-altera layer. I also am using our own application layer, but the only (I think) relevant item in there is the image recipe, which I've edited into the question.Winding
Thanks for the updated info! I've update my answer, adding info on how to get the kernel source into the SDK for the fido release, as the kernel handling has been changed. I've verified that the workflow from the Usage Example section in my answer really works (at least on a pure Poky checkout, building for the qemux86).Stuart
Yes, that did the trick; TOOLCHAIN_TARGET_TASK! Thank you so much. Also, I edited step 5 in your answer to clarify what needs to happen if running make with sudo.Winding
Good to hear! Thanks for the edit! (Most of the time, I've ensured that I has direct write access to the install location, thus I'm easily forgetting about the sudo requirements!Stuart
M
1

anders answer is very good, but in recent versions of yocto the way to add kernel-devsrc seems to be

IMAGE_INSTALL += "kernel-devsrc"

which I found here: https://www.mail-archive.com/[email protected]/msg36448.html

Median answered 20/11, 2020 at 14:6 Comment(1)
This will install the kernel source in the rootfs as wellWiner
A
0

With Yocto Zeus (3.0.x) add this to your image recipe:

    TOOLCHAIN_TARGET_TASK += "kernel-devsrc"

EDIT: Same for Gatesgarth (3.2.x) but the make scripts command has a new host dependency to libyaml-dev

Anatole answered 30/4, 2021 at 15:14 Comment(1)
+= is equal to _appendDeclarant

© 2022 - 2024 — McMap. All rights reserved.