How to compile MT7668 WiFi & Bluetooth drivers for Linux? [Detailed Tutorial]

Learn how to compile MT7668 Bluetooth and WiFi driver modules for use with devices on Linux, including PS4, Android Boxes (CoreElec), etc.

A few months ago, I was able to release the WiFi and Bluetooth drivers for Mediatek MT7668 for PS4, thanks to the sponsorship provided by novice4321. Since then, there has been a lot of demand to make the source code public. But, I needed some more time to work on cleaning up the code for better public consumption. But, in the past two weeks, I have been working on-and-off on finally cleaning up the code and open-sourcing my edit of the drivers. And, here we are.

In this article, I will explain, how my edition of the source code can be utilised by anyone. Doesn’t matter if you are trying to build the MT7668 drivers for PS4 or for any other Android box, this article will help you get started.

UPDATE 1 (28 August, 2023) – Latest kernels with inbuilt MT7668 WiFi & Bluetooth.
UPDATE 2 (18th January, 2024) – Fix for DNS issues on MT7668 kernels.

Without further ado, let’s begin with the requirements.

Requirements

  • PC/VM running Linux (currently, Ubuntu/Fedora)
  • PS4 or Android Box with MT7668 (Check if you have MT7668 here)
  • Source Code on GitHub
  • Kernel source (For PS4, check here)

Those are the basic requirements. As for now, the source code has been tested on kernel 5.4.213 for PS4. But, in the current state, it should work for other 5.4.x kernels too. As for the newer kernels, the source code might require reworking. I will try my best to help. Leave a comment below.

Now, let’s get into the compilation and installation process itself. This tutorial itself will be divided into multiple parts, but mainly into two. In the first part, we will see how the driver module itself is compiled. And, in the second part, we will see how we can use the module on another device with the MT7668 chipset, for example, PS4, Android boxes, etc.

Compile MT7668 WiFi & Bluetooth drivers for Linux

Let’s go through the compilation process step-by-step.

Step 1. Preparing Linux for driver module compilation

For now, we will see how the driver can be compiled and used on an Ubuntu/Fedora-based distro. To compile the kernel, we need some applications. These are the steps required to install them.

  • On Ubuntu or Ubuntu-based distros:-
    1. Open a terminal and run sudo apt install build-essential
  • On Fedora or Fedora-based distros:-
    1. Open a terminal and run sudo dnf install @development-tools gcc g++ ncurses

Once that’s done, let’s jump into the kernel-headers building process.

Step 2. Compile and install kernel-headers

  1. Download the kernel target source and extract it to a suitable folder or clone it into a suitable folder.
  2. Check if a config file exists. If yes, open the config file, CONFIG_LOCALVERSION is set to nothing, i.e., it says, CONFIG_LOCALVERSION="". Once confirmed, save the config file and exit.
  3. Open a terminal in the kernel source folder.
    1. On Ubuntu or Ubuntu-based distros:-
      1. Run make -j5 deb-pkg.
      2. Once complete, check the terminal for the location of the .deb files, named linux-headers… and linux-image… Copy those .deb files to a suitable location.
    2. On Fedora or Fedora-based distros:-
      1. Run make -j5 rpm-pkg.
      2. Once complete, check the terminal for the location of the .rpm files, named kernel… and kernel-devel… and kernel-headers… Copy those .rpm files to a suitable location.
  4. Copy the bzImage within the arch/x86/boot folder to somewhere safe.
  5. Install the kernel header files.
    1. On Ubuntu or Ubuntu-based distros:-
      1. Open a terminal in the folder containing .deb files that we created in the previous step.
      2. Run sudo dpkg -i *.deb and wait for them to install.
    2. On Fedora or Fedora-based distros:-
      1. Open a terminal in the folder containing .rpm files that we created in the previous step.
      2. Run sudo rpm -i --nodeps --force *.rpm and wait for them to install.

Just to be sure that the kernel-related files have been properly installed, check /usr/lib/modules and /usr/src folders. You should find folder pertaining to your kernel version.

Step 3. Compile MT7668 WiFi and Bluetooth drivers

  1. Clone the driver source code to a suitable folder by running git clone https://github.com/noob404yt/mt7668-wifi-bt.
  2. Go into the folder and open the text file, Makefile.x86 within the folder MT7668-WiFi. Replace kernel_version at top with your kernel version’s folder, for eg.- 5.4.213+. To confirm, on your PC/VM, go into the folder /lib/modules to find the exact folder name. Make the same replacement in Makefile within the folder MT7668-Bluetooth.
  3. To build the WiFi driver, open a terminal in the folder, MT7668-WiFi and run make EXTRA_CFLAGS="-w" CROSS_COMPILE= -f Makefile.x86. You will find the compiled module named wlan_mt76x8.ko within MT7668-WiFi/drv_wlan/MT6632/wlan. Copy it somewhere safe.
  4. To build the Bluetooth driver, open a terminal in the folder, MT7668-Bluetooth and run make. You will find the compiled module named bt_mt7668.ko within MT7668-Bluetooth. Copy it somewhere safe.

That’s it! That’s how you can compile WiFi and Bluetooth driver modules for MT7668. Now, let’s see how we can use the compiled modules on our target system.

Install MT7668 WiFi & Bluetooth drivers on Linux (PS4, Android Boxes, etc.)

Step 1. Preparing target system for driver module installation

  1. Boot the target system (PS4, Android Box, etc.) with the compiled kernel (bzImage), that we had copied in Step 2.4.
  2. Install the kernel header files built in Step 2.3 on the target system.
    1. On Ubuntu or Ubuntu-based distros:-
      1. Open a terminal in the folder containing .deb files that we created in the previous step.
      2. Run sudo dpkg -i *.deb and wait for them to install.
    2. On Fedora or Fedora-based distros:-
      1. Open a terminal in the folder containing .rpm files that we created in the previous step.
      2. Run sudo rpm -i --nodeps --force *.rpm and wait for them to install.
  3. Go back to the driver source code on GitHub and copy every file in MT7668-WiFi/7668_firmware to /usr/lib/firmware on the target system.

That prepares the system to accept the WiFi and Bluetooth driver modules that we built in Step 3.

Step 2. Install MT7668 WiFi and Bluetooth driver modules

  • To temporarily load the modules without restart:-
    1. Open a terminal within the folder containing the modules (.ko).
    2. Run these commands one-by-one:-
      1. sudo insmod bt_mt7668.ko
      2. sudo insmod wlan_mt76x8.ko
    3. You should have both Bluetooth and WiFi running now.
  • To automatically load modules on every boot:-
    1. Copy the modules (.ko) to /usr/lib/modules/kernel_version folder.
    2. Open a terminal anywhere and run these commands one-by-one:-
      1. echo "bt_mt7668" | sudo tee -a /etc/modules
      2. echo "wlan_mt76x8" | sudo tee -a /etc/modules
      3. sudo depmod -a
    3. Reboot and there shall be WiFi and Bluetooth.

That’s it, guys!

Troubleshooting

This section will be updated with your comments and solutions.

Conclusion

Before concluding, I’d like to thank everyone that made this project possible, mainly novice4321 (sponsor) and other donors and testers including Reo Au In. Special thanks to Khadas’ repo, on which the source code is based.

As for the future of this project, please do understand that this is only one method of doing this. With a little more work, especially for the PS4, we could incorporate the module into the kernel as a driver, instead of being loaded as a module. I am led to believe that many capable members and devs within the PS4 community itself are working on this, as we speak and have had successes much before my work went open-source. I hope that this article will help them and everyone else. Anyways, I’ll keep updating you guys with the latest information on the PS4 Linux scene. Stay tuned!

9 Comments

  1. h ./scripts/package/mkspec >./kernel.spec
    TAR kernel-5.4.213+.tar.gz
    rpmbuild –target x86_64 -ta kernel-5.4.213+.tar.gz \
    –define=’_smp_mflags %{nil}’
    make[1]: rpmbuild: No such file or directory
    make[1]: *** [scripts/Makefile.package:59: rpm-pkg] Error 127
    make: *** [Makefile:1472: rpm-pkg] Error 2

    got this error when running make -j5 rpm-pkg

  2. Hello, I want to impement your driver into CoreELEC.
    But when I execute “make -j5 deb-pkg”, I only get this error in return:

    make: *** No rule to make target ‘deb-pkg’. Stop.

    Am I doing something wrong? Would be great if you could help me with that issue! Thanks!

  3. Thank you for your answer. I brought the issue to the EmuELEC-developers and he was able to implement the PS4-patch and now it’s working, thanks to your effort. Keep up the good work! All the best!

Leave a Reply

Your email address will not be published.


*