How to compile Linux kernel for Orange Pi Zero

In the article Arch Linux on Orange Pi Zero, I wrote about Arch Linux distribution on Orange Pi Zero. Now, I will describe, how to compile own linux kernel for this development platform. But please note, this article is not for newbies. It is necessary to know, how to compile linux kernel, install it by hand and what is DT.

Steps

  1. Download Toolchain
  2. Download kernel source code
  3. Download WiFi driver source code
  4. Configuration of kernel
  5. Compilation of kernel
  6. Compilation of WiFi driver
  7. Installation
  8. Device Tree preparation
  9. U-Boot (optional)
  10. Make SD card bootable

Prerequisites

We need to install Git version control system tools to out GNU/Linux distribution.

X86/X64 GNU/Linux system – everything will be cross-compiled.

Toolchain, kernel and WiFi driver

Just now, we need to download and install toolchain, kernel source code and WiFi driver source code.

For the following, we will use directory /data/OrangePi on our GNU/Linux system.

Now, create /data/OrangePI/download.sh script with content:

Make it executable and execute. After some minutes, we have all prepared and ready for compiling.

If you are installing Toolchain on x64, please uncoment [multilib] section in the /etc/pacman.conf file and install lib32-libstdc++5 and lib32-zlib packages.

Kernel

The /data/OrangePI/linux-sunxi directory contains Linux kernel tree patched by sunxi. It includes patches for ARM SoCs from Allwinner Technology.

You can use my own configuration as a template. Save following content as file named .config, and run make -j9 ARCH=arm oldconfig.

Compile kernel

In this step we will compile linux kernel source code. The appropriate script is here:

zImage and modules are installed in directory /data/OrangePi/output.

WiFi driver

OrangePi Zero uses XR819 WiFi chip. The appropriate driver is not included in the linux kernel code, but we can uses the one from Github. The source code is already downloaded in the /data/OrangePI/xradio folder.

Also here we can use script for compiling and install.

Kernel installation

Kernel and WiFi driver is installed in directory /data/OrangePi/output. Now, it’s necessary to copy everything to the SD card with Arch Linux.

But please note, if files modules.*. the directory /lib/modules/<KERNEL_VERSION> are too small or has zero length, you need to use depmod command on the OrangePi Zero to recreate them. If you don’t do it, no modules will be loaded after boot into new kernel.

If you don’t have XR819 firmware (for the WiFi driver) still downloaded, please grab it from Github and place to directory /lib/firmware/xr819.

Next step is download or compile Device Tree with WiFi nodes enabled.

Device Tree

Make compatible Device Tree with WiFi and I2C support enabled. Don’t use DT included in kernel source tree.

You can also use my DTS file and compile it with Device Tree Compiler:

Device Tree Compiler is installable in your GNU/Linux distribution.

Precompiled DTB you can download here.

sun8i-h2-plus-orangepi-zero.dtbfile place next to zImage (the same directory).

U-Boot

OrangePi Zero uses U-Boot as bootloader. We can also compile it by hand. Here is my configuration as a template:

You can download my precompiled U-Boot here.

Installation to the SD card can be done with:

Now, we need to instruct U-Boot, where is our kernel and DT. For that purphose, there is file boot.scr. This file is output from mkimage command, available in uboot-tools package.

Make sure, that root= parameter includes your right Root filesystem.

Linux kernel 4.15-rc2 and U-Boot 2018.01

Here

7 komentářů u „How to compile Linux kernel for Orange Pi Zero

  1. Andreas

    Thanks for the detailed instructions and your ArchLinuxImage.
    If possible you now could possibly describe howto update an/your
    ArchLinux without deleting your provided kernel .. and or
    howto update a newly compiled kernel on an/your ArchLinux running
    system.

    Cheers

  2. Andreas

    btw. I could do a second stage ‚pacman -Syu‘ update and reboot.
    everything was fine afterwards :-)

    I could also bring up a new zImage 4.14 on the updated device
    additional besides the 4.12 image.
    But unfortunately then the ethernet interface did not show up even after
    depmod for the lib/modules on the device.

    do you have an idea?

    Thanks

  3. Pingback: Linux kernel 4.15-rc2 for OrangePi Zero and OrangePi Zero Plus (H5) | brichacek.net

  4. Francesco

    Dear Zdeněk,
    I follow your guide for Orange PiZero kernel compilation, but during compilation using command:

    make -j9 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- LOADADDR=0x48000000 zImage modules dtbs

    i’ve this error:
    CC [M] drivers/net/wireless/realtek/rtlwifi/usb.o
    LD [M] drivers/net/wireless/realtek/rtlwifi/rtlwifi.o
    LD [M] drivers/net/wireless/realtek/rtlwifi/rtl_usb.o
    AR drivers/net/wireless/built-in.a
    AR drivers/net/built-in.a
    make: *** [drivers] Error 2

    Please can you help me to solve it? How can i take more informations about the error?
    Thanks a lot

Leave a Reply