Skip to content

Commit

Permalink
libtrellis: Allow specifying idcode override in ecpunpack
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Andersen <[email protected]>
  • Loading branch information
EnJens committed Feb 24, 2019
1 parent a7947fa commit ef3fb4f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion libtrellis/tools/ecpunpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Chip.hpp"
#include "Database.hpp"
#include <iostream>
#include <boost/optional.hpp>
#include <boost/program_options.hpp>
#include <stdexcept>
#include <streambuf>
Expand All @@ -14,13 +15,15 @@ int main(int argc, char *argv[])
{
using namespace Trellis;
namespace po = boost::program_options;
boost::optional<uint32_t> idcode;

std::string database_folder = TRELLIS_PREFIX "/share/trellis/database";

po::options_description options("Allowed options");
options.add_options()("help,h", "show help");
options.add_options()("verbose,v", "verbose output");
options.add_options()("db", po::value<std::string>(), "Trellis database folder location");
options.add_options()("idcode", po::value<std::string>(), "IDCODE to override in bitstream");
po::positional_options_description pos;
options.add_options()("input", po::value<std::string>()->required(), "input bitstream file");
pos.add("input", 1);
Expand Down Expand Up @@ -59,6 +62,17 @@ int main(int argc, char *argv[])
database_folder = vm["db"].as<string>();
}

if (vm.count("idcode")) {
string idcode_str = vm["idcode"].as<string>();
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) {
Expand All @@ -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<string>());
if (!out_file) {
Expand Down

0 comments on commit ef3fb4f

Please sign in to comment.