QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5872|回复: 18

hello world module for LK26

[复制链接]
发表于 2003-10-29 05:16:48 | 显示全部楼层 |阅读模式
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.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| 发表于 2003-10-29 05:21:00 | 显示全部楼层
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]
回复

使用道具 举报

发表于 2003-10-29 15:18:50 | 显示全部楼层
[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?
回复

使用道具 举报

发表于 2003-10-29 15:31:07 | 显示全部楼层
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 ?
回复

使用道具 举报

发表于 2003-10-29 15:34:44 | 显示全部楼层
In a word, could you please tell us how to compile a kernel module without the makefile inside the 2.6 kernel source?! Thanks!
回复

使用道具 举报

 楼主| 发表于 2003-10-29 22:51:41 | 显示全部楼层
currently this is the only way. pls search the lkml to know this. i think u know how to do this.
回复

使用道具 举报

发表于 2003-10-29 23:19:35 | 显示全部楼层
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 ?
回复

使用道具 举报

发表于 2003-10-29 23:28:10 | 显示全部楼层
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?  
回复

使用道具 举报

发表于 2003-10-30 03:07:39 | 显示全部楼层
[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 各位为什么不用中文?这样讨论群体会更多些:)
回复

使用道具 举报

发表于 2003-10-30 04:08:06 | 显示全部楼层
[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 &lt;&lt;&lt;<Bian Xue Bian Gan--Linux Nei He Zhi Dao>&gt;&gt;&gt; writen by my teacher LiShanPing (ZheJiang University).

  Now I will TELL you in more details:
回复

使用道具 举报

 楼主| 发表于 2003-10-30 07:09:21 | 显示全部楼层
[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.
回复

使用道具 举报

 楼主| 发表于 2003-10-30 07:13:04 | 显示全部楼层
[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.
回复

使用道具 举报

 楼主| 发表于 2003-10-30 07:14:53 | 显示全部楼层
[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 &lt;&lt;&lt;<Bian Xue Bian Gan--Linux Nei He Zhi Dao>&gt;&gt;&gt; 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.

回复

使用道具 举报

 楼主| 发表于 2003-10-30 12:08:57 | 显示全部楼层
hehe, gxl117 get the solution. how did u find this? make V=1? ls -a?
回复

使用道具 举报

 楼主| 发表于 2003-10-31 02:09:06 | 显示全部楼层
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.  
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-16 06:25 , Processed in 0.078870 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表