Unc123
Unc123

Reputation: 43

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

  1. Build driver as a module CONFIG_DRIVER = m and I can use rmmod and modprobe to unload and load device driver.

  2. Build device driver into kernel itself 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 !

Upvotes: 3

Views: 9520

Answers (1)

0andriy
0andriy

Reputation: 4709

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):

% 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
  • device name: 0000:02:02.4 (note that lspci gives reduced PCI address, i.e. without domain or i.o.w. BDF, while driver expects domain:BDF)
  • driver name: 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.

Upvotes: 4

Related Questions