在京东上给家里的台式机(DELL OPTIPLEX 380)买了一个腾达(Tenda)U12 1300M USB无线网卡,遗憾的是腾达官方的U12网卡驱动无法直接使用,因为其支持的Linux内核最大版本为4.4。那就自己想办法编译吧,本文接下来就介绍如何在Ubuntu16.04(32位内核)上编译并安装这一网卡驱动。
00 - 系统信息
$ cat /etc/*release | grep VERSION= VERSION="16.04.6 LTS (Xenial Xerus)" $ uname -rp
4.15.0-88-generic i686
01 - 尝试编译腾达官方提供的rtl8812au驱动
$ wget https://down.tenda.com.cn/uploadfile/U12/U12_linux_v5.1.5_19247_Driver.zip $ unzip U12_linux_v5.1.5_19247_Driver.zip $ cd U12_linux_v5.1.5_19247.20160830/driver $ tar zxf rtl8812AU_linux_v5.1.5_19247.20160830.tar.gz $ cd rtl8812AU_linux_v5.1.5_19247.20160830/ $ make make ARCH=i386 CROSS_COMPILE= -C /lib/modules/4.15.0-88-generic/build M=/tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830 modules make[1]: Entering directory '/usr/src/linux-headers-4.15.0-88-generic' CC [M] /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/core/rtw_cmd.o In file included from /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/include/osdep_service.h:41:0, from /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/include/drv_types.h:32, from /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/core/rtw_cmd.c:22: /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/include/osdep_service_linux.h: In function ‘_init_timer’: /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/include/osdep_service_linux.h:273:8: error: ‘_timer {aka struct timer_list}’ has no member named ‘data’ ptimer->data = (unsigned long)cntx; ^ /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/include/osdep_service_linux.h:274:2: error: implicit declaration of function ‘init_timer’ [-Werror=implicit-function-declaration] init_timer(ptimer); ^ In file included from /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/include/drv_types.h:32:0, from /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/core/rtw_cmd.c:22: /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/include/osdep_service.h: In function ‘thread_enter’: /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/include/osdep_service.h:345:2: error: implicit declaration of function ‘allow_signal’ [-Werror=implicit-function-declaration] allow_signal(SIGTERM); ^ /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/include/osdep_service.h: In function ‘flush_signals_thread’: /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/include/osdep_service.h:355:6: error: implicit declaration of function ‘signal_pending’ [-Werror=implicit-function-declaration] if (signal_pending(current)) ^ /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/include/osdep_service.h:356:3: error: implicit declaration of function ‘flush_signals’ [-Werror=implicit-function-declaration] flush_signals(current); ^ cc1: some warnings being treated as errors scripts/Makefile.build:330: recipe for target '/tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/core/rtw_cmd.o' failed make[2]: *** [/tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/core/rtw_cmd.o] Error 1 Makefile:1577: recipe for target '_module_/tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830' failed make[1]: *** [_module_/tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-88-generic' Makefile:1838: recipe for target 'modules' failed make: *** [modules] Error 2
尝试修改了一些编译错误,例如:
--- /tmp/osdep_service_linux.h +++ /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/include/osdep_service_linux.h @@ -57,6 +57,7 @@ #include <linux/kthread.h> #include <linux/list.h> #include <linux/vmalloc.h> +#include <linux/sched/signal.h> #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 5, 41)) #include <linux/tqueue.h> @@ -270,7 +271,7 @@ { /* setup_timer(ptimer, pfunc,(u32)cntx); */ ptimer->function = pfunc; - ptimer->data = (unsigned long)cntx; + ptimer->expires = (unsigned long)cntx; init_timer(ptimer); }
但是, init_timer(ptimer)的问题一时半会儿解决不了,
make ARCH=i386 CROSS_COMPILE= -C /lib/modules/4.15.0-88-generic/build M=/tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830 modules make[1]: Entering directory '/usr/src/linux-headers-4.15.0-88-generic' CC [M] /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/core/rtw_cmd.o In file included from /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/include/osdep_service.h:41:0, from /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/include/drv_types.h:32, from /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/core/rtw_cmd.c:22: /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/include/osdep_service_linux.h: In function ‘_init_timer’: /tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/include/osdep_service_linux.h:275:2: error: implicit declaration of function ‘init_timer’ [-Werror=implicit-function-declaration] init_timer(ptimer); ^ cc1: some warnings being treated as errors scripts/Makefile.build:330: recipe for target '/tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/core/rtw_cmd.o' failed make[2]: *** [/tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830/core/rtw_cmd.o] Error 1 Makefile:1577: recipe for target '_module_/tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830' failed make[1]: *** [_module_/tmp/U12_linux_v5.1.5_19247.20160830/driver/rtl8812AU_linux_v5.1.5_19247.20160830] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-88-generic' Makefile:1838: recipe for target 'modules' failed make: *** [modules] Error 2
于是果断放弃这一"自己造轮子"的思路!
02 - 搜索现成的解决方案
使用关键字"rtl8812au" + "github"进行google搜索,
果然找到了一个GitHub的repo, Realtek 802.11n WLAN Adapter Linux driver! 既然有人做了对应的修复,那就站在巨人的肩膀上,直接拿来用吧。
$ git clone https://github.com/gnab/rtl8812au.git $ cd rtl8812au $ make $ sudo make install $ file /lib/modules/4.15.0-88-generic/kernel/drivers/net/wireless/8812au.ko /lib/modules/4.15.0-88-generic/kernel/drivers/net/wireless/8812au.ko: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), BuildID[sha1]=4be6be46e28f1bdd558f472dda7d35c86d435ece, not stripped $ modinfo /lib/modules/4.15.0-88-generic/kernel/drivers/net/wireless/8812au.ko filename: /lib/modules/4.15.0-88-generic/kernel/drivers/net/wireless/8812au.ko version: v4.2.3 author: Realtek Semiconductor Corp. description: Realtek Wireless Lan Driver license: GPL srcversion: 719F640400ECDE6A55AB3B9 alias: usb:v0BDAp0823d*dc*dsc*dp*ic*isc*ip*in* ...<snip>.............................................. name: 8812au vermagic: 4.15.0-88-generic SMP mod_unload 686 parm: rtw_ips_mode:The default IPS mode (int) ...<snip>.............................................. parm: rtw_led_enable:Enable status LED (int) $ sudo modprobe 8812au $ sudo lsmod | egrep 8812au 8812au 856064 0
连接wifi成功上网,网卡状态如下:
$ ethinfo enx502b73d14b1b ETH MAC STATE DEVICEID VENDORID MTU SPEED BDF DRIVER IPv4 enx502b73d14b1b 50:2b:73:d1:4b:1b up 1500 1-5:1.0 usb/drivers/rtl8812au 192.168.3.9/24
大功告成!Have fun:-)
03 - 小结
做研究/写论文时,找不到相关文献往往只有两种可能:
- 没有选择合适的关键字(keywords);
- 所提的问题没有意义,没有人做。
科研如此,解决日常生活及工作中遇到的问题也如此。之所以果断放弃自己修复rtl8812au驱动代码的方案,是因为:
- 首先,"自己发明轮子"的难度较大,时间成本太高;
- 其次,这个问题有价值,Linux内核不断迭代,rtl8812au既然没有被停产,那其驱动的升级维护就一定有同行在干或已经干成了。
果然一搜就有现成的代码,那就愉快地站在巨人的肩膀上have fun吧:-)
扩展阅读