linux 查看驱动模块(lsmod)和 驱动设备(ls /dev)

一、lsmod

lsmod 命令,用于列出当前 linux 系统中加载的模块。当驱动开发人员编写好驱动代码,并生成驱动代码对应的驱动模块后,可以通过 insmod xxx.ko 将驱动模块(.ko)加载到 linux 操作系统中。最后,通过 lsmod 命令就可以看到 xxx.ko 已经加载到 linux 系统当中了。

驱动代码:

back@ubuntu2205:~$ cat driver.c
#include <linux/module.h>
#include <linux/init.h>
#include <linux/platform_device.h>


int hello_probe(struct platform_device *pdev)
{
        printk("[%s] match ok\n", __FILE__);
        return 0;
}
int hello_remove(struct platform_device *pdev)
{
        printk("[%s] hello_remove\n", __FILE__);
        return 0 ;
}

struct platform_driver hello_driver = {
        .probe = hello_probe,
        .remove = hello_remove,
        .driver.name = "yikoulinux",
};

static int hello_init(void)
{
        printk("[%s] hello_init\n", __FILE__);
        return platform_driver_register(&hello_driver);
}

static void hello_exit(void)
{
        printk("[%s] hello_exit\n", __FILE__);
        platform_driver_unregister(&hello_driver);
        return;
}
MODULE_LICENSE("GPL");
module_init(hello_init);
module_exit(hello_exit);
back@ubuntu2205:~$ cat device.c
#include <linux/module.h>
#include <linux/init.h>
#include <linux/platform_device.h>


void    hello_release(struct device *dev)
{
        printk("[%s] hello_release\n",__FILE__);
        return;
}

struct platform_device hello_device ={
        .name = "yikoulinux",
        .id = -1,
        .dev.release = hello_release,
        //hardware TBD
};

static int hello_init(void)
{
        printk("[%s] hello_init\n", __FILE__);
        return platform_device_register(&hello_device);
}

static void hello_exit(void)
{
        printk("[%s] hello_exit\n", __FILE__);
        platform_device_unregister(&hello_device);
        return;
}
MODULE_LICENSE("GPL");
module_init(hello_init);
module_exit(hello_exit);
back@ubuntu2205:~$ ls -lh
total 1.1M
-rw-r--r--  1 back back  709 83 12:13 device.c
-rw-rw-r--  1 back back 5.6K 83 12:18 device.ko
-rw-r--r--  1 back back  829 83 12:13 driver.c
-rw-rw-r--  1 back back 5.3K 83 12:18 driver.ko
back@ubuntu2205:~$ 

在这里插入图片描述
可以看到,我们通过 insmod 命令将 1.1 中的 device.ko 和 driver.ko加载到系统后,lsmod 就会发现我们 insmod 加载的 .ko 模块。

二、其他常见信息的查看

查看CPU信息: cat /proc/cpuinfo
查看板卡信息:cat /proc/pci
查看PCI信息: lspci
例子: lspci |grep Ethernet 查看网卡型号
查看内存信息:cat /proc/meminfo
查看USB设备: cat /proc/bus/usb/devices
查看键盘和鼠标:cat /proc/bus/input/devices
查看系统硬盘信息和使用情况:fdisk & disk - l & df
查看各设备的中断请求(IRQ): cat /proc/interrupts
查看系统体系结构:uname -a

dmidecode查看硬件信息,包括bios、cpu、内存等信息
dmesg | more 查看硬件信息

三、ls /dev

ls /dev 命令用于查看系统中的驱动设备,包括字符设备、块设备。一个驱动模块可以注册多个设备文件。

如字符设备 i2c-0 ~ i2c-4,这5个都是字符设备,它们的主设备号都是 89,此设备号为 0 ~ 4。
同理,块设备 loop0 ~ loop7,它们的主设备号都是 7,此设备号为 0 ~ 7。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

咖喱年糕

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值