linux自动加载ko模块,[ARM-Linux开发]Linux下加载.ko驱动模块的两种方法:insmod与modprobe...

bool "rtcrtcrtcrtcrtc",编译内核和内核模型,只能生成.O文件.

请问如何生成能够insmod的.KO文件,是不是应该在Makefile中加些语句

生成.ko文件已经完成了,可是

[root@localhost char]# insmod rtc_driver.ko

rtc_driver.ko: ELF file rtc_driver.ko not for this architecture

编译成的.ko和内核不符。

make -C /usr/src/Linux-`uname -r` SUBDIRS=$PWD modules

可以试下在make menuconfig 时选择 M  而不是 * ,即被编译成模块。而不是编译进内核。。

modprobe:

Load module(s):

modprobe [-a -n -v ] [-C config ] [ -t type ] pattern OR module1 module2 ...List modules:

modprobe [-l ] [-C config ] [ -t type ] pattern

note: wildcard patterns should be escaped

Show configuration:

modprobe [-C config ] -c

Remove module(s) or autoclean:

modprobe [-C config ] -r [ module ...]

//详细说明:

options:

-a, --all //加载所有匹配模块

-c, --showconfig //显示当前使用的配置

-d, --debug //显示调试信息

-h, --help //帮助

-k, --autoclean //将指定模块设置为"自动清除"模式.

modules

-l, --list //显示所有匹配模块

-n, --show //仅仅显示要执行的操作,而不实际执行

-q, --quiet //不显示错误信息

-r, --remove //若在命令指定模块,则删除指定模块,否则,指定"自动清除"模式

-s, --syslog //将结果记录到系统记录中

-t, --type moduletype //指定模块类型

-v, --verbose //执行时显示详细信息

-V, --version //显示版本

-C, --config configfile //指定配置文件.默认使用/etc/modules.conf文件为配置文件

几笔有关modprobe命令

1、modprobe 命令是根据depmod -a的输出/lib/modules/version/modules.dep来加载全部的所需要模块。

2、删除模块的命令是:modprobe -r filename

3、系统启动后,正常工作的模块都在/proc/modules文件中列出。使用lsmod命今也可显示相同内容。

4、在内核中有一个“Automatic kernel module loading"功能被编译到了内核中。当用户尝试打开某类型的文件时,内核会根据需要尝试加载相应的模块。/etc/modules.conf或/etc/modprobe.conf文件是一个自动处理内核模块的控制文件。

modprobe与depmod

1.modprobe

modprobe - program to add and remove modules from the Linux Kernel

modprobe和insmod类似,是用来动态加载模块的,区别在于

modprobe可以解决load module时的依赖关系,它是通过/lib/modules//modules.dep(.bb)文件来查找依赖关系的;而insmod不能解决依赖问题。

如有2个模块g_file_storage.ko和udc.ko,g_file_storage.ko依赖于udc.ko,在加载g_file_storage.ko前必须先加载udc.ko,如果使用insmod加载,必须按顺序一个一个加载:

insmod udc.ko

insmode g_file_storage.ko file=/dev/mtdblock3

如果使用modprobe加载则执行:

modprobe g_file_storage file=/dev/mtdblock3/*此处的加载对象写为g_file_storage,非g_file_storage.ko*/

PS:modules.dep(.bb)文件内容如下:

g_file_storage.ko

udc

udc.ko symbol:usb_gadget_unregister_driver symbol:usb_gadget_register_driver

2.depmod

depmod - program to generate modules.dep and map files

当把模块文件放到/lib/module/`uname -r`/目录下,运行depmod,则会在/lib/modules//目录下生成modules.dep(.bb)文件,表明了模块的依赖关系

3. 对于在使用"modprobe xxx"动态加载过程中出现“modprobe XXX not found”

若出现此问题,需确认:

1. modules.dep(.bb)文件是否生成,若没有,则可以运行depmod,生成此依赖关系文件

2. 若有依赖关系文件,仍出现此问题,把modprobe xxx.ko改为执行modprobe xxx

你可能感兴趣的:(linux自动加载ko模块)