解決linux 編譯核心網卡驅動問題

來源:互聯網
上載者:User

由於項目原因,需要從新編譯核心,修改 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.