Merge pull request #231 from YosysHQ/mmaped_chipdb

Load chipdb from filesystem as option
This commit is contained in:
Miodrag Milanović 2019-02-12 18:56:59 +01:00 committed by GitHub
commit cf7baeec55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 228 additions and 160 deletions

View File

@ -7,6 +7,7 @@ option(BUILD_PYTHON "Build Python Integration" ON)
option(BUILD_TESTS "Build GUI" OFF)
option(COVERAGE "Add code coverage info" OFF)
option(STATIC_BUILD "Create static build" OFF)
option(EXTERNAL_CHIPDB "Create build with pre-built chipdb binaries" OFF)
set(link_param "")
if (STATIC_BUILD)
@ -16,6 +17,14 @@ if (STATIC_BUILD)
endif()
endif()
if (EXTERNAL_CHIPDB)
if (NOT DEFINED EXTERNAL_CHIPDB_ROOT)
message(STATUS "EXTERNAL_CHIPDB_ROOT not defined using -DEXTERNAL_CHIPDB_ROOT=/path/to/nextpnr. Default to /usr/share/nextpnr")
set(EXTERNAL_CHIPDB_ROOT "/usr/share/nextpnr")
endif()
add_definitions("-DEXTERNAL_CHIPDB_ROOT=\"${EXTERNAL_CHIPDB_ROOT}\"")
endif()
# List of families to build
set(FAMILIES generic ice40 ecp5)
@ -66,7 +75,7 @@ endif()
find_package(Sanitizers)
# List of Boost libraries to include
set(boost_libs filesystem thread program_options)
set(boost_libs filesystem thread program_options iostreams)
if (BUILD_GUI AND NOT BUILD_PYTHON)
message(FATAL_ERROR "GUI requires Python to build")

View File

@ -19,6 +19,7 @@
*/
#include <algorithm>
#include <boost/iostreams/device/mapped_file.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <cmath>
#include <cstring>
@ -63,11 +64,37 @@ static const ChipInfoPOD *get_chip_info(const RelPtr<ChipInfoPOD> *ptr) { return
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;
boost::iostreams::mapped_file_source blob_files[3];
const char *mmap_file(int index, const char *filename)
{
try {
blob_files[index].open(filename);
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);
}
}
void load_chipdb()
{
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");
}
#endif
//#define LFE5U_45F_ONLY
Arch::Arch(ArchArgs args) : args(args)
{
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(EXTERNAL_CHIPDB_ROOT)
load_chipdb();
#endif
#ifdef LFE5U_45F_ONLY

View File

@ -204,7 +204,7 @@ NPNR_PACKED_STRUCT(struct ChipInfoPOD {
RelPtr<SpeedGradePOD> speed_grades;
});
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(EXTERNAL_CHIPDB_ROOT)
extern const char *chipdb_blob_25k;
extern const char *chipdb_blob_45k;
extern const char *chipdb_blob_85k;

View File

@ -1,4 +1,4 @@
if (NOT EXTERNAL_CHIPDB)
set(devices 25k 45k 85k)
if (NOT DEFINED TRELLIS_ROOT)
@ -75,3 +75,4 @@ else()
endforeach (target)
endforeach (dev)
endif()
endif()

View File

@ -19,6 +19,7 @@
*/
#include <algorithm>
#include <boost/iostreams/device/mapped_file.hpp>
#include <cmath>
#include "cells.h"
#include "gfx.h"
@ -48,9 +49,37 @@ static const ChipInfoPOD *get_chip_info(const RelPtr<ChipInfoPOD> *ptr) { return
void load_chipdb();
#endif
#if defined(EXTERNAL_CHIPDB_ROOT)
const char *chipdb_blob_384 = nullptr;
const char *chipdb_blob_1k = nullptr;
const char *chipdb_blob_5k = nullptr;
const char *chipdb_blob_8k = nullptr;
boost::iostreams::mapped_file_source blob_files[4];
const char *mmap_file(int index, const char *filename)
{
try {
blob_files[index].open(filename);
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);
}
}
void load_chipdb()
{
chipdb_blob_384 = mmap_file(0, EXTERNAL_CHIPDB_ROOT "/ice40/chipdb-384.bin");
chipdb_blob_1k = mmap_file(1, EXTERNAL_CHIPDB_ROOT "/ice40/chipdb-1k.bin");
chipdb_blob_5k = mmap_file(2, EXTERNAL_CHIPDB_ROOT "/ice40/chipdb-5k.bin");
chipdb_blob_8k = mmap_file(3, EXTERNAL_CHIPDB_ROOT "/ice40/chipdb-8k.bin");
}
#endif
Arch::Arch(ArchArgs args) : args(args)
{
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(EXTERNAL_CHIPDB_ROOT)
load_chipdb();
#endif

View File

@ -244,7 +244,7 @@ NPNR_PACKED_STRUCT(struct ChipInfoPOD {
RelPtr<RelPtr<char>> tile_wire_names;
});
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(EXTERNAL_CHIPDB_ROOT)
extern const char *chipdb_blob_384;
extern const char *chipdb_blob_1k;
extern const char *chipdb_blob_5k;

View File

@ -1,3 +1,4 @@
if (NOT EXTERNAL_CHIPDB)
if(ICE40_HX1K_ONLY)
set(devices 1k)
foreach (target ${family_targets})
@ -82,3 +83,4 @@ else()
endforeach (target)
endforeach (dev)
endif()
endif()