当前位置:首页 » 编程软件 » 编译进内核的驱动怎么卸载

编译进内核的驱动怎么卸载

发布时间: 2023-05-23 08:30:33

A. linux怎么卸载驱动

Linux下大部分驱动都是以模块方式加载到内核的,所以要删除一个驱动,主要从模块下手。所以首先要学会如何查看已经加载的模块:
lsmod
第一列是模块的名字,根据模块名字往往可以猜出哪个模块是你要删除的驱动。如果对硬件不熟悉的话就要试着通过其他命令来找相关的信息。
比如我要删除无线网卡的驱动,那么我可以用:
lspci | grep less
lspci命令会列出所有PCI设备,而grep会找出返回结果中包含less的行。无线是Wireless,所以返回结果就会包含有我的无线网卡的信息,比如:
02:00.0 Network controller: Realtek Semiconctor Co., Ltd. RTL8192E Wireless LAN Controller (rev 01)
可以看出型号是RTL8192E,这个时候再用lsmod命令,查看有没有与8192相关的模块名就可以了。
找到模块名字后(比如我的无线网卡叫做r8192e_pci)就可以用如下命令卸载模块:
rmmod 模块名
对于我的无线网卡就是rmmod r8192e_pci。这时候驱动就已经成功被卸载了,但是是临时的,重启又会重新加载,如果要永久卸载这个驱动的话还需要改一点东西。
在Ubuntu下进入/etc/modprobe.d目录下(其他发行版会有些差别),编辑blacklist.conf文件,加入一行(一般加在最下面):
blacklist 模块名
这样就将你要删的驱动加入了黑名单,以后就再也见不到它啦!: )

B. linux 内核驱动问题

1,重新编译内核浪费时间,可以考虑把fedora的it20驱动移植过来!参考网上的makefile写个,自己编译一下。把编译得到的ko放到某目录下, 在启动脚本里加载它!

2, 如果想重新编译内核也可以,把fedora9的it驱动替换你的驱动(把源文件名字改成一样的),前提是你有内核源代码!一般安装完fedora后,在源码里有个.config文件,这就是默认的配置文件,你也不许要再make menuconfig了,直接make oldconfig make 就行。

C. 如何编译一个linux下的驱动模块

Linux内核源码路径:/usr/src/linux(这个源码是从kernel.org网站download的2.4.18版本)

按照《linux设备驱动开发详解》一书中的步骤实现经典例子"hello,world!"的例子。
具体步骤如下:
=============================================
1.源码如下:
/*
* hello.c -- the example of printf "hello world!" in the screen of driver program
*/
#include <linux/init.h>
#include <linux/mole.h>
MODULE_LICENSE("Dual BSD/GPL");/* declare the license of the mole ,it is necessary */
static int hello_init(void)
{
printk(KERN_ALERT "Hello World enter!\n");
return 0;
}
static int hello_exit(void)
{
printk(KERN_ALERT "Hello world exit!\n");
}
mole_init(hello_init); /* load the mole */
mole_exit(hello_exit); /* unload the mole */
进入目录:
[root@Alex_linux /]#cd /work/jiakun_test/moletest
[root@Alex_linux moletest]# vi hello.c
然后拷入上面书上的源码。
2.编译代码:
1>.首先我在2.4内核的虚拟机上进行编译,编译过程如下:
[root@Alex_linux moletest]#gcc -D__KERNEL__ -I /usr/src/linux -DMODULE -Wall -O2 -c -o hello.o hello.c
其中-I选项指定内河源码,也就是内核源码树路径。编译结果:
hello.c:1:22: net/sock.h: No such file or directory
hello.c: In function `hello_init':
hello.c:6: warning: implicit declaration of function `printk'
hello.c:6: `KERN_ALERT' undeclared (first use in this function)
hello.c:6: (Each undeclared identifier is reported only once
hello.c:6: for each function it appears in.)
hello.c:6: parse error before string constant
hello.c: In function `hello_exit':
hello.c:11: `KERN_ALERT' undeclared (first use in this function)
hello.c:11: parse error before string constant
hello.c: At top level:
hello.c:13: warning: type defaults to `int' in declaration of `mole_init'
hello.c:13: warning: parameter names (without types) in function declaration
hello.c:13: warning: data definition has no type or storage class
hello.c:14: warning: type defaults to `int' in declaration of `mole_exit'
hello.c:14: warning: parameter names (without types) in function declaration
hello.c:14: warning: data definition has no type or storage class
在网上查询有网友提示没有引入kernel.h
解决:vi hello.c
在第一行加入:#include <linux/kernel.h>
再次编译仍然报KERN_ALERT没有声明
修改编译条件-I,再次编译:
[root@Alex_linux moletest]#gcc -D__KERNEL__ -I /usr/src/linux -DMODULE -Wall -O2 -c -o hello.o hello.c
[root@Alex_linux moletest]#ls
hello.c hello.o Makefile
[root@Alex_linux moletest]#
2>.接着我尝试在2.6内核的虚拟机上进行编译
编译过程如下:
[root@JiaKun moletest]# ls
hello.c makefile
[root@JiaKun moletest]# vi hello.c
[root@JiaKun moletest]# make
make -C /mylinux/kernel/2.4.18-rmk7 M=/home/alex/test/moletest moles
make: *** /mylinux/kernel/2.4.18-rmk7: No such file or directory. Stop.
make: *** [moles] Error 2
[root@JiaKun moletest]# vi makefile
[root@JiaKun moletest]# make
make -C /usr/src/kernels/2.6.18-53.el5-i686 M=/home/alex/test/moletest moles
make[1]: Entering directory `/usr/src/kernels/2.6.18-53.el5-i686'
scripts/Makefile.build:17: /home/alex/test/moletest/Makefile: No such file or directory
make[2]: *** No rule to make target `/home/alex/test/moletest/Makefile'. Stop.
make[1]: *** [_mole_/home/alex/test/moletest] Error 2
make[1]: Leaving directory `/usr/src/kernels/2.6.18-53.el5-i686'
make: *** [moles] Error 2
[root@JiaKun moletest]# mv makefile Makefile
[root@JiaKun moletest]# make
make -C /usr/src/kernels/2.6.18-53.el5-i686 M=/home/alex/test/moletest moles
make[1]: Entering directory `/usr/src/kernels/2.6.18-53.el5-i686'
CC [M] /home/alex/test/moletest/hello.o
Building moles, stage 2.
MODPOST
CC /home/alex/test/moletest/hello.mod.o
LD [M] /home/alex/test/moletest/hello.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.18-53.el5-i686'
[root@JiaKun moletest]# ls
hello.c hello.ko hello.mod.c hello.mod.o hello.o Makefile Mole.symvers

