The general plan is to build an sd-image-aarch64 from nixpkgs/nixos/modules/installer/cd-dvd/sd-image-aarch64.nix flash it to the eMMC and have the system come up, similar to how this “just works” for raspberry-pis.
The RockPi 4 is a RockChip RK3399 based board, build by radxa with the same formfactor as a rasperry Pi. One noticable difference is that the Rock Pi’s cpu is at the bottom to better allow for the installation of a heatsink. The heatsink as such will prevent it from fitting into raspberry pi enclosures, however together with the heatsink it forms a relatively stable package.
From Rock Pi 4 Partitions we can see that the official linux image partitions are layed out like this:
Part Number | Offset | Name | Description |
---|---|---|---|
1 | 32KB | loader1 | First stage loader |
2 | 8MB | loader2 | U-boot image |
3 | 12MB | trust | ATF |
4 | 16MB | boot | Kernel partition |
5 | 128MB | rootfs | Rootsfs |
Thus we should be able to just dd
the files onto it if
we had the files prepared like so:
dd if=idbloader.img of=/dev/sdx seek=64 dd if=uboot.img of=/dev/sdx seek=16384 dd if=trust.img of=/dev/sdx seek=24576 dd if=boot.img of=/dev/sdx seek=32768 dd if=rootfs.img of=/dev/sdx seek=262144
Inspecting the exampe rockpi4b-ubuntu-bionic-minimal-20191127_1942-gpt.img, we’ll find
$ sfdisk -l rockpi4b-ubuntu-bionic-minimal-20191127_1942-gpt.img -d label: gpt label-id: 992DF2C2-0170-4F66-9492-FBF320673EEF device: rockpi4b-ubuntu-bionic-minimal-20191127_1942-gpt.img unit: sectors first-lba: 34 last-lba: 4458462 rockpi4b-ubuntu-bionic-minimal-20191127_1942-gpt.img1 : start= 64, size= 8000, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=95D89D52-CA00-42D6-883F-50F5720EF37E, name="loader1" rockpi4b-ubuntu-bionic-minimal-20191127_1942-gpt.img2 : start= 16384, size= 8192, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=78BE2786-ACB9-4885-BB6C-77DDDEF5AAC9, name="loader2" rockpi4b-ubuntu-bionic-minimal-20191127_1942-gpt.img3 : start= 24576, size= 8192, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A36BC2FB-B345-417B-8AEF-B49EA06C1F7B, name="trust" rockpi4b-ubuntu-bionic-minimal-20191127_1942-gpt.img4 : start= 32768, size= 229376, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=CEE6EBD4-DA8F-4378-A430-05693004C5DA, name="boot" rockpi4b-ubuntu-bionic-minimal-20191127_1942-gpt.img5 : start= 262144, size= 4196319, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=B921B045-1DF0-41C3-AF44-4C6F280D3FAE, name="rootfs"
The debian-stretch-desktop image has almost the identical layout:
sfdisk -l rockpi4-debian-stretch-desktop-arm64-20190730_2022-gpt.img -d label: gpt label-id: 69E3E4E5-2BF4-4C94-8774-841F0A4EE8CB device: rockpi4-debian-stretch-desktop-arm64-20190730_2022-gpt.img unit: sectors first-lba: 34 last-lba: 7331806 rockpi4-debian-stretch-desktop-arm64-20190730_2022-gpt.img1 : start= 64, size= 8000, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=4C98C92E-398A-4FB8-AFD1-1529095B79B8, name="loader1" rockpi4-debian-stretch-desktop-arm64-20190730_2022-gpt.img2 : start= 16384, size= 8192, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=C8BDD4F5-12D8-42B8-8F69-147391C0438A, name="loader2" rockpi4-debian-stretch-desktop-arm64-20190730_2022-gpt.img3 : start= 24576, size= 8192, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=8E58643E-760F-452C-94F9-8703182E8FB2, name="trust" rockpi4-debian-stretch-desktop-arm64-20190730_2022-gpt.img4 : start= 32768, size= 1048576, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=BBF86B96-61B3-446D-A789-BED7E5B85490, name="boot" rockpi4-debian-stretch-desktop-arm64-20190730_2022-gpt.img5 : start= 1081344, size= 6250463, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=B921B045-1DF0-41C3-AF44-4C6F280D3FAE, name="rootfs"
radxa provides their build repo on github, where we can find the mk-image.sh for some additonal assistence.
As of this writing sd-image-aarch64.nix will use sd-image.nix to build
the disk. However sd-image will generate a MBR partitioned image.
With a Fat32 /boot/firmware
partition, and an ext4 /
nixos root
partition. Thus for the rockpi; this is not very useful.
For the rock64, thefloweringash already built a gpt based sd-image-rockchip.nix.
The Boot options as described in the Rockchip wiki make be believe we can get away with three partition. The SPL (idbloader.img), u-boot.itb, and the rootfs (containg the kernel) as boot partition.
Hi @angerman, thanks for trying to get NixOS to work on RockPi4. How would I go about running this? I'm trying to compile the image as suggested on NixOS documentation:
nix-build '<nixpkgs/nixos>' -A config.system.build.sdImage -I nixos-config=./sd-image.nix --argstr system aarch64-linux
However, that leads to the following error: