Difference between revisions of "NixOS on ARM/Orange Pi Zero2 H616"

From NixOS Wiki
Jump to: navigation, search
(Got working USB)
Line 24: Line 24:
 
Upstream unstable NixOS AArch64 image will boot on the Orange Pi Zero2 (H616), using the proper upstream u-boot.
 
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.
+
The limited support of allwiner H616 soc was introduced to the Linux upstream kernel since 6.0 version, see [[#Periphery|periphery]] for details.
  
 
== Board-specific installation notes ==
 
== Board-specific installation notes ==
Line 40: Line 40:
 
=== Better way ===
 
=== Better way ===
  
You can use next flake to prepare ready-to-work image
+
To get the more useful output from board better to build image with kernel which supports more periphery (like USB). See [[#Periphery|periphery]].
 
 
<syntaxHighlight lang=nix>
 
{
 
  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;
 
    };
 
  };
 
}
 
</syntaxHighlight>
 
 
 
Run <syntaxhighlight lang="bash">nix build .#images.orpiz2</syntaxhighlight> to prepare image
 
  
 
== Serial console==
 
== Serial console==
Line 92: Line 50:
 
Connected at 1Gbps mode.
 
Connected at 1Gbps mode.
  
== USB ==
+
== Periphery==
 +
 
 +
Current newest numerated kernel version 6.1 does not contains full H616 sock support. At least some regulators and USB blocks are [https://github.com/torvalds/linux/blob/v6.1-rc8/arch/arm64/boot/dts/allwinner/sun50i-h616.dtsi missing] in DTS. But they are [https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/allwinner/sun50i-h616.dtsi available] in master branch.
 +
 
 +
Here is flake with which an image with better periphery support (at least - USB) may be build.
 +
 
 +
<syntaxHighlight lang=nix>
 +
{
 +
  description = "Build image for OrangePi Zero 2";
 +
  inputs = {
 +
    nixpkgs.url = github:nixos/nixpkgs/nixos-22.11;
 +
  };
 +
  outputs = { self, nixpkgs }: let
 +
    system = "aarch64-linux";
 +
 
 +
    #Build manipulation
 +
    stateVersion = "22.11";  # NixOS Version
 +
    useUnstableKernel = true; # Set to false to use mainline kernel
 +
    compressImage = true;    # Set to false to disable image compressing
  
The vanilla dts from kernel 6.0.9 does not contains required usb sections. Working on correct dts overlay for it.
+
    pkgs = nixpkgs.legacyPackages.x86_64-linux.pkgsCross.aarch64-multiplatform;
  
== Wireless ==
+
    # Build unstable kernel
 +
    kernel =
 +
      with pkgs;
 +
      with lib;
 +
      buildLinux rec {
 +
        kernelPatches = [
 +
          linuxKernel.kernelPatches.bridge_stp_helper
 +
          linuxKernel.kernelPatches.request_key_helper
 +
        ];
 +
        src = fetchGit {
 +
          url = git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git;
 +
          rev = "8395ae05cb5a2e31d36106e8c85efa11cda849be";
 +
        };
 +
        version = "6.1.0";
 +
        modDirVersion = version;
 +
        extraMeta.branch = versions.majorMinor version;
 +
      };
  
Not tested
+
    # Boot related configuration
 +
    bootConfig = let
 +
      bootloaderPackage = pkgs.ubootOrangePiZero2;
 +
      bootloaderSubpath = "/u-boot-sunxi-with-spl.bin";
 +
      # Disable ZFS support to prevent problems with fresh kernels.
 +
      filesystems = pkgs.lib.mkForce [ "btrfs" "reiserfs" "vfat" "f2fs" "xfs"
 +
                                      "ntfs" "cifs" /* "zfs" */ "ext4" "vfat"
 +
                                    ];
 +
    in {
 +
      system.stateVersion = stateVersion;
 +
      boot.kernelPackages = if useUnstableKernel
 +
        then pkgs.linuxPackagesFor kernel
 +
        else pkgs.linuxPackages_latest;
 +
      boot.supportedFilesystems = filesystems;
 +
      boot.initrd.supportedFilesystems = filesystems;
 +
      sdImage = {
 +
        postBuildCommands = ''
 +
          # Emplace bootloader to specific place in firmware file
 +
          dd if=${bootloaderPackage}${bootloaderSubpath} of=$img    \
 +
            bs=8 seek=1024                                          \
 +
            conv=notrunc # prevent truncation of image
 +
        '';
 +
        inherit compressImage;
 +
      };
 +
    };
  
== HDMI ==
+
    # NixOS configuration
 +
    nixosSystem = nixpkgs.lib.nixosSystem rec {
 +
      inherit system;
 +
      modules = [
 +
        # Default aarch64 SOC System
 +
        "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
 +
        # Minimal configuration
 +
        "${nixpkgs}/nixos/modules/profiles/minimal.nix"
 +
        { config = bootConfig; }
 +
        # Put your configuration here. e.g. ./configuration.nix
 +
      ];
 +
    };
 +
  in {
 +
    inherit system;
 +
    # Run nix build .#images.orangePiZero2 to build image.
 +
    images = {
 +
      orangePiZero2 = nixosSystem.config.system.build.sdImage;
 +
    };
 +
  };
 +
}
 +
</syntaxHighlight>
  
Not tested
+
{{note|Be careful with such firmware - the unstable kernel version may be harmfull}}
  
 
== Resources ==
 
== Resources ==

Revision as of 21:44, 22 December 2022

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 limited support of allwiner H616 soc was introduced to the Linux upstream kernel since 6.0 version, see periphery for details.

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

To get the more useful output from board better to build image with kernel which supports more periphery (like USB). See periphery.

Serial console

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

Ethernet

Connected at 1Gbps mode.

Periphery

Current newest numerated kernel version 6.1 does not contains full H616 sock support. At least some regulators and USB blocks are missing in DTS. But they are available in master branch.

Here is flake with which an image with better periphery support (at least - USB) may be build.

{
  description = "Build image for OrangePi Zero 2";
  inputs = {
    nixpkgs.url = github:nixos/nixpkgs/nixos-22.11;
  };
  outputs = { self, nixpkgs }: let
    system = "aarch64-linux";

    #Build manipulation
    stateVersion = "22.11";   # NixOS Version
    useUnstableKernel = true; # Set to false to use mainline kernel
    compressImage = true;     # Set to false to disable image compressing

    pkgs = nixpkgs.legacyPackages.x86_64-linux.pkgsCross.aarch64-multiplatform;

    # Build unstable kernel
    kernel =
      with pkgs;
      with lib;
      buildLinux rec {
        kernelPatches = [
          linuxKernel.kernelPatches.bridge_stp_helper
          linuxKernel.kernelPatches.request_key_helper
        ];
        src = fetchGit {
          url = git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git;
          rev = "8395ae05cb5a2e31d36106e8c85efa11cda849be";
        };
        version = "6.1.0";
        modDirVersion = version;
        extraMeta.branch = versions.majorMinor version;
      };

    # Boot related configuration
    bootConfig = let
      bootloaderPackage = pkgs.ubootOrangePiZero2;
      bootloaderSubpath = "/u-boot-sunxi-with-spl.bin";
      # Disable ZFS support to prevent problems with fresh kernels.
      filesystems = pkgs.lib.mkForce [ "btrfs" "reiserfs" "vfat" "f2fs" "xfs"
                                       "ntfs" "cifs" /* "zfs" */ "ext4" "vfat"
                                     ];
    in {
      system.stateVersion = stateVersion;
      boot.kernelPackages = if useUnstableKernel
        then pkgs.linuxPackagesFor kernel
        else pkgs.linuxPackages_latest;
      boot.supportedFilesystems = filesystems;
      boot.initrd.supportedFilesystems = filesystems;
      sdImage = {
        postBuildCommands = ''
          # Emplace bootloader to specific place in firmware file
          dd if=${bootloaderPackage}${bootloaderSubpath} of=$img    \
            bs=8 seek=1024                                          \
            conv=notrunc # prevent truncation of image
        '';
        inherit compressImage;
      };
    };

    # NixOS configuration
    nixosSystem = nixpkgs.lib.nixosSystem rec {
      inherit system;
      modules = [
        # Default aarch64 SOC System
        "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
        # Minimal configuration
        "${nixpkgs}/nixos/modules/profiles/minimal.nix"
        { config = bootConfig; }
        # Put your configuration here. e.g. ./configuration.nix
      ];
    };
  in {
    inherit system;
    # Run nix build .#images.orangePiZero2 to build image.
    images = {
      orangePiZero2 = nixosSystem.config.system.build.sdImage;
    };
  };
}
Note: Be careful with such firmware - the unstable kernel version may be harmfull

Resources