From cc1dc3c86847aad00dc4e650f94328809d30f0a8 Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Wed, 28 Jan 2026 14:52:41 +0100 Subject: [PATCH] CMakeLists.txt,main: added options to enable/disable vendors drivers --- CMakeLists.txt | 231 +++++++++++++++++++++++++++++++++++-------------- src/main.cpp | 84 ++++++++++++++++-- 2 files changed, 244 insertions(+), 71 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea7f19b..12c68e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,23 @@ else() set(ENABLE_XILINX_VIRTUAL_CABLE OFF) endif() +#################################################################################################### +# VENDORS Options +#################################################################################################### + +# set all vendor on by default +option(ENABLE_VENDORS_ALL "Enable all vendors support" ON) + +option(ENABLE_ALTERA_SUPPORT "enable Altera FPGAs Support" ${ENABLE_VENDORS_ALL}) +option(ENABLE_ANLOGIC_SUPPORT "enable Anlogic FPGAs Support" ${ENABLE_VENDORS_ALL}) +option(ENABLE_COLOGNECHIP_SUPPORT "enable CologneChip FPGAs Support (requires libftdi)" ${ENABLE_VENDORS_ALL}) +option(ENABLE_EFINIX_SUPPORT "enable Efinix FPGAs Support (requires libftdi)" ${ENABLE_VENDORS_ALL}) +option(ENABLE_GOWIN_SUPPORT "enable Gowin FPGAs Support" ${ENABLE_VENDORS_ALL}) +option(ENABLE_ICE40_SUPPORT "enable Ice40 FPGAs Support (requires libftdi)" ${ENABLE_VENDORS_ALL}) +option(ENABLE_LATTICE_SUPPORT "enable Lattice FPGAs Support" ${ENABLE_VENDORS_ALL}) +option(ENABLE_LATTICESSPI_SUPPORT "enable Lattice FPGAs Support (SSPI / requires libftdi)" ${ENABLE_VENDORS_ALL}) +option(ENABLE_XILINX_SUPPORT "enable Xilinx FPGAs Support" ${ENABLE_VENDORS_ALL}) + #################################################################################################### # Variables #################################################################################################### @@ -146,7 +163,7 @@ if (USE_PKGCONFIG) endif(USE_LIBUSB) if(ENABLE_CMSISDAP) - pkg_check_modules(HIDAPI hidapi-libusb) + pkg_check_modules(HIDAPI hidapi-libusb) # if libusb not found try with hidraw if (NOT HIDAPI_FOUND) pkg_check_modules(HIDAPI hidapi-hidraw) @@ -155,6 +172,7 @@ if (USE_PKGCONFIG) pkg_check_modules(HIDAPI hidapi) endif() endif() + # zlib support (gzip) pkg_check_modules(ZLIB zlib) if (NOT ZLIB_FOUND) @@ -217,44 +235,33 @@ set(OPENFPGALOADER_HEADERS # =========================== # Parsers classes # =========================== -list(APPEND OPENFPGALOADER_SOURCE - src/anlogicBitParser.cpp - src/bitparser.cpp - src/fsparser.cpp - src/mcsParser.cpp - src/pofParser.cpp - src/rawParser.cpp - src/xilinxMapParser.cpp -) +list(APPEND OPENFPGALOADER_SOURCE src/rawParser.cpp) +list(APPEND OPENFPGALOADER_HEADERS src/rawParser.hpp) -list(APPEND OPENFPGALOADER_HEADERS - src/anlogicBitParser.hpp - src/bitparser.hpp - src/fsparser.hpp - src/mcsParser.hpp - src/pofParser.hpp - src/rawParser.hpp - src/xilinxMapParser.hpp -) +if (${ENABLE_LATTICE_SUPPORT} OR ${ENABLE_XILINX_SUPPORT}) + list(APPEND OPENFPGALOADER_SOURCE + src/jedParser.cpp + src/mcsParser.cpp + ) + + list(APPEND OPENFPGALOADER_HEADERS + src/jedParser.hpp + src/mcsParser.hpp + ) +endif() # =========================== # 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/jtag.hpp src/jtagInterface.hpp src/spiFlash.hpp @@ -262,8 +269,6 @@ list(APPEND OPENFPGALOADER_HEADERS src/epcq.hpp src/spiInterface.hpp src/svf_jtag.hpp - src/gowin.hpp - src/xilinx.hpp ) # FTDI Based cables @@ -287,52 +292,148 @@ if (${USE_LIBFTDI}) ) # CologneChip Drivers / Files parsers. - list(APPEND OPENFPGALOADER_SOURCE - src/colognechip.cpp - src/colognechipCfgParser.cpp - ) + if (ENABLE_COLOGNECHIP_SUPPORT) + list(APPEND OPENFPGALOADER_SOURCE + src/colognechip.cpp + src/colognechipCfgParser.cpp + ) - list(APPEND OPENFPGALOADER_HEADERS - src/colognechip.hpp - src/colognechipCfgParser.hpp - ) + list(APPEND OPENFPGALOADER_HEADERS + src/colognechip.hpp + src/colognechipCfgParser.hpp + ) + add_definitions(-DENABLE_COLOGNECHIP_SUPPORT=1) + message("CologneChip support enabled") + else() + message("CologneChip support disabled") + endif(ENABLE_COLOGNECHIP_SUPPORT) # Efinix Drivers / Files parsers. - list(APPEND OPENFPGALOADER_SOURCE - src/efinix.cpp - src/efinixHexParser.cpp - ) + if (ENABLE_EFINIX_SUPPORT) + list(APPEND OPENFPGALOADER_SOURCE + src/efinix.cpp + src/efinixHexParser.cpp + ) - list(APPEND OPENFPGALOADER_HEADERS - src/efinix.hpp - src/efinixHexParser.hpp - ) + list(APPEND OPENFPGALOADER_HEADERS + src/efinix.hpp + src/efinixHexParser.hpp + ) + add_definitions(-DENABLE_EFINIX_SUPPORT=1) + message("Efinix support enabled") + else() + message("Efinix support disabled") + endif(ENABLE_EFINIX_SUPPORT) - # Lattice Drivers / Files parsers. - list(APPEND OPENFPGALOADER_SOURCE - src/ice40.cpp - src/latticeSSPI.cpp - ) - list(APPEND OPENFPGALOADER_HEADERS - src/ice40.hpp - src/latticeSSPI.hpp - ) + # ICE40 Driver. + if (ENABLE_ICE40_SUPPORT) + list(APPEND OPENFPGALOADER_SOURCE src/ice40.cpp) + list(APPEND OPENFPGALOADER_HEADERS src/ice40.hpp) + add_definitions(-DENABLE_ICE40_SUPPORT=1) + message("ICE40 support enabled") + else() + message("ICE40 support disabled") + endif(ENABLE_ICE40_SUPPORT) + + # Lattice SSPI Driver. + if (ENABLE_LATTICESSPI_SUPPORT) + list(APPEND OPENFPGALOADER_SOURCE src/latticeSSPI.cpp) + list(APPEND OPENFPGALOADER_HEADERS src/latticeSSPI.hpp) + add_definitions(-DENABLE_LATTICESSPI_SUPPORT=1) + message("Lattice SSPI support enabled") + else() + message("Lattice SSPI support disabled") + endif(ENABLE_LATTICESSPI_SUPPORT) endif() -# Lattice Drivers / Files parsers. -list(APPEND OPENFPGALOADER_SOURCE - src/lattice.cpp - src/feaparser.cpp - src/jedParser.cpp - src/latticeBitParser.cpp -) +# Altera Drivers / Files parsers. +if (ENABLE_ALTERA_SUPPORT) + list(APPEND OPENFPGALOADER_SOURCE + src/altera.cpp + src/pofParser.cpp + ) -list(APPEND OPENFPGALOADER_HEADERS - src/lattice.hpp - src/jedParser.hpp - src/feaparser.hpp - src/latticeBitParser.hpp -) + list(APPEND OPENFPGALOADER_HEADERS + src/altera.hpp + src/pofParser.hpp + ) + add_definitions(-DENABLE_ALTERA_SUPPORT=1) + message("Altera support enabled") +else() + message("Altera support disabled") +endif(ENABLE_ALTERA_SUPPORT) + +# Anlogic Drivers / Files parsers. +if (ENABLE_ANLOGIC_SUPPORT) + list(APPEND OPENFPGALOADER_SOURCE + src/anlogic.cpp + src/anlogicBitParser.cpp + ) + + list(APPEND OPENFPGALOADER_HEADERS + src/anlogic.hpp + src/anlogicBitParser.hpp + ) + add_definitions(-DENABLE_ANLOGIC_SUPPORT=1) + message("Anlogic support enabled") +else() + message("Anlogic support disabled") +endif(ENABLE_ANLOGIC_SUPPORT) + +# Gowin Drivers / Files parsers. +if (ENABLE_GOWIN_SUPPORT) + list(APPEND OPENFPGALOADER_SOURCE + src/gowin.cpp + src/fsparser.cpp + ) + + list(APPEND OPENFPGALOADER_HEADERS + src/gowin.hpp + src/fsparser.hpp + ) + add_definitions(-DENABLE_GOWIN_SUPPORT=1) + message("Gowin support enabled") +else() + message("Gowin support disabled") +endif(ENABLE_GOWIN_SUPPORT) + +# Xilinx Drivers / Files parsers. +if (ENABLE_XILINX_SUPPORT) + list(APPEND OPENFPGALOADER_SOURCE + src/bitparser.cpp + src/xilinx.cpp + src/xilinxMapParser.cpp + ) + + list(APPEND OPENFPGALOADER_HEADERS + src/bitparser.hpp + src/xilinx.hpp + src/xilinxMapParser.hpp + ) + add_definitions(-DENABLE_XILINX_SUPPORT=1) + message("Xilinx support enabled") +else() + message("Xilinx support disabled") +endif(ENABLE_XILINX_SUPPORT) + +# Lattice Drivers / Files parsers. +if (ENABLE_LATTICE_SUPPORT) + list(APPEND OPENFPGALOADER_SOURCE + src/lattice.cpp + src/feaparser.cpp + src/latticeBitParser.cpp + ) + + list(APPEND OPENFPGALOADER_HEADERS + src/lattice.hpp + src/feaparser.hpp + src/latticeBitParser.hpp + ) + add_definitions(-DENABLE_LATTICE_SUPPORT=1) + message("Lattice support enabled") +else() + message("Lattice support disabled") +endif(ENABLE_LATTICE_SUPPORT) # Cables select diff --git a/src/main.cpp b/src/main.cpp index be2a440..941d42c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,11 +13,15 @@ #include #include +#ifdef ENABLE_ALTERA_SUPPORT #include "altera.hpp" +#endif +#ifdef ENABLE_ANLOGIC_SUPPORT #include "anlogic.hpp" +#endif #include "board.hpp" #include "cable.hpp" -#ifdef USE_LIBFTDI +#ifdef ENABLE_COLOGNECHIP_SUPPORT #include "colognechip.hpp" #endif #include "common.hpp" @@ -27,14 +31,22 @@ #include "dfu.hpp" #endif #include "display.hpp" -#ifdef USE_LIBFTDI +#ifdef ENABLE_EFINIX_SUPPORT #include "efinix.hpp" +#endif +#ifdef USE_LIBFTDI #include "ftdispi.hpp" #endif +#ifdef ENABLE_GOWIN_SUPPORT #include "gowin.hpp" +#endif +#ifdef ENABLE_LATTICE_SUPPORT #include "lattice.hpp" -#ifdef USE_LIBFTDI +#endif +#ifdef ENABLE_ICE40_SUPPORT #include "ice40.hpp" +#endif +#ifdef ENABLE_LATTICESSPI_SUPPORT #include "latticeSSPI.hpp" #endif #ifdef ENABLE_USB_SCAN @@ -44,7 +56,9 @@ #include "part.hpp" #include "spiFlash.hpp" #include "rawParser.hpp" +#ifdef ENABLE_XILINX_SUPPORT #include "xilinx.hpp" +#endif #include "svf_jtag.hpp" #ifdef ENABLE_XVC #include "xvc_server.hpp" @@ -304,25 +318,45 @@ int main(int argc, char **argv) if (board && board->manufacturer != "none") { Device *target; if (board->manufacturer == "efinix") { +#ifdef ENABLE_EFINIX_SUPPORT target = new Efinix(spi, args.bit_file, args.file_type, board->reset_pin, board->done_pin, board->oe_pin, args.verify, args.verbose); +#else + printError("Support for Efinix FPGAs was not enabled at compile time"); + return EXIT_FAILURE; +#endif } else if (board->manufacturer == "lattice") { if (board->fpga_part == "ice40") { +#ifdef ENABLE_ICE40_SUPPORT target = new Ice40(spi, args.bit_file, args.file_type, args.prg_type, board->reset_pin, board->done_pin, args.verify, args.verbose); +#else + printError("Support for ICE40 FPGAs was not enabled at compile time"); + return EXIT_FAILURE; +#endif } else if (board->fpga_part == "ecp5") { +#ifdef ENABLE_LATTICESSPI_SUPPORT target = new LatticeSSPI(spi, args.bit_file, args.file_type, args.verbose); +#else + printError("Support for Lattice FPGAs (SSPI mode) was not enabled at compile time"); + return EXIT_FAILURE; +#endif } else { printError("Error (SPI mode): " + board->fpga_part + " is an unsupported/unknown Lattice Model"); return EXIT_FAILURE; } } else if (board->manufacturer == "colognechip") { +#ifdef ENABLE_COLOGNECHIP_SUPPORT target = new CologneChip(spi, args.bit_file, args.file_type, args.prg_type, board->reset_pin, board->done_pin, DBUS6, board->oe_pin, args.verify, args.verbose); +#else + printError("Support for Gowin FPGAs was not enabled at compile time"); + return EXIT_FAILURE; +#endif } else { printError("Error (SPI mode): " + board->manufacturer + " is an unsupported/unknown target"); @@ -474,7 +508,7 @@ int main(int argc, char **argv) return EXIT_SUCCESS; #else - throw std::runtime_error("DFU support: disabled at build time"); + printError("DFU support: disabled at build time"); return EXIT_FAILURE; #endif } @@ -612,33 +646,71 @@ int main(int argc, char **argv) Device *fpga; try { if (fab == "xilinx") { +#ifdef ENABLE_XILINX_SUPPORT fpga = new Xilinx(jtag, args.bit_file, args.secondary_bit_file, args.file_type, args.prg_type, args.fpga_part, args.bridge_path, args.target_flash, args.verify, args.verbose, args.skip_load_bridge, args.skip_reset, args.read_dna, args.read_xadc); +#else + printError("Support for Xilinx FPGAs was not enabled at compile time"); + delete(jtag); + return EXIT_FAILURE; +#endif } else if (fab == "altera") { +#ifdef ENABLE_ALTERA_SUPPORT fpga = new Altera(jtag, args.bit_file, args.file_type, args.prg_type, args.fpga_part, args.bridge_path, args.verify, args.verbose, args.flash_sector, args.skip_load_bridge, args.skip_reset); +#else + printError("Support for Altera FPGAs was not enabled at compile time"); + delete(jtag); + return EXIT_FAILURE; +#endif } else if (fab == "anlogic") { +#ifdef ENABLE_ANLOGIC_SUPPORT fpga = new Anlogic(jtag, args.bit_file, args.file_type, args.prg_type, args.verify, args.verbose); -#ifdef USE_LIBFTDI +#else + printError("Support for Anlogic FPGAs was not enabled at compile time"); + delete(jtag); + return EXIT_FAILURE; +#endif } else if (fab == "efinix") { +#ifdef ENABLE_EFINIX_SUPPORT 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); +#else + printError("Support for Efinix FPGAs was not enabled at compile time"); + delete(jtag); + return EXIT_FAILURE; #endif } else if (fab == "Gowin") { +#ifdef ENABLE_GOWIN_SUPPORT 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 + printError("Support for Gowin FPGAs was not enabled at compile time"); + delete(jtag); + return EXIT_FAILURE; +#endif } else if (fab == "lattice") { +#ifdef ENABLE_LATTICE_SUPPORT 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 + printError("Support for Lattice FPGAs was not enabled at compile time"); + delete(jtag); + return EXIT_FAILURE; +#endif } else if (fab == "colognechip") { +#ifdef ENABLE_COLOGNECHIP_SUPPORT fpga = new CologneChip(jtag, args.bit_file, args.file_type, args.prg_type, args.board, args.cable, args.verify, args.verbose); +#else + printError("Support for Gowin FPGAs was not enabled at compile time"); + delete(jtag); + return EXIT_FAILURE; #endif } else { printError("Error: manufacturer " + fab + " not supported");