Building Android On Server

New LXC Machine

Building Android need a Ubuntu machine, so I created the LXC machine which runs Ubuntu.
Install the bootstrap:

zypper in bootstrap

Then create the Ubuntu LXC via:

export LANG=en_US.UTF-8
Linux59:~ # lxc-create -n Ubuntu_Container -t /usr/share/lxc/templates/lxc-ubuntu

Start the container, username and password are ubuntu:

lxc-start -n Ubuntu_Container

Configure the LXC Machine

Better we have the static IP, and let the Container startup when machine boot.

Static IP Configuration

Change the network configuration via modifying the /etc/network/interfaces:

auto eth0

# Enable it for dhcp
#iface eth0 inet dhcp

# Enable them for static IP address
iface eth0 inet static
address 1xx.xxx.xxx.159
netmask 255.255.255.0
network 1xx.xxx.xxx.0
broadcast 1xx.xxx.xxx.255
gateway 1xx.xxx.xxx.1

Then next time you login into the machine, it hold the address of 159.

Start Together With Host Machine

Create a new definition file of systemd under the /usr/lib/systemd/system directory:

Linux59:/usr/lib/systemd/system # cat lxc\@.service
[Unit]
Description=%i LXC
After=network.target

[Service]
Type=forking
ExecStart=/usr/bin/lxc-start -d -n %i
ExecStop=/usr/bin/lxc-stop -n %i

[Install]
WantedBy=multi-user.target

Linux59:/usr/lib/systemd/system # pwd
/usr/lib/systemd/system

Let Ubuntu_Container runs when system bootup.

# systemctl enable lxc@Ubuntu_Container.service
ln -s '/usr/lib/systemd/system/lxc@.service' '/etc/systemd/system/multi-user.target.wants/lxc@Ubuntu_Container.service'

Update

visudo to change the settings:

ubuntu  ALL=(ALL:ALL) ALL
Defaults env_keep = "http_proxy https_proxy ftp_proxy"

Enable proxy for apt-get:

$ cat /etc/apt/apt.conf
Acquire::http::Proxy "http://127.0.0.1:9001";

Update the system and install some packages:

$ sudo apt-get update
$ sudo apt-get install tmux openjdk-7-jdk
$ sudo update-alternatives --config java && sudo update-alternatives --config javac
$ sudo apt-get install git gnupg flex bison gperf    zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev   libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386   libgl1-mesa-dev  mingw32 tofrodos   python-markdown libxml2-utils xsltproc zlib1g-dev:i386
$ sudo apt-get install build-essential 
$ sudo apt-get install g++-multilib
$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

Configuration on USB

Create following file:

ubuntu@Ubuntu_Container:~$ cat /etc/udev/rules.d/51-android.rules 
# adb protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="ubuntu"
# fastboot protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="ubuntu"
# adb protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="ubuntu"
# fastboot protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="ubuntu"
# adb protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER="ubuntu"
# fastboot protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER="ubuntu"
# adb protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="ubuntu"
# fastboot protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER="ubuntu"
# adb protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER="ubuntu"
# adb protocol on panda (PandaBoard ES)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d002", MODE="0600", OWNER="ubuntu"
# fastboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER="ubuntu"
# usbboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d00f", MODE="0600", OWNER="ubuntu"
# usbboot protocol on panda (PandaBoard ES)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d010", MODE="0600", OWNER="ubuntu"
# adb protocol on grouper/tilapia (Nexus 7)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0600", OWNER="ubuntu"
# fastboot protocol on grouper/tilapia (Nexus 7)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e40", MODE="0600", OWNER="ubuntu"
# adb protocol on manta (Nexus 10)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee2", MODE="0600", OWNER="ubuntu"
# fastboot protocol on manta (Nexus 10)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee0", MODE="0600", OWNER="ubuntu"

Building

Enable git proxy

Configure the git configuration:

ubuntu@Ubuntu_Container:~$ git config --global user.email "xxx@gmail.com"
ubuntu@Ubuntu_Container:~$ git config --global user.name "xxx"

Compile the connect.c for getting the cross-firewall tool.

$ gcc -o connect connect.c
$ sudo mv connect /usr/bin
$ sudo chmod  777 /usr/bin/connect
$ cat /usr/bin/myproxy 
/usr/bin/connect -H 127.0.0.1:9001 $@
$ sudo chmod 777 /usr/bin/myproxy

Let your git authenticated by github, please refers to the following article:
http://kkkttt.github.io/blog/2014/10/14/verified-to-github/

Then add the proxy setting in .gitconfig:

[core]
	gitproxy = /usr/bin/myproxy


Preparation

Install repo:

   57  echo $PATH
