Skip to content

Instantly share code, notes, and snippets.

@blizko
Created May 10, 2018 16:33
Show Gist options
  • Select an option

  • Save blizko/1550ab3ff40c8983d0452ca093468245 to your computer and use it in GitHub Desktop.

Select an option

Save blizko/1550ab3ff40c8983d0452ca093468245 to your computer and use it in GitHub Desktop.
Emercoin OpenWRT Cross-Compile Build
# Before Build - check Endianness of your target system. Haven't managed to get it working on Big-Endian with TP-Link TL1043-ND (Some notes in code have clues that it is not possible)
# As from https://github.com/corsis/PortFusion/wiki/MIPS-Builds
$ echo -n I | hexdump -o | awk '{ print substr($2,6,1); exit}'
# 0 = big-endian
# 1 = little-endian
apt-get install build-essential ncurses-dev unzip python zlib1g-dev autoconf libtool pkg-config libssl-dev subversion
# Idea Source - http://telecnatron.com/articles/Cross-Compiling-For-OpenWRT-On-Linux/index.html
mkdir -p /build/
cd /build
git clone https://github.com/openwrt/openwrt.git
cd openwrt
# Must Modify package definition to get Boost version 1.62. Newer versions were failing to build
./scripts/feeds update -a
# Edit feeds/packages/libs/boost/Makefile
# Change 1.66 to 1.62
# 1_66 to 1_62
# Change hash 36c96b0f6155c98404091d8ceb48319a28279ca0333fba1ad8611eb90afb2ca0
./scripts/feeds update -i packages
./scripts/feeds install -a
make menuconfig
# Select Target System as necessary. Check OpenWRT guides for necessary platform.
# Advanced Conf Options -> ToolChain Options -> Gcc version -> 5x #Must select GCC 5.4. Otherwise it will fail to build
# "Package the OpenWrt-based Toolchain"
# Libraries -> SSL -> Openssl
# Libraries -> libupnp
# Libraries -> boost
# Select Boost Package (Module) / Static only! Dynamic will fail Autoconfigure tests
# Include Boost - all libs
make -j 3
# Grab coffee and wait - very time consuming process
# Build BDB4.8
# Idea Source - https://cryptoandcoffee.com/mining-gems/install-berkeley-4-8-db-libs-on-ubuntu-16-04/
export STAGING_DIR=/build/openwrt/staging_dir
export TOOLCHAIN_DIR=$STAGING_DIR/toolchain-mips_24kc_gcc-5.5.0_musl
export CFLAGS="-fPIC" # Some part for Static linking
export CXXFLAGS="-fPIC"
# Otherwise - relocation R_MIPS_HI16 against `_ZTV2Db' can not be used when making a shared object; recompile with -fPIC
export CPPFLAGS='-I/build/openwrt/staging_dir/target-mips_24kc_musl/usr/include -lstdc++'
export LDCFLAGS="$TOOLCHAIN_DIR/lib:/build/openwrt/staging_dir/target-mips_24kc_musl/usr/lib/"
export LDFLAGS='-L/build/openwrt/staging_dir/target-mips_24kc_musl/usr/lib'
export LIBS=""
export LD_LIBRARY_PATH=$TOOLCHAIN_DIR/lib
export PATH=$TOOLCHAIN_DIR/bin:$PATH
mkdir -p /build/bdb
cd /build/bdb
wget http://download.oracle.com/berkeley-db/db-4.8.30.zip
unzip db-4.8.30.zip
cd db-4.8.30
cd build_unix/
../dist/configure --prefix=$TOOLCHAIN_DIR --build=mips-openwrt-linux-gnu --host=mips-openwrt-linux --enable-cxx --enable-static=yes
make
# Build Emercoind
export STAGING_DIR=/build/openwrt/staging_dir
export TOOLCHAIN_DIR=$STAGING_DIR/toolchain-mips_24kc_gcc-5.5.0_musl
export PATH=$TOOLCHAIN_DIR/bin:$PATH
export CPPFLAGS='-I/build/bdb/db-4.8.30/build_unix/ -I/build/openwrt/staging_dir/target-mips_24kc_musl/usr/include -lstdc++'
# Without lstdc got failures at a few points - https://stackoverflow.com/questions/6045809/link-error-undefined-reference-to-gxx-personality-v0-and-g/6045846
export LDFLAGS='-L/build/bdb/db-4.8.30/build_unix/.libs/ -L/build/openwrt/staging_dir/target-mips_24kc_musl/usr/lib -lboost_system -lboost_atomic'
export LIBS="-L/build/bdb/db-4.8.30/build_unix/.libs/ -L/build/openwrt/staging_dir/target-mips_24kc_musl/usr/lib -lboost_system -lboost_atomic -lboost_timer -lboost_chrono" #??
cd /build
git clone https://github.com/emercoin/emercoin.git
cd emercoin
./autogen.sh
./configure --prefix=$TOOLCHAIN_DIR --build=mips-openwrt-linux-gnu --host=mips-openwrt-linux --with-boost=/build/openwrt/staging_dir/target-mips_24kc_musl/usr --enable-dynamic=yes --enable-static=no
make
# After Make - Going to OpenWRT:
# Since OpenWRT devices have limited memory - additional disk must be present. In this example it is mounted to /mnt/sda1
# Must be installed on base system to enable external storage
block-mount
kmod-fs-msdos
kmod-scsi-core
kmod-fs-exfat
cd /mnt/sda1/
mkdir /mnt/sda1/libs
scp -r ubuntu@$buildHostIp:/build/emercoin .
scp -r ubuntu@$buildHostIp:/build/openwrt/staging_dir/toolchain-mips_24kc_gcc-5.5.0_musl/lib/* /mnt/sda1/libs
scp -r ubuntu@$buildHostIp:/build/openwrt/staging_dir/target-mips_24kc_musl/usr/lib/* /mnt/sda1/libs
scp -r ubuntu@$buildHostIp:/build/bdb/db-4.8.30/build_unix/.libs/libdb_cxx-4.8.so /mnt/sda1/libs
#Prepare for running:
export LD_LIBRARY_PATH="/mnt/sda1/emercoin/src/.libs:/mnt/sda1/libs"
export LD_LIBRARY_PATH="/mnt/sda1/libs:/mnt/sda1/emercoin/src/univalue/lib:/mnt/sda1/emercoin/src/.libs"
export LD_LIBRARY_PATH="/mnt/sda1/emercoin2/src/.libs:/mnt/sda1/libs"
/mnt/sda1/emercoin/src/.libs/emercoind
/mnt/sda1/src/emercoin-cli -datadir=/mnt/sda1/temp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment