[Raspberry Pi General] Mirhawk:
I recently got the Raspberry Pi 2 and wanted to use it for Media Center purposes. I also got the Xiaomi Portable USB 2.0 Powered Wi-Fi Access Point Adapter to work with the Pie, but alas, it had a different chipset (Mediatek)

which didn't work with the Pi out of the box and hence drivers needed to be built for it. I had to go through a lot of pages to sucessfully make the WiFI dongle work, and to save the trouble for others, following is a guide to do

so.

Note, this driver was built on Raspbian with kernel 3.18.14-v7+ #792 . Same process can be followed for other kernel versions.

First we need to check if the device is getting detected in Your pi. Keep the dongle dis connected from Your pi. Then do as follows:

dmesg -c

This will clear all the previous output of dmesg in memory and display it in terminal.

Now connect the dongle and run

dmesg

It should show something like this:

[ 2871.923204] usb 1-1.5: new high-speed USB device number 10 using dwc_otg
[ 2872.034659] usb 1-1.5: New USB device found, idVendor=2717, idProduct=4106
[ 2872.034685] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 2872.034703] usb 1-1.5: Product: MI WLAN Adapter
[ 2872.034720] usb 1-1.5: Manufacturer: MediaTek
[ 2872.034736] usb 1-1.5: SerialNumber: 1.0

Write down the idVendor and the idProduct from here, it will be needed further.

Also run

lsusb

This will display the devices attached to the pi, and will have utput similar to following:

Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 009: ID 2717:4106

There should a device with the idVendor and the idProduct we wrote down earlier, like Mine is shown in the last device.

Now this confirms that the dongle is getting detected by pi. The we can do the following steps to build the driver.

First, we need to download latest updates:

sudo apt-get update
sudo apt-get upgrade
sudo rpi-update

Then We need to take backup up of Your pi, the size of the backup will depend on the size of Your sdcard, so if it is 8GB, then the backup size would be 8GB.

First we need to recognize in where Your device is detcted. You can check it using Disk utility. It will show You the device name as sdb or sdc (You need to recognize using size)

or as mmcblok if You atach it via internal memory card reader. Let us assume that it is detected as sdb.

Then run the following command to backup.

sudo dd if=/dev/sdb of=raspbian.img bs=4M

This step can be skipped, but is recommended.

Now to build, we need some sources. We can get them as follows.

We need to create a directory in which we will be working:

mkdir src
cd src

Now You are in src folder. Then we need to download linux kernel source of raspberry pi, as this is needed to compile the driver module:

git clone --depth 1 https://github.com/raspberrypi/firmware
git clone --depth 1 https://github.com/raspberrypi/linux

This step migh be optional, as it worked for some where as it didn't for some.

In the terminal, type

uname -r | cut -c9-12

This will display a alphanumberic output something like v7+ or +v11. Remeber this because we are going to edit a file below and add it to it.

sudo nano linux/Makefile

Find the text "EXTRAVERSION = " there and then type the output of the previous command, so it will look like:

EXTRAVERSION = v7+

This step is must, else build won't work! The gcc needs to be updated for building the source, for it follow the guide from here.

or can be done as follows:

Ever needed gcc/g++ 4.8 on your wheezy? Then do

sudo nano /etc/apt/sources.list

Change content to

deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
deb http://archive.raspbian.org/raspbian wheezy main contrib non-free rpi
# Source repository to add
deb-src http://archive.raspbian.org/raspbian wheezy main contrib non-free rpi
deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi
deb http://archive.raspbian.org/raspbian jessie main contrib non-free rpi
# Source repository to add
deb-src http://archive.raspbian.org/raspbian jessie main contrib non-free rpi

Add preferences file

sudo nano /etc/apt/preferences

and insert

Package: *
Pin: release n=wheezy
Pin-Priority: 900
Package: *
Pin: release n=jessie
Pin-Priority: 300
Package: *
Pin: release o=Raspbian
Pin-Priority: -10

update package list

sudo apt-get update
Install gcc/g++ 4.8 from jessie repositories

sudo apt-get install -t jessie gcc-4.8 g++-4.8

To remove gcc/g++ alternative configuration (if there is any, there is none by default)

sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++

Install alternatives

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50

Now 4.8 is your default compiler. You can verify it by

sudo gcc --version

If you want to change it, you can

sudo update-alternatives --config gcc
sudo update-alternatives --config g++

Just a few more steps to get ready for the build now:

sudo mkdir /boot/backup
sudo cp /boot/* /boot/backup/
sudo cp -r firmware/modules /lib
sudo cp -r src/firmware/boot /
sudo cp firmware/extra/Module7.symvers linux/Module.symvers
sync
sudo reboot
cd src/
sudo ln -s /home/pi/src/linux /lib/modules/$(uname -r)/build
cd linux
sudo gunzip -c /proc/config.gz > .config
sudo make oldconfig
sudo make modules_prepare

Now that we are finally done preparing the system, we need to download the source for the drivers. The one's that worked for Me and are latest can be found here.

To download and build the code:

mkdir ~/git
cd ~/git
git clone https://github.com/porjo/mt7601
cd src

This will create a git directory in your home directory and download the source code to it.

Now rememeber the idVendor and idProduct we wrote at beginning? We need to add that to a file. This need to be done so as to make the driver work with the dongle. The driver is built for the device, but since the device id is not present, the driver will not attach to the dongle.

to do so,

sudo nano common/rtusb_dev_id.c

/* module table */

