注册完设备和驱动之后,就需要注册设备节点

Linux杂项设备出现的意义在于:有很多简单的外围字符设备,它们功能相对简单,一个设备占用一个主设备号对于内核资源来说太浪费。所以对于这些简单的字符设备它们共用一个主设备号,不同的设备使用不同的次设备号。

MISC_DYNAMIC_MINOR 表示由系统分配子设备号

生成helloword.ko文件后,执行 insmod helloworld,就可以在 dev/ 文件夹下看到 hello_device_node 文件,表明成功生成设备节点,执行 rmmod helloword,则节点消失。

helloworld.c

#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/miscdevice.h>
#include <linux/fs.h> #define DRIVER_NAME "hello"
#define NODE_NAME "hello_device_node" MODULE_LICENSE("Dual BSD/GPL"); // required
MODULE_AUTHOR("liuShuiDeng"); static long hello_fs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
printk("cmd is %d, arg is %ld\n", cmd, arg);
return ;
}
static int hello_fs_release(struct inode *inode, struct file *file)
{
printk(KERN_EMERG "hello_fs_release");
return ;
}
static int hello_fs_open(struct inode *inode, struct file *file)
{
printk(KERN_EMERG "hello_fs_open");
return ;
}
static struct file_operations hello_fops = {
.owner = THIS_MODULE,
.open = hello_fs_open,
.release = hello_fs_release,
.unlocked_ioctl = hello_fs_ioctl,
};
static struct miscdevice hello_miscdevice = {
.minor = MISC_DYNAMIC_MINOR,
.name = NODE_NAME,
.fops = &hello_fops,
};
static int hello_probe(struct platform_device *p)
{
printk(KERN_EMERG "\nhello_probe\n");
misc_register(&hello_miscdevice);
return ;
} static int hello_remove(struct platform_device *p)
{
printk(KERN_EMERG "\nhello_remove\n");
misc_deregister(&hello_miscdevice);
return ;
} static void hello_shutdown(struct platform_device *p)
{
printk(KERN_EMERG "\nhello_shutdown\n");
} static int hello_suspend(struct platform_device *p, pm_message_t state)
{
printk(KERN_EMERG "\nhello_suspend\n"); return ;
} static int hello_resume(struct platform_device *p)
{
printk(KERN_EMERG "\nhello_resume\n"); return ;
} static struct platform_driver hello_driver={
.probe = hello_probe,
.remove = hello_remove,
.shutdown = hello_shutdown,
.suspend = hello_suspend,
.resume = hello_resume,
.driver = {
.name = DRIVER_NAME,
.owner = THIS_MODULE,
},
}; static int hello_init(void) //insmod xxx.ko, execute it
{
printk(KERN_EMERG "\nhello world enter~\n\n");
platform_driver_register(&hello_driver);
return ;
} static void hello_exit(void) //rmmod xxx( note: not xxx.ko ), execute it
{
printk(KERN_EMERG "\nhello world exit~\n\n");
platform_driver_unregister(&hello_driver);
} module_init(hello_init);
module_exit(hello_exit);

Makefile

obj-m += helloworld.o # source file is helloworld.c

#kernel root directory
KDIR := /home/god/Desktop/logicalVolume/iTop4412_Kernel_3. # directory of source file and Makefile
PWD ?= $(shell pwd) all:
$(MAKE) -C $(KDIR) M=$(PWD) modules
rm -rf *.o
rm -rf Module.*
rm -rf modules.order
rm -rf *.mod.*
rm -rf .*.cmd
rm -rf .*versions
clean:
make -C $(KDIR) M=$(PWD) clean

