解决linux 编译内核网卡驱动问题

作者:简简单单 2016-03-29

由于项目原因,需要从新编译内核,修改 TUN 源码支持共享模式,编译内核期间遇到了网卡驱动丢失问题,废话不多说,直接说解决问题的方式,本人对底层的东西了解很浅,所以解决问题的方式也很笨拙。

OS version : Centos 5.9 kernel : 2.6.18-402 更新内核版本: 2.6.20

由于 yum 里面的内核头文件和卡发包并没有过多的源码 .c 文件。所以只能从 www.kernel.org 下载 相近的版本,有人肯定说了下你还不下个最新的 内核版本,答: 如内核版本跨度比较大,本人担心会出现各种问题,很多老的编译选项新版内核不支持。

首先先下载 原系统的 开发包和头文件:

shell $> yum install kernel-devel kernel-headers
解压 2.6.20 内核压缩包,开始编译内核
shell $> mv linux-2.6.20.tar.bz2 /usr/src/
shell $> cd /usr/src/
shell $> tar jxvf linux-2.6.20.tar.bz2
shell $> cd linux-2.6.20

# 修改源码 更改自己需要的,我修改了 tun 相关的 源码文件。

shell $> make mrproper

# 选择需要的选项和修改的选项,删除多余的选项

shell $> make menuconfig
shell $> make -j 12
shell $> make modules_install
shell $> make install

# 修改 grub.conf 用新内核启动后发现网卡驱动并未发现!但是驱动加载了

2.6.20 shell $> lsmod |grep tg3
# 查看日志:

2.6.20 shell $> vim /var/log/message

# 查找tg3 相关日志:

Feb 26 11:02:01 localhost kernel: input: PC Speaker as /class/input/input1
Feb 26 11:02:01 localhost kernel: tg3: Unknown symbol pci_channel_offline
Feb 26 11:02:01 localhost kernel: intel_rng: Firmware space is locked read-only. If you can't or
Feb 26 11:02:01 localhost kernel: intel_rng: don't want to disable this in firmware setup, and if
Feb 26 11:02:01 localhost kernel: intel_rng: you are certain that your system has a functional
Feb 26 11:02:01 localhost kernel: intel_rng: RNG, try using the 'no_fwh_detect' option.
# 看到了 pci_channel_offline
# 下载对应网卡的驱动,编译安装看是否有错:
shell $> wget http://www.broadcom.com/support/license.php?file=570x/linux-3.136h.zip
shell $> reboot
2.6.20 shell $> unzip linux-3.137h.zip
2.6.20 shell $> tar zxvf tg3-3.136h.tar.gz
2.6.20 shell $> cd tg3-3.136h
2.6.20 shell $> make

# 并没有报错,但是有警告:

sh makeflags.sh /lib/modules/2.6.20/source  > tg3_flags.h
make -C /lib/modules/2.6.20/build SUBDIRS=/data1/software/tg3-3.136h modules
make[1]: Entering directory `/data1/software/linux-2.6.20'
  CC [M]  /data1/software/tg3-3.136h/tg3.o
/data1/software/tg3-3.136h/tg3.c: In function ‘tg3_ape_lock’:
/data1/software/tg3-3.136h/tg3.c:845: 警告:隐式声明函数 ‘pci_channel_offline’
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: "pci_channel_offline" [/data1/software/tg3-3.136h/tg3.ko] undefined!
  CC      /data1/software/tg3-3.136h/tg3.mod.o
  LD [M]  /data1/software/tg3-3.136h/tg3.ko
make[1]: Leaving directory `/data1/software/linux-2.6.20'

# 按照常规,警告我们是可以忽略的,那么我们更新这个驱动应该就没问题了,我跟你想的一样可是他还是有问题的

2.6.20 shell $> make install
2.6.20 shell $> rmmod tg3
2.6.20 shell $> modprobe tg3

# 还是报错了,看日志还是 Unknown symbol pci_channel_offline
# 然后我就想 ,那我在老内核里编译看出错吗?结果在老内核里没有报错,我就在看老内核里 的 pci.h 文件,找到了 pci_channel_offline 方法:

static inline int pci_channel_offline(struct pci_dev *pdev)
{
        return (pdev->error_state != pci_channel_io_normal);
}
# 那么好,我把这段 复制到 2.6.20 内核里的 pci.h 里面
2.6.20 shell $> vim /usr/src/linux-2.6.20/include/linux/pci.h
# 加在 183行下面,在从新编译 网卡驱动
2.6.20 shell $> make clean
2.6.20 shell $> make
# 这次 make 没错了
2.6.20 shell $> make install
2.6.20 shell $> rmmod tg3
2.6.20 shell $> modprobe tg3
# 重启网卡
2.6.20 shell $> /etc/init.d/network restart

相关文章

精彩推荐