insmod lsmod modinfo
insmod一个模块的时候出现问题: Invalid module format
通过modinfo查看模块信息,发现模块的vermagic与内核的版本是不匹配的。
第一种解决办法是使用目标板子上所用的内核重新编译模块
第二种办法是insmod -f xxx.ko或者insmod --force-vermagic xxx.ko (但是现在的insmod好像不支持这些参数)
modprobe depmod
如何实现modprobe,使用modprobe来加载这些模块
modprobe不会知道module之间的依赖性,而是通过读取/lib/modules/2.6.xx/modules.dep文件获知,这个文件是通过depmod建立的。开发板上modules.dep文件生成步骤如下:
步骤1: mkdir -p /lib/modules/uname -r
步骤2:将源码linux-imx目录下的modules.order和modules.builtin复制到/lib/modules/uname -r
目录下
步骤3:执行depmod -a会生成modprobe的依赖文件modules.dep
rmmod
-f, --force This option can be extremely dangerous: it has no effect unless CONFIG_MODULE_FORCE_UNLOAD was set when the kernel was compiled. With this option, you can remove modules which are being used, or which are not designed to be removed, or have been marked as unsafe (see lsmod(8)).
rmmod -f出现的问题:
a. rmmod: ERROR: Resource temporarily unavailable
内核CONFIG_MODULE_FORCE_UNLOAD未使能之前,rmmod会出现
b. rmmod: ERROR: could not remove Device or resource busy
First I wouldn’t do the __KERNEL__ and MODULE defines
Second you aren’t telling the kernel what the init and exit fuctions are, you need to do something like
module_init(init_module);
module_exit(cleanup_module);
Third they need to be declared to be of a type module_init and module_exit can work with, use the __init and __exit macros to do this.
static int __init init_module(void) {…}
static int __exit cleanup_module(void) {…}
Forth make sure you are using a compatible compiler, if they aren’t compatible you’ll sometimes get this issue