add fabric bitstream writer

This commit is contained in:
tangxifan 2020-04-21 12:02:10 -06:00
parent 3f1fb70d16
commit d325bede68
7 changed files with 110 additions and 5 deletions

View File

@ -12,7 +12,8 @@
#include "openfpga_digest.h"
#include "build_device_bitstream.h"
#include "bitstream_writer.h"
#include "arch_bitstream_writer.h"
#include "fabric_bitstream_writer.h"
#include "build_fabric_bitstream.h"
#include "openfpga_bitstream.h"
@ -56,10 +57,24 @@ int build_fabric_bitstream(OpenfpgaContext& openfpga_ctx,
const Command& cmd, const CommandContext& cmd_context) {
CommandOptionId opt_verbose = cmd.option("verbose");
CommandOptionId opt_file = cmd.option("file");
/* Build fabric bitstream here */
openfpga_ctx.mutable_fabric_bitstream() = build_fabric_dependent_bitstream(openfpga_ctx.bitstream_manager(),
openfpga_ctx.module_graph(),
cmd_context.option_enable(cmd, opt_verbose));
/* Write fabric bitstream if required */
if (true == cmd_context.option_enable(cmd, opt_file)) {
std::string src_dir_path = find_path_dir_name(cmd_context.option_value(cmd, opt_file));
/* Create directories */
create_directory(src_dir_path);
write_fabric_bitstream_to_text_file(openfpga_ctx.bitstream_manager(),
openfpga_ctx.fabric_bitstream(),
cmd_context.option_value(cmd, opt_file));
}
/* TODO: should identify the error code from internal function execution */
return CMD_EXEC_SUCCESS;

View File

@ -76,6 +76,11 @@ ShellCommandId add_openfpga_fabric_bitstream_command(openfpga::Shell<OpenfpgaCon
const std::vector<ShellCommandId>& dependent_cmds) {
Command shell_cmd("build_fabric_bitstream");
/* Add an option '--file' in short '-f'*/
CommandOptionId opt_file = shell_cmd.add_option("file", false, "file path to output the fabric bitstream to plain text file");
shell_cmd.set_option_short_name(opt_file, "f");
shell_cmd.set_option_require_value(opt_file, openfpga::OPT_STRING);
/* Add an option '--verbose' */
shell_cmd.add_option("verbose", false, "Enable verbose output");

View File

@ -17,7 +17,7 @@
#include "openfpga_naming.h"
#include "bitstream_manager_utils.h"
#include "bitstream_writer.h"
#include "arch_bitstream_writer.h"
/* begin namespace openfpga */
namespace openfpga {

View File

@ -1,5 +1,5 @@
#ifndef BITSTREAM_WRITER_H
#define BITSTREAM_WRITER_H
#ifndef ARCH_BITSTREAM_WRITER_H
#define ARCH_BITSTREAM_WRITER_H
/********************************************************************
* Include header files that are required by function declaration

View File

@ -0,0 +1,61 @@
/********************************************************************
* This file includes functions that output a fabric-dependent
* bitstream database to files in different formats
*******************************************************************/
#include <chrono>
#include <ctime>
#include <fstream>
/* Headers from vtrutil library */
#include "vtr_assert.h"
#include "vtr_log.h"
#include "vtr_time.h"
/* Headers from openfpgautil library */
#include "openfpga_digest.h"
#include "openfpga_naming.h"
#include "bitstream_manager_utils.h"
#include "fabric_bitstream_writer.h"
/* begin namespace openfpga */
namespace openfpga {
/********************************************************************
* Write the fabric bitstream to a plain text file
* Notes:
* - This is the final bitstream which is loadable to the FPGA fabric
* (Verilog netlists etc.)
* - Do NOT include any comments or other characters that the 0|1 bitstream content
* in this file
*******************************************************************/
void write_fabric_bitstream_to_text_file(const BitstreamManager& bitstream_manager,
const std::vector<ConfigBitId>& fabric_bitstream,
const std::string& fname) {
/* Ensure that we have a valid file name */
if (true == fname.empty()) {
VTR_LOG_ERROR("Received empty file name to output bitstream!\n\tPlease specify a valid file name.\n");
}
std::string timer_message = std::string("Write ") + std::to_string(fabric_bitstream.size()) + std::string(" fabric bitstream into plain text file '") + fname + std::string("'");
vtr::ScopedStartFinishTimer timer(timer_message);
/* Create the file stream */
std::fstream fp;
fp.open(fname, std::fstream::out | std::fstream::trunc);
check_file_stream(fname.c_str(), fp);
/* Put down pure 0|1 bitstream here */
for (const ConfigBitId& fabric_bit : fabric_bitstream) {
fp << bitstream_manager.bit_value(fabric_bit);
}
/* Print an end to the file here */
fp << std::endl;
/* Close file handler */
fp.close();
}
} /* end namespace openfpga */

View File

@ -0,0 +1,24 @@
#ifndef FABRIC_BITSTREAM_WRITER_H
#define FABRIC_BITSTREAM_WRITER_H
/********************************************************************
* Include header files that are required by function declaration
*******************************************************************/
#include <string>
#include <vector>
#include "bitstream_manager.h"
/********************************************************************
* Function declaration
*******************************************************************/
/* begin namespace openfpga */
namespace openfpga {
void write_fabric_bitstream_to_text_file(const BitstreamManager& bitstream_manager,
const std::vector<ConfigBitId>& fabric_bitstream,
const std::string& fname);
} /* end namespace openfpga */
#endif

View File

@ -34,7 +34,7 @@ repack #--verbose
build_architecture_bitstream --verbose --file /var/tmp/xtang/openfpga_test_src/fabric_indepenent_bitstream.xml
# Build fabric-dependent bitstream
build_fabric_bitstream --verbose
build_fabric_bitstream --verbose --file /var/tmp/xtang/openfpga_test_src/and.bitstream
# Write the Verilog netlist for FPGA fabric
# - Enable the use of explicit port mapping in Verilog netlist