From 3f64f000e01a0534b1e0095355dd900b70c870c4 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Fri, 4 Feb 2022 12:30:17 +0800 Subject: [PATCH] add flake --- flake.lock | 218 ++++++++++++++++++++++++++++++++++++++++ flake.nix | 290 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 508 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..294938f --- /dev/null +++ b/flake.lock @@ -0,0 +1,218 @@ +{ + "nodes": { + "artiq": { + "inputs": { + "mozilla-overlay": "mozilla-overlay", + "nixpkgs": "nixpkgs", + "src-migen": "src-migen", + "src-misoc": "src-misoc", + "src-pythonparser": "src-pythonparser", + "src-sipyco": "src-sipyco" + }, + "locked": { + "lastModified": 1643542736, + "narHash": "sha256-SXOAQ2hxwoT+zTrMZCtjlcf/i8phN4AwwCAwUlhufzc=", + "ref": "master", + "rev": "dd3279e50622b5ceb1c24b4d1891f442cc0acce3", + "revCount": 7947, + "type": "git", + "url": "https://github.com/m-labs/artiq.git" + }, + "original": { + "type": "git", + "url": "https://github.com/m-labs/artiq.git" + } + }, + "mozilla-overlay": { + "flake": false, + "locked": { + "lastModified": 1638887313, + "narHash": "sha256-FMYV6rVtvSIfthgC1sK1xugh3y7muoQcvduMdriz4ag=", + "owner": "mozilla", + "repo": "nixpkgs-mozilla", + "rev": "7c1e8b1dd6ed0043fb4ee0b12b815256b0b9de6f", + "type": "github" + }, + "original": { + "owner": "mozilla", + "repo": "nixpkgs-mozilla", + "type": "github" + } + }, + "mozilla-overlay_2": { + "flake": false, + "locked": { + "lastModified": 1638887313, + "narHash": "sha256-FMYV6rVtvSIfthgC1sK1xugh3y7muoQcvduMdriz4ag=", + "owner": "mozilla", + "repo": "nixpkgs-mozilla", + "rev": "7c1e8b1dd6ed0043fb4ee0b12b815256b0b9de6f", + "type": "github" + }, + "original": { + "owner": "mozilla", + "repo": "nixpkgs-mozilla", + "type": "github" + } + }, + "mozilla-overlay_3": { + "flake": false, + "locked": { + "lastModified": 1638887313, + "narHash": "sha256-FMYV6rVtvSIfthgC1sK1xugh3y7muoQcvduMdriz4ag=", + "owner": "mozilla", + "repo": "nixpkgs-mozilla", + "rev": "7c1e8b1dd6ed0043fb4ee0b12b815256b0b9de6f", + "type": "github" + }, + "original": { + "owner": "mozilla", + "repo": "nixpkgs-mozilla", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1642522226, + "narHash": "sha256-m/j9U8KYuwwxjwgRCjmEj8ejftvdMLJ+NGXh/L2I4FU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "610d4ea2750e064bf34b33fa38cb671edd893d3d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-21.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1643247693, + "narHash": "sha256-rmShxIuNjYBz4l83J0J++sug+MURUY1koPCzX4F8hfo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6c4b9f1a2fd761e2d384ef86cff0d208ca27fdca", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-21.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1642961095, + "narHash": "sha256-RLatktZmvwFBOyqdoIk4qdS4OGKB7aKIvvs4ZP2L8D8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "604c44137d97b5111be1ca5c0d97f6e24fbc5c2c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-21.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "artiq": "artiq", + "mozilla-overlay": "mozilla-overlay_2", + "nixpkgs": "nixpkgs_2", + "zynq-rs": "zynq-rs" + } + }, + "src-migen": { + "flake": false, + "locked": { + "lastModified": 1639659493, + "narHash": "sha256-qpVj/yJf4hDDc99XXpVPH4EbLC8aCmEtACn5qNc3DGI=", + "owner": "m-labs", + "repo": "migen", + "rev": "ac703010eaa06ac9b6e32f97c6fa98b15de22b31", + "type": "github" + }, + "original": { + "owner": "m-labs", + "repo": "migen", + "type": "github" + } + }, + "src-misoc": { + "flake": false, + "locked": { + "lastModified": 1641889368, + "narHash": "sha256-0Ai25lry9ju1HxFmfMRNKG8mamBqvw+kvDfpuK8Dtjo=", + "ref": "master", + "rev": "7242dc5a41732135425acc4871487461dfae6c66", + "revCount": 2419, + "submodules": true, + "type": "git", + "url": "https://github.com/m-labs/misoc.git" + }, + "original": { + "submodules": true, + "type": "git", + "url": "https://github.com/m-labs/misoc.git" + } + }, + "src-pythonparser": { + "flake": false, + "locked": { + "lastModified": 1628745371, + "narHash": "sha256-p6TgeeaK4NEmbhimEXp31W8hVRo4DgWmcCoqZ+UdN60=", + "owner": "m-labs", + "repo": "pythonparser", + "rev": "5413ee5c9f8760e95c6acd5d6e88dabb831ad201", + "type": "github" + }, + "original": { + "owner": "m-labs", + "repo": "pythonparser", + "type": "github" + } + }, + "src-sipyco": { + "flake": false, + "locked": { + "lastModified": 1641866796, + "narHash": "sha256-TSH0IgNbi9IcMcBDb2nWRphKlxstbWeATjrGbi6K2m0=", + "owner": "m-labs", + "repo": "sipyco", + "rev": "b04234c49379cd446d4cb3346d4741868d86841a", + "type": "github" + }, + "original": { + "owner": "m-labs", + "repo": "sipyco", + "type": "github" + } + }, + "zynq-rs": { + "inputs": { + "mozilla-overlay": "mozilla-overlay_3", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1643612643, + "narHash": "sha256-I6xEppSuvN3JxyYslg9U9HMoPMZtAhCpKeLZzUq8r0o=", + "ref": "flake_extra_outputs", + "rev": "fe5d5694f4adac605b71fb513696775c58104d77", + "revCount": 597, + "type": "git", + "url": "file:///home/spaqin/m-labs/zynq-rs" + }, + "original": { + "type": "git", + "url": "file:///home/spaqin/m-labs/zynq-rs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b68abd7 --- /dev/null +++ b/flake.nix @@ -0,0 +1,290 @@ +{ + description = "ARTIQ port for Zynq platform"; + + inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-21.11; + inputs.mozilla-overlay = { url = github:mozilla/nixpkgs-mozilla; flake = false; }; + inputs.zynq-rs.url = git+file:///home/spaqin/m-labs/zynq-rs; + inputs.artiq.url = git+https://github.com/m-labs/artiq.git; + + outputs = { self, nixpkgs, mozilla-overlay, zynq-rs, artiq }: + let + pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ (import mozilla-overlay) ]; }; + zynqpkgs = zynq-rs.packages.x86_64-linux; + artiqpkgs = artiq.packages.x86_64-linux; + + rustPlatform = zynq-rs.rustPlatform; + + fastnumbers = pkgs.python3Packages.buildPythonPackage rec { + pname = "fastnumbers"; + version = "2.2.1"; + + src = pkgs.python3Packages.fetchPypi { + inherit pname version; + sha256 = "0j15i54p7nri6hkzn1wal9pxri4pgql01wgjccig6ar0v5jjbvsy"; + }; + }; + + artiq-netboot = pkgs.python3Packages.buildPythonPackage rec { + pname = "artiq-netboot"; + version = "unstable-2020-10-15"; + + src = pkgs.fetchgit { + url = "https://git.m-labs.hk/m-labs/artiq-netboot.git"; + rev = "04f69eb07df73abe4b89fde2c24084f7664f2104"; + sha256 = "0ql4fr8m8gpb2yql8aqsdqsssxb8zqd6l65kl1f6s9845zy7shs9"; + }; + }; + + ramda = pkgs.python3Packages.buildPythonPackage { + pname = "ramda"; + version = "unstable-2019-02-01"; + + src = pkgs.fetchFromGitHub { + owner = "peteut"; + repo = "ramda.py"; + rev = "bd58f8e69d0e9a713d9c1f286a1ac5e5603956b1"; + sha256 = "0qzd5yp9lbaham8p1wiymdjapzbqsli7lvngv24c3z4ybd9jlq9g"; + }; + + nativeBuildInputs = with pkgs.python3Packages; [ pbr ]; + propagatedBuildInputs = with pkgs.python3Packages; [ future fastnumbers ]; + + checkInputs = with pkgs.python3Packages; [ pytest pytest-flake8 ]; + checkPhase = "pytest"; + doCheck = false; + + preBuild = '' + export PBR_VERSION=0.0.1 + ''; + }; + + migen-axi = pkgs.python3Packages.buildPythonPackage { + pname = "migen-axi"; + version = "unstable-2021-09-15"; + + src = pkgs.fetchFromGitHub { + owner = "peteut"; + repo = "migen-axi"; + rev = "9763505ee96acd7572280a2d1233721342dc7c3f"; + sha256 = "15c7g05n183rka66fl1glzp6h7xjlpy1p6k8biry24dangsmxmvg"; + }; + + nativeBuildInputs = with pkgs.python3Packages; [ pbr ]; + propagatedBuildInputs = with pkgs.python3Packages; [ setuptools click numpy toolz jinja2 ramda artiqpkgs.migen artiqpkgs.misoc ]; + + postPatch = '' + substituteInPlace requirements.txt \ + --replace "jinja2==2.11.3" "jinja2" + substituteInPlace requirements.txt \ + --replace "future==0.18.2" "future" + substituteInPlace requirements.txt \ + --replace "ramda==0.5.5" "ramda" + substituteInPlace requirements.txt \ + --replace "colorama==0.4.3" "colorama" + substituteInPlace requirements.txt \ + --replace "toolz==0.10.0" "toolz" + substituteInPlace requirements.txt \ + --replace "pyserial==3.4" "pyserial" + substituteInPlace requirements.txt \ + --replace "markupsafe==1.1.1" "markupsafe" + ''; + + checkInputs = with pkgs.python3Packages; [ pytest pytest-timeout pytest-flake8 ]; + checkPhase = "pytest"; + + preBuild = '' + export PBR_VERSION=0.0.1 + ''; + }; + binutils = { platform, target, zlib }: pkgs.stdenv.mkDerivation rec { + basename = "binutils"; + version = "2.30"; + name = "${basename}-${platform}-${version}"; + src = pkgs.fetchurl { + url = "https://ftp.gnu.org/gnu/binutils/binutils-${version}.tar.bz2"; + sha256 = "028cklfqaab24glva1ks2aqa1zxa6w6xmc8q34zs1sb7h22dxspg"; + }; + configureFlags = + [ "--enable-shared" "--enable-deterministic-archives" "--target=${target}"]; + outputs = [ "out" "info" "man" ]; + depsBuildBuild = [ pkgs.buildPackages.stdenv.cc ]; + buildInputs = [ zlib ]; + enableParallelBuilding = true; + }; + binutils-arm = pkgs.callPackage binutils { platform = "arm"; target = "armv7-unknown-linux-gnueabihf"; }; + + # ======== default.nix + # FSBL configuration supplied by Vivado 2020.1 for these boards: + fsblTargets = ["zc702" "zc706" "zed"]; + sat_variants = [ + # kasli-soc satellite variants + "satellite" + # zc706 satellite variants + "nist_clock_satellite" "nist_qc2_satellite" "acpki_nist_clock_satellite" "acpki_nist_qc2_satellite" + "nist_clock_satellite_100mhz" "nist_qc2_satellite_100mhz" "acpki_nist_clock_satellite_100mhz" "acpki_nist_qc2_satellite_100mhz" + ]; + build = { target, variant, json ? null }: let + szl = zynqpkgs."${target}-szl"; + fsbl = zynqpkgs."${target}-fsbl"; + fwtype = if builtins.elem variant sat_variants then "satman" else "runtime"; + + firmware = rustPlatform.buildRustPackage rec { + name = "firmware"; + + src = ./src; + cargoLock = { lockFile = src/Cargo.lock; }; + + nativeBuildInputs = [ + pkgs.gnumake + (pkgs.python3.withPackages(ps: (with artiqpkgs; [ ps.jsonschema migen migen-axi misoc artiq ]))) + zynqpkgs.cargo-xbuild + pkgs.llvmPackages_9.llvm + pkgs.llvmPackages_9.clang-unwrapped + ]; + buildPhase = '' + export XARGO_RUST_SRC="${rustPlatform.rust.rustc}/lib/rustlib/src/rust/library" + export CLANG_EXTRA_INCLUDE_DIR="${pkgs.llvmPackages_9.clang-unwrapped.lib}/lib/clang/9.0.1/include" + export CARGO_HOME=$(mktemp -d cargo-home.XXX) + make TARGET=${target} GWARGS="${if json == null then "-V ${variant}" else json}" ${fwtype} + ''; + + installPhase = '' + mkdir -p $out $out/nix-support + cp ../build/${fwtype}.bin $out/${fwtype}.bin + cp ../build/firmware/armv7-none-eabihf/release/${fwtype} $out/${fwtype}.elf + echo file binary-dist $out/${fwtype}.bin >> $out/nix-support/hydra-build-products + echo file binary-dist $out/${fwtype}.elf >> $out/nix-support/hydra-build-products + ''; + + doCheck = false; + dontFixup = true; + }; + gateware = pkgs.runCommand "${target}-${variant}-gateware" + { + nativeBuildInputs = [ + (pkgs.python3.withPackages(ps: (with artiqpkgs; [ ps.jsonschema migen migen-axi misoc artiq ]))) + artiqpkgs.vivado + ]; + } + '' + python ${./src/gateware}/${target}.py -g build ${if json == null then "-V ${variant}" else json} + mkdir -p $out $out/nix-support + cp build/top.bit $out + echo file binary-dist $out/top.bit >> $out/nix-support/hydra-build-products + ''; + + # SZL startup + jtag = pkgs.runCommand "${target}-${variant}-jtag" {} + '' + mkdir $out + ln -s ${szl}/szl.elf $out + ln -s ${firmware}/${fwtype}.bin $out + ln -s ${gateware}/top.bit $out + ''; + sd = pkgs.runCommand "${target}-${variant}-sd" + { + buildInputs = [ zynqpkgs.mkbootimage ]; + } + '' + # Do not use "long" paths in boot.bif, because embedded developers + # can't write software (mkbootimage will segfault). + bifdir=`mktemp -d` + cd $bifdir + ln -s ${szl}/szl.elf szl.elf + ln -s ${firmware}/${fwtype}.elf ${fwtype}.elf + ln -s ${gateware}/top.bit top.bit + cat > boot.bif << EOF + the_ROM_image: + { + [bootloader]szl.elf + top.bit + ${fwtype}.elf + } + EOF + mkdir $out $out/nix-support + mkbootimage boot.bif $out/boot.bin + echo file binary-dist $out/boot.bin >> $out/nix-support/hydra-build-products + ''; + + # FSBL startup + fsbl-sd = pkgs.runCommand "${target}-${variant}-fsbl-sd" + { + buildInputs = [ zynqpkgs.mkbootimage ]; + } + '' + bifdir=`mktemp -d` + cd $bifdir + ln -s ${fsbl}/fsbl.elf fsbl.elf + ln -s ${gateware}/top.bit top.bit + ln -s ${firmware}/${fwtype}.elf ${fwtype}.elf + cat > boot.bif << EOF + the_ROM_image: + { + [bootloader]fsbl.elf + top.bit + ${fwtype}.elf + } + EOF + mkdir $out $out/nix-support + mkbootimage boot.bif $out/boot.bin + echo file binary-dist $out/boot.bin >> $out/nix-support/hydra-build-products + ''; + in { + "${target}-${variant}-firmware" = firmware; + "${target}-${variant}-gateware" = gateware; + "${target}-${variant}-jtag" = jtag; + "${target}-${variant}-sd" = sd; + } // ( + if builtins.elem target fsblTargets + then { + "${target}-${variant}-fsbl-sd" = fsbl-sd; + } + else {} + ); + in { + packages.x86_64-linux = (build { target = "zc706"; variant = "nist_clock"; }) // + (build { target = "zc706"; variant = "nist_clock_master"; }) // + (build { target = "zc706"; variant = "nist_clock_satellite"; }) // + (build { target = "zc706"; variant = "nist_clock_satellite_100mhz"; }) // + (build { target = "zc706"; variant = "nist_qc2"; }) // + (build { target = "zc706"; variant = "nist_qc2_master"; }) // + (build { target = "zc706"; variant = "nist_qc2_satellite"; }) // + (build { target = "zc706"; variant = "nist_qc2_satellite_100mhz"; }) // + (build { target = "zc706"; variant = "acpki_nist_clock"; }) // + (build { target = "zc706"; variant = "acpki_nist_clock_master"; }) // + (build { target = "zc706"; variant = "acpki_nist_clock_satellite"; }) // + (build { target = "zc706"; variant = "acpki_nist_clock_satellite_100mhz"; }) // + (build { target = "zc706"; variant = "acpki_nist_qc2"; }) // + (build { target = "zc706"; variant = "acpki_nist_qc2_master"; }) // + (build { target = "zc706"; variant = "acpki_nist_qc2_satellite"; }) // + (build { target = "zc706"; variant = "acpki_nist_qc2_satellite_100mhz"; }) // + (build { target = "kasli_soc"; variant = "demo"; json = ./demo.json; }) // + (build { target = "kasli_soc"; variant = "master"; json = ./kasli-soc-master.json; }) // + (build { target = "kasli_soc"; variant = "satellite"; json = ./kasli-soc-satellite.json; }); + + devShell.x86_64-linux = pkgs.mkShell { + name = "artiq-zynq-dev-shell"; + buildInputs = with pkgs; [ + rustPlatform.rust.rustc + rustPlatform.rust.cargo + llvmPackages_9.llvm + llvmPackages_9.clang-unwrapped + gnumake + cacert + zynqpkgs.cargo-xbuild + zynqpkgs.mkbootimage + openocd + openssh rsync + (python3.withPackages(ps: (with artiqpkgs; [ migen migen-axi misoc artiq artiq-netboot ps.jsonschema ps.pyftdi ]))) + artiqpkgs.artiq + artiqpkgs.vivado + binutils-arm + ]; + XARGO_RUST_SRC = "${rustPlatform.rust.rustc}/lib/rustlib/src/rust/library"; + CLANG_EXTRA_INCLUDE_DIR = "${pkgs.llvmPackages_9.clang-unwrapped.lib}/lib/clang/9.0.1/include"; + OPENOCD_ZYNQ = "${zynq-rs}/openocd"; + SZL = "${zynqpkgs.szl}"; + }; + + }; +} \ No newline at end of file