中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 操作系统 > Linux > Linux综合
Building External Linux Kernel Modules Under FC3
作者:未知 时间:2005-09-13 22:12 出处:Blog.ChinaUnix.net 责编:chinaitpower
              摘要:Building External Linux Kernel Modules Under FC3

Building External Linux Kernel Modules Under Fedora Core 3

Kernel Preparation

First you need to fetch the proper kernel source rpm. Obtain your kernel version using the command:

# uname -r

My computer gives:

2.6.9-1.667

Fetch the kernel source rpm from a rpmfind web site. I obtained kernel-2.6.9-1.667.FC3.src.rpm. Next, install the kernel source rpm using rpm as root. I used the following command. Your kernel version may vary.

# rpm -ivh kernel-2.6.9-1.667.FC3.src.rpm

Now change your working directory to the SPECS directory and extract the kernel source using rpmbuild:

# cd /usr/src/redhat/SPECS
# rpmbuild -bp kernel-2.6.spec

rpmbuild only prepared the kernel for compilation. We do not need to actually compile kernel. Next, change your current working directory to the kernel source. The path will vary depending on your kernel version. Copy the appropriate architecture either i586, i686, i586-smp, or i686-smp config file from the configs directory to the root of the kernel tree and call the copy .config. Use uname to obtain your architecture. My computer has an architecture of i686.

# cd /usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9
# uname -m
i686
# cp configs/kernel-2.6.9-i686.config .config

The final step to prepare the kernel is to build the make target modules_prepare.

# make modules_prepare

Building External Modules

After creating a Makefile and writing module code in a different directory, using make to build your module. Refer to The Linux Kernel Module Programming Guide for information about writing module Makefiles and code. make requires the path to the kernel source, the variable M set to the current working directory and the target modules. It will vary depending on your kernel version. For my computer:

# cd ~/mydriver
# vi Makefile
# vi mydevice.c
# make -C /usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9 M=$PWD modules

You can use the target clean as well.

Building Specific Internal Modules

To build all configured modules within a particular subdirectory in the Linux kernel tree, issue the same make command as for external modules. Only modules that have been configured in the .config file will be built. This means the make variable related to a particular modules must exist and have a value of a lower case m. For example, for the kernel module blkmtd to be built, the associated make variable called CONFIG_MTD_BLKMTD must appears in the .config file as follows:

CONFIG_MTD_BLKMTD=m

The associated make variable name can be found in the local Makefile, for this case in drivers/mtd/devices/Makefile. To compile the module, including several others in the directory, give the following command

# cd /usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9/drivers/mtd/devices 
# make -C /usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9 M=$PWD modules

Alternatively, you can copy the desired files out of the kernel source tree, edit the Makefile, and treat the result like an external module. Again, see The Linux Kernel Module Programming Guide to help you edit the Makefile.

# cp blkmtd.c Makefile /tmp
# vi Makefile
# make -C /usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9 M=$PWD modules
关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有