What’s this blog about?
This blog is part 2 of creating a BSP for Nanopi Neo H3 board. Now that u-boot has been installed, all that remains is to prepare the kernel, device tree blob, and the user space.
Also, since the concepts are pretty straight-forward, this blog is written more like a “how-to” tutorial than a “conceptual” blog. So if you’re not into these kind of things, you’ve been warned :)
Linux kernel
The kernel goes first. After obtaining the source code (can be anywhere, from Linus’ GitHub repo to a mirror from a random university in East Asia), you can then compile the kernel for your board.
First, run:
make sunxi_defconfig
This is a good starting point. Next, run:
make menuconfig
and select the required drivers for the peripherals you have on your board (maybe it’s a sensor, ETH PHY, etc.). Once completed, you can then compile the kernel:
make zImage ARCH=arm CROSS_COMPILE=<cross-compiler-tuple>-
Once completed, the zImage (the kernel image) can be obtained from /arch/arm/boot directory.
Finally, but the kernel image in the boot partition (the 16MB vfat partition).
Device tree
The device tree is something that you should write if you’re creating your own board. However, since I’m just re-creating a BSP for Nanopi Neo H3, I can just use .dts that someone already made and compile it.
Just like the kernel image, the compiled blob goes to the boot partition as well.
extlinux.conf
u-boot’s final job is to launch the kernel and hand over control of the computer. But how does u-boot know where the kernel is?
Well, u-boot will look at /extlinux/extlinux.conf in the boot partition. So we just need to write the extlinux.conf script to tell it what it needs to do:
timeout 50 # 5 seconds delay
label Linux # boot entry
kernel /zImage
fdt /sun8i-h3-nanopi-neo.dtb
append console=ttyS0,115200n8 console=tty1 loglevel=8 root=UUID=<ROOT_PARTITION_UUID> rootwait rw # can define init=/path/to/init here.
As simple as that!
Creating user space with Debootstrap
Lastly, the user space. Unlike the kernel & device tree, this one goes to the second partition, the root partition. To install the user space, we’ll use Debootstrap (so we’ll be using Debian as the distro).
There really isn’t much to cover here, and below are just taken from the official guide:
Stage 1: Download root
debootstrap --arch=armhf --foreign <distro> <ROOTFS_MOUNTPOINT>
<distro> can be trixie or noble, or any distribution version.
Stage 2: Setup root
cp /usr/bin/qemu-arm-static <ROOTFS_MOUNTPOINT>/usr/bin/
chroot <ROOTFS_MOUNTPOINT> /usr/bin/qemu-arm-static /bin/sh -i
/debootstrap/debootstrap --second-stage
Stage 3: Create some configs
First setup password;
passwd
Up next, set up the hostname by modifying /etc/hostname.
Then, setup /etc/fstab:
UUID=<ROOT_PARTITION_UUID> / ext4 defaults 0 1
UUID=<BOOT_PARTITION_UUID> /boot vfat defaults 0 2
Lastly, in /etc/inittab:
T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt100
Conclusion
After all is said and done, we’ve re-created a BSP for Nanopi Neo H3! yay :)