记一次centos7编译安装r8168网卡错误解决

CentOS7内置Realtek网卡驱动r8169降级r8168的问题在网上也有不少文章。(1条消息) centos7物理机升级内核_centos7升级内核,网卡没有了_kkooll2013的博客-CSDN博客https://blog.csdn.net/kkooll2013/article/details/128049937?ops_request_misc=&request_id=&biz_id=102&utm_term=KKOOLL2013&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0-128049937.142%5Ev71%5Ejs_top,201%5Ev4%5Eadd_ask&spm=1018.2226.3001.4187其中有关系到升级内核导致r8168在新内核识别为r8169的原因。

所以,解决的办法就是重新安装8168网卡驱动呗,但安装8168驱动的过程并不顺利。

关于gcc:

按上面教程,首先要编译gcc安装。但编译过程就是几个小时,所以,没什么事能不编译gcc吗?

答案是有的。可以直接yum install gcc 安装,但安装到的版本不对,编译会出现

./autorun.sh

Check old driver and unload it.
rmmod r8168
Build the module and install
warning: the compiler differs from the one used to build the kernel
  The kernel was built by: gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
  You are using:           gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
gcc: 错误:unrecognized command line option ‘-fpatchable-function-entry=16,16’
gcc: 错误:unrecognized command line option ‘-mrecord-mcount’
gcc: 错误:unrecognized command line option ‘-Wimplicit-fallthrough=5’
make[4]: *** [/root/r8168-8.051.02/src/r8168_n.o] 错误 1
make[3]: *** [/root/r8168-8.051.02/src] 错误 2
make[2]: *** [__sub-make] 错误 2
make[1]: *** [modules] 错误 2

make: *** [modules] 错误 2

这个错误。又在网上找教程,找到CentOS/Ubuntu安装最新的gcc-9 - codeRhythm - 博客园 (cnblogs.com)https://www.cnblogs.com/codeRhythm/p/13809904.html

sudo yum install -y centos-release-scl

sudo yum install -y devtoolset-9-gcc devtoolset-9-gcc-c++

scl enable devtoolset-9 bash

gcc -v

几行命令,能用,是gcc9,适合centos7最新的内核。

关于编译安装:

关于编译安装,需要改网上驱动的代码。可以参考这篇博客:

CentOS7内置Realtek网卡驱动r8169降级r8168 https://www.cnblogs.com/xujiecnblogs/p/16725022.html

./autorun.sh

Check old driver and unload it.
Build the module and install
In file included from /root/r8168-8.051.02/src/r8168_n.c:87:
/root/r8168-8.051.02/src/r8168_n.c: In function ‘rtl8168_init_one’:
/root/r8168-8.051.02/src/r8168.h:569:57: error: too many arguments to function ‘netif_napi_add’
569 | #define RTL_NAPI_CONFIG(ndev, priv, function, weight) netif_napi_add(ndev, &priv->napi, function, weight)
| ^~~~~~~~~~~~~~
/root/r8168-8.051.02/src/r8168_n.c:27014:9: note: in expansion of macro ‘RTL_NAPI_CONFIG’
27014 | RTL_NAPI_CONFIG(dev, tp, rtl8168_poll, R8168_NAPI_WEIGHT);
| ^~~~~~~~~~~~~~~
In file included from /root/r8168-8.051.02/src/r8168_n.c:46:
./include/linux/netdevice.h:2588:1: note: declared here
2588 | netif_napi_add(struct net_device *dev, struct napi_struct *napi,
| ^~~~~~~~~~~~~~
make[4]: *** [/root/r8168-8.051.02/src/r8168_n.o] 错误 1
make[3]: *** [/root/r8168-8.051.02/src]

可是我运行./autorun.sh的错误和博主的错误是不一样的呀。这代码咋改啊。

现在能从网上找到的8168驱动就只有这三个版本了。每一个版本的错误都不一样。我挑了显示错误最少的r8168-8.051.02入手。

解决问题的流程:

对于没有写代码工程经验的人,面对一个网卡驱动仍然是无法入手。大家可以看我上面转载的博客。里面的留言评论充满了我对博主的恳求帮助。经过几天时间得不到回复,只能自动动手拆解问题了。

1、/root/r8168-8.051.02/src/r8168.h:569:57: error: too many arguments to function ‘netif_napi_add’
569 | #define RTL_NAPI_CONFIG(ndev, priv, function, weight) netif_napi_add(ndev, &priv->napi, function, weight)根据这个error提示,r8168.h文件的569行方法“netif_napi_add”有太多的参数,先找到r8168.h文件的569行

定义了“netif_napi_add”有四个参数(ndev, &priv->napi, function, weight)

2、又根据提示找r8168_n.c这个文件,这个文件3万行,没有“netif_napi_add”的引用,只有“RTL_NAPI_CONFIG”,提示里没有关于“RTL_NAPI_CONFIG”的报错,先不管。留意到

 In file included from /root/r8168-8.051.02/src/r8168_n.c:46:
./include/linux/netdevice.h:2588:1: note: declared here
2588 | netif_napi_add(struct net_device *dev, struct napi_struct *napi,

这句话,对应文件的46行,确定是有

 对linux/netdevice.h文件的包含引用。

3、查找linux/netdevice.h。但问题来了,linux/netdevice.h在哪里找?又是各种网上找帖子。有找到下面等这些文章看的云里雾里,依然是找不到北。

(1条消息) GCC/G++编译器中指定库文件(LIB)、头文件(INCLUDE)_gcc lib_赶路人儿的博客-CSDN博客https://blog.csdn.net/liuxiao723846/article/details/97617681解决问题的突破在log.txt 

2023年 07月 04日 星期二 20:54:51 CST
make -C src/ clean
make[1]: 进入目录“/root/r8168-8.051.02/src”
make -C /lib/modules/6.2.9-1.el7.elrepo.x86_64/build M=/root/r8168-8.051.02/src clean
make[2]: 进入目录“/usr/src/kernels/6.2.9-1.el7.elrepo.x86_64”
make[2]: 离开目录“/usr/src/kernels/6.2.9-1.el7.elrepo.x86_64”
make[1]: 离开目录“/root/r8168-8.051.02/src”
make -C src/ modules
make[1]: 进入目录“/root/r8168-8.051.02/src”
make -C /lib/modules/6.2.9-1.el7.elrepo.x86_64/build M=/root/r8168-8.051.02/src modules
make[2]: 进入目录“/usr/src/kernels/6.2.9-1.el7.elrepo.x86_64”
  CC [M]  /root/r8168-8.051.02/src/r8168_n.o
make[2]: 离开目录“/usr/src/kernels/6.2.9-1.el7.elrepo.x86_64”
make[1]: 离开目录“/root/r8168-8.051.02/src”

 这是log的内容。上面显示make进入了“/usr/src/kernels/6.2.9-1.el7.elrepo.x86_64”这个目录,最终还是在/usr/src/kernels/6.2.9-1.el7.elrepo.x86_64/include/linux/这个目录里找到了netdevice.h。打开找到2588行,

确实是比r8168.h文件的569行定义的“netif_napi_add”少了一个参数,一个逗号代表一个参数。虽然我并不理解参数的具体含义。

于是,我大起胆子,内核源文件我是不敢改。驱动源文件我就改一下呗。

 经过比对,既然netdevice.h的2588行定义了一个netif_napi_add_weight的方法,可以对比看出“netif_napi_add”多了的参数就是WEIGHT,把参数删了,再运行./autorun.sh

./autorun.sh

Check old driver and unload it.
Build the module and install
At main.c:167:
- SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:175
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:182
sign-file: ./certs/signing_key.pem
DEPMOD 6.2.9-1.el7.elrepo.x86_64
load module r8168
Completed.

等一下,它会备份 原来r8169模块,加载r8168模块,看到load module r8168 Completed.就是说成功了。lspci -v

06:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 15)
        Subsystem: Realtek Semiconductor Co., Ltd. Device 0123
        Flags: bus master, fast devsel, latency 0, IRQ 16
        I/O ports at e000 [size=256]
        Memory at fbc04000 (64-bit, non-prefetchable) [size=4K]
        Memory at fbc00000 (64-bit, non-prefetchable) [size=16K]
        Capabilities: [40] Power Management version 3
        Capabilities: [50] MSI: Enable- Count=1/1 Maskable- 64bit+
        Capabilities: [70] Express Endpoint, MSI 01
        Capabilities: [b0] MSI-X: Enable+ Count=4 Masked-
        Capabilities: [100] Advanced Error Reporting
        Capabilities: [140] Virtual Channel
        Capabilities: [160] Device Serial Number 01-00-00-00-68-4c-e0-00
        Capabilities: [170] Latency Tolerance Reporting
        Capabilities: [178] L1 PM Substates
        Kernel driver in use: r8168
        Kernel modules: r8168
 

看到加载的是r8168模块,那应该是没有问题了。希望这样暴力改代码使用起来是不会有问题吧

我这个解决办法是比较乱来,并没有什么严谨的基础知识支撑和对驱动程序透彻的理解,但希望给遇到问题的朋友提供一种解决的思路。

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
以下是在CentOS 7安装BCM43142无线网卡驱动的步骤: 1. 确认无线网卡型号:使用以下命令查看无线网卡型号: ```shell lspci | grep Network ``` 如果输出中包含"BCM43142",则确认使用的是博通BCM43142无线网卡。 2. 安装必要的软件包:使用以下命令安装所需的软件包: ```shell sudo yum install -y kernel-devel sudo yum install -y gcc ``` 3. 下载驱动程序:从官方网站下载适用于CentOS 7的BCM43142无线网卡驱动程序。将驱动程序文件保存到本地目录。 4. 解压驱动程序:使用以下命令解压驱动程序文件: ```shell tar -zxvf <驱动程序文件名>.tar.gz ``` 5. 进入驱动程序目录:使用以下命令进入解压后的驱动程序目录: ```shell cd <驱动程序目录> ``` 6. 编译安装驱动程序:使用以下命令编译安装驱动程序: ```shell make sudo make install ``` 7. 加载驱动程序:使用以下命令加载驱动程序: ```shell sudo modprobe <驱动程序模块名> ``` 8. 配置无线网络:使用以下命令配置无线网络连接: ```shell sudo nmcli dev wifi connect <无线网络名称> password <无线网络密码> ``` 将"<无线网络名称>"替换为你要连接的无线网络的名称,将"<无线网络密码>"替换为你要连接的无线网络的密码。 请注意,以上步骤仅适用于CentOS 7,并且需要下载适用于CentOS 7的BCM43142无线网卡驱动程序。如果你使用的是其他操作系统或版本,请参考相应的文档或官方网站获取适用于你的系统的驱动程序和安装说明。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值