2017-12-14 22:46:54 +01:00
|
|
|
#include <algorithm>
|
2017-12-05 00:50:55 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
#include <absl/strings/str_cat.h>
|
|
|
|
|
#include <absl/types/span.h>
|
|
|
|
|
#include <gflags/gflags.h>
|
|
|
|
|
#include <prjxray/memory_mapped_file.h>
|
2017-12-05 19:17:36 +01:00
|
|
|
#include <prjxray/xilinx/xc7series/bitstream_reader.h>
|
|
|
|
|
|
|
|
|
|
namespace xc7series = prjxray::xilinx::xc7series;
|
2017-12-05 00:50:55 +01:00
|
|
|
|
|
|
|
|
struct Action {
|
|
|
|
|
std::string name;
|
2018-01-08 22:30:02 +01:00
|
|
|
std::function<int(int, char* [])> handler;
|
2017-12-05 00:50:55 +01:00
|
|
|
};
|
|
|
|
|
|
2018-01-08 22:30:02 +01:00
|
|
|
int ListConfigPackets(int argc, char* argv[]) {
|
2017-12-13 19:43:06 +01:00
|
|
|
if (argc < 1) {
|
|
|
|
|
std::cerr << "ERROR: no input specified" << std::endl;
|
|
|
|
|
std::cerr << "Usage: " << argv[0]
|
2018-01-08 22:30:02 +01:00
|
|
|
<< "list_config_packets <bit_file>" << std::endl;
|
2017-12-13 19:43:06 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto in_file_name = argv[0];
|
|
|
|
|
auto in_file = prjxray::MemoryMappedFile::InitWithFile(in_file_name);
|
2017-12-05 00:50:55 +01:00
|
|
|
if (!in_file) {
|
2017-12-13 19:43:06 +01:00
|
|
|
std::cerr << "Unable to open bit file: " << in_file_name
|
2018-01-08 22:30:02 +01:00
|
|
|
<< std::endl;
|
2017-12-05 00:50:55 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 22:30:02 +01:00
|
|
|
auto reader =
|
|
|
|
|
xc7series::BitstreamReader::InitWithBytes(in_file->as_bytes());
|
2017-12-05 00:50:55 +01:00
|
|
|
if (!reader) {
|
2018-01-08 22:30:02 +01:00
|
|
|
std::cerr << "Input doesn't look like a bitstream" << std::endl;
|
2017-12-05 00:50:55 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto packet : *reader) {
|
|
|
|
|
std::cout << packet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 22:30:02 +01:00
|
|
|
int DumpDebugbitstreamFrameAddresses(int argc, char* argv[]) {
|
2017-12-13 19:13:26 +01:00
|
|
|
if (argc < 1) {
|
|
|
|
|
std::cerr << "ERROR: no input specified" << std::endl;
|
|
|
|
|
std::cerr << "Usage: " << argv[0]
|
2018-01-08 22:30:02 +01:00
|
|
|
<< "dump_debugbitstream_frame_addresses <bit_file>"
|
|
|
|
|
<< std::endl;
|
2017-12-13 19:13:26 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto in_file_name = argv[0];
|
|
|
|
|
auto in_file = prjxray::MemoryMappedFile::InitWithFile(in_file_name);
|
|
|
|
|
if (!in_file) {
|
|
|
|
|
std::cerr << "Unable to open bit file: " << in_file_name
|
2018-01-08 22:30:02 +01:00
|
|
|
<< std::endl;
|
2017-12-13 19:13:26 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto in_bytes = absl::Span<uint8_t>(
|
2018-01-08 22:30:02 +01:00
|
|
|
static_cast<uint8_t*>(in_file->data()), in_file->size());
|
2017-12-13 19:13:26 +01:00
|
|
|
auto reader = xc7series::BitstreamReader::InitWithBytes(in_bytes);
|
|
|
|
|
if (!reader) {
|
2018-01-08 22:30:02 +01:00
|
|
|
std::cerr << "Input doesn't look like a bitstream" << std::endl;
|
2017-12-13 19:13:26 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool found_one_lout = false;
|
|
|
|
|
for (auto packet : *reader) {
|
|
|
|
|
if ((packet.opcode() !=
|
|
|
|
|
xc7series::ConfigurationPacket::Opcode::Write) ||
|
|
|
|
|
(packet.address() !=
|
|
|
|
|
xc7series::ConfigurationRegister::LOUT)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (packet.data().size() != 1) {
|
|
|
|
|
std::cerr << "Write to FAR with word_count != 1"
|
2018-01-08 22:30:02 +01:00
|
|
|
<< std::endl;
|
2017-12-13 19:13:26 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
found_one_lout = true;
|
|
|
|
|
std::cout << std::dec << packet.data()[0] << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!found_one_lout) {
|
|
|
|
|
std::cerr << "No LOUT writes found. Was "
|
2018-01-08 22:30:02 +01:00
|
|
|
<< "BITSTREAM.GENERAL.DEBUGBITSTREAM set to YES?"
|
|
|
|
|
<< std::endl;
|
2017-12-13 19:13:26 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 22:30:02 +01:00
|
|
|
int GetDeviceId(int argc, char* argv[]) {
|
2017-12-14 22:46:54 +01:00
|
|
|
if (argc < 1) {
|
|
|
|
|
std::cerr << "ERROR: no input specified" << std::endl;
|
2018-01-08 22:30:02 +01:00
|
|
|
std::cerr << "Usage: " << argv[0] << "get_device_id <bit_file>"
|
|
|
|
|
<< std::endl;
|
2017-12-14 22:46:54 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto in_file_name = argv[0];
|
|
|
|
|
auto in_file = prjxray::MemoryMappedFile::InitWithFile(in_file_name);
|
|
|
|
|
if (!in_file) {
|
|
|
|
|
std::cerr << "Unable to open bit file: " << in_file_name
|
2018-01-08 22:30:02 +01:00
|
|
|
<< std::endl;
|
2017-12-14 22:46:54 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto in_bytes = absl::Span<uint8_t>(
|
2018-01-08 22:30:02 +01:00
|
|
|
static_cast<uint8_t*>(in_file->data()), in_file->size());
|
2017-12-14 22:46:54 +01:00
|
|
|
auto reader = xc7series::BitstreamReader::InitWithBytes(in_bytes);
|
|
|
|
|
if (!reader) {
|
2018-01-08 22:30:02 +01:00
|
|
|
std::cerr << "Input doesn't look like a bitstream" << std::endl;
|
2017-12-14 22:46:54 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto idcode_packet = std::find_if(
|
2018-01-08 22:30:02 +01:00
|
|
|
reader->begin(), reader->end(),
|
|
|
|
|
[](const xc7series::ConfigurationPacket& packet) {
|
|
|
|
|
return (packet.opcode() ==
|
|
|
|
|
xc7series::ConfigurationPacket::Opcode::Write) &&
|
|
|
|
|
(packet.address() ==
|
|
|
|
|
xc7series::ConfigurationRegister::IDCODE);
|
|
|
|
|
});
|
2017-12-14 22:46:54 +01:00
|
|
|
if (idcode_packet != reader->end()) {
|
|
|
|
|
if (idcode_packet->data().size() != 1) {
|
|
|
|
|
std::cerr << "Write to IDCODE with word_count != 1"
|
2018-01-08 22:30:02 +01:00
|
|
|
<< std::endl;
|
2017-12-14 22:46:54 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::cout << "0x" << std::hex << idcode_packet->data()[0]
|
2018-01-08 22:30:02 +01:00
|
|
|
<< std::endl;
|
2017-12-14 22:46:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2018-01-08 22:30:02 +01:00
|
|
|
int main(int argc, char* argv[]) {
|
2017-12-05 00:50:55 +01:00
|
|
|
Action actions[] = {
|
2018-01-08 22:30:02 +01:00
|
|
|
{"list_config_packets", ListConfigPackets},
|
|
|
|
|
{"dump_debugbitstream_frame_addresses",
|
|
|
|
|
DumpDebugbitstreamFrameAddresses},
|
|
|
|
|
{"get_device_id", GetDeviceId},
|
2017-12-05 00:50:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
gflags::SetUsageMessage(
|
2018-01-08 22:30:02 +01:00
|
|
|
absl::StrCat("Usage: ", argv[0], " [options] [bitfile]"));
|
2017-12-05 00:50:55 +01:00
|
|
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
|
|
2017-12-13 19:43:06 +01:00
|
|
|
if (argc < 2) {
|
|
|
|
|
std::cerr << "ERROR: no command specified" << std::endl;
|
|
|
|
|
std::cerr << "Usage: " << argv[0]
|
2018-01-08 22:30:02 +01:00
|
|
|
<< "<command> <command_options>" << std::endl;
|
2017-12-05 00:50:55 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-13 19:43:06 +01:00
|
|
|
auto requested_action_str = argv[1];
|
2017-12-05 00:50:55 +01:00
|
|
|
auto requested_action = std::find_if(
|
2018-01-08 22:30:02 +01:00
|
|
|
std::begin(actions), std::end(actions),
|
|
|
|
|
[&](const Action& t) { return t.name == requested_action_str; });
|
2017-12-05 00:50:55 +01:00
|
|
|
if (requested_action == std::end(actions)) {
|
2018-01-08 22:30:02 +01:00
|
|
|
std::cerr << "Unknown action: " << requested_action_str
|
|
|
|
|
<< std::endl;
|
2017-12-05 00:50:55 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-13 19:43:06 +01:00
|
|
|
return requested_action->handler(argc - 2, argv + 2);
|
2017-12-05 00:50:55 +01:00
|
|
|
}
|