简体   繁体   English

如何加载和卸载 kernel 中内置的 linux 驱动程序

[英]How to load and unload linux drivers that are built into kernel

I want to load and unload linux drivers in the device terminal,and I have two options but I do not want to do the first one我想在设备终端中加载和卸载 linux 驱动程序,我有两个选项,但我不想做第一个

  1. Build driver as a module CONFIG_DRIVER = m and I can use rmmod and modprobe to unload and load device driver.将驱动程序构建为模块 CONFIG_DRIVER = m,我可以使用 rmmod 和 modprobe 来卸载和加载设备驱动程序。

  2. Build device driver into kernel itself CONFIG_DRIVER = Y将设备驱动程序构建到 kernel 本身 CONFIG_DRIVER = Y

I want to follow the 2nd option but I do not know how to unload and load the device driver, can the open source community please help me out here !我想遵循第二个选项,但我不知道如何卸载和加载设备驱动程序,请开源社区帮助我!

It's easy as that.就这么简单。 You find a device and driver which you want to unbind.您找到要解除绑定的设备和驱动程序。 For example, on my Intel Minnownboard (v1) I have PCH UDC controller (a PCI device):例如,在我的 Intel Minnownboard (v1) 上,我有 PCH UDC controller(一个 PCI 设备):

% lspci -nk
...
02:02.4 0c03: 8086:8808 (rev 02)
        Subsystem: 1cc8:0001
        Kernel driver in use: pch_udc

Now I know necessary bits:现在我知道了必要的位:

  • bus on which the device is located: PCI设备所在的总线: PCI
  • device name: 0000:02:02.4 (note that lspci gives reduced PCI address, ie without domain or iow BDF , while driver expects domain:BDF )设备名称: 0000:02:02.4 (请注意, lspci提供减少的 PCI 地址,即没有 domain 或 iow BDF ,而驱动程序需要domain:BDF
  • driver name: pch_udc驱动程序名称: pch_udc

Take altogether we can unbind the device:总而言之,我们可以解绑设备:

% echo 0000:02:02.4 > /sys/bus/pci/drivers/pch_udc/unbind
[ 3042.531872] configfs-gadget 0000:02:02.4: unregistering UDC driver [g1]
[ 3042.540979] udc 0000:02:02.4: releasing '0000:02:02.4'

You may bind it again.您可以重新绑定它。 Simple use bind node in the same folder.在同一文件夹中简单使用绑定节点。

The feature appeared more than 15 years ago and here is the article on LWN that explains it.该功能出现在 15 多年前,这里是 LWN 上的文章对其进行了解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM