linux 内核模块开发相关的文章搜集和知识记录,


最近需要开发一些内核模块,进行探究linux内核的一些特征,现在把一些遇到的比较好的文章和知识点,进行简要记录和备忘;

内核模块开发相关链接:

  • https://www.thegeekstuff.com/2013/07/write-linux-kernel-module/ 入门教程;insmod, rmmod, modinfo等相关命令;
  • https://www.thegeekstuff.com/2010/08/make-utility/ make 工具使用教程;
  • https://www.thegeekstuff.com/2010/11/modprobe-command-examples/ modprobe 命令的使用方法;

内核模块开发过程遇到的知识点:

  • make命令,会隐士调用cc -c 命令,生成.o文件;所以在内核模块的makefile中,可以直接写上:  obj-m += hello_mod.o

最简单的内核模块编译示例:

//必要的头文件 #include <linux/module.h> // included for all kernel modules #include <linux/kernel.h> // include for KERN_INFO #include <linux/init.h> // include for __init and __exit macros //模块许可证声明(必须) MODULE_LICENSE("Dual BSD/GPL"); // 通常使用BSD 和 GPL 双协议 //声明模块的作者(可选) MODULE_AUTHOR("Yaowen Xu"); MODULE_AUTHOR("YaoXu"); MODULE_DESCRIPTION("This is a simple example!"); MODULE_ALIAS("A simplest example"); //模块加载函数(必须) static int hello_init(void) { printk(KERN_ALERT "Hello World enter/n"); return 0; } //模块卸载函数(必须) static void hello_exit(void) { printk(KERN_ALERT "Hello World exit/n"); } //模块的注册 module_init(hello_init); module_exit(hello_exit); hello_mod.c obj-m += hello_mod.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean Makefile

编译前需要安装必要编译工具和所需要的文件:

apt-get install build-essential linux-headers-$(uname -r) 

保持更新,转载请注明出处;更多内容请关注cnblogs.com/xuyaowen;

相关内容

    暂无相关文章