From 9166a4364945596f60b7838ba352554565b42395 Mon Sep 17 00:00:00 2001 From: Keith Rothman <537074+litghost@users.noreply.github.com> Date: Thu, 15 Nov 2018 14:01:12 -0800 Subject: [PATCH 1/4] Do not insert non-existant frames. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- tools/xc7patch.cc | 110 +++++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 45 deletions(-) diff --git a/tools/xc7patch.cc b/tools/xc7patch.cc index 9ea3962d..dd53a559 100644 --- a/tools/xc7patch.cc +++ b/tools/xc7patch.cc @@ -36,6 +36,67 @@ DEFINE_string(output_file, "", "Write patched bitsteam to file"); namespace xc7series = prjxray::xilinx::xc7series; +int patch_frames(const std::string &frm_file_str, + std::map> *frames) { + // Apply the deltas. + std::ifstream frm_file(frm_file_str); + if (!frm_file) { + std::cerr << "Unable to open frm file: " << frm_file_str + << std::endl; + return 1; + } + + std::string frm_line; + while (std::getline(frm_file, frm_line)) { + if (frm_line[0] == '#') + continue; + + std::pair frame_delta = + absl::StrSplit(frm_line, ' '); + + uint32_t frame_address = + std::stoul(frame_delta.first, nullptr, 16); + + auto iter = frames->find(frame_address); + if(iter == frames->end()) { + std::cerr + << "frame address 0x" << std::hex <second; + frame_data.resize(101); + + std::vector frame_data_strings = + absl::StrSplit(frame_delta.second, ','); + if (frame_data_strings.size() != 101) { + std::cerr << "Frame " << std::hex << frame_address + << ": found " << std::dec + << frame_data_strings.size() + << "words instead of 101"; + continue; + }; + + std::transform(frame_data_strings.begin(), + frame_data_strings.end(), frame_data.begin(), + [](const std::string& val) -> uint32_t { + return std::stoul(val, nullptr, 16); + }); + + uint32_t ecc = 0; + for (size_t ii = 0; ii < frame_data.size(); ++ii) { + ecc = xc7series::icap_ecc(ii, frame_data[ii], ecc); + } + + // Replace the old ECC with the new. + frame_data[0x32] &= 0xFFFFE000; + frame_data[0x32] |= (ecc & 0x1FFF); + } + + return 0; +} + int main(int argc, char* argv[]) { gflags::SetUsageMessage(argv[0]); gflags::ParseCommandLineFlags(&argc, &argv, true); @@ -80,52 +141,11 @@ int main(int argc, char* argv[]) { std::back_inserter(cur_frame)); } - // Apply the deltas. - std::ifstream frm_file(FLAGS_frm_file); - if (!frm_file) { - std::cerr << "Unable to open frm file: " << FLAGS_frm_file - << std::endl; - return 1; - } - - std::string frm_line; - while (std::getline(frm_file, frm_line)) { - if (frm_line[0] == '#') - continue; - - std::pair frame_delta = - absl::StrSplit(frm_line, ' '); - - uint32_t frame_address = - std::stoul(frame_delta.first, nullptr, 16); - - auto& frame_data = frames[frame_address]; - frame_data.resize(101); - - std::vector frame_data_strings = - absl::StrSplit(frame_delta.second, ','); - if (frame_data_strings.size() != 101) { - std::cerr << "Frame " << std::hex << frame_address - << ": found " << std::dec - << frame_data_strings.size() - << "words instead of 101"; - continue; - }; - - std::transform(frame_data_strings.begin(), - frame_data_strings.end(), frame_data.begin(), - [](const std::string& val) -> uint32_t { - return std::stoul(val, nullptr, 16); - }); - - uint32_t ecc = 0; - for (size_t ii = 0; ii < frame_data.size(); ++ii) { - ecc = xc7series::icap_ecc(ii, frame_data[ii], ecc); + if(!FLAGS_frm_file.empty()) { + int ret = patch_frames(FLAGS_frm_file, &frames); + if(ret != 0) { + return ret; } - - // Replace the old ECC with the new. - frame_data[0x32] &= 0xFFFFE000; - frame_data[0x32] |= (ecc & 0x1FFF); } std::vector> From 8da0a38fd77d39cb91bff0966d02f7e966650b13 Mon Sep 17 00:00:00 2001 From: Keith Rothman <537074+litghost@users.noreply.github.com> Date: Thu, 15 Nov 2018 14:04:22 -0800 Subject: [PATCH 2/4] Run make format. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- tools/xc7patch.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/xc7patch.cc b/tools/xc7patch.cc index dd53a559..222fc6e1 100644 --- a/tools/xc7patch.cc +++ b/tools/xc7patch.cc @@ -36,8 +36,9 @@ DEFINE_string(output_file, "", "Write patched bitsteam to file"); namespace xc7series = prjxray::xilinx::xc7series; -int patch_frames(const std::string &frm_file_str, - std::map> *frames) { +int patch_frames( + const std::string& frm_file_str, + std::map>* frames) { // Apply the deltas. std::ifstream frm_file(frm_file_str); if (!frm_file) { @@ -58,10 +59,10 @@ int patch_frames(const std::string &frm_file_str, std::stoul(frame_delta.first, nullptr, 16); auto iter = frames->find(frame_address); - if(iter == frames->end()) { + if (iter == frames->end()) { std::cerr - << "frame address 0x" << std::hex < Date: Thu, 15 Nov 2018 14:05:43 -0800 Subject: [PATCH 3/4] Correct sentence. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- tools/xc7patch.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/xc7patch.cc b/tools/xc7patch.cc index 222fc6e1..f10d89ac 100644 --- a/tools/xc7patch.cc +++ b/tools/xc7patch.cc @@ -62,7 +62,7 @@ int patch_frames( if (iter == frames->end()) { std::cerr << "frame address 0x" << std::hex << frame_address - << " because it was not found frames." << std::endl; + << " because it was not found in frames." << std::endl; return 1; } From 84ccebce228eef2d0d40225fd25f42d9244e72f9 Mon Sep 17 00:00:00 2001 From: Keith Rothman <537074+litghost@users.noreply.github.com> Date: Thu, 15 Nov 2018 15:28:17 -0800 Subject: [PATCH 4/4] make format. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- tools/xc7patch.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/xc7patch.cc b/tools/xc7patch.cc index f10d89ac..d82b2869 100644 --- a/tools/xc7patch.cc +++ b/tools/xc7patch.cc @@ -60,9 +60,10 @@ int patch_frames( auto iter = frames->find(frame_address); if (iter == frames->end()) { - std::cerr - << "frame address 0x" << std::hex << frame_address - << " because it was not found in frames." << std::endl; + std::cerr << "frame address 0x" << std::hex + << frame_address + << " because it was not found in frames." + << std::endl; return 1; }