Need help porting mt76-driver to R2-Kernel

Your GCC does not support the regular stack protection. This is not good.

This error is confusing me a little. With -mabi you give machine dependent options to the compiler. The option value “apcs-gnu” tells me that you are not using any toolchain for cross compiling.

Some posts before, i told you that cross compiling requires a toolchain because you build it for an different architecture and therefore it s an requirement.

Before you start any further tries to get the driver working i recommend to do the following steps first:

  1. Do an release upgrade from Ubuntu 14.04 to minimum 16.04.
  2. Install the required toolchain via apt-get install.
  3. Add the toolchain bin directory to your PATH variable
  4. Then compile the required tools depmod etc. with the toolchain.
  5. Now you can compile the driver.

If problems occurs then post your questions and i am going to help you.

using now VM with Ubuntu 16.4:

$ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 

installed toolchain:

$ ls /usr/bin/arm*

$ make M=/home/frank/bpi-r2/BPI-R2-bsp/linux-mt/ ARCH=arm CROSS-COMPILE=arm-linux-gnueabihf-gcc
Building backport-include/backport/autoconf.h ... done.
Makefile:702: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: -fstack-protector-strong not supported by compiler
  CC [M]  /home/frank/bpi-r2/compat-wireless-2017-01-31/compat/main.o
gcc: error: unrecognized argument in option ‘-mabi=apcs-gnu’
gcc: note: valid arguments to ‘-mabi=’ are: ms sysv
gcc: error: unrecognized command line option ‘-mlittle-endian’
gcc: error: unrecognized command line option ‘-mapcs’
gcc: error: unrecognized command line option ‘-mno-sched-prolog’

Please post your Makefile

Makefile from compat wireless(not changed by me): Makefile (6,0 KB)

From linux-mt-folder: Makefile (54,1 KB)

had copied compat-wireless and mt76 driver from lede-build-dir after building lede

try now integrate into the 4.4-kernel compiles except of ampdu_action which seems differently line 403 vs. line

working on it…maybe i get that working :wink:

static int
mt76_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
//          enum ieee80211_ampdu_mlme_action action,
//          struct ieee80211_sta *sta,u16 tid, u16 *ssn, u8 buf_size,
//          bool amsdu
struct ieee80211_ampdu_params *params
  enum ieee80211_ampdu_mlme_action action=params->action;
  struct ieee80211_sta *sta=params->sta;
  u16 tid=params->tid;
  u16 *ssn = &params->ssn; //<< is that right? local pointer needed, params->ssn = u16

    struct mt76_dev *dev = hw->priv;
    struct mt76_sta *msta = (struct mt76_sta *) sta->drv_priv;
    struct ieee80211_txq *txq = sta->txq[tid];
    struct mt76_txq *mtxq = (struct mt76_txq *) txq->drv_priv;

  //*ssn=params->ssn;  //does not work

mt76.tar.gz (166,3 KB)

compiles fine (when copied to r2-kernel 4.4.70), needs no compat-wireless and create mt76pci.ko :slight_smile:

hope i have it changed right and it’s working…

You compare apples with bananas. The result will never equals. You compare an PCI hardware driver with with a network protocol driver.

You see the difference?

You should not copy the files to your kernel directory. It compiles, yes. But successfull compilation does not mean that it works. A PCI chipset btw PCI bus driver needs no wireless driver to work. But without the PCI driver you are not able to communicate with the wireless device through the PCI bus.

You see the difference between the drivers?

The PCI driver is required for PCI bus. The wireless driver is required to speak with the wireless device.

You mean wireless driver is missing in that mt76x2-old repo and i have only the pci-part?

How to do it the right way? I’found nothing a step-by-step guide howto port a driver using backports/compat-wireless

Currently i try different thing with simple c/cpp knowledge but without knowing anything about driver structure or backporting. Simple try anything and try to fix the compiler-errors

Is it possible to compile that current tree

against the bpi-kernel in github?

Using that backport (newest i’ve found): /

Just for a clean start…all 3 parts in separate folders or mt76 inside backports? maybe my previous sources from lede are not compatible with “normal” kernel (lede-specific patches)

This is the PCI Driver not the wireless driver. The wireless chipset is an MT6625L. This driver is the PCI Bridge driver.

All communications with the wireless Chipset, with the SATA Connectors, the IR device … is done through the PCI bridge. The wireless driver communicates only with the wireless MT6625L Chip, e.g. loading binary firmware, channel selection, frequency …

The wireless chip is the city cologn, the cpu is berlin, the pci bridge is the highway cross würzburg. Without the the highway bridge würzburg, it is not possible that berlin (the cpu) communicates with cologn (wirless chip) but berlin can communicate with frankfurt the ethernet.

I hope it i explain a little bit understandable. :slight_smile:

I understand the difference between pci-wireless,but i cannot see that in code.

gary is working on the internal wireless-driver (Client mode is working as i read).

Here i’m trying to get a mt7612e wlan-pcie-card working. i see it using lspci…so pci-driver seems working so far.

