2019-02-14 15:29:42 +08:00
|
|
|
# Install Vivado in /opt and add to /etc/nixos/configuration.nix:
|
|
|
|
# nix.sandboxPaths = ["/opt"];
|
|
|
|
|
2020-06-18 04:39:41 +08:00
|
|
|
{ pkgs
|
2021-09-12 18:17:47 +08:00
|
|
|
, rustPlatform
|
2020-06-18 04:39:41 +08:00
|
|
|
, vivado ? import ./vivado.nix { inherit pkgs; }
|
|
|
|
}:
|
2019-02-14 15:29:42 +08:00
|
|
|
|
|
|
|
let
|
2019-07-03 20:26:30 +08:00
|
|
|
artiqSrc = import ./pkgs/artiq-src.nix { fetchgit = pkgs.fetchgit; };
|
2020-04-04 13:02:18 +08:00
|
|
|
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;
|
2019-02-14 15:29:42 +08:00
|
|
|
};
|
2021-09-12 18:17:47 +08:00
|
|
|
cargoDeps-legacy = fetchcargo-legacy rec {
|
2019-02-14 15:29:42 +08:00
|
|
|
name = "artiq-firmware-cargo-deps";
|
|
|
|
src = "${artiqSrc}/artiq/firmware";
|
2019-11-01 10:28:53 +08:00
|
|
|
sha256 = (import "${artiqSrc}/artiq/firmware/cargosha256.nix");
|
2019-02-14 15:29:42 +08:00
|
|
|
};
|
2021-09-12 18:17:47 +08:00
|
|
|
cargoVendored-legacy = pkgs.stdenv.mkDerivation {
|
2019-02-14 15:29:42 +08:00
|
|
|
name = "artiq-firmware-cargo-vendored";
|
2021-09-12 18:17:47 +08:00
|
|
|
src = cargoDeps-legacy;
|
2019-02-14 15:29:42 +08:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
};
|
2020-12-21 02:59:56 +08:00
|
|
|
|
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";
|
|
|
|
|
2020-06-18 04:39:41 +08:00
|
|
|
in
|
|
|
|
{ target
|
|
|
|
, variant
|
2020-07-12 23:20:31 +08:00
|
|
|
, src ? null
|
2020-06-18 04:39:41 +08:00
|
|
|
, buildCommand ? "python -m artiq.gateware.targets.${target} -V ${variant}"
|
2021-01-28 03:06:05 +08:00
|
|
|
, extraInstallCommands ? ""
|
|
|
|
, ... }:
|
2020-12-02 17:22:54 +08:00
|
|
|
|
2020-12-21 02:59:56 +08:00
|
|
|
# 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
|
|
|
|
]);
|
2020-12-21 02:59:56 +08:00
|
|
|
buildInputs = [ (pkgs.python3.withPackages(ps: with ps; [ jinja2 numpy artiqpkgs.migen artiqpkgs.microscope artiqpkgs.misoc artiqpkgs.jesd204b artiqpkgs.artiq ])) ];
|
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}
|
|
|
|
''
|
|
|
|
else
|
|
|
|
''
|
|
|
|
export CARGO_HOME=${cargoVendored-legacy}
|
|
|
|
export TARGET_AR=or1k-linux-ar
|
|
|
|
${buildCommand}
|
|
|
|
'';
|
2020-12-21 02:59:56 +08:00
|
|
|
# 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;
|
2020-12-21 02:59:56 +08:00
|
|
|
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\."
|
2020-12-02 17:22:54 +08:00
|
|
|
'';
|
2020-12-21 02:59:56 +08:00
|
|
|
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}
|
2019-02-14 15:29:42 +08:00
|
|
|
'';
|
2020-12-21 02:59:56 +08:00
|
|
|
# don't mangle ELF files as they are not for NixOS
|
|
|
|
dontFixup = true;
|
|
|
|
})
|