2017-02-03 02:53:12 +08:00
Developing ARTIQ
^^^^^^^^^^^^^^^^
2018-05-18 14:18:36 +08:00
.. warning ::
This section is only for software or FPGA developers who want to modify ARTIQ. The steps described here are not required if you simply want to run experiments with ARTIQ.
2018-01-19 04:29:24 +08:00
.. note ::
Developing ARTIQ is currently only possible on Linux.
2017-02-03 02:53:12 +08:00
We describe two different approaches to creating a development environment for ARTIQ.
2017-08-29 22:22:57 +08:00
The first method uses existing pre-compiled Anaconda packages and the `` artiq-dev `` meta-package for the development environment.
This is fast and convenient because it avoids compiling the entire toolchain.
Consequently, some ARTIQ developers as well as the buildbot that's used for continuous integration all employ this method to build the `` artiq `` Anaconda packages and the bitstreams.
2017-02-03 02:53:12 +08:00
It is completely sufficient to develop and tweak the ARTIQ code and to build
bitstreams.
2017-08-29 22:22:57 +08:00
But with the meta-pakage developing individual components within the toolchain requires extra care.
Consequently, the second method builds most components in the toolchain from their sources.
This takes time and care to reproduce accurately but it gives absolute control over the components and an immediate handle at developing them.
Some ARTIQ developers use this second method of building the entire toolchain
from sources.
2017-02-03 02:53:12 +08:00
It is only recommended for developers and advanced users.
.. _develop-from-conda:
ARTIQ Anaconda development environment
======================================
1. Install `` git `` as recommended for your operating system and distribution.
2. Obtain ARTIQ::
2017-02-03 03:03:15 +08:00
2017-02-03 02:53:12 +08:00
$ git clone --recursive https://github.com/m-labs/artiq ~/artiq-dev/artiq
$ cd ~/artiq-dev/artiq
2017-05-22 19:05:39 +08:00
2017-12-07 19:24:32 +08:00
Add `` -b release-X `` to the `` git clone `` command if you are building a stable branch of ARTIQ. Replace `` X `` with the major release. The default will fetch the development `` master `` branch.
2017-02-03 02:53:12 +08:00
3. :ref: `Install Anaconda or Miniconda <install-anaconda>`
4. Create and activate a conda environment named `` artiq-dev `` and install the `` artiq-dev `` package which pulls in all the packages required to develop ARTIQ::
2017-02-03 03:03:15 +08:00
2017-02-03 02:53:12 +08:00
$ conda env create -f conda/artiq-dev.yaml
$ source activate artiq-dev
5. Add the ARTIQ source tree to the environment's search path::
2017-02-03 03:03:15 +08:00
2017-08-23 05:44:37 +08:00
$ pip install -e .
2017-05-15 17:17:44 +08:00
6. :ref: `Install Vivado <install-xilinx>`
2017-12-07 19:24:32 +08:00
7. :ref: `Configure OpenOCD <setup-openocd>`
8. :ref: `Build target binaries <build-target-binaries>`
9. :ref: `Flash target binaries <flash-target-binaries>`
2017-02-03 02:53:12 +08:00
2016-06-22 10:01:56 +08:00
.. _install-from-source:
2016-06-22 09:45:56 +08:00
2016-06-22 10:01:56 +08:00
Installing ARTIQ from source
============================
2016-06-22 09:45:56 +08:00
Preparing the build environment for the core device
2016-06-22 10:01:56 +08:00
---------------------------------------------------
2016-06-22 09:45:56 +08:00
These steps are required to generate code that can run on the core
device. They are necessary both for building the MiSoC BIOS
and the ARTIQ kernels.
2016-08-21 10:16:48 +08:00
* Install required host packages: ::
$ sudo apt-get install python3.5 pip3 build-essential cmake cargo
2016-06-22 09:45:56 +08:00
* Create a development directory: ::
$ mkdir ~/artiq-dev
* Clone ARTIQ repository: ::
$ cd ~/artiq-dev
$ git clone --recursive https://github.com/m-labs/artiq
2017-04-19 17:38:24 +08:00
2017-03-29 09:56:09 +08:00
Add `` -b release-X `` to the `` git clone `` command if you are building a stable branch of ARTIQ (the default will fetch the development `` master `` branch).
2016-06-22 09:45:56 +08:00
* Install OpenRISC binutils (or1k-linux-...): ::
$ cd ~/artiq-dev
2016-08-22 03:55:59 +08:00
$ wget https://ftp.gnu.org/gnu/binutils/binutils-2.27.tar.bz2
$ tar xvf binutils-2.27.tar.bz2
$ cd binutils-2.27
2017-02-21 13:19:59 +08:00
$ curl -L 'https://raw.githubusercontent.com/m-labs/conda-recipes/c3effbc26e96c6e246d6e8035f8a07bc52d8ded1/conda/binutils-or1k-linux/fix-R_OR1K_GOTOFF-relocations.patch' | patch -p1
2016-06-22 09:45:56 +08:00
$ mkdir build
$ cd build
$ ../configure --target=or1k-linux --prefix=/usr/local
$ make -j4
$ sudo make install
.. note ::
We're using an `` or1k-linux `` target because it is necessary to enable
shared library support in `` ld `` , not because Linux is involved.
* Install LLVM and Clang: ::
$ cd ~/artiq-dev
2018-08-29 04:00:32 +08:00
$ git clone -b artiq-6.0 https://github.com/m-labs/llvm-or1k
2016-08-24 00:00:54 +08:00
$ cd llvm-or1k
2018-08-29 04:00:32 +08:00
$ git clone -b artiq-6.0 https://github.com/m-labs/clang-or1k tools/clang
2016-06-22 09:45:56 +08:00
$ mkdir build
$ cd build
2017-12-26 21:47:27 +08:00
$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/llvm-or1k -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=OR1K -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_INSTALL_UTILS=ON -DCLANG_ENABLE_ARCMT=OFF -DCLANG_ENABLE_STATIC_ANALYZER=OFF
2016-06-22 09:45:56 +08:00
$ make -j4
$ sudo make install
2016-08-21 10:16:48 +08:00
* Install Rust: ::
$ cd ~/artiq-dev
2018-08-29 04:00:32 +08:00
$ git clone -b artiq-1.28.0 https://github.com/m-labs/rust
2016-11-04 00:04:26 +08:00
$ cd rust
2018-01-10 09:27:10 +08:00
$ git submodule update --init --recursive
2016-08-21 10:16:48 +08:00
$ mkdir build
$ cd build
2017-09-25 01:49:34 +08:00
$ ../configure --prefix=/usr/local/rust-or1k --llvm-root=/usr/local/llvm-or1k --disable-manage-submodules --disable-docs
2017-04-19 17:38:24 +08:00
$ sudo mkdir /usr/local/rust-or1k
$ sudo chown $USER.$USER /usr/local/rust-or1k
$ make install
2018-12-21 10:37:08 +08:00
$ cd ..
2016-08-21 10:16:48 +08:00
2016-11-04 11:35:33 +08:00
$ destdir="/usr/local/rust-or1k/lib/rustlib/or1k-unknown-none/lib/"
2018-08-29 04:00:32 +08:00
$ rustc="rustc --out-dir ${destdir} -L ${destdir} --target or1k-unknown-none -g -C target-feature=+mul,+div,+ffl1,+cmov,+addc -C opt-level=s --crate-type rlib"
2017-09-25 01:49:34 +08:00
$ mkdir -p ${destdir}
2018-08-29 04:00:32 +08:00
$ ${rustc} --crate-name core src/libcore/lib.rs
$ ${rustc} --crate-name compiler_builtins src/libcompiler_builtins/src/lib.rs --cfg $ 'feature="compiler-builtins"' --cfg 'feature="mem"'
$ ${rustc} --crate-name std_unicode src/libstd_unicode/lib.rs
$ ${rustc} --crate-name alloc src/liballoc/lib.rs
$ ${rustc} --crate-name libc src/liblibc_mini/lib.rs
$ ${rustc} --crate-name unwind src/libunwind/lib.rs
$ ${rustc} -Cpanic=abort --crate-name panic_abort src/libpanic_abort/lib.rs
$ ${rustc} -Cpanic=unwind --crate-name panic_unwind src/libpanic_unwind/lib.rs \
--cfg llvm_libunwind
2016-08-21 10:16:48 +08:00
2016-06-22 09:45:56 +08:00
.. note ::
2016-08-21 10:16:48 +08:00
Compilation of LLVM can take more than 30 min on some machines. Compilation of Rust can take more than two hours.
2016-06-22 09:45:56 +08:00
Preparing the core device FPGA board
2016-06-22 10:01:56 +08:00
------------------------------------
2016-06-22 09:45:56 +08:00
These steps are required to generate gateware bitstream (`` .bit `` ) files, build the MiSoC BIOS and ARTIQ runtime, and flash FPGA boards. If the board is already flashed, you may skip those steps and go directly to `Installing the host-side software` .
2017-02-03 02:53:12 +08:00
.. _install-xilinx:
2017-05-15 17:17:44 +08:00
* Install the FPGA vendor tools (i.e. Vivado):
2016-06-22 09:45:56 +08:00
2017-05-15 17:17:44 +08:00
* Get Vivado from http://www.xilinx.com/support/download/index.htm.
2016-06-22 09:45:56 +08:00
2018-02-15 21:20:43 +08:00
* The "appropriate" Vivado version to use for building the bitstream can
vary. Some versions contain bugs that lead to hidden or visible failures,
others work fine.
Refer to the `M-Labs buildbot logs <http://buildbot.m-labs.hk/> `_ to
2018-02-17 00:11:48 +08:00
determine which version is currently used when building the binary
2018-02-15 21:20:43 +08:00
packages.
2017-05-15 17:17:44 +08:00
* During the Vivado installation, uncheck `` Install cable drivers `` (they are not required as we use better and open source alternatives).
2016-06-22 09:45:56 +08:00
* Install Migen: ::
$ cd ~/artiq-dev
$ git clone https://github.com/m-labs/migen
$ cd migen
2017-01-30 09:24:43 +08:00
$ python3 setup.py develop --user
2016-06-22 09:45:56 +08:00
.. note ::
The options `` develop `` and `` --user `` are for setup.py to install Migen in `` ~/.local/lib/python3.5 `` .
2017-02-03 02:53:12 +08:00
.. _install-bscan-spi:
2016-06-22 09:45:56 +08:00
* Install the required flash proxy gateware bitstreams:
The purpose of the flash proxy gateware bitstream is to give programming software fast JTAG access to the flash connected to the FPGA.
2017-05-15 17:17:44 +08:00
* KC705:
2016-06-22 09:45:56 +08:00
::
$ cd ~/artiq-dev
2017-10-21 01:44:50 +08:00
$ wget https://raw.githubusercontent.com/jordens/bscan_spi_bitstreams/master/bscan_spi_xc7k325t.bit
2016-06-22 09:45:56 +08:00
2017-09-23 11:31:17 +08:00
Then move `` ~/artiq-dev/bscan_spi_xc7k325t.bit `` to `` ~/.migen `` , `` /usr/local/share/migen `` , or `` /usr/share/migen `` .
2016-06-22 09:45:56 +08:00
* :ref: `Download and install OpenOCD <install-openocd>` .
2016-07-21 22:33:51 +08:00
* Download and install `` asyncserial `` : ::
$ cd ~/artiq-dev
$ git clone https://www.github.com/m-labs/asyncserial
$ cd asyncserial
2017-01-30 09:24:43 +08:00
$ python3 setup.py develop --user
2016-07-21 22:33:51 +08:00
2016-06-22 09:45:56 +08:00
* Download and install MiSoC: ::
$ cd ~/artiq-dev
$ git clone --recursive https://github.com/m-labs/misoc
$ cd misoc
2017-01-30 09:24:43 +08:00
$ python3 setup.py develop --user
2016-06-22 09:45:56 +08:00
2016-07-21 22:33:51 +08:00
* Download and install `` pythonparser `` : ::
$ cd ~/artiq-dev
$ git clone https://www.github.com/m-labs/pythonparser
$ cd pythonparser
2017-01-30 09:24:43 +08:00
$ python3 setup.py develop --user
2016-07-21 22:33:51 +08:00
2016-06-22 09:45:56 +08:00
* Download and install ARTIQ: ::
$ cd ~/artiq-dev
$ git clone --recursive https://github.com/m-labs/artiq
$ cd artiq
2017-01-30 09:24:43 +08:00
$ python3 setup.py develop --user
2016-06-22 09:45:56 +08:00
.. note ::
If you have any trouble during ARTIQ setup about `` pygit2 `` installation,
refer to the section dealing with
:ref: `installing the host-side software <installing-the-host-side-software>` .
* Build the gateware bitstream, BIOS and runtime by running:
::
$ cd ~/artiq-dev
$ export PATH=/usr/local/llvm-or1k/bin:$PATH
.. note :: Make sure that `` /usr/local/llvm-or1k/bin `` is first in your `` PATH `` , so that the `` clang `` command you just built is found instead of the system one, if any.
2017-02-03 02:53:12 +08:00
.. _build-target-binaries:
2017-02-03 02:58:26 +08:00
2016-06-22 09:45:56 +08:00
* For KC705::
2018-01-22 18:25:10 +08:00
$ python3 -m artiq.gateware.targets.kc705 -V nist_clock # or nist_qc2
2016-06-22 09:45:56 +08:00
2017-05-15 17:17:44 +08:00
.. note :: Add `` --toolchain ise `` if you wish to use ISE instead of Vivado. ISE needs a separate installation step.
2016-06-22 09:45:56 +08:00
2017-08-29 22:22:57 +08:00
.. _flash-target-binaries:
2016-06-22 09:45:56 +08:00
* Then, gather the binaries and flash them: ::
$ mkdir binaries
$ cp misoc_nist_qcX_<board>/gateware/top.bit binaries
$ cp misoc_nist_qcX_<board>/software/bios/bios.bin binaries
$ cp misoc_nist_qcX_<board>/software/runtime/runtime.fbi binaries
2017-08-29 22:22:57 +08:00
$ artiq_flash -d binaries
2016-06-22 09:45:56 +08:00
* Check that the board boots by running a serial terminal program (you may need to press its FPGA reconfiguration button or power-cycle it to load the gateware bitstream that was newly written into the flash): ::
2017-01-25 08:29:37 +08:00
$ flterm /dev/ttyUSB1
2016-06-22 09:45:56 +08:00
MiSoC BIOS http://m-labs.hk
[...]
Booting from flash...
Loading xxxxx bytes from flash...
Executing booted program.
ARTIQ runtime built <date/time>
.. note :: flterm is part of MiSoC. If you installed MiSoC with `` setup.py develop --user `` , the flterm launcher is in `` ~/.local/bin `` .
2017-01-25 08:29:37 +08:00
The communication parameters are 115200 8-N-1. Ensure that your user has access
2016-06-22 09:45:56 +08:00
to the serial device (`` sudo adduser $USER dialout `` assuming standard setup).
.. _installing-the-host-side-software:
Installing the host-side software
2016-06-22 10:01:56 +08:00
---------------------------------
2016-06-22 09:45:56 +08:00
* Install the llvmlite Python bindings: ::
$ cd ~/artiq-dev
$ git clone https://github.com/m-labs/llvmlite
$ cd llvmlite
2017-01-06 02:10:07 +08:00
$ git checkout artiq-3.9
2017-01-30 09:24:43 +08:00
$ LLVM_CONFIG=/usr/local/llvm-or1k/bin/llvm-config python3 setup.py install --user
2016-06-22 09:45:56 +08:00
* Install ARTIQ: ::
$ cd ~/artiq-dev
$ git clone --recursive https://github.com/m-labs/artiq # if not already done
$ cd artiq
2017-01-30 09:24:43 +08:00
$ python3 setup.py develop --user
2016-06-22 09:45:56 +08:00
.. note ::
If you have any trouble during ARTIQ setup about `` pygit2 `` installation,
you can install it by using `` pip `` :
On Ubuntu 14.04::
2017-01-30 09:24:43 +08:00
$ python3 `which pip3` install --user pygit2==0.19.1
2016-06-22 09:45:56 +08:00
On Ubuntu 14.10::
2017-01-30 09:24:43 +08:00
$ python3 `which pip3` install --user pygit2==0.20.3
2016-06-22 09:45:56 +08:00
On Ubuntu 15.04 and 15.10::
2017-01-30 09:24:43 +08:00
$ python3 `which pip3` install --user pygit2==0.22.1
2016-06-22 09:45:56 +08:00
2016-08-21 10:16:48 +08:00
On Ubuntu 16.04::
2017-01-30 09:24:43 +08:00
$ python3 `which pip3` install --user pygit2==0.24.1
2016-08-21 10:16:48 +08:00
2016-06-22 09:45:56 +08:00
The rationale behind this is that pygit2 and libgit2 must have the same
major.minor version numbers.
See http://www.pygit2.org/install.html#version-numbers
* Build the documentation: ::
$ cd ~/artiq-dev/artiq/doc/manual
$ make html