Building a module

SOLVED! This took me weeks! :frowning:

So it’s not in anyway intuitive or easy or documented 100%. Here is how you compile a module for a custom Linux build and install it:

Requirements:

  1. Must build on a normal Linux PC/kernel. The redirection of the RT kernel on Navio+ seems to prevent proper version calculation hence the never ending “Bad EXE format/symbol version mismatch” errors if you try. Wasted loads of time with that.
  2. Forget building on the Raspberry Pi it takes too long. In order to build the relatively small driver (“module”) you need access to the a copy of the source with the “Module.symvers” file specifically plus the other prepared headers. That means you have to run a “make modules” on the Emlid RT kernel source.
  3. Follow the instructions on the Emlid LINUX-RT-RPI GitHub repository to download and build the source (and download the cross compiler also used for the driver).
  4. If using a 64bit development PC make sure you use the 64bit raspbian tools (cross-compiler). It may work on Ubuntu 14 (Linux 3.18) but will fail on Ubuntu 15 (Linux 3.19) with weird “command not found” errors.
  5. Download and re-(cross-)compile your driver. Usually this means editing the Makefile, selecting the ARM and Raspberry Pi build options and providing paths to the (Emlid) source and the cross-compiler (Raspbian Tools). There should be instructions with the driver on how to build. The target of the build is a “.ko” file, a Linux module.

Sometimes the original drivers won’t work because they’re written for older kernel versions with depreciated functions. This is the case currently with the newer 802.11AC models from Edimax, what I was trying to get working. Luckily others have does this work for them, the “gnab” user on GitHub is one example. He’s created a “rtl8812au” repository with fixed source code so all the new AC wireless adapters will work!

I’m going to write all this up into a detailed article, but for now people wishing to play with the newer WiFi adapters with a Raspberry Pi 2 on the current “3.18.9-rt5-v7+” kernel build (exactly as downloaded from the Emlid web site) can try this driver:

http://1drv.ms/1QglyoF

It’s a ZIP containing two versions of a built 8812au.ko module (driver), one with power saving on and one with those functions disabled (probably what you want for a drone). To install it do the following:

  1. Download and extract the ZIP. You only need the 8812au.ko file from the directory named after the configuration you want (“Power Save” or “No Power Save”).

  2. Copy the file to the SD card of the Raspberry Pi, using the “sudo” elevation because it’s in a system path (if you have the SD card mounted in another Linux machine you would prefix “/lib/…” with the mount path, e.g. on Ubuntu it’s “/media///”):

    sudo cp 8812au.ko /lib/modules/3.18.9-rt5-v7+/kernel/drivers/net/wireless/
    sudo chmod 644 /lib/modules/3.18.9-rt5-v7+/kernel/drivers/net/wireless/8812au.ko

  3. Boot the Raspberry Pi and run the following command to install the driver:

    sudo insmod /lib/modules/3.18.9-rt5-v7+/kernel/drivers/net/wireless/8812au.ko
    sudo depmod -a $(uname -r)

  4. Check the driver loaded, you should see 8812au in the list:

    lsmod

  5. Check the WLAN adapter has initialized:

    iwconfig

  6. Follow instructions to configure the WLAN0 interface and WPA_SUPPLICANT. I’m writing an article on that too, but for now you can get a quick start here:

Note: This modified version by GNAB is not perfect. Although it seems to run reliably when configured correctly, when playing with settings you may find a kernel fault occurs and the system locks-up, specifically when editing the “wpa_supplicant.conf” file. To correct this, remove the adapter, power-cycle then correct the configuration before re-inserting it.

One example I found is when configuring Ad-Hoc/IBSS/P2P mode but not specifying a frequency. Looking at the source shows he did not convert all the functions to the newer kernel, so there are some special cases when it’s trying to print debug messages and falling-over because it contains the old code. I plan to get the latest code from Realtek somehow and re-implement this later, but hope Edimax do the right thing and update their Linux drivers first.

2 Likes