From 6bac72cd6858faa52d6e46be787b936630c287a7 Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Mon, 13 Oct 2025 11:40:26 +0200 Subject: [PATCH] Global: added option to select/deselect all cables, added variables ENABLE_xxx to enable corresponding cables. Some vendor drivers needs to to be disabled accordlingly --- CMakeLists.txt | 572 ++++++++++++++++++++++++++++++++------------ src/colognechip.cpp | 9 + src/colognechip.hpp | 4 + src/jtag.cpp | 52 +++- src/main.cpp | 19 ++ src/usbBlaster.cpp | 16 ++ src/usbBlaster.hpp | 8 + 7 files changed, 530 insertions(+), 150 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c3e0860..9962d98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,27 +3,94 @@ cmake_minimum_required(VERSION 3.5) # set the project name project(openFPGALoader VERSION "1.0.0" LANGUAGES CXX) add_definitions(-DVERSION=\"v${PROJECT_VERSION}\") -option(ENABLE_OPTIM "Enable build with -O3 optimization level" ON) -option(BUILD_STATIC "Whether or not to build with static libraries" OFF) + +#################################################################################################### +# Generics Options +#################################################################################################### + +option(ENABLE_OPTIM "Enable build with -O3 optimization level" ON) +option(BUILD_STATIC "Whether or not to build with static libraries" OFF) +option(USE_PKGCONFIG "Use pkgconfig to find libraries" ON) +option(LINK_CMAKE_THREADS "Use CMake find_package to link the threading library" OFF) + if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(ENABLE_UDEV OFF) else() option(ENABLE_UDEV "use udev to search JTAG adapter from /dev/xx" ON) endif() -option(ENABLE_CMSISDAP "enable cmsis DAP interface (requires hidapi)" ON) -option(ENABLE_GOWIN_GWU2X "enable Gowin GWU2X interface" ON) -if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - option(ENABLE_LIBGPIOD "enable libgpiod bitbang driver (requires libgpiod)" ON) - option(ENABLE_REMOTEBITBANG "enable remote bitbang driver" ON) -else() - set(ENABLE_LIBGPIOD OFF) - set(ENABLE_REMOTEBITBANG OFF) -endif() -option(USE_PKGCONFIG "Use pkgconfig to find libraries" ON) -option(LINK_CMAKE_THREADS "Use CMake find_package to link the threading library" OFF) -set(BLASTERII_PATH "" CACHE STRING "usbBlasterII firmware directory") + +option(ENABLE_USB_SCAN "Enable USB Scan option" ON) + +#################################################################################################### +# CABLES Options +#################################################################################################### + +# set all cable on by default +option(ENABLE_CABLE_ALL "Enable all cables" ON) + +option(ENABLE_ANLOGIC_CABLE "enable Anlogic cable (requires libUSB)" ${ENABLE_CABLE_ALL}) +option(ENABLE_CH347 "enable CH347 cable (requires libUSB)" ${ENABLE_CABLE_ALL}) +option(ENABLE_CMSISDAP "enable cmsis DAP interface (requires hidapi)" ${ENABLE_CABLE_ALL}) +option(ENABLE_DIRTYJTAG "enable dirtyJtag cable (requires libUSB)" ${ENABLE_CABLE_ALL}) +option(ENABLE_ESP_USB "enable ESP32S3 cable (requires libUSB)" ${ENABLE_CABLE_ALL}) +option(ENABLE_JLINK "enable JLink cable (requires libUSB)" ${ENABLE_CABLE_ALL}) +option(ENABLE_DFU "enable DFU support (requires libUSB)" ${ENABLE_CABLE_ALL}) +option(ENABLE_FTDI_BASED_CABLE "enable cables based on FTDI (requires libFTDI" ${ENABLE_CABLE_ALL}) +option(ENABLE_GOWIN_GWU2X "enable Gowin GWU2X interface" ${ENABLE_CABLE_ALL}) +option(ENABLE_USB_BLASTERI "enable Altera USB Blaster I support" ${ENABLE_CABLE_ALL}) +option(ENABLE_USB_BLASTERII "enable Altera USB Blaster II support" ${ENABLE_CABLE_ALL}) + +set(BLASTERII_PATH "" CACHE STRING "usbBlasterII firmware directory") set(ISE_PATH "/opt/Xilinx/14.7" CACHE STRING "ise root directory (default: /opt/Xilinx/14.7)") +# Libgpiod, XVC and RemoteBitbang are only available on Linux OS. +if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + option(ENABLE_LIBGPIOD "enable libgpiod bitbang driver (requires libgpiod)" ${ENABLE_CABLE_ALL}) + option(ENABLE_REMOTEBITBANG "enable remote bitbang driver" ${ENABLE_CABLE_ALL}) + option(ENABLE_XILINX_VIRTUAL_CABLE "enable Xilinx Virtual Cable (XVC) support" ${ENABLE_CABLE_ALL}) +else() + set(ENABLE_LIBGPIOD OFF) + set(ENABLE_REMOTEBITBANG OFF) + set(ENABLE_XILINX_VIRTUAL_CABLE OFF) +endif() + +#################################################################################################### +# Variables +#################################################################################################### + +# set dependencies +set(USE_FX2_LL OFF) +set(USE_LIBFTDI OFF) +set(USE_LIBUSB OFF) +set(USE_LIBUSB_LL OFF) + +# Only adds libftdi as dependency when a cable +# need this library. +if (ENABLE_FTDI_BASED_CABLE OR ENABLE_USB_BLASTERI OR ENABLE_XILINX_VIRTUAL_CABLE) + set(USE_LIBFTDI ON) +else() + message("disabled all cables based on FTDI devices") +endif(ENABLE_FTDI_BASED_CABLE OR ENABLE_USB_BLASTERI OR ENABLE_XILINX_VIRTUAL_CABLE) + +# Only adds libusb as dependency when a cable need this library +if (ENABLE_DFU OR ENABLE_ANLOGIC_CABLE OR ENABLE_CH347 OR ENABLE_DIRTYJTAG + OR ENABLE_ESP_USB OR ENABLE_JLINK OR ENABLE_GOWIN_GWU2X OR ENABLE_USB_BLASTERII OR ENABLE_USB_SCAN) + set(USE_LIBUSB ON) +endif() + +if (ENABLE_USB_SCAN OR ENABLE_GOWIN_GWU2X) + set(USE_LIBUSB_LL ON) +endif() + +# Only enable fx2_ll when cable using it +if (ENABLE_USB_BLASTERII) + set(USE_FX2_LL ON) +endif() + +#################################################################################################### +# Build options +#################################################################################################### + ## specify the C++ standard set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED True) @@ -42,19 +109,39 @@ include(GNUInstallDirs) add_definitions(-DDATA_DIR=\"${CMAKE_INSTALL_FULL_DATAROOTDIR}\") add_definitions(-DISE_DIR=\"${ISE_PATH}\") -add_definitions(-DBLASTERII_DIR=\"${BLASTERII_PATH}\") + +#################################################################################################### +# Dependencies check/search +#################################################################################################### if (USE_PKGCONFIG) find_package(PkgConfig REQUIRED) - pkg_check_modules(LIBFTDI REQUIRED libftdi1) - pkg_check_modules(LIBUSB REQUIRED libusb-1.0) + + if (USE_LIBFTDI) + pkg_check_modules(LIBFTDI REQUIRED libftdi1) + else() + set(LIBFTDI_LIBRARY_DIRS "") + set(LIBFTDI_INCLUDE_DIRS "") + set(LIBFTDI_LIBRARIES "") + endif(USE_LIBFTDI) + + if (USE_LIBUSB) + pkg_check_modules(LIBUSB REQUIRED libusb-1.0) + else() + set(LIBUSB_LIBRARY_DIRS "") + set(LIBUSB_INCLUDE_DIRS "") + set(LIBUSB_LIBRARIES "") + endif(USE_LIBUSB) + + if(ENABLE_CMSISDAP) pkg_check_modules(HIDAPI hidapi-libusb) - # if libusb not found try with hidraw - if (NOT HIDAPI_FOUND) - pkg_check_modules(HIDAPI hidapi-hidraw) - endif() - if (NOT HIDAPI_FOUND) - pkg_check_modules(HIDAPI hidapi) + # if libusb not found try with hidraw + if (NOT HIDAPI_FOUND) + pkg_check_modules(HIDAPI hidapi-hidraw) + endif() + if (NOT HIDAPI_FOUND) + pkg_check_modules(HIDAPI hidapi) + endif() endif() # zlib support (gzip) pkg_check_modules(ZLIB zlib) @@ -87,120 +174,248 @@ if (USE_PKGCONFIG) endif() endif() +#################################################################################################### +# FILES +#################################################################################################### + +# =========================== +# Core Classes +# =========================== set(OPENFPGALOADER_SOURCE - src/anlogic.cpp - src/anlogicBitParser.cpp - src/anlogicCable.cpp - src/ch552_jtag.cpp src/common.cpp - src/dfu.cpp - src/dfuFileParser.cpp - src/dirtyJtag.cpp - src/ch347jtag.cpp - src/efinix.cpp - src/efinixHexParser.cpp - src/fx2_ll.cpp - src/ihexParser.cpp - src/pofParser.cpp - src/rawParser.cpp - src/spiFlash.cpp - src/spiInterface.cpp - src/usbBlaster.cpp - src/epcq.cpp - src/svf_jtag.cpp - src/display.cpp - src/jtag.cpp - src/ftdiJtagBitbang.cpp - src/ftdiJtagMPSSE.cpp src/configBitstreamParser.cpp - src/ftdipp_mpsse.cpp - src/main.cpp - src/libusb_ll.cpp - src/gowin.cpp src/device.cpp - src/jlink.cpp + src/display.cpp + src/main.cpp src/progressBar.cpp - src/fsparser.cpp - src/mcsParser.cpp - src/ftdispi.cpp - src/altera.cpp - src/bitparser.cpp - src/xilinx.cpp - src/xilinxMapParser.cpp - src/colognechip.cpp - src/colognechipCfgParser.cpp - src/esp_usb_jtag.cpp ) set(OPENFPGALOADER_HEADERS + src/board.hpp + src/cable.hpp + src/common.hpp + src/configBitstreamParser.hpp + src/cxxopts.hpp + src/device.hpp + src/display.hpp + src/part.hpp + src/progressBar.hpp +) + +# =========================== +# Parsers classes +# =========================== +list(APPEND OPENFPGALOADER_SOURCE + src/anlogicBitParser.cpp + src/bitparser.cpp + src/fsparser.cpp + src/ihexParser.cpp + src/mcsParser.cpp + src/pofParser.cpp + src/rawParser.cpp + src/xilinxMapParser.cpp +) + +list(APPEND OPENFPGALOADER_HEADERS + src/anlogicBitParser.hpp + src/bitparser.hpp + src/fsparser.hpp + src/ihexParser.hpp + src/mcsParser.hpp + src/pofParser.hpp + src/rawParser.hpp + src/xilinxMapParser.hpp +) + +# =========================== +# To be sorted +# =========================== +list(APPEND OPENFPGALOADER_SOURCE + src/anlogic.cpp + src/spiFlash.cpp + src/spiInterface.cpp + src/epcq.cpp + src/svf_jtag.cpp + src/jtag.cpp + src/gowin.cpp + src/altera.cpp + src/xilinx.cpp +) + +list(APPEND OPENFPGALOADER_HEADERS src/altera.hpp src/anlogic.hpp - src/anlogicBitParser.hpp - src/anlogicCable.hpp - src/ch552_jtag.hpp - src/common.hpp - src/cxxopts.hpp - src/dfu.hpp - src/dfuFileParser.hpp - src/dirtyJtag.hpp - src/ch347jtag.hpp - src/efinix.hpp - src/efinixHexParser.hpp - src/fx2_ll.hpp - src/ihexParser.hpp - src/pofParser.hpp - src/progressBar.hpp - src/rawParser.hpp - src/usbBlaster.hpp - src/bitparser.hpp - src/ftdiJtagBitbang.hpp - src/ftdiJtagMPSSE.hpp - src/jlink.hpp src/jtag.hpp src/jtagInterface.hpp - src/libusb_ll.hpp - src/fsparser.hpp - src/part.hpp - src/board.hpp - src/display.hpp - src/mcsParser.hpp - src/ftdipp_mpsse.hpp src/spiFlash.hpp src/spiFlashdb.hpp src/epcq.hpp src/spiInterface.hpp src/svf_jtag.hpp - src/configBitstreamParser.hpp - src/device.hpp src/gowin.hpp - src/cable.hpp - src/ftdispi.hpp src/xilinx.hpp - src/xilinxMapParser.hpp - src/colognechip.hpp - src/colognechipCfgParser.hpp - src/esp_usb_jtag.hpp ) +# FTDI Based cables +if (${USE_LIBFTDI}) + add_definitions(-DUSE_LIBFTDI) + + list(APPEND OPENFPGALOADER_SOURCE + src/ch552_jtag.cpp + src/ftdiJtagBitbang.cpp + src/ftdiJtagMPSSE.cpp + src/ftdipp_mpsse.cpp + src/ftdispi.cpp + ) + + list(APPEND OPENFPGALOADER_HEADERS + src/ch552_jtag.hpp + src/ftdiJtagBitbang.hpp + src/ftdiJtagMPSSE.hpp + src/ftdipp_mpsse.hpp + src/ftdispi.hpp + ) + + # CologneChip Drivers / Files parsers. + list(APPEND OPENFPGALOADER_SOURCE + src/colognechip.cpp + src/colognechipCfgParser.cpp + ) + + list(APPEND OPENFPGALOADER_HEADERS + src/colognechip.hpp + src/colognechipCfgParser.hpp + ) + + # Efinix Drivers / Files parsers. + list(APPEND OPENFPGALOADER_SOURCE + src/efinix.cpp + src/efinixHexParser.cpp + ) + + list(APPEND OPENFPGALOADER_HEADERS + src/efinix.hpp + src/efinixHexParser.hpp + ) + + # Lattice Drivers / Files parsers. + list(APPEND OPENFPGALOADER_SOURCE + src/ice40.cpp + src/latticeSSPI.cpp + ) + list(APPEND OPENFPGALOADER_HEADERS + src/ice40.hpp + src/latticeSSPI.hpp + ) +endif() + # Lattice Drivers / Files parsers. list(APPEND OPENFPGALOADER_SOURCE - src/ice40.cpp src/lattice.cpp - src/latticeSSPI.cpp src/feaparser.cpp src/jedParser.cpp src/latticeBitParser.cpp ) list(APPEND OPENFPGALOADER_HEADERS - src/ice40.hpp src/lattice.hpp - src/latticeSSPI.hpp src/jedParser.hpp src/feaparser.hpp src/latticeBitParser.hpp ) +# Cables select + +# DFU +if (ENABLE_DFU) +list(APPEND OPENFPGALOADER_SOURCE + src/dfu.cpp + src/dfuFileParser.cpp +) + +list(APPEND OPENFPGALOADER_HEADERS + src/dfu.hpp + src/dfuFileParser.hpp +) +endif(ENABLE_DFU) + +# Anlogic Cable +if (ENABLE_ANLOGIC_CABLE) +list(APPEND OPENFPGALOADER_SOURCE src/anlogicCable.cpp) +list(APPEND OPENFPGALOADER_HEADERS src/anlogicCable.hpp) +endif() + +# CH347 +if (ENABLE_CH347) +list(APPEND OPENFPGALOADER_SOURCE src/ch347jtag.cpp) +list(APPEND OPENFPGALOADER_HEADERS src/ch347jtag.hpp) +endif() + +# dirtyJtag +if (ENABLE_DIRTYJTAG) +list(APPEND OPENFPGALOADER_SOURCE src/dirtyJtag.cpp) +list(APPEND OPENFPGALOADER_HEADERS src/dirtyJtag.hpp) +endif() + +# ESP32S3 +if (ENABLE_ESP_USB) +list(APPEND OPENFPGALOADER_SOURCE src/esp_usb_jtag.cpp) +list(APPEND OPENFPGALOADER_HEADERS src/esp_usb_jtag.hpp) +endif() + +# Gowin GWU2X JTAG interface +if(ENABLE_GOWIN_GWU2X) +list(APPEND OPENFPGALOADER_SOURCE src/gwu2x_jtag.cpp) +list(APPEND OPENFPGALOADER_HEADERS src/gwu2x_jtag.hpp) +endif() + +# Jetson Nano (libGPIO based) +if (ENABLE_JETSONNANOGPIO) +list(APPEND OPENFPGALOADER_SOURCE src/jetsonNanoJtagBitbang.cpp) +list(APPEND OPENFPGALOADER_HEADERS src/jetsonNanoJtagBitbang.hpp) +endif() + +# JLINK +if (ENABLE_JLINK) +list(APPEND OPENFPGALOADER_SOURCE src/jlink.cpp) +list(APPEND OPENFPGALOADER_HEADERS src/jlink.hpp) +endif() + +# libGPIOD support +if (ENABLE_LIBGPIOD) +list(APPEND OPENFPGALOADER_SOURCE src/libgpiodJtagBitbang.cpp) +list(APPEND OPENFPGALOADER_HEADERS src/libgpiodJtagBitbang.hpp) +endif() + +# RemoteBitbang +if (ENABLE_REMOTEBITBANG) +list (APPEND OPENFPGALOADER_SOURCE src/remoteBitbang_client.cpp) +list (APPEND OPENFPGALOADER_HEADERS src/remoteBitbang_client.hpp) +endif() + +# Xilinx Virtual Cable +if (ENABLE_XILINX_VIRTUAL_CABLE) +list (APPEND OPENFPGALOADER_SOURCE src/xvc_client.cpp src/xvc_server.cpp) +list (APPEND OPENFPGALOADER_HEADERS src/xvc_client.hpp src/xvc_server.hpp) +endif() + +# Altera USB Blaster (I & II). +if (ENABLE_USB_BLASTERI OR ENABLE_USB_BLASTERII) + add_definitions(-DENABLE_USBBLASTER) + + if (ENABLE_USB_BLASTERI) + add_definitions(-DENABLE_USB_BLASTERI) + endif() + + if (ENABLE_USB_BLASTERII) + add_definitions(-DBLASTERII_DIR=\"${BLASTERII_PATH}\") + add_definitions(-DENABLE_USB_BLASTERII) + endif (ENABLE_USB_BLASTERII) + + list(APPEND OPENFPGALOADER_SOURCE src/usbBlaster.cpp) + list(APPEND OPENFPGALOADER_HEADERS src/usbBlaster.hpp) +endif(ENABLE_USB_BLASTERI OR ENABLE_USB_BLASTERII) + link_directories( ${LIBUSB_LIBRARY_DIRS} ${LIBFTDI_LIBRARY_DIRS} @@ -214,6 +429,16 @@ if (ENABLE_CMSISDAP AND HIDAPI_FOUND) link_directories(${HIDAPI_LIBRARY_DIRS}) endif() +if (USE_LIBUSB_LL) +list(APPEND OPENFPGALOADER_SOURCE src/libusb_ll.cpp) +list(APPEND OPENFPGALOADER_HEADERS src/libusb_ll.hpp) +endif() + +if (USE_FX2_LL) +list(APPEND OPENFPGALOADER_SOURCE src/fx2_ll.cpp) +list(APPEND OPENFPGALOADER_HEADERS src/fx2_ll.hpp) +endif() + add_executable(openFPGALoader ${OPENFPGALOADER_SOURCE} ${OPENFPGALOADER_HEADERS} @@ -229,16 +454,6 @@ target_link_libraries(openFPGALoader ${LIBFTDI_LIBRARIES} ) -# Gowin GWU2X JTAG interface -if(ENABLE_GOWIN_GWU2X) - target_sources(openFPGALoader PRIVATE src/gwu2x_jtag.cpp) - list (APPEND OPENFPGALOADER_HEADERS src/gwu2x_jtag.hpp) - add_definitions(-DENABLE_GOWIN_GWU2X=1) - message("Gowin GWU2X support enabled") -else() - message("Gowin GWU2X support disabled") -endif() - if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") # winsock provides ntohs target_link_libraries(openFPGALoader ws2_32) @@ -257,27 +472,6 @@ if (ENABLE_UDEV) target_link_libraries(openFPGALoader ${LIBUDEV_LIBRARIES}) endif() -if (ENABLE_LIBGPIOD) - include_directories(${LIBGPIOD_INCLUDE_DIRS}) - target_link_libraries(openFPGALoader ${LIBGPIOD_LIBRARIES}) - add_definitions(-DENABLE_LIBGPIOD=1) - target_sources(openFPGALoader PRIVATE src/libgpiodJtagBitbang.cpp) - list (APPEND OPENFPGALOADER_HEADERS src/libgpiodJtagBitbang.hpp) - if (LIBGPIOD_VERSION VERSION_GREATER_EQUAL 2) - message("libgpiod v2 support enabled") - add_definitions(-DGPIOD_APIV2) - else() - message("libgpiod v1 support enabled") - endif() -endif(ENABLE_LIBGPIOD) - -if (ENABLE_JETSONNANOGPIO) - add_definitions(-DENABLE_JETSONNANOGPIO=1) - target_sources(openFPGALoader PRIVATE src/jetsonNanoJtagBitbang.cpp) - list (APPEND OPENFPGALOADER_HEADERS src/jetsonNanoJtagBitbang.hpp) - message("Jetson Nano GPIO support enabled") -endif(ENABLE_JETSONNANOGPIO) - if (ENABLE_UDEV OR ENABLE_LIBGPIOD OR ENABLE_JETSONNANOGPIO) add_definitions(-DUSE_DEVICE_ARG) endif(ENABLE_UDEV OR ENABLE_LIBGPIOD OR ENABLE_JETSONNANOGPIO) @@ -286,6 +480,22 @@ if (BUILD_STATIC) set_target_properties(openFPGALoader PROPERTIES LINK_SEARCH_END_STATIC 1) endif() +# Anlogic Cable +if (ENABLE_ANLOGIC_CABLE) + add_definitions(-DENABLE_ANLOGIC_CABLE=1) + message("Anlogic Cable support enabled") +else() + message("Anlogic Cable support disabled") +endif() + +# CH347 +if (ENABLE_CH347) + add_definitions(-DENABLE_CH347=1) + message("CH347 support enabled") +else() + message("CH347 support disabled") +endif() + if (ENABLE_CMSISDAP) if (HIDAPI_FOUND) include_directories(${HIDAPI_INCLUDE_DIRS}) @@ -299,25 +509,85 @@ if (ENABLE_CMSISDAP) endif() endif(ENABLE_CMSISDAP) -if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - add_definitions(-DENABLE_XVC=1) - target_sources(openFPGALoader PRIVATE src/xvc_client.cpp src/xvc_server.cpp) - list (APPEND OPENFPGALOADER_HEADERS src/xvc_client.hpp src/xvc_server.hpp) - set(CMAKE_EXE_LINKER_FLAGS "-pthread ${CMAKE_EXE_LINKER_FLAGS}") - message("Xilinx Virtual Server support enabled") +# DFU +if (ENABLE_DFU) + add_definitions(-DENABLE_DFU=1) + message("DFU support enabled") else() - message("Xilinx Virtual Server support disabled") + message("DFU support disabled") endif() +# dirtyJtag +if (ENABLE_DIRTYJTAG) + add_definitions(-DENABLE_DIRTYJTAG=1) + message("dirtyJtag support enabled") +else() + message("dirtyJtag support disabled") +endif() + +# ESP32S3 +if (ENABLE_ESP_USB) + add_definitions(-DENABLE_ESP_USB=1) + message("ESP32S3 support enabled") +else() + message("ESP32S3 support disabled") +endif() + +# Gowin GWU2X JTAG interface +if(ENABLE_GOWIN_GWU2X) + add_definitions(-DENABLE_GOWIN_GWU2X=1) + message("Gowin GWU2X support enabled") +else() + message("Gowin GWU2X support disabled") +endif() + +# Jetson Nano (libGPIO based) +if (ENABLE_JETSONNANOGPIO) + add_definitions(-DENABLE_JETSONNANOGPIO=1) + message("Jetson Nano GPIO support enabled") +endif(ENABLE_JETSONNANOGPIO) + +# JLINK +if (ENABLE_JLINK) + add_definitions(-DENABLE_JLINK=1) + message("JLink support enabled") +else() + message("JLink support disabled") +endif() + +# libGPIOD support +if (ENABLE_LIBGPIOD) + include_directories(${LIBGPIOD_INCLUDE_DIRS}) + target_link_libraries(openFPGALoader ${LIBGPIOD_LIBRARIES}) + add_definitions(-DENABLE_LIBGPIOD=1) + if (LIBGPIOD_VERSION VERSION_GREATER_EQUAL 2) + message("libgpiod v2 support enabled") + add_definitions(-DGPIOD_APIV2) + else() + message("libgpiod v1 support enabled") + endif() +endif(ENABLE_LIBGPIOD) + if (ENABLE_REMOTEBITBANG) add_definitions(-DENABLE_REMOTEBITBANG=1) - target_sources(openFPGALoader PRIVATE src/remoteBitbang_client.cpp) - list (APPEND OPENFPGALOADER_HEADERS src/remoteBitbang_client.hpp) message("Remote bitbang client support enabled") else() message("Remote bitbang client support disabled") endif() +if (ENABLE_XILINX_VIRTUAL_CABLE) + add_definitions(-DENABLE_XVC=1) + set(CMAKE_EXE_LINKER_FLAGS "-pthread ${CMAKE_EXE_LINKER_FLAGS}") + message("Xilinx Virtual Server support enabled") +else() + message("Xilinx Virtual Server support disabled") +endif() + +# USB Devices Scan +if (ENABLE_USB_SCAN) + add_definitions("-DENABLE_USB_SCAN=1") +endif() + if (ZLIB_FOUND) include_directories(${ZLIB_INCLUDE_DIRS}) target_link_libraries(openFPGALoader ${ZLIB_LIBRARIES}) @@ -331,17 +601,23 @@ if (LINK_CMAKE_THREADS) target_link_libraries(openFPGALoader Threads::Threads) endif() -# libftdi < 1.4 as no usb_addr -# libftdi >= 1.5 as purge_buffer obsolete -string(REPLACE "." ";" VERSION_LIST ${LIBFTDI_VERSION}) -list(GET VERSION_LIST 0 LIBFTDI_VERSION_MAJOR) -list(GET VERSION_LIST 1 LIBFTDI_VERSION_MINOR) -math(EXPR FTDI_VAL "${LIBFTDI_VERSION_MAJOR} * 100 + ${LIBFTDI_VERSION_MINOR}") +if (USE_LIBFTDI) + # libftdi < 1.4 as no usb_addr + # libftdi >= 1.5 as purge_buffer obsolete + string(REPLACE "." ";" VERSION_LIST ${LIBFTDI_VERSION}) + list(GET VERSION_LIST 0 LIBFTDI_VERSION_MAJOR) + list(GET VERSION_LIST 1 LIBFTDI_VERSION_MINOR) + math(EXPR FTDI_VAL "${LIBFTDI_VERSION_MAJOR} * 100 + ${LIBFTDI_VERSION_MINOR}") + add_definitions(-DFTDI_VERSION=${FTDI_VAL}) +endif() -add_definitions(-DFTDI_VERSION=${FTDI_VAL}) install(TARGETS openFPGALoader DESTINATION bin) +#################################################################################################### +# SPIOverJtag bitstreams install +#################################################################################################### + file(GLOB GZ_FILES spiOverJtag/spiOverJtag_*.*.gz) # Compress rbf and bit files present into repository diff --git a/src/colognechip.cpp b/src/colognechip.cpp index 4b6167e..2b10fb6 100644 --- a/src/colognechip.cpp +++ b/src/colognechip.cpp @@ -47,11 +47,16 @@ CologneChip::CologneChip(Jtag* jtag, const std::string &filename, } else if (cable_name == "gatemate_pgm") { ftdi_board_name = "gatemate_pgm_spi"; } else if (cable_name == "dirtyJtag") { +#ifdef ENABLE_DIRTYJTAG _dirtyjtag = reinterpret_cast(_jtag->_jtag); _rstn_pin = (1 << 6); _done_pin = 0; _fail_pin = 0; _oen_pin = 0; +#else + std::cerr << "Jtag: support for dirtyJtag cable was not enabled at compile time" << std::endl; + throw std::exception(); +#endif } if (ftdi_board_name != "") { @@ -90,10 +95,12 @@ void CologneChip::reset() _ftdi_jtag->gpio_clear(_rstn_pin | _oen_pin); usleep(SLEEP_US); _ftdi_jtag->gpio_set(_rstn_pin); +#ifdef ENABLE_DIRTYJTAG } else if (_dirtyjtag) { _dirtyjtag->gpio_clear(_rstn_pin); _dirtyjtag->gpio_set(_rstn_pin); usleep(SLEEP_US); +#endif } } @@ -142,10 +149,12 @@ bool CologneChip::prepare_flash_access() /* enable output and disable reset */ _ftdi_jtag->gpio_clear(_oen_pin); _ftdi_jtag->gpio_set(_rstn_pin); +#ifdef ENABLE_DIRTYJTAG } else if (_dirtyjtag) { _dirtyjtag->gpio_clear(_rstn_pin); _dirtyjtag->gpio_set(_rstn_pin); usleep(SLEEP_US); +#endif } return true; diff --git a/src/colognechip.hpp b/src/colognechip.hpp index 29ec58b..70e6ac0 100644 --- a/src/colognechip.hpp +++ b/src/colognechip.hpp @@ -12,7 +12,9 @@ #include #include "device.hpp" +#ifdef ENABLE_DIRTYJTAG #include "dirtyJtag.hpp" +#endif #include "jtag.hpp" #include "ftdispi.hpp" #include "ftdiJtagMPSSE.hpp" @@ -70,7 +72,9 @@ class CologneChip: public Device, SPIInterface { FtdiSpi *_spi = NULL; FtdiJtagMPSSE *_ftdi_jtag = NULL; +#ifdef ENABLE_DIRTYJTAG DirtyJtag *_dirtyjtag = NULL; +#endif uint16_t _rstn_pin; uint16_t _done_pin; uint16_t _fail_pin; diff --git a/src/jtag.cpp b/src/jtag.cpp index c7ed49e..3fd9785 100644 --- a/src/jtag.cpp +++ b/src/jtag.cpp @@ -12,12 +12,18 @@ #include #include +#ifdef ENABLE_ANLOGIC_CABLE #include "anlogicCable.hpp" +#endif +#ifdef USE_LIBFTDI #include "ch552_jtag.hpp" +#endif #include "display.hpp" #include "jtag.hpp" +#ifdef USE_LIBFTDI #include "ftdiJtagBitbang.hpp" #include "ftdiJtagMPSSE.hpp" +#endif #ifdef ENABLE_GOWIN_GWU2X #include "gwu2x_jtag.hpp" #endif @@ -27,18 +33,28 @@ #ifdef ENABLE_JETSONNANOGPIO #include "jetsonNanoJtagBitbang.hpp" #endif +#ifdef ENABLE_JLINK #include "jlink.hpp" +#endif #ifdef ENABLE_CMSISDAP #include "cmsisDAP.hpp" #endif +#ifdef ENABLE_DIRTYJTAG #include "dirtyJtag.hpp" +#endif +#ifdef ENABLE_ESP_USB_JTAG #include "esp_usb_jtag.hpp" +#endif +#ifdef ENABLE_CH347 #include "ch347jtag.hpp" +#endif #include "part.hpp" #ifdef ENABLE_REMOTEBITBANG #include "remoteBitbang_client.hpp" #endif +#ifdef ENABLE_USBBLASTER #include "usbBlaster.hpp" +#endif #ifdef ENABLE_XVC #include "xvc_client.hpp" #endif @@ -92,8 +108,14 @@ Jtag::Jtag(const cable_t &cable, const jtag_pins_conf_t *pin_conf, { switch (cable.type) { case MODE_ANLOGICCABLE: +#ifdef ENABLE_ANLOGIC_CABLE _jtag = new AnlogicCable(clkHZ); +#else + std::cerr << "Jtag: support for Anlogic cable was not enabled at compile time" << std::endl; + throw std::exception(); +#endif break; +#ifdef USE_LIBFTDI case MODE_FTDI_BITBANG: if (pin_conf == NULL) throw std::exception(); @@ -106,29 +128,55 @@ Jtag::Jtag(const cable_t &cable, const jtag_pins_conf_t *pin_conf, case MODE_CH552_JTAG: _jtag = new CH552_jtag(cable, dev, serial, clkHZ, verbose); break; +#endif case MODE_CH347: +#ifdef ENABLE_CH347 _jtag = new CH347Jtag(clkHZ, verbose, cable.vid, cable.pid, cable.bus_addr, cable.device_addr); +#else + std::cerr << "Jtag: support for CH347 cable was not enabled at compile time" << std::endl; + throw std::exception(); +#endif break; case MODE_DIRTYJTAG: +#ifdef ENABLE_DIRTYJTAG _jtag = new DirtyJtag(clkHZ, verbose); +#else + std::cerr << "Jtag: support for dirtyJtag cable was not enabled at compile time" << std::endl; + throw std::exception(); +#endif break; -#ifdef ENABLE_GOWIN_GWU2X case MODE_GWU2X: +#ifdef ENABLE_GOWIN_GWU2X _jtag = new GowinGWU2x((cable_t *)&cable, clkHZ, verbose); - break; #else std::cerr << "Jtag: support for Gowin GWU2X was not enabled at compile time" << std::endl; throw std::exception(); #endif + break; case MODE_JLINK: +#ifdef ENABLE_JLINK _jtag = new Jlink(clkHZ, verbose, cable.vid, cable.pid); +#else + std::cerr << "Jtag: support for JLink cable was not enabled at compile time" << std::endl; + throw std::exception(); +#endif break; case MODE_ESP: +#ifdef ENABLE_ESP_USB_JTAG _jtag = new esp_usb_jtag(clkHZ, verbose, 0x303a, 0x1001); +#else + std::cerr << "Jtag: support for esp32s3 cable was not enabled at compile time" << std::endl; + throw std::exception(); +#endif break; case MODE_USBBLASTER: +#ifdef ENABLE_USBBLASTER _jtag = new UsbBlaster(cable, firmware_path, verbose); break; +#else + std::cerr << "Jtag: support for usb-blaster was not enabled at compile time" << std::endl; + throw std::exception(); +#endif case MODE_CMSISDAP: #ifdef ENABLE_CMSISDAP _jtag = new CmsisDAP(cable, cable.config.index, verbose); diff --git a/src/main.cpp b/src/main.cpp index 071e9c8..4aca9f6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,9 @@ #include "common.hpp" #include "cxxopts.hpp" #include "device.hpp" +#ifdef ENABLE_DFU #include "dfu.hpp" +#endif #include "display.hpp" #include "efinix.hpp" #include "ftdispi.hpp" @@ -29,7 +31,9 @@ #include "ice40.hpp" #include "lattice.hpp" #include "latticeSSPI.hpp" +#ifdef ENABLE_USB_SCAN #include "libusb_ll.hpp" +#endif #include "jtag.hpp" #include "part.hpp" #include "spiFlash.hpp" @@ -217,6 +221,7 @@ int main(int argc, char **argv) } cable = select_cable->second; +#ifdef USE_LIBFTDI if (args.ftdi_channel != -1) { if (cable.type != MODE_FTDI_SERIAL && cable.type != MODE_FTDI_BITBANG){ printError("Error: FTDI channel param is for FTDI cables."); @@ -241,6 +246,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } } +#endif if (args.vid != 0) { printInfo("Cable VID overridden"); @@ -258,6 +264,7 @@ int main(int argc, char **argv) cable.config.index = args.cable_index; cable.config.status_pin = args.status_pin; +#ifdef USE_LIBFTDI /* FLASH direct access */ if (args.spi || (board && board->mode == COMM_SPI)) { /* if no instruction from user -> select flash mode */ @@ -404,11 +411,13 @@ int main(int argc, char **argv) return spi_ret; } +#endif /* ------------------- */ /* DFU access */ /* ------------------- */ if (args.dfu || (board && board->mode == COMM_DFU)) { +#ifdef ENABLE_DFU /* try to init DFU probe */ DFU *dfu = NULL; uint16_t vid = 0, pid = 0; @@ -458,6 +467,10 @@ int main(int argc, char **argv) } return EXIT_SUCCESS; +#else + throw std::runtime_error("DFU support: disabled at build time"); + return EXIT_FAILURE; +#endif } #ifdef ENABLE_XVC @@ -604,19 +617,23 @@ int main(int argc, char **argv) } else if (fab == "anlogic") { fpga = new Anlogic(jtag, args.bit_file, args.file_type, args.prg_type, args.verify, args.verbose); +#ifdef USE_LIBFTDI } else if (fab == "efinix") { fpga = new Efinix(jtag, args.bit_file, args.file_type, args.prg_type, args.board, args.fpga_part, args.bridge_path, args.verify, args.verbose); +#endif } else if (fab == "Gowin") { fpga = new Gowin(jtag, args.bit_file, args.file_type, args.mcufw, args.prg_type, args.external_flash, args.verify, args.verbose, args.user_flash); } else if (fab == "lattice") { fpga = new Lattice(jtag, args.bit_file, args.file_type, args.prg_type, args.flash_sector, args.verify, args.verbose, args.skip_load_bridge, args.skip_reset); +#ifdef USE_LIBFTDI } else if (fab == "colognechip") { fpga = new CologneChip(jtag, args.bit_file, args.file_type, args.prg_type, args.board, args.cable, args.verify, args.verbose); +#endif } else { printError("Error: manufacturer " + fab + " not supported"); delete(jtag); @@ -1193,9 +1210,11 @@ void displaySupported(const struct arguments &args) cout << endl; } +#ifdef ENABLE_USB_SCAN if (args.scan_usb) { libusb_ll usb(0, 0, args.verbose); usb.scan(); } +#endif } diff --git a/src/usbBlaster.cpp b/src/usbBlaster.cpp index 51f5ab1..771fbf9 100644 --- a/src/usbBlaster.cpp +++ b/src/usbBlaster.cpp @@ -13,7 +13,9 @@ #include #include "display.hpp" +#ifdef USE_LIBFTDI #include "ftdipp_mpsse.hpp" +#endif #include "fx2_ll.hpp" #include "usbBlaster.hpp" @@ -43,9 +45,17 @@ UsbBlaster::UsbBlaster(const cable_t &cable, const std::string &firmware_path, _curr_tms(0), _buffer_size(64) { if (cable.pid == 0x6001) +#ifdef ENABLE_USB_BLASTERI ll_driver = new UsbBlasterI(); +#else + throw std::runtime_error("usb-blasterI: Not build"); +#endif +#ifdef ENABLE_USB_BLASTERII else if (cable.pid == 0x6810) ll_driver = new UsbBlasterII(firmware_path); +#else + throw std::runtime_error("usb-blasterII: Not build"); +#endif else throw std::runtime_error("usb-blaster: unknown VID/PID"); @@ -58,6 +68,7 @@ UsbBlaster::UsbBlaster(const cable_t &cable, const std::string &firmware_path, _nb_bit = 0; memset(_in_buf, 0, _buffer_size); +#ifdef ENABLE_USB_BLASTERI /* Force flush internal FT245 internal buffer */ if (cable.pid == 0x6001) { uint8_t val = DEFAULT | DO_WRITE | DO_BITBB | _tms_pin; @@ -70,6 +81,7 @@ UsbBlaster::UsbBlaster(const cable_t &cable, const std::string &firmware_path, ll_driver->write(tmp_buf, _nb_bit, NULL, 0); _nb_bit = 0; } +#endif } UsbBlaster::~UsbBlaster() @@ -337,6 +349,7 @@ int UsbBlaster::write(bool read, int rd_len) return ret; } +#ifdef ENABLE_USB_BLASTERI /* * USB Blash I specific implementation */ @@ -426,7 +439,9 @@ int UsbBlasterI::write(uint8_t *wr_buf, int wr_len, } return ret; } +#endif +#ifdef ENABLE_USB_BLASTERII /* * USB Blash II specific implementation */ @@ -512,3 +527,4 @@ int UsbBlasterII::write(uint8_t *wr_buf, int wr_len, } return ret; } +#endif diff --git a/src/usbBlaster.hpp b/src/usbBlaster.hpp index b04a2c6..82b80b1 100644 --- a/src/usbBlaster.hpp +++ b/src/usbBlaster.hpp @@ -5,13 +5,17 @@ #ifndef SRC_USBBLASTER_HPP_ #define SRC_USBBLASTER_HPP_ +#ifdef USE_LIBFTDI #include +#endif #include #include #include #include "cable.hpp" +#ifdef USE_LIBFTDI #include "ftdipp_mpsse.hpp" +#endif #include "fx2_ll.hpp" #include "jtagInterface.hpp" @@ -95,6 +99,7 @@ class UsbBlaster : public JtagInterface { uint16_t _buffer_size; }; +#ifdef ENABLE_USB_BLASTERI /*! * \file UsbBlaster.hpp * \class UsbBlasterI @@ -113,7 +118,9 @@ class UsbBlasterI: public UsbBlaster_ll { private: struct ftdi_context *_ftdi; /*!< ftdi_context */ }; +#endif +#ifdef ENABLE_USB_BLASTERII /*! * \file UsbBlaster.hpp * \class UsbBlasterII @@ -132,4 +139,5 @@ class UsbBlasterII: public UsbBlaster_ll { private: FX2_ll *fx2; }; +#endif #endif // SRC_USBBLASTER_HPP_