Jump to content

NixOS on ARM/Banana Pi BPI-M5: Difference between revisions

From Official NixOS Wiki
Pigs (talk | contribs)
m Add category
Replaced the outdated instructions with currently working ones. The issue was the gcc-arm-embedded package not providing the needed cross compiler anymore, along with shebang issues. This is my first time editing the wiki, so please check everything extra hard for issues.
 
Line 1: Line 1:
{{ARM/breadcrumb}}
{{ARM/breadcrumb}}


== Status ==
'''Note:''' To build an image for a BPI-M5 you will need to use flakes. If you don't know them or need to set them up for your system, follow [[Flakes|the Flakes Wiki page]].


Work in progress
== Setting up the Flake for cross-compilation ==
Create a folder with a name of your choosing. In it create a flake.nix file with the following contents:<syntaxhighlight lang="nix">
{
  description = "Banana Pi M5 NixOS Build Environment";


== Building Amlogic-compatible U-Boot ==
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };
 
  outputs = { nixpkgs, ... }: let
    system = "x86_64-linux";
    pkgs = import nixpkgs { inherit system; };
 
    # Expose the correct AArch64 cross-compilation package set
    crossPkgs = import nixpkgs {
      inherit system;
      crossSystem = {
        config = "aarch64-unknown-linux-gnu";
      };
    };
  in {
    devShells.${system}.default = pkgs.mkShell {
      packages = [
        # For patching shebangs in the official build scripts
        pkgs.stdenv
 
        # Provides the 64-bit aarch64-unknown-linux-gnu-gcc
        crossPkgs.buildPackages.gcc
 
        # Retained for Amlogic's 32-bit SCP/BL30 binary generation
        pkgs.gcc-arm-embedded
 
        pkgs.ubootTools
        pkgs.dtc
        pkgs.flex
        pkgs.bison
        pkgs.swig
 
        pkgs.openssl
        pkgs.gnutls
 
        # Resolves the insecure Python 2 dependency
        pkgs.python3
      ];
 
      # Pre-set the build variables expected by Make
      shellHook = ''
        export CROSS_COMPILE="aarch64-unknown-linux-gnu-"
        export ARCH="arm"
      '';
    };
  };
}


</syntaxhighlight>


