Showing posts with label Cross-compiling. Show all posts
Showing posts with label Cross-compiling. Show all posts

Sunday, 13 December 2015

ushare in MIPS platform

If looking for a light-weight DLNA Media Server (DMS) to run in embedded device then ushare is one of the good option.


http://ushare.geexbox.org/

 The development for ushare is stopped now but still the version is good to bring up a DMS quickly. Ushare depends on libupnp and libdlna modules.


http://pupnp.sourceforge.net/
http://libdlna.geexbox.org/

The objective of this post is to mention how to cross compile ushare successfully with its dependency for MIPS architecture.


(1) Dependency Matrix


Very first thing is the dependency matrix which I could not see anywhere and spent more time to identify that


ushare - ushare-1.1a
libpupnp - libupnp-1.6.19
libdlna - libdlna-0.2.4
ffmpeg - ffmpeg-1.0.10

(2) Cross compile libpupnp


(3) Cross compile ffmpeg


Export the toolchain location in PATH environment variable.

#export PATH=/user/venkateshm/work/ushare-cc/toolchain/mips4k_gcc_x86_linux_22/bin/:$PATH

#./configure --prefix=/user/venkateshm/work/ushare-cc/OUTPUT/ffmpeg --enable-cross-compile --cross-prefix=mipsel-linux- --arch=mipsel --target-os=linux --disable-static --enable-shared --enable-pic --extra-cflags=-O2 --enable-memalign-hack --disable-devices --disable-muxers --disable-encoders --disable-filters --disable-hwaccels --enable-muxer=adts --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-yasm --disable-demuxer=matroska --disable-stripping

Since we need only the libraries, we can disable the generation of executors like ffmpeg, ffplay.

In runtime, I was facing 'Illegal instruction' when av_log() API is invoked. Not sure about the root cause; for quick resolution, I commented the implementation of av_log API in libavutil/log.c file.


#vi libavutil/log.c


Comment out the implementation of av_log API

#make
#make install

(4) Cross compile libdlna


In the configure file the ffmpeg dependency was not not properly listed and that was causing 'Symbol not found' error. After that edited the configure file to resolve the problem

#export CFLAGS="-I/user/venkateshm/work/ushare-cc/OUTPUT/ffmpeg/include/"


#export LDFLAGS="-L/user/venkateshm/work/ushare-cc/OUTPUT/ffmpeg/lib"

#vi configure

Add -lavutil -lavcodec and -lswresample in line number 646

645 echolog "Checking for libavformat ..."
646 check_lib libavformat/avformat.h av_register_all -lavformat -lavutil -lavcodec -lswresample || die "Error, can't find libavformat !"
647 echolog "Checking for libavcodec ..."

648 check_lib libavcodec/avcodec.h avcodec_register_all -lavcodec || die "Error, can't find libavcodec !"

#./configure --prefix=/user/venkateshm/work/ushare-cc/OUTPUT/libdlna --cross-compile --with-ffmpeg-dir=/user/venkateshm/work/ushare-cc/OUTPUT/ffmpeg --cross-prefix=mipsel-linux- --disable-static --enable-shared --enable-debug

#make

#make install

(5) Cross compile ushare


#export CFLAGS="-I/user/venkateshm/work/ushare-cc/ushare/ushare-1.1a -I/user/venkateshm/work/ushare-cc/OUTPUT/libupnp/include/ -I/user/venkateshm/work/ushare-cc/OUTPUT/libdlna/include/"


#export LDFLAGS="-L/user/venkateshm/work/ushare-cc/OUTPUT/libupnp/lib/ -L/user/venkateshm/work/ushare-cc/OUTPUT/libdlna/lib/ -L/user/venkateshm/work/ushare-cc/OUTPUT/ffmpeg/lib/"

#export CC=/user/venkateshm/work/ushare-cc/toolchain/mips4k_gcc_x86_linux_22/bin/mipsel-linux-gcc


#./configure --prefix=/user/venkateshm/work/ushare-cc/OUTPUT/ushare --with-libupnp-dir=/user/venkateshm/work/ushare-cc/OUTPUT/libupnp/  --with-libdlna-dir=/user/venkateshm/work/ushare-cc/OUTPUT/libdlna/ --cross-compile --disable-nls --disable-strip --enable-debug --enable-dlna