linux driver ------ platform模型,通过杂项设备(主设备号是10)注册设备节点的更多相关文章

  1. linux driver ------ platform模型,驱动开发分析

    一.platform总线.设备与驱动 在Linux 2.6 的设备驱动模型中,关心总线.设备和驱动3个实体,总线将设备和驱动绑定.在系统每注册一个设备的时候,会寻找与之匹配的驱动:相反的,在系统每注册 ...

  2. linux设备管理之主设备号与次设备号

    主设备号和次设备号 一个字符设备或者块设备都有一个主设备号和次设备号.主设备号和次设备号统称为设备号.主设备号用来表示一个特定的驱动程序.次设备号用来表示使用该驱动程序的其他设备.(主设备号和控制这类 ...

  3. Linux:主设备号和次设备号

    http://www.linuxidc.com/Linux/2011-03/33863.htm     Linux的设备管理是和文件系统紧密结合的,各种设备都以文件的形式存放在/dev目录下,称为设备 ...

  4. [ARM-Linux开发] 主设备号--驱动模块与设备节点联系的纽带

    一.如何对设备操作 linux中对设备进行操作是通过文件的方式进行的,包括open.read.write.对于设备文件,一般称其为设备节点,节点有一个属性是设备号(主设备号.次设备号),其中主设备号将 ...

  5. Linux 驱动学习笔记05--字符驱动实例,实现一个共享内存设备的驱动

    断断续续学驱动,好不容易有空,做了段字符驱动的例子.主要还是跟书上学习在此记录下来,以后说不定能回过头来温故知新. 首先上驱动源码 gmem.c: /************************* ...

  6. arm-linux字符设备驱动开发之---简单字符设备驱动

    一.linux系统将设备分为3类:字符设备.块设备.网络设备.使用驱动程序: 1.字符设备:是指只能一个字节一个字节读写的设备,不能随机读取设备内存中的某一数据,读取数据需要按照先后数据.字符设备是面 ...

  7. window 如何枚举设备并禁用该设备和启用该设备?如何注册设备热拔插消息通知?

    目前实现的功能: 1.设备枚举 2.设置设备禁用和启用 3.注册设备热拔插消息通知 4.获取设备 vid pid 数值 需要链接的库 SetupAPI.lib DeviceManager 类如下: D ...

  8. Linux下platform设备以及platform设备和驱动注册的先后顺序

    platform是Linux系统提供的一种管理设备的手段,所有SOC系统中集成的独立的外设控制器.挂接在SOC内存空间的外设等都属Platform设备.如ARM S3C6410处理器中,把内部集成的I ...

  9. linux driver ------ 字符设备驱动 之 “ 创建设备节点流程 ”

    在字符设备驱动开发的入门教程中,最常见的就是用device_create()函数来创建设备节点了,但是在之后阅读内核源码的过程中却很少见device_create()的踪影了,取而代之的是device ...

随机推荐

  1. html转js字符串拼接

    https://www.bejson.com/convert/html_js/ html转js字符串拼接

  2. Peer Programming Project: 4 Elevators Scheduler 学号后三位 157,165

    1.Advantages and disanvantages of Peer Programming advantages The code are constantly validated by t ...

  3. NEWBE CRALWER 产品需求文档

    1.产品概述 本产品是学霸软件系统的爬虫部分,由NEWBE团队负责.主要任务是从网上爬取出相关数据后提供给C705组使用. 2.产品的发展经历 2.1 产品的发展经历 本产品从2014.10.29开始 ...

  4. UserControl 的一个值得注意的问题 [属性" * "的代码生成失败.错误是:"程序集"*.Version=1.0.0.0,Culture=neutral,..........无标记为序列化"

    开发时在做UserControl,需要注意的List<>集合问题~~~! 其他类型的集合可能也存在这样的问题,但是我没去测试,在写集合的时候一般List<>用的多点,所以经常碰 ...

  5. Java源码--Array

    1. Arrays.asList() 该方法是将数组转化为List,需要注意以下几点: (1)该方法不适用于基本数据类型(byte,short,int,long,float,double,boolea ...

  6. JSONObject使用方法详解

    1.JSONObject介绍 JSONObject-lib包是一个beans,collections,maps,java arrays和xml和JSON互相转换的包. 2.下载jar包 http:// ...

  7. Unigine mesh顶点坐标转换精度问题

    本问题虽然与Unigine引擎相关,但对其他精度问题也有参考价值. 问题: 将精细模型顶点从自身参考系的相对坐标(类似4378.95020,4561.00000,31.3887463) 转到椭球面世界 ...

  8. 在VS2017上对C++项目进行单元测试

    操作系统:win10 VS2017安装:http://www.cnblogs.com/Metak/p/7471671.html 参考博客: http://blog.csdn.net/lovehaiho ...

  9. PAT 1046 划拳

    https://pintia.cn/problem-sets/994805260223102976/problems/994805277847568384 划拳是古老中国酒文化的一个有趣的组成部分.酒 ...

  10. Debian中APT的前世今生

    https://baike.baidu.com/item/apt-get/2360755 https://www.debian.org/doc/manuals/debian-handbook/sect ...