Zynthian on Compute Module 4 + nvme drive boot: it works!

How to do it:
My CM4 has an onboard emmc module, so that’s trickier then with one without emmc. I assume you know how to access remotely to your zynthian and have a basic knowledge of some bash command line tool.

Write Zynthian image to emmc

  1. Disable emmc boot on the cm4-IO board by placing a jumper on the header close to the CM4.
  2. Connect a micro usb to USB cable between the cm4-IO board and your computer.
  3. Power the cm4-IO board. The emmc drive will appear as an external USB drive.
  4. Burn the Zynthain image to that drive using your favorite tool. Mine’s USBimager, wich is lightweight, FOSS, and it runs on Win, Mac, Linux.
  5. Remove the drive (unmount it)
  6. Power off the cm4-IO board
  7. Remove jumper

Setup Zynthian / Update kernel version

  1. plug all your hardware to the cm4-IO board
  2. Power on and wait until the Zynthian setup process finish
  3. Enable USB host:

nano /boot/config.txt

and be sure you have:

dtoverlay=dwc2,dr_mode=host

  1. Using webconf, setup your hardware. Reboot, you should have hopefully a working Zynthian running from the emmc.
  2. Update kernel to 5.10:

rpi-update

  1. Reboot. Verify: uname -r => 5.10.39-v7l+ You can now access to your nvme drive: use lsblk command to identify it.

nvme drive setup

  1. create with fdisk command a 256Mb partition of type FAT32 and a second one big enough for housing the zynthian root file system (30Gb is ok) of type ext4. Save your changes, then exit fdisk.

lsblk:
mmcblk0 179:0 0 14.6G 0 disk
|-mmcblk0p1 179:1 0 256M 0 part /boot
|-mmcblk0p2 179:2 0 14.3G 0 part /
mmcblk0boot0 179:32 0 4M 1 disk
mmcblk0boot1 179:64 0 4M 1 disk
nvme0n1 259:0 0 238.5G 0 disk
|-nvme0n1p1 259:1 0 256M 0 part
|-nvme0n1p2 259:2 0 238.2G 0 part

  1. Format the partitions:

mkfs -f vfat /dev/nvme0n1p1
mkfs -f ext4 /dev/nvme0n1p2

  1. Create mount points:

mkdir /mnt/boot
mkdir /mnt/root

  1. Mount nvme partitions:

mount /dev/nvme0n1p1 /mnt/boot
mount /dev/nvme0n1p2 /mnt/root

  1. Copy filesystem:

rsync -avx / /mnt/root
rm -r /mnt/root/boot

Customize startup

  1. nvme module has to be loaded on an early stage to mount the root file system, so we use intramfs:

nano /etc/initramfs-tools/modules

add

nvme

at the end of the file.

  1. create initramfs:

update-initramfs -c -k uname -r

Be carefull, they are backticks around uname -r

  1. Update config.txt:

nano /boot/config.txt

add at the end

initramfs initrd.img-5.10.39-v7l+

  1. copy /boot partition on the nvme drive:

rsync -avx /boot /mnt/boot

  1. identify nvme partitions UUID with blkid commad.

blkid
/dev/nvme0n1p1: SEC_TYPE=“msdos” UUID=“5E2E-A6ED” TYPE=“vfat” PARTUUID=“da93a86c-01”
/dev/nvme0n1p2: UUID=“8369e8b4-5f56-4285-97a0-d67c93cb52cf” TYPE=“ext4” PARTUUID=“da93a86c-02”
/dev/mmcblk0p1: LABEL_FATBOOT=“boot” LABEL=“boot” UUID=“592B-C92C” TYPE=“vfat” PARTUUID=“2fed7fee-01”
/dev/mmcblk0p2: LABEL=“rootfs” UUID=“706944a6-7d0f-4a45-9f8c-7fb07375e9f7” TYPE=“ext4” PARTUUID=“2fed7fee-02”
/dev/nvme0n1: PTUUID=“da93a86c” PTTYPE=“dos”
/dev/mmcblk0: PTUUID=“2fed7fee” PTTYPE=“dos”

so on my nvme drive, boot partition is da93a86c-01 and root partition is da93a86c-02

  1. Modify kernel command line parameter:

nano /mnt/boot/cmdline.txt

modify the root= argument:

root=PARTUUID=da93a86c-02

  1. To ensure this modification persist if ever you change your hardware configuration or switch from stable to testing branc or vice versa:
    Create scripts directory

mkdir /mnt/root/var/zynthian/zynthian-my-data/scripts

create post install script:

nano /mnt/root//var/zynthian/zynthian-my-data/scripts/update_zynthian_sys.sh

and add the following:

#!/bin/bash
echo “initramfs initrd.img-5.10.39-v7l+” >> /boot/config.txt
echo “dtoverlay=dwc2,dr_mode=host” >> /boot/config.txt
echo “dwc_otg.lpm_enable=0 console=tty1 root=PARTUUID=da93a86c-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait” > /boot/cmdline.txt

Make it executable

chmod a+x /mnt/root/var/zynthian/zynthian-my-data/scripts/update_zynthian_sys.sh

  1. Modify fstab:

nano /mnt/root/etc/fstab

set the right PARTUUID:

PARTUUID=da93a86c-01 /boot vfat defaults 0 2
PARTUUID=da93a86c-02 / ext4 defaults,noatime 0 1

  1. Umount mount points:

umount /mnt/boot
umount /mnt/root

  1. Power off zynthian

Tell the bootloader to boot on the nvme drive

You will need the usbboot utility (Github link) installed on an another computer.

  1. Once installed you have to told the bootloader to modify the boot order. In usbbot/nvme/boot.conf change:

BOOT_ORDER=0xf25461

to

BOOT_ORDER=0xf25416

  1. From usbboot/nvme directory create a new eeprom:

./update-pieeprom.sh

  1. Write eeprom on cm4:
    repeat step 1. 2. 3. go in usbboot directory and run:

./rpiboot -d nvme

  1. repeat step 6. 7. reboot, cross fingers

root@zynthian:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
mmcblk0 179:0 0 14.6G 0 disk
|-mmcblk0p1 179:1 0 256M 0 part
|-mmcblk0p2 179:2 0 14.3G 0 part
mmcblk0boot0 179:32 0 4M 1 disk
mmcblk0boot1 179:64 0 4M 1 disk
nvme0n1 259:0 0 238.5G 0 disk
|-nvme0n1p1 259:1 0 256M 0 part /boot
|-nvme0n1p2 259:2 0 238.2G 0 part /

with the help of
RBPI nvme documentation
RBPI forum post

2 Likes