Fedora Core 5 内核模块编译

来源:互联网 发布:深入了解java虚拟机 编辑:程序博客网 时间:2024/05/16 06:35

Fedora Core 5 内核模块编译

 

 

http://download.fedora.redhat.com/pub/fedora/linux/core/5/source/SRPMS/kernel-2.6.15-1.2054_FC5.src.rpm下载kernel-2.6.15-1.2054_FC5.src的安装包。(我的内核版本是这个所以就下载的这个版本,你可以用uname -r这个命令来查看你内核版本号)
# rpm –Uvh kernel-2.6.15-1.2054_FC5.src.rpm
# cd /usr/src/redhat/SPECS
# rpmbuild -bp --target $(uname -m) kernel-2.6.spec
# ls /usr/src/redhat/BUILD/kernel-2.6.15/
Config.mk linux-2.6.15.i686 vanilla xen xen-vanilla
# cd /usr/src/redhat/BUILD/kernel-2.6.15/linux-2.6.15.i686
# cp configs/kernel-2.6.15-i686.config .config
cp:是否覆盖“.config”? y
继续编译:
#make mrproper
#make oldconfig
#make
#make modules_install
到此我们要用的内核编译完成,可以开始编写内核模块了。
/*hello.c*/
#include <linux/init.h>
#include <linux/module.h>
static int hello_init(void)
{
printk(KERN_ALERT "hello,world/n");
return 0;
}
static void hello_exit(void)
{
  printk(KERN_ALERT "bye/n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");

/*makefile*/
KERNELDIR = /usr/src/redhat/BUILD/kernel-2.6.15/linux-2.6.15.i686/
SUBDIR = /home/driver
all:modules
obj-m:=module.o
module-objs:=hello.o
modules:
$(MAKE) -C $(KERNELDIR) M=$(SUBDIR) modules 

原创粉丝点击