diff options
author | Clifford Wolf <clifford@clifford.at> | 2019-12-01 00:42:53 +0100 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2019-12-01 00:44:07 +0100 |
commit | 0392cd3a5b2a00a13dc3f48ea74f4f28613ee6ab (patch) | |
tree | fb495c1109d34f1d6615618b8195d0b0a8035ff6 /bba | |
parent | 1c1c096861d553f1fc71d7db3652af25b980b219 (diff) | |
download | nextpnr-0392cd3a5b2a00a13dc3f48ea74f4f28613ee6ab.tar.gz nextpnr-0392cd3a5b2a00a13dc3f48ea74f4f28613ee6ab.tar.bz2 nextpnr-0392cd3a5b2a00a13dc3f48ea74f4f28613ee6ab.zip |
Add bba #embed support
Signed-off-by: Clifford Wolf <clifford@clifford.at>
Diffstat (limited to 'bba')
-rw-r--r-- | bba/main.cc | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/bba/main.cc b/bba/main.cc index d4d16e12..5940797e 100644 --- a/bba/main.cc +++ b/bba/main.cc @@ -72,6 +72,7 @@ int main(int argc, char **argv) bool verbose = false; bool bigEndian; bool writeC = false; + bool writeE = false; char buffer[512]; namespace po = boost::program_options; @@ -82,7 +83,8 @@ int main(int argc, char **argv) options.add_options()("debug,d", "debug output"); options.add_options()("be,b", "big endian"); options.add_options()("le,l", "little endian"); - options.add_options()("c,c", "write c strings"); + options.add_options()("c,c", "write C strings"); + options.add_options()("e,e", "write #embed C"); options.add_options()("files", po::value<std::vector<std::string>>(), "file parameters"); pos.add("files", -1); @@ -115,13 +117,19 @@ int main(int argc, char **argv) } if (vm.count("c")) writeC = true; + if (vm.count("e")) + writeE = true; + if (writeC && writeE) { + printf("Incompatible modes\n"); + exit(-1); + } if (vm.count("files") == 0) { printf("File parameters are mandatory\n"); exit(-1); } std::vector<std::string> files = vm["files"].as<std::vector<std::string>>(); - if (files.size() != 2) { + if (files.size() != (writeE ? 3 : 2)) { printf("Input and output parameters must be set\n"); exit(-1); } @@ -433,6 +441,22 @@ int main(int argc, char **argv) for (auto &s : postText) fprintf(fileOut, "%s\n", s.c_str()); + } else if (writeE) { + for (auto &s : preText) + fprintf(fileOut, "%s\n", s.c_str()); + + fprintf(fileOut, "const char %s[%d] =\n", streams[0].name.c_str(), int(data.size())); + char *bin_basename_buf = strdup(files.at(2).c_str()); + fprintf(fileOut, "#embed \"%s\"\n", basename(bin_basename_buf)); + fprintf(fileOut, ";\n"); + + for (auto &s : postText) + fprintf(fileOut, "%s\n", s.c_str()); + + FILE *fileBin = fopen(files.at(2).c_str(), "wb"); + assert(fileBin != nullptr); + fwrite(data.data(), int(data.size()), 1, fileBin); + fclose(fileBin); } else { fwrite(data.data(), int(data.size()), 1, fileOut); } |