Author: admin

  • Prepare SBC for kernel development

    First gather information about the SBC. In this post I focus on Orange Pi Zero3. This is quite cheap (if not for the RAM prices) board based on Allwinner H616 SoC. The support for it is mainlined in Trusted Firmware, U-boot and Kernel so it will be quite smooth ride.

    SD card preparation

    # Assuming /dev/sdb represent SD card
    sudo umount /dev/sdb*
    sudo dd if=/dev/zero of=/dev/sdb bs=1M count=32768 # Adjust for SD card size
    sudo blockdev --rereadpt /dev/sdb
    sudo sfdisk /dev/sdb
    # To create Linux partition from 1M onward: 1M,,L
    sudo blockdev --rereadpt /dev/sdb
    sudo mkfs.ext4 /dev/sdb1

    Clone, configure and build Trusted Firmware – step needed only on aarch64

    git clone https://github.com/ARM-software/arm-trusted-firmware.git
    cd arm-trusted-firmware/
    make PLAT=sun50i_h616 CROSS_COMPILE=aarch64-linux-gnu- bl31

    Clone, configure and build U-boot

    git clone https://source.denx.de/u-boot/u-boot.git
    cd u-boot/
    git s v2026.01 --detach # choose your own version
    make CROSS_COMPILE=aarch64-linux-gnu- distclean
    make CROSS_COMPILE=aarch64-linux-gnu- orangepi_zero3_defconfig
    make CROSS_COMPILE=aarch64-linux-gnu- BL31=../arm-trusted-firmware/build/sun50i_h616/release/bl31.bin -j$(nproc) # Path to previously built TF
    sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/sdb bs=1k seek=8 conv=fsync

    Install Debian on SD card

    apt install qemu-user-static debootstrap
    sudo mount -o remount,exec,dev,suid /mnt/sdb1
    debootstrap --arch=arm64 --foreign trixie /mnt/sdb1 http://deb.debian.org/debian
    cp /usr/bin/qemu-aarch64-static /mnt/sdb1/usr/bin/
    chroot /mnt/sdb1 /debootstrap/debootstrap --second-stage
    chroot /mnt/sdb1 /bin/bash # Run passwd inside to set root password

    Clone, configure and build kernel, install modules to SD card

    https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
    make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- O=build-opiz3 defconfig
    make -j"$(nproc)" ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- O=build-opiz3 Image dtbs modules compile_commands.json
    sudo make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- O=build-opiz3 modules_install INSTALL_MOD_PATH=/mnt/sdb1
    sudo cp build-opiz3/Image /mnt/sdb1/boot/
    sudo cp build-opiz3/arch/arm64/boot/dts/allwinner/sun50i-h618-orangepi-zero3.dtb /mnt/sdb1/boot/

    Extlinux in /mnt/sdb1/boot/extlinux/extlinux.conf

    MENU TITLE Kernel Lab Boot Menu
    TIMEOUT 50
    DEFAULT debian
    
    LABEL debian
    MENU LABEL Debian
    LINUX /boot/Image
    FDT /boot/sun50i-h618-orangepi-zero3.dtb
    APPEND console=ttyS0,115200 earlycon root=/dev/mmcblk0p1 rootwait rw rootfstype=ext4

    Notes

    • Allwinner SoC’s expect their SPL from sector 16 (8kb). That’s the reason U-boot needs to be copied from that sector
    • Only aarch64 needs Trusted Firmware. Previous architectures do not have support for Exception Level 3 (EL3).
    • Finding proper board for TF and dts/config for U-boot and Kernel can be non trivial. Best would be to start from Linux forums like https://linux-sunxi.org/Main_Page