Linux

Custom Kernel on 96boards Hikey LeMaker

I started exploring CoreSight on the newer Cortex A-53 based platforms and the one which caught my eye was a Hisilicon Kirin 620 octa-core CPU based Hikey LeMaker. It seems really powerful for the size it comes in. However, the trials with Coresight did not end well for me as I soon realized that there is some issue in hardware that is preventing Coresight access on all CPUs with upstream kernel drivers. I further looked at the device tree files in their kernel tree and it seems the descriptions for CoreSight components is still not there. Probably it will be fixed somehow with more kernel patches hopefully. I did not experiment with it further. Apart from that, the board seems a really nice thing to play around with. There is Android as well as Debain support that works out of the box. I am just documenting steps I used to get a custom kernel for the board so that I don’t forget them😉 Probably someone else may also find them useful. For a complete guide go here. Lets start with getting the necessary files and the latest filesystem. I am using the 17th March snapshot from here. It is based on the hikey-mainline-rebase branch of their custom Linux kernel repo. Hopefully in the near future none of this will be required and things get into mainline. We also need the flashing tools and bootloader from here.

Updating with pre-built Images

The board ships with a v3.10 kernel. We need to first update it with the prebuilt binaries and then add our own custom built kernel to a custom location in rootfs. First get fastboot on your host with

$ sudo dnf install fastboot

Then copy the following lines in /etc/udev/rules.d/51-android.rules on the host so we can set proper read/write permissoins and access it withour root.

SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d00d", MODE="0660", GROUP="dialout"
SUBSYSTEM=="usb", ATTR{idVendor}=="12d1", ATTR{idProduct}=="1057", MODE="0660", GROUP="dialout"
SUBSYSTEM=="usb", ATTR{idVendor}=="12d1", ATTR{idProduct}=="1050", MODE="0660", GROUP="dialout"

Now close Jumper 1 and Jumper 2 in CONFIG section (J601) on the board. It is near the Extended IO. Power on the board. If you have a serial connection to your host, nothing should come up. Now send the boot downloader to the board. A green LED lights up. Also, after that check if the device is now recognized by fastboot.

$ sudo python hisi-idt.py -d /dev/ttyUSB0 --img1=l-loader.bin
$ sudo fastboot devices

The board should now be listed by fastboot as a device. We now start writing all binaries to the EMMC – partition table, kernel image, rootfs etc to get the system alive again. The 8G table is for the board with 8G NAND.

$ sudo fastboot flash ptable ptable-linux-8g.img
$ sudo fastboot flash fastboot fip.bin
$ sudo fastboot flash nvme nvme.img
$ sudo fastboot flash boot boot-fat.uefi.img
$ sudo fastboot flash system hikey-jessie_developer_20160317-33.emmc.img

We are done. Open Jumper 2 and restart. You should now see the snapshot kernel being booted up.

Build Custom Kernel

This is a quick way to build and test kernels based on the source from here. More and detailed information on building software from source is here. You will also need a cross toolchain to build the kernel. Get the Linaro one and set it up.

$ export LOCALVERSION="-suchakra-hikey"
$ make distclean
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig

You can customize what you want in the kernel now and then build the Image, modules and the device tree blob,

$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig 
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j8 Image modules hisilicon/hi6220-hikey.dtb

Install the modules in a local directory for now

$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH=./modules-4.4-suchakra modules_install

Transfer Kernel to Board

Next, copy /arch/arm64/boot/Image and /arch/arm64/boot/dts/hisilicon/hi6220-hikey.dtb  from the host to the board in /boot/suchakra directory. You can just scp these from the host. Add another menu entry in  /boot/efi/…/grub.cfg with the new kernel and dtb file. You can keep the initrd same. Copy the /lib/modules inside modules-4.4-suchakra from host to the target.

That is all. Time to reboot! I sometimes need to build custom kernel often so I have setup a script to build and scp the image from host to the target.

What about CoreSight?

As I said before, this may not be the best platform to experiment CoreSight however it maybe possible to access trace features using the Coresight Access Library from ARM DS-5. I also tried the Snapdragon based Dragonboard 410c and I was able to build and run the 4.4 kernel with CoreSight support quite quickly on that one as well. Linaro developers hint at CoreSight support for A-53 (v8) reaching mainline kernel in v4.7. The v4.4 one that I have right now is from the landing-team git of Linaro. I can confirm that on Dragonboard 410c, it is possible to get traces using ETF as sink and ETM as source by using the default kernel drivers and following  the default kernel documentation on the same. The generated trace binary can be read using ptm2human which supports ETMv4 now. However, I am still trying to get my head around what the decoded traces actually mean. More coresight stuff will follow as I discover its power. Apart from that, it was fun learning how DTBs work :)

Standard

One thought on “Custom Kernel on 96boards Hikey LeMaker

  1. Pingback: Links 18/4/2016: Linux 4.6 RC4, Tomb Raider for GNU/Linux | Techrights

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s