> 文档中心 > Linux查看驱动模块之间的依赖关系的方法

Linux查看驱动模块之间的依赖关系的方法


Linux 查看驱动模块之间的依赖关系方法

查看依赖方法

    • Linux 查看驱动模块之间的依赖关系的方法
      • 编写两个有依赖关系的驱动模块
      • 查看模块之间的依赖关系方法
        • 方法一、module.dep 是指默认安装的驱动模块的查看方法
        • 方法二、lsmod | grep modname
        • 方法三、modinfo modname.ko
        • 方法四、使用modprobe 来加载模块

编写两个有依赖关系的驱动模块

Makefile  scull.c  scull.h  use_scull.c modprobe_use.sh
#Makefile DEBUG = yifeq ($(DEBUG), y) DEBFLAGS = -O -gelse DEBFLAGS = -O2endifCFLAGS +=$(DEBFLAGS)EXTRA_CFLAGS += $(DEBFLAGS)ifeq ($(KERNELRELEASE),)KDIR ?= /lib/modules/$(shell uname -r)/buildPWD :=$(shell pwd)modules:$(MAKE) -C $(KDIR) M=$(PWD) modulesmodules_install:$(MAKE) -C $(KDIR) M=$(PWD) modules_installclean:$(MAKE) -C $(KDIR) M=$(PWD) clean.PHONY: modules modules_install cleanelse obj-m := scull.o    obj-m += use_scull.oendif############# Makefile end here
//scull.c#include    //mod init include#include  //mod must include#include  //printkstatic int num = 10;void show(void) {printk(KERN_INFO"show(),num=%d\n",num);}static __init int hello_init(void){    printk(KERN_INFO"%s\n",__func__;    return 0;}static __exit void hello_exit(void){    printk("%s\n",__func__);}EXPORT_SYMBOL_GPL(show);module_init(hello_init);module_exit(hello_exit);MODULE_LICENSE("GPL");MODULE_VERSION("1.0.2");MODULE_DESCRIPTION("A example module");
// use_scull.c#include    //mod init include#include  //mod must include#include  //printk#include "scull.h"extern void show(void);static __init int use_init(void){    printk(KERN_INFO"%s\n",__func__);    show();    return 0;}static __exit void use_exit(void){    printk("%s\r\n",__FUNCTION__);}module_init(use_init);module_exit(use_exit);MODULE_LICENSE("GPL");MODULE_VERSION("1.0.2");MODULE_DESCRIPTION("A example module");
// scull.h#ifndef __SCULL_H#define __SCULL_Hvoid show(void);#endif

查看模块之间的依赖关系方法

# 方法一、modules.depcat /lib/modules/$(uname -r)/modules.dep # 方法二、lsmod | grep modnamelsmod | grep modname# 方法三、modinfo modname.komodinfo simple.ko# 方法四、modprobe modnamemodprobe modname

方法一、module.dep 是指默认安装的驱动模块的查看方法

root@ubuntu:/tmp# cat /lib/modules/$(uname -r)/modules.dep kernel/arch/x86/events/intel/intel-cstate.ko:kernel/arch/x86/events/rapl.ko:kernel/arch/x86/kernel/cpu/mce/mce-inject.ko:kernel/arch/x86/kernel/msr.ko:kernel/arch/x86/kernel/cpuid.ko:kernel/arch/x86/crypto/twofish-x86_64.ko: kernel/crypto/twofish_common.kokernel/arch/x86/crypto/twofish-x86_64-3way.ko: kernel/arch/x86/crypto/twofish-x86_64.ko kernel/crypto/twofish_common.kokernel/arch/x86/crypto/twofish-avx-x86_64.ko: kernel/crypto/crypto_simd.ko kernel/crypto/cryptd.ko kernel/arch/x86/crypto/twofish-x86_64-3way.ko kernel/arch/x86/crypto/twofish-x86_64.ko kernel/crypto/twofish_common.kokernel/arch/x86/crypto/serpent-sse2-x86_64.ko: kernel/crypto/serpent_generic.ko kernel/crypto/crypto_simd.ko kernel/crypto/cryptd.ko

方法二、lsmod | grep modname

此种方法是只能查看加载驱动完成后。

root@ubuntu:/home/upwards/Desktop/modprobe/driver_sample# lsmod | grep useuse_scull16384  0scull    16384  1 use_scullpsmouse 159744  0

方法三、modinfo modname.ko

root@ubuntu:/home/upwards/Desktop/modprobe/driver_sample# modinfo use_scull.ko filename:/home/upwards/Desktop/modprobe/driver_sample/use_scull.kodescription:    A example moduleversion: 1.0.2license: GPLsrcversion:     036296573EBA9C7BB964625depends: scullretpoline:      Yname:    use_scullvermagic:5.13.0-41-generic SMP mod_unload modversions 

就能看出上面的depends 后面显示的就是此模块所依赖的驱动模块。

方法四、使用modprobe 来加载模块

# modprobe 使用方法modprobe modname #自动加载所依赖的模块modprobe -r modname # 自动卸载所依赖的模块

modprobe 加载ko的脚本

# root@ubuntu:/home/upwards/Desktop/modprobe/driver_sample# cat modprobe_use.sh #/bin/bashpath=$PWDcp $path/*.ko /lib/modules/$(uname -r) || exitecho "copy to path"/sbin/depmod -a || exitecho "depmod done"echo "Please input modules_name:"read modules_nameecho $modules_name/sbin/modprobe $modules_name || exit

冰雪之城