Category Archives: OpenWRT

LinkIt Smart 7688 Toolchain with OpenWRT

My last post was about how to get the LinkIt Smart 7688 embedded Linux module running and updating the firmware. This post in the series is going to explain the next step in the embedded development sequence, getting a cross compiler GCC toolchain working for the target to start developing software in C and C++.

A cross compiling toolchain is a crucial piece in any embedded development effort. While the LinkIt has programming languages built in such as python, lua, and node, many times system programmers need a native C/C++ toolchain to program low level fast systems. Many embedded platforms, such as the RaspberryPi, come with a toolchain already built and running on the system. This is handy for quick development but you are limited to compiling on the target processor, in this case 580MHz which can be a slow and painful process. A cross compiler is a compiler that runs on a PC and generates binary programs that run on a different machine. The LinkIt is a MIPS processor, so we need a compiler that runs on a typical PC (Most likely x86_64) and generates programs that run on MIPS.

The OpenWRT SDK Toolchain

OpenWRT’s build system is based on Buildroot, a set of tools for generating embedded Linux systems. The Buildroot system downloads all the packages needed for a system, compiles them for the target and builds an image. To compile the packages Buildroot downloads and makes a cross compiler toolchain which we can use for our system! OpenWRT does a great job of putting all the toolchain pieces together in an SDK when the image is built. Because the LinkIt is based on the ramips target of the 15.01 Chaos Calmer, the SDK is available on the build root servers. You can find the packages here: . On a 64bit Linux system, simply download the OpenWrt-SDK-15.05.1-ramips-mt7688_gcc-4.8-linaro_uClibc- file and decompress it. Windows cross compilers do exist or can be built but are outside of the scope of this post.

The OpenWRT SDK contains the GCC compiler, plus all the other tools needed to link and package binary files. The SDK also contains all the libraries required to link a Linux application such as the C library (LibC), pthreads, librt, etc. You will find the tools in the following locations in the bz2 package:

  • GCC Compiler: staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-
  • GCC libraries (RFS): staging_dir/target-mipsel_24kec+dsp_uClibc-

Using the Toolchain

Lets make a ‘hello world’ application for the LinkIt with the OpenWRT SDK toolchain. Create a test file:

int main(int argc, char ** argv)
printf(“Hello world\n”);
return 0;

Now compile the test program with the toolchain from the SDK:

<PATHTOBIN>/mipsel-openwrt-linux-gcc -c test.c -o test.bin

There should be no errors or warnings when you do the compile, and the output will be test.bin, an application that will only run on the LinkIt. The compiler also wanted the STAGING_DIR environment variable set with ‘export STAGING_DIR=<PATHTOSTAGINGDIR>’. You can confirm that the binary is for MIPS with the ‘file’ command:

file test.bin

Simply copy the binary file to the Linkit /root/ directory and run with ./test.bin. If your Linkit is connected to the network you can copy using scp.

scp test.bin root@<IP_ADDRESS>:/root/

Running the binary with ./test.bin from the /root/ directory and you should see the “Hello world” output.

Working with the LinkIt Smart 7688

As an embedded systems engineer I am always interested in new systems. I’ve worked with the NixCore X1 boards and got pretty deep in to the OpenWRT/LEDE environment. For those that don’t know, OpenWRT is a Linux system designed for deeply embedded systems with pretty limited resources. It was designed to be run on routers like the Linksys WRT54G series but it is much more than that. I’ve been keeping my eye on dev boards and SOMs that support OpenWRT and I came across the LinkIt series of boards from Seeed Studios and Mediatek, specifically the LinkIt Smart 7688. These are fully supported by OpenWRT, are FCC certified and available for only $15 each! I purchased one of the LinkIt Smart 7688 boards a while back and haven’t really messed with it too much. Since Protologcal was due for a new post I thought I would share my experience working with the LinkIt, booting it up for the first time, poking around the insides, and then upgrading the firmware.


  • MT7688AN Mediatek SOC
  • 580MHz
  • 128MB RAM
  • 22 GPIO
  • 3x UART
  • SPI
  • I2C
  • USB Host
  • Ethernet connections (100 base)
  • 802.11bg/g/n 2.4GHz

