LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-15-2008, 08:54 AM   #1
Rovalk
LQ Newbie
 
Registered: Sep 2007
Posts: 5

Rep: Reputation: 0
Unable to build kernel modules outside the kernel tree


I'm trying to build some external kernel modules but I can't get it work.
The source files are not located in the kernel source tree and I need the output to be in a separate directory too.

I've tried many options and combinations but make generates the following error over and over:
ERROR: Kernel configuration is invalid.
include/linux/autoconf.h or include/config/auto.conf are missing.
Run 'make oldconfig && make prepare' on kernel src to fix it.

The kernel tree is located at "/data/kernel2.6.20
The module sources are located at "/data/module"
The output of the module must be at "/data/output"

What's going on:

I execute make at the module source location. In the Makefile of the module I defined a rule which will execute the following command:
make -C ${KERNEL_DIR} CROSS_COMPILE=${CROSS_COMPILE} ARCH=arm M=$(shell pwd) O=${OUTPUT_DIR} modules

Now make will execute a new make in the kernel directory using the Makefile of the kernel. Because I've set the "0" variable to the output directory make will executes another make in the output directory still using the kernels Makefile. And this is where it goes wrong! Because make is running in the output directory it can't find "include/config/auto.conf" which is located in the kernel source tree.

This is what I've read in the kernels Makefile:
# external modules needs include/linux/autoconf.h and include/config/auto.conf
# but do not care if they are up-to-date. Use auto.conf to trigger the test
PHONY += include/config/auto.conf

include/config/auto.conf:
$(Q)test -e include/linux/autoconf.h -a -e $@ || ( \
echo; \
echo " ERROR: Kernel configuration is invalid."; \
echo " include/linux/autoconf.h or $@ are missing."; \
echo " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
echo; \
/bin/false)


I tried to run 'make oldconfig && make prepare' but that didn't solve the problem either. After some research I found out that if the 'O=output/dir' option is used it must be used for all invocations of make, even with menuconfig.
So while writing this I tried to run make menuconfig with the 'O' option and build the kernel with the 'O' option. The kernel output has been generated in the separate output directory, but when I build the external module, the output is still generated in the source directory of the module. (at least it has been build without errors now )

Does anyone know if it's possible to build an external module without having the sources in the kernel source tree and the output generated in a separate output directory?

Does anyone have any ideas? Please feel free to ask me when something isn't clear.

Thanks,
Ronald
 
Old 01-17-2008, 10:50 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,523

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
I do not have much experience compiling kernel modules, however when I had to do it for a recent project, all I did was create a Makefile similar to the following (in whatever directory I choose):

PHP Code:
obj-+= module-name.
To execute the Makefile, I used this command (within the directory where the Makefile resides):

PHP Code:
make -/lib/modules/`uname -r`/build M=`pwd
This worked for me on Fedora 7 and Ubuntu 7.04 systems. I'm sure it works with other systems too.

Last edited by dwhitney67; 01-17-2008 at 10:52 AM.
 
Old 01-19-2008, 02:18 AM   #3
Rovalk
LQ Newbie
 
Registered: Sep 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Hi dwhitney67,

Thanks for your reply. Compiling the module isn't the problem but the location of the output. I don't want the output in the source directory but somewhere else.

I've tried some other things but can't get it work the official way, if there is any, so I used a little trick and now it's working. In the makefile of the module I created a rule that'll create hardlinks on the desired output location linked to all the files located in the source directory. After that I call make with -C=${KERNEL_DIR} and M=${OUTPUT_DIR}, the output will now be generated in the output directory because of the hardlinks. When the module has been build, I remove the hardlinks from the output directory.

I know this isn't the prettiest method, but it works (for the time being).

Please let me know if somebody knows the official way.

Thanks,
Ronald
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to build the kernel tree on the system? Nishant Desai Linux - Kernel 24 12-01-2006 09:05 PM
LXer: Howto: build Linux kernel module against installed kernel w/o full kernel source tree LXer Syndicated Linux News 0 09-03-2006 09:21 PM
How to build usb modules into kernel?? coolguy_2005 Suse/Novell 2 08-21-2006 06:27 AM
Unable to Build ELDK3.1 for kernel 2.4.25. On Booting Unable to mount root fs.. kannath Debian 0 05-11-2006 10:26 AM
Unable to build NVIDIA kernel module / determin kernel version Night Ink Fedora 2 05-31-2004 05:54 PM


All times are GMT -5. The time now is 07:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration