Build WiFi driver for Tenda U12

The GitHub repository morrownr · GitHub has a number of repositories with the source for various RealTek WiFi chipsets. I had a Tenda U12, an older USB WiFi device, that I wanted to try with the VisionFive 2.

I finally derived this procedure after days of reading and trying things involving Linux headers and modules and using both cross compiling and the VisionFive 2 to compile and failing and failing and failing until I finally realized that everything I needed should be in the cross compile image build area and I just had to figure out the correct make command arguments to point make to the proper place to find what it needed.

What I did was to take the file tree created when making a desktop image using this procedure, Building the Debian Image from scratch, and then created a new folder next to soft_3rdpart called soft_extra.

In the directory soft_extra I did a git clone https://github.com/morrownr/8812au-20210629 to download the source. There are several RealTek chipsets so you must pick the correct driver. In my case after much searching I found this site, Tenda U12 - WikiDevi.Wi-Cat.RU which told me it was most likely the RTL8812AU chipset.

I compiled the driver with the following make command, make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv KSRC=$VF2_WORK_DIR/linux and the make completed successfully.

I then used the riscv cross compiler to build the device driver which I then put onto the VisionFive 2 using PuTTY PSFTP.

On the VisionFive 2 I used /sbin/insmod to install the driver. I swapped out the USB WiFi dongle I’ve been using and inserted the Tenda U12. After several very long seconds, I checked dmesg and it looked like the driver was engaged and working. I then went into setup and now I could see both my 2.4 Ghz WiFi and the 5 Ghz WiFi. I authenticated in the Setup utility and was able to watch YouTube videos with FireFox.

1 Like

I have since found that the manufacturer has a download for Linux drivers which contain the source for the driver for the Realtek chipset used in the Tenda U12. I haven’t tried looking at it other than to scan through and it looks like there is a lot of material there along with source code.

I can build my USB to WiFi adapter driver for the Tenda U12 successfully when I use the Debian build work products procedure at Building StarFive Debian image | RVspace.

However when I try to build the device driver against the VisionFive2 repository build work products generated using the README.md file procedure in GitHub - starfive-tech/VisionFive2 I’m getting the following error:

rick@rchamber2:~/Documents/starfive/github/VisionFive2/soft_extra/8812au-20210629$ make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv KSRC=~/Documents/starfive/github/VisionFive2/work/linux
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- -C /home/rick/Documents/starfive/github/VisionFive2/work/linux M=/home/rick/Documents/starfive/github/VisionFive2/soft_extra/8812au-20210629  modules
make[1]: Entering directory '/home/rick/Documents/starfive/github/VisionFive2/work/linux'
  CC      arch/riscv/kernel/vdso/vgettimeofday.o
cc1: error: incompatible gcc/plugin versions
cc1: error: failed to initialize plugin ./scripts/gcc-plugins/structleak_plugin.so
make[2]: *** [/home/rick/Documents/starfive/github/VisionFive2/linux/scripts/Makefile.build:277: arch/riscv/kernel/vdso/vgettimeofday.o] Error 1
make[1]: *** [/home/rick/Documents/starfive/github/VisionFive2/linux/arch/riscv/Makefile:120: vdso_prepare] Error 2
make[1]: Leaving directory '/home/rick/Documents/starfive/github/VisionFive2/work/linux'
make: *** [Makefile:2510: modules] Error 2
rick@rchamber2:~/Documents/starfive/github/VisionFive2/soft_extra/8812au-20210629

This appears to indicate that the compiler I’m using to compile the device driver is not the same compiler as what was used to compile the VisionFive2 repository Linux kernel and BusyBox.

If I change the pathname in the KSRC argument to the Debian build work products, it compiles fine.

I vaguely recall that there is a tools difference between the VisionFive2 procedure and the Debian build procedure.

How can I debug this problem?

Addendum:

Found this handy little app from a Stackoverflow post. It’s in go but it works. The repository is at GitHub - xyproto/elfinfo: Utility for displaying which compiler was used for creating an ELF file + basic info and here is a bit of documentation https://elfinfo.roboticoverlords.org/ Just note that though the documentation mentions using the git: form of git clone that seemed to hang for me while using the https: form downloaded just fine.

Looks like the Debian image build is using GCC 11.4.0 and the VisionFive2 repository image build is using GCC 12.2.0.

Looking through the buildroot file hierarchy in the VisionFive2 repository, I found where it is creating or pulling down the tool chain need to perform compiles. The various make and configuration and other files is quite complex and byzantine however what I did was to do a search in the VisionFive2 GitHub repository until I found some mention of what appeared to be a command line option specifying the compiler name which was riscv64-buildroot-linux-gnu-, a label that is similar to but not quite the same as riscv64-linux-gnu-.

I then did a find . -iname "riscv64-buildroot-linux-gnu"* from the root of the VisionFive2 file tree on my development PC and I found two different directories that had what appeared to be a riscv64 compiler, one in ./work/buildroot_rootfs/host/bin/ and the other in ./work//buildroot_initramfs/host/bin/.

Purely by chance I tried the buildroot_initramfs version first and my device driver compiled. I checked with modinfo and the vermagic label was the same for my compiled 8812au.ko driver as for the ch341.ko built by Buildroot and put in the directory ./work/linux/drivers/usb/serial/. I used the elfinfo utility and both had the same compiler version. I plan to try burning the image onto an SD card and seeing if my device driver will actually load tomorrow.

Strangely, when I tried changing the $PATH environment variable to use the buildroot_rootfs directory version of the compiler, I got a make error:

rick@rchamber2:~/Documents/starfive/github/VisionFive2/soft_extra/8812au-20210629$ make CROSS_COMPILE=riscv64-buildroot-linux-gnu- ARCH=riscv KSRC=~/Documents/starfive/github/VisionFive2/work/linux
make ARCH=riscv CROSS_COMPILE=riscv64-buildroot-linux-gnu- -C /home/rick/Documents/starfive/github/VisionFive2/work/linux M=/home/rick/Documents/starfive/github/VisionFive2/soft_extra/8812au-20210629  modules
make[1]: Entering directory '/home/rick/Documents/starfive/github/VisionFive2/work/linux'
  CC      arch/riscv/kernel/vdso/vgettimeofday.o
cc1: error: incompatible gcc/plugin versions
cc1: error: failed to initialize plugin ./scripts/gcc-plugins/structleak_plugin.so
make[2]: *** [/home/rick/Documents/starfive/github/VisionFive2/linux/scripts/Makefile.build:277: arch/riscv/kernel/vdso/vgettimeofday.o] Error 1
make[1]: *** [/home/rick/Documents/starfive/github/VisionFive2/linux/arch/riscv/Makefile:120: vdso_prepare] Error 2
make[1]: Leaving directory '/home/rick/Documents/starfive/github/VisionFive2/work/linux'
make: *** [Makefile:2510: modules] Error 2

and when I changed it back to buildroot_initramfs, then it compiled fine.

When I used the –version option with each compiler, they both appeared to be the same version, riscv64-buildroot-linux-gnu-gcc.br_real (Buildroot VF2_v3.8.2) 12.2.0.

So it looks like if I add the ~/Documents/starfive/github/VisionFive2/work/buildroot_initramfs/host/bin to the $PATH environment variable then cd to the directory containing the 8812au driver, I can then use make CROSS_COMPILE=riscv64-buildroot-linux-gnu- ARCH=riscv KSRC=~/Documents/starfive/github/VisionFive2/work/linux to compile the driver.