Image for post
Image for post
Getting closer to UEFI, HiKey960 and the kernel

What am I going to do?

Two weeks ago, I blogged about @microcolonel’s plan to port Redox OS to the Armv8 Architecture and specifically to the 64-bit AArch64 execution state.

  • Sanity checking @microcolonel’s current status of Redox OS. As a first step, and as explained in that doc, I compiled the whole of Redox for x86_64 on a Debian Stretch 9 host.
  • Building @microcolonel’s AArch64 Redox kernel development branch to get my first AArch64 entry into the Redox (micro) kernel!
  • Exploring the possibility of chain loading U-Boot from UEFI (i.e. Use U-Boot as an EFI payload) . For more details on this, look at this SuSE paper.
  • Getting on par with @microcolonel’s qemu based core kernel work on HiKey960 reference board. I will describe what works, where it fails, and the difficulties encountered.
  • Sharing some interesting community links, a Stanford course for Raspberry Pi (spoiler: it includes writing low level code in RUST 😍) and some insight on UEFI, U-Boot and OS Booting. A good read for anyone entering the playing field!

A summary of work done since the last blog posting

At the time of writing the previous blog the plan was to target the Raspberry Pi 3 (Cortex A53) as a development platform because of its availability, popularity and community. Sadly, it seems that Broadcom went through a lot of shortcuts while implementing this specific design, which means features like GIC are half-there or completely missing, like in this case.

Board Preparation

The HiKey960 needs a UART to USB cable (such as the Mezzanine board from 96Boards or any other 1.8V-compatible cable; beware that is not your usual 3V3/5V Amazon TTL2USB!)

Image for post
Image for post
  • Green — TxD (same as above)
  • Black — GND
  • Pink (I suppose trying to be red) — Vcc [leave that unconnected]
  • In case that you need there’s also an active low reset available on pin 6 of the 40 pin connector. A jumper from there to GND will reset the board and set it to fastboot mode (optional)
Image for post
Image for post
Serial output from HiKey960

Sanity check the Redox build environment

Here is the summary of my process, mainly following @microcolonel’s How-To but improvising at a few different points:

  • Install the required packages and libraries
  • Get the keys and install a Redox toolchain
  • Install Rust (nightly), cargo and xargo
  • Do a make fetch; make pull on the main repo
  • Get a Redox login prompt (x86_64) with make kvm=no vga=no qemu

Mission accomplished! 🎉

Compile the kernel for AArch64

What? Yes indeed! Thanks to @microcolonel’s this can be done (check the above mentioned How-To for detailed steps).Switch to origin/aarch64 branch

  • Update the submodules (kernel and syscall)
  • Get the aarch64-elf GNU toolchain
  • Get @microcolonel’s modified rust compiler that is using llvm with added toolchain triplet support for the aarch64-unknown-redox
  • Compiling a patched version of U-Boot
  • Let rustup know about our new AArch64 Rust compiler
  • Build the kernel!

Building UEFI for HiKey960 from source

Hikey960 currently only supports UEFI based booting using the Tianocore edk2 project. @microcolonel and I are exploring how we can get to the same boot flow by chain-loading u-boot from edk2 but that’s for later.

Code Preparation

Note: I only recently discovered that you can find pre-built binary UEFI images from Linaro but here are the steps I followed ot build from source for those who want to learn about it!

git clone -b integration
git clone -b testing/hikey960_v2.5
git clone -b testing/hikey960_v1.3.4
git clone -b testing/hikey960_v1.2
git clone
git clone

Let’s build!

Note: You may be able to find lot of the following instructions online, especially in the HiKey960 GitHub official documentation, as well a few Japanese blogs, where they are installing Debian on the HiKey. The problem is that in all of those sources, there’s always an error that stops you from following the steps successfully.

# Install UEFI from source on HiKey960
export BUILD_PATH=`pwd`cd ${BUILD_PATH}/edk2
ln -s ../OpenPlatformPkg
# for the v1 of Hikey960, remove the following line from the tools/platform.config
export UEFI_TOOLS_DIR=${BUILD_PATH}/uefi-tools
export EDK2_DIR=${BUILD_PATH}/edk2
EDK2_OUTPUT_DIR=${EDK2_DIR}/Build/HiKey960/${BUILD_OPTION}_${AARCH64_TOOLCHAIN}cd ${EDK2_DIR}# Build UEFI & ARM Trust Firmware
# Again, please use gcc-5.3 to build
${UEFI_TOOLS_DIR}/ -b ${BUILD_OPTION} -a ../arm-trusted-firmware hikey960# Generate l-loader.bincd ${BUILD_PATH}/l-loader
ln -sf ${EDK2_OUTPUT_DIR}/FV/bl1.bin
ln -sf ${EDK2_OUTPUT_DIR}/FV/fip.bin
ln -sf ${EDK2_OUTPUT_DIR}/FV/BL33_AP_UEFI.fd
python -o l-loader.bin — img_bl1=bl1.bin —
# Generate partition table (You can download from net directly)
# See to config your own ptable
PTABLE=linux-32g SECTOR_SIZE=4096 SGDISK=./sgdisk bash -x

Serial and flashing

To flash the loader you need to have the board in Recovery Mode (look at the following table for reference):

HiKey960 modes
  • Install the HiKey960 recovery tools:
git clone tools-images-hikey960# Ensure that the l-loader is set up 
# on the correct addresss
cat config./hisi-sec_usb_xloader.img 0x00020000
./hisi-sec_uce_boot.img 0x6A908000
./recovery.bin 0x1AC00000
  • Run the command to download l-loader.bin into HiKey960, using the right USB port:
    sudo ./hikey_idt -c config -p /dev/ttyUSB0{1}
  • Now that UEFI is running on the Recovery Mode it’s time to flash update the images!
# Flash the images onto HiKey960
sudo fastboot flash ptable prm_ptable.img
sudo fastboot flash xloader hisi-sec_xloader.img
sudo fastboot flash fastboot l-loader.bin
sudo fastboot flash fip fip.bin
sudo fastboot flash boot boot.img
sudo fastboot flash cache cache.img
sudo fastboot flash system system.img
sudo fastboot flash userdata userdata.img
  • Runtelnet localhost 2001
  • Using the Esc key, the boot manager is loaded. From there you can access UEFI Console, Android Fastboot or Grub!

Good job!!! 🥂🎇

Using U-Boot as an EFI payload

Das U-Boot is not just *another bootloader. *It’s one of the most used bootloaders in the embedded world. A brain child of Wolfgang Denk, it has been adopted by many developers and companies and they all contribute to its source base.

Fun Stuff

Would you like to learn more about Operating Systems, their internals and do some small (but exciting) experiments on Raspberry Pi?

Next steps

To conclude, I am trying to get into the habit of writing more often blogs but it feels currently that my time is better spent experimenting and keeping everybody updated with a longer (and hopefully more detailed) monthly blog entry!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store