linux driver 简单实例
来源:互联网 发布:数据透视图 总数 编辑:程序博客网 时间:2024/06/06 03:03
helloworld.c 代码:
#include <linux/module.h>
#include <linux/kernel.h>#include <linux/init.h>
static int __init hellokernel_init(void)
{
printk(KERN_INFO "hello kernel!\n");
return 0;
}
static void __exit hellokernel_exit(void)
{
printk(KERN_INFO "exit kernel!\n");
}
module_init(hellokernel_init);
module_exit(hellokernel_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("****");
Makefile 代码:
hailonxi@hailonxi-VirtualBox:~$ cat Makefile
obj-m := helloworld.o
PWD := $(shell pwd)
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
rm -rf *.o *~core .*.cmd *.mod.c ./tmp_version
编译make:
hailonxi@hailonxi-VirtualBox:~$ make
make -C /lib/modules/3.11.0-15-generic/build M=/home/hailonxi modules
make[1]: Entering directory `/usr/src/linux-headers-3.11.0-15-generic'
Building modules, stage 2.
MODPOST 1 modules
make[1]: Leaving directory `/usr/src/linux-headers-3.11.0-15-generic'
目录生成文件如下:
hailonxi@hailonxi-VirtualBox:~$ ls
Desktop helloworld.c helloworld.o Music Videos
Documents helloworld.ko Makefile Pictures
Downloads helloworld.mod.c modules.order Public
examples.desktop helloworld.mod.o Module.symvers Templates
执行:
hailonxi@hailonxi-VirtualBox:~$
hailonxi@hailonxi-VirtualBox:~$ insmod helloworld.ko //插入模块
insmod: error inserting 'helloworld.ko': -1 Operation not permitted===要root权限
hailonxi@hailonxi-VirtualBox:~$ sudo insmod helloworld.ko ===插入模块
[sudo] password for hailonxi:
hailonxi@hailonxi-VirtualBox:~$ sudo rmmod helloworld ==删除模块
hailonxi@hailonxi-VirtualBox:~$ dmesg | tail -8 ===显示驱动的打印信息
[ 8.684696] vesafb: framebuffer at 0xe0000000, mapped to 0xffffc90000680000, using 1216k, total 1216k
[ 8.685904] Console: switching to colour frame buffer device 80x30
[ 8.687450] fb0: VESA VGA frame buffer device
[ 45.864889] audit_printk_skb: 171 callbacks suppressed
[ 45.864892] type=1400 audit(1438051706.759:69): apparmor="DENIED" operation="open" parent=1 profile="/usr/lib/telepathy/mission-control-5" name="/usr/share/gvfs/remote-volume-monitors/" pid=1914 comm="mission-control" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
[ 897.462531] type=1400 audit(1438052558.359:70): apparmor="DENIED" operation="capable" parent=1 profile="/usr/sbin/cupsd" pid=671 comm="cupsd" pid=671 comm="cupsd" capability=36 capname="block_suspend"
[ 1597.010173] hello kernel!
[ 1726.934708] exit kernel!
谢谢!!
- linux driver 简单实例
- Linux driver dts使用,实例驱动编写
- 一个简单的linux driver Makefile
- Linux Driver 简单 按键驱动 - 1
- linux驱动简单实例
- Linux Driver输入子系统和按键的实例
- Linux driver
- linux driver
- Linux Driver
- linux driver
- linux device driver 3 简单的字符驱动
- linux kernel, driver, network driver
- linux线程使用简单实例
- Linux Socket编程简单实例
- Linux 网络编程 简单实例
- linux 网络编程简单实例
- linux 按键驱动简单实例
- linux脚本之简单实例
- swift基础语法
- Java log4j日志记录工具配置说明
- 数据库常见面试题
- 控件——radioButton
- Android播放HLS协议的流媒体
- linux driver 简单实例
- 软件工程(4-6章)
- 黑马程序员--算数运算和运算符
- 互联网四大入口
- win7访问Linux Samba的共享目录提示“登录失败:用户名或密码错误”解决方法
- [设计模式]工厂模式
- IOS NSString比较,截取,NSLog,NSRang,isEqualToString,stringWithFormat
- iOS开发使用代码创建一个Label控件
- uvalive 2572