Your Linux distro or even the stock Linux kernel comes with all thinkable drivers for all those hardware that they supported. Most of them are preselected by default (base on hardware architecture) to cover a wide palette of hardware.
However, if you are going to compile a Linux kernel only for your system, you should select/include only those modules that have something to do with your system. By cutting down the default kernel configuration you will save time, memory and will make your system faster.
How could you find out what drivers are need it by your system?If you have already a functional system or if you can boot a Live Linux CD then all you have to do is to look into the Linux system filesystem (sysfs) and to determine which device is using what driver.
For instance, to determine what driver is my network card using, first I need to know the network interface (eq. eth0, wlan0, etc) I want to find what where does the symlink /sys/class/net/<net-if>/device/driver/module point to.
In my case if I run the command ls against the path specified earlier I get the relative path to the driver module for my network card (where <net-if>=wlan1):
user@rpi-gentoo ~ $ ls -l /sys/class/net/<net-if>/device/driver/module /sys/class/net/wlan1/device/driver/module -> ../../../../module/ath5k
As you can see the driver needed by this device is called ath5k. To setup the kernel to include this driver all I have to do is to search a configuration parameter named CONFIG_%ATH5K% (where % means one or more characters).
You should not be surprised if you will find more than one parameter with the pattern shown above because there could hundreds devices from that vendor. For example, the following configuration parameters contain the pattern show earlier:
CONFIG_ATH5K CONFIG_ATH5K_AHB CONFIG_ATH5K_DEBUG CONFIG_ATH5K_PCI
If you want to understand what means any of those drivers I suggest you to look them up on Linux Hardware Database (lhwdb.org). The query string for any kernel configuration parameter is:
Note: the CONFIG_ prefix in the example above is stripped, so if the kernel parameter is named CONFIG_parameter you should use only the parameter part in the lhwdb.org query (or just go to lhwdb.org and use the damn search box :o).
Ok, so you’ve found out what is the driver name for you network card, right? But there could be at least 10-20 different drivers and finally, just to determine the kernel configuration name you have to search the content of at least 1600 different kernel Makefiles. It could be done automatically, though:
#!/bin/bash TMP=$(mktemp) FLIST=$(mktemp) find -type f -name Makefile|sort -u > $FLIST for f in $(find /sys/ -type l -name driver 2>/dev/null) ; do test -e $f/module && basename `readlink $f/module` done|sort -u >$TMP for m in $(cat $TMP);do echo -e "\e[33;1;31m[$m]\e[0m" for f in $(cat $FLIST);do grep -io "(CONFIG_.*$m.*)" $f done|sort -u done|sed -e 's/^.*(//g;s/).*$//g' rm -f $TMP $FLIST
The output of the code above run on my system looks like this (but it could look different on your system):
[ahci] CONFIG_EXYNOS4_DEV_AHCI CONFIG_IMX_HAVE_PLATFORM_AHCI CONFIG_SATA_ACARD_AHCI CONFIG_SATA_AHCI CONFIG_SATA_AHCI_PLATFORM [ath5k] CONFIG_ATH5K CONFIG_ATH5K_AHB CONFIG_ATH5K_DEBUG CONFIG_ATH5K_PCI [coretemp] CONFIG_SENSORS_CORETEMP [drm] CONFIG_DRM CONFIG_DRM_AST CONFIG_DRM_CIRRUS_QEMU CONFIG_DRM_EXYNOS ... CONFIG_DRM_I915 ... [ehci_hcd] CONFIG_USB_EHCI_HCD CONFIG_USB_EHCI_HCD_PLATFORM [snd_hda_intel] CONFIG_SND_HDA_INTEL [uhci_hcd] CONFIG_USB_UHCI_HCD [usbcore] [usbhid]
I searched on lhwdb.org and I’ve determined what represents each of these drivers and I’ve decided that those written with bold are the ones I need.
To include these and only these drivers on my Linux kernel, all I have to do is to step in each class of “Device drivers” (the lhwdb.org tells you even the kernel menus where to find these configuration parameters) and to select only those parameters that match with those shown by the output of the script above.
Final note: The method shown above it’s just the tip of the iceberg since it covers the process of finding the core drivers for the system. In order to determine each tiny driver used by each tiny device you might have, I would recommend reading the “Linux kernel in a Nutshell” by Greg Kroah-Hartman, which presents more techniques regarding this topic.