Skip to content

Instantly share code, notes, and snippets.

@basilfx
Last active July 23, 2019 17:46
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basilfx/1485bfbaccec04bf7c4a to your computer and use it in GitHub Desktop.
Save basilfx/1485bfbaccec04bf7c4a to your computer and use it in GitHub Desktop.
Install MT7601U WiFi adapter driver for OpenELEC (Raspberry Pi)

I bought (a few) Wireless-N WiFi adapters from Ebay to enable WiFi on my OpenELEC-featured Raspberry Pi. I was hoping it would work out-of-the-box, but that wasn't true. Some attempts such as modprobe rt2x00usb did not work as expected because it's a totally different chipset.

The output of lsusb:

...
Bus 001 Device 004: ID 148f:7601 Ralink Technology, Corp.
...

This guide shows you how to cross compile the driver and integrate it in an existing OpenELEC installation. It works under Ubuntu 14.04 for OpenELEC nightly with kernel version 3.15. Common build tools are assumed, plus squashfs-tools). I'm not a pro in building modules, but this has worked for me.

  • Install the dependencies: apt-get install build-essential squashfs-tools git
  • Download the the driver source from here (version v3.0.0.4 from 9/13/2013) and unzip it.
  • Apply this patch, for kernel 3.13+. Can be done manually.
  • Note your OpenELEC kernel version, via SSH uname -a.
  • Clone the Raspberry Pi tools repository: git clone https://github.com/raspberrypi/tools.
  • Clone the OpenELEC repository: git clone https://github.com/OpenELEC/OpenELEC.tv.
  • Download the approriate kernel version from here, and unzip it.
    • Apply the patch to KERNEL_ROOT: patch -p1 < OPENELEC_ROOT/projects/RPi/patches/linux/linux-01-RPi_support.patch. Make sure you have changed directory to the KERNEL_ROOT folder.
    • Copy OPENELEC_ROOT/project/RPi/config/linux.arm.conf to KERNEL_ROOT/.config
  • Add RPI_TOOLS_ROOT/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin to your PATH. The compile tools should be available for running.
  • Compile kernel modules: make modules.
  • Change DRIVER_ROOT/Makefile to look as below (around line 198). Replace the LINUX_ROOT with your path.
ifeq ($(PLATFORM),PC)
# Linux 2.6
LINUX_SRC = LINUX_ROOT
# Linux 2.4 Change to your local setting
#LINUX_SRC = /usr/src/linux-2.4
LINUX_SRC_MODULE = LINUX_ROOT/kernel/drivers/net/wireless/
CROSS_COMPILE = arm-linux-gnueabihf-
ARCH=arm
export ARCH
export CROSS_COMPILE
endif
  • Run make, which should result in a kernel object DRIVER_ROOT/os/linux/mt7601Usta.ko
  • Take the SYSTEM image file from your SD card, and mount it with sudo mount -t squashfs SYSTEM TMPDIR.
  • Since the file system is read-only, rsync (as root) the contents to another dir sudo rsync -avp TMPDIR TMPDIR2.
  • Create directories for the following operations (as root) if needed. Replace x.x.x with the kernel version.
    • Copy DRIVER_ROOT/os/linux/mt7601Usta.ko to TMPDIR2/lib/modules/x.x.x/kernel/drivers/net/wireless
    • Copy DRIVER_ROOT/RT2870STA.dat to TMPDIR2/etc/Wireless/RT2870STA/RT2870STA.dat
    • In TMPDIR2, run depmod -a -b . x.x.x
  • Repack the filesystem (as root) with sudo mksquashfs TMPDIR2 SYSTEM -noappend -comp gzip.
  • Run chown USER:USER SYSTEM so you can access the file.
  • Copy the new SYSTEM image to your SD card and boot OpenELEC.

Your WiFi should be ready to use! In case of problems, SSH into the system, and view the output of dmesg. Note that auto-update will probably overwrite your custom SYSTEM image, but chances are the driver will still work.

@Harnon
Copy link

Harnon commented Sep 3, 2014