There is a bug in ushare source code, before make fix the code in ushare.c:line number 191 file

# vi src/ushare.c

ip = ((struct in_addr*)&request->CtrlPtIPAddr)->s_addr;

#make

#make install


At run time, export LD_LIBRARY_PATH environment variable before executing ushare binary

# export LD_LIBRARY_PATH=/user/venkateshm/work/ushare-cc/OUTPUT/libupnp/lib/:/user/venkateshm/work/ushare-cc/OUTPUT/libdlna/lib/:/user/venkateshm/work/ushare-cc/OUTPUT/ffmpeg/lib

Wednesday, 29 July 2015

Running Wetty.js in MIPS platform


The objective of this post is to explain the step-by-step procedure on bringing up wetty node-module in a linux OS based on MIPS architecture.


About Wetty


Wetty is a web based tty. It allows us to open a tty (text terminal) session in a web browser to access the remote machine. Normally we use a standard tty client such as putty or Xshell to access the remote machine. Wetty gives us the flexibility of accessing remote machine from a browser without the need of any other software.

Wetty is a node.js module and it runs on top of node.js


Prerequisites:

  1. Download node.js source code (https://nodejs.org/download/); v0.12.7 is the current version during the time of writing
  2. Clone wetty (https://github.com/krishnasrinivas/wetty)
  3. Host Linux (virtual) machine for cross compiling
  4. MIPS toolchain
I prefer to run a virtual machine in vagrant environment, it is so easy to configure and bring up a VM in vagrant. And file sharing between virtual machine and host is also so simple.

Cross compiling Node.js


|> Download node.js source code and prepare the build folder

# mkdir -p /usr/venkateshm/source/nodejs
# cd /usr/venkateshm/source/nodejs
# curl -O https://nodejs.org/dist/v0.12.7/node-v0.12.7.tar.gz
# tar xvf node-v0.12.7.tar.gz
# cd node-v0.12.7

|> Set the necessary terminal variables

# export TC_PATH=/usr/venkateshm/toolchain/stbgcc-4.5.3-2.4/bin
# export CC=$TC_PATH/mipsel-linux-gcc
# export AR=$TC_PATH/mipsel-linux-ar
# export CXX=$TC_PATH/mipsel-linux-g++
# export LINK=$TC_PATH/mipsel-linux-g++

|> Configure the make; the configuration for node.js is written is python so python 2.5 or 2.6 is required before running the below command

# ./configure --dest-cpu=mipsel --dest-os=linux --prefix=/usr/local/nodejs --without-snapshot
# vi config.gypi

|> Add following entry under variables 

'mips_arch_variant': 'mips32r1'

|> Make

# make
# make install



copy out/Release/node and put it in /usr/local/bin folder of MIPS machine


Installing wetty in MIPS



Most of the nodejs modules are platform independent as they will be written in javascript. But few modules like websocket are dependent on platform as they use platform specific implementation. 

Wetty is platform independent but its dependencies modules websocket and pts.js are platform dependent. 

Node.js ships with a utility called node.gyp to handle the cases like machine dependent node-module, this utility builds the node-module and generates .node file.

The easy approach is to install wetty first in host virtual machine

# git clone https://github.com/krishnasrinivas/wetty.git
# cd wetty
# npm install

Now all the dependencies of wetty are successful downloaded and can be found inside node_modules folder.

Now download the source of websocket and pty.js node-module

# git clone https://github.com/theturtle32/WebSocket-Node.git
# cd WebSocket-Node
# npm install nan
# /usr/venkateshm/source/nodejs/node-v0.12.7/deps/npm/bin/node-gyp-bin/node-gyp --arch mipsel configure build


If the build is successful, copy the generated build folder and replace it in wetty/node_modules/websocket/build

Similarly steps for pty.js

# git clone https://github.com/chjj/pty.js.git
# cd pty.js
# npm install nan
# /usr/venkateshm/source/nodejs/node-v0.12.7/deps/npm/bin/node-gyp-bin/node-gyp --arch mipsel configure build