Using populate_sdk to include kernel headers

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 silentoldconfig scripts

    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 silentoldconfig scripts"

  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 ysroots/<mach>/usr/src/kernel/, we'll have to look into that.