3.执行代码,加载驱动模块:
2.4内核加载模块:
insmod ./hello.o
但是此时并没有输出printk打印的信息。但是可以在/var/log/messages 中看到打印的信息,这是由于KERN_ALERT优先级不够高。这里
需要修改为:KERN_EMERG。再次编译,加载模块即可以看到结果
2.6内核加载模块:
[root@JiaKun moletest]# insmod hello.ko
[root@JiaKun moletest]#
Message from syslogd@ at Sat Jul 26 19:52:44 2008 ...
JiaKun kernel: Hello, world
有的朋友可能会出现insmod命令找不到的错误,这可能有下面几个原因:
<1> 你的系统没有安装mole-init-tools工具,关于此问题,只需安装即可,但是一般装完系统是有这个命令的。
<2> 环境变量没有添加导致不能使用该命令。使用echo $PATH即可查看PATH环境变量,发现没有/sbin这个路径,所以你当然不能使用insmod这个命令了。解决的方法很简单,只需在命令行输入:
PATH = "$PATH:/sbin"即可添加。(insmod在/sbin这个目录下,你可以使用whereis insmod查看)。
<3> insmod这个命令需要在root权限下才能使用。
加载完成后你可以输入lsmod查看hello这个模块哦。

4.卸载驱动模块:rmmod hello.
加载模块后就可在屏幕上看到如下信息:Hello world enter.
卸载时就可在屏幕上看到如下信息:hello world exit.
[root@JiaKun moletest]# rmmod hello.ko
[root@JiaKun moletest]#
Message from syslogd@ at Sat Jul 26 19:52:58 2008 ...
JiaKun kernel: Goodbye, cruel world

另外,如果有多个文件,则按下列方式编写Makefile文件(file1.c、file2.c):
obj -m := molename.o
mole-objs := file1.o file2.o
转载仅供参考,版权属于原作者。祝你愉快,满意请采纳哦

D. 嵌入式linux下如何卸载内核已有的一些驱动

用lsmod确认要卸载的驱动,
然后用rmmod卸载就可以了。

E. ubuntu卸载已安装的ko驱动

ubuntu是不需要卸载已安装的陪租镇ko驱动。ko文件是kernelobject文件(内核模块),该文件的型桐意义就是把内核的一些功能移动到内核外边,需要的芦粗时候插入内核,不需要时卸载。

F. 用ctex编译时怎么终止前一个应用

