how to write your first linux device driver
how to write your first linux device driver
0. environment
-ubuntu 1804 64bit
1. apt-get install linux-headers-$(uname -r)
2. code hello.c
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(void)
{
printk(KERN_ALERT "Hello, solidmango\n");
return ;
} static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, solidmango\n");
} module_init(hello_init);
module_exit(hello_exit);
3. Makefile
# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
4. sudo insmod hello.ko
5. sudo rmmod hello
6. view result
sm@ubuntu:~/dev$ cat /var/log/syslog|grep solidmango
Sep :: ubuntu kernel: [ 3041.143749] Hello, solidmango
Sep :: ubuntu kernel: [ 3068.192172] Goodbye, solidmango
7. sign your kernel module
/lib/modules/4.15./build/scripts/sign-file sha512 /lib/modules/4.15./build/certs/signing_key.pem /lib/modules/4.15./build/certs/signing_key.x509 hello.ko
signing_key.pem and signing_key.x509 files are generated when build the linux kernel
reference
https://wiki.gentoo.org/wiki/Signed_kernel_module_support#Enabling_module_signature_verification
how to write your first linux device driver的更多相关文章
- linux device driver —— 环形缓冲区的实现
还是没有接触到怎么控制硬件,但是在书里看到了一个挺巧妙的环形缓冲区实现. 此环形缓冲区实际为一个大小为bufsize的一维数组,有一个rp的读指针,一个wp的写指针. 在数据满时写进程会等待读进程读取 ...
- Linux Device Driver 学习(1)
Linux Device Driver 学习(1) 一.搭建虚拟机开发环境 1.选择虚拟机VirtualBox,官网下载.deb包安装: VirtualBox Linux 5.1.6 下载fedora ...
- Linux Device Driver && Device File
catalog . 设备驱动程序简介 . I/O体系结构 . 访问设备 . 与文件系统关联 . 字符设备操作 . 块设备操作 . 资源分配 . 总线系统 1. 设备驱动程序简介 设备驱动程序是内核的关 ...
- How to learn linux device driver
To learn device driver development, like any other new knowledge, the bestapproach for me is to lear ...
- <<linux device driver,third edition>> Chapter 4:Debugging Techniques
Debugging by Printing printk lets you classify messages accoring to their severity by associating di ...
- <<linux device driver,third edition>> Chapter 3:Char Drivers
The Internal Representation of Device Numbers Within the kernel,the dev_t type(defined in linux/type ...
- linux device driver —— ioctl
实现了应用程序和设备驱动通过ioctl通信.还是对设备驱动没什么感觉,贴一下代码吧. 在Ubuntu 16.04 64bit中测试通过 ioctldemo.c #include <linux/m ...
- linux device driver —— 字符设备
现在对linux设备驱动还没有什么认识,跟着书上敲了一个字符驱动,这里把代码贴一下. 测试环境是 Ubuntu 16.04 64bit 驱动程序: #include <linux/fs.h> ...
- <<linux device driver,third edition>> Chapter 2: Building and Running Modules
Kernel Modules Versus Applications Kernel modules programming is similar to event driven programming ...
随机推荐
- WPF 精修篇 事件触发器
原文:WPF 精修篇 事件触发器 事件触发器 一般使用的就是动画 <Grid> <TextBlock Text="事件触发器" Opacity="0.2 ...
- 练手WPF(一)——模拟时钟与数字时钟的制作(上)
一.Visual Studio创建一个WPF项目. 简单调整一下MainWindow.xaml文件.主要使用了两个Canvas控件,分别用于显示模拟和数字时钟,命名为AnalogCanvas.digi ...
- mysql 查询数据库表信息,字段信息
#======================================================================= #查询表信息 select table_name, t ...
- el-upload进度条无效,on-progress无效问题解决方案
事先声明,本人系.net后端老菜鸟,vue接触没有多长时间,如果存在技术分享错误,切莫见怪,第一次写博,还请大佬们多多担待,转载请注明出处谢谢! 最近项目用到饿了么上传,于是参照官网接入el-uplo ...
- 解决plsql中文显示问号(???)问题
最近新买的电脑,配置好数据库连接后,plsql查看数据与插入中文数据都显示问号(???),同事的都正常显示,查看了很多资料,有的说是数据库字符集的原因让修改数据库的字符集,但是我的数据库都是远程连接正 ...
- 线程---Day22
并发与并行 并发:指两个或多个事件在同一个时间段内发生. 并行:指两个或多个事件在同一时刻发生(同时发生) 在操作系统中,安装了多个程序,并发指的是在一段时间内宏观上有多个程序同时运行,这在单CPU系 ...
- js计算数组中元素出现的次数,并实现去重
function getCount(arr, rank,ranktype){ var obj = {}, k, arr1 = []; for (var i = 0, len = arr.length; ...
- XSS靶场练习
0x00:前言 一个XSS练习平台,闯关形式,一共20关 0x01:开始 第一行都是代码插入点,下面几行是payloads(插入点和payloads中间空一行) LV1 <script>a ...
- 【软件工程第三次作业】结对编程:四则运算( Java 实现)
1. GitHub 地址 本项目由 莫少政(3117004667).余泽端(3117004679)结对完成. 项目 GitHub 地址:https://github.com/Yuzeduan/Arit ...
- ORACLE百分比分析函数RATIO_TO_REPORT() OVER()
有时候不用的指标的绝对值不能比,但是转转为百分比的形式就容易看出波动了,是数据分析的好用的一个分析函数 20:00:24 SYS@orcl> conn scott/tiger; Connecte ...