== Building Amlogic-compatible U-Boot ==
=== Building U-Boot ===
=== Building U-Boot ===
'''Note:''' Do not use the severely outdated [https://github.com/BPI-SINOVOIP/BPI-M5-bsp BPI-M5-bsp] or [https://github.com/Dangku/Amlogic-u-boot Amlogic-u-boot] to build u-boot.
'''Note:''' Do not use the severely outdated [https://github.com/BPI-SINOVOIP/BPI-M5-bsp BPI-M5-bsp] or [https://github.com/Dangku/Amlogic-u-boot Amlogic-u-boot] to build u-boot.


<syntaxhighlight lang="shell-session">
<syntaxhighlight lang="shell-session">
$ nix develop
$ git clone git://git.denx.de/u-boot.git
$ git clone git://git.denx.de/u-boot.git
$ cd u-boot
$ cd u-boot
$ nix-shell -p ubootTools gcc-arm-embedded dtc flex bison python swig
$ make -j$(nproc) bananapi-m5_defconfig
$ make -j$(nproc) ARCH=arm CROSS_COMPILE=aarch64-unknown-linux-gnu- bananapi-m5_defconfig
$ make -j$(nproc)
$ make -j$(nproc) ARCH=arm CROSS_COMPILE=aarch64-unknown-linux-gnu-
$ cd ..
$ cd ..
</syntaxhighlight>
</syntaxhighlight>
Line 24: Line 76:
'''Note:''' The following steps require an AMD64 platform.
'''Note:''' The following steps require an AMD64 platform.


<syntaxhighlight lang="shell-session">
<syntaxhighlight lang="shell-session">$ git clone https://github.com/LibreELEC/amlogic-boot-fip
$ git clone https://github.com/LibreELEC/amlogic-boot-fip
$ cd amlogic-boot-fip
$ cd amlogic-boot-fip
$ mkdir -p output-bananapim5/
$ mkdir -p output-bananapim5/
$ patchShebangs .
$ ./build-fip.sh bananapi-m5 ../u-boot/u-boot.bin output-bananapim5
$ ./build-fip.sh bananapi-m5 ../u-boot/u-boot.bin output-bananapim5
$ hexdump -C -n 32 output-bananapim5/u-boot.bin | grep "40 41 4d 4c"
$ hexdump -C -n 32 output-bananapim5/u-boot.bin | grep "40 41 4d 4c"
$ cd ..
$ cd ..</syntaxhighlight>
</syntaxhighlight>


Verify that the new u-boot.bin contains <code>40 41 4d 4c</code> (<code>@AML</code>) at 0x10 onwards.
Verify that the new u-boot.bin contains <code>40 41 4d 4c</code> (<code>@AML</code>) at 0x10 onwards.
Line 37: Line 88:
== Board-specific installation notes ==
== Board-specific installation notes ==


First follow the [[NixOS_on_ARM#SD_card_images_.28SBCs_and_similar_platforms.29|NixOS_on_ARM instructions to get the SD card image]] and decompress it.
First follow the [[NixOS on ARM/Installation|NixOS_on_ARM instructions to get the SD card image]] and decompress it.


Once the image has been decompressed, the Amlogic U-Boot package needs to be copied to byte 512+ inside the image (replace the image with the name downloaded and decompressed image):
Once the image has been decompressed, the Amlogic U-Boot package needs to be copied to byte 512+ inside the image (replace the image with the name downloaded and decompressed image):


<syntaxhighlight lang="shell-session">
<syntaxhighlight lang="shell-session">$ sudo dd if=amlogic-boot-fip/output-bananapim5/u-boot.bin of=nixos-sd-image-22.11.2620.de5448dab58-aarch64-linux.img conv=fsync,notrunc bs=512 seek=1</syntaxhighlight>
$ sudo dd if=amlogic-boot-fip/output-bananapim5/u-boot.bin of=nixos-sd-image-22.11.2620.de5448dab58-aarch64-linux.img conv=fsync,notrunc bs=512 seek=1
</syntaxhighlight>


Then, copy the image onto the eMMC or sdcard using the [[NixOS_on_ARM#Installation_steps|the installation steps]].
Then, copy the image onto the eMMC or sdcard using the [[NixOS_on_ARM#Installation_steps|the installation steps]].

Latest revision as of 15:47, 4 June 2026

Note: To build an image for a BPI-M5 you will need to use flakes. If you don't know them or need to set them up for your system, follow the Flakes Wiki page.

Setting up the Flake for cross-compilation

Create a folder with a name of your choosing. In it create a flake.nix file with the following contents:

{
  description = "Banana Pi M5 NixOS Build Environment";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };

  outputs = { nixpkgs, ... }: let
    system = "x86_64-linux";
    pkgs = import nixpkgs { inherit system; };

    # Expose the correct AArch64 cross-compilation package set
    crossPkgs = import nixpkgs {
      inherit system;
      crossSystem = {
        config = "aarch64-unknown-linux-gnu";
      };
    };
  in {
    devShells.${system}.default = pkgs.mkShell {
      packages = [
        # For patching shebangs in the official build scripts
        pkgs.stdenv

        # Provides the 64-bit aarch64-unknown-linux-gnu-gcc
        crossPkgs.buildPackages.gcc

        # Retained for Amlogic's 32-bit SCP/BL30 binary generation
        pkgs.gcc-arm-embedded

        pkgs.ubootTools
        pkgs.dtc
        pkgs.flex
        pkgs.bison
        pkgs.swig

        pkgs.openssl
        pkgs.gnutls

        # Resolves the insecure Python 2 dependency
        pkgs.python3
      ];

      # Pre-set the build variables expected by Make
      shellHook = ''
        export CROSS_COMPILE="aarch64-unknown-linux-gnu-"
        export ARCH="arm"
      '';
    };
  };
}

Building Amlogic-compatible U-Boot

Building U-Boot

Note: Do not use the severely outdated BPI-M5-bsp or Amlogic-u-boot to build u-boot.

$ nix develop
$ git clone git://git.denx.de/u-boot.git
$ cd u-boot
$ make -j$(nproc) bananapi-m5_defconfig
$ make -j$(nproc)
$ cd ..

Creating Amlogic Package

Note: The following steps require an AMD64 platform.

$ git clone https://github.com/LibreELEC/amlogic-boot-fip
$ cd amlogic-boot-fip
$ mkdir -p output-bananapim5/
$ patchShebangs .
$ ./build-fip.sh bananapi-m5 ../u-boot/u-boot.bin output-bananapim5
$ hexdump -C -n 32 output-bananapim5/u-boot.bin | grep "40 41 4d 4c"
$ cd ..

Verify that the new u-boot.bin contains 40 41 4d 4c (@AML) at 0x10 onwards.

Board-specific installation notes

First follow the NixOS_on_ARM instructions to get the SD card image and decompress it.

Once the image has been decompressed, the Amlogic U-Boot package needs to be copied to byte 512+ inside the image (replace the image with the name downloaded and decompressed image):

$ sudo dd if=amlogic-boot-fip/output-bananapim5/u-boot.bin of=nixos-sd-image-22.11.2620.de5448dab58-aarch64-linux.img conv=fsync,notrunc bs=512 seek=1

Then, copy the image onto the eMMC or sdcard using the the installation steps.

In order to get a serial console output, it is required to replace ttyAMA0 with ttyAML0 in the /boot/extlinux/extlinux.conf file inside the image. The easiest way is to just mount the respective folder after the image has been flashed on the SD-card

$ sudo mount /dev/sdX /mnt/
$ sudo sed -i 's/ttyAMA0/ttyAML0/g' /mnt/boot/extlinux/extlinux.conf


Resources