How to Export a Modified Kernel Header

Install a modified kernel header for access to kernel programs

But the question still remains that why are the kernel headers in /usr/src/ used?

Actually, nobody forces that. If you're using standard Makefile for building your module, it is a place that states it.
Mine contains the following line:

make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

If you examine what /lib/modules/$(shell uname -r)/build really is, you will find that this is a symlink to folder where kernel source is located.

~ $ ls -l /lib/modules/$(uname -r)/build
lrwxrwxrwx 1 root root 32 Jun 9 04:46 /lib/modules/3.12.21-gentoo-r1/build -> /usr/src/linux-3.12.21-gentoo-r1

For ubuntu, linux-headers contains only minimum kernel part necessary to build your own module (not only headers).

exporting/ installing Kernel header in ubuntu

The headers in /usr/include/linux are the headers of the kernel which glibc and other system libraries depend on. See to which package they belong:

$ dpkg -S /usr/include/linux/if.h 
linux-libc-dev: /usr/include/linux/if.h

Some of glibc sys/ headers depend on the linux/ headers, and these are usually the same headers (or close to the ones) glibc's binary was compiled against.

Therefore, building a custom kernel should not replace those by default, otherwise it can create binary incompatibility.

Export kernel module headers to userspace

There is no such functionality out of the box because most kernel modules which need something like that come with an extra "devel" package which contains the (cleaned) header files and probably a shared library to talk to the module.

As for cleaning your headers, I suggest to split the header files into a generic part (which you export) and an internal part (which only the kernel module can see). typedef is your friend.

How to create shared header file for kernel filesystem and user program?

Existed filesystem drivers place their headers, which are also intended for user space, under include/uapi/linux/. Here you may find jffs2.h, btrfs.h and many other filesystems-related headers.

These headers are intended to be included with

#include <linux/xxx.h>

This automatically works for the kernel.

For user this would work too, after you install "uapi" headers with make headers_install, rebuild C library (libc) against new headers, and rebuild gcc against new C library. Otherwise, you need to copy required headers and adjust include directories manually.

How to include an arbitrary kernel header file in a module?

How do I reference those 2 symbols in my kernel module?

You should not need those in a "normal" kernel module. If you really do, re-define them in your module.

Are those symbols supposed to be referenced directly by a standard module?

They are not, that particular sched.h file is only supposed to be used by scheduler code (files in kernel/sched). That's why it is not exported (i.e. not in the include dir). You will not find them in your headers folder (/lib/modules/.../build).

Is the Makefile related to how I can import a file in kernel code into my module?

Unsure what this means really... if you want to know if there is some way to configure your Makefile such that it will be possible to include that file, then there is not. If you are building using the kernel headers exported by the kernel in /lib/modules (which is what you are doing when you hand over control to the kernel's Makefile with $(MAKE) -C $(KROOT)) then the file is simply not there.

Linux kernel headers

I've been looking into this matter a little bit myself recently.

I don't know how related this answer is since it sounds like you are only concerned about understanding the packaging of the kernel source you have on hand. This answer probably only pertains to your second question. Nevertheless here is some stuff I've found about kernel headers.

From what I've found there are two potential locations that end up being referred to as "kernel headers".

The first location is in /usr/src/linux-headers-`version' (at least on my Ubuntu machine). This is where your kernel (source?) is installed as well as the accompanying headers. If you want to build kernel modules then you will need to build against the headers found here.

On the other hand /usr/include/{linux,asm} also contain "kernel headers". You can think of these header files as the userland interface to your kernel. It is the API exported by the kernel so userland programs can make system calls. Your libc will take advantage of this API so it can create functions (in /usr/include) based on which system calls are available.

Here are a couple of documents to back up what I've just said and to clarify things a bit more:

Here is a link about the difference between /usr/src/linux-headers-`version' and /usr/include on RHEL4.

http://www.linuxquestions.org/questions/red-hat-31/rhel4-kernel-devel-headers-packages-missing-directories-697552/

Here is a link about 'exporting' kernel headers:
http://www.kernel.org/doc/Documentation/make/headers_install.txt

Finally here is another explanation of what kernel headers are for:
http://www.overclockers.com/forums/showthread.php?t=647638

So maybe you knew this already and you just wanted to know how to create a driver using the sources in your kernel package, but at least with this answer you know that its definitely the place to start.



Related Topics



Leave a reply



Submit