LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 04-27-2010, 04:42 AM   #1
bizoo
LQ Newbie
 
Registered: Jul 2009
Posts: 17

Rep: Reputation: 0
Adding external module to linux kernel source


Hi
Me being a kernel newbie needs some guidance.

There is a module A which is compiled with the kernel.

I wrote an external module B which exported a symbol using EXPORT_SYMBOL.
The module A now needs to talk with that exported symbol (function call). For that i modified A so that it includes the function call from B. However i now get unidentified symbol errors during 'make' operation as symbols of B are not present during kernel compile and A now kind of depends on B.

One solution is that make B part of the kernel as well. However, it would mean that whenever now i try to compile a kernel with a different source, i have to modify the config files and everything to accommodate B.
Hence i am seeking a solution which does not include modifying the kernel.

Any pointers will be appreciated.
br
 
Old 04-27-2010, 04:57 PM   #2
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Hey,

Quote:
Originally Posted by bizoo View Post
There is a module A which is compiled with the kernel.
I assume that you mean a real kernel module that will be dynamically loaded in the Linux kernel by using modprobe/insmod. Right?

Quote:
Originally Posted by bizoo View Post
The module A now needs to talk with that exported symbol (function call). For that i modified A so that it includes the function call from B. However i now get unidentified symbol errors during 'make' operation as symbols of B are not present during kernel compile and A now kind of depends on B.
Well, the first question is, how do you build the two modules? In the context of the currently running kernel sources or did you create an own make file? Secondly, did you include the function prototype of B in A?

If you search for 'Linux 2.6 kernel modules' using your favorite WEB search engine, you'll get the following two tutorials:

http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html
http://www.captain.at/programming/kernel-2.6/

As a hint: always compile your kernel modules with the kernel makefiles as described in the tutorials. Furthermore, it is important to use the sources of the kernel which is currently running on your system, otherwise you might get unwanted side-effects

More generally, you shouldn't get undefined symbols at module link time (if you use the correct make file), because the 'kernel' linker will resolve those symbols at load-time when insmod()ed into your kernel.

For example, take any of the existing modules of your kernel and do a 'nm' on the module file und you'll see some 'undefined symbols' like e.g. kfree.

Quote:
Originally Posted by bizoo View Post
One solution is that make B part of the kernel as well. However, it would mean that whenever now i try to compile a kernel with a different source, i have to modify the config files and everything to accommodate B.
Hence i am seeking a solution which does not include modifying the kernel.
You only need the kernel makefile, but you could keep your module source code independent of the kernel source code (except the kernel header files).

If anythink is unclear or you have further questions, just post them :-)

- Andi -
 
Old 04-28-2010, 02:09 AM   #3
bizoo
LQ Newbie
 
Registered: Jul 2009
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
I assume that you mean a real kernel module that will be dynamically loaded in the Linux kernel by using modprobe/insmod. Right?
Yes


Quote:
Well, the first question is, how do you build the two modules? In the context of the currently running kernel sources or did you create an own make file? Secondly, did you include the function prototype of B in A?
Well module A is compiled with the kernel source and its makefile is embedded in the kernel and it also has its own Kconfig file. Thus whenever i make changes inside A, i just go to my linux kernel source and type 'make'. Always does the job for me. Then i simply load my my module through insmod or modprobe. And yes, the module A have the prototype of function from B.

Module B is not built in the kernel and has its own makefile in which i seek the kernel Makefile to compile my module.




Quote:
As a hint: always compile your kernel modules with the kernel makefiles as described in the tutorials. Furthermore, it is important to use the sources of the kernel which is currently running on your system, otherwise you might get unwanted side-effects
I do it this way, i can even copy the makefile of module B. I am pretty sure that i am doing it the right way.



In my understanding, as module B has a symbol which is needed inside A for its compilation, Module A now depends upon module B. This means that now i have to change the Kconfig file of A and add this new dependency in. Also i have to make module B before A and as A comes from the kernel source, B should also be there in the kernel source tree and thats what i want to avoid.

Hope i have presented my situation a bit more clearly and thanking in anticipation for more pointers and ideas!

br
 
Old 05-07-2010, 06:30 AM   #4
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Quote:
Originally Posted by bizoo View Post
Well module A is compiled with the kernel source and its makefile is embedded in the kernel and it also has its own Kconfig file. Thus whenever i make changes inside A, i just go to my linux kernel source and type 'make'. Always does the job for me. Then i simply load my my module through insmod or modprobe. And yes, the module A have the prototype of function from B.

Module B is not built in the kernel and has its own makefile in which i seek the kernel Makefile to compile my module.
Right, both sounds okay to me ...

Quote:
Originally Posted by bizoo View Post
In my understanding, as module B has a symbol which is needed inside A for its compilation, Module A now depends upon module B. This means that now i have to change the Kconfig file of A and add this new dependency in. Also i have to make module B before A and as A comes from the kernel source, B should also be there in the kernel source tree and thats what i want to avoid.
Right, module A depends on module B which means that module B must be loaded into the kernel BEFORE module A gets loaded. Though, either you guarantee this dependency by using a shell script which insmod() the modules in the correct order or you use the dependency model of depmod.

I don't think you need module B to be available in the kernel source tree. If you would use the depmod utility, it just checks for the available kernel objects (ko) and doesn't care about where a specific module was built.

Anyway, this is just the secondary step, but you're already getting problems during compilation.

Could you possibly make your code available in the net? I mean just the sources which aren't available in the vanilla tree (maybe a diff?).

- Andi -

Hope i have presented my situation a bit more clearly and thanking in anticipation for more pointers and ideas!

br[/QUOTE]
 
  


Reply



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
adding a new kernel module to wireless driver module nandan.amar Linux - Newbie 2 04-22-2010 09:21 AM
LXer: Dynamic Content - Simply Adding from External Source LXer Syndicated Linux News 0 08-25-2008 03:30 PM
Help Calculating page faults in Linux Kernel 2.6 & Adding external Load to a system umassd123 Linux - Kernel 1 12-11-2007 06:59 AM
LXer: Howto: build Linux kernel module against installed kernel w/o full kernel source tree LXer Syndicated Linux News 0 09-03-2006 08:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:34 PM.

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
Open Source Consulting | Domain Registration