Linux之hello驱动编写
来源:互联网 发布:阿迪达斯网络授权书 编辑:程序博客网 时间:2024/06/05 01:15
## CentOS下搭建编译驱动的环境
S1、yum install kernel 和 yum install kernel-devel
S2、修改软连接
/lib/modules/$(uname -a)/build 指向的软连接
查看默认的ll build指向的软连接,如果不正确,编译会报错,如下:
make: *** /lib/modules/2.6.32-431.29.2.el6.x86_64/build: No such file or directory. Stop.
S3、执行S1步骤之后,在/usr/src/kernels目录之下将生成对应的安装包,然后让S2中build目录指向该目录,如下
ln -s /usr/src/kernels/2.6.32-573.8.1.el6.centos.plus.x86_64 /lib/modules/2.6.32-431.29.2.el6.x86_64/build
## hello_driver.c
#include <linux/init.h>#include <linux/module.h>#include <linux/kernel.h>static int __init hello_init(void){ printk(KERN_ALERT "hello driver init!\n"); return 0;}static void __exit hello_exit(void){ printk(KERN_ALERT "hello driver exit\n");}module_init(hello_init);module_exit(hello_exit);
## Makefile
ifneq ($(KERNELRELEASE),)obj-m :=hello_driver.oelseKERNELDIR ?=/lib/modules/$(shell uname -r)/buildPWD := $(shell pwd)modules:$(MAKE) -C $(KERNELDIR) M=$(PWD) modulesendifclean: rm -rf *.o *~ .depend .* .
## printk的权限定义(1-7输出信息到 /var/log/message,0输出信息到终端)
linux/kernel.h#define KERN_EMERG "<0>"#define KERN_ALERT "<1>"#define KERN_CRIT "<2>"#define KERN_ERR "<3>"#define KERN_WARNING "<4>"#define KERN_NOTICE "<5>"#define KERN_INFO "<6>"#define KERN_DEBUG "<7>"
## 驱动ko使用
insmod hello_driver.kormmod hello_driver.kolsmod | grep hello_driver //检查
## 驱动测试
0 0
- Linux之hello驱动编写
- 编写linux驱动--Hello World
- Linux内核驱动模块编写(Hello,World)
- Linux内核驱动模块编写(Hello,World)
- linux驱动入门-hello设备驱动程序编写
- linux驱动之Hello world
- linux设备驱动之hello
- linux驱动之Hello World
- 一步一步编写最简单的linux驱动 hello world
- Linux 2.6驱动开发之Hello World!
- linux内核驱动之hello world module
- Linux 2.6内核驱动之hello模块
- Linux设备驱动开发之hello, world
- linux设备驱动之hello.c
- 树莓派linux驱动学习之hello world
- Linux驱动编程之“Hello World”
- 树莓派linux驱动学习之hello world
- 树莓派linux驱动学习之hello world
- Windows10下JDK、eclipse与SDK及ADT的配置
- 关于TCP的滑动窗口和拥塞控制
- Android广播机制-BroadcastReceiver
- OCP课程之ORACLE审计
- 【jQuery】:visible过滤选择器
- Linux之hello驱动编写
- 用linux制作Mac OS U盘启动
- Appstore检查自动更新时间
- 【C语言提高32】数组类型
- 一、Java多线程之wait,notify,sleep,yield,join,suspend,resume
- 不浪漫爱情--等你来--等你来
- Ubuntu 平台下OpenResty的安装
- IO基础-UITabBarController
- Android 自定义view --圆形百分比(进度条)