LinuxQuestions.org
Visit Jeremy's Blog.
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 02-25-2005, 01:24 PM   #1
rajesh_b
Member
 
Registered: Sep 2004
Location: Hyderabad.
Posts: 83

Rep: Reputation: 15
Problem in inserting a device driver module


Hi,

I started reading linux device drivers by rubini. As the part of the book i try to compile and load a simple module. It compiled well but when i m trying to inserting this i m facing a version mismatch problem.
The program looks like this

#define MODULE
#include<linux/module.h>

int init_module(void)
{
printk("<1> Hello \n");
return 0;
}

void cleanup_module(void)
{
printk("<1> Bye \n");
}

I compiled the prog as
gcc -c firstmod.c

But when i try to insert the module with the following command

insmod firstmod.c
I m getting the following error message.
Module is compiled for a different kernel and u r inserting into a kernel whose version is different. It is saying that "Version mismatch occurs". And it is saying that version of kernel for which my module is compiled is 2.4.20 and where as kernel version into which im inserting module is 2.4.20-8. But how can it is possible. When i used uname to print info it prints my kernel version as 2.4.20-8. Then how can module is compiled with the kernel 2.4.20

By this output what i understood is my module is compiled with a kernel header whose version is different than the kernel into which i m inserting my module. But i dont know how can i solve this problem. I m using red hat 9.0 on pentium 4 machine. Can any body help me to resolve this version mismatch.

Thanx in advance.
Rajesh.
 
Old 02-25-2005, 03:20 PM   #2
peter_robb
Senior Member
 
Registered: Feb 2002
Location: Szczecin, Poland
Distribution: Gentoo, Debian
Posts: 2,458

Rep: Reputation: 48
Check the Makefile version number in the linux sources..
 
Old 02-28-2005, 02:47 AM   #3
rajesh_b
Member
 
Registered: Sep 2004
Location: Hyderabad.
Posts: 83

Original Poster
Rep: Reputation: 15
Hi

Can u plz tell me how to check the makefile version. I have two directories in /usr/src folder one linux-2.4 and another one is linux-2.4.20-8. Thanx in advance.

Rajesh.
 
Old 02-28-2005, 06:42 AM   #4
peter_robb
Senior Member
 
Registered: Feb 2002
Location: Szczecin, Poland
Distribution: Gentoo, Debian
Posts: 2,458

Rep: Reputation: 48
That would depend on the linking to the linux headers you are using during your build..

You may find that linux-2.4 is a symlink to linux-2.4.20-8..
Either way, look at the files /usr/src/linux-2.4/Makefile and /usr/src/linux-2.4.20-8/Makefile
These determine the version number used by the built kernel and modules.
You need to have done at least make dep to create the linking that fixes the version number.
Whatever the version & extraversion show in the Makefiles, use that as the name of the directory the sources are in.
Then create symlinks /usr/src/linux and /usr/src/linux-2.4 to the directory with 2.4.20-8 name
If the sources have not been used for a kernel/module build, do make dep to prepare them.

Last edited by peter_robb; 02-28-2005 at 06:44 AM.
 
Old 03-01-2005, 09:06 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: NetBSD, Void, Debian, Mint, Ubuntu, Puppy, Raspbian
Posts: 3,485

Rep: Reputation: 223Reputation: 223Reputation: 223
Quote:
insmod firstmod.c
shouldn't that be
insmod firstmod.o
???
 
Old 05-10-2007, 12:20 AM   #6
misbah
LQ Newbie
 
Registered: Nov 2006
Location: india
Distribution: red hat
Posts: 5

Rep: Reputation: 0
regarding insmod

Quote:
Originally Posted by bigearsbilly
shouldn't that be
insmod firstmod.o
???

well i guess it should be insmod file_name.ko to inserte the module and rmmod file_name.ko

After compiling and linking the .c file you will get .ko file ......Please correct me if i am wrong ....
Thanks
Misbah Khan
 
  


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
Problem inserting a new module to kernel hetzme Programming 2 07-18-2005 06:21 AM
Problem inserting a new module hetzme Linux - Software 2 07-17-2005 08:33 PM
inserting a module without recompiling? Simon Bridge Linux - Software 1 05-14-2004 05:53 PM
Installing a device driver as a Module lehumphr Linux - Newbie 1 04-27-2004 11:31 PM
creating a simple module(device driver) pessanimahi Linux - Software 1 09-16-2003 11:34 AM

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

All times are GMT -5. The time now is 07:25 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration