码迷,mamicode.com
首页 > 系统相关 > 详细

linux内核编译,配置本机驱动

时间:2016-01-01 20:59:09      阅读:364      评论:0      收藏:0      [点我收藏+]

标签:

1.前言                                                  

编译linux内核失败的原因很多时候就是驱动选错,适合自己本机的驱动没编译进去。面对特殊平台(或者有些洁癖者,我就是^_^),要编译精简内核,只要本机驱动,其他都不需要。面对内核里面这么多驱动,不懂硬件的我们,看到都头大。本人第一次安装gentoo的时候,内核编译了5次,前4次主要失败原因是以太网卡驱动、无线网卡驱动、显卡驱动、声卡驱动都没一次性配置正确。虽然gentoo提供了genkernel命令,可以自动帮你编译内核,但还是想自己手工尝试下。

2.获取本机驱动信息                              

既然跟内核挂钩,我们获取本机内核驱动信息最直接的办法就是使用lspci命令,这个命令可以输出本机驱动信息,配合-k选项可以看到此驱动在内核的位子。

一般编译内核的场景:更新旧内核,安装定制版linux发行版(gentoo,arch等),嵌入式平台,其他特殊平台等等...

大部分场景在下都可以使用lspci命令,安装gentoo的livecd版都提供了该工具,如果其他系统没有就安装该工具

debian系列安装

1 $:sudo apt-get install pciutils 

或者源码编译安装,下载地址https://www.kernel.org/pub/software/utils/pciutils/

然后我们获取本机环境现存的驱动信息,下面是我的机器上面的信息:

 1 $:lspci -k
 2 00:00.0 Host bridge: Intel Corporation 2nd Generation Core Processor Family DRAM Controller (rev 09)
 3     Subsystem: Lenovo Device 21e2
 4 00:01.0 PCI bridge: Intel Corporation Xeon E3-1200/2nd Generation Core Processor Family PCI Express Root Port (rev 09)
 5     Kernel driver in use: pcieport
 6 00:02.0 VGA compatible controller: Intel Corporation 2nd Generation Core Processor Family Integrated Graphics Controller (rev 09)
 7     Subsystem: Lenovo Device 21e3
 8     Kernel driver in use: i915
 9 00:16.0 Communication controller: Intel Corporation 6 Series/C200 Series Chipset Family MEI Controller #1 (rev 04)
10     Subsystem: Lenovo Device 21e2
11     Kernel driver in use: mei_me
12 00:1a.0 USB controller: Intel Corporation 6 Series/C200 Series Chipset Family USB Enhanced Host Controller #2 (rev 04)
13     Subsystem: Lenovo Device 21e2
14     Kernel driver in use: ehci-pci
15 00:1b.0 Audio device: Intel Corporation 6 Series/C200 Series Chipset Family High Definition Audio Controller (rev 04)
16     Subsystem: Lenovo Device 21e2
17     Kernel driver in use: snd_hda_intel
18 00:1c.0 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 1 (rev b4)
19     Kernel driver in use: pcieport
20 00:1c.1 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 2 (rev b4)
21     Kernel driver in use: pcieport
22 00:1c.2 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 3 (rev b4)
23     Kernel driver in use: pcieport
24 00:1c.3 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 4 (rev b4)
25     Kernel driver in use: pcieport
26 00:1c.7 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 8 (rev b4)
27     Kernel driver in use: pcieport
28 00:1d.0 USB controller: Intel Corporation 6 Series/C200 Series Chipset Family USB Enhanced Host Controller #1 (rev 04)
29     Subsystem: Lenovo Device 21e2
30     Kernel driver in use: ehci-pci
31 00:1f.0 ISA bridge: Intel Corporation HM65 Express Chipset Family LPC Controller (rev 04)
32     Subsystem: Lenovo Device 21e2
33     Kernel driver in use: lpc_ich
34 00:1f.2 SATA controller: Intel Corporation 6 Series/C200 Series Chipset Family 6 port SATA AHCI Controller (rev 04)
35     Subsystem: Lenovo Device 21e2
36     Kernel driver in use: ahci
37 00:1f.3 SMBus: Intel Corporation 6 Series/C200 Series Chipset Family SMBus Controller (rev 04)
38     Subsystem: Lenovo Device 21e2
39 01:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Seymour [Radeon HD 6400M/7400M Series] (rev ff)
40     Kernel driver in use: radeon
41 03:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 06)
42     Subsystem: Lenovo Device 21e2
43     Kernel driver in use: r8169
44 04:00.0 System peripheral: Ricoh Co Ltd PCIe SDXC/MMC Host Controller (rev 07)
45     Subsystem: Lenovo Device 21e2
46     Kernel driver in use: sdhci-pci
47 09:00.0 Network controller: Realtek Semiconductor Co., Ltd. RTL8188CE 802.11b/g/n WiFi Adapter (rev 01)
48     Subsystem: Realtek Semiconductor Co., Ltd. Device 8195
49     Kernel driver in use: rtl8192ce

我们可以看到每个驱动后面都有Kernel driver in use:,代表驱动在内核中的链接位子。

3.配置内核驱动                              

下载内核源码https://www.kernel.org/,我这里下载的是stable 4.3.3,解压后进入源码目录执行:

1 $:make menuconfig

接下来就会弹出编译选项界面,如图:

技术分享

我们可以看到上面有快捷键操作说明,我重点在</> for Search,在界面直接按反斜杠,进入搜索界面。接下来挑个重点驱动说明一下,我们看

Network controller,可以看到型号是Realtek  RTL8188CE,然后Kernel driver in use: rtl8192ce,在内核的位子链接是rtl8192ce

我们按</>,输入rtl8192ce,然后回车,就会出现详细位子,如图:

技术分享技术分享

我们可以看到Pormt提示上面跟我要的型号一样,具体选项的前面有个(1),注意这里同一个Sombol(就是刚刚输入的rtl8192ce)有的对应很多选项,我根据前面的序号,按对应的数字就可以直接进入选项,按<esc>可以返回来这个界面。这里,我直接按1。按1后,就到具体选项了,如图:

技术分享

我们看到上面,发行版为了兼容各种机器,把所有Realtek的驱动都编译进成了模块。接下来就保留自己的驱动型号,去掉其他不要的。

剩下的驱动跟上面操作一样的,还有的不必要驱动是直接编译进了内核,非模块。对照自己的驱动,其他都可以不要。配置好后的内核

配置文件最好保存下来,如果驱动没配置成功,再配置的时候把保存的配置文件复制一份到源码目录,命名为.config。继续make menuconfig配置。 

linux内核编译,配置本机驱动

标签:

原文地址:http://www.cnblogs.com/yuuyuu/p/5093335.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!