设为首页 加入收藏

TOP

一个简单的Linux驱动程序
2014-11-24 03:00:57 来源: 作者: 【 】 浏览:1
Tags:一个 简单 Linux 驱动程序

1。写一个简单的Linux驱动程序,命名为Hello.c


#include
#include
#include
static int __init hello_init(void)
{
printk(KERN_INFO "Hello world\n");
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_INFO "Goodbye world\n");
}
module_init(hello_init);
module_exit(hello_exit);


2。然后书写Makefile文件


obj-m := hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd)
clean


3。在命令行输入 make命令


4。接下来,将生成的模块加载到内核。sudo insmod hello.ko


5。可以通过dmesg查看 内核里面的输出



6。sudo rmmod hello.ko


大功告成。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux 驱动开发-字符设备驱动 下一篇Android 中的ListView内容刷新问题

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Sphinx : 高性能SQL (2025-12-24 10:18:11)
·Pandas 性能优化 - (2025-12-24 10:18:08)
·MySQL 索引 - 菜鸟教 (2025-12-24 10:18:06)
·Shell 基本运算符 - (2025-12-24 09:52:56)
·Shell 函数 | 菜鸟教 (2025-12-24 09:52:54)