There are various articles and videos about setting up the HiKey 960 so I won’t review the details. If you are interested just search for "HiKey 960 unboxing". Besides the board and the power supply, an HDMI monitor, USB keyboard and mouse, and a USB Type-C cable for flashing the software images are required.

The first step is to connect the HDMI monitor, keyboard, mouse, and power supply to start up Android. The installed version will be out of date, but starting it up is a good test to make sure the monitor, keyboard, and mouse work fine.

When Android starts, it’s a bit of a mystery what do with it. Wireless can be connected, but it has only a rudimentary WebView browser (which cannot download any files), no terminal, and no file manager app. This makes it difficult install any other applications.

There are two ways to install apps from places like APKMirror. One way is to download the .apk on another machine, put it on a micro SD card, put the card in the HiKey 960, and then use Storage menu in the Android settings to get to the SD card. Installing an apk file requires enabling apps from unknown sources in the Security settings. Using this technique, it’s possible to install a few useful apps such as a browser, terminal, and file manager. A second way is to read on and connect adb. With adb, apk files can be installed using the “adb install” command. The initial setup of adb may take longer, but it’s required to get maximum benefit from Streamline anyway and is perfectly fine for sideloading apps.

Let’s get started with the information to enable all features of Streamline on the HiKey 960.

Flashing the latest AOSP

The Android SDK Platform Tools are needed to setup Streamline on the HiKey 960. Download and install the version for the host machine to be used. The Platform Tools provide fastboot and adb. Fastboot is used to flash the software images and adb will connect to the board from the host machine.

To get up to speed with the latest software, download the current AOSP release from Linaro. The file to update everything is the one with “factory” in the name, such as hikey960-linaro-2017.08.23-factory-576c88f9.zip. The builds are numbered and directory named latest/ always points to the most recent build.

Extract the .zip file using unzip on Linux or a suitable program on Windows. It’s helpful to add the directory with fastboot and adb to the PATH environment variable.

Flashing the software is done using the fastboot utility. Official documentation is provided at 96Boards.

To prep for the software update:

Power down the board

Move switch 3 to the ON position (push up if you are looking at the numbers right side up)

This is the picture for the default settings, to boot Android. To use fastboot move the top switch in the picture (Ext boot) to the left.

The easiest way to flash the software is from a Linux host using the flash-all.sh script. It assumes fastboot is in the PATH. Although the documentation says only Linux is supported for flashing, Windows probably also works fine if the same commands are executed.

Once the updates are complete:

Power-off the board

Move switch 3 (Ext boot) back to the OFF position (as shown in the picture above)

Remove the USB Type-C connection

Power-on the board and boot Android

One quirk about the HiKey 960 is that the USB keyboard and mouse will not work when the USB Type-C cable is connected so it must be disconnected to use the keyboard and mouse.

Setting up adb

The Android Debug Bridge (adb) is a must for any development with Android. It is included in the Android SDK Platform Tools. The commands below assume adb is installed and in the PATH on either Linux or Windows.

First, make sure the HiKey 960 is in developer mode. Tap 7 times on the Build number in the configuration Settings -> About phone. This will also enable the board to stay alive when there is no screen activity and allow adb to connect.

To connect adb to the HiKey 960, connect the USB Type-C cable between the host and the board and use “adb devices” to confirm the board is visible. The first time some extra messages about starting the daemon on the host machine will display. This is on the first time only. If the host machine is Linux, sudo may be needed for permission to access the USB device for adb. The important output is the line with the number and “device”. This confirms the board is found by adb.

To avoid the problem with using USB Type-C for adb and for the keyboard and mouse, it’s helpful to connect adb over wireless.

This can be done with the USB Type-C cable connected and then the cable can be removed and a wireless link for adb can be used; assuming the host machine and the HiKey 960 board are on the same network. This enables adb and the keyboard/mouse at the same time.

The commands with $ are on the host machine and the # are on the target via the adb shell. Most instructions will miss the commands on the target which I found are required for HiKey 960.

This may disconnect adb since it is stopped! If needed go to the Developer options in the Android configuration using the HDMI monitor and slide the USB debugging off and then back on. This should restart adb with the new tcp configuration.

If not disconnected restart adbd:

# start adbd
# exit
$ sudo adb tcpip 5555

Remove the cable, find the IP address of the HiKey board in the configuration About phone -> Status or type ifconfig in a terminal app on the HDMI monitor, and connect over wireless. For my network I did:

$ sudo adb connect 192.168.1.63:5555

When necessary come back to this section follow the instructions to connect adb again.

Streamline has three modes of operation:

