November 22, 2024, 04:37:44 AM

News : LinuxSolved.com Linux Help Community Forum..


Author Topic: Cannot Load Kernel Loadable MOdule...  (Read 6435 times)

Offline mohit.saha

  • Linux Noob !
  • *
  • Posts: 10
Cannot Load Kernel Loadable MOdule...
« on: April 18, 2008, 11:39:36 AM »
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: [Select]
/* 
 *  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: [Select]
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: [Select]
[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...:)

Offline mohit.saha

  • Linux Noob !
  • *
  • Posts: 10
Re: Cannot Load Kernel Loadable MOdule...
« Reply #1 on: April 18, 2008, 02:02:17 PM »
I inserted the code:

Code: [Select]
/* 
 *  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: [Select]
[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....