If you can write in german we can talk via pm an posting results here.

i have now the mt76 included in compat wireless and the following structure:

bpi-r2/linux-mt <<<kernel

compiles fine without ARCH=arm

export ARCH=arm export INSTALL_MOD_PATH=$(pwd)/mod/ export CROSS_COMPILE=arm-linux-gnueabihf-

/media/data_ext/download/bpi-r2/compat-wireless-2017-01-31$ make M=/media/data_ext/download/bpi-r2/linux-mt/

multiple files coming with warning

./arch/arm/include/asm/swab.h:20:5: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef]

at the end:

include/linux/preempt.h:59:25: fatal error: asm/preempt.h: Datei oder Verzeichnis nicht gefunden
 #include <asm/preempt.h>
compilation terminated.

that Variable/Const is defined in linux-mt/arch/arm/Makefile, but seems not be used

# This selects which instruction set is used.
# Note that GCC does not numerically define an architecture version
# macro, but instead defines a whole series of macros which makes
# testing for a specific architecture or later rather impossible.
arch-$(CONFIG_CPU_32v7M)        =-D__LINUX_ARM_ARCH__=7 -march=armv7-m -Wa,-march=armv7-m
arch-$(CONFIG_CPU_32v7)         =-D__LINUX_ARM_ARCH__=7 $(call cc-option,-march=armv7-a,-march=armv5t -Wa$(comma)-march=armv7-a)
arch-$(CONFIG_CPU_32v6)         =-D__LINUX_ARM_ARCH__=6 $(call cc-option,-march=armv6,-march=armv5t -Wa$(comma)-march=armv6)
# Only override the compiler option if ARMv6. The ARMv6K extensions are
# always available in ARMv7
ifeq ($(CONFIG_CPU_32v6),y)
arch-$(CONFIG_CPU_32v6K)        =-D__LINUX_ARM_ARCH__=6 $(call cc-option,-march=armv6k,-march=armv5t -Wa$(comma)-march=armv6k)
arch-$(CONFIG_CPU_32v5)         =-D__LINUX_ARM_ARCH__=5 $(call cc-option,-march=armv5te,-march=armv4t)
arch-$(CONFIG_CPU_32v4T)        =-D__LINUX_ARM_ARCH__=4 -march=armv4t
arch-$(CONFIG_CPU_32v4)         =-D__LINUX_ARM_ARCH__=4 -march=armv4
arch-$(CONFIG_CPU_32v3)         =-D__LINUX_ARM_ARCH__=3 -march=armv3

any hint?

Supposing you’ll be able to build this ( I was able to build backports-4.14-rc4 ) you’ll lose internal wifi driver as you cannot use both internal and backported mac80211 driver at the same time (also: mac80211 must be disabled or module)

how do you build this driver with kernel 4.4.70 and backports 4.14-rc4 (from where did you got it)? can you make a a step-by-step guide?

since internal wifi does not have AP-Mode currently i can test with my mt7612, maybe the internal driver will also be ported to 4.14 if it’s working

cd /root
mkdir backports
cd /root/backports

git clone git://
git clone git://

cd /root/backports/linux-next
git checkout v4.14-rc4

cd /root/backports/linux-backports
git checkout v4.14-rc4-1
./ --clean --gitdebug --git-revision v4.14-rc4 /root/backports/linux-next/ /root/backports/updates

# /root/backports/updates contains -backports sources
1 Like

Hi Frank, could you please test the following driver? It builds fine with the R2 kernel but I have not yet received the MT7612 I ordered so I cannot test it.

To build it:

  • 1 - clone repository inside linux-mt/drivers/net/wireless/mediatek

  • 2 - apply patch inside kernel-patches directory to linux-mt/

  • 3 - add following line to linux-mt/drivers/net/wireless/mediatek/Makefile:

    obj-$(CONFIG_MT76) += mt76/

  • 4 - add following line to linux-mt/drivers/net/wireless/mediatek/Kconfig before endif # WL_MEDIATEK:

    source "drivers/net/wireless/mediatek/mt76/Kconfig"

  • 5 - enable CONFIG_MAC80211 and CONFIG_MT76 using

  • 6 - build the kernel using

1 Like

thank you…compiled without errors, now testing:

