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

最新文章

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

热门文章

  1. 让您的WinForm控件快速支持拖拽文件
  2. linux centos无法删除网站根目录下的.user.ini解决办法
  3. Bootstrap3-导航
  4. MAC电脑卸载Jenkins
  5. vue-cli vue脚手架搭建步骤
  6. shell脚本初学者笔记
  7. 阿里云Mysql导入大数据文件
  8. linux 利器
  9. nginx docker 命令: command not found
  10. eclipse中解决/**/多行注释代码后,格式变乱的问题