From 89e0cc8078ecbb57ca450cc6c8a40f6b634b8c9c Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 25 Jun 2020 15:11:47 +0000 Subject: Simplify and improve chipdb embedding/loading. --- ecp5/arch.cc | 82 +++++++++++++++++++----------------------------- ecp5/arch.h | 13 ++------ ecp5/family.cmake | 11 +++++-- ecp5/main.cc | 30 ++++++++++++------ ecp5/resource/chipdb.rc | 5 --- ecp5/resource/embed.cc | 28 ----------------- ecp5/resource/resource.h | 4 --- ecp5/trellis_import.py | 2 ++ 8 files changed, 66 insertions(+), 109 deletions(-) delete mode 100644 ecp5/resource/chipdb.rc delete mode 100644 ecp5/resource/embed.cc delete mode 100644 ecp5/resource/resource.h (limited to 'ecp5') diff --git a/ecp5/arch.cc b/ecp5/arch.cc index f947783e..a9ffd1e9 100644 --- a/ecp5/arch.cc +++ b/ecp5/arch.cc @@ -27,6 +27,7 @@ #include "globals.h" #include "log.h" #include "nextpnr.h" +#include "embed.h" #include "placer1.h" #include "placer_heap.h" #include "router1.h" @@ -60,69 +61,52 @@ void IdString::initialize_arch(const BaseCtx *ctx) // ----------------------------------------------------------------------- -static const ChipInfoPOD *get_chip_info(const RelPtr *ptr) { return ptr->get(); } - -#if defined(WIN32) -void load_chipdb(); -#endif - -#if defined(EXTERNAL_CHIPDB_ROOT) -const char *chipdb_blob_25k = nullptr; -const char *chipdb_blob_45k = nullptr; -const char *chipdb_blob_85k = nullptr; +static const ChipInfoPOD *get_chip_info(ArchArgs::ArchArgsTypes chip) { + std::string chipdb; + if (chip == ArchArgs::LFE5U_12F || chip == ArchArgs::LFE5U_25F || + chip == ArchArgs::LFE5UM_25F || chip == ArchArgs::LFE5UM5G_25F) { + chipdb = "ecp5/chipdb-25k.bin"; + } else if (chip == ArchArgs::LFE5U_45F || + chip == ArchArgs::LFE5UM_45F || chip == ArchArgs::LFE5UM5G_45F) { + chipdb = "ecp5/chipdb-45k.bin"; + } else if (chip == ArchArgs::LFE5U_85F || + chip == ArchArgs::LFE5UM_85F || chip == ArchArgs::LFE5UM5G_85F) { + chipdb = "ecp5/chipdb-85k.bin"; + } else { + log_error("Unknown chip\n"); + } -boost::iostreams::mapped_file blob_files[3]; + auto ptr = reinterpret_cast *>(get_chipdb(chipdb)); + if (ptr == nullptr) + return nullptr; + return ptr->get(); +} -const char *mmap_file(int index, const char *filename) +bool Arch::isAvailable(ArchArgs::ArchArgsTypes chip) { - try { - // WASI only supports MAP_PRIVATE - blob_files[index].open(filename, boost::iostreams::mapped_file::priv); - if (!blob_files[index].is_open()) - log_error("Unable to read chipdb %s\n", filename); - return (const char *)blob_files[index].data(); - } catch (...) { - log_error("Unable to read chipdb %s\n", filename); - } + return get_chip_info(chip) != nullptr; } -void load_chipdb() +std::vector Arch::getSupportedPackages(ArchArgs::ArchArgsTypes chip) { - chipdb_blob_25k = mmap_file(0, EXTERNAL_CHIPDB_ROOT "/ecp5/chipdb-25k.bin"); - chipdb_blob_45k = mmap_file(1, EXTERNAL_CHIPDB_ROOT "/ecp5/chipdb-45k.bin"); - chipdb_blob_85k = mmap_file(2, EXTERNAL_CHIPDB_ROOT "/ecp5/chipdb-85k.bin"); + const ChipInfoPOD *chip_info = get_chip_info(chip); + std::vector packages; + for (int i = 0; i < chip_info->num_packages; i++) + packages.push_back(chip_info->package_info[i].name.get()); + return packages; } -#endif -//#define LFE5U_45F_ONLY + +// ----------------------------------------------------------------------- Arch::Arch(ArchArgs args) : args(args) { -#if defined(WIN32) || defined(EXTERNAL_CHIPDB_ROOT) - load_chipdb(); -#endif -#ifdef LFE5U_45F_ONLY - if (args.type == ArchArgs::LFE5U_45F) { - chip_info = get_chip_info(reinterpret_cast *>(chipdb_blob_45k)); - } else { - log_error("Unsupported ECP5 chip type.\n"); - } -#else - if (args.type == ArchArgs::LFE5U_12F || args.type == ArchArgs::LFE5U_25F || args.type == ArchArgs::LFE5UM_25F || - args.type == ArchArgs::LFE5UM5G_25F) { - chip_info = get_chip_info(reinterpret_cast *>(chipdb_blob_25k)); - } else if (args.type == ArchArgs::LFE5U_45F || args.type == ArchArgs::LFE5UM_45F || - args.type == ArchArgs::LFE5UM5G_45F) { - chip_info = get_chip_info(reinterpret_cast *>(chipdb_blob_45k)); - } else if (args.type == ArchArgs::LFE5U_85F || args.type == ArchArgs::LFE5UM_85F || - args.type == ArchArgs::LFE5UM5G_85F) { - chip_info = get_chip_info(reinterpret_cast *>(chipdb_blob_85k)); - } else { + chip_info = get_chip_info(args.type); + if (chip_info == nullptr) log_error("Unsupported ECP5 chip type.\n"); - } -#endif if (chip_info->const_id_count != DB_CONST_ID_COUNT) log_error("Chip database 'bba' and nextpnr code are out of sync; please rebuild (or contact distribution " "maintainer)!\n"); + package_info = nullptr; for (int i = 0; i < chip_info->num_packages; i++) { if (args.package == chip_info->package_info[i].name.get()) { diff --git a/ecp5/arch.h b/ecp5/arch.h index c13f2041..0f351319 100644 --- a/ecp5/arch.h +++ b/ecp5/arch.h @@ -207,16 +207,6 @@ NPNR_PACKED_STRUCT(struct ChipInfoPOD { RelPtr speed_grades; }); -#if defined(WIN32) || defined(EXTERNAL_CHIPDB_ROOT) -extern const char *chipdb_blob_25k; -extern const char *chipdb_blob_45k; -extern const char *chipdb_blob_85k; -#else -extern const char chipdb_blob_25k[]; -extern const char chipdb_blob_45k[]; -extern const char chipdb_blob_85k[]; -#endif - /************************ End of chipdb section. ************************/ struct BelIterator @@ -494,6 +484,9 @@ struct Arch : BaseCtx ArchArgs args; Arch(ArchArgs args); + static bool isAvailable(ArchArgs::ArchArgsTypes chip); + static std::vector getSupportedPackages(ArchArgs::ArchArgsTypes chip); + std::string getChipName() const; std::string getFullChipName() const; diff --git a/ecp5/family.cmake b/ecp5/family.cmake index 0f96811a..cc97ae5e 100644 --- a/ecp5/family.cmake +++ b/ecp5/family.cmake @@ -30,9 +30,14 @@ foreach(device ${ECP5_DEVICES}) endif() endforeach() if(WIN32) - list(APPEND chipdb_sources - ${CMAKE_CURRENT_SOURCE_DIR}/${family}/resource/embed.cc - ${CMAKE_CURRENT_SOURCE_DIR}/${family}/resource/chipdb.rc) + set(chipdb_rc ${CMAKE_CURRENT_BINARY_DIR}/${family}/resource/chipdb.rc) + list(APPEND chipdb_sources ${chipdb_rc}) + + file(WRITE ${chipdb_rc}) + foreach(device ${ECP5_DEVICES}) + file(APPEND ${chipdb_rc} + "${family}/chipdb-${device}.bin RCDATA \"${CMAKE_CURRENT_BINARY_DIR}/${family}/chipdb/chipdb-${device}.bin\"") + endforeach() endif() add_custom_target(chipdb-${family}-bins DEPENDS ${chipdb_sources} ${chipdb_binaries}) diff --git a/ecp5/main.cc b/ecp5/main.cc index f1cb9760..311f5401 100644 --- a/ecp5/main.cc +++ b/ecp5/main.cc @@ -49,16 +49,26 @@ ECP5CommandHandler::ECP5CommandHandler(int argc, char **argv) : CommandHandler(a po::options_description ECP5CommandHandler::getArchOptions() { po::options_description specific("Architecture specific options"); - specific.add_options()("12k", "set device type to LFE5U-12F"); - specific.add_options()("25k", "set device type to LFE5U-25F"); - specific.add_options()("45k", "set device type to LFE5U-45F"); - specific.add_options()("85k", "set device type to LFE5U-85F"); - specific.add_options()("um-25k", "set device type to LFE5UM-25F"); - specific.add_options()("um-45k", "set device type to LFE5UM-45F"); - specific.add_options()("um-85k", "set device type to LFE5UM-85F"); - specific.add_options()("um5g-25k", "set device type to LFE5UM5G-25F"); - specific.add_options()("um5g-45k", "set device type to LFE5UM5G-45F"); - specific.add_options()("um5g-85k", "set device type to LFE5UM5G-85F"); + if (Arch::isAvailable(ArchArgs::LFE5U_12F)) + specific.add_options()("12k", "set device type to LFE5U-12F"); + if (Arch::isAvailable(ArchArgs::LFE5U_25F)) + specific.add_options()("25k", "set device type to LFE5U-25F"); + if (Arch::isAvailable(ArchArgs::LFE5U_45F)) + specific.add_options()("45k", "set device type to LFE5U-45F"); + if (Arch::isAvailable(ArchArgs::LFE5U_85F)) + specific.add_options()("85k", "set device type to LFE5U-85F"); + if (Arch::isAvailable(ArchArgs::LFE5UM_25F)) + specific.add_options()("um-25k", "set device type to LFE5UM-25F"); + if (Arch::isAvailable(ArchArgs::LFE5UM_45F)) + specific.add_options()("um-45k", "set device type to LFE5UM-45F"); + if (Arch::isAvailable(ArchArgs::LFE5UM_85F)) + specific.add_options()("um-85k", "set device type to LFE5UM-85F"); + if (Arch::isAvailable(ArchArgs::LFE5UM5G_25F)) + specific.add_options()("um5g-25k", "set device type to LFE5UM5G-25F"); + if (Arch::isAvailable(ArchArgs::LFE5UM5G_45F)) + specific.add_options()("um5g-45k", "set device type to LFE5UM5G-45F"); + if (Arch::isAvailable(ArchArgs::LFE5UM5G_85F)) + specific.add_options()("um5g-85k", "set device type to LFE5UM5G-85F"); specific.add_options()("package", po::value(), "select device package (defaults to CABGA381)"); specific.add_options()("speed", po::value(), "select device speedgrade (6, 7 or 8)"); diff --git a/ecp5/resource/chipdb.rc b/ecp5/resource/chipdb.rc deleted file mode 100644 index 60f690c6..00000000 --- a/ecp5/resource/chipdb.rc +++ /dev/null @@ -1,5 +0,0 @@ -#include "resource.h" - -IDR_CHIPDB_25K BINARYFILE "ecp5/chipdb/chipdb-25k.bin" -IDR_CHIPDB_45K BINARYFILE "ecp5/chipdb/chipdb-45k.bin" -IDR_CHIPDB_88K BINARYFILE "ecp5/chipdb/chipdb-85k.bin" diff --git a/ecp5/resource/embed.cc b/ecp5/resource/embed.cc deleted file mode 100644 index adbb7781..00000000 --- a/ecp5/resource/embed.cc +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include "nextpnr.h" -#include "resource.h" - -NEXTPNR_NAMESPACE_BEGIN - -const char *chipdb_blob_25k; -const char *chipdb_blob_45k; -const char *chipdb_blob_85k; - -const char *LoadFileInResource(int name, int type, DWORD &size) -{ - HMODULE handle = ::GetModuleHandle(NULL); - HRSRC rc = ::FindResource(handle, MAKEINTRESOURCE(name), MAKEINTRESOURCE(type)); - HGLOBAL rcData = ::LoadResource(handle, rc); - size = ::SizeofResource(handle, rc); - return static_cast(::LockResource(rcData)); -} -void load_chipdb() -{ - DWORD size = 0; - chipdb_blob_25k = LoadFileInResource(IDR_CHIPDB_25K, BINARYFILE, size); - chipdb_blob_45k = LoadFileInResource(IDR_CHIPDB_45K, BINARYFILE, size); - chipdb_blob_85k = LoadFileInResource(IDR_CHIPDB_85K, BINARYFILE, size); -} - -NEXTPNR_NAMESPACE_END \ No newline at end of file diff --git a/ecp5/resource/resource.h b/ecp5/resource/resource.h deleted file mode 100644 index 1a18bee2..00000000 --- a/ecp5/resource/resource.h +++ /dev/null @@ -1,4 +0,0 @@ -#define BINARYFILE 256 -#define IDR_CHIPDB_25K 101 -#define IDR_CHIPDB_45K 102 -#define IDR_CHIPDB_85K 103 diff --git a/ecp5/trellis_import.py b/ecp5/trellis_import.py index b591e09f..174f475f 100755 --- a/ecp5/trellis_import.py +++ b/ecp5/trellis_import.py @@ -391,7 +391,9 @@ def write_database(dev_name, chip, ddrg, endianness): bba = BinaryBlobAssembler() bba.pre('#include "nextpnr.h"') + bba.pre('#include "embed.h"') bba.pre('NEXTPNR_NAMESPACE_BEGIN') + bba.post('EmbeddedFile chipdb_file_%s("ecp5/chipdb-%s.bin", chipdb_blob_%s);' % (dev_name, dev_name, dev_name)) bba.post('NEXTPNR_NAMESPACE_END') bba.push("chipdb_blob_%s" % dev_name) bba.r("chip_info", "chip_info") -- cgit v1.2.3