[   13.937028] cfg80211: World regulatory domain updated:
[   13.937038] cfg80211:  DFS Master region: unset
[   13.937038] cfg80211:   (start_freq - end_freq @ bandwidth), (max_antenna_ga)
[   13.937048] cfg80211:   (2402000 KHz - 2472000 KHz @ 40000 KHz), (N/A, 2000 )
BPI-ROOT: fsck [   13.937054] cfg80211:   (2457000 KHz - 2482000 KHz @ 20000 KH)
[   13.937058] cfg80211:   (2474000 KHz - 2494000 KHz @ 20000 KHz), (N/A, 2000 )
[   13.937062] cfg80211:   (5170000 KHz - 5250000 KHz @ 80000 KHz, 160000 KHz A)
[   13.937067] cfg80211:   (5250000 KHz - 5330000 KHz @ 80000 KHz, 160000 KHz A)
BPI-ROOT: fsck [   13.937071] cfg80211:   (5490000 KHz - 5730000 KHz @ 160000 K)
[   13.937075] cfg80211:   (5735000 KHz - 5835000 KHz @ 80000 KHz), (N/A, 2000 )
[   13.937079] cfg80211:   (57240000 KHz - 63720000 KHz @ 2160000 KHz), (N/A, 0)
[   14.241708] pci 0000:00:00.0: enabling device (0140 -> 0142)
[   14.250870] mt76x2e 0000:01:00.0: enabling device (0140 -> 0142)
[   14.260438] mt76x2e 0000:01:00.0: ASIC revision: 76120044
[   14.284794] mt76x2e 0000:01:00.0: ROM patch ad
[   14.298542] mt76x2e 0000:01:00.0: Direct firmware load for mt7662.bin failed2
[   14.310413] mt76x2e: probe of 0000:01:00.0 failed with error -2

tries to load wrong firmware…i assume that firmware-folder must also be copied (/lib/firmware), right? added it and rebooted:

scp linux-mt/drivers/net/wireless/mediatek/mt76/firmware/* [email protected]:/lib/firmware/

[   12.277101] pci 0000:00:00.0: enabling device (0140 -) Volatile Files
[   12.286972] mt76x2e 0000:01:00.0: enabling device (0140 -> 0 and Directories.
[   12.298464] mt76x2e 0000:01:00.0: ASIC revision: 76120044

[   12.322607] mt76x2e 0000:01:00.0: ROM patch already applied
[   12.338694] mt76x2e 0000:01:00.0: Firmware Version: 0.0.00
[   12.344616] systemd-journald[244]: Received request to flush runtime journal1
[   12.360023] mt76x2e 0000:01:00.0: Build: 1
[   12.360028] mt76x2e 0000:01:00.0: Build Time: 201507311614____
[   12.511759] mt76x2e 0000:01:00.0 wlan2: renamed from wlan0
[   12.551141] systemd-udevd[253]: renamed network interface wlan0 to wlan2

[10:01] [email protected]:~# lspci
00:00.0 PCI bridge: MEDIATEK Corp. Device 0801 (rev 01)
00:01.0 PCI bridge: MEDIATEK Corp. Device 0801 (rev 01)
01:00.0 Network controller: MEDIATEK Corp. Device 7612  <<<<<
02:00.0 IDE interface: ASMedia Technology Inc. ASM1061 SATA IDE Controller (rev)
[10:01] [email protected]:~# ifconfig -a | grep Link
bond0     Link encap:Ethernet  HWaddr 96:fb:01:14:e5:68  
eth0      Link encap:Ethernet  HWaddr 08:00:00:00:00:00  
          inet6 addr: fe80::a00:ff:fe00:0/64 Scope:Link
eth1      Link encap:Ethernet  HWaddr 08:00:00:00:00:01  
          inet6 addr: fe80::a00:ff:fe00:1/64 Scope:Link
lo        Link encap:Local Loopback  
sit0      Link encap:IPv6-in-IPv4  
tunl0     Link encap:IPIP Tunnel  HWaddr   
wlan2     Link encap:Ethernet  HWaddr f8:62:aa:50:12:1d    <<<< wlan-device visible :)
1 Like

Oh, this is really good, thank you for the test! Could you please attach a iw phy output? I want to check what capabilities are supported by the card :slight_smile:

iw_phy_mt76.log (7,2 KB)

    Supported interface modes:
         * IBSS
         * managed
         * AP
         * AP/VLAN
         * monitor

should only be the mt7612-card (other card currently not active), but found nothing the wlanx / MAC

1 Like

Thank you! Please let me know if you have any issue :wink:

@garywang can you please add the mt76-driver to your github, too?

  • add contents of mt76-github
  • apply patch
  • patch for (same as github-issue), Makefile and Kconfig patch_fwu.diff (1,8 KB)

maybe adding contents of drivers/net/wireless/mediatek/mt76/firmware to BPI_ROOT/lib/firmware if CONFIG_MT76 is set, when packing

also hostapd seems to work fine with mt76-driver…see ssid with hand and can connect (waiting for ip because i have no IP of wlan1 set and no dnsmasq running)

added current todo to my WIKI…

had dnsmasq + local IP working, got an IP from dnsmasq and can ping the IP from R2 :wink:

seems to work so far…also without antennas :stuck_out_tongue:

have you found a technical sheet for the card? i have 2 antenna connectors and want to know which is for 2.4G and which is for 5G

found a datasheet here, but its chip-only, not for the board: if i read it right, then both connectors can be used for G/A (Page 6, WF0/WF1), on the board one connector is labeled “main”, the other “aux”

i added an antenna to Main-Connector and it works for both bands (2.4 + 5GHz)


seems to work in my short tests without problems

1 Like

added mt76-driver to my fork of kernel-4.4:

1 Like