LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Error compiling loadable kernel module with vanilla kernel (https://www.linuxquestions.org/questions/linux-kernel-70/error-compiling-loadable-kernel-module-with-vanilla-kernel-4175414977/)

aijazbaig1 07-05-2012 12:46 AM

Error compiling loadable kernel module with vanilla kernel
 
Hello Folks

Ive been trying to compile a vanilla kernel just for the purpose of refreshing some long forgotten loadable modules concepts. By the way, Im running centos 6.

what ive done is, ive downloaded a vanilla kernel image 2.6.32 from kernel.org and then I did a
Code:

menu xconfig
on it to create a .config file. After having done that, I run
Code:

make
on the top level directory which seems to work fine.

However
Code:

make modules
fails with the following errors:

Code:

No rule to make target 'net/ipv4/netfilter/ipt_ecn.c', needed by `net/ipv4/netfilter/ipt_ecn.o'. Stop'
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [net/ipv4/netfilter] Error 2
make[1]: *** [net/ipv4] Error 2
make: *** [net] Error 2
make: *** Waiting for unfinished jobs....

I believe this just means that it was NOT able to build the 'ipt_ecn' module ('iptables' module which is typically used as a filtering, network traffic sniffer/shaper..and many other things. Thats out of topic for this). And thats fine with me. What has got me concerned is, since it apparently failed in the middle, it may have missed out on any book-keeping task(s) which it does at the end of 'make modules'?

Nonetheless, I ran a
Code:

make modules
and it seemed to have went fine (note that ive already installed the modules under /lib/modules/ by doing a
Code:

make modules_install
at the top of the vanilla kernel source tree). I then cd into the directory where my kernel module source code is located. My Makefile in it looks like this:
Code:

obj−m += hello−1.o

all:
make -C /lib/modules/2.6.32.59/build M=$(shell pwd) modules

clean:
make -C /lib/modules/2.6.32.59/build M=$(shell pwd) clean

I DID NOT use the /lib/modules/`uname -r`/build path as I do not want to have these modules linked against the currently running kernel. I will only do an 'insmod' after having booted into the '2.6.32.59' vanilla kernel later. So am I allowed to build a kernel module against a kernel which is not currently running?

Anyways, I try doing exactly that, by doing a
Code:

make all
in the directory where I have my kernel module source. However I get the following errors:
Code:

make -C /lib/modules/2.6.32.59/build M=/home/aijazbaig1/modules modules
make[1]: Entering directory `/home/aijazbaig1/linux-2.6.32.59'
test -e include/linux/autoconf.h -a -e include/config/auto.conf || ( \
echo; \
echo " ERROR: Kernel configuration is invalid."; \
echo " include/linux/autoconf.h or include/config/auto.conf are missing."; \
echo " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
echo; \
/bin/false)
mkdir -p /home/aijazbaig1/modules/.tmp_versions ; rm -f /home/aijazbaig1/modules/.tmp_versions/*

WARNING: Symbol version dump /home/aijazbaig1/linux-2.6.32.59/Module.symvers
is missing; modules will have no dependencies and modversions.

make -f scripts/Makefile.build obj=/home/aijazbaig1/modules
(cat /dev/null; ) > /home/aijazbaig1/modules/modules.order
make -f /home/aijazbaig1/linux-2.6.32.59/scripts/Makefile.modpost
scripts/mod/modpost -m -a -i /home/aijazbaig1/linux-2.6.32.59/Module.symvers -I /home/aijazbaig1/modules/Module.symvers -o /home/aijazbaig1/modules/Module.symvers -S -w -s
make[1]: Leaving directory `/home/aijazbaig1/linux-2.6.32.59

After searching a lot over the internet, ive come across many different opinions but I couldn't figure out a single reason as to why it fails to find the autoconf.h or auto.conf files. These files are present under the source tree

[root@MyCentOS-VM linux-2.6.32.59]# find . -name autoconf.h
./include/linux/autoconf.h
[root@MyCentOS-VM linux-2.6.32.59]# find . -name auto.conf
./include/config/auto.conf

Ive also created a soft link (since it wasn't there by default to begin with) '/usr/src/linux' to point to the directory where the stock kernel is located.
Here:
[root@MyCentOS-VM modules]# ls -l /usr/src/
total 8
drwxr-xr-x. 2 root root 4096 Sep 23 2011 debug
drwxr-xr-x. 3 root root 4096 Jun 27 16:08 kernels
lrwxrwxrwx. 1 root root 33 Jul 2 16:05 linux -> /home/aijazbaig1/linux-2.6.32.59/

I fail to understand what exactly is causing the build to fail. Please enlighten me or give me some pointers as to where should I be looking at.

Keen to hear from you soon.

Regards,
Aijaz

unSpawn 07-05-2012 02:04 AM

Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread should be closed because it is a duplicate of http://www.linuxquestions.org/questi...el-4175414846/.

aijazbaig1 07-05-2012 03:24 AM

Hello

Id rather keep this thread open and close the 'other one' since that one was in the 'wrong' section and ive already put in a request there to the mod

So if you know how to close that one, please do tell me.

unSpawn 07-05-2012 03:48 AM

Please use the report button on your original post (http://www.linuxquestions.org/questi....php?p=4719607) and ask a moderator to close / move / whatever the thread for you.

aijazbaig1 07-05-2012 06:47 PM

I have already reported the other thread so the mod will soon close that one. But THIS one need not be closed as I believe more 'kernel' folks will take a shot at it if its here.

bsat 07-06-2012 12:54 AM

Try this

In the makefile for the module use the path to the kernel source along with make i.e.

Code:

obj−m += hello−1.o

all:
make -C <Path to kernel source> M=$(shell pwd) modules

clean:
make -C <Path to kernel source> M=$(shell pwd) clean


aijazbaig1 07-08-2012 10:53 PM

Hi Bsat

Heres how my Makefile looks now:
Code:

obj−m += hello−1.o

EXTRA_CFLAGS = -c -W -Wall -nostdinc

all:
        make -C /home/aijazbaig1/linux-2.6.32.59 M=$(shell pwd) modules
#        make -I /home/aijazbaig1/linux-2.6.32.59/include -C /lib/modules/2.6.32.59/build M=$(PWD) modules

clean:
        make -C /home/aijazbaig1/linux-2.6.32.59 M=$(shell pwd) clean
#        make -I /home/aijazbaig1/linux-2.6.32.59/include -C /lib/modules/2.6.32.59/build M=$(PWD) clean

But even now I get a similar looking error:
Code:

make -C /home/aijazbaig1/linux-2.6.32.59 M=/home/aijazbaig1/modules modules
make[1]: Entering directory `/home/aijazbaig1/linux-2.6.32.59'
test -e include/linux/autoconf.h -a -e include/config/auto.conf || (                \
        echo;                                                                \
        echo "  ERROR: Kernel configuration is invalid.";                \
        echo "        include/linux/autoconf.h or include/config/auto.conf are missing.";        \
        echo "        Run 'make oldconfig && make prepare' on kernel src to fix it.";        \
        echo;                                                                \
        /bin/false)
mkdir -p /home/aijazbaig1/modules/.tmp_versions ; rm -f /home/aijazbaig1/modules/.tmp_versions/*
make -f scripts/Makefile.build obj=/home/aijazbaig1/modules
(cat /dev/null; ) > /home/aijazbaig1/modules/modules.order
make -f /home/aijazbaig1/linux-2.6.32.59/scripts/Makefile.modpost
  scripts/mod/modpost -m -a -i /home/aijazbaig1/linux-2.6.32.59/Module.symvers -I /home/aijazbaig1/modules/Module.symvers  -o /home/aijazbaig1/modules/Module.symvers -S -w  -s
make[1]: Leaving directory `/home/aijazbaig1/linux-2.6.32.59'
[aijazbaig1@MyCentOS-VM modules]$ ls
compile_gcc.log  hello-1.c  Makefile  Makefile_Logs  make_install.log  make.log  modules.order        Module.symvers
[aijazbaig1@MyCentOS-VM modules]$ make clean
make -C /home/aijazbaig1/linux-2.6.32.59 M=/home/aijazbaig1/modules clean
make[1]: Entering directory `/home/aijazbaig1/linux-2.6.32.59'
  CLEAN  /home/aijazbaig1/modules/.tmp_versions
  CLEAN  /home/aijazbaig1/modules/Module.symvers /home/aijazbaig1/modules/modules.order
make[1]: Leaving directory `/home/aijazbaig1/linux-2.6.32.59'

What exactly seems to be going wrong. I cannot figure out what to do...

By the way, Ive even tried pointing make explicitly to the include folder within the top level source tree but to no avail. Additionally in both these cases, module.symvers and modules.order get created but they both are empty (0 byte) files

bsat 07-08-2012 11:40 PM

Are you sure the compilation of kernel has completed successfully,did you get the bzImage ?
Did you run make oldconfig and make prepare as suggested in the error message ?

aijazbaig1 07-09-2012 04:20 AM

I think I had already done that. To make sure, I prepared the vanilla kernel source by issuing a
Code:

make oldconfig
followed by a
Code:

make prepare
After that, I built the kernel using
Code:

make
installed the modules using make
Code:

modules_install
finally installing the image using
Code:

make install
which generated the bzImage and the vmlinuz file under /boot and made the necessary changes under /boot (copying the img and changing grub I believe).

After that, I booted off the new vanilla kernel so
Code:

uname -r
now shows 2.6.32.59. And then I retried what I was trying before. And I still get the exact same error message as shown above...

Im confused. Ive never had this problem a few years back when I first started out...:(

bsat 07-10-2012 02:55 AM

See if this helps

https://www.centos.org/modules/newbb...topic_id=35068

Also try installing the kernel-devel tools .

aijazbaig1 07-10-2012 07:08 AM

Hi. I was unable to understand what was going wrong in that extremely simple code. So perhaps in a bout of frustration, I downloaded a sample from the link below:
http://www.cyberciti.biz/tips/build-...urce-tree.html .

After making a simple change in the Makefile (which was causing the compile to fail), I compiled it and voila! it works!! Modpost did post the module and I could see the ko and the o files. What was unusual though was that I had to use the module name alongwith the ko extension to insert it. So insmod hello wouldnt work but insmod hello.ko does. This wasnt the case earlier as far as I remember.

Any comments?

bsat 07-11-2012 12:00 AM

As far as i have used insmod, it has always been with the ".ko" extention. It is modprobe to which we can pass the module name with out extention.
Any way what was the problem with your makefile, what did you change ?
Mark the thread solved if it is.

aijazbaig1 07-11-2012 08:20 AM

Na..i meant there was a problem in the makefile of the downloaded sample code. And after fixing that, it started to work.

I still don't know what is the problem with mine :(

sundialsvcs 07-13-2012 08:51 AM

Please ignore, for a moment, whether the kernel in question has been decomposed into "modules" or not. The total kernel logically consists of all of its pieces, no matter what module they are (or are not) in. Effectively, conceptually, the entire kernel is linked as-one even though multiple output modules are produced. It must be a logical whole. If your kernel is "vanilla," this implies that it is minimalist; that pieces of it, which some module might require, might not be there. And if so, that's your (only) problem.


All times are GMT -5. The time now is 06:50 AM.