一、手工加载测试 1、insmod 。/key_test。ko 加载驱动模块到内核 2、cat /proc/moles |grep key_test 查看key_test模块在内核中的地址,不加过滤器可以看到全部加载的模块。 3、lsmod 显示模块,这时可以看到所有的模块名字,后面跟的是主设备号和次设备号。
   4、rmmod key_test 把模块从内核里卸载。 二、动态加载 1、把key_test。c源代码放到内核源代码的/drives/char/下,因为这是属字符型驱动,放在这编译到zImage中。 2、这时我们make menuconfig 编译内核是看不到key_test这个选项的。
  我们把这个选项写到菜单里面才行。在内核源代码的/drives/char/下有一个Kconfig文件,打开 (1) vi Kconfig 加几行到里面: config ConFig_key_test bool "key test" //前面那个bool换成tristate就是支持模块化编译 上面句是在make menuconfig时会出现key test这个选项在drive/char子菜单下,bool前面是TAB键 ------help---------- 这句是出现在菜单选项下面的 This key test help。
   这句是你的驱动的说明会出现在help里面 (2)在/drivers/char目录下的Makefile文件里加上一句: obj-$(CONFIG_key_test) += key_test。o 上面这句是让Make时把key_test编译到内核中。
   (3) make menuconfig 把key_test选项选取上 (4) make zImage 生成zImage文件,重启动加载这个新编的内核。 3、lsmod就能看到key_test了,但是还不能用,没有接口,也就是/dev下面没有 4、mknod /dev/key_test c 121 0 这是创建设备到/dev下,使普通程序可以调用了,121是在源代码里定义的它的主设备号,0是次设备号。
   5、cat /dev/key_test 这是相当于open这个设备了,或者写一个程序直接调用open、write等函数。

G. linux下怎么编译安装驱动

linux 编译安装驱动有两种,动态加载与静态加载
动态加载
一,编译,在指点内核树下编译,生成.o文件或.ko文件
二,将生成的.o或.ko文件拷到相应目录,一般是/lib/mole/kernel下面
三,用insmod命令加载,用rmmod命令卸载
静态加载
静态加载主要就是编译内核。就是将编写好的驱动放进内核相应的目录下面。然后编译内核。然后运行编译好的内核。

H. linux 驱动模块编译到内核后不改变内核 怎么修改或更换驱动

insmod,rmmod

I. 编译内核模块常见有关问题怎么解决

第一次把自己编译的驱动模块加载进开发板,就出现问题,还好没花费多长时间,下面列举出现的问题及解决方案
1:出现insmod: error inserting 'hello.ko': -1 Invalid mole format

法一(网上的):是因为内核模块生成的环境与运行的环境不一致,用linux-2.6.27内核源代码生成的模块,可能就不能在linux-2.6.32.2内核的linux环境下加载,需要在linux-2.6.27内核的linux环境下加载。

a.执行判渣 uname -r //查看内核版本

b.一般出错信息被记辩戚录在文件/var/log/messages中,执行下面命令看错误信息
# cat /var/log/messages |tail

若出现类似下面:

Jun 4 22:07:54 localhost kernel:hello: version magic '2.6.35.6-45.fc14.i686.PAE

' should be '2.6.35.13-92.fc14.i686.PAE'

则把 Makefile里的KDIR :=/lib/moles/2.6.35.6-45.fc14.i686.PAE/build1 改为

KDIR :=/lib/moles/2.6.35.13-92.fc14.i686.PAE/build1 //改成自己内核源码路径

(这里的build1是一个文件链接,链接到/usr/src/kernels/2.6.35.6-45.fc14.i686.PAE和13-92的)

然并卵,我的fedora 14 /usr/src/kernels下并没有2.6.35.13-92.fc14.i686.PAE,只有2.6.35.13-92.fc14.i686,虽然不知道两者有什么区别,但改成2.6.35.13-92.fc14.i686还是不行,照样这个问题,还好后来在看教学视频的到启发

法二:改的还是那个位置
KDIR :=/opt/FriendlyARM/linux-2.6.32.2 //把这里改成你编译生成kernel的那个路径
all:
$ (MAKE) -C $ (KDIR) M = $ (PWD) moles ARCH=arm CROSS_COMPILE=arm-linux- //加这掘灶悄句
2. [70685.298483] hello: mole license 'unspecified' taints kernel.
[70685.298673] Disabling lock debugging e to kernel taint

