artiq-fast: build gateware from a self-contained separate source derivation #23
@ -6,6 +6,7 @@
|
|||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
version = import ./pkgs/artiq-version.nix (with pkgs; { inherit stdenv fetchgit git; });
|
||||||
artiqSrc = import ./pkgs/artiq-src.nix { fetchgit = pkgs.fetchgit; };
|
artiqSrc = import ./pkgs/artiq-src.nix { fetchgit = pkgs.fetchgit; };
|
||||||
artiqpkgs = import ./default.nix { inherit pkgs; };
|
artiqpkgs = import ./default.nix { inherit pkgs; };
|
||||||
fetchcargo = import ./fetchcargo.nix {
|
fetchcargo = import ./fetchcargo.nix {
|
||||||
@ -41,59 +42,112 @@ let
|
|||||||
cp -R * $out/registry
|
cp -R * $out/registry
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
in
|
in
|
||||||
{ target
|
{ target
|
||||||
, variant
|
, variant
|
||||||
, src ? null
|
, src ? null
|
||||||
, buildCommand ? "python -m artiq.gateware.targets.${target} -V ${variant}"
|
, buildCommand ? "python -m artiq.gateware.targets.${target} -V ${variant}"
|
||||||
, extraInstallCommands ? ""}:
|
, extraInstallCommands ? ""}:
|
||||||
|
let
|
||||||
# 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}";
|
name = "artiq-board-${target}-${variant}-${version}";
|
||||||
version = import ./pkgs/artiq-version.nix (with pkgs; { inherit stdenv fetchgit git; });
|
installPath = "${pkgs.python3Packages.python.sitePackages}/artiq/board-support/${target}-${variant}";
|
||||||
inherit src;
|
|
||||||
phases = [ "buildPhase" "installCheckPhase" "installPhase" "checkPhase" ];
|
boardModule =
|
||||||
nativeBuildInputs = [
|
# Board packages are Python modules so that they get added to the ARTIQ Python
|
||||||
vivado
|
# environment, and artiq_flash finds them.
|
||||||
pkgs.gnumake
|
pkgs.python3Packages.toPythonModule (pkgs.stdenv.mkDerivation {
|
||||||
artiqpkgs.cargo
|
name = "${name}-firmware";
|
||||||
artiqpkgs.rustc
|
inherit version src;
|
||||||
artiqpkgs.binutils-or1k
|
phases = [ "buildPhase" "installCheckPhase" "installPhase" "checkPhase" ];
|
||||||
artiqpkgs.llvm-or1k
|
nativeBuildInputs = [
|
||||||
];
|
vivado
|
||||||
buildInputs = [ (pkgs.python3.withPackages(ps: with ps; [ jinja2 numpy artiqpkgs.migen artiqpkgs.microscope artiqpkgs.misoc artiqpkgs.jesd204b artiqpkgs.artiq ])) ];
|
pkgs.gnumake pkgs.which
|
||||||
buildPhase =
|
artiqpkgs.cargo
|
||||||
''
|
artiqpkgs.rustc
|
||||||
export CARGO_HOME=${cargoVendored}
|
artiqpkgs.binutils-or1k
|
||||||
export TARGET_AR=or1k-linux-ar
|
artiqpkgs.llvm-or1k
|
||||||
${buildCommand}
|
];
|
||||||
|
buildInputs = [
|
||||||
|
(pkgs.python3.withPackages(ps: with ps; [ jinja2 numpy artiqpkgs.migen artiqpkgs.microscope artiqpkgs.misoc artiqpkgs.jesd204b artiqpkgs.artiq ]))
|
||||||
|
];
|
||||||
|
buildPhase =
|
||||||
|
''
|
||||||
|
export CARGO_HOME=${cargoVendored}
|
||||||
|
export TARGET_AR=or1k-linux-ar
|
||||||
|
${buildCommand} --no-compile-gateware
|
||||||
|
'';
|
||||||
|
installPhase =
|
||||||
|
''
|
||||||
|
TARGET_DIR=$out/${installPath}
|
||||||
|
mkdir -p $TARGET_DIR $out/src
|
||||||
|
|
||||||
|
cp -ar artiq_${target}/${variant}/gateware $out/src/
|
||||||
|
|
||||||
|
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}
|
||||||
|
'';
|
||||||
|
});
|
||||||
|
|
||||||
|
vivadoInputArchive = pkgs.stdenv.mkDerivation {
|
||||||
|
name = "${name}-vivado-input.nar.base64";
|
||||||
|
buildInputs = [ pkgs.nix ];
|
||||||
|
phases = [ "installPhase" ];
|
||||||
|
installPhase = "nix-store --dump ${boardModule}/src/gateware | base64 -w0 > $out";
|
||||||
|
};
|
||||||
|
|
||||||
|
# Funnelling the source code through a Nix string allows dropping
|
||||||
|
# all dependencies via `unsafeDiscardStringContext`. The gateware
|
||||||
|
# will then be rebuilt only when these contents have changed.
|
||||||
|
pureVivadoInputArchive = builtins.toFile "${name}-vivado-input.nar.base64" (
|
||||||
|
builtins.unsafeDiscardStringContext (
|
||||||
|
builtins.readFile vivadoInputArchive
|
||||||
|
));
|
||||||
|
|
||||||
|
# Depends on just Vivado and the generated Bitstream source
|
||||||
|
vivadoOutput = pkgs.stdenvNoCC.mkDerivation {
|
||||||
|
name = builtins.unsafeDiscardStringContext "${name}-vivado-output";
|
||||||
|
|
||||||
|
unpackPhase = "base64 -d < ${pureVivadoInputArchive} | nix-store --restore gateware";
|
||||||
|
buildInputs = [ vivado pkgs.nix ];
|
||||||
|
buildPhase = ''
|
||||||
|
cd gateware
|
||||||
|
vivado -mode batch -source top.tcl
|
||||||
'';
|
'';
|
||||||
# temporarily disabled because there is currently always at least one Kasli bitstream
|
|
||||||
# that fails timing and blocks the conda channel.
|
installPhase = ''
|
||||||
doCheck = false;
|
TARGET_DIR=$out/${builtins.unsafeDiscardStringContext installPath}
|
||||||
checkPhase = ''
|
mkdir -p $TARGET_DIR
|
||||||
# Search for PCREs in the Vivado output to check for errors
|
|
||||||
check_log() {
|
chmod a+r top.bit
|
||||||
grep -Pe "$1" artiq_${target}/${variant}/gateware/vivado.log && exit 1 || true
|
cp top.bit $TARGET_DIR
|
||||||
}
|
|
||||||
check_log "\d+ constraint not met\."
|
|
||||||
check_log "Timing constraints are not met\."
|
|
||||||
'';
|
'';
|
||||||
installPhase =
|
|
||||||
''
|
# temporarily disabled because there is currently always at least one Kasli bitstream
|
||||||
TARGET_DIR=$out/${pkgs.python3Packages.python.sitePackages}/artiq/board-support/${target}-${variant}
|
# that fails timing and blocks the conda channel.
|
||||||
mkdir -p $TARGET_DIR
|
doCheck = false;
|
||||||
cp artiq_${target}/${variant}/gateware/top.bit $TARGET_DIR
|
checkPhase = ''
|
||||||
if [ -e artiq_${target}/${variant}/software/bootloader/bootloader.bin ]
|
# Search for PCREs in the Vivado output to check for errors
|
||||||
then cp artiq_${target}/${variant}/software/bootloader/bootloader.bin $TARGET_DIR
|
check_log() {
|
||||||
fi
|
set +e
|
||||||
if [ -e artiq_${target}/${variant}/software/runtime ]
|
grep -Pe "$1" vivado.log
|
||||||
then cp artiq_${target}/${variant}/software/runtime/runtime.{elf,fbi} $TARGET_DIR
|
FOUND=$?
|
||||||
else cp artiq_${target}/${variant}/software/satman/satman.{elf,fbi} $TARGET_DIR
|
set -e
|
||||||
fi
|
if [ $FOUND != 1 ]; then
|
||||||
${extraInstallCommands}
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
check_log "\d+ constraint not met\."
|
||||||
|
check_log "Timing constraints are not met\."
|
||||||
'';
|
'';
|
||||||
})
|
};
|
||||||
|
in pkgs.buildEnv rec {
|
||||||
|
inherit name;
|
||||||
|
paths = [ boardModule vivadoOutput ];
|
||||||
|
pathsToLink = [ "/${installPath}" ];
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user