I’m researching how to run NixOS on a NanoPi R6C here:
https://github.com/jakubgs/nixos-nanopi-r6c/issues/1
And I’ve built U-Boot for it from the recommended sources with FAT and EXT4 support, but for some reason the SD card refuses to boot. I’ve connected up the UART console over USB, and I have access to the U-Boot interactive shell, but I can’t seem to be able to boot it.
Here’s the whole result of printenv
:
I can see that the SD card is the mmc
number 1
:
=> mmc list
mmc@fe2c0000: 1
mmc@fe2e0000: 0 (eMMC)
But when I try to boot it it fails:
=> run bootcmd_mmc1
switch to partitions #0, OK
mmc1 is current device
Failed to mount ext2 filesystem...
** Unrecognized filesystem type **
I am able to list contents of the first FAT partition with firmware:
=> ls mmc 1:2
512 armstub8-gic.bin
52593 bcm2711-rpi-4-b.dtb
52682 bcm2711-rpi-400.dtb
53202 bcm2711-rpi-cm4.dtb
50504 bcm2711-rpi-cm4s.dtb
52476 bootcode.bin
946 config.txt
7266 fixup.dat
5399 fixup4.dat
3173 fixup4cd.dat
8381 fixup4db.dat
8387 fixup4x.dat
3173 fixup_cd.dat
10230 fixup_db.dat
10228 fixup_x.dat
2975680 start.elf
2251392 start4.elf
805756 start4cd.elf
3747688 start4db.elf
2998888 start4x.elf
805756 start_cd.elf
4819624 start_db.elf
3722504 start_x.elf
573544 u-boot-rpi3.bin
620720 u-boot-rpi4.bin
25 file(s), 0 dir(s)
But I can’t list or find the EXT4 partition with the system root and /boot
:
=> ls mmc 1:3
Failed to mount ext2 filesystem...
** Unrecognized filesystem type **
=> ls mmc 1:4
Failed to mount ext2 filesystem...
** Unrecognized filesystem type **
=> ls mmc 1:5
Failed to mount ext2 filesystem...
** Unrecognized filesystem type **
And the list of partitions I get for the SD card from mmc part
doesn’t seem to reflect what I see with fdisk
or parted
, which shows just two partitions:
I’m a bit stuck. Not sure what I’m doing wrong.
1 Like
I managed to get some progress by essentially tarballing the contents of a NixOS aarch64
SD card image 2nd ext4
partition and then unpacking that into a simple DOS partition layout with just one partition:
> sudo parted /dev/sda
GNU Parted 3.6
Using /dev/nvme0n1
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel msdos
(parted) mkpart primary 0% 100%
Which then managed to be detected by U-Boot:
=> mmc part
Partition Map for MMC device 1 -- Partition Type: DOS
Part Start Sector Num Sectors UUID Type
1 2048 122165248 f3d35a5f-01 83
=> run bootcmd_mmc1
switch to partitions #0, OK
mmc1 is current device
Scanning mmc 1:1...
Found /boot/extlinux/extlinux.conf
Retrieving file: /boot/extlinux/extlinux.conf
735 bytes read in 11 ms (64.5 KiB/s)
------------------------------------------------------------
1: NixOS - Default
Enter choice: 1: NixOS - Default
Retrieving file: /boot/extlinux/../nixos/8kqlms92cy9ycvh2x189xalay0d4fj39-initrd-linux-6.1.31-initrd
12278723 bytes read in 1007 ms (11.6 MiB/s)
Retrieving file: /boot/extlinux/../nixos/8qajvgdwgl58xahzwk4xd8ay3sgyynzj-linux-6.1.31-Image
57461248 bytes read in 4650 ms (11.8 MiB/s)
append: init=/nix/store/hfbp8ig1n2jsnq9hxv2sqxxsiyxwj03x-nixos-system-nixos-23.05pre-git/init console=ttyS0,115200n8 console=ttyAMA0,115200n8 console=tty0 cma=32M conso7
Retrieving file: /boot/extlinux/../nixos/8qajvgdwgl58xahzwk4xd8ay3sgyynzj-linux-6.1.31-dtbs/rockchip-nanopi6.dtb
** File not found /boot/extlinux/../nixos/8qajvgdwgl58xahzwk4xd8ay3sgyynzj-linux-6.1.31-dtbs/rockchip-nanopi6.dtb **
Skipping nixos-default for failure retrieving fdt
SCRIPT FAILED: continuing...
But failed with inability to find rockchip-nanopi6.dtb
file. But this is progress.
It appears something in how the SD card image is partitioned makes it not possible to boot by default.
I managed to scavenge an rk3588s-nanopi-r6c.dtb
file from official Armbian image for NanoPi R6C and copied it into my simplified SD card without the FAT partition and managed to get further:
=> env set fdtfile rockchip/rk3588s-nanopi-r6c.dtb
=> run bootcmd_mmc1
switch to partitions #0, OK
mmc1 is current device
Scanning mmc 1:1...
Found /boot/extlinux/extlinux.conf
Retrieving file: /boot/extlinux/extlinux.conf
735 bytes read in 12 ms (59.6 KiB/s)
------------------------------------------------------------
1: NixOS - Default
Enter choice: 1: NixOS - Default
Retrieving file: /boot/extlinux/../nixos/8kqlms92cy9ycvh2x189xalay0d4fj39-initrd-linux-6.1.31-initrd
12278723 bytes read in 1007 ms (11.6 MiB/s)
Retrieving file: /boot/extlinux/../nixos/8qajvgdwgl58xahzwk4xd8ay3sgyynzj-linux-6.1.31-Image
57461248 bytes read in 4651 ms (11.8 MiB/s)
append: init=/nix/store/hfbp8ig1n2jsnq9hxv2sqxxsiyxwj03x-nixos-system-nixos-23.05pre-git/init console=ttyS0,115200n8 console=tt7
Retrieving file: /boot/extlinux/../nixos/8qajvgdwgl58xahzwk4xd8ay3sgyynzj-linux-6.1.31-dtbs/rockchip/rk3588s-nanopi-r6c.dtb
216342 bytes read in 87 ms (2.4 MiB/s)
Fdt Ramdisk skip relocation
## Flattened Device Tree blob at 0x08300000
Booting using the fdt blob at 0x08300000
'reserved-memory' ramoops@110000: addr=110000 size=f0000
Using Device Tree in place at 0000000008300000, end 0000000008337d15
Adding bank: 0x00200000 - 0x08400000 (size: 0x08200000)
Adding bank: 0x09400000 - 0xf0000000 (size: 0xe6c00000)
Adding bank: 0x100000000 - 0x200000000 (size: 0x100000000)
Adding bank: 0x2f0000000 - 0x300000000 (size: 0x10000000)
Total: 46171.869 ms
Starting kernel ...
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x412fd050]
[ 0.000000] Linux version 6.1.31 (nixbld@localhost) (gcc (GCC) 12.2.0, GNU ld (GNU Binutils) 2.40) #1-NixOS SMP Tue May 30 13
[ 0.000000] Machine model: FriendlyElec NanoPi R6C
[ 0.000000] earlycon: uart8250 at MMIO32 0x00000000feb50000 (options '')
[ 0.000000] printk: bootconsole [uart8250] enabled
[ 0.000000] efi: UEFI not found.
...
But then the boot process stops at:
...
[ 0.000000] arch_timer: cp15 timer(s) running at 24.00MHz (phys).
[ 0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x588fe9dc0, max_idle_ns: 440795202592 ns
[ 0.000000] sched_clock: 56 bits at 24MHz, resolution 41ns, wraps every 4398046511097ns
[ 0.002301] Failed to get pclk for 'rk_timer'
[ 0.005511] Console: colour dummy device 80x25
[ 0.005928] printk: console [tty0] enabled
[ 0.006312] printk: bootconsole [uart8250] disabled
I/TC: Secondary CPU 1 initializing
I/TC: Secondary CPU 1 switching to normal world boot
I/TC: Secondary CPU 2 initializing
I/TC: Secondary CPU 2 switching to normal world boot
I/TC: Secondary CPU 3 initializing
I/TC: Secondary CPU 3 switching to normal world boot
I/TC: Secondary CPU 4 initializing
I/TC: Secondary CPU 4 switching to normal world boot
I/TC: Secondary CPU 5 initializing
I/TC: Secondary CPU 5 switching to normal world boot
I/TC: Secondary CPU 6 initializing
I/TC: Secondary CPU 6 switching to normal world boot
I/TC: Secondary CPU 7 initializing
I/TC: Secondary CPU 7 switching to normal world boot
And there’s no console interaction or video on the HDMI. So I guess re-using a DTB from another distro or kernel build is probably not the correct solution.
My experience in this area is limited, but I’m interested in learning more about it. Maybe my questions will help you find the problem.
I thought that the NixOS arm64 image contains uboot. Are you replacing it with yours, or am I just wrong about how your board decides what uboot to run?
Your mmc part
output shows a significant difference between mmc0
and mmc1
: mmc1
begins with userdata
; mmc0
has userdata
at the end. However, the type
properties of each sub-partition align by partition number. That is, mmc1.1
has the same value for type
as mmc0.1
. In other words, the sub-partition names do not match their corresponding types.
So, how does your mmc1
image get made such that userdata
appears first? Does fdisk
list the ext4
partition before the efi/vfat partition?
If I recall correctly, fdisk
has a command to reorder the gpt partition table to match the partition order on disk. This might be enough to fix your problem.
By the way, I would not expect NixOS to be able to run from a VFAT filesystem. VFAT has no support for symlinks.
I didn’t want to build custom U-Boot, but when I tried to boot I could not get it to work so I tried building my custom U-Boot with Ext4 support which in hindsight might have not been necessary, as the issue appears to be with the generic aarch64
NixOS SD card image that I tried using. I essentially got an image from here:
https://hydra.nixos.org/job/nixos/release-23.05/nixos.sd_image.aarch64-linux
But that image has a FAT partition with firmware files as first, and then after it Ext4 with the system. If you read my issue you’ll see that I was never trying to boot NixOS from FAT. I was simply trying to understand why my U-Boot is not detecting the Ext4 filesystem on the SD card.
Once I made my own SD card which did not include the FAT partition but simply had one Ext4 with the same contents as before, it actually was detected by U-Boot. So my thinking is that there’s something wrong either with my U-Boot or the NixOS image, because I could not read the Ext4 partition on a stock image.
Right now I’m trying to figure out how to build an SD card image which would include the missing rk3588s-nanopi-r6c.dtb
. I’m assuming I would have to build a kernel from the official FriendlyARM kernel repo:
Since it does contain a defconfig
for NanoPi 6: nanopi6_linux_defconfig
Because my attempt to include a DTB from armbian failed(though it went further than any other method), which I’m assuming is due to not being built together with the kernel that NixOS is using. But I’m not sure. I need to read more about how DTB files work.