方法:在模块程序中加入: MODULE_LICENSE("GPL");
3. rmmod: chdir(2.6.32.2-FriendlyARM): No such file or directory 错误解决
方法:lsmod 可查看模块信息
即无法删除对应的模块。
就是必须在/lib/moles下建立错误提示的对应的目录((2.6.32.2)即可。

必须创建/lib/moles/2.6.32.2这样一个空目录,否则不能卸载ko模块.
# rmmod nls_cp936
rmmod: chdir(/lib/moles): No such file or directory
但是这样倒是可以卸载nls_cp936,不过会一直有这样一个提示:
rmmod: mole 'nls_cp936' not found
初步发现,原来这是编译kernel时使用make moles_install生成的一个目录,
但是经测试得知,rmmod: mole 'nls_cp936' not found来自于busybox,并不是来自kernel
1).创建/lib/moles/2.6.32.2空目录
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_mole(modname, O_NONBLOCK | O_EXCL);//系统调用sys_delete_mole
if (ret < 0 && errno == EAGAIN)
usleep(500000);
else
break;
}
if (ret != 0)
printf("Unable to unload driver mole \"%s\": %s\n",
modname, strerror(errno));
}
3).把生成的命令复制到文件系统
# arm-linux-gcc -static -o rmmod rmmod.c
# arm-linux-strip -s rmmod
# cp rmmod /nfs/
cp /nfs/rmmod /sbin

代码如下:
proc.c
[html] view plain
<span style="font-size:18px;">#include <linux/mole.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/proc_fs.h> /* Necessary because we use the proc fs */
#define procfs_name "proctest"

MODULE_LICENSE("GPL");
struct proc_dir_entry *Our_Proc_File;
int procfile_read(char *buffer,char **buffer_location,off_t offset, int buffer_length, int *eof, void *data)
{ int ret;
ret = sprintf(buffer, "HelloWorld!\n");
return ret;
}

int proc_init()
{ Our_Proc_File = create_proc_entry(procfs_name, 0644, NULL);
if (Our_Proc_File == NULL) {
remove_proc_entry(procfs_name, NULL);
printk(KERN_ALERT "Error: Could not initialize /proc/%s\n",procfs_name);
return -ENOMEM; }
Our_Proc_File->read_proc = procfile_read;//
// Our_Proc_File->owner = THIS_MODULE;
Our_Proc_File->mode = S_IFREG | S_IRUGO;
Our_Proc_File->uid = 0;
Our_Proc_File->gid = 0;
Our_Proc_File->size = 37;
printk("/proc/%s created\n", procfs_name);
return 0;
}
void proc_exit()
{ remove_proc_entry(procfs_name, NULL);
printk(KERN_INFO "/proc/%s removed\n", procfs_name);
}
mole_init(proc_init);
mole_exit(proc_exit);</span></span></span></span></span>

[html] view plain
<span style="font-size:18px;">

ifneq ($(KERNELRELEASE),)
obj-m :=proc.o
else
KDIR :=/opt/FriendlyARM/linux-2.6.32.2
#KDIR :=/lib/moles/2.6.35.13-92.fc14.i686.PAE/build1
PWD :=$(shell pwd)
all:
$(MAKE) -C $(KDIR) M=$(PWD) moles ARCH=arm CROSS_COMPILE=arm-linux-
clean:
rm -f *.ko *.o *.mod.o *.mod.c *.symvers
endif</span></span></span></span></span>

make后生成proc.ko,再在开发板上insmod proc.ko即可
执行 dmesg 就可以看到 产生的内核信息啦

J. Linux无法卸载驱动模块

在网上查了查,原来是现在的内核模块在插入卸载时都会要转到喊简/lib/亩裂moles/内核版本号/ 这个目录里。郑耐裤
所以只要建立这个目录并且把要使用的模块.ko文件复制到这个目录就行了。
最近在使用busybox 1.13.1时发现要卸载必须要完全匹配模块名才行,原来在老标本的使用模块文件名就能卸载,现在发现不行了。

热点内容
solidworkspcb服务器地址 发布:2025-07-18 22:50:35 浏览:815
怎么在堆叠交换机里配置vlan 发布:2025-07-18 22:42:35 浏览:623
java调用别人的接口 发布:2025-07-18 22:37:35 浏览:433
服务器四个节点如何联网 发布:2025-07-18 22:36:02 浏览:271
华强北什么地方休安卓手机 发布:2025-07-18 22:24:56 浏览:735
数据库的根本目标 发布:2025-07-18 21:37:50 浏览:938
压缩机的流速 发布:2025-07-18 21:37:40 浏览:407
三星怎么取消手机密码 发布:2025-07-18 21:33:50 浏览:630
安卓手机耳机如何弹窗显示电量 发布:2025-07-18 21:20:53 浏览:60
云服务器搭建需要什么工具 发布:2025-07-18 20:51:08 浏览:322