You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
你写的任何一个模块都需要使用她们来初始化或退出,或者说注册以及后来的注销.当你用<br />
module_init()为一个模块注册了之后,在你使用insmod 这个命令去安装的时<br />
候,module_init()注册的函数将会被执行,而当你用rmmod 这个命令去卸载一个模块的时<br />
候,module_exit()注册的函数将会被执行.module_init()被称为驱动程序的初始化入口<br />
(driver initialization entry point).<br />
怎么样演示以上代码的运行呢?没错,你需要一个Makefile.<br />
+++++++++++++++++++++Makefile++++++++++++++++++++++++<br />
+++<br />
1 # To build modules outside <strong>of</strong> the kernel tree, we run "make"<br />
2 # in the kernel source tree; the Makefile these then includes this<br />
3 # Makefile once again.<br />
4 # This conditional selects whether we are being included from the<br />
5 # kernel Makefile or not.<br />
6 ifeq ($(KERNELRELEASE),)<br />
7<br />
8 # Assume the source tree is where the running kernel was built<br />
9 # You should set KERNELDIR in the environment if it's elsewhere<br />
10 KERNELDIR ?= /lib/modules/$(shell uname -r)/build<br />
11 # The current directory is passed to sub-makes as argument<br />
12 PWD := $(shell pwd)<br />
8<br />
13<br />
14 modules:<br />
15 $(MAKE) -C $(KERNELDIR) M=$(PWD) modules<br />
16<br />
17 modules_install:<br />
18 $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install<br />
19<br />
20 clean:<br />
21 rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions<br />
22<br />
23 .PHONY: modules modules_install clean<br />
24<br />
25 else<br />
26 # called from kernel build system: just declare what our modules are<br />
27 obj-m := hello.o<br />
28 endif<br />
++++++++++++++++++++++++++++++++++++++++++++++++++<br />
++++++++++++<br />
在lwn 上可以找到这个例子,你可以把以上两个文件放在你的某个目录下,然后执行make,也许<br />
你不一定能成功,因为LK 2.6 要求你编译模块之前,必须先在内核源代码目录下执行make,换言<br />
之,你必须先配置过内核,执行过make,然后才能make 你自己的模块.原因我就不细说了,你按<br />
着她要求的这么去做就行了.在内核顶层目录make 过之后,你就可以在你当前放置Makefile<br />
的