打印

hello world module for LK26

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.
附件: 您所在的用户组无法下载或查看附件
Time is always not enough!

TOP

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.

-------------------------------------------
[code:1]
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
[/code:1]
Time is always not enough!

TOP

[quote:9298c11d4f="Dragonfly"]make -C /lib/modules/`uname -r`/build/ SUBDIRS=`pwd` modules   [/quote]

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?
http://conke.3322.org kernel 2.4 & 2.6 study, embedded linux development, etc.

TOP

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 ?
http://conke.3322.org kernel 2.4 & 2.6 study, embedded linux development, etc.

TOP

In a word, could you please tell us how to compile a kernel module without the makefile inside the 2.6 kernel source?! Thanks!
http://conke.3322.org kernel 2.4 & 2.6 study, embedded linux development, etc.

TOP

currently this is the only way. pls search the lkml to know this. i think u know how to do this.
Time is always not enough!

TOP

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 ?
http://conke.3322.org kernel 2.4 & 2.6 study, embedded linux development, etc.

TOP

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 generated  step by step, from .c to .mod.c, and to .mod.o, and finally to .ko.

When you know, please inform me, will you?  
http://conke.3322.org kernel 2.4 & 2.6 study, embedded linux development, etc.

TOP

[quote:e906879b61="conke"]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 generated  step by step, from .c to .mod.c, and to .mod.o, and finally to .ko.

When you know, please inform me, will you?  [/quote]

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 各位为什么不用中文?这样讨论群体会更多些:)

TOP

[quote:9e9cc83fe5="cswbww"]Please share your experience. Thanks. [/quote] 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 be used in 2.6 kernel. Secondly, read and implement Chapter 11 of <<<>>> writen by my teacher LiShanPing (ZheJiang University). Now I will TELL you in more details:
http://conke.3322.org kernel 2.4 & 2.6 study, embedded linux development, etc.

TOP

[quote:7356a7442a="conke"]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 ?[/quote]

i think i need not to argue with you about this "ONLY". u can write machine code if you can, the third way.
Time is always not enough!

TOP

[quote:e8ebe0a0e0="conke"]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 generated  step by step, from .c to .mod.c, and to .mod.o, and finally to .ko.

When you know, please inform me, will you?  [/quote]

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.
Time is always not enough!

TOP

[quote:0222cda3eb="conke"][quote:0222cda3eb="cswbww"]Please share your experience. Thanks. [/quote] 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 be used in 2.6 kernel. Secondly, read and implement Chapter 11 of <<<>>> writen by my teacher LiShanPing (ZheJiang University). Now I will TELL you in more details:[/quote] 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.
Time is always not enough!

TOP

hehe, gxl117 get the solution. how did u find this? make V=1? ls -a?
Time is always not enough!

TOP

the further is to know why do we need these steps.  

in u module dir, ls -a, there are several .xx files. the content is interesting.  
Time is always not enough!

TOP