tadpole
tadpole

Reputation: 1219

Try to build tutorial for linux device driver

i am trying to learn how to write device driver on linux. I have looked at several online tutorials. They are simple enough but I have problem compiling it. I got a makefile error at the bottom. I have not done anything to the linux-header-2.6.32-27-generic. It is in the state that it was installed. It may be that it has some dependencies but I have no ideas which one. I am not sure what make is expecting. I would appreciate any help.

Here is my system info.

Linux rat-desktop 2.6.32-27-generic #49-Ubuntu SMP Wed Dec 1 23:52:12 UTC 2010 i686 GNU/Linux

The include files are in /usr/src/linux-headers-2.6.32-27-generic

rat@rat-desktop:/usr/src/linux-headers-2.6.32-27-generic$ ls
   arch           firmware  Kbuild    modules.order   security  usr
   block          fs        kernel    Module.symvers  sound     virt
   crypto         include   lib       net             source
   Documentation  init      Makefile  samples         tools
   drivers        ipc       mm        scripts         ubuntu


nothing.c
    #include <linux/init.h>
    #include <linux/module.h>

    MODULE_LICENSE("Dual BSD/GPL");

    static int __init hello_init(void)
    {
            printk(KERN_ALERT "Hello,world tapas\n");
            return 0;
    }
    static void __exit hello_exit(void)
    {
            printk(KERN_ALERT "Good Bye,cruel world\n");
    }

    module_init(hello_init);
    module_exit(hello_exit);

Makefile
obj-m := nothing.o

KDIR =  /usr/src/linux-headers-2.6.32-27-generic

all:
        $(MAKE) make -C $(KDIR) M=pwd modules

clean:
        rm -rf *.o *.ko *.mo.* *.symvers *.order


sudo make
make make -C /usr/src/linux-headers-2.6.32-27-generic M=pwd modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-27-generic'
make[1]: *** No rule to make target `make'.  Stop.
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-27-generic'
make: *** [all] Error 2

I used another Makefile which got me a little more detail

obj-m += nothing.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

rat@rat-desktop:~/deviceDrivers$ sudo make
make -C /lib/modules/2.6.32-27-generic/build M= modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-27-generic'
  CHK     include/linux/version.h
  CHK     include/linux/utsrelease.h
  SYMLINK include/asm -> include/asm-x86
make[2]: *** No rule to make target `kernel/bounds.c', needed by `kernel/bounds.s'.  Stop.
make[1]: *** [prepare0] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-27-generic'
make: *** [all] Error 2

Upvotes: 1

Views: 761

Answers (1)

raghav3276
raghav3276

Reputation: 1098

In the first Makefile, observe the make command that is being executed in the output when you run sudo make (generally sudo is not required to build the modules) :

make make -C /usr/src/linux-headers-2.6.32-27-generic M=pwd modules

In this case, make is searching for a target named 'make'! Remove the $(MAKE) from the Makefile and try. And also M=pwd option is incorrect!

In the second case, the PWD variable isn't defined. You can define it in the Makefile something like this : PWD := $(shell pwd)

Upvotes: 1

Related Questions