LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 08-30-2005, 02:33 PM   #1
Pratik H Pandya
LQ Newbie
 
Registered: Jun 2005
Location: India
Distribution: RedHat 9.0,Fedora core 3
Posts: 22

Rep: Reputation: 15
kernel programming help


Hello friends

I'm using Redhat 9.0 and i want to start the kernel programming
but as it is different the case i'm not getting how to compile modules and running them so i read one e-book and wrote the "hello world" module
and tried to compile by making make file
but it is giving error like "Nothing to be done for all"

i'm not getting please help me i'm writing my program and make file below

****************Hello.c***************************

#include<linux/module.h>
#include<linux/kernel.h>

int init_module(void)
{
printk(KERN_ALERT "\nHello Kernel\n");
return 0;
}
int cleanup_module(void)
{
printk(KERN_ALERT "\nGoodbye kernel\n");
}


*********** Makefile*****************************

obj -y+=hello.o

all:
gcc -C /lib/modules/$(shell uname -r)/build/M=$(PWD) module

clean:

gcc -C /lib/modules/$(shell uname -r)/build/M=$(PWD) clean


please help me and please tell me if there is a good book of kernel programming.

thanx in advance.
 
Old 08-30-2005, 06:31 PM   #2
comprookie2000
Gentoo Developer
 
Registered: Feb 2004
Location: Fort Lauderdale FL.
Distribution: Gentoo
Posts: 3,291
Blog Entries: 5

Rep: Reputation: 58
I have heard this is "the" book;
http://rlove.org/kernel_book/
 
Old 09-02-2005, 06:37 AM   #3
jasdeep_js
LQ Newbie
 
Registered: Sep 2005
Location: Bangalore (INDIA)
Distribution: Redhat9
Posts: 10

Rep: Reputation: 0
well pratik this is the problem that everyone who starts kernel programming is bound to face.
you can refer to Rubinni's "Linux Device Driver" or can go through LKMPG available online at tldp.org.
This is a sample makefile for the hello world program,which i used for my hello world program.

TARGET := hello
INCLUDE := /usr/src/linux-2.4.20/include
CFLAGS := -I$(INCLUDE) -O -Wall

$(TARGET).o:$(TARGET).c

clean:
rm -rf $(TARGET).o

hope this is self-explanatory.
 
Old 09-02-2005, 11:56 AM   #4
Pratik H Pandya
LQ Newbie
 
Registered: Jun 2005
Location: India
Distribution: RedHat 9.0,Fedora core 3
Posts: 22

Original Poster
Rep: Reputation: 15
Hello Jasdeep Thank you for that make file. it really worked. But as i used to experiments with my PC and Operating system i've just recompile my kernel of redhat 9.0

and now i'm getting another error whenever i compile a module it get compiles successfully
but at the time of insertion it gives error like "version Mismatch error"
it is compiled for 2.4.20-8custom while the kernel version is 2.4.20-8
i tried in both the kernels but i'm getting same error. then
i read some sources and modified the code as belows

i tried some code that


#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/init.h>
#include <linux/version.h>

#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif


MODULES_LICENSE("GPL"); /* removes license warning*/
int init_module(void)
{
printk(KERN_ALERT "\nHello Kernel\n");
return 0;
}
int cleanup_module(void)
{
printk(KERN_ALERT "\nGoodbye kernel\n");
}



but still not getting the solution it will be so graceful if you can help me out

thanks in advance.
 
Old 09-02-2005, 11:54 PM   #5
jasdeep_js
LQ Newbie
 
Registered: Sep 2005
Location: Bangalore (INDIA)
Distribution: Redhat9
Posts: 10

Rep: Reputation: 0
sometimes it gives this error during insertion.I am not very sure how it can be fixed but yes,you can do one thing--compile your kernel with modversioning option OFF.just do make menuconfig,there you go to "Loadable module support" option ,select it and in that you will find "set version info on all module symbols",make it N and compile the kernel.
then there is no need for if CONFIG_MODVERSIONS code.
no need for version.h either.
also add #define MODULE in your code.
hope it will work
 
  


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
about kernel programming wangjinyi Programming 1 09-26-2005 09:23 AM
Kernel Programming. dreamz_jaleel Programming 7 04-15-2005 11:38 AM
Kernel Programming arunka Programming 1 03-01-2005 02:50 PM
Kernel Module Programming in 2.6 KneeLess Programming 3 04-13-2004 02:27 PM
Kernel Module programming Config Programming 2 03-24-2004 04:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 07:18 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