1
0
Fork 0
nix-scripts/artiq-fast/artiq-board.nix

143 lines
4.7 KiB
Nix
Raw Normal View History

# Install Vivado in /opt and add to /etc/nixos/configuration.nix:
# nix.sandboxPaths = ["/opt"];
{ pkgs
2021-09-12 18:17:47 +08:00
, rustPlatform
, vivado ? import ./vivado.nix { inherit pkgs; }
}:
let
artiqSrc = import ./pkgs/artiq-src.nix { fetchgit = pkgs.fetchgit; };
artiqpkgs = import ./default.nix { inherit pkgs; };
2021-09-12 18:17:47 +08:00
fetchcargo-legacy = import ./fetchcargo-legacy.nix {
2021-03-10 05:48:37 +08:00
inherit (pkgs) stdenv lib cacert git;
2021-09-12 18:17:47 +08:00
cargo = artiqpkgs.cargo-legacy;
cargo-vendor = artiqpkgs.cargo-vendor-legacy;
};
2021-09-12 18:17:47 +08:00
cargoDeps-legacy = fetchcargo-legacy rec {
name = "artiq-firmware-cargo-deps";
src = "${artiqSrc}/artiq/firmware";
2019-11-01 10:28:53 +08:00
sha256 = (import "${artiqSrc}/artiq/firmware/cargosha256.nix");
};
2021-09-12 18:17:47 +08:00
cargoVendored-legacy = pkgs.stdenv.mkDerivation {
name = "artiq-firmware-cargo-vendored";
2021-09-12 18:17:47 +08:00
src = cargoDeps-legacy;
phases = [ "unpackPhase" "installPhase" ];
installPhase =
''
mkdir -p $out/registry
cat << EOF > $out/config
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = "vendored-sources"
[source."https://github.com/m-labs/libfringe"]
git = "https://github.com/m-labs/libfringe"
rev = "b8a6d8f"
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "$out/registry"
EOF
cp -R * $out/registry
'';
};
2021-09-12 18:17:47 +08:00
cargoDeps = rustPlatform.fetchCargoTarball {
name = "artiq-firmware-cargo-deps";
src = "${artiqSrc}/artiq/firmware";
sha256 = "0hh9x34gs81a8g15abka6a0z1wlankra13rbap5j7ba2r8cz4962";
};
cargo-xbuild = rustPlatform.buildRustPackage rec {
pname = "cargo-xbuild";
version = "0.6.5";
src = pkgs.fetchFromGitHub {
owner = "rust-osdev";
repo = pname;
rev = "v${version}";
sha256 = "18djvygq9v8rmfchvi2hfj0i6fhn36m716vqndqnj56fiqviwxvf";
};
cargoSha256 = "13sj9j9kl6js75h9xq0yidxy63vixxm9q3f8jil6ymarml5wkhx8";
};
artiq7 = pkgs.lib.strings.versionAtLeast artiqpkgs.artiq.version "7.0";
in
{ target
, variant
2020-07-12 23:20:31 +08:00
, src ? null
, buildCommand ? "python -m artiq.gateware.targets.${target} -V ${variant}"
, extraInstallCommands ? ""
, ... }:
# Board packages are Python modules so that they get added to the ARTIQ Python
# environment, and artiq_flash finds them.
pkgs.python3Packages.toPythonModule (pkgs.stdenv.mkDerivation rec {
name = "artiq-board-${target}-${variant}-${version}";
version = import ./pkgs/artiq-version.nix (with pkgs; { inherit stdenv fetchgit git; });
2021-09-12 18:17:47 +08:00
phases = [ "buildPhase" "checkPhase" "installPhase" ];
nativeBuildInputs = [ vivado pkgs.gnumake ]
++ (if artiq7
then [
rustPlatform.rust.rustc
rustPlatform.rust.cargo
pkgs.llvmPackages_11.clang-unwrapped
pkgs.llvm_11
pkgs.lld_11
rustPlatform.cargoSetupHook
cargo-xbuild
] else [
artiqpkgs.cargo-legacy
artiqpkgs.rustc-legacy
artiqpkgs.binutils-or1k
artiqpkgs.llvm-or1k
]);
2021-09-12 19:06:29 +08:00
buildInputs = [ (pkgs.python3.withPackages(ps: with ps; [ artiqpkgs.migen artiqpkgs.microscope artiqpkgs.misoc artiqpkgs.jesd204b artiqpkgs.artiq ] ++ (pkgs.lib.optional artiq7 jsonschema))) ];
2021-09-12 18:17:47 +08:00
buildPhase = if artiq7
then
''
ARTIQ_PATH=`python -c "import artiq; print(artiq.__path__[0])"`
ln -s $ARTIQ_PATH/firmware/Cargo.lock .
cargoDeps=${cargoDeps}
cargoSetupPostUnpackHook
cargoSetupPostPatchHook
export TARGET_AR=llvm-ar
${buildCommand}
''
2021-09-12 18:17:47 +08:00
else
''
export CARGO_HOME=${cargoVendored-legacy}
export TARGET_AR=or1k-linux-ar
${buildCommand}
'';
# temporarily disabled because there is currently always at least one Kasli bitstream
# that fails timing and blocks the conda channel.
2021-09-12 18:17:47 +08:00
doCheck = artiq7;
checkPhase = ''
# Search for PCREs in the Vivado output to check for errors
check_log() {
grep -Pe "$1" artiq_${target}/${variant}/gateware/vivado.log && exit 1 || true
}
check_log "\d+ constraint not met\."
check_log "Timing constraints are not met\."
'';
installPhase =
''
TARGET_DIR=$out/${pkgs.python3Packages.python.sitePackages}/artiq/board-support/${target}-${variant}
mkdir -p $TARGET_DIR
cp artiq_${target}/${variant}/gateware/top.bit $TARGET_DIR
if [ -e artiq_${target}/${variant}/software/bootloader/bootloader.bin ]
then cp artiq_${target}/${variant}/software/bootloader/bootloader.bin $TARGET_DIR
fi
if [ -e artiq_${target}/${variant}/software/runtime ]
then cp artiq_${target}/${variant}/software/runtime/runtime.{elf,fbi} $TARGET_DIR
else cp artiq_${target}/${variant}/software/satman/satman.{elf,fbi} $TARGET_DIR
fi
${extraInstallCommands}
'';
# don't mangle ELF files as they are not for NixOS
dontFixup = true;
})