First boot:

With OpenWRT embedded systems like the LinkIt, there is almost always a serial port console allowing access to the bootloader and the root system. This allows developers to upgrade the firmware from a physical connection with the least amount of software. This is the starting point for all of my embedded system hacking, get the console and see what the system does.

I added the LinkIt to a breadboard, found the pinout diagram, connected up my FTDI232R-3v3 cable to UART2 as per this info, 57600 baud 8-N-1. Powering up the board through the micro-USB and you get the very familiar Ralink uBoot menu (Ralink is the original SOC+WiFi manufacturer purchased by Mediatek). uBoot is a bare-metal bootloader application that allows you to update the firmware on the device before the ‘true’ system boots. We will dive more in to that later. By default uBoot times out after a few seconds and hands control off to the Linux system partition which boots the kernel and enables the system. After a ton of messages we can hit enter and are dropped in to the standard OpenWRT console.

I was really impressed to see the standard OpenWRT 15.01 Chaos Calmer banner on the console, this to me means that Seeed or Mediatek didn’t do a lot of messing around with the stock system. For those who have worked with OpenWRT the system was pretty vanilla, the WiFi config uses the standard /etc/config/wireless, the init system appears to be unmodified, opkg reported all the packages (stock package list here), dropbear ssh server, etc. This is really really good to see, nothing crazy was running and taking up 100% CPU, so we have a pretty darn open development platform right out of the box, nicely done Mediatek!

Firmware upgrades:

I like to roll my own OpenWRT firmware, that way I have full control and I know what is installed in the system (no NSA or botnet backdoors!). Before getting in to building a custom OpenWRT image I like know that I can go back to the stock image if I really mess something up. Mediatek has a lot of information on how to upgrade the firmware on their Mediatek Labs website, so after some reading here is how you can flash a new image:

  • From stock firmware there is a web based flashing utility that uploads an image file and uses OpenWRT’s sysupgrade utility
  • You can also copy the firmware image to a USB drive and use uBoot to flash the image
  • uBoot has menu options for downloading via Serial and TFTP

The web upgrade UI is from the device, so you need to connect a computer to the open WiFi access point “Linkit_XXXXX” and go to from a browser. Using the web based upgrade path I was able to upgrade my LinkIt to the latest 0.9.4 firmware just as a test. This upgrade took a few minutes and there was no real indication on what was going on, other than the blinking orange LED. The serial console didn’t show anything during the sysupgrade, so you just have to upload and hope for the best.

The uBoot USB based upgrade path is a little better. First you copy your image file to a FAT formatted USB drive and name it lks7688.img. Then you plug the drive in to an USB OTG cable connected to the USB data port. Hold the wifi button on the LinkIt and reset the device with the reset button. With the serial console connected you can see that uBoot detects the wifi button held down, and after 5 seconds it starts searching for a USB drive. What is interesting is that the console outputs:

“5: System Load Linux then write to Flash via USB Storage.”

If you look at the boot menu there is no option for 5, it jumps from 4 to 7. Rebooting without the wifi button pressed, and entering 5 into the uboot menu and the system drops in to the same USB update routine, so there are a few ways to start this upgrade.

When uBoot finds the drive it will automatically burn the lks7688.img system image file to the correct location in the SPI flash. The system reboots and you have a new firmware image. The USB update still takes about 2 minutes, but that’s better than the 3+ minutes for the web update method. I did not try the serial or TFTP upgrade methods, that is going to take some digging in to the SPI flash partitioning done by Mediatek, but I’m sure it is possible. Again, I was really happy to see there is a commonly accepted bootloader method to upgrade firmware, not some janky software solution!

Overall, I am quite impressed with the LinkIt Smart 7688, it is powerful, open, well documented, and cheap embedded system. The next steps are to create a footprint in Eagle PCB, make a few adapter boards for some hardware I have here, and then build a custom OpenWRT image. In a later post I will go over how to build and download OpenWRT, with support for the WiFi hardware on the LinkIt, to make a truly custom embedded Linux platform!