Go Language on OpenWRT – Carambola2

I’m playing with interesting go language which is built for system programming however, golang has been using to solve variety problems. For me, the most important aspect of the language is it is compiled and cross platform . Its simple, easy to learn and solves resource problems efficiently.

For test purposes, I wrote a simple hello world application, which dumps  struct as hex string on Carambola2 (MIP32 arch.). To be able compile go source code on OpenWRT gccgo is required. There are OpenWRT repos adds go lang support to gcc for MIPS32 architecture.

If target environment doesn’t contain go library (libgo.so) , source code should be compiled with “-static-libgo” flag. In my case;

mips-openwrt-linux-gccgo -g -static-libgo hello.go -o hello2

Output ;

root@Carambola2:~# ls -lah
drwxr-xr-x 1 root root 0 Aug 18 18:09 .
drwxr-xr-x 1 root root 0 Aug 18 17:58 ..
-rwxr-xr-x 1 root root 16.5K Aug 18 2016 hello
-rwxr-xr-x 1 root root 2.8M Aug 18 18:09 hello2
root@Carambola2:~# ./hello2
00000000 01 02 |..|



package main

import (

type Data struct {
       X uint8
       y uint8

func main() {
       var buf bytes.Buffer
       dt := Data{1, 2}

       binary.Write(&buf, binary.BigEndian, dt)


Also see this blog post further information.


OpenWRT Mac OSX SDK & Toolchain

OpenWRT (trunk version for x86) and Carambola2 (v2.8) SDK and Toolchain development binaries can be found at http://mehmetalierturk.com/openwrt for Mac OSX (El Capitan). Binaries contain main developments packages  as preinstalled (gcc & gdb) and others packed under packages subdir.

My OpenWRT Development Environment on OSX with Vagrant

You can find how to build OpenWRT on Mac OSX from my previous posts, here I’ll share my development environment for wireless devices.

IDE:  After XCode, Clion is the best IDE for C/C++ development on OS X.  Only disadvantage is, it doesn’t support remote debugging.

Toolchain: Cross compiled toolchain for openWRT

Vagrant: There are boxes for openwrt I use qqshfox/openwrt-barrier_breaker and I added a shutdown script to get it working correctly. Auto sync doesn’t work instead installed both Mac and OpenWRT rsync to handle configuration.

I use Clion for development, and vagran rsync-auto sync’s binaries with vagrant box. Also, I  use USB Wifi adapter on vagrant box ( TP-Link WN727N works perfect).

My CMakeList.txt files is as follows;

cmake_minimum_required(VERSION 3.5)

#set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -std=c++11”)

set(SOURCE_FILES main.c CNetLib.c CNetLib.h)
add_executable(CNetLink ${SOURCE_FILES})


SET(CMAKE_STAGING_PREFIX /Volumes/OpenWRT/openwrt/staging_dir)
SET(STAGING_DIR /Volumes/OpenWRT/openwrt/staging_dir)

set(TOOLCHAIN_DIR ${STAGING_DIR}/toolchain-i386_i486_gcc-4.8-linaro_uClibc-

SET(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/bin/i486-openwrt-linux-uclibc-gcc)
SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/i486-openwrt-linux-uclibc-g++)
SET(CMAKE_STRIP ${TOOLCHAIN_DIR}/bin/i486-openwrt-linux-uclibc-strip)

set(CMAKE_C_FLAGS “${CMAKE_C_FLAGS} -Wall -Werror -L ${STAGING_DIR}/target-i386_i486_uClibc- -lnl-genl-3 -lnl-3”)


OpenWRT 15.05 Chaos Calmer on Mac OS X El Capitan 10.11

When I try to build new OpenWRT release 15.05 Chaos Calmer on OSX 10.11 mkimage build fails with following error:
Undefined symbols for architecture x86_64:
“_ERR_remove_thread_state”, referenced from:
_rsa_sign in rsa-sign.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[5]: *** [tools/dumpimage] Error 1
make[4]: *** [tools-only] Error 2
make[3]: *** [/Volumes/OpenWRT/openwrt/build_dir/host/u-boot-2014.10/.built] Error 2
make[3]: Leaving directory `/Volumes/OpenWRT/openwrt/tools/mkimage’
make[2]: *** [tools/mkimage/compile] Error 2
make[2]: Leaving directory `/Volumes/OpenWRT/openwrt’
make[1]: *** [/Volumes/OpenWRT/openwrt/staging_dir/target-mips_34kc_uClibc-] Error 2
make[1]: Leaving directory `/Volumes/OpenWRT/openwrt’
make: *** [world] Error 2

So, I replaced openssl with the one comes with homebrew build. Replaced Host/Compile section in tools/mkimage/Makefile, solves the issue.

define Host/Compile

$(MAKE) -C $(HOST_BUILD_DIR) defconfig

HOSTCFLAGS=”$(HOST_CFLAGS) -I/usr/local/Cellar/openssl/1.0.2d_1/include” \
HOSTLDFLAGS=”$(HOST_STATIC_LINKING) $(HOST_LDFLAGS) -L/usr/local/Cellar/openssl/1.0.2d_1/lib” \
$(MAKE) -C $(HOST_BUILD_DIR) tools-only

Building OpenWRT with Homebrew on Yosemite Mac OS X 10.10

Recently homebrew is more popular than macports and has support  most of the packages you may need on Mac OS X. To get OpenWRT complied on OS X prepare a disk image with  Disk Utiliy->New Image-> Case sensitive, sparse disk Image. Second, install XCode from App Store, and Command Line Tools:

xcode-select –install

Install Homebrew:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install required packages by brew install …

gcc47 coreutils asciidoc bzip2 fastjar flex gnu-getopt gtk2 intltool zlib openssl rsync ruby sdcc unzip gettext libxslt bison gawk autoconf wget ncurses e2fsprogs ossp-uuid gawk findutils gnu-tar

You may need to move existing getopt and tar and make symbolic link new gnu-getopt and gnu-tar. Switch to the new disk image and follow:

git clone git://git.openwrt.org/14.07/openwrt.git
cd openwrt
make menuconfig
make -j 8