其中有关系到升级内核导致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
yum install -y centos-release-scl
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模块,那应该是没有问题了。希望这样暴力改代码使用起来是不会有问题吧
我这个解决办法是比较乱来,并没有什么严谨的基础知识支撑和对驱动程序透彻的理解,但希望给遇到问题的朋友提供一种解决的思路。
————————————————
版权声明:本文为CSDN博主「weixin_39394823」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_39394823/article/details/131596113
发表评论: