添加代码、Kconfig和Makefile
在linux-2.6.31/drivers/char目录下建立子目录:
bhsong@bhsong-laptop:~/develop/svn/ldd6410/linux-2.6.31/drivers/char$ mkdir driver_examples
将三个驱动hello.c、globalmem.c、globalfifo.c拷入driver_examples目录:
cd driver_examples/
cp ../../../../training/kernel/drivers/hello/hello.c ./
cp ../../../../training/kernel/drivers/globalmem/globalmem.c ./
cp ../../../../training/kernel/drivers/globalmem/globalfifo.c ./
修改drivers/char下面的Kconfig和Makefile导入driver_examples目录:
- 在drivers/char/Kconfig中添加:
source "drivers/char/driver_examples/Kconfig"
添加drivers/char/driver_examples/Kconfig文件:
#
# driver examples configuration
#
menuconfig DRIVER_EXAMPLE
tristate "driver examples in 'Explain Linux Device Drivers in detail'"
---help---
say Yes to build-in hello world, globalmem, globalfifo, say M to get
those kernel modules
if DRIVER_EXAMPLE
config HELLO_WORLD
tristate "Hello World"
---help---
To compile this driver as a module, choose M here; the module will be
called hello.mem
config GLOBALMEM
tristate "globalmem"
---help---
To compile this driver as a module, choose M here; the module will be
called globalmem.
config GLOBALFIFO
tristate "globalfifo"
---help---
To compile this driver as a module, choose M here; the module will be
called globalfifo.
endif # DRIVER_EXAMPLE
这将形成如下菜单:
driver examples in 'Explain Linux Device Drivers in detail' ─────────────────────────────┐
│ Arrow keys navigate the menu. <Enter> selects submenus --->. Highlighted letters are hotkeys. Pressing <Y> │
│ includes, <N> excludes, <M> modularizes features. Press <Esc><Esc> to exit, <?> for Help, </> for Search. Legend: │
│ [*] built-in [ ] excluded <M> module < > module capable │
│ │
│ ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │
│ │ --- driver examples in 'Explain Linux Device Drivers in detail' │ │
│ │ < > Hello World (NEW) │ │
│ │ < > globalmem (NEW) │ │
│ │ < > globalfifo (NEW) │ │
│ │ │ │
│ │ │ │
│ │
- 在drivers/char/Makefile中添加:
obj-$(CONFIG_DRIVER_EXAMPLE) += driver_examples/
添加drivers/char/driver_examples/Makefile文件:
obj-$(CONFIG_HELLO_WORLD) += hello.o
obj-$(CONFIG_GLOBALMEM) += globalmem.o
obj-$(CONFIG_GLOBALFIFO) += globalfifo.o
相关的Kconfig和Makefile patch如下:
Index: drivers/char/Kconfig
===================================================================
--- drivers/char/Kconfig (revision 87)
+++ drivers/char/Kconfig (working copy)Index: drivers/char/driver_examples/Makefile
===================================================================
--- drivers/char/driver_examples/Makefile (revision 0)
+++ drivers/char/driver_examples/Makefile (revision 0)
@@ -0,0 +1,3 @@
+obj-$(CONFIG_HELLO_WORLD) += hello.o
+obj-$(CONFIG_GLOBALMEM) += globalmem.o
+obj-$(CONFIG_GLOBALFIFO) += globalfifo.o
@@ -1110,5 +1110,7 @@
source "drivers/s390/char/Kconfig"
+source "drivers/char/driver_examples/Kconfig"
+
endmenu
Index: drivers/char/Makefile
===================================================================
--- drivers/char/Makefile (revision 87)
+++ drivers/char/Makefile (working copy)
@@ -111,6 +111,8 @@
obj-$(CONFIG_JS_RTC) += js-rtc.o
js-rtc-y = rtc.o
+obj-$(CONFIG_DRIVER_EXAMPLE) += driver_examples/
+
# Files generated that shall be removed upon make clean
clean-files := consolemap_deftbl.c defkeymap.c
Index: drivers/char/driver_examples/Kconfig
===================================================================
--- drivers/char/driver_examples/Kconfig (revision 0)
+++ drivers/char/driver_examples/Kconfig (revision 0)
@@ -0,0 +1,31 @@
+#
+# driver examples configuration
+#
+
+menuconfig DRIVER_EXAMPLE
+ tristate "driver examples in 'Explain Linux Device Drivers in detail'"
+ ---help---
+ say Yes to build-in hello world, globalmem, globalfifo, say M to get
+ those kernel modules
+
+if DRIVER_EXAMPLE
+
+config HELLO_WORLD
+ tristate "Hello World"
+ ---help---
+ To compile this driver as a module, choose M here; the module will be
+ called hello.
+
+config GLOBALMEM
+ tristate "globalmem"
+ ---help---
+ To compile this driver as a module, choose M here; the module will be
+ called globalmem.
+
+config GLOBALFIFO
+ tristate "globalfifo"
+ ---help---
+ To compile this driver as a module, choose M here; the module will be
+ called globalfifo.
+
+endif # DRIVER_EXAMPLE
+Index: drivers/char/Kconfig
===================================================================
--- drivers/char/Kconfig (revision 87)
+++ drivers/char/Kconfig (working copy)
@@ -1110,5 +1110,7 @@
source "drivers/s390/char/Kconfig"
+source "drivers/char/driver_examples/Kconfig"
+
endmenu
Index: drivers/char/Makefile
===================================================================
--- drivers/char/Makefile (revision 87)
+++ drivers/char/Makefile (working copy)
@@ -111,6 +111,8 @@
obj-$(CONFIG_JS_RTC) += js-rtc.o
js-rtc-y = rtc.o
+obj-$(CONFIG_DRIVER_EXAMPLE) += driver_examples/
+
# Files generated that shall be removed upon make clean
clean-files := consolemap_deftbl.c defkeymap.c
Index: drivers/char/driver_examples/Kconfig
===================================================================
--- drivers/char/driver_examples/Kconfig (revision 0)
+++ drivers/char/driver_examples/Kconfig (revision 0)
@@ -0,0 +1,31 @@
+#
+# driver examples configuration
+#
+
+menuconfig DRIVER_EXAMPLE
+ tristate "driver examples in 'Explain Linux Device Drivers in detail'"
+ ---help---
+ say Yes to build-in hello world, globalmem, globalfifo, say M to get
+ those kernel modules
+
+if DRIVER_EXAMPLE
+
+config HELLO_WORLD
+ tristate "Hello World"
+ ---help---
+ To compile this driver as a module, choose M here; the module will be
+ called hello.
+
+config GLOBALMEM
+ tristate "globalmem"
+ ---help---
+ To compile this driver as a module, choose M here; the module will be
+ called globalmem.
+
+config GLOBALFIFO
+ tristate "globalfifo"
+ ---help---
+ To compile this driver as a module, choose M here; the module will be
+ called globalfifo.
+
+endif # DRIVER_EXAMPLE
Index: drivers/char/driver_examples/Makefile
===================================================================
--- drivers/char/driver_examples/Makefile (revision 0)
+++ drivers/char/driver_examples/Makefile (revision 0)
@@ -0,0 +1,3 @@
+obj-$(CONFIG_HELLO_WORLD) += hello.o
+obj-$(CONFIG_GLOBALMEM) += globalmem.o
+obj-$(CONFIG_GLOBALFIFO) += globalfifo.o