LinuxDev 板


LINE

※ 引述《andytzeng (Ya-Shiuan)》之铭言: : 推 andytzeng:事实上..执行 make install 就会帮你 copy config file 04/08 18:35 : → andytzeng:再者, 2.6.18, 2.6.19, 2.6.20 许多 module 位置换地方 04/08 18:36 : → andytzeng:因此直接套用就会发现部分功能出问题(尤其 iptables) 04/08 18:36 感谢各位的帮忙,在此奉上一篇(最简的的Kernel module)以回报本版。 这只是入门而已,当然高手可以省略此篇 make a directory named as "module_begin" Edit a make file as: #################################################################### # Make file begine # #################################################################### obj-m := hello.o KERNELDIR ?= /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) all: $(MAKE) -C $(KERNELDIR) M=$(PWD) clean: @rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions \ Module.symvers #################################################################### # Make file End # #################################################################### Edit hello.c as: /*************************************************************************** * Hello.c Begin ***************************************************************************/ #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #define ENABLE_DMSG 1 #if(1 == ENABLE_DMSG) #define MSG(X...) printk(KERN_ALERT __FILE__ ": " X) #else #define MSG(X...) do { } while (0) #endif static int __init hello_init(void) { MSG(KERN_ALERT "Hello Driver!\n"); return 0; } static void __exit hello_exit(void) { MSG(KERN_ALERT "Goodbye Driver!\n"); } module_init( hello_init); module_exit( hello_exit); MODULE_LICENSE( "GPL" ); MODULE_AUTHOR( "MyName" ); /************************************************************************** * Hello.c End **************************************************************************/ type "make" command to make, the result ought to be make -C /lib/modules/2.6.19-rc6/build M=/root/code/module_begin make[1]: Entering directory `/usr/src/linux-2.6.18' LD /root/code/module_begin/built-in.o CC [M] /root/code/module_begin/hello.o Building modules, stage 2. MODPOST 1 modules CC /root/code/module_begin/hello.mod.o LD [M] /root/code/module_begin/hello.ko make[1]: Leaving directory `/usr/src/linux-2.6.18' use the command "insmod hello.ko" to install hello module, then "dmesg" the messgae is /root/code/module_begin/hello.c: <1>Hello Driver! use the command "rmmod hello" to remove hello module, the message is /root/code/module_begin/hello.c: <1>Goodbye Driver! P.S. 太久没写Linux driver了,没想到变了这麽多。 --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 203.73.175.134
1F:推 andytzeng:w大该不会之前是在 2.4 上面写 driver 吧..!! 04/13 10:39
2F:→ wlsabcd:早上赶着上班,程式有误,下班之後再补 04/13 11:20
※ 编辑: wlsabcd 来自: 203.73.175.134 (04/13 20:12)
3F:推 wlsabcd:错误地方以补足 04/13 20:12
4F:→ wlsabcd:我之前写driver是为了project需求,还没有module的观念 04/13 20:13
5F:→ wlsabcd:现在感觉完全是新手一样 04/13 20:14
6F:→ wlsabcd:我上上篇是指我之之前写linux driver时,linux还没导入 04/13 20:54
7F:→ wlsabcd:module的观念 04/13 20:55







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Tech_Job站内搜寻

TOP