简体   繁体   中英

Installing Linux PCI driver without connecting the device

Is there any way to install a Linux device driver without connecting the device?

I have complete access to the driver code. I'm using Linux Kernel 2.6.35.

I have tried insmod and modprobe to no avail. I am working on a custom driver (I didn't write it) but there isn't any documentation.

Device drivers in Linux are (mostly) kernel modules. So yes! All you need to do is load the kernel module.

Compile the code to a kernel module, make install and modprobe <modulename> .

The documentation of your driver should've already told you that tho. ;)

A properly written device driver should not install when no instances of the device exist in the system (hot-pluggable device might be an exception). In some versions of Unix the probe() function of the driver checks if the device is present. In Linux the probe functionality is often incorporated into the _init() routine. When no hardware is detected, the driver should not register itself, and return status that would cause it to be unloaded if it is a module.

If you insist on having the driver code in memory, then don't build it as a loadable module, but rather select the Linux driver to be part of the memory-resident kernel. Building a driver as a loadable module is selected by typing an "M" in the menuconfig program. To have the driver built into the kernel, use the space bar to select the driver. The selection will be marked with an asterisk * rather than an M to indicate this difference.

(The text for this menuconfig dialog comes from Kconfig files. The product of this configuration dialog is the .config file, which has configuration symbols that are used in Makefile s to control the compilation of object files. The previous assumes that this driver has been incorporated into the Linux kernel source code tree. If all you have is the source code file, then you'll have to decide where in the source tree this driver fits. You then might be able to manually edit a Makefile to unconditionally compile the driver in that appropriate sub-directory. Or customize the Kconfig and Makefile files with a configuration variable for this driver.)

To keep all of the driver's code resident, you will have to make some minor code changes. Normally the initialization code and data are placed in text and data sections separate from "ordinary" text and data, and this memory section is freed once the kernel has finished booting. To prevent any driver code and data from being freed, remove the __init and __exit section specifiers in declarations.

Of course you will have to build a new kernel binary in order to incorporate this device driver. You should try to use the previous build's .config file before adding the driver.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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