You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.2 KiB

9 months ago
  1. # Install Vivado in /opt and add to /etc/nixos/configuration.nix:
  2. # nix.sandboxPaths = ["/opt"];
  3. { pkgs ? import <nixpkgs> {}
  4. , artiq-fast
  5. }:
  6. let
  7. artiqSrc = import (artiq-fast + "/pkgs/artiq-src.nix") { fetchgit = pkgs.fetchgit; };
  8. artiqpkgs = import artiq-fast { inherit pkgs; };
  9. pythonEnv = pkgs.python3.withPackages (ps: with ps; [
  10. jinja2 jsonschema numpy artiqpkgs.migen artiqpkgs.microscope artiqpkgs.misoc artiqpkgs.jesd204b artiqpkgs.artiq
  11. ]);
  12. fetchcargo = import (artiq-fast + "/fetchcargo-legacy.nix") {
  13. inherit (pkgs) stdenv lib cacert git;
  14. cargo = artiqpkgs.cargo-legacy;
  15. cargo-vendor = artiqpkgs.cargo-vendor-legacy;
  16. };
  17. cargoDeps = fetchcargo rec {
  18. name = "artiq-firmware-cargo-deps";
  19. src = "${artiqSrc}/artiq/firmware";
  20. sha256 = import (artiqSrc + "/artiq/firmware/cargosha256.nix");
  21. };
  22. cargoVendored = pkgs.stdenv.mkDerivation {
  23. name = "artiq-firmware-cargo-vendored";
  24. src = cargoDeps;
  25. phases = [ "unpackPhase" "installPhase" ];
  26. installPhase =
  27. ''
  28. mkdir -p $out/registry
  29. cat << EOF > $out/config
  30. [source.crates-io]
  31. registry = "https://github.com/rust-lang/crates.io-index"
  32. replace-with = "vendored-sources"
  33. [source."https://github.com/m-labs/libfringe"]
  34. git = "https://github.com/m-labs/libfringe"
  35. rev = "b8a6d8f"
  36. replace-with = "vendored-sources"
  37. [source.vendored-sources]
  38. directory = "$out/registry"
  39. EOF
  40. cp -R * $out/registry
  41. '';
  42. };
  43. in
  44. { target
  45. , variant
  46. , src ? null
  47. , buildCommand ? "python -m artiq.gateware.targets.${target} -V ${variant}"
  48. , extraInstallCommands ? ""
  49. , ...
  50. }:
  51. let
  52. name = "artiq-board-${target}-${variant}-${artiqpkgs.artiq.version}-xxx";
  53. installPath = "${pkgs.python3Packages.python.sitePackages}/artiq/board-support/${target}-${variant}";
  54. in
  55. # Board packages are Python modules so that they get added to the ARTIQ Python
  56. # environment, and artiq_flash finds them.
  57. pkgs.stdenv.mkDerivation {
  58. name = "artiq-board-${target}-${variant}-${artiqpkgs.artiq.version}";
  59. inherit src;
  60. phases = [ "buildPhase" "installPhase" ];
  61. nativeBuildInputs = [
  62. pkgs.gnumake pkgs.which pythonEnv
  63. artiqpkgs.cargo-legacy
  64. artiqpkgs.rustc-legacy
  65. artiqpkgs.binutils-or1k
  66. artiqpkgs.llvm-or1k
  67. ];
  68. buildInputs = [ pythonEnv ];
  69. buildPhase =
  70. ''
  71. export CARGO_HOME=${cargoVendored}
  72. export TARGET_AR=or1k-linux-ar
  73. ${buildCommand} --no-compile-gateware --gateware-identifier-str=unprogrammed
  74. '';
  75. installPhase =
  76. ''
  77. mkdir -p $out
  78. cp -ar artiq_${target}/${variant}/gateware $out
  79. TARGET_DIR=$out/${pkgs.python3Packages.python.sitePackages}/artiq/board-support/${target}-${variant}
  80. mkdir -p $TARGET_DIR
  81. if [ -e artiq_${target}/${variant}/software/bootloader/bootloader.bin ]
  82. then cp artiq_${target}/${variant}/software/bootloader/bootloader.bin $TARGET_DIR
  83. fi
  84. if [ -e artiq_${target}/${variant}/software/runtime ]
  85. then cp artiq_${target}/${variant}/software/runtime/runtime.{elf,fbi} $TARGET_DIR
  86. else cp artiq_${target}/${variant}/software/satman/satman.{elf,fbi} $TARGET_DIR
  87. fi
  88. ${extraInstallCommands}
  89. '';
  90. # don't mangle ELF files as they are not for NixOS
  91. dontFixup = true;
  92. }