USB_DEVICE_ID rtusb_dev_id[] = {

#ifdef RT6570

{USB_DEVICE(0x148f,0x6570)}, /* Ralink 6570 */

#endif /* RT6570 */

{USB_DEVICE(0x148f, 0x7650)}, /* MT7650 */

#ifdef MT7601U

{USB_DEVICE(0x148f,0x6370)}, /* Ralink 6370 */

{USB_DEVICE(0x148f,0x7601)}, /* MT 6370 */

{USB_DEVICE(0x148f,0x760b)}, /* 360 wifi */

{USB_DEVICE(0x2a5f,0x1000)}, /* Tencent wifi QQ */

{USB_DEVICE(0x2955,0x0001)}, /* XiaoDu Wifi */

{USB_DEVICE(0x2955,0x1001)}, /* XiaoDu Wifi */

{USB_DEVICE(0x2955,0x1003)}, /* nuomi wifi */

#endif /* MT7601U */

{ }/* Terminating entry */

};

INT const rtusb_usb_id_len = sizeof(rtusb_dev_id) / sizeof(USB_DEVICE_ID);

MODULE_DEVICE_TABLE(usb, rtusb_dev_id);

Add the device details in the MT7601U block, so it will look like below:

/* module table */

USB_DEVICE_ID rtusb_dev_id[] = {

#ifdef RT6570

{USB_DEVICE(0x148f,0x6570)}, /* Ralink 6570 */

#endif /* RT6570 */

{USB_DEVICE(0x148f, 0x7650)}, /* MT7650 */

#ifdef MT7601U

{USB_DEVICE(0x148f,0x6370)}, /* Ralink 6370 */

{USB_DEVICE(0x148f,0x7601)}, /* MT 6370 */

{USB_DEVICE(0x148f,0x760b)}, /* 360 wifi */

{USB_DEVICE(0x2a5f,0x1000)}, /* Tencent wifi QQ */

{USB_DEVICE(0x2955,0x0001)}, /* XiaoDu Wifi */

{USB_DEVICE(0x2955,0x1001)}, /* XiaoDu Wifi */

{USB_DEVICE(0x2955,0x1003)}, /* nuomi wifi */

{USB_DEVICE(0x2717,0x4106)}, /* Xiaomi WiFi */

#endif /* MT7601U */

{ }/* Terminating entry */

};

INT const rtusb_usb_id_len = sizeof(rtusb_dev_id) / sizeof(USB_DEVICE_ID);

MODULE_DEVICE_TABLE(usb, rtusb_dev_id);

Now to finally build the driver, run :

sudo make

After the building is complete, run following command to load the module to make it work with the dongle:

sudo insmod /home/pi/git/mt7601/src/os/linux/mt7601Usta.ko

To check if the module has been loaded, run:

lsmod

the output should be like:

Module Size Used by

mt7601Usta 583863 0

Now if the module loads successfully and is shown in lsmod, do:

sudo make install

This will install the driver for the dongle and load it automatically at boot.

To check if the device is working properly, run following various commands. The device is recognised as ra0.

iwconfig

Output:

ra0 Ralink STA ESSID:"11n-AP" Nickname:"MT7601STA"

Mode:Auto Frequency=2.412 GHz Access Point: Not-Associated

Bit Rate:1 Mb/s

RTS thr:off Fragment thr:off

Link Quality=10/100 Signal level:0 dBm Noise level:0 dBm

Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0

Tx excessive retries:0 Invalid misc:0 Missed beacon:0

lo no wireless extensions.

eth0 no wireless extensions.

ip link

Output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000

link/ether ##:##:##:##:##:## brd ff:ff:ff:ff:ff:ff

3: ra0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 1000

link/ether ##:##:##:##:##:## brd ff:ff:ff:ff:ff:ff

Also, You can search the WiFi networks by tunning command:

sudo iwlist ra0 scan

Now we need to configure the pi and the dongle to connect to a specific WiFi. To do so:

edit the /etc/network/interfaces

sudo nano /etc/network/interfaces

allow-hotplug ra0
iface ra0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

The first line is used to enable the dongle on connecting it. The second one sets it to set it's network to dhcp, so as to acquire ip address configuration automatically. The third one sets where the device should look for WiFi details.

Now edit the file as below:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

and add

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid="WiFi_name"
psk="password"
}

And reboot! Done!

If You are on

Raspbian with kernel version 3.18.14-v7-792

, then You can directly use the following driver, no need to compile as above.

Note: It renames ra0 to wa0.

Download driver from here.

Then run the following code:

tar xzf mt7601-3.18.14-v7-792.tar.gz
./install.sh

Credits go to various people for their online help and sources!

Sources:

Raspberry Pi 2, module compiles, but failes to load #18

GCC 4.8 ON RASPBERRY PI WHEEZY

Driver Sources

MediaTek MT7601 USB WIFI on the Raspberry Pi