Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 !

like image 986
Unc123 Avatar asked Oct 12 '25 15:10

Unc123


1 Answers

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.

like image 105
0andriy Avatar answered Oct 14 '25 06:10

0andriy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!