LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-16-2007, 11:02 PM   #1
payretep
LQ Newbie
 
Registered: Sep 2007
Posts: 5

Rep: Reputation: 0
Problem in compiling a char device driver formerly for kernel 2.4 on kernel 2.6


Hi all, this is my first post here on LinuxQuestions and I really hope that you guys will be able to help me. I'm very new on Linux and I hope you all can understand the newbie question that I'm posting. (After all this is the newbie section )

Here goes: I'm compiling a char device driver for Linux. It was formerly for kernel version 2.4.20-8 on Redhat and it was compiling working properly on that version. The problem comes when I am required to upgrade the kernel version from 2.4.20-8 to 2.6.18.

Fundamentally, I understand that there are major differences when using different kernel versions. However, as I am very new to the Linux environment and the error messages during compilation has nothing to do with device related errors, more of environment mismatch types, I am quite stuck.

I hope that the following error message that I paste can make some sense and provide some clues to you guys as to what I should do.

=====================================================================

/usr/src/linux/include/asm/rwsem.h: In function ‘__down_read’:
/usr/src/linux/include/asm/rwsem.h:106: error: expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/rwsem.h: In function ‘__down_write’:
/usr/src/linux/include/asm/rwsem.h:158: error: expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/rwsem.h: In function ‘__up_read’:
/usr/src/linux/include/asm/rwsem.h:195: error: expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/rwsem.h:189: warning: unused variable ‘tmp’
/usr/src/linux/include/asm/rwsem.h: In function ‘__up_write’:
/usr/src/linux/include/asm/rwsem.h:221: error: expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/rwsem.h: In function ‘__downgrade_write’:
/usr/src/linux/include/asm/rwsem.h:246: error: expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
In file included from /usr/src/linux/include/linux/sched.h:20,
from /usr/src/linux/include/linux/module.h:10,
from client3.c:229:
/usr/src/linux/include/asm/semaphore.h: In function ‘down’:
/usr/src/linux/include/asm/semaphore.h:105: error: expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/semaphore.h: In function ‘down_interruptible’:
/usr/src/linux/include/asm/semaphore.h:130: error: expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/semaphore.h: In function ‘down_trylock’:
/usr/src/linux/include/asm/semaphore.h:155: error: expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/semaphore.h: In function ‘up’:
/usr/src/linux/include/asm/semaphore.h:179: error: expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
In file included from /usr/src/linux/include/asm/smp.h:18,

=======================================================================
I have tried to look this up on the internet, but I got nothing useful as of now. Any help here will be appreciated. Thanks in advance. =)
 
Old 09-17-2007, 03:58 PM   #2
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 114Reputation: 114
Assuming that your kernel is properly installed, then you are using the wrong makefile.

The makefile to compile a kernel driver for 2.6 must look exactly like this:

Code:
obj-m := mydrivermodule.o
KDIR    := /lib/modules/$(shell uname -r)/build
PWD    := $(shell pwd)

default:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
 
Old 09-17-2007, 05:21 PM   #3
Mikhail_16
Member
 
Registered: Oct 2003
Distribution: Gentoo rules them all
Posts: 279

Rep: Reputation: 31
True dat ^^.

Although i think you're missing the obvious point where the OP is trying to compile a 2.4 module for a 2.6 kernel. I think you should try to find out a module version for your spefic kernel version, as there are some major differences between 2.4 and 2.6 modules. Try searching for an updated version as a start. See if you can find some documentation on what needs to be configured or installed for the module to compile successfully too.

2.4.20 to 2.6.18 is a HUGE jump in kernel terms. Are you sure that your device isn't supported by 2.6 already?
 
Old 09-17-2007, 07:41 PM   #4
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 114Reputation: 114
It is indeed a huge jump, but backward compatibility has been (mostly) maintained. A driver written for 2.4 will *probably* work for 2.6. Might be locking issues and might not be as efficient as desired, but will probably work.

In any case, his particular problem is associated with incorrect makefile.
 
Old 09-18-2007, 08:58 AM   #5
payretep
LQ Newbie
 
Registered: Sep 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Hey guys, thanks for the response. Like you guys said, the makefile structure of kernel 2.6 is totally different from that of kernel 2.4. Therefore, the makefile for the kernel 2.4 compliant device driver cannot be used. Looks like I will need to rewrite the makefile from scratch and follow the kbuild structure. -_-;

Thanks again for the response, I appreciate it. =)
 
Old 09-18-2007, 09:58 AM   #6
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 114Reputation: 114
no, you don't rewrite the makefile from scratch. You use the exact format I provided.
 
Old 09-24-2007, 05:43 AM   #7
payretep
LQ Newbie
 
Registered: Sep 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Hi all again,

I have successfully used the makefile that was provided to me by jiml8 and its compiling fine now. However, I'm getting loads of warning. 2 of the most common ones are that some XXXX_API is COMMON symbol and YYYY_API is undefined. These warnings occur during the linking stage, and they did not appear during compiling in a kernel 2.4 environment. Can anybody help me with it.

And one "tiny" problem is that when I try to install the generated *.ko module, I will get a "-l invalid module format". Any idea what am I doing wrong here?

Thanks for your help in advance. Cheers!
 
  


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
compiling kernel problem --- Kernel panic: unable to mount root fs ........ anthonymts123 Linux - General 5 07-31-2006 02:29 AM
char driver on linux-kernel-2.6.10 prashy Programming 2 05-09-2005 01:44 PM
problem compiling kernel for installing alcatel driver fawkes.phoenix Linux - Software 2 07-01-2004 01:46 PM


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

Main Menu
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