LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 04-18-2008, 06:31 AM   #1
mohit.saha
LQ Newbie
 
Registered: Feb 2008
Posts: 15

Rep: Reputation: 0
Unhappy Cannot Load Kernel Loadable MOdule...


hi everybody,

I tried to create a new module as given in http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html, hello-1.c.

Code:
/*  
 *  hello-1.c - The simplest kernel module.
 */
#include <linux/module.h>	/* Needed by all modules */
#include <linux/kernel.h>	/* Needed for KERN_INFO */

int init_module(void)
{
	printk(KERN_INFO "Hello world 1.\n");

	/* 
	 * A non 0 return means init_module failed; module can't be loaded. 
	 */
	return 0;
}

void cleanup_module(void)
{
	printk(KERN_INFO "Goodbye world 1.\n");
}
and then created the Makefile as

Code:
obj-m += hello-1.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
and then make that... but the following errors are coming:

Code:
[root@dhcp-ptp2-10-177-142-249 LKM]# make
make -C /lib/modules/2.6.22.5/build M=/root/Desktop/LKM modules
make[1]: Entering directory `/usr/src/linux-2.6.22.5'
  Building modules, stage 2.
  MODPOST 0 modules
WARNING: vmlinux(.text+0xc040116f): Section mismatch: reference to .init.text:start_kernel (between 'is386' and 'check_x87')
WARNING: vmlinux(.text+0xc061fc70): Section mismatch: reference to .init.text: (between 'rest_init' and 'alloc_node_mem_map')
WARNING: vmlinux(.text+0xc062460a): Section mismatch: reference to .init.text: (between 'iret_exc' and '_etext')
WARNING: vmlinux(.text+0xc0624616): Section mismatch: reference to .init.text: (between 'iret_exc' and '_etext')
WARNING: vmlinux(.text+0xc0624622): Section mismatch: reference to .init.text: (between 'iret_exc' and '_etext')
WARNING: vmlinux(.text+0xc062462e): Section mismatch: reference to .init.text: (between 'iret_exc' and '_etext')
WARNING: vmlinux(.text+0xc061fcf0): Section mismatch: reference to .init.text:__alloc_bootmem_node (between 'alloc_node_mem_map' and 'zone_wait_table_init')
WARNING: vmlinux(.text+0xc061fd96): Section mismatch: reference to .init.text:__alloc_bootmem_node (between 'zone_wait_table_init' and 'setup_cpu_cache')
WARNING: vmlinux(.text+0xc061fe11): Section mismatch: reference to .init.text: (between 'setup_cpu_cache' and 'schedule')
WARNING: vmlinux(.text+0xc061fe4b): Section mismatch: reference to .init.text: (between 'setup_cpu_cache' and 'schedule')
WARNING: vmlinux(.text+0xc05066f2): Section mismatch: reference to .init.text:__alloc_bootmem (between 'vgacon_startup' and 'vgacon_scrolldelta')
WARNING: vmlinux(.text+0xc0624dc2): Section mismatch: reference to .init.text: (between 'iret_exc' and '_etext')
make[1]: Leaving directory `/usr/src/linux-2.6.22.5'
can u suggest what is the problem?
Also if anyone can suggest me gd book on Kernel Module Programming for LInux 2.6..

Thanks in advance...
 
Old 04-18-2008, 06:55 AM   #2
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 492

Rep: Reputation: 50
The bible:
http://lwn.net/Kernel/LDD3/
 
Old 04-18-2008, 08:50 AM   #3
mohit.saha
LQ Newbie
 
Registered: Feb 2008
Posts: 15

Original Poster
Rep: Reputation: 0
I inserted the code:

Code:
/*  
 *  hello-1.c - The simplest kernel module.
 */
#include <linux/module.h>	/* Needed by all modules */
#include <linux/kernel.h>	/* Needed for KERN_INFO */

int init_module(void)
{
	printk(KERN_INFO "Hello world 1.\n");

	/* 
	 * A non 0 return means init_module failed; module can't be loaded. 
	 */
	return 0;
}

void cleanup_module(void)
{
	printk(KERN_INFO "Goodbye world 1.\n");
}


module_init(init_module);
module_exit(cleanup_module);
but it is still giving some error...

Code:
[mohit@dhcp-ptp2-10-177-142-249 LKM]$ make
make -C /lib/modules/2.6.22.5/build M=/home/mohit/Desktop/LKM modules
make[1]: Entering directory `/usr/src/linux-2.6.22.5'
  CC [M]  /home/mohit/Desktop/LKM/hello-1.o
/home/mohit/Desktop/LKM/hello-1.c:23: error: redefinition of ‘init_module’
/home/mohit/Desktop/LKM/hello-1.c:8: error: previous definition of ‘init_module’ was here
/home/mohit/Desktop/LKM/hello-1.c:24: error: redefinition of ‘cleanup_module’
/home/mohit/Desktop/LKM/hello-1.c:18: error: previous definition of ‘cleanup_module’ was here
make[2]: *** [/home/mohit/Desktop/LKM/hello-1.o] Error 1
make[1]: *** [_module_/home/mohit/Desktop/LKM] Error 2
make[1]: Leaving directory `/usr/src/linux-2.6.22.5'
make: *** [all] Error 2
Now tell me what is the problem....
 
Old 04-18-2008, 10:00 AM   #4
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
I'm far from expert, but based on what I see there, I wonder if:

1) one of the 2 files you are including, includes the other already (so you are including it twice)
and
2) are your kernel headers installed properly? (Like, appropriate headers for your kernel, correct location, etc..)?

Sasha
 
  


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
How to create new process from within loadable kernel module? mtb001 Programming 5 08-31-2007 11:09 PM
how to insert a loadable module into the kernel.? moog Linux - Newbie 2 01-08-2007 08:37 AM
Help, loadable kernel module . ERBRMN Linux - General 3 10-13-2006 07:34 AM
how to add new loadable module to kernel? Mistreated Linux - Software 7 02-02-2005 10:22 AM
loadable kernel module brajesh Linux - General 2 01-17-2003 12:54 AM


All times are GMT -5. The time now is 03:32 PM.

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