Problem building simple Linux kernel module.

Discussion in 'Embedded Systems and Microcontrollers' started by sagar474, Nov 30, 2012.

  1. sagar474

    Thread Starter New Member

    Jul 22, 2010
    16
    0
    I'm trying to build my first Linux kernel module.

    I'm running ubuntu 12.10

    Code ( (Unknown Language)):
    1. /* Module source file 'crash1.c'. */
    2. #include <linux/module.h>
    3. #include <linux/init.h>
    4. #include <linux/kernel.h>
    5.  
    6. static int hi(void)
    7. {
    8.      printk(KERN_INFO "crash1 module being loaded.\n");
    9.      return 0;
    10. }
    11.  
    12. static void bye(void)
    13. {
    14.      printk(KERN_INFO "crash1 module being unloaded.\n");
    15. }
    16.  
    17. module_init(hi);
    18. module_exit(bye);
    19.  
    20. MODULE_AUTHOR("Robert P. J. Day, http://crashcourse.ca");
    21. MODULE_LICENSE("Dual BSD/GPL");
    22. MODULE_DESCRIPTION("Doing a whole lot of nothing.");
    23.  
    24.  
    25.  
    Code ( (Unknown Language)):
    1.  
    2. ifeq ($(KERNELRELEASE),)
    3.  
    4. KERNELDIR ?= /lib/modules/$(shell uname -r)/build
    5. PWD := $(shell pwd)
    6.  
    7. .PHONY: build clean
    8.  
    9. build:
    10.     $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
    11.  
    12. clean:
    13.     rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c
    14.  
    15. else    
    16.  
    17. $(info Building with KERNELRELEASE = ${KERNELRELEASE})
    18. obj-m :=    crash1.o
    19.  
    20. endif
    21.  


    Code ( (Unknown Language)):
    1.  
    2. make -C /lib/modules/3.5.0-17-generic/build M=/home/sagar/module1 modules
    3. make[1]: Entering directory `/usr/src/linux-headers-3.5.0-17-generic'
    4. scripts/Makefile.build:44: /home/sagar/module1/Makefile: No such file or directory
    5. make[2]: *** No rule to make target `/home/sagar/module1/Makefile'.  Stop.
    6. make[1]: *** [_module_/home/sagar/module1] Error 2
    7. make[1]: Leaving directory `/usr/src/linux-headers-3.5.0-17-generic'
    8. make: *** [build] Error 2
    9.  
    10.  
     
Loading...