Compiling the rtl8812au Wifi Driver for Raspbian

updated on 2020-01-30

Motivation

In the beginning of 2016 the Raspberry Pi Foundation released the Raspberry Pi 3 Model B. It was the first Raspberry Pi model that was equipped with 802.11 Wireless LAN out of the box. Previous models just didn’t have wifi. Buying a wifi USB dongle is the only way to use Wireless LAN with older models like the Raspberry Pi 2 Model B.

The drawback of Raspberry Pi 3’s wifi, the very popular Edimax EW-7811Un or even the official Raspbery Pi USB Wifi Dongle is that all of them only operate in the 2.4Ghz band (IEEE 802.11b/g/n). If you live in a big city like me you may have noticed that those frequencies are pretty crowded. That’s because each of your neighbours runs his own access point. I’m talking of 30+ wireless networks within reach. That means a lot of interference and concurrent usage of frequencies. In such an environment throughput performance is quite bad. Sometimes also connection losses occur. If it’s really bad not even switching the channel helps. Fortunatelly the IEEE 802.11 standard also specifies operation in other frequency bands. IEEE 802.11a/n/ac do so for the 5GHz band. Even though these parts of the standard also exist for several years now, they are less often in use. This is good news. That’s why almost all of the wifi devices in my place support IEEE 802.11a, n or ac. And in fact competition with neighbours is less.

When I was looking for a wifi dongle for my Raspberry Pi 2 I was specifically searching for one supporting 5GHz. A friend recommended the Edimax EW-7811UTC. So I bought one. What I didn’t consider before buying that thing was the driver support by common distributions for the Raspberry Pi. I realized that while OpenELEC for instance does come with a driver for the Edimax EW-7811UTC out of the box, Raspbian doesn’t.

Compiling the Driver step by step

While finding an open source driver for the Edimax EW-7811UTC was easy, compiling it for Raspbian was a bit more of a challenge. That’s because Raspbian doesn’t ship with its kernel sources in the software repositories. After some web research I stumbled upon rpi-source. This small tool is able to install the kernel source used to build the kernel on the Raspian image.

By the way, the driver could not only be used for the Edimax EW-7811UTC. The Realtek 8812au chipset is also built into many other wifi products like the D-Link DWA-171. So if you know that your wifi dongle is also using the rtl8812au chipset this might work for you, too.

So here is what it takes to compile the rtl8812au driver for Raspbian:

$ # install necessary software
$ sudo apt-get update
$ sudo apt-get install git bc bison flex libssl-dev
$ 
$ # download raspbian kernel sources, takes some minutes
$ sudo wget "https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source" -O /usr/bin/rpi-source
$ sudo chmod 755 /usr/bin/rpi-source
$ rpi-source
$ 
$ # download the rtl8812au kernel driver and compile it, takes some minutes
$ git clone "https://github.com/gnab/rtl8812au"
$ cd rtl8812au
$ sed -i 's/CONFIG_PLATFORM_I386_PC = y/CONFIG_PLATFORM_I386_PC = n/g' Makefile
$ sed -i 's/CONFIG_PLATFORM_ARM_RPI = n/CONFIG_PLATFORM_ARM_RPI = y/g' Makefile
$ make
$ # copy the driver and use it
$ sudo cp 8812au.ko /lib/modules/`uname -r`/kernel/drivers/net/wireless
$ sudo depmod -a
$ sudo modprobe 8812au
$ 
$ # check wlan0 interface appeared
$ ip a s
$ iwconfig

Now you can start configuring your wifi network using iwconfig or wpa_supplicant or the wifi configuration tool of your choice.

The procedure has been tested on a Raspberry Pi 2 Model B and Raspberry Pi Zero running:

Ansible role

I started to bootstrap all my computers using Ansible a while ago. Especially for the Raspberry Pi I find an Ansible playbook pretty helpful since I keep setting it up from scratch for various new projects very often. For compiling the rtl8812au wifi driver on Raspbian I published an Ansible role on github. Check it out:

https://github.com/layereight/raspbian-rtl8812au