1、hello 简单内核模块的编写
最近在看《linux设备驱动程序》这本书,刚看完第二章。。。。。
先介绍下环境:本地有一个ubuntu的远程服务器,版本是
~/Documents$ uname -r
3.13.0-32-generic
本来在kernel.org下载了linux4.9编译了hello的模块,但是insmod时候,报错:insmod: error inserting ‘./helloworld.ko’: -1 Invalid module format,这是因为模块基于的内核版本号和系统的内核版本号不一致 解决方法写在下面吧
hello.c
#include<linux/init.h>
#include<linux/module.h>
static int __init hello_init(void)
{
printk(KERN_ALERT "hello 0220\n");
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_ALERT "exit 0220\n");
}
MODULE_LICENSE("GPL");
module_init(hello_init);
module_exit(hello_exit);
Makefile
obj-m := hello.o
KERN := $(shell uname -r)
PWD := $(shell p