Thursday, January 30, 2014

OpenWRT for WEMO - Part 1 - Compiling firmware

While waiting for a Belkin WEMO to arrive in the mail, I decided to at least get the firmware and development tools ready for its arrival. The Belkin WEMO is a power socket switch that can be turned on and off via the internet. It runs an embedded form of linux, with 16 Mb of storage and 32 Mb of ram. The embedded processor it uses (RT5350F) is part of the ralink mips embedded processor line for networking devices such as routers. OpenWRT is embedded linux for routers and many ARM and MIPS based devices. The ralink MIPS processor is supported by OpenWRT, so I will show how to install OpenWRT on the router and develop software for it.  This will enable development of custom applications to run on the device for switching appliances not restricted to Belkins proprietary software. Alternatively you could use the uPnP protocol with the stock firmware to control the unit (here), but that's a messy solution that requires a computer!

There are some prerequisites for putting OpenWRT on the WEMO, which are:

  • You must have Linux, preferably Ubuntu
  • The WEMO must be running stock firmware (pre 2.00.2176), due to an exploit Belkin locked access to the device (see here).

The following steps show how to create the toolchain for cross compilation, create tools for remote debugging, and create the firmware image for the WEMO.

  1. Install the latest build tools for linux.

    sudo apt-get install subversion build-essential libncurses5-dev
    sudo apt-get install git-core python2.7-dev
     
  2. Checkout the latest OpenWRT.
     
    mkdir ~/openwrt
    cd ~/openwrt
    git clone git://git.openwrt.org/openwrt.git
     
  3. Update and download the feeds, the feeds are source code for building packages to install in the firmware image.
     

    cd ~/openwrt/openwrt
    ./scripts/feeds update -a
    ./scripts/feeds install -a
     
  4. Start the menu configuration for OpenWRT, this will check for dependencies required for cross compilation.
     

    make menuconfig
     
  5. The menu configuration configures which cross compilation tools are to be compiled for creating a firmware image for a specific platform. For the Belking WEMO select the Target System as "Ralink RT288x/RT3xxx" and select the Subtarget as "RT3x5x/RT5350 based boards"
     
  6. This step enables options to build a toolchain for cross compiling and tools for remote debugging in eclipse (tutorial how to do this here). To build a toolchain and remote debugging tools select the following options:
     
    • Enable "Advanced configuration options (for developers)" (press space  bar), and from this menu (press enter to open once enabled) select "Toolchain Options --->" and ensure "Build gdb (NEW)" is enabled.
    • Back in the main menu, enable "Build the OpenWRT based Toolchain"
    • Select the "Development --->" menu and enable the "gdbserver" option, To select the option press space bar twice until an * appears next to the option, when M appears next to an option the package will be built but not installed in the firmware image.
    • Back to the main menu, then select "Network --->", "SSH --->" and enable the package "openssh-sftp-server"
     
    These options will allow for compilation and remote debugging using Eclipse, guide will be [here]
     
  7. Exit menu configuration and when prompted save the configuration.
     
  8. Begin the build processing with:
     
    make 
    
     
    This can take several hours, if there are problems use the option V=99 to get a more verbrose output. 

This completes the build of the firmware image, which can be found in:
  

~/openwrt/openwrt/bin/ramips/openwrt-ramips-rt305x-belkinf7c027-squashfs-sysupgrade.bin

The next step (here) is to connect serial lines to the Wemo, prepare the uboot environment, and finally flash the firmware image.

1 comment:

  1. Question! Why do you say "You must have Linux, preferably Ubuntu"? Should any distribution have all of that installed?

    ReplyDelete