最简单的内核模块编译记录

来源:互联网 发布:mac综艺体字体下载 编辑:程序博客网 时间:2024/05/16 11:59

1、下载源码
参考:https://wiki.centos.org/zh/HowTos/I_need_the_Kernel_Source
yum install kernel-devel

2、编写内核模块代码

#include <linux/module.h>      /* Needed by all modules */#include <linux/kernel.h>      /* Needed for KERN_INFO */#include <linux/init.h>        /* Needed for the macros */static int __init hello_start(void){printk(KERN_INFO "Loading hello module...\n");printk(KERN_INFO "Hello world\n");return 0;}static void __exit hello_end(void){printk(KERN_INFO "Goodbye,hello world\n");}module_init(hello_start);module_exit(hello_end);

3、编写makefile

obj-m=hello.oKVERSION=$(shell uname -r)all:        make -C /lib/modules/$(KVERSION)/build M=$(PWD) modulesclean:        make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean                                                          
0 0
原创粉丝点击