Hello,
It seems really great you could do it.
As I read on the web, many people are searching for this solution.
For someone like me, even I can handle linux knowledges, I am lost with this recipe. (I don't have any idea of how to "apply a patch" etc )
Could you just write the entire command line process you used for it, as example ?
Would be great !
Thanks
Harnon.

@basilfx
Copy link
Author

basilfx commented Sep 15, 2014

Hi Harnon,

Thanks for the feedback. I have updated the gist a tiny bit, but to be honest: I don't have the exact procedure anymore. Also, every version may be a tiny bit different, so I think the guide as presented above should be enough.

Bas

@Harnon
Copy link

Harnon commented Sep 15, 2014

Thanks a lot ! I will try once more and see how far I can go with it.
Greetings,
H.

@mthierry
Copy link

Hi, a couple of tips for people following Bas steps and trying to compile the kernel:
a. Set export CCPREFIX=arm-linux-gnueabihf-
b. Use ARCH and CROSS_COMPILE in the kernel's make command, e.g:

  make ARCH=arm oldconfig
  make ARCH=arm CROSS_COMPILE=${CCPREFIX} modules

or

  make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- modules

Cheers.

@vinnitu
Copy link

vinnitu commented Jan 11, 2015

[ 2.930919] usb 1-1.3: new high-speed USB device number 5 using dwc_otg
[ 3.049599] usb 1-1.3: New USB device found, idVendor=148f, idProduct=7601
[ 3.049636] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 3.049654] usb 1-1.3: Product: 802.11 n WLAN
[ 3.049669] usb 1-1.3: Manufacturer: MediaTek
[ 3.049682] usb 1-1.3: SerialNumber: 1.0

I see in dmesg - it is ok?

But how to configure wlan?


I have raspberrypi B
openelec with kodi 14.0
5.0.0 build
Bus 001 Device 004: ID 148f:7601 Ralink Technology, Corp.

@gsmith-to
Copy link

I just tried this with OpenElec 5.0.3 which has a 3.17.8 kernel. The patch failed.
So it looks like the OpenElec is in active development and I need to get the one which matches the actual release, not the most current. It looks like this should be the 'openelec-5.0' branch... I'll try that...

--- update -- yes, it works fine now.
you can do a 'git checkout openelec-5.0' in the OPENELEC_ROOT after the 'git clone' (or, what I did, when I realized that only two files are needed - the .patch and the config - I just got those files directly off the 'raw' links on github).

I also ended up removing a line from the linux root Makefile which causes 'implicit integer declaration' to be an error - but that might not have been necessary. In my first try I had actually unpacked the wrong driver (version 3.0.0.3) somehow, and managed to build it and try it, and discovered that it actually comes in two modules, and, well, I'll stop now. Suffice it to say that the one you want is called DPO_MT7601U_LinuxSTA_3.0.0.4_20130913.tar.bz2, and that the process described worked fine for me on OpenElec 5.0.3 once I selected the openelec-5.0 branch as described above, and followed all the instructions properly.

@gsmith-to
Copy link

vinnitu - the lines in dmesg that you report would be there even if you didn't install the driver. Go to 'system/openelec' and under 'connections' you should see wireless set up, if the driver is working.

If not, connect with ssh and try the below.

Make sure all the files are there:

(change 3.17.8 to whatever your kernel is)

carson:/ # cd /lib/modules/3.17.8/
carson:/lib/modules/3.17.8 # ls -l kernel/drivers/net/wireless/mt7601Usta.ko
-rw-r--r-- 1 root root 913282 Feb 16 01:31 kernel/drivers/net/wireless/mt7601Usta.ko
carson:/lib/modules/3.17.8 # ls -l /etc/Wireless/RT2870STA/
total 2
-rwxr-xr-x 1 root root 1222 Feb 16 01:31 RT2870STA.dat
carson:/lib/modules/3.17.8 # grep mt7601 modules.dep
kernel/drivers/net/wireless/mt7601Usta.ko:

The first two files are the driver, and a firmware file for the wireless unit (your sizes may be different). The 'grep' output verifies that the depmod was done. If none of them are there, check the same places in your TMPDIR2; if the files are there, you didn't do the squashfs properly (or failed to put the new SYSTEM back in the right place). If the first two files are present but the line in modules.dep does not appear, you may have not done the 'depmod' operation properly. In either case just go back to that step and redo from there.

[ Oh - I'd also recommend the instructions be modified so that 'sudo umount TMPDIR' be done after the rsync command in the procedure. Otherwise the squashfs command will be overwriting a mounted file. I'm not sure how problematic that is, since I did the unmount -- but I'd be inclined to avoid doing that. And of course it should be done sooner or later to clean up].

If all the above three are present, check if 'mt7601Usta' appears in the output from 'lsmod'. If it doesn't, try 'modprobe mt7601Usta' and see if that works (or if it generates errors in dmesg). If it does appear, it should be working...

@basilfx
Copy link
Author

basilfx commented Mar 9, 2015

Someone is working on a Linux 3.19+ module that should be integrated into the Linux Repository someday. His repository can be found at https://github.com/kuba-moo/mt7601u.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment