I am trying to write kernel modules. And am running Ubuntu 10.04 x64. I have downloaded both kernel source and headers. Unpacked kernel source and made a /usr/src/linux symbolic link pointing to the src.
Here is the output of running make:
Code:
make -C /lib/modules/2.6.32-22-generic/build M= modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-22-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-22-generic'
make: *** [all] Error 2
Here is my Makefile:
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 here is my simple module:
Code:
#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 failes; module can't be loaded.
*/
return 0;
}
void cleanup_module (void)
{
printk (KERN_INFO "Good night world 1.\n");
}
I am taking both the module and the Makefile from Linux Kernel Module Programming Guide book. I don't know what am missing. So any help would be appreciated.
Thanks in advance.