hello world module for LK26
Linux kernel 2.6 changes much on module programming. So some people are asking how to write the module for 2.6. And the main issue is known that we need a suitable Makefile.so here I attach a small example hello world style module. The change in hello.c is minor, only need to add that <linux/init.h>. the main change is the Makefile. I tested it under 2.6.0-test8 and test9. should be able to work under other 2.6 version.
good luck on u 2.6 trip. am i stupid? i can not attach two files at one time. sigh. and I can not attach the makefile. so i have to post it here.
-------------------------------------------
EXTRA_LDFLAGS += -t
obj-m += hello.o
CLEAN_OBJS := built-in.o hello.ko hello.o hello.mod.c hello.mod.o
standalone:
make -C /lib/modules/`uname -r`/build/ SUBDIRS=`pwd` modules
.PHONY: clean
clean:
@for i in $(CLEAN_OBJS); do \
(if [ -f $$i ] ; \
then \
echo $$i; \
rm -f $$i ; \
else \
: ;\
fi); \
done
make -C /lib/modules/`uname -r`/build/ SUBDIRS=`pwd` modules:lol:
You do the same job with me! but unfortunately it is not what I need.
All that you do(or say, what I had done) is just to use the makefile inside the kernel source.
Can you write one by yourself? I want to know how the .mod.c .mod.o and .ko are generated step by step. Which commands or compiling options(or something else) should be used ? In a word, could you please tell us how to compile a kernel module without the makefile inside the 2.6 kernel source?! Thanks! currently this is the only way. pls search the lkml to know this. i think u know how to do this.
:-D Ha ha ha, maybe not (?)
It cannot be the ONLY way. Think that we could trace the compiling commands in the makefiles and extract them all, and put all the usefull commands into a sigle makefile.
Can you do that ? If your aim were just to compile kernel modules, there would be no need knowing "how" but, as a kernel developer(or just a kernel fan), you(or me) should know exactly how the .ko is generatedstep by step, from .c to .mod.c, and to .mod.o, and finally to .ko.
When you know, please inform me, will you?:lol: If your aim were just to compile kernel modules, there would be no need knowing "how" but, as a kernel developer(or just a kernel fan), you(or me) should know exactly how the .ko is generatedstep by step, from .c to .mod.c, and to .mod.o, and finally to .ko.
When you know, please inform me, will you?:lol:
sorry, as far as i know, a kernel fan mostly posts his idea first, just like Dragon, then sits back and argues with others. Not always ask people to tell him this or that. Please share your experience. Thanks.
By the way, i am a newbie but 各位为什么不用中文?这样讨论群体会更多些:) Please share your experience. Thanks.
OK, let me tell you two ways to study how to write kernel module in linux 2.6 kernel, which have heen found by myself instend of COPYing from other web pages!
Firstly, study the Makefile of nvidia driver(after being patched) which can beused in 2.6 kernel.
Secondly, read and implement Chapter 11 of <<<<Bian Xue Bian Gan--Linux Nei He Zhi Dao>>>> writen by my teacher LiShanPing (ZheJiang University).
Now I will TELL you in more details: Ha ha ha, maybe not (?)
It cannot be the ONLY way. Think that we could trace the compiling commands in the makefiles and extract them all, and put all the usefull commands into a sigle makefile.
Can you do that ?
i think i need not to argue with you about this "ONLY". u can write machine code if you can, the third way. If your aim were just to compile kernel modules, there would be no need knowing "how" but, as a kernel developer(or just a kernel fan), you(or me) should know exactly how the .ko is generatedstep by step, from .c to .mod.c, and to .mod.o, and finally to .ko.
When you know, please inform me, will you?:lol:
yes, as a developer, i should know as more as possible. currently i have something more important to do, so i only need to make my module workable under 2.6. if you have time, u can try to know that (or u might already know) then post u experience here.
btw, to know the commands used to compile kernel is quite easy. u should know that if you are a developer and stick to know every detail. Please share your experience. Thanks.
OK, let me tell you two ways to study how to write kernel module in linux 2.6 kernel, which have heen found by myself instend of COPYing from other web pages!
Firstly, study the Makefile of nvidia driver(after being patched) which can beused in 2.6 kernel.
Secondly, read and implement Chapter 11 of <<<<Bian Xue Bian Gan--Linux Nei He Zhi Dao>>>> writen by my teacher LiShanPing (ZheJiang University).
Now I will TELL you in more details:
yes, pls give us more detail. you still ask us to go and see this and that. pls give us the results directly, as you had suggested.
:-D hehe, gxl117 get the solution. how did u find this? make V=1? ls -a? :-D the further is to know why do we need these steps.:-D
in u module dir, ls -a, there are several .xx files. the content is interesting.:-D
页:
[1]
2