#### how to start
# Connect to X15's own display, keyboard, mouse or Connect to another machine with a USB cable.
# Plug in the power and press power switch. User LEDs start to blink.
# Plug a ethernet cable. NOTE: the connecting port must be the upper one.
# In the USB-connected machine,
$ ifconfig
# inet 192.168.6.1 appears
# ssh debian@192.168.6.2
#### make a bootable micro SD card
# Don't confuse with flasher image; select micro SD card image in https://elinux.org/BeagleBoardDebian#BeagleBoard-X15
# In a linux machine, with the micro SD card inserted and unmounted:
$ wget https://rcn-ee.com/rootfs/2017-12-08/microsd/bbx15-ubuntu-16.04.3-console-armhf-2017-12-08-2gb.img.xz
$ xzcat bbx15-ubuntu-16.04.3-console-armhf-2017-12-08-2gb.img.xz | sudo dd of=/dev/mmcblk0
# Confirm the disk name by lsblk and don't use mmcblk0p1
# The site uses wget with debian 9 image, which contains GCC-6, which is maybe the cause of the problem.
# I tried to install GCC-4.8 on debian, which was recommended in samjabrahams' guide, without success.
# This ubuntu 16.04.3 contains GCC-5.4, which is OK with an added flag.
# Insert the SD card into X15 and then just press the power button (don't confuse with pressing and holding boot-select button for flasher)
# Now X15 is booted by micro SD card; Connect to the ubuntu of X15 from the USB-cable-connected-machine.
$ ssh ubuntu@192.168.6.2
#### resize the 1.7GB file system to the full card size
$ cd /opt/scripts/tools
$ git pull
$ sudo ./grow_partition.sh
# some error message, but it's ok.
$ sudo reboot
ubuntu@arm:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 820384 0 820384 0% /dev
tmpfs 186068 6792 179276 4% /run
/dev/mmcblk0p1 30758104 888212 28589844 4% /
tmpfs 930340 0 930340 0% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 930340 0 930340 0% /sys/fs/cgroup
tmpfs 186068 0 186068 0% /run/user/1000
# python3.5 and gcc 5.4 and g++ 5.4 are contained;
# I guess that GCC-6 results in "Bus Error" for "session.run()" after tensorflow installed
#### install bazel
ubuntu@arm:~$ sudo apt-get update
ubuntu@arm:~$ sudo apt-get install pkg-config zip g++ zlib1g-dev unzip
ubuntu@arm:~$ sudo apt-get install openjdk-8-jdk
ubuntu@arm:~$ mkdir tfbuild
ubuntu@arm:~$ cd tfbuild
ubuntu@arm:~/tfbuild$ wget https://github.com/bazelbuild/bazel/releases/download/0.9.0/bazel-0.9.0-dist.zip
# the most recent version was selected
ubuntu@arm:~/tfbuild$ unzip -d bazel bazel-0.9.0-dist.zip
ubuntu@arm:~/tfbuild$ cd bazel
ubuntu@arm:~/tfbuild/bazel$ vi scripts/bootstrap/compile.sh
run "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \
-d "${output}/classes" -source "$JAVA_VERSION" -target "$JAVA_VERSION" \
-encoding UTF-8 "@${paramfile}" -J-Xmx500M
ubuntu@arm:~/tfbuild/bazel$ vi tools/cpp/cc_configure.bzl
# at about line 25, change
cpu_value = get_cpu_value(repository_ctx)
# to
cpu_value = "arm"
ubuntu@arm:~/tfbuild/bazel$ ./compile.sh
# needs heat sink or fan, or x15 will shutdown due to CPU heat; about 50 min. taken
ubuntu@arm:~/tfbuild/bazel$ sudo cp output/bazel /usr/local/bin/bazel
#### install tensorflow
# cf. samjabrahams' guide https://github.com/samjabrahams/tensorflow-on-raspberry-pi/blob/master/GUIDE.md
# cf. https://www.tensorflow.org/install/install_sources
ubuntu@arm:~/tfbuild/bazel$ cd
ubuntu@arm:~$ sudo apt-get install python3-pip python3-numpy swig python3-dev
# to install wheel
ubuntu@arm:~$ export LC_ALL=C
ubuntu@arm:~$ sudo pip3 install wheel
ubuntu@arm:~$ cd rebuild
ubuntu@arm:~/tfbuild$ git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git
ubuntu@arm:~/tfbuild$ cd tensorflow
ubuntu@arm:~/tfbuild/tensorflow$ grep -Rl 'lib64' | xargs sed -i 's/lib64/lib/g'
# this is for 32-bit OS
ubuntu@arm:~/tfbuild/tensorflow$ ./configure
# select /usr/bin/python3.5 and its default lib path; select jemalloc Yes and the others are all No or defaults
ubuntu@arm:~/tfbuild/tensorflow$ bazel build --config=opt --local_resources 1024,1.0,1.0 --verbose_failures //tensorflow/tools/pip_package:build_pip_package --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"
# 1024 seems to fit RPi's RAM size, but I didn't want to take risk. I also removed all opt flags: these options may be tried later.
# about 200 min. taken
ubuntu@arm:~/tfbuild/tensorflow$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
ubuntu@arm:~/tfbuild/tensorflow$ sudo pip3 install /tmp/tensorflow_pkg/tensorflow-1.4.0-cp35-cp35m-linux_armv7l.whl
ubuntu@arm:~$ du rebuild
...
648072 tfbuild
ubuntu@arm:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 820384 0 820384 0% /dev
tmpfs 186068 9120 176948 5% /run
/dev/mmcblk0p1 30758104 3368668 26109388 12% /
tmpfs 930340 0 930340 0% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 930340 0 930340 0% /sys/fs/cgroup
tmpfs 186068 0 186068 0% /run/user/1000