From 1e7ba3227f94959304584e7431f8b8197967feb6 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 1 Jan 2019 22:25:56 +0800 Subject: [PATCH] nix: add development environment --- nix/README.rst | 17 ++++++++---- nix/artiq-dev.nix | 33 +++++++++++++++++++++++ nix/default.nix | 1 + nix/pkgs/openocd.nix | 63 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 nix/artiq-dev.nix create mode 100644 nix/pkgs/openocd.nix diff --git a/nix/README.rst b/nix/README.rst index 7df289bd4..c6f69e4d6 100644 --- a/nix/README.rst +++ b/nix/README.rst @@ -1,12 +1,10 @@ -Install ARTIQ via the Nix Package Manager -========================================= +Use ARTIQ via the Nix Package Manager +===================================== These instructions provide an alternative route to install ARTIQ for people who do not wish to use conda. This sets up an environment suitable for using ARTIQ, including the ARTIQ-Python compiler, device drivers, and the graphical user interfaces. This works correctly on Linux, and partially works (but not to a level that we would consider usable) with WSL introduced in Windows 10. -ARTIQ firmware and gateware development tools (e.g. rustc, Migen) and ARTIQ core device flashing tools (OpenOCD, proxy bitstreams) are currently not available on Nix. Pull requests welcome! - * Install the Nix package manager * many Linux distros already have a package for the `Nix package manager `_ @@ -25,4 +23,13 @@ ARTIQ firmware and gateware development tools (e.g. rustc, Migen) and ARTIQ core * $ ``cd artiq/nix`` * $ ``nix-env -i -f default.nix`` -The above command will setup your entire environment. Note that it will compile LLVM and Clang, which uses a lot of CPU time and disk space. +The above command will setup your entire environment. Note that it will compile LLVM, which uses a lot of CPU time and disk space. + +ARTIQ development environment with Nix +====================================== + +Run ``nix-shell artiq-dev.nix`` to obtain an environment containing Migen, MiSoC, Clang, Rust, Cargo, and OpenOCD in addition to the user environment above. + +This creates a FHS chroot environment in order to simplify the installation and patching of Xilinx Vivado (it needs to be installed manually e.g. in your home folder). + +You can then build the firmware and gateware with a command such as ``python -m artiq.gateware.targets.kasli --gateware-toolchain-path ~/Xilinx/Vivado``. diff --git a/nix/artiq-dev.nix b/nix/artiq-dev.nix new file mode 100644 index 000000000..89c079379 --- /dev/null +++ b/nix/artiq-dev.nix @@ -0,0 +1,33 @@ +let + pkgs = import {}; + artiqpkgs = import ./default.nix { inherit pkgs; }; +in +( + pkgs.buildFHSUserEnv { + name = "artiq-dev"; + targetPkgs = pkgs: ( + with pkgs; [ + ncurses5 + gnumake + xorg.libSM + xorg.libICE + xorg.libXrender + xorg.libX11 + xorg.libXext + xorg.libXtst + xorg.libXi + (python3.withPackages(ps: with ps; [ jinja2 numpy artiqpkgs.migen artiqpkgs.misoc artiqpkgs.artiq ])) + ] ++ + (with artiqpkgs; [ + rustc + cargo + binutils-or1k + llvm-or1k + openocd + ]) + ); + profile = '' + export TARGET_AR=${artiqpkgs.binutils-or1k}/bin/or1k-linux-ar + ''; + } +).env diff --git a/nix/default.nix b/nix/default.nix index 72210c430..5aaaf7621 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -14,4 +14,5 @@ in rec { llvm-or1k = callPackage ./llvm-or1k.nix { inherit llvm-src; }; llvmlite = callPackage ./llvmlite.nix { inherit llvm-or1k; }; artiq = callPackage ./artiq.nix { inherit binutils-or1k; inherit llvm-or1k; inherit llvmlite; }; + openocd = callPackage ./pkgs/openocd.nix {}; } diff --git a/nix/pkgs/openocd.nix b/nix/pkgs/openocd.nix new file mode 100644 index 000000000..c820d4c14 --- /dev/null +++ b/nix/pkgs/openocd.nix @@ -0,0 +1,63 @@ +{ stdenv, fetchFromGitHub, autoreconfHook, libftdi, libusb1, pkgconfig, hidapi }: + +stdenv.mkDerivation rec { + name = "openocd-${version}"; + version = "0.10.0"; + + src = fetchFromGitHub { + owner = "m-labs"; + repo = "openocd"; + fetchSubmodules = true; + rev = "c383a57adcff332b2c5cf8d55a84626285b42c2c"; + sha256 = "0xlj9cs72acx3zqagvr7f1c0v6lnqhl8fgrlhgmhmvk5n9knk492"; + }; + + nativeBuildInputs = [ pkgconfig ]; + buildInputs = [ autoreconfHook libftdi libusb1 hidapi ]; + + configureFlags = [ + "--enable-jtag_vpi" + "--enable-usb_blaster_libftdi" + "--enable-amtjtagaccel" + "--enable-gw16012" + "--enable-presto_libftdi" + "--enable-openjtag_ftdi" + "--enable-oocd_trace" + "--enable-buspirate" + "--enable-sysfsgpio" + "--enable-remote-bitbang" + ]; + + NIX_CFLAGS_COMPILE = [ + "-Wno-implicit-fallthrough" + "-Wno-format-truncation" + "-Wno-format-overflow" + ]; + + postInstall = '' + mkdir -p "$out/etc/udev/rules.d" + rules="$out/share/openocd/contrib/60-openocd.rules" + if [ ! -f "$rules" ]; then + echo "$rules is missing, must update the Nix file." + exit 1 + fi + ln -s "$rules" "$out/etc/udev/rules.d/" + ''; + + meta = with stdenv.lib; { + description = "Free and Open On-Chip Debugging, In-System Programming and Boundary-Scan Testing"; + longDescription = '' + OpenOCD provides on-chip programming and debugging support with a layered + architecture of JTAG interface and TAP support, debug target support + (e.g. ARM, MIPS), and flash chip drivers (e.g. CFI, NAND, etc.). Several + network interfaces are available for interactiving with OpenOCD: HTTP, + telnet, TCL, and GDB. The GDB server enables OpenOCD to function as a + "remote target" for source-level debugging of embedded systems using the + GNU GDB program. + ''; + homepage = http://openocd.sourceforge.net/; + license = licenses.gpl2Plus; + maintainers = with maintainers; [ bjornfor ]; + platforms = platforms.linux; + }; +}