0
votes

I am a newbie to kernel programming and I want to modify a header file in arch/x86/include/asm/tlbflush.h so that my kernel module can use one of the functions exported by this header file.

I have the source code for 3.2.59 kernel and made changes to tlbflush.h. I included the header file tlbflush.h. When i compile the module i get a warning saying the function that I am using is not found and as a result I am not able to insmod my kernel module.

I went through the following how to export a modified kernel header

and tried the following steps to install the modified kernel header:

  1. make
  2. sudo make modules_install
  3. sudo make headers_install INSTALL_HDR_PATH=/usr/include
  4. sudo make install
  5. sudo update-initramfs -c -k 3.2.59

The link mentioned talks about installing kernel headers to /usr/include for access to user space processes

I want to mention that I have so many headers installed due to the upgrades done on my ubuntu machine. Also all of them have extensions like 3.2.0-59, 3.2.0-xx I considered 3.2.0-59 to be same as 3.2.59 though I am not sure. Please correct me in case this is wrong. Thanks !

Edit:

I am sorry, I got confused with the headers in /usr/src/... folder versus the headers in the source code of kernel that is being modified. I made a change in the headers of the kernel source that i downloaded and after that there is no warning now.

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

I am sorry for the waste of time, if you spent on this.

1

1 Answers

0
votes

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