Thursday, May 28, 2015

MT7601 on Raspbmc

I brought myself a whole bunch of wifi dongles off aliexpress to sell though the condition on people buying a lot of them was reliant on them being suitable to use on Raspbmc.

Unfortunately they don't work straight out of the box and so I set about trying to get it working. On my desktop it was really easy (mostly).

 sudo apt-get install build-essential linux-headers dkms -y  
 sudo dpkg -i mt7601-sta-dkms_3.0.0.4-0~201502051732~rev18~pkg2~ubuntu14.10.1_all.deb  

So the reason I didn't bother adding the ppa... Well... a dkms package is source code with some configuration files to make it recompile every time a kernel is installed. Which means, it should work regardless of what version of Ubuntu I'm no. Unfortunately, the ppa doesn't contain packages for 12.04 - which is no problem whatsoever. Just download the package and install...

Which means the dongles aren't completely useless. And on to Raspbmc. I started to look for information and was kind of disappointed by a lot of it. People had managed to compile it but hadn't left instructions as to how they managed it - instead providing binaries for particular version.

Others were running into much the same problems that I was and going around in circles not really getting answers. So I decided I needed a script. So the binary could be provided, for quick and easy installation, but also, giving others the ability to compile the binaries themselves should the need arise.

The REALLY neat thing about this script is that it sets up an environment that should be suitable for other modules as well. The first part of this script could be split off into kind of a universal "build an environment for compiling modules" thing...

And yes... I get the chicken and egg thing... You require the Internet in order to run this script... There's no way around this.

 #Might not be needed but... if you don't have enough space on your SD card and you've got a mounted USB drive on the pi,  
 #this makes it use that instead... Comment out the next line if you just want to use pwd.  
 MOUNTPOINT="$( df | grep "^/dev/sd" | sed 's/ */ /g' | cut -f 5,6 -d " " | sort -h | head -n1 | cut -f 2 -d " " )"  
 CURRENT_KERNEL_VERSION="$( uname -r )"  
 if [ -z "$MOUNTPOINT" ] ; then  
 if [ "$( whoami )" != "root" ] ; then  
  echo "Must run as root"  
  exit 1  
 #install the compiler (hopefully this is enough to get what you need).  
 if [ -z "$( dpkg -l | grep build-essential )" ] ; then  
  apt-get install build-essential -y  
 if [ ! -d "$MOUNTPOINT/mt7601" ] ; then  
  mkdir "$MOUNTPOINT/mt7601"  
 cd "$MOUNTPOINT/mt7601"  
 #download kernel source. It's just chucking into the current working dir for now... mainly because I'm excessively lazy  
 KERNEL_VERSION="rpi-$( echo $CURRENT_KERNEL_VERSION | cut -d. -f-1,2).y"  
 if [ ! -d src ] ; then  
  mkdir src  
 tar xvf $KERNEL_VERSION.tar.gz -C src  
 #I know.. this next bit seems really dumb.... just for a single file.... Apparently these headers aren't suitable for
 #building wifi drivers BUT has the Module.symvers file that we need...
 if [ ! -d headers ] ; then  
  mkdir headers  
 wget $HEADERS_DOWNLOAD -P headers  
 cd headers  
 HEADERS="$(basename "$HEADERS_DOWNLOAD")"  
 ar x "$HEADERS"  
 tar xvf data.tar.gz ./usr/src/linux-headers-$CURRENT_KERNEL_VERSION/Module.symvers  
 cd ..  
 mv headers/usr/src/linux-headers-$CURRENT_KERNEL_VERSION/Module.symvers "$KERNEL_DIR"  
 rm "/lib/modules/$CURRENT_KERNEL_VERSION/build"  
 ln -sf "$KERNEL_DIR" "/lib/modules/$CURRENT_KERNEL_VERSION/build"  
 exit 0  
 cd "$MOUNTPOINT/mt7601/src/linux-$KERNEL_VERSION"  
 make mrproper  
 zcat /proc/config.gz | sed 's/CONFIG_CROSS_COMPILE.*/CONFIG_CROSS_COMPILE=""/' > .config  
 make modules_prepare  
 #now deal to the drivers... Change this part down if you want to use this script for other wireless drivers 
 cd "$MOUNTPOINT/mt7601"  
 tar xvf "$DRIVER_FILENAME" -P src  
 cd src/mt7601*  
 #Make a package so that you can you share the binary with others and to make it easy to remove if necessary.
 mkdir -p package/etc/Wireless/RT2870STA  
 cp RT2870STA.dat package/etc/Wireless/RT2870STA  
 mkdir -p package/lib/modules/$CURRENT_KERNEL_VERSION/kernel/drivers/net/wireless/  
 chmod 755 package/lib/modules/$CURRENT_KERNEL_VERSION/kernel/drivers/net/wireless/  
 cp os/linux/mt7601Usta.ko package/lib/modules/$CURRENT_KERNEL_VERSION/kernel/drivers/net/wireless/  
 chmod 755 package/lib/modules/$CURRENT_KERNEL_VERSION/kernel/drivers/net/wireless/  
 mkdir package/DEBIAN  
 echo '#!/bin/bash  
 depmod -a $CURRENT_KERNEL_VERSION' > package/DEBIAN/postinst  
 chmod 555 package/DEBIAN/postinst  
 echo "Package: mt7601$CURRENT_KERNEL_VERSION  
 Version: $(echo $DRIVER_FILENAME | egrep -o "([0-9]\.){3}[0-9]")  
 Architecture: armhf  
 Maintainer: script by Nevyn Hira <>  
 Section: admin  
 Priority: optional  
 Description: Ralink MT7601 binary drivers specifically for Raspbmc" > package/DEBIAN/control  
 dpkg -b package "$MOUNTPOINT/mt7601/"
 dpkg -i "$MOUNTPOINT/mt7601/package"

At the moment the script doesn't do any sort of clean up.


I think the word "professional" is overused in ALL the wrong contexts. "You will act in a professional manner". Forgetting of course, that within certain contexts, a "professional manner" means to drop your pants and get fucked or get down on your knees and "be the hover".

So, I propose to you, that whenever someone says something as infuriating and stupid as "act professionally", that you all pick the profession that best suits the situation.

Someone being a complete wank? Dominatrix's get paid right? Whip 'em till they say the safe word (just don't tell them what the safe word is and change it every so often to keep them guessing).

Actually... the dominatrix example works in all sorts of places. Yell at 'em till they're feeling humiliated. Order them into nappies. Sure, it's not the only way to act professionally, but it's probably the most fun/apt.