Realtek 8168 芯片驱动程序无法在内核 6.5.0-15-generic 上编译有效的驱动程序

Realtek 8168 芯片驱动程序无法在内核 6.5.0-15-generic 上编译有效的驱动程序

我正在尝试安装 Realtek 官方驱动程序,因为 r8168-dkms 无法正常工作。

日志:

cat /var/lib/dkms/r8168/8.049.02/build/make.log
DKMS make.log for r8168-8.049.02 for kernel 6.5.0-15-generic (x86_64)
Tue Feb  6 09:10:19 AM AST 2024
make: Entering directory '/usr/src/linux-headers-6.5.0-15-generic'
  CC [M]  /var/lib/dkms/r8168/8.049.02/build/r8168_n.o
  CC [M]  /var/lib/dkms/r8168/8.049.02/build/r8168_asf.o
  CC [M]  /var/lib/dkms/r8168/8.049.02/build/rtl_eeprom.o
  CC [M]  /var/lib/dkms/r8168/8.049.02/build/rtltool.o
In file included from ./include/linux/string.h:254,
                 from ./include/linux/bitmap.h:11,
                 from ./include/linux/cpumask.h:12,
                 from ./arch/x86/include/asm/paravirt.h:17,
                 from ./arch/x86/include/asm/cpuid.h:62,
                 from ./arch/x86/include/asm/processor.h:19,
                 from ./arch/x86/include/asm/timex.h:5,
                 from ./include/linux/timex.h:67,
                 from ./include/linux/time32.h:13,
                 from ./include/linux/time.h:60,
                 from ./include/linux/stat.h:19,
                 from ./include/linux/module.h:13,
                 from /var/lib/dkms/r8168/8.049.02/build/r8168_n.c:43:
/var/lib/dkms/r8168/8.049.02/build/r8168_n.c: In function ‘rtl8168_set_mac_address’:
/var/lib/dkms/r8168/8.049.02/build/r8168_n.c:24197:19: warning: passing argument 1 of ‘__builtin_memcpy’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
24197 |         memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
      |                ~~~^~~~~~~~~~
./include/linux/fortify-string.h:648:27: note: in definition of macro ‘__fortify_memcpy_chk’
  648 |         __underlying_##op(p, q, __fortify_size);                        \
      |                           ^
/var/lib/dkms/r8168/8.049.02/build/r8168_n.c:24197:9: note: in expansion of macro ‘memcpy’
24197 |         memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
      |         ^~~~~~
/var/lib/dkms/r8168/8.049.02/build/r8168_n.c:24197:19: note: expected ‘void *’ but argument is of type ‘const unsigned char *’
24197 |         memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
      |                ~~~^~~~~~~~~~
./include/linux/fortify-string.h:648:27: note: in definition of macro ‘__fortify_memcpy_chk’
  648 |         __underlying_##op(p, q, __fortify_size);                        \
      |                           ^
/var/lib/dkms/r8168/8.049.02/build/r8168_n.c:24197:9: note: in expansion of macro ‘memcpy’
24197 |         memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
      |         ^~~~~~
/var/lib/dkms/r8168/8.049.02/build/r8168_n.c:24199:32: warning: passing argument 2 of ‘rtl8168_rar_set’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
24199 |         rtl8168_rar_set(tp, dev->dev_addr);
      |                             ~~~^~~~~~~~~~
/var/lib/dkms/r8168/8.049.02/build/r8168_n.c:575:59: note: expected ‘uint8_t *’ {aka ‘unsigned char *’} but argument is of type ‘const unsigned char *’
  575 | void rtl8168_rar_set(struct rtl8168_private *tp, uint8_t *addr);
      |                                                  ~~~~~~~~~^~~~
/var/lib/dkms/r8168/8.049.02/build/r8168_n.c: In function ‘r8168_csum_workaround’:
/var/lib/dkms/r8168/8.049.02/build/r8168_n.c:27733:24: error: implicit declaration of function ‘skb_gso_segment’; did you mean ‘skb_gso_reset’? [-Werror=implicit-function-declaration]
27733 |                 segs = skb_gso_segment(skb, features);
      |                        ^~~~~~~~~~~~~~~
      |                        skb_gso_reset
/var/lib/dkms/r8168/8.049.02/build/r8168_n.c:27733:22: warning: assignment to ‘struct sk_buff *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
27733 |                 segs = skb_gso_segment(skb, features);
      |                      ^
/var/lib/dkms/r8168/8.049.02/build/r8168_n.c: In function ‘rtl8168_resume’:
/var/lib/dkms/r8168/8.049.02/build/r8168_n.c:28693:32: warning: passing argument 2 of ‘rtl8168_rar_set’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
28693 |         rtl8168_rar_set(tp, dev->dev_addr);
      |                             ~~~^~~~~~~~~~
/var/lib/dkms/r8168/8.049.02/build/r8168_n.c:24214:26: note: expected ‘uint8_t *’ {aka ‘unsigned char *’} but argument is of type ‘const unsigned char *’
24214 |                 uint8_t *addr)
      |                 ~~~~~~~~~^~~~
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:251: /var/lib/dkms/r8168/8.049.02/build/r8168_n.o] Error 1
make[1]: *** [/usr/src/linux-headers-6.5.0-15-generic/Makefile:2037: /var/lib/dkms/r8168/8.049.02/build] Error 2
make: *** [Makefile:234: __sub-make] Error 2
make: Leaving directory '/usr/src/linux-headers-6.5.0-15-generic'
lspci | grep Ethernet
04:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 0c)

