how to write your first linux device driver
2024-09-04 06:18:12
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
最新文章
- Yii2 事务
- Android开发环境的发展演变
- 【three.js详解之二】渲染器篇
- 扫描二维码下载安装apk的app
- SNM2无法编辑HostGroup项
- leetcode二分查找问题整理
- js浏览器键盘事件控制(转自新浪微博)
- 分别给出BOOL,int,float,指针变量 与“零值”比较的 if 语句(假设变量名为var)
- IBM BigInsights 3.0.0.2 集群环境搭建
- Oracle的用户、角色以及权限相关操作
- Linux CentOS7下安装Python3及其setuptools、pip
- JS判断是否是数组的四种做法
- SWFUpload 在ie9上出现的bug
- 编写高质量JavaScript代码的68个有效方法
- 【DeepLearning学习笔记】Neurons神经元
- .NET CORE 2.1 导出excel文件的两种方法
- 后台运行 screen命令
- unity3d相关资源
- unity 热更新方案ILRuntime
- pygame小游戏之坦克大战