Built Debian 9 (4.20 kernel) for my N1 box

Cross build Debian 9 for N1

This is what the box finally looks like:

It turns out to be quite easy..

Build the kernel

Debootstrap the rootfs

Before deboostrapping the rootfs, we will need qemu-user-static for emulating aarch64 environment.

debootstrapping an aarch64 rootfs on x86/64 would be a 2 stage process.

  • We first download the packages by sudo debootstrap --arch=arm64 --verbose --foreign stretch rootfs [mirror] in the x86/64 world.
  • Then we “enter” the aarch64 world by sudo chroot rootfs /bin/bash, and finish the debootstrapping by /debootstrap/debootstrap --second-stage.

We might also install some package (openssh-server, net-tools, just to name a few) / add configs we think useful at this moment.

root’s password might also be set now by executing passwd.

To be able to connect to the box through ethernet, I also added /etc/network/interfaces.d/eth0:

… and enabled PermitRootLogin yes in /etc/ssh/sshd_config.

Create initramfs

Before we leave the aarch64 world, we would want to create an initramfs for booting.

initramfs-tools and u-boot-tools will be needed for this step.

First we have to copy the modules compiled in the first step to /lib/modules/[kernel-version]/ (Keep in mind we’re still in the aarch64 world, with / being chrooted.

The initramfs can then be created by update-initramfs -c -k [kernel-version].

But what update-initramfs creates is a cpio archive, and is not directly usable in u-boot environment. To convert it to uInitrd, which is recognized by u-boot, we need to execute mkimage -A arm64 -T ramdisk -C none -n uInitrd -d /boot/initrd.img /boot/uInitrd.

Boot the newly built system

Now we may leave the aarch64 world.

We still would like to keep uEnv.ini / *_autoscript (which could also be mkimaged by us if we want to) and .dtbs in /boot (the first partition of the USB drive in my case), but now zImage could be replaced with our newly built vmlinuz, and uInitrd could be replaced by what we made in the previous step. If you’d like to, it’s also possible to use our newly built dtbs, but I kept my old one (with my patches) though. All other files might be deleted now (if you haven’t).

This is what /boot looks like now (this list is captured after I installed my newly built system onto my EMMC, s905_autoscript will be used instead if boot from USB drive):

As for the rootfs, we could simply rm -rf ./* the old one, and rsync -a /path/to/rootfs /path/to/root-partition (which is the second partition of the USB drive in my case).

It’s also possible to pack these files into boot.tar.gz and rootfs.tar.gz individually, if you’d like to.

Having done all of these, we could now try to boot from the system we newly built (the USB drive in my case).

If all goes well, our newly built system should boot without errors.

Install to EMMC

It would be straight forward to install it to EMMC.

After booting from the USB drive with the system we newly made, we just have to remove the old files in EMMC, and copy (or preferrably, rsync -a, to keep ownerships / permissions / …) the files in /dev/sda1 (the first partition of the USB drive) / /dev/sda2 (the second partition) into /dev/mmcblk1p1 (the first partiiton in EMMC) / /dev/mmcblk1p2 individually, and we’re done.

Install “standard” softwares

After rebooting from EMMC, we might want to install some “standard” softwares, as debootstrap just gave us a base system to boot from.

You might want to dpkg-reconfigure locales before installing the softwares.

tasksel install standard does a great job here.

This could also be done in aarch64 environment emulated by qemu with / chrooted.

References

Credits to them. Really appreciated.

Leave a Reply

Your email address will not be published.