Results 1 to 9 of 9
These two files i have created in som efolder in home dir
1)hello-1.c
2)Makefile
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
int ...
- 01-04-2008 #1Just Joined!
- Join Date
- Jul 2006
- Posts
- 20
need help to start kernel module programming
These two files i have created in som efolder in home dir
1)hello-1.c
2)Makefile
#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");
}
---------------------------------------------------------------------------
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
------------------------------------------------------------------------------
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
-vinay
- 01-05-2008 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Place one real tab before a make statement (not spaces!):
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
Regards
- 01-07-2008 #3Just Joined!
- Join Date
- Jul 2006
- Posts
- 20
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/2.6.23.1-42.fc8 /build M=/root/myComp/research/linKer/hello-1 modules
make[1]: Entering directory `/lib/modules/2.6.23.1-42.fc8'
make[1]: *** No rule to make target `/build'. Stop.
make[1]: Leaving directory `/lib/modules/2.6.23.1-42.fc8'
make: *** [all] Error 2
--------------------------------------------------------------------------------------------------------
"[all] Error 2" where does the actual error happened...!
- 01-08-2008 #4
Do you have the kernel sources (`uname -r`) under /lib/modules
i.e.
[amit@localhost modules]$ pwd
/lib/modules
[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 System.map vmlinux
COPYING cscope.out fs ipc lib mm README security tmp vmlinux.o
~amit
- 01-08-2008 #5Just Joined!
- Join Date
- Jun 2006
- Posts
- 29
I suggest u to use below commands to compile ur module
if ur trying #make it wont work , it works with #make modules and still it need to support loadable kernel module.Code:#gcc -c -O2 -Wall -isystem /lib/modules/`uname -r`/build/include -D__KERNEL__ -DMODULE xxxxx.c
Anyhow go through Makefile programming once to understand
- 01-08-2008 #6Just Joined!
- Join Date
- Jul 2006
- Posts
- 20
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/2.6.23.1-42.fc8/build/include/linux/prefetch.h:14,
from /lib/modules/2.6.23.1-42.fc8/build/include/linux/list.h:8,
from /lib/modules/2.6.23.1-42.fc8/build/include/linux/module.h:9,
from hello-1.c:1:
/lib/modules/2.6.23.1-42.fc8/build/include/asm/processor.h:83: error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function)
/lib/modules/2.6.23.1-42.fc8/build/include/asm/processor.h:83: error: requested alignment is not a constant
In file included from /lib/modules/2.6.23.1-42.fc8/build/include/linux/module.h:20,
from hello-1.c:1:
/lib/modules/2.6.23.1-42.fc8/build/include/asm/module.h:69:2: error: #error unknown processor family
- 01-09-2008 #7Just Joined!
- Join Date
- Jun 2006
- Posts
- 29
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
#make modules
#make modules_install
try
#make help --for more
Go through any document on Kernel compilation before you start, just google..
- 01-09-2008 #8Just Joined!
- Join Date
- Jul 2006
- Posts
- 20
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 .!
- 01-09-2008 #9Just Joined!
- Join Date
- Jul 2006
- Posts
- 20
ashok1
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.. .


Reply With Quote
