Compiling the 8192eu driver for the Raspberry Pi

I recently had the need to Wi-Fi enable a Raspberry Pi and so bought a D-Link DWA-131 Wireless USB Adapter.  I knew from something I'd read that it was a bit of a gamble in terms of whether it would be supported by the Pi under Raspian.  It turns out there are currently 3 revs of this adapter with different chipsets in each.  The one I got was the latest E1 version identified with the USB Device ID 2001:3319 that requires the realtek 8192eu driver.

Here's how to get it working under the September 2015 Raspian Jessie running Kernel 4.1.7+ for which I found some similar instructions a helpful starter:

1.  Get up to date and ready for compilation

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential git


2. Grab the Driver Source

git clone https://github.com/romcyncynatus/rtl8192eu.git

or from

http://support.dlink.com.au/download/download.aspx?product=DWA-131


3. Patch the driver source for Kernel 4.x

cd rtl8192eu
Apply the following patch to rtw_android.c

diff --git a/os_dep/linux/rtw_android.c b/os_dep/linux/rtw_android.c
index 40ddf07..f7c496e 100755
--- a/os_dep/linux/rtw_android.c
+++ b/os_dep/linux/rtw_android.c
@@ -342,7 +342,11 @@ int rtw_android_cmdstr_to_num(char *cmdstr)
 {
        int cmd_num;
        for(cmd_num=0 ; cmd_num<ANDROID_WIFI_CMD_MAX; cmd_num++)
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,0,0))
+               if(0 == strncasecmp(cmdstr , android_wifi_cmd_str[cmd_num], strlen(android_wifi_cmd_str[cmd_num])) )
+#else
                if(0 == strnicmp(cmdstr , android_wifi_cmd_str[cmd_num], strlen(android_wifi_cmd_str[cmd_num])) )
+#endif
                        break;

        return cmd_num;



4. Grab the rpi-source tool (to download the Pi kernel source)

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


5. Install the Pi kernel

sudo rpi-source --skip-gcc


6. Build and install the driver

make ARCH=arm
sudo make ARCH=arm install
sudo bash -c 'echo "options 8192eu rtw_power_mgnt=0 rtw_enusbss=0" > /etc/modprobe.d/8192eu.conf'
modprobe 8192eu

Comments

Anonymous said…
Hi Graham,
I'm having trouble with step 3 - applying the patch.

"diff --git" isn't an option on the diff command I have.

Are you able to elaborate a bit more on this step and how I can apply the patch? I'm quite new to working with source files, compiling etc, but otherwise intermediate with Linux/Commandline.

Any pointers on how to do this?
Graham White said…
Hi Seb,

You should be applying a patch i.e. you use the "patch" command rather than the diff command. The "diff -git" you see on the blog post is the start of the patch itself that you must apply to the file.

So for step 3 you would do something along the lines of:
(3.1) Cut-and-paste the patch text into a file (all the monospace font in step 3 from the "diff --git" line at the start through "return cmd_num;". Call that new file of yours, say rtw_android_new.c

(3.2) cd rtl8192eu

(3.3) run the patch command, "patch -p1 < rtw_android_new.c"

Hopefully, that patch will still work. If the source code (that you downloaded in step 2) has been updated since I wrote the blog post then you might need to edit the patch slightly or possibly not even use it at all if the source has been made to work correctly. Either way, it should be fairly self-explanatory I'd hope.

Hope that helps!

Graham
Unknown said…
Graham, I too am struggling with compiling/ installing 8192eu driver for rpi - my target OS version: 4.4.15-hypriotos-v7+ (linux kernal Linux kernel 4.4.10] beside your patch I also needed to patch a couple of other files e.g. duplicated file_path definition. I assume this means that your rtl9192eu was for prior linux version

Anyway complied successfully then when I executed: modprobe 8192eu
modprobe: ERROR: could not insert '8192eu': Exec format error

Any ideas?
Graham White said…
Hi Ian,

This is a new one on me, I've been messing with Linux since the darker days when re-compiling kernels was fairly common and I've not seen this error before.

A quick bit of searching around the web does reveal some hints. It appears there likely to be some sort of versioning error somewhere in your build chain. It looks like you'll be able to load your module with the "modprobe --force" which causes modprobe to ignore these version checks.

Try a web search for this: modprobe "Exec format error"

This was one of the results I found and looks quite useful... https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=73005
Unknown said…
Graham, thanks for response had previously done the web search and tried "modprobe --force" without success. When I find an answer will update here.
Unknown said…
Solved - problem was indeed kernel version - rpi-source for some reason had downloaded 4.4.13 and i was running 4.4.15
mocs said…
pi@raspberrypi ~/Download/rtl8192eu $ sudo make ARCH=arm
make ARCH=arm CROSS_COMPILE= -C /lib/modules/4.4.13+/build M=/home/pi/Download/rtl8192eu modules
make[1]: Entering directory '/root/linux-9892c762a4f8a3f56356cba528104618d1222376'
CC [M] /home/pi/Download/rtl8192eu/core/rtw_cmd.o
cc1: error: -Werror=date-time: no option -Wdate-time
scripts/Makefile.build:258: recipe for target '/home/pi/Download/rtl8192eu/core/rtw_cmd.o' failed
make[2]: *** [/home/pi/Download/rtl8192eu/core/rtw_cmd.o] Error 1
Makefile:1385: recipe for target '_module_/home/pi/Download/rtl8192eu' failed
make[1]: *** [_module_/home/pi/Download/rtl8192eu] Error 2
make[1]: Leaving directory '/root/linux-9892c762a4f8a3f56356cba528104618d1222376'
Makefile:1455: recipe for target 'modules' failed
make: *** [modules] Error 2
matt4054 said…
Thanks, it took me hours to go through this procedure (due to kernel version mismatch) but it's the only way I could get rev. E of the chip (EU version) working for my RPi 2. Phew! ^^