Re: [轉錄][問題]kernel跟驅動程式版本不合
※ 引述《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
推
04/13 10:39, , 1F
04/13 10:39, 1F
→
04/13 11:20, , 2F
04/13 11:20, 2F
※ 編輯: wlsabcd 來自: 203.73.175.134 (04/13 20:12)
推
04/13 20:12, , 3F
04/13 20:12, 3F
→
04/13 20:13, , 4F
04/13 20:13, 4F
→
04/13 20:14, , 5F
04/13 20:14, 5F
→
04/13 20:54, , 6F
04/13 20:54, 6F
→
04/13 20:55, , 7F
04/13 20:55, 7F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 5 篇):
LinuxDev 近期熱門文章
PTT數位生活區 即時熱門文章