sonicbs
May 28th, 2010, 04:53 PM
Hi, I am trying to learn how to write a kernel module.
I am following the excellent guide from The Linux Documentation Project (http://tldp.org/) called The Linux Kernel Module Programming Guide v.2.6.4 (http://tldp.org/LDP/lkmpg/2.6/html/index.html).
My machine is running Ubuntu Lucid Lynx (10.04)
uname -r
2.6.32-22-generic
I installed the corresponding linux headers and just to make sure I also installed the linux source and extracted it in /usr/src
I am trying to run the following trivial kernel module
/*
* 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_ALERT "Goodbye world 1.\n");
}
with the following Makefile
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
as it appears in pages 5 and 6 of the pdf version of the tutorial above.
I got the following error from make
uname: extra operand `−r'
Try `uname --help' for more information.
make −C /lib/modules//build M=/home/sonny/km modules
make[1]: Entering directory `/home/sonny/km'
make[1]: *** No rule to make target `−C'. Stop.
make[1]: Leaving directory `/home/sonny/km'
make: *** [all] Error 2
So, from the first and third lines I saw there was a problem with uname -r
so I changed the Makefile to
obj−m += hello-1.o
KVERSION = $(shell uname -r)
all:
make −C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make −C /lib/modules/$(KVERSION)/build M=$(PWD) clean
and then running make corrected the first error, but I still get the following:
make −C /lib/modules/2.6.32-22-generic/build M=/home/sonny/km modules
make[1]: Entering directory `/home/sonny/km'
make[1]: *** No rule to make target `−C'. Stop.
make[1]: Leaving directory `/home/sonny/km'
make: *** [all] Error 2
What am I doing wrong? All the headers are in place and the source is there as well.
lib/modules/2.6.32-22-generic links to (what I think are) the right places.
Any help would be much appreciated.
Thanks a lot!
I am following the excellent guide from The Linux Documentation Project (http://tldp.org/) called The Linux Kernel Module Programming Guide v.2.6.4 (http://tldp.org/LDP/lkmpg/2.6/html/index.html).
My machine is running Ubuntu Lucid Lynx (10.04)
uname -r
2.6.32-22-generic
I installed the corresponding linux headers and just to make sure I also installed the linux source and extracted it in /usr/src
I am trying to run the following trivial kernel module
/*
* 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_ALERT "Goodbye world 1.\n");
}
with the following Makefile
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
as it appears in pages 5 and 6 of the pdf version of the tutorial above.
I got the following error from make
uname: extra operand `−r'
Try `uname --help' for more information.
make −C /lib/modules//build M=/home/sonny/km modules
make[1]: Entering directory `/home/sonny/km'
make[1]: *** No rule to make target `−C'. Stop.
make[1]: Leaving directory `/home/sonny/km'
make: *** [all] Error 2
So, from the first and third lines I saw there was a problem with uname -r
so I changed the Makefile to
obj−m += hello-1.o
KVERSION = $(shell uname -r)
all:
make −C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make −C /lib/modules/$(KVERSION)/build M=$(PWD) clean
and then running make corrected the first error, but I still get the following:
make −C /lib/modules/2.6.32-22-generic/build M=/home/sonny/km modules
make[1]: Entering directory `/home/sonny/km'
make[1]: *** No rule to make target `−C'. Stop.
make[1]: Leaving directory `/home/sonny/km'
make: *** [all] Error 2
What am I doing wrong? All the headers are in place and the source is there as well.
lib/modules/2.6.32-22-generic links to (what I think are) the right places.
Any help would be much appreciated.
Thanks a lot!