本想按照官网文档去编译驱动,发现好麻烦,不知道那步骤出了差错,死活编译不出来,
后来看了网上有一篇教程编译openwrt的应用的,发现openwrt其实就跟普通linux无差别
所以试试写用之前的驱动helloworld写了makefile,果然也是可行的
下面是最普通的驱动hello world程序
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
/* hello_init ---- 初始化函数,当模块装载时被调用,如果成功装载返回0 否则返回非0值 */
static int __init hello_init(void)
{
printk("I bear a charmed life.\n");
return 0;
}
/* hello_exit ---- 退出函数,当模块卸载时被调用 */
static void __exit hello_exit(void)
{
printk("Out, out, brief candle\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
在同一个目录下创建一个Makefile,注意文件名大小写M是大写
ifneq ($(KERNELRELEASE),)
obj-m := example.o
else
KDIR := /home/zmy/Ubuntu/BPI-OpenWRT/build_dir/target-arm_cortex-