LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 02-04-2007, 06:45 AM   #1
yannifan
Member
 
Registered: Feb 2007
Location: Bangalore, India
Distribution: Ubuntu Feisty, Fedora 6 dual boot
Posts: 36

Rep: Reputation: 15
Making kernel module


Hello ppl,
Im new to kernel programming and have been trying to build my first kernel module 'hello world'

Im totally confused even after checking many posts.

My source file is hello.c :
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
printk(KERN_ALERT "Hello World\n");
return 0;
}
static int hello_exit(void)
{
printk(KERN_ALERT "Goodbye!\n");
return 0;
}
module_init(hello_init);
module_init(hello_exit);

I installed a kernel tree from kernel.org(2.6.1
then i did "make config"
this is in /usr/src/linux-2.6.28.6

The Makefile addition is :

#Hello World module
obj-m += hello.ko
KDIR = /usr/src/linux-2.6.18.6/
SUBDIRS = $(PWD)
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
modules:
$(MAKE) -C $(KDIR) M=$(SUBDIRS) $@

Im not sure if this is correct (/lib/modules/2/6/15-27-386/build exists)
The source file is in /usr/src/linux*

I have linuxheaders installed in /usr/src
ie. /usr/src/linux-headers-2.6.15-27
and linux-headers-2.6.15-27-386 exist

donno wat to do after tat!!!

Am i in the rite direction.... How do i continue???
Pls help Am using ubuntu dapper drake

Cheers

PS: sorry if its a duplicate post couldnt help.
Reply With Quote
 
Old 02-04-2007, 08:00 AM   #2
Franklin52
LQ Newbie
 
Registered: Nov 2006
Posts: 6

Rep: Reputation: 0
The version of the header and source files must match your kernel.
Check your kernel version with:
Code:
uname -r
If they don't google for how to install them.

And try this Makefile:
Code:
obj-m	+= hello.o
all:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
BTW the whitespace before the command make must be the tab character; eight spaces will
not suffice.

Regards
 
  


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
[Error] Kernel Module : No kernel module build environment saman007uk Debian 7 09-09-2006 06:34 PM
Making rtl8139.o module Hondro Slackware 1 08-28-2006 11:32 PM
error making a module e13438 Linux - Networking 2 11-24-2005 12:52 PM
module making linuxhippy Slackware 3 03-26-2005 02:01 PM
kernel module ignorant newbie looking for any one with kernel module knowledge cpoet Slackware 4 11-24-2003 09:37 PM

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

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