From 1c103ccb62ffcffb9a4a9659a80166d75a3f63a1 Mon Sep 17 00:00:00 2001 From: Stephan Maka Date: Sun, 20 Dec 2020 19:59:56 +0100 Subject: [PATCH 1/5] artiq-fast: move new artiq-board.nix to artiq-full/ --- artiq-fast/artiq-board-legacy.nix | 101 ---------------- artiq-fast/artiq-board.nix | 185 ++++++++--------------------- artiq-fast/default.nix | 6 +- artiq-full.nix | 5 +- artiq-full/artiq-board.nix | 190 ++++++++++++++++++++++++++++++ 5 files changed, 242 insertions(+), 245 deletions(-) delete mode 100644 artiq-fast/artiq-board-legacy.nix create mode 100644 artiq-full/artiq-board.nix diff --git a/artiq-fast/artiq-board-legacy.nix b/artiq-fast/artiq-board-legacy.nix deleted file mode 100644 index ba1c788..0000000 --- a/artiq-fast/artiq-board-legacy.nix +++ /dev/null @@ -1,101 +0,0 @@ -# Install Vivado in /opt and add to /etc/nixos/configuration.nix: -# nix.sandboxPaths = ["/opt"]; - -{ pkgs -, vivado ? import ./vivado.nix { inherit pkgs; } -}: - -let - artiqSrc = import ./pkgs/artiq-src.nix { fetchgit = pkgs.fetchgit; }; - artiqpkgs = import ./default.nix { inherit pkgs; }; - fetchcargo = import ./fetchcargo.nix { - inherit (pkgs) stdenv cacert git; - inherit (artiqpkgs) cargo cargo-vendor; - }; - cargoDeps = fetchcargo rec { - name = "artiq-firmware-cargo-deps"; - src = "${artiqSrc}/artiq/firmware"; - sha256 = (import "${artiqSrc}/artiq/firmware/cargosha256.nix"); - }; - - 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 - ''; - }; - -in -{ target -, variant -, 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; }); - inherit src; - phases = [ "buildPhase" "installCheckPhase" "installPhase" "checkPhase" ]; - nativeBuildInputs = [ - vivado - pkgs.gnumake - artiqpkgs.cargo - artiqpkgs.rustc - artiqpkgs.binutils-or1k - artiqpkgs.llvm-or1k - ]; - 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} - ''; - # temporarily disabled because there is currently always at least one Kasli bitstream - # that fails timing and blocks the conda channel. - doCheck = false; - 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; -}) diff --git a/artiq-fast/artiq-board.nix b/artiq-fast/artiq-board.nix index 006f144..ba1c788 100644 --- a/artiq-fast/artiq-board.nix +++ b/artiq-fast/artiq-board.nix @@ -6,7 +6,6 @@ }: let - version = import ./pkgs/artiq-version.nix (with pkgs; { inherit stdenv fetchgit git; }); artiqSrc = import ./pkgs/artiq-src.nix { fetchgit = pkgs.fetchgit; }; artiqpkgs = import ./default.nix { inherit pkgs; }; fetchcargo = import ./fetchcargo.nix { @@ -42,149 +41,61 @@ let cp -R * $out/registry ''; }; + in { target , variant , src ? null , buildCommand ? "python -m artiq.gateware.targets.${target} -V ${variant}" , 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}"; - installPath = "${pkgs.python3Packages.python.sitePackages}/artiq/board-support/${target}-${variant}"; - - boardModule = - # Board packages are Python modules so that they get added to the ARTIQ Python - # environment, and artiq_flash finds them. - pkgs.stdenv.mkDerivation { - name = "${name}-firmware"; - inherit version src; - phases = [ "buildPhase" "installCheckPhase" "installPhase" "checkPhase" ]; - nativeBuildInputs = [ - pkgs.gnumake pkgs.which - artiqpkgs.cargo - artiqpkgs.rustc - artiqpkgs.binutils-or1k - artiqpkgs.llvm-or1k - ]; - 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 --gateware-identifier-str=unprogrammed - ''; - 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} - ''; - # don't mangle ELF files as they are not for NixOS - dontFixup = true; - }; - - identifierStr = "${version};${variant}"; - identifiers = import ( - pkgs.runCommandLocal "${name}-identifiers.nix" { - buildInputs = [ pkgs.python3 ]; - } ''python ${./generate-identifier.py} "${identifierStr}" > $out'' - ); - - 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 - vivadoCheckpoint = pkgs.stdenvNoCC.mkDerivation { - name = builtins.unsafeDiscardStringContext "${name}-vivado-checkpoint"; - - unpackPhase = "base64 -d < ${pureVivadoInputArchive} | nix-store --restore gateware"; - buildInputs = [ vivado pkgs.nix ]; - buildPhase = '' - cd gateware - vivado -mode batch -source top_route.tcl + version = import ./pkgs/artiq-version.nix (with pkgs; { inherit stdenv fetchgit git; }); + inherit src; + phases = [ "buildPhase" "installCheckPhase" "installPhase" "checkPhase" ]; + nativeBuildInputs = [ + vivado + pkgs.gnumake + artiqpkgs.cargo + artiqpkgs.rustc + artiqpkgs.binutils-or1k + artiqpkgs.llvm-or1k + ]; + 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} ''; - - installPhase = '' - mkdir -p $out - - chmod a+r top_route.dcp - cp top_route.dcp $out - cp top_bitstream.tcl $out + # temporarily disabled because there is currently always at least one Kasli bitstream + # that fails timing and blocks the conda channel. + doCheck = false; + 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\." ''; - }; - - vivadoOutput = pkgs.stdenvNoCC.mkDerivation { - name = builtins.unsafeDiscardStringContext "${name}-vivado-output"; - src = vivadoCheckpoint; - buildInputs = [ vivado ]; - buildPhase = - '' - cat >top.tcl <} $out/fast + cp ${./artiq-full}/artiq-board.nix $out cp ${./artiq-full}/conda-artiq-board.nix $out cp ${./artiq-full}/extras.nix $out cp ${./artiq-full}/*.patch $out @@ -104,8 +105,8 @@ let vivado = import ./fast/vivado.nix { inherit pkgs; }; artiq-board-import = if pkgs.lib.strings.versionAtLeast artiq-fast.artiq.version "6.0" - then ./fast/artiq-board.nix - else ./fast/artiq-board-legacy.nix; + then ./artiq-board.nix + else ./fast/artiq-board.nix; artiq-board = import artiq-board-import { inherit pkgs vivado; }; conda-artiq-board = import ./conda-artiq-board.nix { inherit pkgs; }; src = pkgs.fetchgit { diff --git a/artiq-full/artiq-board.nix b/artiq-full/artiq-board.nix new file mode 100644 index 0000000..006f144 --- /dev/null +++ b/artiq-full/artiq-board.nix @@ -0,0 +1,190 @@ +# Install Vivado in /opt and add to /etc/nixos/configuration.nix: +# nix.sandboxPaths = ["/opt"]; + +{ pkgs +, vivado ? import ./vivado.nix { inherit pkgs; } +}: + +let + version = import ./pkgs/artiq-version.nix (with pkgs; { inherit stdenv fetchgit git; }); + artiqSrc = import ./pkgs/artiq-src.nix { fetchgit = pkgs.fetchgit; }; + artiqpkgs = import ./default.nix { inherit pkgs; }; + fetchcargo = import ./fetchcargo.nix { + inherit (pkgs) stdenv cacert git; + inherit (artiqpkgs) cargo cargo-vendor; + }; + cargoDeps = fetchcargo rec { + name = "artiq-firmware-cargo-deps"; + src = "${artiqSrc}/artiq/firmware"; + sha256 = (import "${artiqSrc}/artiq/firmware/cargosha256.nix"); + }; + + 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 + ''; + }; +in +{ target +, variant +, src ? null +, buildCommand ? "python -m artiq.gateware.targets.${target} -V ${variant}" +, extraInstallCommands ? ""}: +let + name = "artiq-board-${target}-${variant}-${version}"; + installPath = "${pkgs.python3Packages.python.sitePackages}/artiq/board-support/${target}-${variant}"; + + boardModule = + # Board packages are Python modules so that they get added to the ARTIQ Python + # environment, and artiq_flash finds them. + pkgs.stdenv.mkDerivation { + name = "${name}-firmware"; + inherit version src; + phases = [ "buildPhase" "installCheckPhase" "installPhase" "checkPhase" ]; + nativeBuildInputs = [ + pkgs.gnumake pkgs.which + artiqpkgs.cargo + artiqpkgs.rustc + artiqpkgs.binutils-or1k + artiqpkgs.llvm-or1k + ]; + 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 --gateware-identifier-str=unprogrammed + ''; + 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} + ''; + # don't mangle ELF files as they are not for NixOS + dontFixup = true; + }; + + identifierStr = "${version};${variant}"; + identifiers = import ( + pkgs.runCommandLocal "${name}-identifiers.nix" { + buildInputs = [ pkgs.python3 ]; + } ''python ${./generate-identifier.py} "${identifierStr}" > $out'' + ); + + 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 + vivadoCheckpoint = pkgs.stdenvNoCC.mkDerivation { + name = builtins.unsafeDiscardStringContext "${name}-vivado-checkpoint"; + + unpackPhase = "base64 -d < ${pureVivadoInputArchive} | nix-store --restore gateware"; + buildInputs = [ vivado pkgs.nix ]; + buildPhase = '' + cd gateware + vivado -mode batch -source top_route.tcl + ''; + + installPhase = '' + mkdir -p $out + + chmod a+r top_route.dcp + cp top_route.dcp $out + cp top_bitstream.tcl $out + ''; + }; + + vivadoOutput = pkgs.stdenvNoCC.mkDerivation { + name = builtins.unsafeDiscardStringContext "${name}-vivado-output"; + src = vivadoCheckpoint; + buildInputs = [ vivado ]; + buildPhase = + '' + cat >top.tcl < Date: Tue, 22 Dec 2020 01:21:43 +0100 Subject: [PATCH 2/5] artiq-full: fix artiq-board paths --- artiq-full.nix | 1 + artiq-full/artiq-board.nix | 10 +++++----- {artiq-fast => artiq-full}/generate-identifier.py | 0 3 files changed, 6 insertions(+), 5 deletions(-) rename {artiq-fast => artiq-full}/generate-identifier.py (100%) diff --git a/artiq-full.nix b/artiq-full.nix index fb4aca5..3f32f02 100644 --- a/artiq-full.nix +++ b/artiq-full.nix @@ -9,6 +9,7 @@ let cp -a ${} $out/fast cp ${./artiq-full}/artiq-board.nix $out + cp ${./artiq-full}/generate-identifier.py $out cp ${./artiq-full}/conda-artiq-board.nix $out cp ${./artiq-full}/extras.nix $out cp ${./artiq-full}/*.patch $out diff --git a/artiq-full/artiq-board.nix b/artiq-full/artiq-board.nix index 006f144..8cbe0e5 100644 --- a/artiq-full/artiq-board.nix +++ b/artiq-full/artiq-board.nix @@ -2,14 +2,14 @@ # nix.sandboxPaths = ["/opt"]; { pkgs -, vivado ? import ./vivado.nix { inherit pkgs; } +, vivado ? import ./fast/vivado.nix { inherit pkgs; } }: let - version = import ./pkgs/artiq-version.nix (with pkgs; { inherit stdenv fetchgit git; }); - artiqSrc = import ./pkgs/artiq-src.nix { fetchgit = pkgs.fetchgit; }; - artiqpkgs = import ./default.nix { inherit pkgs; }; - fetchcargo = import ./fetchcargo.nix { + version = import ./fast/pkgs/artiq-version.nix (with pkgs; { inherit stdenv fetchgit git; }); + artiqSrc = import ./fast/pkgs/artiq-src.nix { fetchgit = pkgs.fetchgit; }; + artiqpkgs = import ./fast/default.nix { inherit pkgs; }; + fetchcargo = import ./fast/fetchcargo.nix { inherit (pkgs) stdenv cacert git; inherit (artiqpkgs) cargo cargo-vendor; }; diff --git a/artiq-fast/generate-identifier.py b/artiq-full/generate-identifier.py similarity index 100% rename from artiq-fast/generate-identifier.py rename to artiq-full/generate-identifier.py -- 2.42.0 From 0cf2def0709c502cb2ec0800f2f1521835dbe4eb Mon Sep 17 00:00:00 2001 From: Stephan Maka Date: Tue, 22 Dec 2020 01:22:16 +0100 Subject: [PATCH 3/5] artiq-board: move software build into separate derivation --- artiq-full/artiq-board.nix | 63 +++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/artiq-full/artiq-board.nix b/artiq-full/artiq-board.nix index 8cbe0e5..83b77ef 100644 --- a/artiq-full/artiq-board.nix +++ b/artiq-full/artiq-board.nix @@ -50,44 +50,65 @@ in , extraInstallCommands ? ""}: let name = "artiq-board-${target}-${variant}-${version}"; - installPath = "${pkgs.python3Packages.python.sitePackages}/artiq/board-support/${target}-${variant}"; + installPath = builtins.unsafeDiscardStringContext "${pkgs.python3Packages.python.sitePackages}/artiq/board-support/${target}-${variant}"; + pythonEnv = pkgs.python3.withPackages (ps: with ps; [ + jinja2 numpy artiqpkgs.migen artiqpkgs.microscope artiqpkgs.misoc artiqpkgs.jesd204b artiqpkgs.artiq + ]); - boardModule = - # Board packages are Python modules so that they get added to the ARTIQ Python - # environment, and artiq_flash finds them. + generatedSources = pkgs.stdenv.mkDerivation { - name = "${name}-firmware"; + name = "${name}-src"; inherit version src; phases = [ "buildPhase" "installCheckPhase" "installPhase" "checkPhase" ]; + buildInputs = [ pythonEnv ]; + buildPhase = + '' + ${buildCommand} --no-compile-software --no-compile-gateware --gateware-identifier-str=unprogrammed + ''; + installPhase = + '' + mkdir -p $out + cp -ar artiq_${target}/${variant}/{gateware,software} $out + substituteInPlace $out/software/Makefile \ + --replace /build/artiq_${target}/${variant}/software/ "" + ''; + }; + # Board packages are Python modules so that they get added to the ARTIQ Python + # environment, and artiq_flash finds them. + software = + pkgs.stdenv.mkDerivation { + name = "${name}-software"; + src = generatedSources; nativeBuildInputs = [ - pkgs.gnumake pkgs.which + pkgs.gnumake pkgs.which pythonEnv artiqpkgs.cargo artiqpkgs.rustc artiqpkgs.binutils-or1k artiqpkgs.llvm-or1k ]; - 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 --gateware-identifier-str=unprogrammed + + for PKG in software/{libunwind,libm,libprintf,ksupport,bootloader,runtime,satman} ; do + [ -e $PKG/Makefile ] && make -C $PKG BUILDINC_DIRECTORY=`pwd`/software/include + done + echo Ok + # TODO: https://github.com/m-labs/misoc/pull/104 + # make -C software BUILDINC_DIRECTORY=`pwd`/software/include ''; installPhase = '' TARGET_DIR=$out/${installPath} - mkdir -p $TARGET_DIR $out/src + mkdir -p $TARGET_DIR - 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 + if [ -e software/bootloader/bootloader.bin ] + then cp 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 + if [ -e software/runtime ] + then cp software/runtime/runtime.{elf,fbi} $TARGET_DIR + else cp software/satman/satman.{elf,fbi} $TARGET_DIR fi ${extraInstallCommands} ''; @@ -106,7 +127,7 @@ let name = "${name}-vivado-input.nar.base64"; buildInputs = [ pkgs.nix ]; phases = [ "installPhase" ]; - installPhase = "nix-store --dump ${boardModule}/src/gateware | base64 -w0 > $out"; + installPhase = "nix-store --dump ${generatedSources}/gateware | base64 -w0 > $out"; }; # Funnelling the source code through a Nix string allows dropping @@ -157,7 +178,7 @@ let vivado -mode batch -source top.tcl ''; installPhase = '' - TARGET_DIR=$out/${builtins.unsafeDiscardStringContext installPath} + TARGET_DIR=$out/${installPath} mkdir -p $TARGET_DIR chmod a+r top.bit cp top.bit $TARGET_DIR/ @@ -185,6 +206,6 @@ in pkgs.python3Packages.toPythonModule ( pkgs.buildEnv rec { inherit name; - paths = [ boardModule vivadoOutput ]; + paths = [ software vivadoOutput ]; pathsToLink = [ "/${installPath}" ]; }) -- 2.42.0 From 2f4b0635135dd55591a79c289c08e93a91bbb8a7 Mon Sep 17 00:00:00 2001 From: Stephan Maka Date: Wed, 23 Dec 2020 15:28:51 +0100 Subject: [PATCH 4/5] artiq-board: use new misoc top-level Makefile for software build --- artiq-full/artiq-board.nix | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/artiq-full/artiq-board.nix b/artiq-full/artiq-board.nix index 83b77ef..2f9f015 100644 --- a/artiq-full/artiq-board.nix +++ b/artiq-full/artiq-board.nix @@ -91,12 +91,7 @@ let export CARGO_HOME=${cargoVendored} export TARGET_AR=or1k-linux-ar - for PKG in software/{libunwind,libm,libprintf,ksupport,bootloader,runtime,satman} ; do - [ -e $PKG/Makefile ] && make -C $PKG BUILDINC_DIRECTORY=`pwd`/software/include - done - echo Ok - # TODO: https://github.com/m-labs/misoc/pull/104 - # make -C software BUILDINC_DIRECTORY=`pwd`/software/include + make BUILDINC_DIRECTORY=`pwd`/include ''; installPhase = '' -- 2.42.0 From e189ee4c8f7481e386929d080c0a1a8ed3e5f707 Mon Sep 17 00:00:00 2001 From: Stephan Maka Date: Wed, 23 Dec 2020 15:30:38 +0100 Subject: [PATCH 5/5] artiq-board: refactor vivado derivations into discardContextFromPath, tighten software src --- artiq-full/artiq-board.nix | 58 +++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/artiq-full/artiq-board.nix b/artiq-full/artiq-board.nix index 2f9f015..90b2d24 100644 --- a/artiq-full/artiq-board.nix +++ b/artiq-full/artiq-board.nix @@ -42,6 +42,31 @@ let cp -R * $out/registry ''; }; + + # Funnelling the source code through a Nix string allows dropping + # all dependencies via `unsafeDiscardStringContext`. + discardContextFromPath = { name, src }: + let + packed = pkgs.stdenv.mkDerivation { + name = "${name}.nar.base64"; + buildInputs = [ pkgs.nix ]; + phases = [ "installPhase" ]; + installPhase = "nix-store --dump ${src} | base64 -w0 > $out"; + }; + unpacked = archive: + pkgs.stdenvNoCC.mkDerivation { + name = builtins.unsafeDiscardStringContext name; + + phases = [ "installPhase" ]; + buildInputs = [ pkgs.nix ]; + installPhase = "base64 -d < ${archive} | nix-store --restore $out"; + }; + in + unpacked ( + builtins.toFile "${builtins.unsafeDiscardStringContext name}.nar.base64" ( + builtins.unsafeDiscardStringContext ( + builtins.readFile packed + ))) ; in { target , variant @@ -78,7 +103,7 @@ let software = pkgs.stdenv.mkDerivation { name = "${name}-software"; - src = generatedSources; + src = "${generatedSources}/software"; nativeBuildInputs = [ pkgs.gnumake pkgs.which pythonEnv artiqpkgs.cargo @@ -98,12 +123,12 @@ let TARGET_DIR=$out/${installPath} mkdir -p $TARGET_DIR - if [ -e software/bootloader/bootloader.bin ] - then cp software/bootloader/bootloader.bin $TARGET_DIR + if [ -e bootloader/bootloader.bin ] + then cp bootloader/bootloader.bin $TARGET_DIR fi - if [ -e software/runtime ] - then cp software/runtime/runtime.{elf,fbi} $TARGET_DIR - else cp software/satman/satman.{elf,fbi} $TARGET_DIR + if [ -e runtime ] + then cp runtime/runtime.{elf,fbi} $TARGET_DIR + else cp satman/satman.{elf,fbi} $TARGET_DIR fi ${extraInstallCommands} ''; @@ -118,29 +143,16 @@ let } ''python ${./generate-identifier.py} "${identifierStr}" > $out'' ); - vivadoInputArchive = pkgs.stdenv.mkDerivation { - name = "${name}-vivado-input.nar.base64"; - buildInputs = [ pkgs.nix ]; - phases = [ "installPhase" ]; - installPhase = "nix-store --dump ${generatedSources}/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 vivadoCheckpoint = pkgs.stdenvNoCC.mkDerivation { name = builtins.unsafeDiscardStringContext "${name}-vivado-checkpoint"; - unpackPhase = "base64 -d < ${pureVivadoInputArchive} | nix-store --restore gateware"; + src = discardContextFromPath { + name = "${name}-gateware"; + src = "${generatedSources}/gateware"; + }; buildInputs = [ vivado pkgs.nix ]; buildPhase = '' - cd gateware vivado -mode batch -source top_route.tcl ''; -- 2.42.0