2019-02-14 15:29:42 +08:00
|
|
|
# Install Vivado in /opt and add to /etc/nixos/configuration.nix:
|
|
|
|
# nix.sandboxPaths = ["/opt"];
|
|
|
|
|
2019-04-24 15:23:58 +08:00
|
|
|
{ pkgs }:
|
2019-02-19 22:20:03 +08:00
|
|
|
{ target
|
|
|
|
, variant
|
|
|
|
, buildCommand ? "python -m artiq.gateware.targets.${target} -V ${variant}"
|
|
|
|
, extraInstallCommands ? ""}:
|
2019-02-14 15:29:42 +08:00
|
|
|
|
|
|
|
let
|
|
|
|
fetchcargo = import ./fetchcargo.nix {
|
|
|
|
inherit (pkgs) stdenv cacert git cargo cargo-vendor;
|
|
|
|
};
|
2019-02-14 19:31:46 +08:00
|
|
|
artiqSrc = import ./pkgs/artiq-src.nix { fetchgit = pkgs.fetchgit; };
|
2019-02-14 15:29:42 +08:00
|
|
|
cargoDeps = fetchcargo rec {
|
|
|
|
name = "artiq-firmware-cargo-deps";
|
|
|
|
src = "${artiqSrc}/artiq/firmware";
|
|
|
|
sha256 = "1xzjn9i4rkd9124v2gbdplsgsvp1hlx7czdgc58n316vsnrkbr86";
|
|
|
|
};
|
|
|
|
|
|
|
|
cargoVendored = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "artiq-firmware-cargo-vendored";
|
|
|
|
src = cargoDeps;
|
|
|
|
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
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
buildenv = import ./artiq-dev.nix { inherit pkgs; };
|
|
|
|
|
2019-02-15 23:16:36 +08:00
|
|
|
in pkgs.python3Packages.buildPythonPackage rec {
|
2019-02-15 23:00:03 +08:00
|
|
|
name = "artiq-board-${target}-${variant}-${version}";
|
2019-04-24 15:17:40 +08:00
|
|
|
version = import ./pkgs/artiq-version.nix (with pkgs; { inherit stdenv fetchgit git; });
|
2019-05-28 04:08:36 +08:00
|
|
|
phases = [ "buildPhase" "installCheckPhase" "installPhase" ];
|
2019-02-14 15:29:42 +08:00
|
|
|
buildPhase =
|
|
|
|
''
|
2019-02-19 21:20:57 +08:00
|
|
|
${buildenv}/bin/artiq-dev -c "export CARGO_HOME=${cargoVendored}; ${buildCommand}"
|
2019-02-14 15:29:42 +08:00
|
|
|
'';
|
2019-05-28 04:08:36 +08:00
|
|
|
preCheck = ''
|
|
|
|
# Search for PCREs in the Vivado output to check for errors
|
|
|
|
function check_log() {
|
2019-05-28 04:46:36 +08:00
|
|
|
if [ $(grep -Pe "$1" artiq_${target}/${variant}/gateware/vivado.log) != 1 ]; then
|
2019-05-28 04:08:36 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
check_log "\d+ constraint not met\."
|
|
|
|
check_log "Timing constraints are not met\."
|
|
|
|
'';
|
2019-02-14 15:29:42 +08:00
|
|
|
installPhase =
|
|
|
|
''
|
2019-02-22 23:16:17 +08:00
|
|
|
TARGET_DIR=$out/${pkgs.python3Packages.python.sitePackages}/artiq/board-support/${target}-${variant}
|
2019-02-14 15:29:42 +08:00
|
|
|
mkdir -p $TARGET_DIR
|
|
|
|
cp artiq_${target}/${variant}/gateware/top.bit $TARGET_DIR
|
|
|
|
cp artiq_${target}/${variant}/software/bootloader/bootloader.bin $TARGET_DIR
|
2019-02-19 22:14:10 +08:00
|
|
|
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
|
2019-02-19 22:20:03 +08:00
|
|
|
${extraInstallCommands}
|
2019-02-14 15:29:42 +08:00
|
|
|
'';
|
|
|
|
}
|