Linux Kernel Headers' Organization

Linux kernel headers' organization

I've asked this question on Kernel Newbies ML. I got the following answer which makes things clear:

Cihangir Akturk wrote:

AFAIK, headers found in /include/asm-generic directory is for
architechture independent (probably shared across architectures) code.
Most likely you do not need to include these headers directly, instead
we include these headers indirectly via architecthure dependent
headers.

OTOH, /include/linux directory is for generic header files to define
interfaces between components of the kernel. In most situations, you
will find all the kernel functionalities you need in these headers.

regards, chngr.

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.

asm vs asm-generic in linux headers -- are they same

Short answer

They are not the same.

kernel developer might include asm-generic headers in a asm header while asm headers are the headers required for kernel modules.

You may get more info from following post

  • in linux kernel, asm or asm-generic?
  • Linux kernel headers' organization
  • linux module compilng missed folder asm

Take this question in another way.

It seems you're trying to make a kernel module.

To build a kernel module you need kernel-headers or compiled kernel source code. However I don't know kali linux, so I just provide generic suggestions here.

Where to get them

  • Some of distributions, like Ubuntu, have prebuilt linux-headers.

    • Eg: Ubuntu has it in /usr/src/linux-headers-$(uname -r)/include
  • Download it by sudo apt-get install linux-headers-$(uname -r)

    • It seems kali linux 2.0 might need more operations. Found this post might help.
  • Build it yourself

    1. Checkout linux kernel code of your desired distro.
    2. Set up kernel config with make menuconfig ( You might get stumbled here a while.. many packages might be required )
    3. Compile kernel with make modules_prepare to compile essential Module.symvers for drivers. It take significant less time than compiling a full kernel.

I presume you already found a kernel module build example. If not, you may consult offical kernel module documentation. It helps a lot if you take a while to read first two chapters.

Or another example

Make kernel headers available to user space

I think you should treat your public user-space API headers like any others, and put them under /usr/include. Either as a single file if it's a small API, or in a subdirectory. Just make sure to provide only the necessary pieces in that header, and not the implementation details. If you're going to produce a Linux package for developers, you'd usually name it like foo-dev (APT/Ubuntu) or foo-devel (YUM/RHEL).

How to include kernel headers in a program

try this find / -name skbuff.h 2>/dev/null then when it finds the location use the -I/path/to/folder when you compile your program.. If it doesn't find the header you don't have it!



Related Topics



Leave a reply



Submit