From ef3fb4f2ae8fa253cbf6caae1e5baf07236e8257 Mon Sep 17 00:00:00 2001 From: Jens Andersen Date: Sun, 24 Feb 2019 13:53:01 +0100 Subject: [PATCH] libtrellis: Allow specifying idcode override in ecpunpack Signed-off-by: Jens Andersen --- libtrellis/tools/ecpunpack.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libtrellis/tools/ecpunpack.cpp b/libtrellis/tools/ecpunpack.cpp index d76aba17..68ad3a89 100644 --- a/libtrellis/tools/ecpunpack.cpp +++ b/libtrellis/tools/ecpunpack.cpp @@ -3,6 +3,7 @@ #include "Chip.hpp" #include "Database.hpp" #include +#include #include #include #include @@ -14,6 +15,7 @@ int main(int argc, char *argv[]) { using namespace Trellis; namespace po = boost::program_options; + boost::optional idcode; std::string database_folder = TRELLIS_PREFIX "/share/trellis/database"; @@ -21,6 +23,7 @@ int main(int argc, char *argv[]) options.add_options()("help,h", "show help"); options.add_options()("verbose,v", "verbose output"); options.add_options()("db", po::value(), "Trellis database folder location"); + options.add_options()("idcode", po::value(), "IDCODE to override in bitstream"); po::positional_options_description pos; options.add_options()("input", po::value()->required(), "input bitstream file"); pos.add("input", 1); @@ -59,6 +62,17 @@ int main(int argc, char *argv[]) database_folder = vm["db"].as(); } + if (vm.count("idcode")) { + string idcode_str = vm["idcode"].as(); + uint32_t idcode_val; + idcode_val = uint32_t(strtoul(idcode_str.c_str(), nullptr, 0)); + if (idcode_val == 0) { + cerr << "Invalid idcode: " << idcode_str << endl; + return 1; + } + idcode = idcode_val; + } + try { load_database(database_folder); } catch (runtime_error &e) { @@ -67,7 +81,7 @@ int main(int argc, char *argv[]) } try { - Chip c = Bitstream::read_bit(bit_file).deserialise_chip(); + Chip c = Bitstream::read_bit(bit_file).deserialise_chip(idcode); ChipConfig cc = ChipConfig::from_chip(c); ofstream out_file(vm["textcfg"].as()); if (!out_file) {