Gator Android application

Gator daemon as root

Gator daemon as root with Gator kernel driver

Streamline Gator Android application

The quickest way to do something with Streamline is to install the Android apk from the DS-5 installation.

Running the Streamline Android app shows many warnings about security and permission on Android 7+ and many other things which cannot be done.

The net result is the only thing that can be traced with Android O and the Streamline Android application is the gator daemon itself! This is not much help for profiling an application or overall system performance. Continue reading to learn how to overcome this by running the gator daemon as root and use the gator driver to get the most out of Streamline.

Connect Streamline

To just practice how to connect Streamline anyway, setup the path to ADB in the Streamline preferences. Browse to the adb.exe on Windows and set the ADB Path:

Connect to the HiKey 960 board (eyeball) and start a trace by clicking on the red dot.

The result is the profile information for the gator daemon! The screenshot shows the Android application and the underlying libgatord.so

To improve Streamline functionality the gator daemon (running as root) and driver must be used. The gator daemon is a userspace application which can be built using the Android NDK and the gator driver is a Linux kernel driver. First, let’s try with just the daemon and see what is possible.

Building the gator daemon for Streamline

These instructions to build the gator daemon are for a Linux host. A similar flow may be possible on Windows hosts, but I have not tried it.

Connecting Streamline with gatord running as root provides access to CPU counters and Linux profiling, but not the Mali G-71 information.

A bunch of warning are shown related to Mali which can be fixed by adding the gator driver to the system.

To get all the system profiling features of Streamline including the Mali GPU, the gator driver must be added to the Linux kernel.

Building the gator driver

Adding the gator driver is a challenge because it’s not possible to load kernel models into the running Android O kernel.

The file /proc/sys/kernel/module_disabled contains a 1 and there is no way to write a 0 to it. This prohibits the use of kernel modules.

This leaves two options:

Change and rebuild the kernel to allow loadable modules

Statically compile the gator driver into a new kernel

Both options require the kernel to be recompiled so the second one is probably preferred since it eliminates the extra step of loading the gator module. To maintain the control of unloading the gator module use the first method.

Either way, the kernel needs to be rebuilt so let's get started.

Rebuilding the kernel with gator

The kernel source tree is available from android.googlesource.com

There are branches for the 4.4 and 4.9 kernels. The Linaro images used at the start of the article use the 4.9 kernel so that is the branch that should be used.

The gator driver source was already retrieved from github for the daemon step. Use the path from that step to copy the driver source.

To add the gator driver into the kernel:

$ cd drivers
$ mkdir gator
$ cp -r /path/to/gator/driver/* gator

Edit the Makefile in the kernel drivers folder and add this to the end:

obj-$(CONFIG_GATOR) += gator/

Edit Kconfig in the kernel drivers/ directory and add this before the last endmenu:

source "drivers/gator/Kconfig"

The gator driver can now be enabled using menuconfig. It’s in the Device Drivers menu and select the * to include it in the kernel. Select M to build the loadable gator module. If the * is selected then the driver will be included in the kernel and there is nothing else to do except build the kernel. If M is selected then one more change is needed to enable modules to be loadable in the new kernel.

$ make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 menuconfig

If the M was selected for the Gator module, then module loading can be added by changing the source code to set the value of “modules_disabled” to zero in the kernel source code at kernel/sysctl.c The last two lines change from &one to &zero as shown below:

To update the kernel use fastboot to flash the 2 new images using the same procedure as described above to move the switch, run fastboot, put the switch back, and restart.

$ fastboot flash dts new-dt.img
$ fastboot flash boot new-boot.img

With the new kernel installed, the board restarted, restart the gatord and connect Streamline.

Now, all features of Streamline can be used. This includes CPU counters, Mali counters, and full process tracing.

Summary

Setting up full Streamline functionality with the HiKey 960 board is a bit more complex than the Raspberry Pi 3, but the solid support of the Android Open Source Project (AOSP) and the work by the Linaro and 96Boards communities make it a great development board for those who want to dig into the latest version of Android on recent, high-performance hardware which is similar to current mobile devices. The full functionality is provided without the need to compile the full Android AOSP userspace. For those who have a host machine with 150 Mb of disk space and 16 Gb of RAM AOSP can be compiled using the AOSP instructions, but the steps here make it possible to use Streamline without performing the full AOSP build procedure.

Give Streamline a try by visiting to the DS-5 download page using the button below and requesting a trial license:

Sorry, I don't have a board running Android right now to check the details, but there are many other articles to look at if you are interested in Mali details. This is a good one and has linked to others that would be useful: