33#include " Chip.hpp"
44#include " Database.hpp"
55#include < iostream>
6+ #include < boost/optional.hpp>
67#include < boost/program_options.hpp>
78#include < stdexcept>
89#include < streambuf>
@@ -14,13 +15,15 @@ int main(int argc, char *argv[])
1415{
1516 using namespace Trellis ;
1617 namespace po = boost::program_options;
18+ boost::optional<uint32_t > idcode;
1719
1820 std::string database_folder = TRELLIS_PREFIX " /share/trellis/database" ;
1921
2022 po::options_description options (" Allowed options" );
2123 options.add_options ()(" help,h" , " show help" );
2224 options.add_options ()(" verbose,v" , " verbose output" );
2325 options.add_options ()(" db" , po::value<std::string>(), " Trellis database folder location" );
26+ options.add_options ()(" idcode" , po::value<std::string>(), " IDCODE to override in bitstream" );
2427 po::positional_options_description pos;
2528 options.add_options ()(" input" , po::value<std::string>()->required (), " input bitstream file" );
2629 pos.add (" input" , 1 );
@@ -59,6 +62,17 @@ int main(int argc, char *argv[])
5962 database_folder = vm[" db" ].as <string>();
6063 }
6164
65+ if (vm.count (" idcode" )) {
66+ string idcode_str = vm[" idcode" ].as <string>();
67+ uint32_t idcode_val;
68+ idcode_val = uint32_t (strtoul (idcode_str.c_str (), nullptr , 0 ));
69+ if (idcode_val == 0 ) {
70+ cerr << " Invalid idcode: " << idcode_str << endl;
71+ return 1 ;
72+ }
73+ idcode = idcode_val;
74+ }
75+
6276 try {
6377 load_database (database_folder);
6478 } catch (runtime_error &e) {
@@ -67,7 +81,7 @@ int main(int argc, char *argv[])
6781 }
6882
6983 try {
70- Chip c = Bitstream::read_bit (bit_file).deserialise_chip ();
84+ Chip c = Bitstream::read_bit (bit_file).deserialise_chip (idcode );
7185 ChipConfig cc = ChipConfig::from_chip (c);
7286 ofstream out_file (vm[" textcfg" ].as <string>());
7387 if (!out_file) {
0 commit comments