NixOS on ARM/Orange Pi Zero2 H616

From NixOS Wiki
Revision as of 22:07, 15 November 2022 by imported>Ein-shved
Orange Pi Zero2 (H616)
An Orange Pi Zero Plus2 (H5).
Manufacturer Xunlong / Orange Pi
Architecture AArch64
Bootloader Upstream u-boot[1]
Maintainer Ein-shved

Status

Upstream unstable NixOS AArch64 image will boot on the Orange Pi Zero2 (H616), using the proper upstream u-boot.

The support of allwiner H616 soc was introduced to the Linux upstream kernel since 6.0 version, but the 5.15.78 kernel still able to boot from unstable NixOS brunch.

Board-specific installation notes

Fastest way

First follow the generic installation steps to get the installer image on an SD card.

U-Boot needs to be copied to specific sectors on the microSD card with dd. Download u-boot for the board, and copy it to the correct location with (again, replace /dev/sdX with the correct path to the SD card device):

sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/sdX bs=1024 seek=8

Then, install using the installation and configuration steps.

Better way

You can use next flake to prepare ready-to-work image

{
  description = "Build image for Orange Pi Zero2 H616";
  inputs.nixpkgs.url = github:nixos/nixpkgs;
  outputs = { self, nixpkgs }: rec {
    # Better to avoid cross-compiling to 
    # download derivations from cache 
    system = "aarch64-linux";
    nixosConfigurations.orpiz2 = nixpkgs.lib.nixosSystem rec {
      system = "aarch64-linux";
      modules = [
        # Based on generic aarch64 image
        "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix" 
        {
          config = let
            # Appropriate bootloader
            bootloader = nixpkgs.legacyPackages.
              aarch64-linux.ubootOrangePiZero2; 
          in {
            system.stateVersion = "22.11";
            # Use the supported kernel
            boot.kernelPackages = nixpkgs.legacyPackages.
              aarch64-linux.linuxKernel.packages.linux_6_0;
            sdImage.postBuildCommands = ''
              # Emplace bootloader to specific place in firmware file
              dd if=${bootloader}/u-boot-sunxi-with-spl.bin of=$img \
                  bs=1024 seek=8 \
                  conv=notrunc # avoid truncation of image
            '';
          };
        }
      ];
    };
    images = {
      orpiz2 = nixosConfigurations.orpiz2.config.system.build.sdImage;
    };
  };
}

Run

nix build .#images.orpiz2

to prepare image

Serial console

The default console configuration from sd-image-aarch64 works out of the box.

Ethernet

Connected at 1Gbps mode.

Wireless

Not tested

HDMI

Not tested

Resources