Find the answer to your Linux question:
Results 1 to 9 of 9
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    need help to start kernel module programming

    These two files i have created in som efolder in home dir

    #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");



    obj−m += hello−1.o
    make −C /lib/modules/$(shell uname −r)/build M=$(PWD) modules
    make −C /lib/modules/$(shell uname −r)/build M=$(PWD) clean


    when i tried
    $ make
    make: Nothing to be done for `all'.

    i tried to compile the c file directly with gcc.

    it is not able to find kernel.h and module.h

    then i gave the whole path . even then it is giving some library errors only .

    How can i made this first step SUCCESSFULL.,

    pls help me.. i am very much interested in learning kernel.

    thanks & regards

  2. #2

    Thumbs up

    Place one real tab before a make statement (not spaces!):

    obj−m += hello−1.o
    	make −C /lib/modules/$(shell uname −r)/build M=$(PWD) modules
    	make −C /lib/modules/$(shell uname −r)/build M=$(PWD) clean


  3. #3
    thanks franklin!

    i changed the make file as u said. now it has started compiling the file.

    still it is not successfully compiling. here is the error after doing "make"
    make -C /lib/modules/ /build M=/root/myComp/research/linKer/hello-1 modules
    make[1]: Entering directory `/lib/modules/'
    make[1]: *** No rule to make target `/build'. Stop.
    make[1]: Leaving directory `/lib/modules/'
    make: *** [all] Error 2

    "[all] Error 2" where does the actual error happened...!

  4. $spacer_open
  5. #4
    Just Joined! amit4g's Avatar
    Join Date
    Feb 2007
    Do you have the kernel sources (`uname -r`) under /lib/modules

    [amit@localhost modules]$ pwd
    [amit@localhost modules]$ ls `uname -r`/source
    arch CREDITS Documentation include Kbuild MAINTAINERS Module.symvers REPORTING-BUGS sound usr
    block crypto drivers init kernel Makefile net scripts vmlinux
    COPYING cscope.out fs ipc lib mm README security tmp vmlinux.o


  6. #5
    I suggest u to use below commands to compile ur module
    #gcc -c -O2 -Wall -isystem /lib/modules/`uname -r`/build/include -D__KERNEL__ -DMODULE xxxxx.c
    if ur trying #make it wont work , it works with #make modules and still it need to support loadable kernel module.

    Anyhow go through Makefile programming once to understand

  7. #6
    Ashok! and amit thanQ.!
    i wil go thru MAKE FILE programming .!

    ashok ,.! i tried with ur string.! it gave me following error.

    one thing is : "#make modules and still it need to support loadable kernel module."

    i have heard this before .. currently i am using FC8 and KUBUNTU 7.04 linux= for practicing this stuff, How can me make a kernel.. to module loadable kerel???????

    do we really need makefile programming?? before starting kernel programming??

    ================================================== ================
    [root@localhost hello-1]# gcc -c -O2 -Wall -isystem /lib/modules/`uname -r`/build/include -D__KERNEL__ -DMODULE hello-1.c
    In file included from /lib/modules/,
    from /lib/modules/,
    from /lib/modules/,
    from hello-1.c:1:
    /lib/modules/ error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function)
    /lib/modules/ error: requested alignment is not a constant
    In file included from /lib/modules/,
    from hello-1.c:1:
    /lib/modules/ error: #error unknown processor family

  8. #7
    Makefile prograaming is simple all you need to do is understanding normal makefile and device driver makefile.

    Re-compile kernel to support loadable modules

    #make menuconfig --> check loadable kernel module support
    #make modules
    #make modules_install

    #make help --for more

    Go through any document on Kernel compilation before you start, just google..

  9. #8
    thanks Ashok..

    on emistake i have done in make file.

    i included a space b4 /build.
    "make −C /lib/modules/$(shell uname −r)/build M=$(PWD) modules"

    all .o .ko files are created..

    thanks alot .!

  10. #9

    jus now i have done insmod hello-1.ko

    now os is behaving strangely
    keys are not functioning well. greater than symbol is not working .. same with grep symbol.

    also.. when i tried to see in /proc/modules file. hello-1.ko is no where

    even in modprobe it is not listed...
    why is kernel behaving like this... did it gone panic.. .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts