nextpnr portable FPGA place and route tool
Go to file
Miodrag Milanović d6483adb4d
Gatemate FPGA initial support (#1473)
* Initial code for GateMate

* Initial work on forming bitstream

* Add CCF parsing

* Use CCF to set IO location

* Propagate errors

* Restructure code

* Add support for reading from config

* Start adding infrastructure for reading bitstream

* Fix script

* GPIO initial work

* Add IN1->RAM_O2 propagation

* Fixed typo

* Cleanup

* More parameter checks

* Add LVDS support

* Cleanup

* Keep just used connections for now

* Naive lut tree CPE pack

* Naive pack CC_DFF

* pack DFF fixes

* Handle MUX flags

* Fix DFF pack

* Prevent pass trough issues

* Cleanup

* Use device wrapper class

* Update due to API changes

* Use pin  connection aliases

* Start work on BUFG support

* Fix CC_L2T5 pack

* Add CPE input inverters

* Constrain routes to have correct inversion state

* Add clock inversion pip

* Added MX2 and MX4 support

* Fix script

* BUFG support

* debug print if route found with wrong polarity

* Some CC_DFF improvements

* Create reproducible chip database

* Simplify inversion of special signals

* Few more DFF features

* Add forgotten virtual port renames

* Handle muxes with constant inputs

* Allow inversion for muxes

* cleanup

* DFF input can be constant

* init DFF only when needed

* cleanup

* Add basic PLL support

* Add some timings

* Add USR_RSTN support

* Display few more primitives

* Use pass trough signals to validate architecture data

* Use extra tile information from chip database

* Updates needed for a build system changes

* Implement SB_DRIVE support

* Properly named configuration bits

* autogenerated constids.inc

* small fix

* Initial code for CPE halfs

* Some cleanup

* make sure FFs are compatible

* reverted due to db change

* Merge DFF where applicable

* memory allocation issue

* fix

* better MX2

* ram_i handling

* Cleanup MX4

* Support latches

* compare L_D flag as well

* Move virtual pips

* Naive addf pack

* carry chains grouping

* Keep chip database reproducible

* split addf vectors

* Block CPEs when GPIO is used

* Prepare placement code

* RAM_I/RAM_O rewrite

* fix ram_i/o index

* Display RAM and add new primitives

* PLL wip code

* CC_PLL_ADV packing

* PLL handling cleanup

* Add PLL comments

* Keep only high fan-out BUFG

* Add skeleton for tests

* Utilize move_ram_o

* GPIO wip

* GPIO wip

* PLL fixes

* cleanup

* FF_OBF support

* Handle FF_IBF

* Make SLEW FAST if not defined as in latest p_r

* Make sure FF_OBF only driving GPIO

* Moved pll calc into separate file

* IDDR handling and started ODDR

* Route DDR input for CC_ODDR

* Notify error in case ODDR or IDDR are used but not with I/O pin

* cleanup for CC_USR_RSTN

* Extract proper RAM location  for bitstream

* Code cleanup

* Allow auto place of pads

* Use clock source flag

* Configure GPIO clock signals

* Handle conflicting clk

* Use BUGF in proper order

* Connected CLK, works without but good for debugging

* CC_CFG_CTRL placement

* Group RAM data 40 bytes per row

* Write BRAM content

* RAM wip

* Use relative constraints from chipdb

* fix broken build

* Memory wip

* Handle custom clock for memories

* Support FIFO

* optimize move_ram_io

* Fix SR signal handling acorrding to findings

* set placer beta

* Pre place what we can

* Revert "debug print if route found with wrong polarity"

This reverts commit cf9ded2f18.

* Revert "Constrain routes to have correct inversion state"

This reverts commit 795c284d48.

* Remove virtual pips

* Implement post processing inversion

* ADDF add ability to route additional CO

* Merge two ADDFs in one CPE

* Added TODO

* clangformat

* Cleanup

* Add serdes handling in config file

* Cleanup

* Cleanup

* Cleanup

* Fix in PLL handling

* Fixed ADDF edge case

* No need for this

* Fix latch

* Sanity checks

* Support CC_BRAM_20K merge

* Start creating testing environment

* LVDS fixes

* Add connection helper

* Cleanup

* Fix tabs

* Formatting fix

* Remove optimization tests for now

* remove read_bitstream

* removed .c_str()

* Removed config parsing

* using snake_case

* Use bool_or_default where applicable

* refactored bitstream write code

* Add allow-unconstrained option

* Update DFF related messages

* Add clock constraint propagation

---------

Co-authored-by: Lofty <dan.ravensloft@gmail.com>
2025-04-22 16:41:01 +02:00
.github ci: test that BUILD_RUST=ON builds (#1459) 2025-03-03 14:44:33 +01:00
3rdparty rust: add getBels() binding (#1460) 2025-03-19 10:02:34 +01:00
bba Prevent chipdb array type narrowing conversion issues 2025-02-01 05:28:29 +00:00
cmake CMake: fix windows BBA resource embedding 2025-01-23 11:15:34 +00:00
common placer1: add sanity check for try_swap_chain (#1472) 2025-04-13 19:11:11 +02:00
docs Add arch API function for pip inversion (#1457) 2025-02-27 12:21:15 +01:00
ecp5 ecp5: Fix constant and inverted CEMUX 2025-01-27 11:46:25 +01:00
frontend frontend: don't connect a const net to ports connected to `x`. (#1447) 2025-01-31 08:29:58 +00:00
generic generic: Fix archcheck crash 2025-02-25 15:28:46 +00:00
gui Gowin: Remove nextpnr-gowin (#1318) 2025-02-14 00:08:12 +00:00
himbaechel Gatemate FPGA initial support (#1473) 2025-04-22 16:41:01 +02:00
ice40 CMake: Add include guards when IMPORT_BBA_FILES is used (#1438) 2025-01-23 10:54:37 +01:00
json CMake: refactor architecture-specific build system parts. 2025-01-21 17:13:03 +00:00
machxo2 CMake: Add include guards when IMPORT_BBA_FILES is used (#1438) 2025-01-23 10:54:37 +01:00
mistral CMake: refactor architecture-specific build system parts. 2025-01-21 17:13:03 +00:00
nexus CMake: Add include guards when IMPORT_BBA_FILES is used (#1438) 2025-01-23 10:54:37 +01:00
python router2: additional heatmap data 2024-10-02 16:29:55 +02:00
rust rust: add getBels() binding (#1460) 2025-03-19 10:02:34 +01:00
tests@ce15412181 CMake: refactor architecture-specific build system parts. 2025-01-21 17:13:03 +00:00
.clang-format Set clangformat column limit to 120 2018-06-23 15:26:07 +02:00
.gitignore Gowin: Remove nextpnr-gowin (#1318) 2025-02-14 00:08:12 +00:00
.gitmodules Remove fpga_interchange 2024-09-30 13:10:30 +02:00
CMakeLists.txt Gowin: Remove nextpnr-gowin (#1318) 2025-02-14 00:08:12 +00:00
CODE_OF_CONDUCT Added a code of conduct, which was taken from the YosysHQ/yosys repo 2023-08-08 16:52:08 +02:00
COPYING Fixing old emails and names in copyrights 2021-06-12 13:22:38 +01:00
README.md Update README to mention checking out submodules. 2025-01-28 03:07:57 +00:00
shell.nix Update shell.nix (#1347) 2024-08-12 16:29:26 +02:00

README.md

nextpnr -- a portable FPGA place and route tool

nextpnr aims to be a vendor neutral, timing driven, FOSS FPGA place and route tool.

Currently nextpnr supports:

There is some work in progress towards support for Xilinx devices but it is not upstream and not intended for end users at the present time. We hope to see more FPGA families supported in the future. We would love your help in developing this awesome new project!

A brief (academic) paper describing the Yosys+nextpnr flow can be found on arXiv.

Here is a screenshot of nextpnr for iCE40. Build instructions and getting started notes can be found below.

See also:

Prerequisites

The following packages need to be installed for building nextpnr, independent of the selected architecture:

  • CMake 3.13 or later
  • Modern C++17 compiler (clang-format required for development)
  • Python 3.5 or later, including development libraries (python3-dev for Ubuntu)
    • Python 3.9 or later is required for nextpnr-himbaechel
    • on Windows make sure to install same version as supported by vcpkg
  • 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)
  • Eigen3 (libeigen3-dev for Ubuntu) is required to build the analytic placer
  • Latest git Yosys is required to synthesise the demo design
  • For building on Windows with MSVC, usage of vcpkg is advised for dependency installation.
    • 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
    • For static builds, add -static to each of the package names. For example, change eigen3:x64-windows to eigen3:x64-windows-static
    • A copy of Python that matches the version in vcpkg (currently Python 3.6.4). You can download the Embeddable Zip File and extract it. You may need to extract python36.zip within the embeddable zip file to a new directory called "Lib".
  • For building on macOS, brew utility is needed.
    • Install all needed packages brew install cmake python boost eigen

Getting started

First of all, run:

git submodule update --init --recursive

nextpnr-ice40

For iCE40 support, install Project 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:

mkdir -p build && cd build
cmake .. -DARCH=ice40
make -j$(nproc)
sudo make install

On Windows, you may specify paths explicitly:

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

To build a static release, change the target triplet from x64-windows to x64-windows-static and add -DBUILD_STATIC=ON.

A simple example that runs on the iCEstick dev board can be found in ice40/examples/blinky/blinky.*. Usage example:

cd ice40/examples/blinky
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

Running nextpnr in GUI mode (see below for instructions on building nextpnr with GUI support):

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

For ECP5 support, install Project Trellis 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:

mkdir -p build && cd build
cmake .. -DARCH=ecp5 -DTRELLIS_INSTALL_PREFIX=/usr/local
make -j$(nproc)
sudo make install

nextpnr-nexus

For Nexus support, install Project Oxide 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:

mkdir -p build && cd build
cmake .. -DARCH=nexus -DOXIDE_INSTALL_PREFIX=$HOME/.cargo
make -j$(nproc)
sudo make install

Nexus support is currently experimental, and has only been tested with engineering sample silicon.

nextpnr-generic

The generic target allows running placement and routing for arbitrary custom architectures.

mkdir -p build && cd build
cmake .. -DARCH=generic
make -j$(nproc)
sudo make install

An example of how to use the generic flow is in generic/examples. See also the Generic Architecture docs.

nextpnr-himbaechel

The himbaechel target allows running placement and routing for larger architectures that share a common structure.

gowin

For Gowin support, install Project Apicula

mkdir -p build && cd build
cmake .. -DARCH="himbaechel" -DHIMBAECHEL_UARCH="gowin"
make -j$(nproc)
sudo make install

ng-ultra

For NanoXplore NG-Ultra support, clone Project Beyond DB repo

mkdir -p build && cd build
cmake .. -DARCH="himbaechel" -DHIMBAECHEL_UARCH="ng-ultra" -DHIMBAECHEL_PRJBEYOND_DB=/path/to/prjbeyond-db -DHIMBAECHEL_NGULTRA_DEVICES=ng-ultra
make -j$(nproc)
sudo make install

Please note that binary bitstream creation requires Impulse tool from NanoXplore.

GUI

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 and OpenGL are available:

  • On Ubuntu 22.04 LTS, install qtcreator qtbase5-dev qt5-qmake
  • On other Ubuntu versions, install qt5-default
  • 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

Multiple architectures

To build nextpnr for multiple architectures at once, a semicolon-separated list can be used with -DARCH.

mkdir -p build && cd build
cmake .. -DARCH="ice40;ecp5"
make -j$(nproc)
sudo make install

To build every available stable architecture, use -DARCH=all. To include experimental arches (currently nexus), use -DARCH=all+alpha.

Per-microarchitecture Himbächel

To build a single nextpnr-himbachel executable for each of the supported microarchitectures, use -DHIMBAECHEL_SPLIT.

mkdir -p build && cd build
cmake .. -DARCH="himbaechel" -DHIMBAECHEL_UARCH="gowin;ng-ultra"
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.

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:

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:

mkdir -p build && cd build
cmake .. -DARCH=ice40 -DCMAKE_BUILD_TYPE=Debug -DBUILD_PYTHON=OFF -DICE40_DEVICES=1k
make -j$(nproc)

To make static build release for iCE40 architecture use the following:

mkdir -p build && cd build
cmake .. -DARCH=ice40 -DBUILD_PYTHON=OFF -DSTATIC_BUILD=ON
make -j$(nproc)

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).

You can change the location where nextpnr will be installed (this will usually default to /usr/local) by using -DCMAKE_INSTALL_PREFIX=/install/prefix.

Notes for developers

  • All code is formatted using clang-format according to the style rules in .clang-format (LLVM based with 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.

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.
  • Manually start all PnR operations you wish
  • Click on recording icon again to stop recording
  • Go to directory containing files and execute ffmpeg -f image2 -r 1 -i movie_%05d.png -c:v libx264 nextpnr.mp4

Testing

  • 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.
  • 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
  • Running tests with code coverage use -DBUILD_TESTS=ON -DCOVERAGE and after make run make ice40-coverage
  • 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

Synthesis, simulation, and logic optimization

FPGA bitstream documentation (and tools) projects

Other FOSS FPGA place and route projects