Dev/OPi/OPiZero2/From Scratch

From Embeded Linux (and more) Wiki by Nathael
< Dev‎ | OPi‎ | OPiZero2
Jump to navigation Jump to search

ARM trusted firmware

You can generate it following the instructions from the file board/sunxi/README.sunxi64 from u-boot sources (see below)

git clone
cd arm-trusted-firmware
make CROSS_COMPILE=aarch64-linux-gnu- PLAT=sun50i_h616 DEBUG=1 bl31

Result is in build/sun50i_h616/debug/bl31.bin


Grab the sources

Grab the sources from official uboot repository

git clone
cd u-boot/


Note: fix the path (or use the right path) to your bl31.bin firmware

make CROSS_COMPILE=aarch64-linux-gnu- orangepi_zero2_defconfig
export BL31=/path/to/arm-trusted-firmware/bl31.bin  ##../arm-trusted-firmware/build/sun50i_h616/debug/bl31.bin
make -j8 CROSS_COMPILE=aarch64-linux-gnu-

Note: you can customize your u-boot configuration by using a make menuconfig


Erase the first Mo of the SD card while keeping the partition table:

dd if=/dev/zero of=${card} bs=1k count=1023 seek=1

Copy uboot image (SPL + ATF + second stage) to the SD card:

dd if=u-boot-sunxi-with-spl.bin of=${card} bs=1k seek=8

Linux Kernel

Grab the sources

  • Kernel from
git clone git://


mkdir -p Build/{linux,results}
cd linux
cp ##Your_old_config_file## ../Build/linux/.config
make ARCH=arm64 -j8 O=../Build/linux/ oldconfig
cd ../Build/linux/ 
make ARCH=arm64 -j8 CROSS_COMPILE=aarch64-linux-gnu-
make ARCH=arm64 -j8 CROSS_COMPILE=aarch64-linux-gnu- modules_install INSTALL_MOD_PATH=../results/Mods


  • Linux Kernel

Compilation result is in arch/arm64/boot/Image

  • Device tree

Use the sun50i-h616-orangepi-zero2.dtb (found in arch/arm64/boot/dts/allwinner/)

  • Modules

If the compilation has been performed using the above command lines you should have a directory "Build/Mods/lib/modules/***" (*** = name of the kernel you just compiled)
You must copy the whole directory (not only the content) on the SD card, in the partition holding the root filesystem (rootfs), in the /lib/modules/ directory without changing the name.

SD Card creation

Original information from linux-sunxi wiki

SD card architecture

start sector size usage
0KB 0 8KB Unused, available for an MBR or (limited) GPT partition table
8KB 16 32KB Initial SPL loader
40KB 80 - U-Boot

Typically partitions start at XXXMB (which is the default setting of most partitioning tools), but there is no hard requirement for this, so U-Boot can grow bigger than 984KB, if needed.


Erase the first Mo of the SD card while keeping the partition table:

dd if=/dev/zero of=${card} bs=1k count=1023 seek=1

(Use count=1024 and remove "seek" option to also erase the partition table)


Copy (dd) uboot images (u-boot-sunxi-with-spl.bin) to the SD card. Refer to "U-boot/Use" section above.

First partition

The first partition must start at +XXXMo, and be a few Mo (50 Mo should be OK) and be formated using ext2/3/4
Place the files "Image-5.19.0-ed3l", "sun50i-h5-orangepi-zero-plus-ed3l.dtb" and "boot.scr" on the first partition.

  • The file "boot.scr" is generated using mkimage from "boot.cmd" with the following command :
mkimage -C none -A arm -T script -d boot.cmd boot.scr

An example "boot.cmd" file can be found in boot_devuan_ceres_***.tar.bz2

A short one can look like this :

setenv kernel_image "Image"
setenv fdtfile "sun50i-h616-orangepi-zero2.dtb"
setenv bootargs "console=ttyS0,115200 root=/dev/mmcblk0p2 rw rootwait quiet"

load ${devtype} ${devnum} ${fdt_addr_r} ${fdtfile}
load ${devtype} ${devnum} ${kernel_addr_r} ${kernel_image}
booti ${kernel_addr_r} - ${fdt_addr_r}

Second partition

The second partition must be formated using ext4 and starts right after the first one. It can take all the remaining size unless you have other specific needs.

This partition holds the root filesystem (rootfs).


This board uses an ARM64 processor, thus the root filesystem should be built using "aarch64-linux-gnu-" cross-toolchain or use the arm64 architecture for Devuan or other Debian based distribution.

Refer to the rootfs creation page for more information.