LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Cannot Load Kernel Loadable MOdule... (http://www.linuxquestions.org/questions/linux-software-2/cannot-load-kernel-loadable-module-636209/)

mohit.saha 04-18-2008 06:31 AM

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...:)

jf.argentino 04-18-2008 06:55 AM

The bible:
http://lwn.net/Kernel/LDD3/

mohit.saha 04-18-2008 08:50 AM

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....

GrapefruiTgirl 04-18-2008 10:00 AM

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


All times are GMT -5. The time now is 02:12 AM.