Compiling LEDE on Windows 10

After receiving my Onion Omega2 from my Indiegogo perk, I really wanted to see what was possible with it. I thought this would be a great opportunity for me to try to compile something and see what it takes to get it running on the Omega2. I always develop on windows and that is a challenge when trying to work with IOT.

Before we can compile anything for the Omega2 we need an environment where we can cross compile our sources. The Onion OS on the Omega2 is a modified version of the LEDE project and the microcontroller used in the Omega2 is the MediaTek Ralink MIPS MT7688. So our goal is to compile LEDE, that gives us as result a GCC compiler capable of compiling source to MIPS that we can run on the Omega2.

Windows On Linux (Beta)

In windows 10 pro version 1607 there is a feature called Windows Subsystem for Linux. The Linux subsystem enables native ELF binaries to run under windows and thus enabling us to compile using GCC without the need to have a virtual machine running. There is a good video from one of the architects giving a presentation at blackhat if you want to know more about the system.

As of writing I’m using Windows Insider Build of the Creators Update Build 15031. You can get this build by enabling the Windows Insider Program under Settings –> Update & security –> Windows Insider Program (can take a couple of hours before you are able to see the updates) or you can download the ISO and run it as an update, if you are not willing to wait a few hours.

Setting up the WSL environment

Before this feature is available you need to enable developer mode on windows 10. Which is found in Settings –> Update & security –> For developers. After enabling you are able to turn the feature on.

After you have restarted, we are going to execute the following command, this will be our gateway to the Linux Subsystem.

Windows asks a few question for you to answer, after you have answered those,  you see the bash environment we will be working in. We are almost ready to install the needed dependencies. Before we continue we first update our environment so we have the latest version of our environment.

Next up is editing the file ~/.bashrc and append a line to it so at start the ~/.profile is also loaded, the WSL doesn’t do that.

We also need to edit the ~/.profile file when left as it is will load the ~/.bashrc file and cause an infinite loop. To prevent that from happening we need to remove the following lines from the file ~/.profile.

Downloading source code of LEDE

We need the LEDE sources so we can build a compiler that emits MIPS code that will run on the Omega2. We will start with the download of the sources to your home directory, thanks to WereCatf for the source. Do not work on the windows drives in /mnt/[c-d]. Every mount under /mnt points to the windows mounts, these mounts work with the DriveFs System and has some deadlock issues for now. If that happens then the only way to get WSL working again is to restart windows.

Installing dependencies

Before we continue with compiling LEDE, we first need to install some dependencies. Use the following command to install the dependencies.

Configuring and compiling LEDE

We need to configure the LEDE project before we compile the toolchain. Set the following options.

  • Target System: MediaTek Ralink MIPS
  • Subtarget: MT7688 based boards
  • Target Profile: Onion Omega2 or Onion Omega2+

Use the following command to configure the options for LEDE.

Tip: If navigating with arrows don’t seem to work try using +- and use <TAB> for navigating the bottom menu.

After you have configured LEDE you are ready to compile, use the following command. Compiling LEDE can take more than an hour to complete.

Tip: If the compilation fails try to remove the j4 argument, this argument tell how many hardware threads to use for the compilation.

After the compilation completes, we have the following directory containing the tools needed to compile our sources for the Omega2.

That is all to it, now we can use the mipsel-openwrt-linux-gcc to compile c code or we can use mipsel-openwrt-linux-g++ to compile our c++ code.

Adjust our environment

Now if we edit our ~/.profile again and add some extra paths, then we can compile without having to reference the complete path to our compiler.

We now have a working environment where we can compile c and c++ code.

One thought on “Compiling LEDE on Windows 10”

Leave a Reply