2018-06-02 13:23:50 +02:00
nextpnr -- a portable FPGA place and route tool
===============================================
2018-08-01 03:51:33 +02:00
nextpnr aims to be a vendor neutral, timing driven, FOSS FPGA place and route
tool.
2018-08-01 10:40:32 +02:00
Currently nextpnr supports:
2023-02-14 06:47:16 +01:00
* Lattice iCE40 devices supported by [Project IceStorm ](https://github.com/YosysHQ/icestorm )
2020-06-26 12:43:27 +02:00
* Lattice ECP5 devices supported by [Project Trellis ](https://github.com/YosysHQ/prjtrellis )
2021-02-08 14:04:49 +01:00
* Lattice Nexus devices supported by [Project Oxide ](https://github.com/gatecat/prjoxide )
2026-02-25 15:43:02 +01:00
* Gowin LittleBee and Aurora V devices supported by [Project Apicula ](https://github.com/YosysHQ/apicula )
2025-09-30 10:05:36 +02:00
* NanoXplore NG-Ultra devices supported by [Project Beyond ](https://github.com/YosysHQ-GmbH/prjbeyond-db )
* Cologne Chip GateMate devices supported by [Project Peppercorn ](https://github.com/YosysHQ/prjpeppercorn )
2021-05-15 22:51:56 +02:00
* *(experimental)* Cyclone V devices supported by [Mistral ](https://github.com/Ravenslofty/mistral )
2021-11-05 18:29:01 +01:00
* *(experimental)* Lattice MachXO2 devices supported by [Project Trellis ](https://github.com/YosysHQ/prjtrellis )
2026-02-25 15:43:02 +01:00
* *(experimental)* Xilinx 7-series devices supported by [Project X-Ray ](https://github.com/F4PGA/prjxray )
2018-08-01 03:51:33 +02:00
* *(experimental)* a "generic" back-end for user-defined architectures
2019-05-20 20:50:23 +02:00
A brief (academic) paper describing the Yosys+nextpnr flow can be found
on [arXiv ](https://arxiv.org/abs/1903.10407 ).
2018-08-01 03:51:33 +02:00
Here is a screenshot of nextpnr for iCE40. Build instructions and
2018-08-01 10:24:55 +02:00
[getting started notes ](#getting-started ) can be found below.
2018-07-30 11:57:02 +02:00
< img src = "https://i.imgur.com/0spmlBa.png" width = "640" / >
2018-08-01 10:24:55 +02:00
See also:
- [F.A.Q. ](docs/faq.md )
- [Architecture API ](docs/archapi.md )
2018-07-30 11:57:02 +02:00
2018-07-29 13:43:04 +02:00
Prerequisites
-------------
2018-06-02 13:23:50 +02:00
2018-07-29 13:43:04 +02:00
The following packages need to be installed for building nextpnr, independent
of the selected architecture:
2026-02-25 15:43:02 +01:00
- CMake 3.25 or later
2024-01-05 20:13:48 +01:00
- Modern C++17 compiler (`clang-format` required for development)
2018-07-29 13:43:04 +02:00
- Python 3.5 or later, including development libraries (`python3-dev` for Ubuntu)
2023-11-17 09:14:19 +01:00
- Python 3.9 or later is required for `nextpnr-himbaechel`
2018-07-29 13:43:04 +02:00
- on Windows make sure to install same version as supported by [vcpkg ](https://github.com/Microsoft/vcpkg/blob/master/ports/python3/CONTROL )
2020-11-16 09:42:15 +01:00
- Boost libraries (`libboost-dev libboost-filesystem-dev libboost-thread-dev libboost-program-options-dev libboost-iostreams-dev libboost-dev` or `libboost-all-dev` for Ubuntu)
2026-02-25 15:43:02 +01:00
- Eigen3 (`libeigen3-dev` for Ubuntu)
- Yosys is required to synthesise the demo design
2018-07-29 13:43:04 +02:00
- For building on Windows with MSVC, usage of vcpkg is advised for dependency installation.
2020-12-08 10:44:50 +01:00
- For 32 bit builds: `vcpkg install boost-filesystem boost-program-options boost-thread eigen3`
- For 64 bit builds: `vcpkg install boost-filesystem:x64-windows boost-program-options:x64-windows boost-thread:x64-windows eigen3:x64-windows`
2019-08-15 06:59:27 +02:00
- For static builds, add `-static` to each of the package names. For example, change `eigen3:x64-windows` to `eigen3:x64-windows-static`
2019-04-02 09:25:00 +02:00
- A copy of Python that matches the version in vcpkg (currently Python 3.6.4). You can download the [Embeddable Zip File ](https://www.python.org/downloads/release/python-364/ ) and extract it. You may need to extract `python36.zip` within the embeddable zip file to a new directory called "Lib".
2018-07-29 13:43:04 +02:00
- For building on macOS, brew utility is needed.
2020-12-08 10:44:50 +01:00
- Install all needed packages `brew install cmake python boost eigen`
2018-07-29 13:43:04 +02:00
Getting started
---------------
2025-01-28 04:07:57 +01:00
First of all, run:
```
git submodule update --init --recursive
```
2018-07-29 13:43:04 +02:00
### nextpnr-ice40
2023-02-14 06:47:16 +01:00
For iCE40 support, install [Project IceStorm ](https://github.com/YosysHQ/icestorm ) to `/usr/local` or another location, which should be passed as `-DICESTORM_INSTALL_PREFIX=/usr` to CMake. Then build and install `nextpnr-ice40` using the following commands:
2018-07-29 13:43:04 +02:00
```
2025-01-26 11:10:46 +01:00
mkdir -p build & & cd build
cmake .. -DARCH=ice40
2018-07-29 13:43:04 +02:00
make -j$(nproc)
sudo make install
```
2019-04-02 09:25:00 +02:00
On Windows, you may specify paths explicitly:
```
2025-01-26 11:10:46 +01:00
cmake . -B build -DARCH=ice40 -DICESTORM_INSTALL_PREFIX=C:/ProgramData/icestorm -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows -G "Visual Studio 15 2017 Win64" -DPython3_EXECUTABLE=C:/Python364/python.exe -DPython3_LIBRARY=C:/vcpkg/packages/python3_x64-windows/lib/python36.lib -DPython3_INCLUDE_DIR=C:/vcpkg/packages/python3_x64-windows/include/python3.6
cmake --build build --config Release
2019-04-02 09:25:00 +02:00
```
2019-08-15 06:59:27 +02:00
To build a static release, change the target triplet from `x64-windows` to `x64-windows-static` and add `-DBUILD_STATIC=ON` .
2019-04-16 06:27:11 +02:00
A simple example that runs on the iCEstick dev board can be found in `ice40/examples/blinky/blinky.*` .
2018-07-29 13:43:04 +02:00
Usage example:
```
2019-04-16 06:27:11 +02:00
cd ice40/examples/blinky
2018-07-29 13:43:04 +02:00
yosys -p 'synth_ice40 -top blinky -json blinky.json' blinky.v # synthesize into blinky.json
nextpnr-ice40 --hx1k --json blinky.json --pcf blinky.pcf --asc blinky.asc # run place and route
icepack blinky.asc blinky.bin # generate binary bitstream file
iceprog blinky.bin # upload design to iCEstick
```
2020-12-08 10:44:50 +01:00
Running nextpnr in GUI mode (see below for instructions on building nextpnr with GUI support):
2018-07-29 13:43:04 +02:00
```
nextpnr-ice40 --json blinky.json --pcf blinky.pcf --asc blinky.asc --gui
```
(Use the toolbar buttons or the Python command console to perform actions
such as pack, place, route, and write output files.)
### nextpnr-ecp5
2020-06-26 12:43:27 +02:00
For ECP5 support, install [Project Trellis ](https://github.com/YosysHQ/prjtrellis ) to `/usr/local` or another location, which should be passed as `-DTRELLIS_INSTALL_PREFIX=/usr/local` to CMake. Then build and install `nextpnr-ecp5` using the following commands:
2018-07-29 13:43:04 +02:00
```
2025-01-26 11:10:46 +01:00
mkdir -p build & & cd build
cmake .. -DARCH=ecp5 -DTRELLIS_INSTALL_PREFIX=/usr/local
2018-07-29 13:43:04 +02:00
make -j$(nproc)
sudo make install
```
2026-02-26 15:30:43 +01:00
- Examples of the ECP5 flow for a range of boards can be found in the [Project Trellis Examples ](https://github.com/YosysHQ/prjtrellis/tree/main/examples ).
2018-07-29 14:17:02 +02:00
2020-11-30 09:59:04 +01:00
### nextpnr-nexus
2021-02-08 14:04:49 +01:00
For Nexus support, install [Project Oxide ](https://github.com/gatecat/prjoxide ) to `$HOME/.cargo` or another location, which should be passed as `-DOXIDE_INSTALL_PREFIX=$HOME/.cargo` to CMake. Then build and install `nextpnr-nexus` using the following commands:
2020-11-30 09:59:04 +01:00
```
2025-01-26 11:10:46 +01:00
mkdir -p build & & cd build
cmake .. -DARCH=nexus -DOXIDE_INSTALL_PREFIX=$HOME/.cargo
2020-11-30 09:59:04 +01:00
make -j$(nproc)
sudo make install
```
2026-02-26 15:30:43 +01:00
- Examples of the Nexus flow for a range of boards can be found in the [Project Oxide Examples ](https://github.com/gatecat/prjoxide/tree/main/examples ).
2020-11-30 09:59:04 +01:00
2025-12-22 16:36:38 +01:00
### nextpnr-mistral
For Cyclone V support, clone [Mistral ](https://github.com/Ravenslofty/mistral/tree/nextpnr-latest ) to `$HOME/mistral` or another location and pass this path as `-DMISTRAL_ROOT=$HOME/mistral` to CMake. Then build and install `nextpnr-mistral` using the following commands:
```
mkdir -p build & & cd build
cmake .. -DARCH=mistral -DMISTRAL_ROOT=$HOME/mistral
make -j$(nproc)
sudo make install
```
Cyclone V support is currently experimental and has limited testing. The backend is undergoing active API refactoring, and its structure, build requirements, and integration points may change between versions.
2024-01-20 14:58:03 +01:00
### nextpnr-generic
2020-12-30 15:59:55 +01:00
2024-01-20 14:58:03 +01:00
The generic target allows running placement and routing for arbitrary custom architectures.
2020-12-30 15:59:55 +01:00
```
2025-01-26 11:10:46 +01:00
mkdir -p build & & cd build
cmake .. -DARCH=generic
2020-12-30 15:59:55 +01:00
make -j$(nproc)
sudo make install
```
2024-01-20 14:58:03 +01:00
An example of how to use the generic flow is in [generic/examples ](generic/examples ). See also the [Generic Architecture docs ](docs/generic.md ).
2020-12-30 15:59:55 +01:00
2024-01-20 14:58:03 +01:00
### nextpnr-himbaechel
2018-07-29 13:43:04 +02:00
2024-01-20 14:58:03 +01:00
The himbaechel target allows running placement and routing for larger architectures that share a common structure.
#### gowin
For Gowin support, install [Project Apicula ](https://github.com/YosysHQ/apicula )
2018-07-29 13:43:04 +02:00
```
2025-01-26 11:10:46 +01:00
mkdir -p build & & cd build
cmake .. -DARCH="himbaechel" -DHIMBAECHEL_UARCH="gowin"
2018-07-29 13:43:04 +02:00
make -j$(nproc)
sudo make install
```
2024-01-20 14:58:03 +01:00
- Examples of the Gowin flow for a range of boards can be found in the [Project Apicula Examples ](https://github.com/YosysHQ/apicula/tree/master/examples ).
2018-07-29 13:43:04 +02:00
2024-12-04 09:00:05 +01:00
#### ng-ultra
For NanoXplore NG-Ultra support, clone [Project Beyond DB ](https://github.com/yosyshq-GmbH/prjbeyond-db ) repo
```
2025-01-26 11:10:46 +01:00
mkdir -p build & & cd build
cmake .. -DARCH="himbaechel" -DHIMBAECHEL_UARCH="ng-ultra" -DHIMBAECHEL_PRJBEYOND_DB=/path/to/prjbeyond-db -DHIMBAECHEL_NGULTRA_DEVICES=ng-ultra
2024-12-04 09:00:05 +01:00
make -j$(nproc)
sudo make install
```
*Please note that binary bitstream creation requires Impulse tool from NanoXplore.*
2025-09-30 10:05:36 +02:00
#### gatemate
For Cologne Chip GateMate support, clone [Project Peppercorn ](https://github.com/YosysHQ/prjpeppercorn )
```
mkdir -p build & & cd build
cmake .. -DARCH="himbaechel" -DHIMBAECHEL_UARCH="gatemate" -DHIMBAECHEL_PEPPERCORN_PATH=/path/to/prjpeppercorn
make -j$(nproc)
sudo make install
```
2020-12-08 10:44:50 +01:00
### GUI
2025-10-17 14:16:07 +02:00
The nextpnr GUI is not built by default, to reduce the number of dependencies for a standard headless build. To enable it, add `-DBUILD_GUI=ON` to the CMake command line and ensure that Qt5/Qt6 and OpenGL are available:
2020-12-08 10:44:50 +01:00
2025-10-17 14:16:07 +02:00
For Qt6:
- On Ubuntu 22.04 LTS or later, install `qt6-base-dev`
- For MSVC vcpkg, install `qt-base` (32-bit) or `qt-base:x64-windows` (64-bit)
- For Homebrew, install `qt6` and add qt6 in path: `echo 'export PATH="/usr/local/opt/qt/bin:$PATH"' >> ~/.bash_profile`
` - this change is effective in next terminal session, so please re-open terminal window before building
For Qt5:
- On Ubuntu 22.04 LTS, install `qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools`
2022-06-23 02:03:04 +02:00
- On other Ubuntu versions, install `qt5-default`
2020-12-08 10:44:50 +01:00
- For MSVC vcpkg, install `qt5-base` (32-bit) or `qt5-base:x64-windows` (64-bit)
- For Homebrew, install `qt5` and add qt5 in path: `echo 'export PATH="/usr/local/opt/qt/bin:$PATH"' >> ~/.bash_profile`
` - this change is effective in next terminal session, so please re-open terminal window before building
2020-06-24 17:44:45 +02:00
### Multiple architectures
2018-07-29 13:43:04 +02:00
2020-06-24 17:44:45 +02:00
To build nextpnr for multiple architectures at once, a semicolon-separated list can be used with `-DARCH` .
2018-07-29 13:43:04 +02:00
2020-06-24 17:44:45 +02:00
```
2025-01-26 11:10:46 +01:00
mkdir -p build & & cd build
cmake .. -DARCH="ice40;ecp5"
2020-06-24 17:44:45 +02:00
make -j$(nproc)
sudo make install
```
2018-07-29 13:43:04 +02:00
2020-11-30 09:59:04 +01:00
To build every available stable architecture, use `-DARCH=all` . To include experimental arches (currently nexus), use `-DARCH=all+alpha` .
2020-06-24 17:44:45 +02:00
2025-01-16 22:09:33 +01:00
### Per-microarchitecture Himbächel
To build a single nextpnr-himbachel executable for each of the supported microarchitectures, use `-DHIMBAECHEL_SPLIT` .
```
2025-01-26 11:10:46 +01:00
mkdir -p build & & cd build
cmake .. -DARCH="himbaechel" -DHIMBAECHEL_UARCH="gowin;ng-ultra"
2025-01-16 22:09:33 +01:00
make -j$(nproc)
sudo make install
```
In such a build, instead of a single `nextpnr-himbaechel` binary, two binaries `nextpnr-himbaechel-gowin` and `nextpnr-himbaechel-ng-ultra` are built. Although they are installed together, each microarchitecture is completely independent of the other, and only needs its corresponding `.../share/himbaechel/<microarchitecture>/` chip database directory to run. Split build reduces the size of individual distributed artifacts (although the total size increases), and allows co-installation of artifacts of different versions.
2020-06-24 17:44:45 +02:00
Cross-compilation
-----------------
Apart from chip databases, nextpnr requires the `bba` tool to be compiled for the build system. This tool can be compiled as a separate project:
2018-08-16 10:32:34 +02:00
```
2020-06-24 17:44:45 +02:00
cd bba
cmake .
make
```
This will create a `bba-export.cmake` file. Provide the path to this file when cross-building nextpnr by using `-DBBA_IMPORT=/path/to/bba-export.cmake` .
Additional notes for building nextpnr
-------------------------------------
The following runs a debug build of the iCE40 architecture without GUI, without Python support, without the HeAP analytic placer and only HX1K support:
```
2025-01-26 11:10:46 +01:00
mkdir -p build & & cd build
cmake .. -DARCH=ice40 -DCMAKE_BUILD_TYPE=Debug -DBUILD_PYTHON=OFF -DICE40_DEVICES=1k
2018-08-16 10:32:34 +02:00
make -j$(nproc)
```
2020-06-24 17:44:45 +02:00
To make static build release for iCE40 architecture use the following:
```
2025-01-26 11:10:46 +01:00
mkdir -p build & & cd build
cmake .. -DARCH=ice40 -DBUILD_PYTHON=OFF -DSTATIC_BUILD=ON
2020-06-24 17:44:45 +02:00
make -j$(nproc)
```
2019-03-22 11:46:54 +01:00
2020-06-24 17:44:45 +02:00
The HeAP placer's solver can optionally use OpenMP for a speedup on very large designs. Enable this by passing `-DUSE_OPENMP=yes` to cmake (compiler support may vary).
2018-11-26 10:47:16 +01:00
2020-06-24 17:44:45 +02:00
You can change the location where nextpnr will be installed (this will usually default to `/usr/local` ) by using `-DCMAKE_INSTALL_PREFIX=/install/prefix` .
2019-09-17 05:33:39 +02:00
2018-07-29 13:43:04 +02:00
Notes for developers
--------------------
2018-08-01 02:33:48 +02:00
- All code is formatted using `clang-format` according to the style rules in `.clang-format` (LLVM based with
2018-07-29 13:43:04 +02:00
increased indent widths and brace wraps after classes).
- To automatically format all source code, run `make clangformat` .
- See the wiki for additional documentation on the architecture API.
2018-06-02 13:57:08 +02:00
2020-01-05 13:51:12 +01:00
Recording a movie
-----------------
- To save a movie recording of place-and-route click recording icon in toolbar and select empty directory
where recording files will be stored and select frames to skip.
2020-09-23 09:08:47 +02:00
- Manually start all PnR operations you wish
2020-01-05 13:51:12 +01:00
- Click on recording icon again to stop recording
2020-09-23 09:08:47 +02:00
- Go to directory containing files and execute `ffmpeg -f image2 -r 1 -i movie_%05d.png -c:v libx264 nextpnr.mp4`
2020-01-05 13:51:12 +01:00
2018-06-24 19:43:21 +02:00
Testing
-------
2019-12-15 20:14:25 +01:00
- To build test binaries as well, use `-DBUILD_TESTS=ON` and after `make` run `make test` to run them, or you can run separate binaries.
2018-07-29 13:43:04 +02:00
- To use code sanitizers use the `cmake` options:
- `-DSANITIZE_ADDRESS=ON`
- `-DSANITIZE_MEMORY=ON -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++`
- `-DSANITIZE_THREAD=ON`
- `-DSANITIZE_UNDEFINED=ON`
- Running valgrind example `valgrind --leak-check=yes --tool=memcheck ./nextpnr-ice40 --json ice40/blinky.json`
2020-06-24 17:44:45 +02:00
- Running tests with code coverage use `-DBUILD_TESTS=ON -DCOVERAGE` and after `make` run `make ice40-coverage`
2018-08-23 18:38:13 +02:00
- After that open `ice40-coverage/index.html` in your browser to view the coverage report
- Note that `lcov` is needed in order to generate reports
2018-07-29 13:43:04 +02:00
Links and references
--------------------
### Synthesis, simulation, and logic optimization
2021-06-09 14:13:50 +02:00
- [Yosys ](https://yosyshq.net/yosys/ )
2018-07-29 13:43:04 +02:00
- [Icarus Verilog ](http://iverilog.icarus.com/ )
- [ABC ](https://people.eecs.berkeley.edu/~alanmi/abc/ )
### FPGA bitstream documentation (and tools) projects
2023-02-14 06:47:16 +01:00
- [Project IceStorm (Lattice iCE40) ](https://github.com/YosysHQ/icestorm )
2020-06-26 12:43:27 +02:00
- [Project Trellis (Lattice ECP5) ](https://yosyshq.github.io/prjtrellis-db/ )
2026-01-16 08:33:22 +01:00
- [Project X-Ray (Xilinx 7-Series) ](https://github.com/F4PGA/prjxray )
2018-07-29 13:43:04 +02:00
- [Project Chibi (Intel MAX-V) ](https://github.com/rqou/project-chibi )
2018-07-30 11:57:02 +02:00
### Other FOSS FPGA place and route projects
2018-07-29 13:43:04 +02:00
- [Arachne PNR ](https://github.com/cseed/arachne-pnr )
- [VPR/VTR ](https://verilogtorouting.org/ )
2018-07-30 11:57:02 +02:00
- [SymbiFlow ](https://github.com/SymbiFlow/symbiflow-arch-defs )