我也尝试自己添加代码,但对于 6.5.0-14,我犯了一个错误。还删除了,sudo rm -rf /var/lib/dkms/r8168/8.052.01/似乎asudo rm -rf /var/lib/dkms/r8168/有些东西还在徘徊,不让我重试这些步骤。

控制台输出:

sudo dkms build r8168/8.052.01 --force
Kernel preparation unnecessary for this kernel. Skipping...
Building module:
cleaning build area...
make -j12 KERNELRELEASE=6.5.0-15-generic...(bad exit status: 2)
Error! Bad return status for module build on kernel: 6.5.0-15-generic (x86_64)
Consult /var/lib/dkms/r8168/8.052.01/build/make.log for more information.
cat /var/lib/dkms/r8168/8.052.01/build/make.log
DKMS make.log for r8168-8.052.01 for kernel 6.5.0-15-generic (x86_64)
Tue Feb  6 10:45:03 AM AST 2024
make -C src/ clean
make -C src/ modules
make -C src/ install
make[1]: Entering directory '/var/lib/dkms/r8168/8.052.01/build/src'
make[1]: Entering directory '/var/lib/dkms/r8168/8.052.01/build/src'
make[1]: *** No rule to make target 'clean'.  Stop.
make[1]: *** No rule to make target 'modules'.  Stop.
make[1]: Leaving directory '/var/lib/dkms/r8168/8.052.01/build/src'
make[1]: Leaving directory '/var/lib/dkms/r8168/8.052.01/build/src'
make[1]: Entering directory '/var/lib/dkms/r8168/8.052.01/build/src'
make[1]: *** No rule to make target 'install'.  Stop.
make[1]: Leaving directory '/var/lib/dkms/r8168/8.052.01/build/src'
make: *** [Makefile:48: clean] Error 2
make: *** Waiting for unfinished jobs....
make: *** [Makefile:41: modules] Error 2
make: *** [Makefile:55: install] Error 2
sudo dkms build r8168 -v 8.052.01 -k 6.5.0-15-generic --force //Can't force rebuild since Makefile has no clean rule.

Kernel preparation unnecessary for this kernel. Skipping...

Building module:
cleaning build area...
make -j12 KERNELRELEASE=6.5.0-15-generic...(bad exit status: 2)
Error! Bad return status for module build on kernel: 6.5.0-15-generic (x86_64)

NOTE: I had noticed that if I had booted into Windows 10 that when I booted back to Ubuntu without a hard power cycle that the NIC would not work correctly. This was actually due to the driver version in Windows creating this problem for some reason. To fix it I had booted back into Windows and downloaded and installed the 10.69 driver from Realtek themselves. Now rebooting from Windows back into Ubuntu there is no issues.

驱动程序安装:

我本来想在 r8168-dkms 上提交一个错误,但是它指出它不是一个官方软件包。

22.04 LTS 存储库中的 8.049.02 版本或 r8168-dkms 驱动程序似乎与 6.5.0-14-generic 内核不兼容,并且 dkms 无法安装该驱动程序。

启动回工作内核并从这里下载 Realtek 8.052.01 驱动程序。

ps autorun.sh 文件不会在 dkms 中设置驱动程序,这需要您在下次内核更新时重新安装该驱动程序。

在安装新的驱动程序之前,我建议从树中删除 8.049.02 驱动程序,以便 dkms 不会尝试将其安装到会导致失败的较新的内核中。

sudo dkms remove r8168/8.049.02 --all

下载驱动程序后,继续并提取文件。

tar xvf r8168-8.052.01.tar.bz2

输入新创建目录。

cd r8168-8.052.01/src

为驱动程序创建一个新的内核源目录。

sudo mkdir /usr/src/r8168-8.052.01

并将所有文件复制到新目录。

sudo cp -v * /usr/src/r8168-8.052.01/

为驱动程序创建一个新的 dkms.conf 文件。

sudo nano /usr/src/r8168-8.052.01/dkms.conf

现在将以下内容添加到文件中。

PACKAGE_NAME="r8168"
PACKAGE_VERSION="8.052.01"
BUILT_MODULE_NAME[0]="$PACKAGE_NAME"
DEST_MODULE_LOCATION[0]="/updates/dkms"
AUTOINSTALL="YES"
REMAKE_INITRD="YES"

保存文件并运行下一行来构建和安装驱动程序。

sudo dkms add r8168/8.052.01
sudo dkms build r8168/8.052.01 -k 6.5.0-14-generic
sudo dkms install r8168/8.052.01 -k 6.5.0-14-generic

来源

答案1

根据您的日志,您有 8.049.02 驱动程序的残留。该驱动程序版本与 6.5.0-xx-generic 内核不兼容。最好将其删除。您的新驱动程序应该已经安装,但如果您不想再看到它,请删除该驱动程序。

sudo dkms remove r8168/8.049.02 --all

这样就可以将它从内核树中彻底删除。

无论旧驱动程序从哪个内核版本中删除,您都可以将新驱动程序重新添加进去。例如,r8168/8.049.02 从 6.2.0-39-generic 中删除,然后您可以运行以下命令将其重新添加至该内核。

sudo dkms build r8168/8.052.01 -k 6.2.0-39-generic
sudo dkms install r8168/8.052.01 -k 6.2.0-39-generic

您可以随时通过运行来查看已安装的驱动程序dkms status

相关内容