Build for OpenWRT

From meshwiki
Jump to: navigation, search

Prebuilt Firmware of OpenWRT and Cjdns

CJD's Method

There's a much simpler way of building for OpenWRT here: https://github.com/cjdelisle/cjdns-openwrt

This is the preferred method.

XertroV's Method

Harder, but it doesn't require compiling the whole OpenWRT toolchain each time (there's probably a way not to with CJD's Method, but I don't know enough about OpenWRT).

Notes

The host distro XertroV used was Ubuntu 11.10, your mileage may vary for other OSs.

You may need to install kmod-tun on OpenWRT if you don't have it installed already:

> opkg update
> opkg install kmod-tun

./cjdroute --genconf takes a long long while on a router. Somewhere between 20-60+ seconds is expected. [Hint: Generate it on a proper computer, then scp/copy-paste it across]

Prerequisites

Ubuntu 11.10:

> sudo apt-get install subversion build-essential git-core libncurses5-dev zlib1g-dev gawk flex quilt

I'm sure you guys can figure out the corresponding packages for other flavours.

Some notes

Proxies really screw with svn. You need to edit /etc/subversion/servers if memory serves. Also be sure to export http_proxy=http://proxy.url:port/

Buildroot Setup

Note: This should all be done on a non-root account. The examples below will be using the user build.

Download Buildroot and Packages

# Setup
> cd ~
> mkdir openwrt
> cd openwrt
# Download
> svn co svn://svn.openwrt.org/openwrt/trunk/
> cd trunk
# Update; uses svn, edit feeds.conf for settings
> ./scripts/feeds update -a
> ./scripts/feeds install libevent2 nacl 
# If the above doesn't provide everything you need, try "./scripts/feeds install -a", though compilation will take longer.

The prebuild section will ensure that you aren't missing any packages. If you need help with which packages to install, check out [1].

# Prebuild
> make defconfig
> make prereq
# Configure
> make menuconfig

The configuration menu will need a bit of intuition. Stuff you need to do:

  1. Change target system (and profile if needed) (I use IXP4xx; you should lookup the architecture of your router on the openwrt router db)
  2. In libraries, select the following (press 'y')
    1. libevent2
    2. nacl
  3. Exit and save

Now we just build it with:

> make

or if you're on a multicore system try: (n + 1 where n is number of cpus)

> make -j 5

This may take a LONG time. Get some tea.

References

[1] http://wiki.openwrt.org/doc/howto/buildroot.exigence

[2] http://wiki.openwrt.org/doc/howto/build

Compiling Cjdns

Download and Precompilation

The following instructions are taken from https://github.com/cjdelisle/cjdns

Make sure to read that for up to date instructions.

> cd ~
> git clone https://github.com/cjdelisle/cjdns.git cjdns
> cd cjdns
> mkdir build
> cd build
> export Log_LEVEL=DEBUG

Create ~/cjdns/build/Toolchain.cmake

Fill it with the following:

# 
# ** Remember to change anything in the format of <SOME TEXT> to whatever should go there. 
# ** You'll have to look to find the right directories and binaries.
# 
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)

#compiler
SET(CMAKE_C_COMPILER /home/<USER>/openwrt/trunk/staging_dir/toolchain-<STUFF HERE>/bin/<ARCH>-openwrt-linux-gcc)
SET(CMAKE_CXX_COMPILER /home/<USER>/openwrt/trunk/staging_dir/toolchain-<STUFF HERE>/bin/<ARCH>-openwrt-linux-g++)

SET(CMAKE_C_FLAGS "-ffreestanding -fno-exceptions -fno-stack-protector")
SET(CMAKE_CXX_FLAGS "-ffreestanding -fno-exceptions -fno-stack-protector")

SET(CMAKE_FIND_ROOT_PATH /home/<USER>/openwrt/trunk/staging_dir/target-<OTHER STUFF HERE>/ /home/<USER>/openwrt/trunk/staging_dir/toolchain-<STUFF HERE>/)

# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Then in ~/cjdns/build/:

> cd ~/cjdns/build/
> mkdir staging_dir
> export STAGING_DIR=/home/<USER>/cjdns/build/staging_dir/

Open ~/cjdns/CMakeLists.txt with your favorite editor.

> nano ~/cjdns/CMakeLists.txt

Things to do:

  1. Remove -Werror from add_definitions() (line 23/127 at the time of writing)
  2. Set Nacl Libraries (do it above the nacl section just for ease) (about line 96/127)
## snip ##

#add_definitions(-Wall -Wextra -std=c99 -Werror -pedantic)
add_definitions(-Wall -Wextra -std=c99 -pedantic)

## snip ##

SET(NACL_INCLUDE_DIRS "/home/<USER>/openwrt/trunk/staging_dir/target-<STUFF HERE>/usr/include/")
find_package(NACL REQUIRED)
include_directories(${NACL_INCLUDE_DIRS})

## snip ##

On to compiling:

> cmake -DCMAKE_TOOLCHAIN_FILE=./Toolchain.cmake ..
> make

You'll notice there are some errors. Not to worry.

> nano ~/cjdns/CMakeLists.txt

Here you need to change

This:
SET(NACL_INCLUDE_DIRS "/home/<USER>/openwrt/trunk/staging_dir/target-<STUFF HERE>/usr/include/")

To This:
SET(NACL_INCLUDE_DIRS "/home/<USER>/openwrt/trunk/staging_dir/target-<STUFF HERE>/usr/include/nacl")

Save and close.

The Final Countdown

> cmake -DCMAKE_TOOLCHAIN_FILE=./Toolchain.cmake ..
> make

And with any luck it all comes together; all that's left is to SCP that sexy binary over to OpenWRT!

References

[3] https://github.com/cjdelisle/cjdns

[4] http://www.vtk.org/Wiki/CMake_Cross_Compiling

[5] All the helpful froods over at #cjdns