{ pkgs }: with pkgs;

let
  atf = buildArmTrustedFirmware rec {
    # TODO: change version to "master" or 2018-11-15 next rebuild
    version = "git";
    src = fetchFromGitHub {
      owner = "ARM-software";
      repo = "arm-trusted-firmware";
      rev = "85397ec4574952de8878ee053e01b1a04b34035f";
      sha256 = "1nlj0x5fl6m12pakbk2pffxfsh27w0a10bbv2hbhpr9dcr8llfdx";
    };

    platform = "sun50i_a64";
    filesToInstall = [ "build/${platform}/release/bl31.bin" ];
  };
in (buildUBoot rec {
  defconfig = "pinebook_defconfig";
  extraMeta.platforms = [ "aarch64-linux" ];
  BL31 = "${atf}/bl31.bin";
  filesToInstall = [ "u-boot-sunxi-with-spl.bin" ];
}).overrideAttrs (old: {
  src = fetchFromGitHub {
    owner = "anarsoul";
    repo = "u-boot-pine64";
    rev = "54dd89fefcf4b6b70351d73bad291dc102b8317c";
    sha256 = "14rq8jn5fvrx4v5iqaf34a5ix9k9jy7qpxiqf4n191vpp9qf7xaz";
  };
})