/home/ubuntu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
   58  curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
   59  chmod a+x ~/bin/repo

Make a new directory for holding the source code:

$ mkdir ~/code
$ repo init -u https://android.googlesource.com/platform/manifest

sync the repository:

$ repo sync

Build

Set the environment variables:

. build/envsetup.sh
lunch 

In lunch you could select whatever you like.
Then make via following command:

make -j 8

Trouble-shooting:

Your version is: java version "1.7.0_65".
The correct version is: Java SE 1.6.

Ok, we change the java version via:

$ sudo apt-get install software-properties-common
$ sudo apt-get install python-software-properties
Add the PPA:
$ sudo add-apt-repository ppa:webupd8team/java
Update the repo index:
$ sudo apt-get update
$ sudo apt-get install oracle-java6-installer

After installation, update the java version via:


$ sudo update-alternatives --config java
[sudo] password for ubuntu: 
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-oracle/jre/bin/java          1062      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-6-oracle/jre/bin/java          1062      manual mode
  3            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1051      manual mode

Press enter to keep the current choice[*], or type selection number: 

Now you could run building.

###Trouble Shooting Build error:

If you are building an old version of android probably you’ll have this error

host C++: obbtool <= frameworks/base/tools/obbtool/Main.cpp
:0:0: error: “_FORTIFY_SOURCE” redefined [-Werror]
:0:0: note: this is the location of the previous definition
cc1plus: all warnings being treated as errors
To fix this, edit build/core/combo/HOST_linux-x86.mk and replace:

HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
with

HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
And that’s it.

When you meet “error: reference ‘counts’ cannot be declared ‘mutable’", install gcc/g++ 4.4 and re-compiling.

$ sudo apt-get install gcc-4.4 g++-4.4  g++-4.4-multilib gcc-4.4-multilib
make CC=gcc-4.4 CXX=g++-4.4

View the CPU ranking:
http://itianti.sinaapp.com/index.php/cpu

490	Intel Core i5-2520M @ 2.50GHz		3537
851	Intel Xeon 5160 @ 3.00GHz		2047

View Result

Since we use the remote machine, we have to enable the vncserver, first install it via:

sudo apt-get install vnc4server

Install lubuntu-desktop as the default X:

sudo apt-get install lubuntu-desktop

Serial Port on BBB

Serial Port Settings

Use following settings for the serial monitor software:

The default serial port settings for the board are:
Baud 115,200
Bits 8
Parity N
Stop Bits 1
Handshake None

Connection

The serial port in BBB is listed as following:
/images/BBBSerial.jpg

Trouble-Shooting on Docker

The guideline I follow is from :
https://wiki.archlinux.org/index.php/Docker

Working behind Proxy

When docker runs under the proxy, it will be blocked by the firewall, thus in the ArchLinux we have to kill the systemd started docker daemon, and manually set the proxy configuration for the docker daemon, following is the tips:

$ systemctl stop docker.service
$ sudo HTTP_PROXY=http://1xx.*.*.2xx:2xx3 docker -d &

Then you run the docker for create the new machine will be OK.

Default Configuration

That leads me for thinking the default configuration of ArchLinux , change it to :

$ cat /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target docker.socket
Requires=docker.socket

[Service]
ExecStart=/usr/bin/docker -d 
LimitNOFILE=1048576
LimitNPROC=1048576

[Install]
Also=docker.socket

Add following line, but failed, Arch Wiki also indicates its failure:

[Service]
Environment="http_proxy=192.168.1.1:3128"
ExecStart=
ExecStart=/usr/bin/docker -d -g /var/yourDockerDir

So everytime you want to enable proxy, simply manually reload it.

Then reload the service status and restart the docker.service:

sudo systemctl daemon-reload
sudo systemctl restart docker.service

Test the docker to view if it runs well:

$ docker info

Docker Management

List the installed images:

[Trusty@~/code/octo/heroku/Tomcat]$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
archlinux           latest              a063a516f4c7        About an hour ago   293 MB
busybox             latest              e72ac664f4f0        13 days ago         2.433 MB
base/archlinux      2014.07.03          ea234cde99e6        12 weeks ago        282.9 MB
base/archlinux      2014.04.01          56c61f5c2920        12 weeks ago        293.3 MB
base/archlinux      latest              dce0559daa1b        12 weeks ago        282.9 MB

List Containers:

[Trusty@~/code/octo/heroku/Tomcat]$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                         PORTS               NAMES
50baf5783c6e        busybox:latest      "/bin/echo hello wor   6 minutes ago       Exited (0) 6 minutes ago                           mad_carson          
2f7108d2ee0e        archlinux:latest    "echo Success."        About an hour ago   Exited (0) About an hour ago                       jolly_galileo       

List the running Containers:

[Trusty@~/code/octo/heroku/Tomcat]$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Now start a container via(This command will run into the container and execute the /bin/bash):

$ docker run -i -t archlinux /bin/bash
[root@b6ab14b2ce65 /]# 

Check the container status:

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
b6ab14b2ce65        archlinux:latest    "/bin/bash"         27 seconds ago      Up 25 seconds                           high_wright   

When you exit, then the ps won’t display the corresponding items.

Install More Images

Install via:

$ docker run ubuntu /bin/echo hello world
$ docker run centos /bin/echo hello world

Run it ubuntu:

$ docker run -i -t ubuntu /bin/bash   
root@34b68719493b:/# cat /etc/issue
Ubuntu 14.04.1 LTS \n \l

Run into centos:

$ docker run -i -t centos /bin/bash   
bash-4.2# uname -a
Linux e3ec1911331b 3.16.4-1-ARCH #1 SMP PREEMPT Mon Oct 6 08:22:27 CEST 2014 x86_64 x86_64 x86_64 GNU/Linux
bash-4.2# cat /etc/issue
\S
Kernel \r on an \m

bash-4.2# which yum
/usr/bin/yum

Run BBB building in server

Background

Since building is heavy task to CPU, I decide to use the server in lab for building

Packages

We need to install following packages for setting up the building environment:

zypper in git patch u-boot-tools git ncurses-devel dpkg dpkg-devel dpkg-lang

Use git for acrossing the firewall of company:

> git config --global user.email xxxx@gmail.com
> git config --global user.name xxxx
> cat ~/.gitconfig
[user]
	email = xxxx@gmail.com
	name = xxx 

Then we compile a cross Firewall tool and tell git for using it.

$ gcc -o connect connect.c
$ sudo cp connect /usr/bin
$ sudo chmod 777 /usr/bin/connect
$ sudo chmod 777 /usr/bin/myproxy
$ cat /usr/bin/myproxy
/usr/bin/connect -H 127.0.0.1:9001 $@

Now add the following lines in ~/.gitconfig:

[core]
	gitproxy = /usr/bin/myproxy


Testing the git via:

git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git

Building

Be sure the directory had the same as in laptop. that is:

> pwd
/media/y/embedded/BBB/Kernel/bb-kernel

For long-time building, I install tmux for handling the process:

zypper in tmux

Under the folder, run build_kernel.sh then you could get the Linux Kernel.
fakeroot should be installed in openSUSE:

http://software.opensuse.org/package/fakeroot?search_term=fakeroot
rpm -ivh fakeroot-1.20-1.18.x86_64.rpm

You should change the following files to enable the hostname:

Linux59:~ # cat /etc/hostname
Linux59
Linux59:~ # cat /etc/hosts
127.0.0.1	localhost.localdomain	localhost
127.0.0.1	Linux59.localdomain	Linux59

Now run hostname via:

Linux59:~ # hostname --fqdn
Linux59.localdomain

Now run ./build_deb.sh you could get the deb file.

Building Angstrom

First you should check out the git source from github:

git clone git://github.com/Angstrom-distribution/setup-scripts.git

Then run:

$ MACHINE=beagleboard ./oebb.sh config beagleboard


Trouble-Shooting

First I met tmux issue. so I installed the tmux in router(OpenWRT):

opkg update
opkg install tmux

Then I use tmux in router,create the new session which holds the ssh connection to the Server.

Then in family computer, the git proxy configuraiton won’t reset even if I update the ~/.gitconfig. This problem didn’t solved. I don’t know why.

Tips for deploying ArchLinux on BBB

The detailed installation guideline could be found at:
http://archlinuxarm.org/platforms/armv7/ti/beaglebone-black

But while there are some tips in changing the uEnv.txt, to enable the boot from 2nd mmc partition. following is the configuration file:

[root@alarm mnt]# cat uEnv.txt
optargs=coherent_pool=1M


#u-boot eMMC specific overrides; Angstrom Distribution (BeagleBone Black) 2013-06-20
kernel_file=zImage
initrd_file=uInitrd
 
loadzimage=load mmc ${mmcdev}:${mmcpart} ${loadaddr} ${kernel_file}
loadinitrd=load mmc ${mmcdev}:${mmcpart} 0x81000000 ${initrd_file}; setenv initrd_size ${filesize}
loadfdt=load mmc ${mmcdev}:${mmcpart} ${fdtaddr} /dtbs/${fdtfile}
#
 
console=ttyO0,115200n8
# If you want to boot from usb
#mmcroot=/dev/sda1 ro
# If you want to boot from SD card
mmcroot=/dev/mmcblk0p2 ro
mmcrootfstype=ext4 rootwait fixrtc


Now reboot and then you could see the BBB runs into the ArchLinux.