Orange Pi 5 | Boot from SATA M.2 SSD

Another report via Twitter (ah “X”, after this maniac renamed the established brand): https://twitter.com/Open_Media/status/1706117397114134926

Actually there is two dedicated issues:

  • The bootloader itself must support SATA, and it seems the one from Armbian we use does not, while the one from Orange Pi does. Since also Armbian’s “legacy” bootloader package is based on vendor sources, I see no issue to instead use the one from Orange Pi. We could create a package from it to make it transparent: https://github.com/orangepi-xunlong/orangepi-build/tree/next/external/packages/bsp/rk3588/usr/share/orangepi5
    What needs to be tested is whether it does not break NMVe or USB boot. I can test USB, would be great if someone could test NVMe.
  • The second thing is adding the SATA device tree overlay, so that also the kernel/OS can detect and mount the rootfs on the SATA SSD. I am pretty sure that it disables NVMe support in the same turn, so we cannot enable it OOTB. But as said, since we use a boot script instead of limited extlinux or similar, we should be able to auto-detect the boot media and select the overlay automatically on demand. For this, I need help form someone with an NVMe and/or SATA SSD to past the output of env print from U-Boot console here, so I can check which variable to check for.

And some simplified instructions to enable SATA boot, which do not require flashing the Orange Pi image or Armbian:

  1. Flash a DietPi image to SD card, eMMC or USB to boot from. Do just a speedy first run setup, or hit CRTL+C at some point to abort and get to a shell prompt quickly.
  2. Download and flash the Orange Pi SPI bootloader:
    cd /tmp
    curl -fO 'https://raw.githubusercontent.com/orangepi-xunlong/orangepi-build/next/external/packages/bsp/rk3588/usr/share/orangepi5/rkspi_loader_sata.img'
    dd if=rkspi_loader_sata.img of=/dev/mtdblock0 conv=notrunc,fdatasync
    
  3. Download and decompress a fresh DietPi image:
    curl -fO 'https://dietpi.com/downloads/images/DietPi_OrangePi5-ARMv8-Bookworm.img.xz'
    # Optional: Check integrity
    sha256sum -c <(curl -sSf 'https://dietpi.com/downloads/images/DietPi_OrangePi5-ARMv8-Bookworm.img.xz.sha256')
    # Optional: Check authenticity
    curl -sSf 'https://github.com/MichaIng.gpg' | gpg --import
    gpg --verify <(curl -sSf 'https://dietpi.com/downloads/images/DietPi_OrangePi5-ARMv8-Bookworm.img.xz.asc') DietPi_OrangePi5-ARMv8-Bookworm.img.xz
    # Decompress
    apt install xz-utils
    xz -d DietPi_OrangePi5-ARMv8-Bookworm.img.xz
    
  4. Flash DietPi image to SATA (attach it if not done yet). PLEASE verify that /dev/sda really is the SATA SSD and not e.g. the USB drive you are booting from :wink:. Check e.g. via lsblk.
    dd if=DietPi_OrangePi5-ARMv8-Bookworm.img of=/dev/sda conv=notrunc
    sync
    
  5. Mount it and apply the SATA overlay:
    mkdir sata
    mount /dev/sda1 sata
    G_CONFIG_INJECT 'overlay_prefix=' 'overlay_prefix=orangepi-5' sata/boot/dietpiEnv.txt
    G_CONFIG_INJECT 'overlays=' 'overlays=sata' sata/boot/dietpiEnv.txt
    
  6. poweroff, detach the SD card/eMMC module/USB drive you booted from to boot from the attached SATA SSD.