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的更多相关文章

  1. linux device driver —— 环形缓冲区的实现

    还是没有接触到怎么控制硬件,但是在书里看到了一个挺巧妙的环形缓冲区实现. 此环形缓冲区实际为一个大小为bufsize的一维数组,有一个rp的读指针,一个wp的写指针. 在数据满时写进程会等待读进程读取 ...

  2. Linux Device Driver 学习(1)

    Linux Device Driver 学习(1) 一.搭建虚拟机开发环境 1.选择虚拟机VirtualBox,官网下载.deb包安装: VirtualBox Linux 5.1.6 下载fedora ...

  3. Linux Device Driver && Device File

    catalog . 设备驱动程序简介 . I/O体系结构 . 访问设备 . 与文件系统关联 . 字符设备操作 . 块设备操作 . 资源分配 . 总线系统 1. 设备驱动程序简介 设备驱动程序是内核的关 ...

  4. How to learn linux device driver

    To learn device driver development, like any other new knowledge, the bestapproach for me is to lear ...

  5. <<linux device driver,third edition>> Chapter 4:Debugging Techniques

    Debugging by Printing printk lets you classify messages accoring to their severity by associating di ...

  6. <<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 ...

  7. linux device driver —— ioctl

    实现了应用程序和设备驱动通过ioctl通信.还是对设备驱动没什么感觉,贴一下代码吧. 在Ubuntu 16.04 64bit中测试通过 ioctldemo.c #include <linux/m ...

  8. linux device driver —— 字符设备

    现在对linux设备驱动还没有什么认识,跟着书上敲了一个字符驱动,这里把代码贴一下. 测试环境是 Ubuntu 16.04 64bit 驱动程序: #include <linux/fs.h> ...

  9. <<linux device driver,third edition>> Chapter 2: Building and Running Modules

    Kernel Modules Versus Applications Kernel modules programming is similar to event driven programming ...

随机推荐

  1. 用JavaScript带你体验V8引擎解析标识符

    上一篇讲了字符串的解析过程,这一篇来讲讲标识符(IDENTIFIER)的解析. 先上知识点,标识符的扫描分为快解析和慢解析,一旦出现Ascii编码大于127的字符或者转义字符,会进入慢解析,略微影响性 ...

  2. 深入V8引擎-默认Platform之mac篇(2)

    先说结论,V8引擎在默认Platform中初始化的这个线程是用于处理类似于setTimeout的延时任务. 另外附一些图,包括继承树.关键属性归属.纯逻辑工作流程,对代码木得兴趣的看完图可以X掉了. ...

  3. [转] linux 查找文本过滤grep正则表达式命令详解用法

    grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用 ...

  4. C++中的Point类与vector类的简单处理

    首先设计Vector与Point的表示方法,再依次完善两个类中的构造函数,复制构造函数等. 向量由两个点表示,当进行运算的时候,转化起点坐标为(0,0): 第14行:由于Vector需要用到Point ...

  5. 一、NodeJS入门——准备工作(1)——NodeJS的安装

    目录 1.介绍 2.nodejs下载 3.nodejs安装 4.nodejs的简单实用 5.nodejs的经典入门:hello world 6.总结 1    介绍 这是一系列的内容主要是关于我在学习 ...

  6. Python Lab Assignments

    引用: https://github.com/saismaran33/Python-Lab-Assignments/wiki/Python-Lab-Assignment-2 Lab 1 对于任何Web ...

  7. ES6 数组的拓展(五)

    一.扩展运算符(...)将数组转化为以,分割的字符串eg: console.log(...[1,2,3,4]); //1 2 3 4 将字符串转化为数组eg: console.log([...'hel ...

  8. Quality Center安装步骤

     测试管理工具 u 安装条件: Quality Center:QC9中文版 数据库:Oracle10 g 操作系统:Windows XP u 安装步骤: 1. 点击setup.exe,出现如下界面,点 ...

  9. (原)netbeans中使用libtorch

    转载请注明处处: https://www.cnblogs.com/darkknightzh/p/11479330.html 说明:第一种方式在netbeans中无法debug代码,设置了断点也不会在断 ...

  10. elastic常用工具

    elasticsearch 常用工具: elasticsearch-dump :备份 elasticsearch-head :数据展示.操作平台 elasticsearch-head github 地 ...