How to compile a Realtek RTL wireless driver on a Raspberry Pi

You've got a raspberry pi. Maybe it's a pi 2 or 3 that doesn't have a wifi chip. You bought a USB dongle and plugged it in, but you can't manage to get it to go. The driver that came with the dongle doesn't compile for raspberry pis, and nothing on the pi forums works.

Here's a quick guide for installing the RT8812 driver onto your pi.

1. Get the source kernel installer:

sudo wget https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source -O /usr/bin/rpi-source && sudo chmod +x /usr/bin/rpi-source && /usr/bin/rpi-source -q --tag-update

2. Install bc, a maths package:

sudo apt-get install bc

3. Install the kernel:

rpi-source

4. Fetch the driver by cloning it:

git clonehttps://github.com/Kongaloosh/rtl8821CU

note: this repo points to an 8821 driver. If you need another kind of driver, maybe start with a different repo. You should be able to change the configuration of this repo to suit your needs.

There are now three non-standard things you need to do in order for the driver to work with both your pi and the dongle you've purchased:

a. Figure out the dongle's Manufacturer and product ID.

b. Modify the makefile to specify the dongle the driver is for.

c. tweak the driver makefile to suit the pi

Finding wifi Dongle's manufacturer name and product ID:

Plug the wifi dongle into the pi and run lsusb to check out what's been plugged into your pi. For instance, when I run it, it looks something like this:

Bus 001 Device 004: ID 0bda:c811 Realtek Semiconductor Corp.
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

look at device 04; this is my wifi dongle. If you're having difficulty figuring out which device it is, unplug your dongle and run lsusb again. whichever device disappeared is your dongle! This is the dongle that I purchased.

Take note of the last four digits of the ID. The ID for my dongle is 0bda:c811, so in my case it's c811. I now know two things about my dongle: the manufacturer (Realtek Semiconductor Corp) and the product ID (c811).

Adding your dongle to the list of USB interfaces

Open os_dep/linux/usb_intf.c using your favourite editor (i.e., nano, vim)

# ifdef CONFIG_RTL8812A
    /*=== Realtek demoboard ===*/
    {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8812), .driver_info = RTL8812}, 
    {USB_DEVICE(USB_VENDER_ID_REALTEK, 0xc811), .driver_info = RTL8821},  # my driver!
    {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x881A), .driver_info = RTL8812},

You might be lucky. When you look in the file, you may find that there's already a line describing your dongle! If that's so, mosey on to the next step.

If like me, you're not so lucky, you now need to add the usb device you want the driver to interface with in this file. Each section will be prefaced with an ifdef CONFIG_RTLXXXXx. These define the interfaces for each section. They match the interface with the appropriate driver. In this case, I added the driver

Modify the makefile to suit your device

open up Make with your favourite editor and change two lines

CONFIG_PLATFORM_I386_PC = y
CONFIG_PLATFORM_ARM_RPI = n

so that they now read

CONFIG_PLATFORM_I386_PC = n
CONFIG_PLATFORM_ARM_RPI = y

This tells the driver to build for our raspberry pi.

Having modified `usb_intf.c and Make, we can continue business-as-usual compiling the driver.

**5. Make sure we can run the installation script: **

sudo chmod +x install.sh

6. Run the installation script:

./install.sh

7. Load our new module into the linux kernel:

sudo insmod 8812au.ko

sudo cp 8812au.ko /lib/modules/$(uname -r)/kernel/drivers/net/wireless

8. Generate a dependency description:

sudo depmod

You should now be done!!! You can verify this by running iwconfig, which should produce an output like so:

wlan0 IEEE 802.11AC  ESSID:"Kongaloosh"  Nickname:"<WIFI@REALTEK>"
      Mode:Managed  Frequency:5.765 GHz  Access Point: C4:04:15:10:86:75
      Bit Rate:434 Mb/s   Sensitivity:0/0
      Retry:off   RTS thr:off   Fragment thr:off
      Power Management:off
      Link Quality=84/100  Signal level=52/100  Noise level=0/100
      Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
      Tx excessive retries:0  Invalid misc:0   Missed beacon:0

which means your wireless lan is working! Congratulations.

If this didn't work...:

It says that I don't have the headers

You need to fetch the headers again. There are links below to forum discussions that cover the topic of headers and missing libraries.

I completed all the steps, but it just doesn't work

Check to make sure that you added your usb interface properly to usb_intf.c. Make sure that you ran things in the correct order. Check to see if you're getting error messages that you missed.

I'm sure the files are correct, it's just not working

If you've been following other tutorials, and made changes to your pi already, it may behoove you to make a clean install and start from scratch.

Other resources on the web:

On Twitter

0 's | 0 's