驱动模块加载、卸载遇到的问题总结

1、rmmod: chdir(/lib/modules): No such file or directory 解决方法
1.创建 /lib/modules/$(uname -r) 空目录就行了

2.使用如下源码生成rmmod命令,就可以没有任何提示的卸载ko模块了[luther.gliethttp]
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>

int main(int argc, char *argv[])
{
    const char *modname = argv[1];
    int ret = -1;
    int maxtry = 10;

    while (maxtry-- > 0) {
        ret = delete_module(modname, O_NONBLOCK | O_EXCL);//系统调用sys_delete_module

        if (ret < 0 && errno == EAGAIN)
            usleep(500000);
        else
            break;
    }

    if (ret != 0)
        printf("Unable to unload driver module /"%s/": %s/n",
             modname, strerror(errno));
}
3.把生成的命令复制到文件系统
# arm-linux-gcc -static -o rmmod rmmod.c 
# arm-linux-strip -s rmmod
# cp rmmod /nfs/

猜你喜欢

转载自blog.csdn.net/jerrygou/article/details/79764160
今日推荐