Yocto: How to Install Header Files Along with Kernel Module in Sdk

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 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.

Intel Galileo adding kernel header files to the cross compile toolchain

Well, first and foremost, you can never build a kernel module by just running ${CC} on it. You should always use a Makefile, which redirects most of its work to the kernel source Makefil.

Create a Makefile for you module, consisting of something similar to:

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 /opt/iot-devkit/1.6.1/sysroots/i586-poky-linux/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=/opt/iot-devkit/1.6.1/sysroots/i586-poky-linux/usr/src/kernel LDFLAGS="" make
    However, this will fail, as fixdep can't be found. We'll fix this manually.
  4. cd /opt/iot-devkit/1.6.1/sysroots/i586-poky-linux/usr/src/kernel
  5. make silentoldconfig scripts
  6. Go back to your modules directory.
  7. KERNEL_SRC=/opt/iot-devkit/1.6.1/sysroots/i586-poky-linux/usr/src/kernel LDFLAGS="" make

This should now produce hello.ko which you should be able to insmod on the Galileo board.

Library used by kernel module and user application

I believe you misunderstood how to use library. From description I understand that you have some piece of code/algo/data that you want to use in both User space app and Kernel module. AFAIK you can't just create a library and share them between user-kernel space to call each other's function.

To access userspace from kernel and vice versa you can use syscall, ioctl, device driver read/write etc.
Sample Image

For your specific application, you may register ioctl in driver and use them to initiate message passing from user to kernel space. You may also register a character driver in driver and perform read/write operation on device file to get/send a little large data.



Related Topics



Leave a reply



Submit