1.前言
编译linux内核失败的原因很多时候就是驱动选错,适合自己本机的驱动没编译进去。面对特殊平台(或者有些洁癖者,我就是^_^),要编译精简内核,只要本机驱动,其他都不需要。面对内核里面这么多驱动,不懂硬件的我们,看到都头大。本人第一次安装gentoo的时候,内核编译了5次,前4次主要失败原因是以太网卡驱动、无线网卡驱动、显卡驱动、声卡驱动都没一次性配置正确。虽然gentoo提供了genkernel命令,可以自动帮你编译内核,但还是想自己手工尝试下。
2.获取本机驱动信息
既然跟内核挂钩,我们获取本机内核驱动信息最直接的办法就是使用lspci命令,这个命令可以输出本机驱动信息,配合-k选项可以看到此驱动在内核的位子。
一般编译内核的场景:更新旧内核,安装定制版linux发行版(gentoo,arch等),嵌入式平台,其他特殊平台等等...
大部分场景在下都可以使用lspci命令,安装gentoo的livecd版都提供了该工具,如果其他系统没有就安装该工具
debian系列安装
$:sudo apt-get install pciutils
或者源码编译安装,下载地址https://www.kernel.org/pub/software/utils/pciutils/
然后我们获取本机环境现存的驱动信息,下面是我的机器上面的信息:
$:lspci -k :) Subsystem: Lenovo Device 21e2 :/2nd Generation Core Processor Family PCI Express Root Port (rev ) Kernel driver in use: pcieport :) Subsystem: Lenovo Device 21e3 Kernel driver in use: i915 : Series/C200 Series Chipset Family MEI Controller # (rev ) Subsystem: Lenovo Device 21e2 Kernel driver in use: mei_me :1a. USB controller: Intel Corporation Series/C200 Series Chipset Family USB Enhanced Host Controller # (rev ) Subsystem: Lenovo Device 21e2 Kernel driver in use: ehci-pci :1b. Audio device: Intel Corporation Series/C200 Series Chipset Family High Definition Audio Controller (rev ) Subsystem: Lenovo Device 21e2 Kernel driver in use: snd_hda_intel :1c. PCI bridge: Intel Corporation Series/C200 Series Chipset Family PCI Express Root Port (rev b4) Kernel driver in use: pcieport :1c. PCI bridge: Intel Corporation Series/C200 Series Chipset Family PCI Express Root Port (rev b4) Kernel driver in use: pcieport :1c. PCI bridge: Intel Corporation Series/C200 Series Chipset Family PCI Express Root Port (rev b4) Kernel driver in use: pcieport :1c. PCI bridge: Intel Corporation Series/C200 Series Chipset Family PCI Express Root Port (rev b4) Kernel driver in use: pcieport :1c. PCI bridge: Intel Corporation Series/C200 Series Chipset Family PCI Express Root Port (rev b4) Kernel driver in use: pcieport :1d. USB controller: Intel Corporation Series/C200 Series Chipset Family USB Enhanced Host Controller # (rev ) Subsystem: Lenovo Device 21e2 Kernel driver in use: ehci-pci :1f. ISA bridge: Intel Corporation HM65 Express Chipset Family LPC Controller (rev ) Subsystem: Lenovo Device 21e2 Kernel driver in use: lpc_ich :1f. SATA controller: Intel Corporation Series/C200 Series Chipset Family port SATA AHCI Controller (rev ) Subsystem: Lenovo Device 21e2 Kernel driver in use: ahci :1f. SMBus: Intel Corporation Series/C200 Series Chipset Family SMBus Controller (rev ) Subsystem: Lenovo Device 21e2 :00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Seymour [Radeon HD 6400M/7400M Series] (rev ff) Kernel driver in use: radeon :/ PCI Express Gigabit Ethernet Controller (rev ) Subsystem: Lenovo Device 21e2 Kernel driver in use: r8169 :) Subsystem: Lenovo Device 21e2 Kernel driver in use: sdhci-pci :.11b/g/n WiFi Adapter (rev ) Subsystem: Realtek Semiconductor Co., Ltd. Device Kernel driver in use: rtl8192ce
我们可以看到每个驱动后面都有Kernel driver in use:,代表驱动在内核中的链接位子。
3.配置内核驱动
下载内核源码https://www.kernel.org/,我这里下载的是stable 4.3.3,解压后进入源码目录执行:
$:make menuconfig
接下来就会弹出编译选项界面,如图:
我们可以看到上面有快捷键操作说明,我重点在</> for Search,在界面直接按反斜杠,进入搜索界面。接下来挑个重点驱动说明一下,我们看
Network controller,可以看到型号是Realtek RTL8188CE,然后Kernel driver in use: rtl8192ce,在内核的位子链接是rtl8192ce
我们按</>,输入rtl8192ce,然后回车,就会出现详细位子,如图:
我们可以看到Pormt提示上面跟我要的型号一样,具体选项的前面有个(1),注意这里同一个Symbol(就是刚刚输入的rtl8192ce)有的对应很多选项,根据前面的序号,按对应的数字就可以直接进入选项,按<esc>可以返回来这个界面。这里,我直接按1。按1后,就到具体选项了,如图:
我们看到上面,发行版为了兼容各种机器,把所有Realtek的驱动都编译进成了模块。接下来就保留自己的驱动型号,去掉其他不要的。
剩下的驱动跟上面操作一样的,还有的不必要驱动是直接编译进了内核,非模块。对照自己的驱动,其他都可以不要。配置好后的内核
配置文件最好保存下来,如果驱动没配置成功,再配置的时候把保存的配置文件复制一份到源码目录,命名为.config。继续make menuconfig配置。